summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-05 01:37:46 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-05 01:37:46 +0000
commitc800d0b75d23e2ac8c10674ff41cc25b0c793ddd (patch)
treef5467a0440e49ed7016e2d21f44ff00de5804855 /marshal.c
parent889a620b769145a7c20c7ce78aff62d80e485496 (diff)
* io.c (rb_fopen): mode string copy at the lowest level.
* io.c (rb_io_flags_mode): requires output buffer no more. no allocation needed. * array.c (rb_ary_index): takes a block to compare items in an array. [ruby-talk:113069] [Ruby2] * array.c (rb_ary_rindex): ditto. * marshal.c (r_byte): retrieve pointer from string value for each time. [ruby-dev:24404] * marshal.c (r_bytes0): ditto. * enum.c (sort_by_i): re-entrance check added. [ruby-dev:24399] * io.c (io_read): should freeze all reading buffer. [ruby-dev:24400] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/marshal.c b/marshal.c
index 91eadb4cd7..71c6d16699 100644
--- a/marshal.c
+++ b/marshal.c
@@ -779,7 +779,8 @@ marshal_dump(argc, argv)
}
struct load_arg {
- char *ptr, *end;
+ VALUE src;
+ long offset;
st_table *symbols;
VALUE data;
VALUE proc;
@@ -794,18 +795,20 @@ r_byte(arg)
{
int c;
- if (!arg->end) {
- VALUE src = (VALUE)arg->ptr;
+ if (TYPE(arg->src) == T_STRING) {
+ if (RSTRING(arg->src)->len > arg->offset) {
+ c = (unsigned char)RSTRING(arg->src)->ptr[arg->offset++];
+ }
+ else {
+ rb_raise(rb_eArgError, "marshal data too short");
+ }
+ }
+ else {
+ VALUE src = arg->src;
VALUE v = rb_funcall2(src, s_getc, 0, 0);
if (NIL_P(v)) rb_eof_error();
c = (unsigned char)FIX2INT(v);
}
- else if (arg->ptr < arg->end) {
- c = *(unsigned char*)arg->ptr++;
- }
- else {
- rb_raise(rb_eArgError, "marshal data too short");
- }
return c;
}
@@ -869,8 +872,18 @@ r_bytes0(len, arg)
VALUE str;
if (len == 0) return rb_str_new(0, 0);
- if (!arg->end) {
- VALUE src = (VALUE)arg->ptr;
+ if (TYPE(arg->src) == T_STRING) {
+ if (RSTRING(arg->src)->len > arg->offset) {
+ str = rb_str_new(RSTRING(arg->src)->ptr+arg->offset, len);
+ arg->offset += len;
+ }
+ else {
+ too_short:
+ rb_raise(rb_eArgError, "marshal data too short");
+ }
+ }
+ else {
+ VALUE src = arg->src;
VALUE n = LONG2NUM(len);
str = rb_funcall2(src, s_read, 1, &n);
if (NIL_P(str)) goto too_short;
@@ -878,14 +891,6 @@ r_bytes0(len, arg)
if (RSTRING(str)->len != len) goto too_short;
if (OBJ_TAINTED(str)) arg->taint = Qtrue;
}
- else {
- if (arg->ptr + len > arg->end) {
- too_short:
- rb_raise(rb_eArgError, "marshal data too short");
- }
- str = rb_str_new(arg->ptr, len);
- arg->ptr += len;
- }
return str;
}
@@ -1391,20 +1396,18 @@ marshal_load(argc, argv)
if (rb_respond_to(port, rb_intern("to_str"))) {
arg.taint = OBJ_TAINTED(port); /* original taintedness */
StringValue(port); /* possible conversion */
- arg.ptr = RSTRING(port)->ptr;
- arg.end = arg.ptr + RSTRING(port)->len;
}
else if (rb_respond_to(port, s_getc) && rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
rb_funcall2(port, s_binmode, 0, 0);
}
arg.taint = Qtrue;
- arg.ptr = (char *)port;
- arg.end = 0;
}
else {
rb_raise(rb_eTypeError, "instance of IO needed");
}
+ arg.src = port;
+ arg.offset = 0;
major = r_byte(&arg);
minor = r_byte(&arg);