summaryrefslogtreecommitdiff
path: root/ext/fiddle
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-28 14:47:51 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-28 14:47:51 +0000
commit60053a0a506440f773da92b09204bde854f4f471 (patch)
tree78d0d6496656765e5380868f673914e054c90977 /ext/fiddle
parente7e87b3c4e5979ab81e924c3f1d26b7a28edbf74 (diff)
* ext/fiddle/closure.c (callback): use rb_ary_tmp_new() instead of
xmalloc() to allocate an array for arguments of callback procedure, to prevent arguments from being swept by GC. [ruby-core:38546] [Bug #4929] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle')
-rw-r--r--ext/fiddle/closure.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
index 157b97c..5f55d6d 100644
--- a/ext/fiddle/closure.c
+++ b/ext/fiddle/closure.c
@@ -56,7 +56,7 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
VALUE rbargs = rb_iv_get(self, "@args");
VALUE ctype = rb_iv_get(self, "@ctype");
int argc = RARRAY_LENINT(rbargs);
- VALUE *params = xcalloc(argc, sizeof(VALUE *));
+ VALUE params = rb_ary_tmp_new(argc);
VALUE ret;
VALUE cPointer;
int i, type;
@@ -70,27 +70,28 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
argc = 0;
break;
case TYPE_INT:
- params[i] = INT2NUM(*(int *)args[i]);
+ rb_ary_push(params, INT2NUM(*(int *)args[i]));
break;
case TYPE_VOIDP:
- params[i] = rb_funcall(cPointer, rb_intern("[]"), 1,
- PTR2NUM(*(void **)args[i]));
+ rb_ary_push(params,
+ rb_funcall(cPointer, rb_intern("[]"), 1,
+ PTR2NUM(*(void **)args[i])));
break;
case TYPE_LONG:
- params[i] = LONG2NUM(*(long *)args[i]);
+ rb_ary_push(params, LONG2NUM(*(long *)args[i]));
break;
case TYPE_CHAR:
- params[i] = INT2NUM(*(char *)args[i]);
+ rb_ary_push(params, INT2NUM(*(char *)args[i]));
break;
case TYPE_DOUBLE:
- params[i] = rb_float_new(*(double *)args[i]);
+ rb_ary_push(params, rb_float_new(*(double *)args[i]));
break;
case TYPE_FLOAT:
- params[i] = rb_float_new(*(float *)args[i]);
+ rb_ary_push(params, rb_float_new(*(float *)args[i]));
break;
#if HAVE_LONG_LONG
case TYPE_LONG_LONG:
- params[i] = rb_ull2inum(*(unsigned LONG_LONG *)args[i]);
+ rb_ary_push(params, rb_ull2inum(*(unsigned LONG_LONG *)args[i]));
break;
#endif
default:
@@ -98,7 +99,8 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
}
}
- ret = rb_funcall2(self, rb_intern("call"), argc, params);
+ ret = rb_funcall2(self, rb_intern("call"), argc, RARRAY_PTR(params));
+ RB_GC_GUARD(params);
type = NUM2INT(ctype);
switch (type) {
@@ -130,7 +132,6 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
default:
rb_raise(rb_eRuntimeError, "closure retval: %d", type);
}
- xfree(params);
}
static VALUE