Skip to content

Commit 90a88ab

Browse files
author
matz
committed
* marshal.c (r_object0): remove unnecessary iv restoration for
USRMARSHAL. [ruby-dev:21582] * marshal.c (w_object): dump generic instance variables from a string from '_dump'. * variable.c (rb_generic_ivar_table): return 0 if obj's FL_EXIVAR is not set. * time.c (time_dump): copy instance variables to dumped string, to be included in the marshaled data. * bignum.c (rb_big2ulong): add range check to ensure round trip. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 80549d5 commit 90a88ab

File tree

6 files changed

+62
-51
lines changed

6 files changed

+62
-51
lines changed

ChangeLog

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,27 @@ Thu Oct 9 17:43:36 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
2323
* eval.c (proc_save_safe_level, proc_get_safe_level,
2424
proc_set_safe_level): save/restore safe level 1..4.
2525

26+
Thu Oct 9 16:33:23 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
27+
28+
* marshal.c (r_object0): remove unnecessary iv restoration for
29+
USRMARSHAL. [ruby-dev:21582]
30+
31+
* marshal.c (w_object): dump generic instance variables from
32+
a string from '_dump'.
33+
34+
* variable.c (rb_generic_ivar_table): return 0 if obj's FL_EXIVAR
35+
is not set.
36+
37+
* time.c (time_dump): copy instance variables to dumped string, to
38+
be included in the marshaled data.
39+
40+
* bignum.c (rb_big2ulong): add range check to ensure round trip.
41+
2642
Thu Oct 9 15:45:27 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
2743

2844
* pack.c (uv_to_utf8): change message to "out of range", since
2945
negative values are not "too big". [ruby-dev21567]
3046

31-
* marshal.c (w_object): should pass the value of "weak" to
32-
w_object(). [ruby-dev:21555] and [ruby-dev:21561]
33-
3447
Thu Oct 9 14:05:38 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
3548

3649
* eval.c (rb_set_end_proc, rb_exec_end_proc): restore safe level.

bignum.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,12 @@ rb_big2ulong(x)
729729
{
730730
unsigned long num = big2ulong(x, "unsigned long");
731731

732-
if (!RBIGNUM(x)->sign) return -num;
732+
if (!RBIGNUM(x)->sign) {
733+
if ((long)num < 0) {
734+
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
735+
}
736+
return -num;
737+
}
733738
return num;
734739
}
735740

marshal.c

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ struct dump_call_arg {
9393
VALUE obj;
9494
struct dump_arg *arg;
9595
int limit;
96-
int weak;
9796
};
9897

9998
static void w_long _((long, struct dump_arg*));
@@ -333,15 +332,15 @@ w_unique(s, arg)
333332
w_symbol(rb_intern(s), arg);
334333
}
335334

336-
static void w_object _((VALUE,struct dump_arg*,int,int));
335+
static void w_object _((VALUE,struct dump_arg*,int));
337336

338337
static int
339338
hash_each(key, value, arg)
340339
VALUE key, value;
341340
struct dump_call_arg *arg;
342341
{
343-
w_object(key, arg->arg, arg->limit, arg->weak);
344-
w_object(value, arg->arg, arg->limit, arg->weak);
342+
w_object(key, arg->arg, arg->limit);
343+
w_object(value, arg->arg, arg->limit);
345344
return ST_CONTINUE;
346345
}
347346

@@ -404,7 +403,7 @@ w_obj_each(id, value, arg)
404403
struct dump_call_arg *arg;
405404
{
406405
w_symbol(id, arg->arg);
407-
w_object(value, arg->arg, arg->limit, arg->weak);
406+
w_object(value, arg->arg, arg->limit);
408407
return ST_CONTINUE;
409408
}
410409

@@ -423,11 +422,10 @@ w_ivar(tbl, arg)
423422
}
424423

425424
static void
426-
w_object(obj, arg, limit, weak)
425+
w_object(obj, arg, limit)
427426
VALUE obj;
428427
struct dump_arg *arg;
429428
int limit;
430-
int weak;
431429
{
432430
struct dump_call_arg c_arg;
433431
st_table *ivtbl = 0;
@@ -439,7 +437,6 @@ w_object(obj, arg, limit, weak)
439437
limit--;
440438
c_arg.limit = limit;
441439
c_arg.arg = arg;
442-
c_arg.weak = weak;
443440

444441
if (ivtbl = rb_generic_ivar_table(obj)) {
445442
w_byte(TYPE_IVAR, arg);
@@ -463,7 +460,7 @@ w_object(obj, arg, limit, weak)
463460
w_long(FIX2LONG(obj), arg);
464461
}
465462
else {
466-
w_object(rb_int2big(FIX2LONG(obj)), arg, limit, weak);
463+
w_object(rb_int2big(FIX2LONG(obj)), arg, limit);
467464
}
468465
#endif
469466
}
@@ -485,17 +482,11 @@ w_object(obj, arg, limit, weak)
485482
if (rb_respond_to(obj, s_mdump)) {
486483
VALUE v;
487484

488-
if (TYPE(obj) == T_OBJECT) {
489-
w_byte(TYPE_IVAR, arg);
490-
ivtbl = ROBJECT(obj)->iv_tbl;
491-
}
492485
v = rb_funcall(obj, s_mdump, 0, 0);
493486
w_byte(TYPE_USRMARSHAL, arg);
494487
w_unique(rb_class2name(CLASS_OF(obj)), arg);
495-
w_object(v, arg, limit, weak);
496-
c_arg.weak = Qtrue;
497-
ivtbl = rb_generic_ivar_table(v);
498-
if (ivtbl) w_ivar(ivtbl, &c_arg);
488+
w_object(v, arg, limit);
489+
if (ivtbl) w_ivar(0, &c_arg);
499490
return;
500491
}
501492
if (rb_respond_to(obj, s_dump)) {
@@ -505,11 +496,14 @@ w_object(obj, arg, limit, weak)
505496
if (TYPE(v) != T_STRING) {
506497
rb_raise(rb_eTypeError, "_dump() must return string");
507498
}
499+
if (!ivtbl && (ivtbl = rb_generic_ivar_table(v))) {
500+
w_byte(TYPE_IVAR, arg);
501+
}
508502
w_class(TYPE_USERDEF, obj, arg);
509503
w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg);
510-
c_arg.weak = Qtrue;
511-
ivtbl = rb_generic_ivar_table(v);
512-
if (ivtbl) w_ivar(ivtbl, &c_arg);
504+
if (ivtbl) {
505+
w_ivar(ivtbl, &c_arg);
506+
}
513507
return;
514508
}
515509

@@ -595,7 +589,7 @@ w_object(obj, arg, limit, weak)
595589

596590
w_long(len, arg);
597591
while (len--) {
598-
w_object(*ptr, arg, limit, weak);
592+
w_object(*ptr, arg, limit);
599593
ptr++;
600594
}
601595
}
@@ -616,7 +610,7 @@ w_object(obj, arg, limit, weak)
616610
w_long(RHASH(obj)->tbl->num_entries, arg);
617611
st_foreach(RHASH(obj)->tbl, hash_each, (st_data_t)&c_arg);
618612
if (!NIL_P(RHASH(obj)->ifnone)) {
619-
w_object(RHASH(obj)->ifnone, arg, limit, weak);
613+
w_object(RHASH(obj)->ifnone, arg, limit);
620614
}
621615
break;
622616

@@ -634,7 +628,7 @@ w_object(obj, arg, limit, weak)
634628
}
635629
for (i=0; i<len; i++) {
636630
w_symbol(SYM2ID(RARRAY(mem)->ptr[i]), arg);
637-
w_object(RSTRUCT(obj)->ptr[i], arg, limit, weak);
631+
w_object(RSTRUCT(obj)->ptr[i], arg, limit);
638632
}
639633
}
640634
break;
@@ -655,15 +649,11 @@ w_object(obj, arg, limit, weak)
655649
rb_obj_classname(obj));
656650
}
657651
v = rb_funcall(obj, s_dump_data, 0);
658-
w_object(v, arg, limit, weak);
652+
w_object(v, arg, limit);
659653
}
660654
break;
661655

662656
default:
663-
if (weak) {
664-
w_byte(TYPE_NIL, arg);
665-
return;
666-
}
667657
rb_raise(rb_eTypeError, "can't dump %s",
668658
rb_obj_classname(obj));
669659
break;
@@ -678,7 +668,7 @@ static VALUE
678668
dump(arg)
679669
struct dump_call_arg *arg;
680670
{
681-
w_object(arg->obj, arg->arg, arg->limit, arg->weak);
671+
w_object(arg->obj, arg->arg, arg->limit);
682672
if (arg->arg->dest) {
683673
rb_io_write(arg->arg->dest, arg->arg->str);
684674
rb_str_resize(arg->arg->str, 0);
@@ -1216,10 +1206,6 @@ r_object0(arg, proc, ivp)
12161206
}
12171207
r_entry(v, arg);
12181208
data = r_object(arg);
1219-
if (ivp) {
1220-
r_ivar(v, arg);
1221-
*ivp = Qfalse;
1222-
}
12231209
rb_funcall(v, s_mload, 1, data);
12241210
}
12251211
break;

pack.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ pack_pack(ary, fmt)
825825

826826
case 'U':
827827
while (len-- > 0) {
828-
unsigned long l;
828+
long l;
829829
char buf[8];
830830
int le;
831831

@@ -834,6 +834,9 @@ pack_pack(ary, fmt)
834834
else {
835835
l = NUM2ULONG(from);
836836
}
837+
if (l < 0) {
838+
rb_raise(rb_eArgError, "pack(U): negative value");
839+
}
837840
le = uv_to_utf8(buf, l);
838841
rb_str_buf_cat(res, (char*)buf, le);
839842
}
@@ -918,7 +921,11 @@ pack_pack(ary, fmt)
918921

919922
if (NIL_P(from)) ul = 0;
920923
else {
921-
ul = NUM2ULONG(from);
924+
long l = NUM2LONG(from);
925+
if (l < 0) {
926+
rb_raise(rb_eArgError, "cannot compress negative numbers");
927+
}
928+
ul = l;
922929
}
923930

924931
while (ul) {
@@ -1857,7 +1864,7 @@ uv_to_utf8(buf, uv)
18571864
buf[5] = (uv&0x3f)|0x80;
18581865
return 6;
18591866
}
1860-
rb_raise(rb_eArgError, "uv_to_utf8(); value out of range");
1867+
rb_raise(rb_eArgError, "pack(U): value out of range");
18611868
}
18621869

18631870
static const long utf8_limits[] = {

time.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,6 @@ time_mdump(time)
13171317
char buf[8];
13181318
time_t t;
13191319
int i;
1320-
VALUE str;
13211320

13221321
GetTimeval(time, tobj);
13231322

@@ -1345,13 +1344,7 @@ time_mdump(time)
13451344
s = RSHIFT(s, 8);
13461345
}
13471346

1348-
str = rb_str_new(buf, 8);
1349-
if (FL_TEST(time, FL_EXIVAR)) {
1350-
rb_copy_generic_ivar(str, time);
1351-
FL_SET(str, FL_EXIVAR);
1352-
}
1353-
1354-
return str;
1347+
return rb_str_new(buf, 8);
13551348
}
13561349

13571350
static VALUE
@@ -1360,10 +1353,16 @@ time_dump(argc, argv, time)
13601353
VALUE *argv;
13611354
VALUE time;
13621355
{
1363-
VALUE dummy;
1356+
VALUE str;
13641357

1365-
rb_scan_args(argc, argv, "01", &dummy);
1366-
return time_mdump(time);
1358+
rb_scan_args(argc, argv, "01", 0);
1359+
str = time_mdump(time);
1360+
if (FL_TEST(time, FL_EXIVAR)) {
1361+
rb_copy_generic_ivar(str, time);
1362+
FL_SET(str, FL_EXIVAR);
1363+
}
1364+
1365+
return str;
13671366
}
13681367

13691368
static VALUE

variable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ rb_generic_ivar_table(obj)
780780
{
781781
st_table *tbl;
782782

783+
if (!FL_TEST(obj, FL_EXIVAR)) return 0;
783784
if (!generic_iv_tbl) return 0;
784785
if (!st_lookup(generic_iv_tbl, obj, (st_data_t *)&tbl)) return 0;
785786
return tbl;

0 commit comments

Comments
 (0)