file.c: fix possible alignment bugs in r60386
* file.c (struct apply_filename): split out from struct apply_arg * file.c (apply2files): use offsetof for flex array size calculation * file.c (apply2files): avoid redundant marking with ALLOCV [ruby-core:83535] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3fc0c18193
commit
95e1c87014
31
file.c
31
file.c
@ -349,16 +349,18 @@ ignored_char_p(const char *p, const char *e, rb_encoding *enc)
|
|||||||
|
|
||||||
#define apply2args(n) (rb_check_arity(argc, n, UNLIMITED_ARGUMENTS), argc-=n)
|
#define apply2args(n) (rb_check_arity(argc, n, UNLIMITED_ARGUMENTS), argc-=n)
|
||||||
|
|
||||||
|
struct apply_filename {
|
||||||
|
const char *ptr;
|
||||||
|
VALUE path;
|
||||||
|
};
|
||||||
|
|
||||||
struct apply_arg {
|
struct apply_arg {
|
||||||
int i;
|
int i;
|
||||||
int argc;
|
int argc;
|
||||||
int errnum;
|
int errnum;
|
||||||
int (*func)(const char *, void *);
|
int (*func)(const char *, void *);
|
||||||
void *arg;
|
void *arg;
|
||||||
struct {
|
struct apply_filename fn[1]; /* flexible array */
|
||||||
const char *ptr;
|
|
||||||
VALUE path;
|
|
||||||
} fn[1]; /* flexible array */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
@ -384,9 +386,8 @@ static VALUE
|
|||||||
apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
|
apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
|
||||||
{
|
{
|
||||||
VALUE v;
|
VALUE v;
|
||||||
VALUE tmp = Qfalse;
|
const size_t size = sizeof(struct apply_filename);
|
||||||
size_t size = sizeof(const char *) + sizeof(VALUE);
|
const long len = (long)(offsetof(struct apply_arg, fn) + (size * argc));
|
||||||
const long len = (long)(sizeof(struct apply_arg) + (size * argc) - size);
|
|
||||||
struct apply_arg *aa = ALLOCV(v, len);
|
struct apply_arg *aa = ALLOCV(v, len);
|
||||||
|
|
||||||
aa->errnum = 0;
|
aa->errnum = 0;
|
||||||
@ -394,24 +395,12 @@ apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
|
|||||||
aa->arg = arg;
|
aa->arg = arg;
|
||||||
aa->func = func;
|
aa->func = func;
|
||||||
|
|
||||||
/*
|
|
||||||
* aa is on-stack for small argc, we must ensure paths are marked
|
|
||||||
* for large argv if aa is on the heap.
|
|
||||||
*/
|
|
||||||
if (v) {
|
|
||||||
tmp = rb_ary_tmp_new(argc);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (aa->i = 0; aa->i < argc; aa->i++) {
|
for (aa->i = 0; aa->i < argc; aa->i++) {
|
||||||
VALUE path = rb_get_path(argv[aa->i]);
|
VALUE path = rb_get_path(argv[aa->i]);
|
||||||
|
|
||||||
path = rb_str_encode_ospath(path);
|
path = rb_str_encode_ospath(path);
|
||||||
aa->fn[aa->i].ptr = RSTRING_PTR(path);
|
aa->fn[aa->i].ptr = RSTRING_PTR(path);
|
||||||
aa->fn[aa->i].path = path;
|
aa->fn[aa->i].path = path;
|
||||||
|
|
||||||
if (tmp != Qfalse) {
|
|
||||||
rb_ary_push(tmp, path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_thread_call_without_gvl(no_gvl_apply2files, aa, RUBY_UBF_IO, 0);
|
rb_thread_call_without_gvl(no_gvl_apply2files, aa, RUBY_UBF_IO, 0);
|
||||||
@ -426,10 +415,6 @@ apply2files(int (*func)(const char *, void *), int argc, VALUE *argv, void *arg)
|
|||||||
if (v) {
|
if (v) {
|
||||||
ALLOCV_END(v);
|
ALLOCV_END(v);
|
||||||
}
|
}
|
||||||
if (tmp != Qfalse) {
|
|
||||||
rb_ary_clear(tmp);
|
|
||||||
rb_gc_force_recycle(tmp);
|
|
||||||
}
|
|
||||||
return LONG2FIX(argc);
|
return LONG2FIX(argc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user