[macruby-changes] [194] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 15 15:04:43 PDT 2008
Revision: 194
http://trac.macosforge.org/projects/ruby/changeset/194
Author: lsansonetti at apple.com
Date: 2008-05-15 15:04:42 -0700 (Thu, 15 May 2008)
Log Message:
-----------
fixing some marshal bugs
Modified Paths:
--------------
MacRuby/trunk/array.c
MacRuby/trunk/encoding.c
MacRuby/trunk/hash.c
MacRuby/trunk/include/ruby/encoding.h
MacRuby/trunk/include/ruby/intern.h
MacRuby/trunk/marshal.c
MacRuby/trunk/parse.y
MacRuby/trunk/string.c
Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/array.c 2008-05-15 22:04:42 UTC (rev 194)
@@ -3847,7 +3847,7 @@
#define RESTORE_RCV(x) \
*(Class *)x = old;
-static bool
+bool
rb_objc_ary_is_pure(VALUE ary)
{
return *(Class *)ary == NSCFARRAY();
Modified: MacRuby/trunk/encoding.c
===================================================================
--- MacRuby/trunk/encoding.c 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/encoding.c 2008-05-15 22:04:42 UTC (rev 194)
@@ -1409,16 +1409,23 @@
#endif
}
-const char *
-rb_enc_name(rb_encoding *enc)
+VALUE
+rb_enc_name2(rb_encoding *enc)
{
CFStringRef str;
if (enc != NULL
&& (str = CFStringConvertEncodingToIANACharSetName(*enc)) != NULL)
- return RSTRING_CPTR(str);
- return NULL;
+ return str;
+ return Qnil;
}
+const char *
+rb_enc_name(rb_encoding *enc)
+{
+ CFStringRef str = rb_enc_name2(enc);
+ return str == Qnil ? NULL : RSTRING_CPTR(str);
+}
+
long
rb_enc_mbminlen(rb_encoding *enc)
{
Modified: MacRuby/trunk/hash.c
===================================================================
--- MacRuby/trunk/hash.c 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/hash.c 2008-05-15 22:04:42 UTC (rev 194)
@@ -2890,15 +2890,25 @@
#if WITH_OBJC
static Class __nscfdictionary = NULL;
+
+#define NSCFDICTIONARY() \
+ (__nscfdictionary == NULL \
+ ? __nscfdictionary = (Class)objc_getClass("NSCFDictionary") \
+ : __nscfdictionary)
+
#define PREPARE_RCV(x) \
- Class old = *(Class *)x; \
- if (__nscfdictionary == NULL) \
- __nscfdictionary = (Class)objc_getClass("NSCFDictionary"); \
- *(Class *)x = __nscfdictionary;
+ Class old = *(Class *)x; \
+ *(Class *)x = __nscfdictionary;
#define RESTORE_RCV(x) \
- *(Class *)x = old;
+ *(Class *)x = old;
+bool
+rb_objc_hash_is_pure(VALUE ary)
+{
+ return *(Class *)ary == NSCFDICTIONARY();
+}
+
static CFIndex
imp_rb_hash_count(void *rcv, SEL sel)
{
Modified: MacRuby/trunk/include/ruby/encoding.h
===================================================================
--- MacRuby/trunk/include/ruby/encoding.h 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/include/ruby/encoding.h 2008-05-15 22:04:42 UTC (rev 194)
@@ -123,6 +123,7 @@
/* encoding -> name */
#if WITH_OBJC
const char *rb_enc_name(rb_encoding *);
+VALUE rb_enc_name2(rb_encoding *);
#else
#define rb_enc_name(enc) (enc)->name
#endif
Modified: MacRuby/trunk/include/ruby/intern.h
===================================================================
--- MacRuby/trunk/include/ruby/intern.h 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/include/ruby/intern.h 2008-05-15 22:04:42 UTC (rev 194)
@@ -81,7 +81,7 @@
VALUE rb_ary_elt(VALUE, long);
void rb_ary_set_named_args(VALUE, bool);
bool rb_ary_is_named_args(VALUE);
-VALUE rb_ary_clone(VALUE);
+bool rb_objc_ary_is_pure(VALUE);
#endif
/* bignum.c */
VALUE rb_big_clone(VALUE);
@@ -363,7 +363,7 @@
int rb_path_check(const char*);
int rb_env_path_tainted(void);
#if WITH_OBJC
-VALUE rb_hash_clone(VALUE);
+bool rb_objc_hash_is_pure(VALUE);
#endif
/* io.c */
#define rb_defout rb_stdout
@@ -573,6 +573,9 @@
VALUE rb_str_intern(VALUE);
VALUE rb_sym_to_s(VALUE);
VALUE rb_str_length(VALUE);
+#if WITH_OBJC
+bool rb_objc_str_is_pure(VALUE);
+#endif
/* struct.c */
VALUE rb_struct_new(VALUE, ...);
VALUE rb_struct_define(const char*, ...);
Modified: MacRuby/trunk/marshal.c
===================================================================
--- MacRuby/trunk/marshal.c 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/marshal.c 2008-05-15 22:04:42 UTC (rev 194)
@@ -443,18 +443,24 @@
}
static void
+#if WITH_OBJC
+w_uclass(VALUE obj, bool is_pure, struct dump_arg *arg)
+#else
w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
+#endif
{
VALUE klass = CLASS_OF(obj);
w_extended(klass, arg, Qtrue);
klass = rb_class_real(klass);
-#if 0
+#if WITH_OBJC
+ if (!is_pure) {
+#else
if (klass != super) {
+#endif
w_byte(TYPE_UCLASS, arg);
w_unique(RSTRING_CPTR(class2path(klass)), arg);
}
-#endif
}
static int
@@ -471,14 +477,14 @@
{
rb_encoding *enc = 0;
#if WITH_OBJC
- const char *name;
+ VALUE name;
enc = rb_enc_get(obj);
if (enc == NULL) {
w_long(num, arg->arg);
return;
}
- name = rb_enc_name(enc);
+ name = rb_enc_name2(enc);
#else
int encidx = rb_enc_get_index(obj);
st_data_t name;
@@ -694,7 +700,11 @@
break;
case T_STRING:
+#if WITH_OBJC
+ w_uclass(obj, rb_objc_str_is_pure(obj), arg);
+#else
w_uclass(obj, rb_cString, arg);
+#endif
w_byte(TYPE_STRING, arg);
w_bytes(RSTRING_CPTR(obj), RSTRING_CLEN(obj), arg);
break;
@@ -707,7 +717,11 @@
break;
case T_ARRAY:
+#if WITH_OBJC
+ w_uclass(obj, rb_objc_ary_is_pure(obj), arg);
+#else
w_uclass(obj, rb_cArray, arg);
+#endif
w_byte(TYPE_ARRAY, arg);
{
long len = RARRAY_LEN(obj);
@@ -729,9 +743,14 @@
break;
case T_HASH:
+#if WITH_OBJC
+ w_uclass(obj, rb_objc_hash_is_pure(obj), arg);
+#else
w_uclass(obj, rb_cHash, arg);
+#endif
#if WITH_OBJC
w_byte(TYPE_HASH, arg);
+ /* TODO: encode ifnone too */
#else
if (NIL_P(RHASH(obj)->ifnone)) {
w_byte(TYPE_HASH, arg);
@@ -1121,15 +1140,14 @@
while (len--) {
ID id = r_symbol(arg);
VALUE val = r_object(arg);
-#if WITH_OBJC
- if (0) {
-#else
+#if !WITH_OBJC
if (id == rb_id_encoding()) {
-#endif
int idx = rb_enc_find_index(StringValueCStr(val));
if (idx > 0) rb_enc_associate_index(obj, idx);
}
- else {
+ else
+#endif
+ {
rb_ivar_set(obj, id, val);
}
}
@@ -1234,12 +1252,19 @@
format_error:
rb_raise(rb_eArgError, "dump format error (user class)");
}
- if (TYPE(v) == T_MODULE || !RTEST(rb_class_inherited_p(c, RBASIC(v)->klass))) {
- VALUE tmp = rb_obj_alloc(c);
+#if WITH_OBJC
+ if (rb_objc_is_non_native(v)) {
+ *(Class *)v = RCLASS_OCID(c);
+ }
+ else {
+#endif
+ if (TYPE(v) == T_MODULE || !RTEST(rb_class_inherited_p(c, RBASIC(v)->klass))) {
+ VALUE tmp = rb_obj_alloc(c);
- if (TYPE(v) != TYPE(tmp)) goto format_error;
+ if (TYPE(v) != TYPE(tmp)) goto format_error;
+ }
+ RBASIC(v)->klass = c;
}
- RBASIC(v)->klass = c;
}
break;
@@ -1284,7 +1309,7 @@
else {
char *e;
d = strtod(ptr, &e);
- d = load_mantissa(d, e, RSTRING_CLEN(str) - (e - ptr));
+ d = load_mantissa(d, e, strlen(ptr) - (e - ptr));
}
v = DOUBLE2NUM(d);
v = r_entry(v, arg);
Modified: MacRuby/trunk/parse.y
===================================================================
--- MacRuby/trunk/parse.y 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/parse.y 2008-05-15 22:04:42 UTC (rev 194)
@@ -9055,7 +9055,7 @@
if (m < e && is_identchar(m, e, enc)) {
if (!ISASCII(*m)) mb = 1;
#if WITH_OBJC
- m += e-m;
+ m += 1;
#else
m += rb_enc_mbclen(m, e, enc);
#endif
@@ -9160,7 +9160,7 @@
if (m >= e || (*m != '_' && !rb_enc_isalpha(*m, enc) && ISASCII(*m)))
return Qfalse;
#if WITH_OBJC
- while (m < e && is_identchar(m, e, enc)) m += e-m;
+ while (m < e && is_identchar(m, e, enc)) m += 1;
#else
while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
#endif
@@ -9272,7 +9272,6 @@
}
break;
}
-#if !WITH_OBJC
mb = 0;
if (!rb_enc_isdigit(*m, enc)) {
while (m <= name + last && is_identchar(m, e, enc)) {
@@ -9281,11 +9280,16 @@
}
else {
mb = 1;
+#if WITH_OBJC
+ m += 1;
+#else
m += rb_enc_mbclen(m, e, enc);
+#endif
}
}
}
if (m - name < len) id = ID_JUNK;
+#if !WITH_OBJC
if (enc != rb_usascii_encoding()) {
/*
* this clause makes sense only when called from other than
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2008-05-15 19:11:55 UTC (rev 193)
+++ MacRuby/trunk/string.c 2008-05-15 22:04:42 UTC (rev 194)
@@ -2396,7 +2396,7 @@
}
#if WITH_OBJC
-static bool rb_objc_str_is_pure(VALUE);
+bool rb_objc_str_is_pure(VALUE);
#endif
/*
@@ -8253,7 +8253,7 @@
#define RESTORE_RCV(x) \
*(Class *)x = old;
-static bool
+bool
rb_objc_str_is_pure(VALUE str)
{
return *(Class *)str == NSCFSTRING();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080515/af1566ca/attachment-0001.htm
More information about the macruby-changes
mailing list