Skip to content
Browse files

expose the bstr APIs

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3716 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent b4141cc commit adfb972763f49764ac97a8c7f5b770c89b876304 Laurent Sansonetti committed Mar 9, 2010
Showing with 147 additions and 132 deletions.
  1. +0 −13 encoding.h
  2. +14 −0 include/ruby/intern.h
  3. +22 −22 io.c
  4. +7 −7 marshal.c
  5. +73 −73 pack.c
  6. +1 −1 random.c
  7. +4 −4 ruby.c
  8. +22 −8 string.c
  9. +4 −4 time.c
View
13 encoding.h
@@ -306,19 +306,6 @@ unsigned long rb_str_hash_uchars(const UChar *chars, long chars_len);
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
View
14 include/ruby/intern.h
@@ -606,6 +606,20 @@ VALUE rb_str_inspect(VALUE);
#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*, ...);
View
44 io.c
@@ -424,8 +424,8 @@ io_write(VALUE io, SEL sel, VALUE data)
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,19 +988,19 @@ rb_io_read_all(rb_io_t *io_struct, VALUE outbuf)
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) {
break;
}
}
- bstr_set_length(outbuf, original_position + bytes_read);
+ rb_bstr_set_length(outbuf, original_position + bytes_read);
return outbuf;
}
@@ -1119,7 +1119,7 @@ io_read(VALUE io, SEL sel, int argc, VALUE *argv)
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 @@ io_read(VALUE io, SEL sel, int argc, VALUE *argv)
}
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 @@ rb_io_gets_m(VALUE io, SEL sel, int argc, VALUE *argv)
}
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,18 +1334,18 @@ rb_io_gets_m(VALUE io, SEL sel, int argc, VALUE *argv)
// 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) {
break;
}
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 @@ rb_io_gets_m(VALUE io, SEL sel, int argc, VALUE *argv)
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 @@ rb_f_backquote(VALUE obj, SEL sel, VALUE str)
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 @@ rb_io_s_readlines(VALUE recv, SEL sel, int argc, VALUE *argv)
}
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 @@ rb_io_s_readlines(VALUE recv, SEL sel, int argc, VALUE *argv)
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;
}
}
View
14 marshal.c
@@ -219,7 +219,7 @@ static void
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 @@ dump(struct dump_call_arg *arg)
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 @@ marshal_dump(VALUE self, SEL sel, int argc, VALUE *argv)
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 @@ r_bytes0(long len, struct load_arg *arg)
}
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;
View
146 pack.c
@@ -454,7 +454,7 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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,15 +562,15 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
byte >>= 1;
else {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
byte = 0;
}
}
if (len & 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,15 +592,15 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
byte <<= 1;
else {
char c = byte & 0xff;
- bstr_concat(data, (const UInt8 *)&c, 1);
+ rb_bstr_concat(data, (const UInt8 *)&c, 1);
byte = 0;
}
}
if (len & 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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
}
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ pack_pack(VALUE ary, SEL sel, VALUE fmt)
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 @@ encodes(VALUE data, const char *s, long len, int type, int tail_lf)
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 @@ encodes(VALUE data, const char *s, long len, int type, int tail_lf)
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 @@ qpencode(VALUE data, VALUE from, long len)
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 @@ qpencode(VALUE data, VALUE from, long len)
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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
}
}
- 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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
*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 @@ pack_unpack(VALUE str, SEL sel, VALUE fmt)
}
s++;
}
- bstr_resize(buf, ptr - ptr_beg);
+ rb_bstr_resize(buf, ptr - ptr_beg);
UNPACK_PUSH(buf);
}
break;
View
2 random.c
@@ -564,7 +564,7 @@ random_bytes(VALUE obj, SEL sel, VALUE len)
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;
}
View
8 ruby.c
@@ -1092,8 +1092,8 @@ load_file(VALUE parser, const char *fname, int script,
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 @@ load_file(VALUE parser, const char *fname, int script,
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') {
View
30 string.c
@@ -5392,14 +5392,14 @@ rb_str_bstr(VALUE str)
}
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 @@ bstr_new_with_data(const uint8_t *bytes, long len)
}
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 @@ rb_str_resize(VALUE str, long len)
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)
{
View
8 time.c
@@ -2169,7 +2169,7 @@ time_mdump(VALUE time)
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 @@ time_mdump(VALUE time)
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 @@ time_mload(VALUE time, VALUE str)
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");
}

0 comments on commit adfb972

Please sign in to comment.
Something went wrong with that request. Please try again.