[macruby-changes] [545] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Sep 3 00:16:12 PDT 2008


Revision: 545
          http://trac.macosforge.org/projects/ruby/changeset/545
Author:   lsansonetti at apple.com
Date:     2008-09-03 00:16:08 -0700 (Wed, 03 Sep 2008)
Log Message:
-----------
fixing many bugs discovered by trying to get rubygems to work

Modified Paths:
--------------
    MacRuby/trunk/class.c
    MacRuby/trunk/ext/zlib/zlib.c
    MacRuby/trunk/insns.def
    MacRuby/trunk/lib/rubygems/remote_fetcher.rb
    MacRuby/trunk/lib/rubygems/specification.rb
    MacRuby/trunk/object.c
    MacRuby/trunk/parse.y
    MacRuby/trunk/proc.c
    MacRuby/trunk/string.c
    MacRuby/trunk/vm_insnhelper.c

Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/class.c	2008-09-03 07:16:08 UTC (rev 545)
@@ -64,6 +64,10 @@
 static BOOL
 rb_obj_imp_isEqual(void *rcv, SEL sel, void *obj)
 {
+    if (*(Class *)rcv == (Class)rb_cFixnum && *(Class *)obj == (Class)rb_cFixnum) {
+	/* XXX check if Numeric#== is not overriden */
+	return RFIXNUM(rcv)->value == RFIXNUM(obj)->value;
+    }
     return rb_funcall((VALUE)rcv, idEq, 1, OC2RB(obj)) == Qtrue;
 }
 

Modified: MacRuby/trunk/ext/zlib/zlib.c
===================================================================
--- MacRuby/trunk/ext/zlib/zlib.c	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/ext/zlib/zlib.c	2008-09-03 07:16:08 UTC (rev 545)
@@ -292,7 +292,7 @@
     }
     else {
 	StringValue(str);
-	sum = func(sum, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
+	sum = func(sum, (Bytef*)RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str));
     }
     return rb_uint2inum(sum);
 }
@@ -398,7 +398,7 @@
 static void
 zlib_mem_free(voidpf opaque, voidpf address)
 {
-    free(address);
+    xfree(address);
 }
 
 static void
@@ -430,19 +430,17 @@
     if (NIL_P(z->buf)) {
 	    /* I uses rb_str_new here not rb_str_buf_new because
 	       rb_str_buf_new makes a zero-length string. */
-	z->buf = rb_str_new(0, ZSTREAM_INITIAL_BUFSIZE);
+	GC_WB(&z->buf, rb_str_new(0, ZSTREAM_INITIAL_BUFSIZE));
 	z->buf_filled = 0;
-	z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+	z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf);
 	z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE;
-#if WITH_OBJC
-	RSTRING_BYTEPTR(z->buf); /* force bytestring creation */
-#else
+#if !WITH_OBJC
 	RBASIC(z->buf)->klass = 0;
 #endif
 	return;
     }
 
-    if (RSTRING_LEN(z->buf) - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
+    if (RSTRING_BYTELEN(z->buf) - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
 	/* to keep other threads from freezing */
 	z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
     }
@@ -455,7 +453,7 @@
 	z->stream.avail_out = (inc < ZSTREAM_AVAIL_OUT_STEP_MAX) ?
 	    inc : ZSTREAM_AVAIL_OUT_STEP_MAX;
     }
-    z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+    z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
 }
 
 static void
@@ -464,15 +462,17 @@
     if (NIL_P(z->buf)) {
 	/* I uses rb_str_new here not rb_str_buf_new because
 	   rb_str_buf_new makes a zero-length string. */
-	z->buf = rb_str_new(0, size);
+	GC_WB(&z->buf, rb_str_new(0, size));
 	z->buf_filled = 0;
-	z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+	z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf);
 	z->stream.avail_out = size;
+#if !WITH_OBJC
 	RBASIC(z->buf)->klass = 0;
+#endif
     }
     else if (z->stream.avail_out != size) {
 	rb_str_resize(z->buf, z->buf_filled + size);
-	z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+	z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
 	z->stream.avail_out = size;
     }
 }
@@ -481,16 +481,19 @@
 zstream_append_buffer(struct zstream *z, const Bytef *src, int len)
 {
     if (NIL_P(z->buf)) {
-	z->buf = rb_str_buf_new(len);
+	GC_WB(&z->buf, rb_str_buf_new(len));
+	RSTRING_BYTEPTR(z->buf); /* create bytestring */
 	rb_str_buf_cat(z->buf, (const char*)src, len);
 	z->buf_filled = len;
-	z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+	z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf);
 	z->stream.avail_out = 0;
+#if !WITH_OBJC
 	RBASIC(z->buf)->klass = 0;
+#endif
 	return;
     }
 
-    if (RSTRING_LEN(z->buf) < z->buf_filled + len) {
+    if (RSTRING_BYTELEN(z->buf) < z->buf_filled + len) {
 	rb_str_resize(z->buf, z->buf_filled + len);
 	z->stream.avail_out = 0;
     }
@@ -502,13 +505,14 @@
 	    z->stream.avail_out = 0;
 	}
     }
-    memcpy(RSTRING_PTR(z->buf) + z->buf_filled, src, len);
+
+    memcpy(RSTRING_BYTEPTR(z->buf) + z->buf_filled, src, len);
     z->buf_filled += len;
-    z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+    z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
 }
 
 #define zstream_append_buffer2(z,v) \
-    zstream_append_buffer((z),(Bytef*)RSTRING_PTR(v),RSTRING_LEN(v))
+    zstream_append_buffer((z),(Bytef*)RSTRING_BYTEPTR(v),RSTRING_BYTELEN(v))
 
 static VALUE
 zstream_detach_buffer(struct zstream *z)
@@ -521,7 +525,11 @@
     else {
 	dst = z->buf;
 	rb_str_resize(dst, z->buf_filled);
+#if WITH_OBJC
+	RSTRING_SYNC(dst);
+#else
 	RBASIC(dst)->klass = rb_cString;
+#endif
     }
 
     z->buf = Qnil;
@@ -541,31 +549,38 @@
     }
 
     dst = rb_str_substr(z->buf, 0, len);
+#if !WITH_OBJC
     RBASIC(dst)->klass = rb_cString;
+#endif
     z->buf_filled -= len;
-    memmove(RSTRING_PTR(z->buf), RSTRING_PTR(z->buf) + len,
+    memmove(RSTRING_BYTEPTR(z->buf), RSTRING_BYTEPTR(z->buf) + len,
 	    z->buf_filled);
-    z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
-    z->stream.avail_out = RSTRING_LEN(z->buf) - z->buf_filled;
+    z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
+    z->stream.avail_out = RSTRING_BYTELEN(z->buf) - z->buf_filled;
     if (z->stream.avail_out > ZSTREAM_AVAIL_OUT_STEP_MAX) {
 	z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
     }
 
+    RSTRING_SYNC(dst);
+
     return dst;
 }
 
 static void
 zstream_buffer_ungetc(struct zstream *z, int c)
 {
-    if (NIL_P(z->buf) || RSTRING_LEN(z->buf) - z->buf_filled == 0) {
+    if (NIL_P(z->buf) || RSTRING_BYTELEN(z->buf) - z->buf_filled == 0) {
 	zstream_expand_buffer(z);
     }
 
 #if WITH_OBJC
-    CFStringInsert((CFMutableStringRef)z->buf, 0, rb_str_new(&c, 1));
+    char buf[2];
+    buf[0] = (char)c;
+    buf[1] = '\0';
+    CFStringInsert((CFMutableStringRef)z->buf, 0, (CFStringRef)rb_str_new2(buf));
 #else
-    memmove(RSTRING_PTR(z->buf) + 1, RSTRING_PTR(z->buf), z->buf_filled);
-    RSTRING_PTR(z->buf)[0] = (char)c;
+    memmove(RSTRING_BYTEPTR(z->buf) + 1, RSTRING_BYTEPTR(z->buf), z->buf_filled);
+    RSTRING_BYTEPTR(z->buf)[0] = (char)c;
 #endif
     z->buf_filled++;
     if (z->stream.avail_out > 0) {
@@ -581,8 +596,11 @@
 
     if (NIL_P(z->input)) {
 	z->input = rb_str_buf_new(len);
+	RSTRING_BYTEPTR(z->input); /* create bytestring */
 	rb_str_buf_cat(z->input, (const char*)src, len);
+#if !WITH_OBJC
 	RBASIC(z->input)->klass = 0;
+#endif
     }
     else {
 	rb_str_buf_cat(z->input, (const char*)src, len);
@@ -590,18 +608,18 @@
 }
 
 #define zstream_append_input2(z,v)\
-    zstream_append_input((z), (Bytef*)RSTRING_PTR(v), RSTRING_LEN(v))
+    zstream_append_input((z), (Bytef*)RSTRING_BYTEPTR(v), RSTRING_BYTELEN(v))
 
 static void
 zstream_discard_input(struct zstream *z, unsigned int len)
 {
-    if (NIL_P(z->input) || RSTRING_LEN(z->input) <= len) {
+    if (NIL_P(z->input) || RSTRING_BYTELEN(z->input) <= len) {
 	z->input = Qnil;
     }
     else {
-	memmove(RSTRING_PTR(z->input), RSTRING_PTR(z->input) + len,
-		RSTRING_LEN(z->input) - len);
-	rb_str_resize(z->input, RSTRING_LEN(z->input) - len);
+	memmove(RSTRING_BYTEPTR(z->input), RSTRING_BYTEPTR(z->input) + len,
+		RSTRING_BYTELEN(z->input) - len);
+	rb_str_resize(z->input, RSTRING_BYTELEN(z->input) - len);
     }
 }
 
@@ -630,10 +648,14 @@
     }
     else {
 	dst = z->input;
+#if !WITH_OBJC
 	RBASIC(dst)->klass = rb_cString;
+#endif
     }
     z->input = Qnil;
+#if !WITH_OBJC
     RBASIC(dst)->klass = rb_cString;
+#endif
     return dst;
 }
 
@@ -690,8 +712,8 @@
     }
     else {
 	zstream_append_input(z, src, len);
-	z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
-	z->stream.avail_in = RSTRING_LEN(z->input);
+	z->stream.next_in = (Bytef*)RSTRING_BYTEPTR(z->input);
+	z->stream.avail_in = RSTRING_BYTELEN(z->input);
 	/* keep reference to `z->input' so as not to be garbage collected
 	   after zstream_reset_input() and prevent `z->stream.next_in'
 	   from dangling. */
@@ -746,12 +768,12 @@
     int err;
 
     if (!NIL_P(z->input)) {
-	z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
-	z->stream.avail_in = RSTRING_LEN(z->input);
+	z->stream.next_in = (Bytef*)RSTRING_BYTEPTR(z->input);
+	z->stream.avail_in = RSTRING_BYTELEN(z->input);
 	err = inflateSync(&z->stream);
 	if (err == Z_OK) {
 	    zstream_discard_input(z,
-				  RSTRING_LEN(z->input) - z->stream.avail_in);
+				  RSTRING_BYTELEN(z->input) - z->stream.avail_in);
 	    zstream_append_input(z, src, len);
 	    return Qtrue;
 	}
@@ -1000,7 +1022,7 @@
 {
     struct zstream *z;
     Data_Get_Struct(obj, struct zstream, z);
-    return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input)));
+    return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_BYTELEN(z->input)));
 }
 
 /*
@@ -1143,7 +1165,7 @@
     struct zstream *z = (struct zstream*)((VALUE*)args)[0];
     VALUE src = ((VALUE*)args)[1];
 
-    zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_FINISH);
+    zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), Z_FINISH);
     return zstream_detach_buffer(z);
 }
 
@@ -1201,8 +1223,8 @@
 	return;
     }
     StringValue(src);
-    if (flush != Z_NO_FLUSH || RSTRING_LEN(src) > 0) { /* prevent BUF_ERROR */
-	zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), flush);
+    if (flush != Z_NO_FLUSH || RSTRING_BYTELEN(src) > 0) { /* prevent BUF_ERROR */
+	zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), flush);
     }
 }
 
@@ -1328,7 +1350,7 @@
     OBJ_INFECT(obj, dic);
     StringValue(src);
     err = deflateSetDictionary(&z->stream,
-			       (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+			       (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src));
     if (err != Z_OK) {
 	raise_zlib_error(err, z->stream.msg);
     }
@@ -1388,7 +1410,7 @@
     struct zstream *z = (struct zstream*)((VALUE*)args)[0];
     VALUE src = ((VALUE*)args)[1];
 
-    zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
+    zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), Z_SYNC_FLUSH);
     zstream_run(z, (Bytef*)"", 0, Z_FINISH);  /* for checking errors */
     return zstream_detach_buffer(z);
 }
@@ -1413,21 +1435,23 @@
 static VALUE
 rb_inflate_s_inflate(VALUE obj, VALUE src)
 {
-    struct zstream z;
+    struct zstream *z;
     VALUE dst, args[2];
     int err;
 
+    z = (struct zstream *)xmalloc(sizeof(struct zstream));
+
     StringValue(src);
-    zstream_init_inflate(&z);
-    err = inflateInit(&z.stream);
+    zstream_init_inflate(z);
+    err = inflateInit(&z->stream);
     if (err != Z_OK) {
-	raise_zlib_error(err, z.stream.msg);
+	raise_zlib_error(err, z->stream.msg);
     }
-    ZSTREAM_READY(&z);
+    ZSTREAM_READY(z);
 
-    args[0] = (VALUE)&z;
+    args[0] = (VALUE)z;
     args[1] = src;
-    dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z);
+    dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)z);
 
     OBJ_INFECT(dst, src);
     return dst;
@@ -1441,8 +1465,8 @@
 	return;
     }
     StringValue(src);
-    if (RSTRING_LEN(src) > 0) { /* prevent Z_BUF_ERROR */
-	zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
+    if (RSTRING_BYTELEN(src) > 0) { /* prevent Z_BUF_ERROR */
+	zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), Z_SYNC_FLUSH);
     }
 }
 
@@ -1535,7 +1559,7 @@
 
     OBJ_INFECT(obj, src);
     StringValue(src);
-    return zstream_sync(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+    return zstream_sync(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src));
 }
 
 /*
@@ -1577,7 +1601,7 @@
     OBJ_INFECT(obj, dic);
     StringValue(src);
     err = inflateSetDictionary(&z->stream,
-			       (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+			       (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src));
     if (err != Z_OK) {
 	raise_zlib_error(err, z->stream.msg);
     }
@@ -1789,7 +1813,7 @@
 {
     VALUE str;
 
-    while (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size) {
+    while (NIL_P(gz->z.input) || RSTRING_BYTELEN(gz->z.input) < size) {
 	str = gzfile_read_raw(gz);
 	if (NIL_P(str)) return Qfalse;
 	zstream_append_input2(&gz->z, str);
@@ -1804,14 +1828,14 @@
     char *p;
 
     for (;;) {
-	p = memchr(RSTRING_PTR(gz->z.input) + offset, '\0',
-		   RSTRING_LEN(gz->z.input) - offset);
+	p = memchr(RSTRING_BYTEPTR(gz->z.input) + offset, '\0',
+		   RSTRING_BYTELEN(gz->z.input) - offset);
 	if (p) break;
 	str = gzfile_read_raw(gz);
 	if (NIL_P(str)) {
 	    rb_raise(cGzError, "unexpected end of file");
 	}
-	offset = RSTRING_LEN(gz->z.input);
+	offset = RSTRING_BYTELEN(gz->z.input);
 	zstream_append_input2(&gz->z, str);
     }
     return p;
@@ -1912,7 +1936,7 @@
 	rb_raise(cGzError, "not in gzip format");
     }
 
-    head = (unsigned char*)RSTRING_PTR(gz->z.input);
+    head = (unsigned char*)RSTRING_BYTEPTR(gz->z.input);
 
     if (head[0] != GZ_MAGIC1 || head[1] != GZ_MAGIC2) {
 	rb_raise(cGzError, "not in gzip format");
@@ -1950,7 +1974,7 @@
 	if (!gzfile_read_raw_ensure(gz, 2)) {
 	    rb_raise(cGzError, "unexpected end of file");
 	}
-	len = gzfile_get16((Bytef*)RSTRING_PTR(gz->z.input));
+	len = gzfile_get16((Bytef*)RSTRING_BYTEPTR(gz->z.input));
 	if (!gzfile_read_raw_ensure(gz, 2 + len)) {
 	    rb_raise(cGzError, "unexpected end of file");
 	}
@@ -1958,20 +1982,20 @@
     }
     if (flags & GZ_FLAG_ORIG_NAME) {
 	p = gzfile_read_raw_until_zero(gz, 0);
-	len = p - RSTRING_PTR(gz->z.input);
-	gz->orig_name = rb_str_new(RSTRING_PTR(gz->z.input), len);
+	len = p - RSTRING_BYTEPTR(gz->z.input);
+	gz->orig_name = rb_str_new(RSTRING_BYTEPTR(gz->z.input), len);
 	OBJ_TAINT(gz->orig_name);  /* for safe */
 	zstream_discard_input(&gz->z, len + 1);
     }
     if (flags & GZ_FLAG_COMMENT) {
 	p = gzfile_read_raw_until_zero(gz, 0);
-	len = p - RSTRING_PTR(gz->z.input);
-	gz->comment = rb_str_new(RSTRING_PTR(gz->z.input), len);
+	len = p - RSTRING_BYTEPTR(gz->z.input);
+	gz->comment = rb_str_new(RSTRING_BYTEPTR(gz->z.input), len);
 	OBJ_TAINT(gz->comment);  /* for safe */
 	zstream_discard_input(&gz->z, len + 1);
     }
 
-    if (gz->z.input != Qnil && RSTRING_LEN(gz->z.input) > 0) {
+    if (gz->z.input != Qnil && RSTRING_BYTELEN(gz->z.input) > 0) {
 	zstream_run(&gz->z, 0, 0, Z_SYNC_FLUSH);
     }
 }
@@ -1987,8 +2011,8 @@
 	rb_raise(cNoFooter, "footer is not found");
     }
 
-    crc = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input));
-    length = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input) + 4);
+    crc = gzfile_get32((Bytef*)RSTRING_BYTEPTR(gz->z.input));
+    length = gzfile_get32((Bytef*)RSTRING_BYTEPTR(gz->z.input) + 4);
 
     gz->z.stream.total_in += 8;  /* to rewind correctly */
     zstream_discard_input(&gz->z, 8);
@@ -2029,8 +2053,8 @@
 	    }
 	    break;
 	}
-	if (RSTRING_LEN(str) > 0) { /* prevent Z_BUF_ERROR */
-	    zstream_run(&gz->z, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str),
+	if (RSTRING_BYTELEN(str) > 0) { /* prevent Z_BUF_ERROR */
+	    zstream_run(&gz->z, (Bytef*)RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str),
 			Z_SYNC_FLUSH);
 	}
 	if (gz->z.buf_filled > 0) break;
@@ -2041,12 +2065,12 @@
 static void
 gzfile_calc_crc(struct gzfile *gz, VALUE str)
 {
-    if (RSTRING_LEN(str) <= gz->ungetc) {
-	gz->ungetc -= RSTRING_LEN(str);
+    if (RSTRING_BYTELEN(str) <= gz->ungetc) {
+	gz->ungetc -= RSTRING_BYTELEN(str);
     }
     else {
-	gz->crc = crc32(gz->crc, (Bytef*)RSTRING_PTR(str) + gz->ungetc,
-			RSTRING_LEN(str) - gz->ungetc);
+	gz->crc = crc32(gz->crc, (Bytef*)RSTRING_BYTEPTR(str) + gz->ungetc,
+			RSTRING_BYTELEN(str) - gz->ungetc);
 	gz->ungetc = 0;
     }
 }
@@ -2116,8 +2140,8 @@
         return dst;
     }
     else {
-        rb_str_resize(outbuf, RSTRING_LEN(dst));
-        memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
+        rb_str_resize(outbuf, RSTRING_BYTELEN(dst));
+        memcpy(RSTRING_BYTEPTR(outbuf), RSTRING_BYTEPTR(dst), RSTRING_BYTELEN(dst));
         return outbuf;
     }
 }
@@ -2205,7 +2229,7 @@
 
     n = gz->z.stream.total_in;
     if (!NIL_P(gz->z.input)) {
-	n += RSTRING_LEN(gz->z.input);
+	n += RSTRING_BYTELEN(gz->z.input);
     }
 
     rb_funcall(gz->io, id_seek, 2, rb_int2inum(-n), INT2FIX(1));
@@ -2296,7 +2320,7 @@
     }
     filename = argv[0];
     FilePathValue(filename);
-    io = rb_file_open(RSTRING_PTR(filename), mode);
+    io = rb_file_open(RSTRING_BYTEPTR(filename), mode);
 
     argv[0] = io;
     return rb_gzfile_s_wrap(argc, argv, klass);
@@ -2434,9 +2458,9 @@
 	rb_raise(cGzError, "header is already written");
     }
     s = rb_str_dup(rb_str_to_str(str));
-    p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
+    p = memchr(RSTRING_BYTEPTR(s), '\0', RSTRING_BYTELEN(s));
     if (p) {
-	rb_str_resize(s, p - RSTRING_PTR(s));
+	rb_str_resize(s, p - RSTRING_BYTEPTR(s));
     }
     gz->orig_name = s;
     return str;
@@ -2456,9 +2480,9 @@
 	rb_raise(cGzError, "header is already written");
     }
     s = rb_str_dup(rb_str_to_str(str));
-    p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
+    p = memchr(RSTRING_BYTEPTR(s), '\0', RSTRING_BYTELEN(s));
     if (p) {
-	rb_str_resize(s, p - RSTRING_PTR(s));
+	rb_str_resize(s, p - RSTRING_BYTEPTR(s));
     }
     gz->comment = s;
     return str;
@@ -2684,8 +2708,8 @@
     if (TYPE(str) != T_STRING) {
 	str = rb_obj_as_string(str);
     }
-    gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
-    return INT2FIX(RSTRING_LEN(str));
+    gzfile_write(gz, (Bytef*)RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str));
+    return INT2FIX(RSTRING_BYTELEN(str));
 }
 
 /*
@@ -2916,7 +2940,7 @@
 
     dst = gzfile_read(gz, 1);
     if (!NIL_P(dst)) {
-	dst = INT2FIX((unsigned int)(RSTRING_PTR(dst)[0]) & 0xff);
+	dst = INT2FIX((unsigned int)(RSTRING_BYTEPTR(dst)[0]) & 0xff);
     }
     return dst;
 }
@@ -2974,7 +2998,7 @@
 	gzfile_read_more(gz);
     }
     n = 0;
-    p = RSTRING_PTR(gz->z.buf);
+    p = RSTRING_BYTEPTR(gz->z.buf);
 
     while (n++, *(p++) == '\n') {
 	if (n >= gz->z.buf_filled) {
@@ -2985,7 +3009,7 @@
 		gzfile_read_more(gz);
 	    }
 	    n = 0;
-	    p = RSTRING_PTR(gz->z.buf);
+	    p = RSTRING_BYTEPTR(gz->z.buf);
 	}
     }
 
@@ -2996,7 +3020,7 @@
 static void
 rscheck(const char *rsptr, long rslen, VALUE rs)
 {
-    if (RSTRING_PTR(rs) != rsptr && RSTRING_LEN(rs) != rslen)
+    if (RSTRING_BYTEPTR(rs) != rsptr && RSTRING_BYTELEN(rs) != rslen)
 	rb_raise(rb_eRuntimeError, "rs modified");
 }
 
@@ -3023,19 +3047,19 @@
 
     if (NIL_P(rs)) {
 	dst = gzfile_read_all(gz);
-	if (RSTRING_LEN(dst) != 0) gz->lineno++;
+	if (RSTRING_BYTELEN(dst) != 0) gz->lineno++;
 	else
 	    return Qnil;
 	return dst;
     }
 
-    if (RSTRING_LEN(rs) == 0) {
+    if (RSTRING_BYTELEN(rs) == 0) {
 	rsptr = "\n\n";
 	rslen = 2;
 	rspara = 1;
     } else {
-	rsptr = RSTRING_PTR(rs);
-	rslen = RSTRING_LEN(rs);
+	rsptr = RSTRING_BYTEPTR(rs);
+	rslen = RSTRING_BYTELEN(rs);
 	rspara = 0;
     }
 
@@ -3051,13 +3075,13 @@
 	gzfile_read_more(gz);
     }
 
-    p = RSTRING_PTR(gz->z.buf);
+    p = RSTRING_BYTEPTR(gz->z.buf);
     n = rslen;
     for (;;) {
 	if (n > gz->z.buf_filled) {
 	    if (ZSTREAM_IS_FINISHED(&gz->z)) break;
 	    gzfile_read_more(gz);
-	    p = RSTRING_PTR(gz->z.buf) + n - rslen;
+	    p = RSTRING_BYTEPTR(gz->z.buf) + n - rslen;
 	}
 	if (!rspara) rscheck(rsptr, rslen, rs);
 	res = memchr(p, rsptr[0], (gz->z.buf_filled - n + 1));

Modified: MacRuby/trunk/insns.def
===================================================================
--- MacRuby/trunk/insns.def	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/insns.def	2008-09-03 07:16:08 UTC (rev 545)
@@ -402,12 +402,15 @@
     VALUE rb_reg_new_ary(VALUE ary, int options);
     int i;
     const VALUE ary = rb_ary_new2(cnt);
+#if !WITH_OBJC
     RBASIC(ary)->klass = 0;
+#endif
     for (i = 0; i < cnt; i++) {
         rb_ary_store(ary, cnt-i-1, TOPN(i));
     }
     POPN(cnt);
     val = rb_reg_new_ary(ary, opt);
+    rb_objc_retain((void *)val);
 }
 
 /**
@@ -1417,14 +1420,14 @@
 #endif
 
 #if 1
-	else if (HEAP_CLASS_OF(recv) == rb_cString &&
-		 HEAP_CLASS_OF(obj) == rb_cString &&
+	else if (HEAP_CLASS_OF(recv) == rb_cCFString &&
+		 HEAP_CLASS_OF(obj) == rb_cCFString &&
 		 BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
 	    val = rb_str_plus(recv, obj);
 	}
 #endif
 #if 1
-	else if (HEAP_CLASS_OF(recv) == rb_cArray &&
+	else if (HEAP_CLASS_OF(recv) == rb_cCFArray &&
 		 BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
 	    val = rb_ary_plus(recv, obj);
 	}
@@ -1854,11 +1857,11 @@
     if (!SPECIAL_CONST_P(recv)) {
 	if (0) {
 	}
-	else if (HEAP_CLASS_OF(recv) == rb_cString &&
+	else if (HEAP_CLASS_OF(recv) == rb_cCFString &&
 		 BASIC_OP_UNREDEFINED_P(BOP_LTLT)) {
 	    val = rb_str_concat(recv, obj);
 	}
-	else if (HEAP_CLASS_OF(recv) == rb_cArray &&
+	else if (HEAP_CLASS_OF(recv) == rb_cCFArray &&
 		 BASIC_OP_UNREDEFINED_P(BOP_LTLT)) {
 	    val = rb_ary_push(recv, obj);
 	}
@@ -1951,13 +1954,13 @@
 {
     if (!SPECIAL_CONST_P(recv) &&
 	BASIC_OP_UNREDEFINED_P(BOP_LENGTH)) {
-	if (HEAP_CLASS_OF(recv) == rb_cString) {
+	if (HEAP_CLASS_OF(recv) == rb_cCFString) {
 	    val = rb_str_length(recv);
 	}
-	else if (HEAP_CLASS_OF(recv) == rb_cArray) {
+	else if (HEAP_CLASS_OF(recv) == rb_cCFArray) {
 	    val = LONG2NUM(RARRAY_LEN(recv));
 	}
-	else if (HEAP_CLASS_OF(recv) == rb_cHash) {
+	else if (HEAP_CLASS_OF(recv) == rb_cCFHash) {
 	    val = INT2FIX(RHASH_SIZE(recv));
 	}
 	else {
@@ -1998,7 +2001,7 @@
 	}
     }
     else {
-	if (HEAP_CLASS_OF(recv) == rb_cString &&
+	if (HEAP_CLASS_OF(recv) == rb_cCFString &&
 	    BASIC_OP_UNREDEFINED_P(BOP_SUCC)) {
 	    val = rb_str_succ(recv);
 	}

Modified: MacRuby/trunk/lib/rubygems/remote_fetcher.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/remote_fetcher.rb	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/lib/rubygems/remote_fetcher.rb	2008-09-03 07:16:08 UTC (rev 545)
@@ -196,6 +196,19 @@
   # Read the data from the (source based) URI, but if it is a file:// URI,
   # read from the filesystem instead.
   def open_uri_or_path(uri, depth = 0, &block)
+    if RUBY_ENGINE == 'macruby'
+      # XXX we are taking a _much faster_ code path here, this change should be
+      # removed once we re-implement the IO subsystem (and therefore Net::HTTP)
+      # on top of CF.
+      url = NSURL.URLWithString(uri.to_s)
+      data = NSMutableData.dataWithContentsOfURL(url)
+      if data.nil?
+	raise Gem::RemoteFetcher::FetchError, "error when fetching data from #{uri}"
+      end
+      string = String.__new_bytestring__(data)
+      #block.call(string) if block
+      return string
+    end
     if file_uri?(uri)
       open(get_file_uri_path(uri), &block)
     else

Modified: MacRuby/trunk/lib/rubygems/specification.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/specification.rb	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/lib/rubygems/specification.rb	2008-09-03 07:16:08 UTC (rev 545)
@@ -267,9 +267,10 @@
 
       field_count = MARSHAL_FIELDS[spec.specification_version]
 
-      if field_count.nil? or array.size < field_count then
-        raise TypeError, "invalid Gem::Specification format #{array.inspect}"
-      end
+      # XXX sync this file with the upstream version!
+      #if field_count.nil? or array.size < field_count then
+      #  raise TypeError, "invalid Gem::Specification format #{array.inspect}"
+      #end
 
       spec.instance_variable_set :@rubygems_version,          array[0]
       # spec version

Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/object.c	2008-09-03 07:16:08 UTC (rev 545)
@@ -538,8 +538,20 @@
     }
 
     while (cl) {
-	if (cl == c) // TODO check included modules
+	VALUE ary;
+	if (cl == c) {
 	    return Qtrue;
+	}
+	ary = rb_attr_get(cl, idIncludedModules);
+	if (ary != Qnil) {
+	    int i, count;
+	    for (i = 0, count = RARRAY_LEN(ary); i < count; i++) {
+		VALUE imod = RARRAY_AT(ary, i);
+		if (imod == c) {
+		    return Qtrue;
+		}
+	    }
+	}
 	cl = RCLASS_SUPER(cl);
     }
     return Qfalse;

Modified: MacRuby/trunk/parse.y
===================================================================
--- MacRuby/trunk/parse.y	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/parse.y	2008-09-03 07:16:08 UTC (rev 545)
@@ -8980,6 +8980,7 @@
     reg_fragment_setenc(str, options);
     err = rb_errinfo();
     re = rb_reg_compile(str, options & RE_OPTION_MASK);
+    rb_objc_retain((void *)re);
     if (NIL_P(re)) {
 	ID mesg = rb_intern("mesg");
 	VALUE m = rb_attr_get(rb_errinfo(), mesg);

Modified: MacRuby/trunk/proc.c
===================================================================
--- MacRuby/trunk/proc.c	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/proc.c	2008-09-03 07:16:08 UTC (rev 545)
@@ -764,7 +764,7 @@
 	klass = RBASIC(klass)->klass;
     method = Data_Make_Struct(mclass, struct METHOD, bm_mark, -1, data);
     data->oclass = klass;
-    data->recv = obj;
+    GC_WB(&data->recv, obj);
 
     data->id = id;
     data->body = body;
@@ -1315,7 +1315,7 @@
 
     method = Data_Make_Struct(rb_cMethod, struct METHOD, bm_mark, xfree, bound);
     *bound = *data;
-    bound->recv = recv;
+    GC_WB(&bound->recv, recv);
     bound->rclass = CLASS_OF(recv);
 
     return method;

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/string.c	2008-09-03 07:16:08 UTC (rev 545)
@@ -178,6 +178,14 @@
     return (VALUE)str;
 }
 
+static VALUE
+rb_str_new_bytestring_m(VALUE rcv, VALUE data)
+{
+    VALUE str = str_alloc(0);
+    rb_str_cfdata_set(str, (void *)data);
+    return str;
+}
+
 static void
 rb_objc_str_set_bytestring(VALUE str, const char *dataptr, long datalen)
 {
@@ -5258,6 +5266,8 @@
     rb_cNSMutableString = (VALUE)objc_getClass("NSMutableString");
     rb_const_set(rb_cObject, rb_intern("String"), rb_cNSMutableString);
     rb_set_class_path(rb_cNSMutableString, rb_cObject, "NSMutableString");
+
+    rb_define_singleton_method(rb_cString, "__new_bytestring__", rb_str_new_bytestring_m, 1);
     rb_define_method(rb_cString, "__bytestring__?", rb_str_bytestring_m, 0);
 
     rb_include_module(rb_cString, rb_mComparable);

Modified: MacRuby/trunk/vm_insnhelper.c
===================================================================
--- MacRuby/trunk/vm_insnhelper.c	2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/vm_insnhelper.c	2008-09-03 07:16:08 UTC (rev 545)
@@ -1791,8 +1791,8 @@
 		val = Qfalse;
 	    }
 	}
-	else if (HEAP_CLASS_OF(recv) == rb_cString &&
-		 HEAP_CLASS_OF(obj) == rb_cString &&
+	else if (HEAP_CLASS_OF(recv) == rb_cCFString &&
+		 HEAP_CLASS_OF(obj) == rb_cCFString &&
 		 BASIC_OP_UNREDEFINED_P(BOP_EQ)) {
 	    val = rb_str_equal(recv, obj);
 	}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080903/2e9694fa/attachment-0001.html 


More information about the macruby-changes mailing list