[macruby-changes] [3716] MacRuby/branches/icu
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 9 15:03:44 PST 2010
Revision: 3716
http://trac.macosforge.org/projects/ruby/changeset/3716
Author: lsansonetti at apple.com
Date: 2010-03-09 15:03:42 -0800 (Tue, 09 Mar 2010)
Log Message:
-----------
expose the bstr APIs
Modified Paths:
--------------
MacRuby/branches/icu/encoding.h
MacRuby/branches/icu/include/ruby/intern.h
MacRuby/branches/icu/io.c
MacRuby/branches/icu/marshal.c
MacRuby/branches/icu/pack.c
MacRuby/branches/icu/random.c
MacRuby/branches/icu/ruby.c
MacRuby/branches/icu/string.c
MacRuby/branches/icu/time.c
Modified: MacRuby/branches/icu/encoding.h
===================================================================
--- MacRuby/branches/icu/encoding.h 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/encoding.h 2010-03-09 23:03:42 UTC (rev 3716)
@@ -306,19 +306,6 @@
long rb_uchar_strtol(UniChar *chars, long chars_len, long pos,
long *end_offset);
-// Return a string object appropriate for bstr_ calls. This does nothing for
-// data/binary RubyStrings.
-VALUE rb_str_bstr(VALUE str);
-
-// Byte strings APIs. Use this only when dealing with raw data.
-VALUE bstr_new(void);
-VALUE bstr_new_with_data(const uint8_t *bytes, long len);
-uint8_t *bstr_bytes(VALUE str);
-void bstr_concat(VALUE str, const uint8_t *bytes, long len);
-long bstr_length(VALUE str);
-void bstr_set_length(VALUE str, long len);
-void bstr_resize(VALUE str, long capa);
-
#if defined(__cplusplus)
} // extern "C"
#endif
Modified: MacRuby/branches/icu/include/ruby/intern.h
===================================================================
--- MacRuby/branches/icu/include/ruby/intern.h 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/include/ruby/intern.h 2010-03-09 23:03:42 UTC (rev 3716)
@@ -606,6 +606,20 @@
#if WITH_OBJC
bool rb_objc_str_is_pure(VALUE);
#endif
+
+// Return a string object appropriate for bstr_ calls. This does nothing for
+// data/binary RubyStrings.
+VALUE rb_str_bstr(VALUE str);
+
+// Byte strings APIs. Use this only when dealing with raw data.
+VALUE rb_bstr_new(void);
+VALUE rb_bstr_new_with_data(const uint8_t *bytes, long len);
+uint8_t *rb_bstr_bytes(VALUE str);
+void rb_bstr_concat(VALUE str, const uint8_t *bytes, long len);
+long rb_bstr_length(VALUE str);
+void rb_bstr_set_length(VALUE str, long len);
+void rb_bstr_resize(VALUE str, long capa);
+
/* struct.c */
VALUE rb_struct_new(VALUE, ...);
VALUE rb_struct_define(const char*, ...);
Modified: MacRuby/branches/icu/io.c
===================================================================
--- MacRuby/branches/icu/io.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/io.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -424,8 +424,8 @@
data = rb_obj_as_string(data);
data = rb_str_bstr(data);
- const uint8_t *buffer = bstr_bytes(data);
- const long length = bstr_length(data);
+ const uint8_t *buffer = rb_bstr_bytes(data);
+ const long length = rb_bstr_length(data);
if (length == 0) {
return INT2FIX(0);
@@ -988,11 +988,11 @@
const long BUFSIZE = 512;
long bytes_read = 0;
- const long original_position = bstr_length(outbuf);
+ const long original_position = rb_bstr_length(outbuf);
while (true) {
- bstr_resize(outbuf, original_position + bytes_read + BUFSIZE);
- uint8_t *bytes = bstr_bytes(outbuf) + original_position + bytes_read;
+ rb_bstr_resize(outbuf, original_position + bytes_read + BUFSIZE);
+ uint8_t *bytes = rb_bstr_bytes(outbuf) + original_position + bytes_read;
const long last_read = rb_io_read_internal(io_struct, bytes, BUFSIZE);
bytes_read += last_read;
if (last_read == 0) {
@@ -1000,7 +1000,7 @@
}
}
- bstr_set_length(outbuf, original_position + bytes_read);
+ rb_bstr_set_length(outbuf, original_position + bytes_read);
return outbuf;
}
@@ -1119,7 +1119,7 @@
rb_io_assert_readable(io_struct);
if (NIL_P(outbuf)) {
- outbuf = bstr_new();
+ outbuf = rb_bstr_new();
}
if (NIL_P(len)) {
@@ -1139,14 +1139,14 @@
}
outbuf = rb_str_bstr(outbuf);
- bstr_resize(outbuf, size);
- uint8_t *bytes = bstr_bytes(outbuf);
+ rb_bstr_resize(outbuf, size);
+ uint8_t *bytes = rb_bstr_bytes(outbuf);
const long data_read = rb_io_read_internal(io_struct, bytes, size);
if (data_read == 0) {
return Qnil;
}
- bstr_set_length(outbuf, data_read);
+ rb_bstr_set_length(outbuf, data_read);
return outbuf;
}
@@ -1281,10 +1281,10 @@
}
const long line_limit = NIL_P(limit) ? -1 : FIX2LONG(limit);
- VALUE bstr = bstr_new();
+ VALUE bstr = rb_bstr_new();
if (line_limit != -1) {
- bstr_resize(bstr, line_limit);
- uint8_t *bytes = bstr_bytes(bstr);
+ rb_bstr_resize(bstr, line_limit);
+ uint8_t *bytes = rb_bstr_bytes(bstr);
rb_io_read_internal(io_struct, bytes, line_limit);
#if 0 // TODO
CFRange r = CFStringFind((CFStringRef)bstr, (CFStringRef)sep, 0);
@@ -1334,9 +1334,9 @@
// Read from IO (slow).
long s = 512;
long data_read = 0;
- bstr_resize(bstr, s);
+ rb_bstr_resize(bstr, s);
- uint8_t *buf = bstr_bytes(bstr);
+ uint8_t *buf = rb_bstr_bytes(bstr);
uint8_t *tmp_buf = (uint8_t *)malloc(seplen);
while (true) {
if (rb_io_read_internal(io_struct, tmp_buf, seplen) != seplen) {
@@ -1344,8 +1344,8 @@
}
if (data_read >= s) {
s += s;
- bstr_resize(bstr, s);
- buf = bstr_bytes(bstr);
+ rb_bstr_resize(bstr, s);
+ buf = rb_bstr_bytes(bstr);
}
memcpy(&buf[data_read], tmp_buf, seplen);
data_read += seplen;
@@ -1359,7 +1359,7 @@
if (data_read == 0) {
return Qnil;
}
- bstr_set_length(bstr, data_read);
+ rb_bstr_set_length(bstr, data_read);
}
}
OBJ_TAINT(bstr);
@@ -3343,7 +3343,7 @@
io_s->pid = -1;
}
- VALUE outbuf = bstr_new();
+ VALUE outbuf = rb_bstr_new();
rb_io_read_all(ExtractIOStruct(io), outbuf);
rb_io_close(io);
@@ -3840,8 +3840,8 @@
}
outbuf = rb_str_bstr(outbuf);
- uint8_t *bytes = bstr_bytes(outbuf);
- const long length = bstr_length(outbuf);
+ uint8_t *bytes = rb_bstr_bytes(outbuf);
+ const long length = rb_bstr_length(outbuf);
VALUE ary = rb_ary_new();
@@ -3852,7 +3852,7 @@
void *ptr;
while ((ptr = memchr(&bytes[pos], byte, length - pos)) != NULL) {
const long s = (long)ptr - (long)&bytes[pos] + 1;
- rb_ary_push(ary, bstr_new_with_data(&bytes[pos], s));
+ rb_ary_push(ary, rb_bstr_new_with_data(&bytes[pos], s));
pos += s;
}
}
Modified: MacRuby/branches/icu/marshal.c
===================================================================
--- MacRuby/branches/icu/marshal.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/marshal.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -219,7 +219,7 @@
w_nbyte(const char *s, int n, struct dump_arg *arg)
{
VALUE buf = arg->str;
- bstr_concat(buf, (const uint8_t *)s, n);
+ rb_bstr_concat(buf, (const uint8_t *)s, n);
if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) {
if (arg->taint) OBJ_TAINT(buf);
rb_io_write(arg->dest, 0, buf);
@@ -898,7 +898,7 @@
w_object(arg->obj, arg->arg, arg->limit);
if (arg->arg->dest) {
rb_io_write(arg->arg->dest, 0, arg->arg->str);
- bstr_resize(arg->arg->str, 0);
+ rb_bstr_resize(arg->arg->str, 0);
}
return 0;
}
@@ -982,14 +982,14 @@
type_error:
rb_raise(rb_eTypeError, "instance of IO needed");
}
- GC_WB(&arg->str, bstr_new());
+ GC_WB(&arg->str, rb_bstr_new());
GC_WB(&arg->dest, port);
if (rb_obj_respond_to(port, s_binmode, Qtrue)) {
rb_funcall2(port, s_binmode, 0, 0);
}
}
else {
- port = bstr_new();
+ port = rb_bstr_new();
GC_WB(&arg->str, port);
}
@@ -1121,9 +1121,9 @@
}
if (TYPE(arg->src) == T_STRING) {
if (RSTRING_LEN(arg->src) - arg->offset >= len) {
- str = bstr_new();
- bstr_resize(str, len + 1);
- uint8_t *data = bstr_bytes(str);
+ str = rb_bstr_new();
+ rb_bstr_resize(str, len + 1);
+ uint8_t *data = rb_bstr_bytes(str);
memcpy(data, (UInt8 *)RSTRING_PTR(arg->src) + arg->offset, len);
data[len] = '\0';
arg->offset += len;
Modified: MacRuby/branches/icu/pack.c
===================================================================
--- MacRuby/branches/icu/pack.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/pack.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -454,7 +454,7 @@
p = RSTRING_PTR(fmt);
pend = p + RSTRING_LEN(fmt);
- VALUE data = bstr_new();
+ VALUE data = rb_bstr_new();
items = RARRAY_LEN(ary);
idx = 0;
@@ -530,19 +530,19 @@
case 'A': /* arbitrary binary string (ASCII space padded) */
case 'Z': /* null terminated string */
if (plen >= len) {
- bstr_concat(data, (const UInt8 *)ptr, len);
+ rb_bstr_concat(data, (const UInt8 *)ptr, len);
if (p[-1] == '*' && type == 'Z') {
- bstr_concat(data, (const UInt8 *)nul10, 1);
+ rb_bstr_concat(data, (const UInt8 *)nul10, 1);
}
}
else {
- bstr_concat(data, (const UInt8 *)ptr, plen);
+ rb_bstr_concat(data, (const UInt8 *)ptr, plen);
len -= plen;
while (len >= 10) {
- bstr_concat(data, (const UInt8 *)((type == 'A')?spc10:nul10), 10);
+ rb_bstr_concat(data, (const UInt8 *)((type == 'A')?spc10:nul10), 10);
len -= 10;
}
- bstr_concat(data, (const UInt8 *)((type == 'A')?spc10:nul10), len);
+ rb_bstr_concat(data, (const UInt8 *)((type == 'A')?spc10:nul10), len);
}
break;
@@ -562,7 +562,7 @@
byte >>= 1;
else {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
byte = 0;
}
}
@@ -570,7 +570,7 @@
char c;
byte >>= 7 - (len & 7);
c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
}
len = j;
goto grow;
@@ -592,7 +592,7 @@
byte <<= 1;
else {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
byte = 0;
}
}
@@ -600,7 +600,7 @@
char c;
byte <<= 7 - (len & 7);
c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
}
len = j;
goto grow;
@@ -625,13 +625,13 @@
byte >>= 4;
else {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
byte = 0;
}
}
if (len & 1) {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
}
len = j;
goto grow;
@@ -656,13 +656,13 @@
byte <<= 4;
else {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
byte = 0;
}
}
if (len & 1) {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
}
len = j;
goto grow;
@@ -678,7 +678,7 @@
from = NEXTFROM;
c = num2i32(from);
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
}
break;
@@ -689,7 +689,7 @@
from = NEXTFROM;
s = num2i32(from);
- bstr_concat(data, (const UInt8 *)OFF16(&s), NATINT_LEN(short,2));
+ rb_bstr_concat(data, (const UInt8 *)OFF16(&s), NATINT_LEN(short,2));
}
break;
@@ -700,7 +700,7 @@
from = NEXTFROM;
i = num2i32(from);
- bstr_concat(data, (const UInt8 *)OFF32(&i), NATINT_LEN(int,4));
+ rb_bstr_concat(data, (const UInt8 *)OFF32(&i), NATINT_LEN(int,4));
}
break;
@@ -711,7 +711,7 @@
from = NEXTFROM;
l = num2i32(from);
- bstr_concat(data, (const UInt8 *)OFF32(&l), NATINT_LEN(long,4));
+ rb_bstr_concat(data, (const UInt8 *)OFF32(&l), NATINT_LEN(long,4));
}
break;
@@ -722,7 +722,7 @@
from = NEXTFROM;
rb_quad_pack(tmp, from);
- bstr_concat(data, (const UInt8 *)&tmp, QUAD_SIZE);
+ rb_bstr_concat(data, (const UInt8 *)&tmp, QUAD_SIZE);
}
break;
@@ -733,7 +733,7 @@
from = NEXTFROM;
s = num2i32(from);
s = NATINT_HTONS(s);
- bstr_concat(data, (const UInt8 *)OFF16(&s), NATINT_LEN(short,2));
+ rb_bstr_concat(data, (const UInt8 *)OFF16(&s), NATINT_LEN(short,2));
}
break;
@@ -744,7 +744,7 @@
from = NEXTFROM;
l = num2i32(from);
l = NATINT_HTONL(l);
- bstr_concat(data, (const UInt8 *)OFF32(&l), NATINT_LEN(long,4));
+ rb_bstr_concat(data, (const UInt8 *)OFF32(&l), NATINT_LEN(long,4));
}
break;
@@ -755,7 +755,7 @@
from = NEXTFROM;
s = num2i32(from);
s = NATINT_HTOVS(s);
- bstr_concat(data, (const UInt8 *)OFF16(&s), NATINT_LEN(short,2));
+ rb_bstr_concat(data, (const UInt8 *)OFF16(&s), NATINT_LEN(short,2));
}
break;
@@ -766,7 +766,7 @@
from = NEXTFROM;
l = num2i32(from);
l = NATINT_HTOVL(l);
- bstr_concat(data, (const UInt8 *)OFF32(&l), NATINT_LEN(long,4));
+ rb_bstr_concat(data, (const UInt8 *)OFF32(&l), NATINT_LEN(long,4));
}
break;
@@ -777,7 +777,7 @@
from = NEXTFROM;
f = RFLOAT_VALUE(rb_Float(from));
- bstr_concat(data, (const UInt8 *)&f, sizeof(float));
+ rb_bstr_concat(data, (const UInt8 *)&f, sizeof(float));
}
break;
@@ -789,7 +789,7 @@
from = NEXTFROM;
f = RFLOAT_VALUE(rb_Float(from));
f = HTOVF(f,ftmp);
- bstr_concat(data, (const UInt8 *)&f, sizeof(float));
+ rb_bstr_concat(data, (const UInt8 *)&f, sizeof(float));
}
break;
@@ -801,7 +801,7 @@
from = NEXTFROM;
d = RFLOAT_VALUE(rb_Float(from));
d = HTOVD(d,dtmp);
- bstr_concat(data, (const UInt8 *)&d, sizeof(double));
+ rb_bstr_concat(data, (const UInt8 *)&d, sizeof(double));
}
break;
@@ -812,7 +812,7 @@
from = NEXTFROM;
d = RFLOAT_VALUE(rb_Float(from));
- bstr_concat(data, (const UInt8 *)&d, sizeof(double));
+ rb_bstr_concat(data, (const UInt8 *)&d, sizeof(double));
}
break;
@@ -824,7 +824,7 @@
from = NEXTFROM;
f = RFLOAT_VALUE(rb_Float(from));
f = HTONF(f,ftmp);
- bstr_concat(data, (const UInt8 *)&f, sizeof(float));
+ rb_bstr_concat(data, (const UInt8 *)&f, sizeof(float));
}
break;
@@ -836,30 +836,30 @@
from = NEXTFROM;
d = RFLOAT_VALUE(rb_Float(from));
d = HTOND(d,dtmp);
- bstr_concat(data, (const UInt8 *)&d, sizeof(double));
+ rb_bstr_concat(data, (const UInt8 *)&d, sizeof(double));
}
break;
case 'x': /* null byte */
grow:
while (len >= 10) {
- bstr_concat(data, (const UInt8 *)nul10, 10);
+ rb_bstr_concat(data, (const UInt8 *)nul10, 10);
len -= 10;
}
- bstr_concat(data, (const UInt8 *)nul10, len);
+ rb_bstr_concat(data, (const UInt8 *)nul10, len);
break;
case 'X': /* back up byte */
shrink:
- plen = bstr_length(data);
+ plen = rb_bstr_length(data);
if (plen < len) {
rb_raise(rb_eArgError, "X outside of string");
}
- bstr_set_length(data, plen - len);
+ rb_bstr_set_length(data, plen - len);
break;
case '@': /* null fill to absolute position */
- len -= bstr_length(data);
+ len -= rb_bstr_length(data);
if (len > 0) {
goto grow;
}
@@ -886,7 +886,7 @@
rb_raise(rb_eRangeError, "pack(U): value out of range");
}
le = rb_uv_to_utf8(buf, l);
- bstr_concat(data, (const UInt8 *)buf, le);
+ rb_bstr_concat(data, (const UInt8 *)buf, le);
}
break;
@@ -957,14 +957,14 @@
}
rb_ary_push(associates, from);
rb_obj_taint(from);
- bstr_concat(data, (const UInt8 *)&t, sizeof(char*));
+ rb_bstr_concat(data, (const UInt8 *)&t, sizeof(char*));
}
break;
case 'w': /* BER compressed integer */
while (len-- > 0) {
unsigned long ul;
- VALUE bufdata = bstr_new();
+ VALUE bufdata = rb_bstr_new();
char c, *bufs, *bufe;
from = NEXTFROM;
@@ -973,7 +973,7 @@
while (TYPE(from) == T_BIGNUM) {
from = rb_big_divmod(from, big128);
c = NUM2INT(RARRAY_AT(from, 1)) | 0x80; /* mod */
- bstr_concat(bufdata, (const UInt8 *)&c, sizeof(char));
+ rb_bstr_concat(bufdata, (const UInt8 *)&c, sizeof(char));
from = RARRAY_AT(from, 0); /* div */
}
}
@@ -986,25 +986,25 @@
while (ul) {
c = ((ul & 0x7f) | 0x80);
- bstr_concat(bufdata, (const UInt8 *)&c, sizeof(char));
+ rb_bstr_concat(bufdata, (const UInt8 *)&c, sizeof(char));
ul >>= 7;
}
- if (bstr_length(bufdata) > 0) {
- UInt8 *buf_beg = bstr_bytes(bufdata);
+ if (rb_bstr_length(bufdata) > 0) {
+ UInt8 *buf_beg = rb_bstr_bytes(bufdata);
bufs = (char *)buf_beg;
- bufe = bufs + bstr_length(bufdata) - 1;
+ bufe = bufs + rb_bstr_length(bufdata) - 1;
*bufs &= 0x7f; /* clear continue bit */
while (bufs < bufe) { /* reverse */
c = *bufs;
*bufs++ = *bufe;
*bufe-- = c;
}
- bstr_concat(data, buf_beg, bstr_length(bufdata));
+ rb_bstr_concat(data, buf_beg, rb_bstr_length(bufdata));
}
else {
c = 0;
- bstr_concat(data, (const UInt8 *)&c, sizeof(char));
+ rb_bstr_concat(data, (const UInt8 *)&c, sizeof(char));
}
}
break;
@@ -1059,7 +1059,7 @@
len -= 3;
}
if (sizeof(buff) - i < 4) {
- bstr_concat(data, (const UInt8 *)buff, i);
+ rb_bstr_concat(data, (const UInt8 *)buff, i);
i = 0;
}
}
@@ -1078,7 +1078,7 @@
if (tail_lf) {
buff[i++] = '\n';
}
- bstr_concat(data, (const UInt8 *)buff, i);
+ rb_bstr_concat(data, (const UInt8 *)buff, i);
free(buff);
}
static const char hex_table[] = "0123456789ABCDEF";
@@ -1122,7 +1122,7 @@
prev = '\n';
}
if (i > 1024 - 5) {
- bstr_concat(data, (const UInt8 *)buff, i);
+ rb_bstr_concat(data, (const UInt8 *)buff, i);
i = 0;
}
s++;
@@ -1132,7 +1132,7 @@
buff[i++] = '\n';
}
if (i > 0) {
- bstr_concat(data, (const UInt8 *)buff, i);
+ rb_bstr_concat(data, (const UInt8 *)buff, i);
}
}
@@ -1447,10 +1447,10 @@
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
bits = 0;
- bitstr = bstr_new();
- bstr_resize(bitstr, len);
+ bitstr = rb_bstr_new();
+ rb_bstr_resize(bitstr, len);
UNPACK_PUSH(bitstr);
- t = (char *)bstr_bytes(bitstr);
+ t = (char *)rb_bstr_bytes(bitstr);
for (i=0; i<len; i++) {
if (i & 7) {
bits >>= 1;
@@ -1473,10 +1473,10 @@
if (p[-1] == '*' || len > (send - s) * 8)
len = (send - s) * 8;
bits = 0;
- bitstr = bstr_new();
- bstr_resize(bitstr, len);
+ bitstr = rb_bstr_new();
+ rb_bstr_resize(bitstr, len);
UNPACK_PUSH(bitstr);
- t = (char *)bstr_bytes(bitstr);
+ t = (char *)rb_bstr_bytes(bitstr);
for (i=0; i<len; i++) {
if (i & 7) {
bits <<= 1;
@@ -1499,10 +1499,10 @@
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
bits = 0;
- bitstr = bstr_new();
- bstr_resize(bitstr, len);
+ bitstr = rb_bstr_new();
+ rb_bstr_resize(bitstr, len);
UNPACK_PUSH(bitstr);
- t = (char *)bstr_bytes(bitstr);
+ t = (char *)rb_bstr_bytes(bitstr);
for (i=0; i<len; i++) {
if (i & 1) {
bits >>= 4;
@@ -1525,10 +1525,10 @@
if (p[-1] == '*' || len > (send - s) * 2)
len = (send - s) * 2;
bits = 0;
- bitstr = bstr_new();
- bstr_resize(bitstr, len);
+ bitstr = rb_bstr_new();
+ rb_bstr_resize(bitstr, len);
UNPACK_PUSH(bitstr);
- t = (char *)bstr_bytes(bitstr);
+ t = (char *)rb_bstr_bytes(bitstr);
for (i=0; i<len; i++) {
if (i & 1) {
bits <<= 4;
@@ -1783,11 +1783,11 @@
case 'u':
{
- VALUE buf = bstr_new();
- bstr_resize(buf, (send - s)*3/4);
- char *ptr = (char *)bstr_bytes(buf);
+ VALUE buf = rb_bstr_new();
+ rb_bstr_resize(buf, (send - s)*3/4);
+ char *ptr = (char *)rb_bstr_bytes(buf);
long total = 0;
- const long buflen = bstr_length(buf);
+ const long buflen = rb_bstr_length(buf);
while (s < send && *s > ' ' && *s < 'a') {
long a,b,c,d;
@@ -1846,16 +1846,16 @@
}
}
- bstr_resize(buf, total);
+ rb_bstr_resize(buf, total);
UNPACK_PUSH(buf);
}
break;
case 'm':
{
- VALUE buf = bstr_new();
- bstr_resize(buf, (send - s)*3/4);
- char *ptr = (char *)bstr_bytes(buf);
+ VALUE buf = rb_bstr_new();
+ rb_bstr_resize(buf, (send - s)*3/4);
+ char *ptr = (char *)rb_bstr_bytes(buf);
char *ptr_beg = ptr;
int a = -1,b = -1,c = 0,d;
static int first = 1;
@@ -1899,16 +1899,16 @@
*ptr++ = b << 4 | c >> 2;
}
}
- bstr_resize(buf, ptr - ptr_beg);
+ rb_bstr_resize(buf, ptr - ptr_beg);
UNPACK_PUSH(buf);
}
break;
case 'M':
{
- VALUE buf = bstr_new();
- bstr_resize(buf, send - s);
- char *ptr = (char *)bstr_bytes(buf);
+ VALUE buf = rb_bstr_new();
+ rb_bstr_resize(buf, send - s);
+ char *ptr = (char *)rb_bstr_bytes(buf);
char *ptr_beg = ptr;
int c1, c2;
@@ -1929,7 +1929,7 @@
}
s++;
}
- bstr_resize(buf, ptr - ptr_beg);
+ rb_bstr_resize(buf, ptr - ptr_beg);
UNPACK_PUSH(buf);
}
break;
Modified: MacRuby/branches/icu/random.c
===================================================================
--- MacRuby/branches/icu/random.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/random.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -564,7 +564,7 @@
ptr[i] = (char)r;
r >>= CHAR_BIT;
}
- VALUE bytes = bstr_new_with_data(ptr, n);
+ VALUE bytes = rb_bstr_new_with_data(ptr, n);
free(ptr);
return bytes;
}
Modified: MacRuby/branches/icu/ruby.c
===================================================================
--- MacRuby/branches/icu/ruby.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/ruby.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -1092,8 +1092,8 @@
char *pend;
line = rb_str_bstr(line);
- p = (char *)bstr_bytes(line);
- pend = p + bstr_length(line);
+ p = (char *)rb_bstr_bytes(line);
+ pend = p + rb_bstr_length(line);
if (pend[-1] == '\n') {
pend--; /* chomp line */
@@ -1127,8 +1127,8 @@
start_read:
p += 4;
- char *linebuf = (char *)bstr_bytes(line);
- const long linebuflen = bstr_length(line);
+ char *linebuf = (char *)rb_bstr_bytes(line);
+ const long linebuflen = rb_bstr_length(line);
linebuf[linebuflen - 1] = '\0';
if (linebuf[linebuflen - 2] == '\r') {
Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/string.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -5392,14 +5392,14 @@
}
uint8_t *
-bstr_bytes(VALUE str)
+rb_bstr_bytes(VALUE str)
{
assert(IS_BSTR(str));
return (uint8_t *)RSTR(str)->data.bytes;
}
VALUE
-bstr_new_with_data(const uint8_t *bytes, long len)
+rb_bstr_new_with_data(const uint8_t *bytes, long len)
{
rb_str_t *str = str_alloc(rb_cRubyString);
str_replace_with_bytes(str, (char *)bytes, len,
@@ -5408,34 +5408,34 @@
}
VALUE
-bstr_new(void)
+rb_bstr_new(void)
{
- return bstr_new_with_data(NULL, 0);
+ return rb_bstr_new_with_data(NULL, 0);
}
long
-bstr_length(VALUE str)
+rb_bstr_length(VALUE str)
{
assert(IS_BSTR(str));
return RSTR(str)->length_in_bytes;
}
void
-bstr_concat(VALUE str, const uint8_t *bytes, long len)
+rb_bstr_concat(VALUE str, const uint8_t *bytes, long len)
{
assert(IS_BSTR(str));
str_concat_bytes(RSTR(str), (const char *)bytes, len);
}
void
-bstr_resize(VALUE str, long capa)
+rb_bstr_resize(VALUE str, long capa)
{
assert(IS_BSTR(str));
str_resize_bytes(RSTR(str), capa);
}
void
-bstr_set_length(VALUE str, long len)
+rb_bstr_set_length(VALUE str, long len)
{
assert(IS_BSTR(str));
assert(len <= RSTR(str)->capacity_in_bytes);
@@ -5854,6 +5854,20 @@
return str;
}
+void
+rb_str_set_len(VALUE str, long len)
+{
+ if (IS_RSTR(str)) {
+ const long len_bytes = str_is_stored_in_uchars(RSTR(str))
+ ? UCHARS_TO_BYTES(len) : len;
+ assert(len_bytes < RSTR(str)->length_in_bytes);
+ RSTR(str)->length_in_bytes = len_bytes;
+ }
+ else {
+ abort(); // TODO
+ }
+}
+
VALUE
rb_str_equal(VALUE str, VALUE str2)
{
Modified: MacRuby/branches/icu/time.c
===================================================================
--- MacRuby/branches/icu/time.c 2010-03-09 02:02:51 UTC (rev 3715)
+++ MacRuby/branches/icu/time.c 2010-03-09 23:03:42 UTC (rev 3716)
@@ -2169,7 +2169,7 @@
s = RSHIFT(s, 8);
}
- str = bstr_new_with_data(buf, 8);
+ str = rb_bstr_new_with_data(buf, 8);
rb_copy_generic_ivar(str, time);
if (nsec) {
/*
@@ -2188,7 +2188,7 @@
buf[0] |= (nsec % 10) << 4;
if (buf[1] == 0)
len = 1;
- rb_ivar_set(str, id_submicro, bstr_new_with_data(buf, len));
+ rb_ivar_set(str, id_submicro, rb_bstr_new_with_data(buf, len));
}
return str;
}
@@ -2238,8 +2238,8 @@
StringValue(str);
str = rb_str_bstr(str);
- uint8_t *buf = bstr_bytes(str);
- const long buflen = bstr_length(str);
+ uint8_t *buf = rb_bstr_bytes(str);
+ const long buflen = rb_bstr_length(str);
if (buflen != 8 && buflen != 9) {
rb_raise(rb_eTypeError, "marshaled time format differ");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100309/eb87d2f6/attachment-0001.html>
More information about the macruby-changes
mailing list