Modified: MacRuby/branches/experimental/bridgesupport.cpp (1895 => 1896)
--- MacRuby/branches/experimental/bridgesupport.cpp 2009-06-20 00:57:44 UTC (rev 1895)
+++ MacRuby/branches/experimental/bridgesupport.cpp 2009-06-20 02:22:44 UTC (rev 1896)
@@ -537,14 +537,33 @@
return Data_Wrap_Struct(rb_cPointer, NULL, NULL, ptr);
}
-static VALUE rb_pointer_assign(VALUE rcv, SEL sel, VALUE val);
+static VALUE rb_pointer_aset(VALUE rcv, SEL sel, VALUE idx, VALUE val);
VALUE
rb_pointer_new2(const char *type_str, VALUE rval)
{
- VALUE p = rb_pointer_new(type_str,
- xmalloc(GET_VM()->get_sizeof(type_str)));
- rb_pointer_assign(p, 0, rval);
+ VALUE p;
+
+ if (TYPE(rval) == T_ARRAY) {
+ const int len = RARRAY_LEN(rval);
+ if (len == 0) {
+ rb_raise(rb_eArgError,
+ "can't convert an empty array to a `%s' pointer",
+ type_str);
+ }
+ p = rb_pointer_new(type_str,
+ xmalloc(GET_VM()->get_sizeof(type_str) * len));
+ int i;
+ for (i = 0; i < len; i++) {
+ rb_pointer_aset(p, 0, INT2FIX(i), RARRAY_AT(rval, i));
+ }
+ }
+ else {
+ p = rb_pointer_new(type_str,
+ xmalloc(GET_VM()->get_sizeof(type_str)));
+ rb_pointer_aset(p, 0, INT2FIX(0), rval);
+ }
+
return p;
}
Modified: MacRuby/branches/experimental/compiler.cpp (1895 => 1896)
--- MacRuby/branches/experimental/compiler.cpp 2009-06-20 00:57:44 UTC (rev 1895)
+++ MacRuby/branches/experimental/compiler.cpp 2009-06-20 02:22:44 UTC (rev 1896)
@@ -4605,9 +4605,10 @@
*cptr = NULL;
}
else {
- if (rb_boxed_is_type(CLASS_OF(rval), type + 1)) {
- // A convenience helper so that the user can pass a Boxed object
- // instead of a Pointer to the object.
+ if (TYPE(rval) == T_ARRAY
+ || rb_boxed_is_type(CLASS_OF(rval), type + 1)) {
+ // A convenience helper so that the user can pass a Boxed or an
+ // Array object instead of a Pointer to the object.
rval = rb_pointer_new2(type + 1, rval);
}
*cptr = rb_pointer_get_data(rval, type);