[macruby-changes] [1896] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jun 19 19:22:44 PDT 2009
Revision: 1896
http://trac.macosforge.org/projects/ruby/changeset/1896
Author: lsansonetti at apple.com
Date: 2009-06-19 19:22:44 -0700 (Fri, 19 Jun 2009)
Log Message:
-----------
also allow an Array of objects as a Pointer arg
Modified Paths:
--------------
MacRuby/branches/experimental/bridgesupport.cpp
MacRuby/branches/experimental/compiler.cpp
Modified: MacRuby/branches/experimental/bridgesupport.cpp
===================================================================
--- 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
===================================================================
--- 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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090619/81464f89/attachment-0001.html>
More information about the macruby-changes
mailing list