[macruby-changes] [120] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 26 15:51:39 PDT 2008
Revision: 120
http://trac.macosforge.org/projects/ruby/changeset/120
Author: lsansonetti at apple.com
Date: 2008-03-26 15:51:38 -0700 (Wed, 26 Mar 2008)
Log Message:
-----------
fixing a few regressions
Modified Paths:
--------------
MacRuby/trunk/array.c
MacRuby/trunk/compile.c
MacRuby/trunk/dln.c
MacRuby/trunk/enum.c
MacRuby/trunk/iseq.c
MacRuby/trunk/object.c
MacRuby/trunk/ruby.c
Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/array.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -40,7 +40,36 @@
}
}
-#if !WITH_OBJC
+#if WITH_OBJC
+struct rb_objc_ary_struct {
+ bool frozen;
+ bool named_args;
+};
+
+/* This variable will always stay NULL, we only use its address. */
+static void *rb_objc_assoc_key = NULL;
+
+static struct rb_objc_ary_struct *
+rb_objc_ary_get_struct(VALUE ary)
+{
+ return rb_objc_get_associative_ref((void *)ary, &rb_objc_assoc_key);
+}
+
+static struct rb_objc_ary_struct *
+rb_objc_ary_get_struct2(VALUE ary)
+{
+ struct rb_objc_ary_struct *s;
+
+ s = rb_objc_ary_get_struct(ary);
+ if (s == NULL) {
+ s = xmalloc(sizeof(struct rb_objc_ary_struct));
+ rb_objc_set_associative_ref((void *)ary, &rb_objc_assoc_key, s);
+ s->frozen = false;
+ s->named_args = false;
+ }
+ return s;
+}
+#else
#define ARY_SHARED_P(a) FL_TEST(a, ELTS_SHARED)
#define ARY_SET_LEN(ary, n) do { \
@@ -92,7 +121,8 @@
rb_ary_freeze(VALUE ary)
{
#if WITH_OBJC
- rb_notimplement();
+ rb_objc_ary_get_struct2(ary)->frozen = true;
+ return ary;
#else
return rb_obj_freeze(ary);
#endif
@@ -110,11 +140,12 @@
rb_ary_frozen_p(VALUE ary)
{
#if WITH_OBJC
- /* TODO */
+ struct rb_objc_ary_struct *s = rb_objc_ary_get_struct(ary);
+ return s != NULL && s->frozen ? Qtrue : Qfalse;
#else
if (OBJ_FROZEN(ary)) return Qtrue;
+ return Qfalse;
#endif
- return Qfalse;
}
#if WITH_OBJC
@@ -776,8 +807,7 @@
#if WITH_OBJC
{
long i;
- len = RARRAY_LEN(ary);
- for (i = len - 1; i >= 0; i++)
+ for (i = argc - 1; i >= 0; i--)
CFArrayInsertValueAtIndex((CFMutableArrayRef)ary,
0, (const void *)argv[i]);
}
@@ -1682,7 +1712,7 @@
long i;
for (i = 0; i < (n / 2); i++)
CFArrayExchangeValuesAtIndices((CFMutableArrayRef)ary,
- i, n - i);
+ i, n - i - 1);
}
#else
VALUE *p1, *p2;
@@ -3828,6 +3858,7 @@
rb_cArray = rb_objc_import_class((Class)objc_getClass("NSArray"));
rb_const_set(rb_cObject, rb_intern("Array"),
rb_objc_import_class((Class)objc_getClass("NSMutableArray")));
+ rb_define_method(rb_cArray, "freeze", rb_ary_freeze, 0);
#else
rb_cArray = rb_define_class("Array", rb_cObject);
#endif
Modified: MacRuby/trunk/compile.c
===================================================================
--- MacRuby/trunk/compile.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/compile.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -863,7 +863,12 @@
iseq->arg_opts = i;
iseq->arg_opt_table = ALLOC_N(VALUE, i);
+#if WITH_OBJC
+ CFArrayGetValues((CFArrayRef)labels, CFRangeMake(0, i),
+ (const void **)iseq->arg_opt_table);
+#else
MEMCPY(iseq->arg_opt_table, RARRAY_PTR(labels), VALUE, i);
+#endif
for (j = 0; j < i; j++) {
iseq->arg_opt_table[j] &= ~1;
}
@@ -1248,25 +1253,22 @@
static int
iseq_set_exception_table(rb_iseq_t *iseq)
{
- VALUE *tptr, *ptr;
int tlen, i;
struct iseq_catch_table_entry *entry;
tlen = RARRAY_LEN(iseq->compile_data->catch_table_ary);
- tptr = RARRAY_PTR(iseq->compile_data->catch_table_ary);
- iseq->catch_table = ALLOC_N(struct iseq_catch_table_entry, tlen);
+ GC_WB(&iseq->catch_table, ALLOC_N(struct iseq_catch_table_entry, tlen));
+
iseq->catch_table_size = tlen;
- /* FIXME this should be rewritten without using RARRAY_PTR */
-
for (i = 0; i < tlen; i++) {
- ptr = RARRAY_PTR(tptr[i]);
+ VALUE a = RARRAY_AT(iseq->compile_data->catch_table_ary, i);
entry = &iseq->catch_table[i];
- entry->type = ptr[0] & 0xffff;
- entry->start = label_get_position((LABEL *)(ptr[1] & ~1));
- entry->end = label_get_position((LABEL *)(ptr[2] & ~1));
- entry->iseq = ptr[3];
+ entry->type = RARRAY_AT(a, 0) & 0xffff;
+ entry->start = label_get_position((LABEL *)(RARRAY_AT(a, 1) & ~1));
+ entry->end = label_get_position((LABEL *)(RARRAY_AT(a, 2) & ~1));
+ GC_WB(&entry->iseq, RARRAY_AT(a, 3));
/* register iseq as mark object */
if (entry->iseq != 0) {
@@ -1274,15 +1276,15 @@
}
/* stack depth */
- if (ptr[4]) {
- LABEL *lobj = (LABEL *)(ptr[4] & ~1);
+ if (RARRAY_AT(a, 4)) {
+ LABEL *lobj = (LABEL *)(RARRAY_AT(a, 4) & ~1);
entry->cont = label_get_position(lobj);
entry->sp = label_get_sp(lobj);
/* TODO: Dirty Hack! Fix me */
if (entry->type == CATCH_TYPE_RESCUE ||
entry->type == CATCH_TYPE_BREAK ||
- (((ptr[0] & 0x10000) == 0)
+ (((RARRAY_AT(a, 0) & 0x10000) == 0)
&& entry->type == CATCH_TYPE_NEXT)) {
entry->sp--;
}
@@ -4779,7 +4781,7 @@
int i;
for (i=0; i<RARRAY_LEN(exception); i++) {
- VALUE v, type, *ptr, eiseqval;
+ VALUE v, type, eiseqval;
LABEL *lstart, *lend, *lcont;
int sp;
@@ -4789,17 +4791,17 @@
rb_raise(rb_eSyntaxError, "wrong exception entry");
}
type = get_exception_sym2type(RARRAY_AT(v, 0));
- if (RARRAY_AT(ptr, 1) == Qnil) {
+ if (RARRAY_AT(v, 1) == Qnil) {
eiseqval = 0;
}
else {
- eiseqval = iseq_load(0, RARRAY_AT(ptr, 1), iseq->self, Qnil);
+ eiseqval = iseq_load(0, RARRAY_AT(v, 1), iseq->self, Qnil);
}
- lstart = register_label(iseq, labels_table, RARRAY_AT(ptr, 2));
- lend = register_label(iseq, labels_table, RARRAY_AT(ptr, 3));
- lcont = register_label(iseq, labels_table, RARRAY_AT(ptr, 4));
- sp = NUM2INT(RARRAY_AT(ptr, 5));
+ lstart = register_label(iseq, labels_table, RARRAY_AT(v, 2));
+ lend = register_label(iseq, labels_table, RARRAY_AT(v, 3));
+ lcont = register_label(iseq, labels_table, RARRAY_AT(v, 4));
+ sp = NUM2INT(RARRAY_AT(v, 5));
ADD_CATCH_ENTRY(type, lstart, lend, eiseqval, lcont);
}
Modified: MacRuby/trunk/dln.c
===================================================================
--- MacRuby/trunk/dln.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/dln.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -366,6 +366,7 @@
return -1;
}
sym_tbl = sym_hash(&hdr, syms);
+ GC_ROOT(&sym_tbl);
if (sym_tbl == NULL) { /* file may be start with #! */
char c = '\0';
char buf[MAXPATHLEN];
@@ -408,6 +409,7 @@
}
dln_init_p = 1;
undef_tbl = st_init_strtable();
+ GC_ROOT(&undef_tbl);
close(fd);
return 0;
Modified: MacRuby/trunk/enum.c
===================================================================
--- MacRuby/trunk/enum.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/enum.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -618,9 +618,11 @@
NODE *memo;
v = enum_yield(argc, argv);
+#if !WITH_OBJC
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
+#endif
memo = rb_node_newnode(NODE_MEMO, v, i, 0);
rb_ary_push(ary, (VALUE)memo);
return Qnil;
@@ -638,9 +640,11 @@
#endif
VALUE ary = (VALUE)data;
+#if !WITH_OBJC
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
+#endif
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
}
@@ -727,7 +731,9 @@
else {
ary = rb_ary_new();
}
+#if !WITH_OBJC
RBASIC(ary)->klass = 0;
+#endif
rb_block_call(obj, id_each, 0, 0, sort_by_i, ary);
if (RARRAY_LEN(ary) > 1) {
#if WITH_OBJC
@@ -739,13 +745,17 @@
sort_by_cmp, (void *)ary);
#endif
}
+#if !WITH_OBJC
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
}
+#endif
for (i=0; i<RARRAY_LEN(ary); i++) {
rb_ary_store(ary, i, RNODE(RARRAY_AT(ary, i))->u2.value);
}
+#if !WITH_OBJC
RBASIC(ary)->klass = rb_cArray;
+#endif
return ary;
}
Modified: MacRuby/trunk/iseq.c
===================================================================
--- MacRuby/trunk/iseq.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/iseq.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -186,7 +186,7 @@
sizeof(struct iseq_compile_data_storage));
GC_WB(&iseq->compile_data->storage_head, iseq->compile_data->storage_head);
- iseq->compile_data->catch_table_ary = rb_ary_new();
+ GC_WB(&iseq->compile_data->catch_table_ary, rb_ary_new());
iseq->compile_data->storage_head->pos = 0;
iseq->compile_data->storage_head->next = 0;
iseq->compile_data->storage_head->size =
Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/object.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -772,6 +772,10 @@
VALUE
rb_obj_frozen_p(VALUE obj)
{
+#if WITH_OBJC
+ if (rb_objc_is_non_native(obj))
+ return Qfalse;
+#endif
if (OBJ_FROZEN(obj)) return Qtrue;
if (SPECIAL_CONST_P(obj)) {
if (!immediate_frozen_tbl) return Qfalse;
Modified: MacRuby/trunk/ruby.c
===================================================================
--- MacRuby/trunk/ruby.c 2008-03-26 04:06:22 UTC (rev 119)
+++ MacRuby/trunk/ruby.c 2008-03-26 22:51:38 UTC (rev 120)
@@ -463,20 +463,12 @@
process_sflag(struct cmdline_options *opt)
{
if (opt->sflag) {
- long n;
- VALUE *args;
+ long i, n;
VALUE argv = rb_argv;
n = RARRAY_LEN(argv);
-#if WITH_OBJC
- args = NULL;
- while (n > 0) {
- VALUE v = RARRAY_AT(argv, n);
-#else
- args = RARRAY_PTR(argv);
- while (n > 0) {
- VALUE v = *args++;
-#endif
+ for (i = 0; i < n; i++) {
+ VALUE v = RARRAY_AT(argv, i);
char *s = StringValuePtr(v);
char *p;
int hyphen = Qfalse;
@@ -508,7 +500,7 @@
else {
rb_str_cat(name_error[0], s, p - s);
}
- name_error[1] = args[-1];
+ name_error[1] = RARRAY_AT(argv, -1);
rb_exc_raise(rb_class_new_instance(2, name_error, rb_eNameError));
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080326/5623d5cc/attachment-0001.html
More information about the macruby-changes
mailing list