[#11357] [PATCH] an analogue of `long long' — "Nobuyoshi.Nakada" <nobu.nakada@...>

なかだです。

18 messages 2000/11/01
[#11358] Re: [PATCH] an analogue of `long long' — matz@... (Yukihiro Matsumoto) 2000/11/01

まつもと ゆきひろです

[#11364] Re: [PATCH] an analogue of `long long' — EGUCHI Osamu <eguchi@...> 2000/11/02

えぐち@エスアンドイー です。

[#11440] class Character (was: Ruby I18N) — Yasushi Shoji <yashi@...>

[ruby-dev:11428] からの続きですが、threadは切りました。

14 messages 2000/11/08
[#11442] Re: class Character (was: Ruby I18N) — TAKAHASHI Masayoshi <maki@...> 2000/11/08

高橋征義です。用語について。

[#11443] Re: class Character (was: Ruby I18N) — Yasushi Shoji <yashi@...> 2000/11/08

At Wed, 8 Nov 2000 20:44:55 +0900,

[#11520] A problem of Socket methods on Windows — OKA Toshiyuki <oka@...>

岡と申します。

22 messages 2000/11/15
[#11523] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11528] Re: A problem of Socket methods on Windows — matz@... (Yukihiro Matsumoto) 2000/11/15

まつもと ゆきひろです

[#11532] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11534] Re: A problem of Socket methods on Windows — OKA Toshiyuki <oka@...> 2000/11/15

岡です。

[#11535] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11538] Re: A problem of Socket methods on Windows — "Nobuyoshi.Nakada" <nobu.nakada@...> 2000/11/15

なかだです。

[#11662] IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org>

In article <E140cR3-0002ls-00@ev.netlab.zetabits.co.jp>,

22 messages 2000/11/28
[#11663] Re: IO (Re: fork problem?) — matz@... (Yukihiro Matsumoto) 2000/11/28

まつもと ゆきひろです

[#11664] Re: IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org> 2000/11/28

In article <E140fxW-0002u9-00@ev.netlab.zetabits.co.jp>,

[#11665] Re: IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org> 2000/11/28

In article <hvor93w5wb8.fsf@coulee.m17n.org>,

[#11669] Re: IO (Re: fork problem?) — Tanaka Akira <akr@...17n.org> 2000/11/29

In article <hvoofz05uwz.fsf@coulee.m17n.org>,

[#11672] Re: IO (Re: fork problem?) — matz@... (Yukihiro Matsumoto) 2000/11/29

まつもと ゆきひろです

[#11675] Re: IO (Re: fork problem?) — Koji Arai <JCA02266@...> 2000/11/30

新井です。

[#11677] Re: IO (Re: fork problem?) — matz@... (Yukihiro Matsumoto) 2000/12/01

まつもと ゆきひろです

[ruby-dev:11590] marshal.c パッチ

From: Kazuhiro NISHIYAMA <zn@...>
Date: 2000-11-18 19:37:48 UTC
List: ruby-dev #11590
array.cと同じように型が気になったところのパッチを作ってみました。
intからlongへの変更とintからsize_tへの変更があります。

それからMARSHAL_MAJORとMARSHAL_MINORのチェックのところを変更して、
新しいのか古いのかわかりやすくしました。

# dRubyでどっちがどっちかわかりにくかったので。


コメント追加だけの変更のところは変更していいかどうかわからなかった
ところです。

/* w_short? */のところ(1つ)は変更するとmarshal結果が変わりそうだった、
/* Is cast necessary? */のところ(3つ)はキャストは不要なのではないか
と思ったところです。
/* or size_t */のところ(1つ)は中(freadやmemcpy)はsize_tの方が
よさそうで外(r_bytes2)はlongの方が良さそうだったのでlongに
してみました。


--- 
ZnZ(ゼット エヌ ゼット)
西山和広(Kazuhiro NISHIYAMA)
mailto:zn@mbf.nifty.com


--- marshal.c~	Thu Nov  2 20:35:09 2000
+++ marshal.c	Sun Nov 19 04:21:59 2000
@@ -111,7 +111,7 @@
 static void
 w_bytes(s, n, arg)
     char *s;
-    int n;
+    size_t n;
     struct dump_arg *arg;
 {
     w_long(n, arg);
@@ -128,7 +128,7 @@
     int x;
     struct dump_arg *arg;
 {
-    int i;
+    size_t i;
 
     for (i=0; i<sizeof(short); i++) {
 	w_byte((x >> (i*8)) & 0xff, arg);
@@ -141,7 +141,7 @@
     struct dump_arg *arg;
 {
     char buf[sizeof(long)+1];
-    int i, len = 0;
+    size_t i, len = 0;
 
     if (x == 0) {
 	w_byte(0, arg);
@@ -350,15 +350,15 @@
 	    w_byte(TYPE_BIGNUM, arg);
 	    {
 		char sign = RBIGNUM(obj)->sign?'+':'-';
-		int len = RBIGNUM(obj)->len;
+		long len = RBIGNUM(obj)->len;
 		BDIGIT *d = RBIGNUM(obj)->digits;
 
 		w_byte(sign, arg);
-		w_long(SHORTLEN(len), arg);
+		w_long(SHORTLEN(len), arg); /* w_short? */
 		while (len--) {
 #if SIZEOF_BDIGITS > SIZEOF_SHORT
 		    BDIGIT num = *d;
-		    int i;
+		    size_t i;
 
 		    for (i=0; i<SIZEOF_BDIGITS; i+=sizeof(short)) {
 			w_short(num & SHORTMASK, arg);
@@ -390,7 +390,7 @@
 	    w_uclass(obj, rb_cArray, arg);
 	    w_byte(TYPE_ARRAY, arg);
 	    {
-		int len = RARRAY(obj)->len;
+		long len = RARRAY(obj)->len;
 		VALUE *ptr = RARRAY(obj)->ptr;
 
 		w_long(len, arg);
@@ -419,10 +419,10 @@
 	  case T_STRUCT:
 	    w_byte(TYPE_STRUCT, arg);
 	    {
-		int len = RSTRUCT(obj)->len;
+		long len = RSTRUCT(obj)->len;
 		char *path = rb_class2name(CLASS_OF(obj));
 		VALUE mem;
-		int i;
+		long i;
 
 		w_unique(path, arg);
 		w_long(len, arg);
@@ -597,12 +597,12 @@
     struct load_arg *arg;
 {
     register long x;
-    int c = (char)r_byte(arg);
+    int c = (char)r_byte(arg); /* Is cast necessary? */
     int i;
 
     if (c == 0) return 0;
     if (c > 0) {
-	if (c > sizeof(long)) long_toobig((int)c);
+	if (c > sizeof(long)) long_toobig((int)c); /* Is cast necessary? */
 	x = 0;
 	for (i=0;i<c;i++) {
 	    x |= (long)r_byte(arg) << (8*i);
@@ -610,7 +610,7 @@
     }
     else {
 	c = -c;
-	if (c > sizeof(long)) long_toobig((int)c);
+	if (c > sizeof(long)) long_toobig((int)c); /* Is cast necessary? */
 	x = -1;
 	for (i=0;i<c;i++) {
 	    x &= ~(0xff << (8*i));
@@ -627,14 +627,14 @@
 } while (0)
 
 #define r_bytes(s, arg) do {		\
-    int r_bytes_len;			\
+    long r_bytes_len;			\
     r_bytes2((s), r_bytes_len, (arg));	\
 } while (0)
 
 static void
 r_bytes0(s, len, arg)
     char *s;
-    int len;
+    long len; /* or size_t */
     struct load_arg *arg;
 {
     if (arg->fp) {
@@ -655,7 +655,7 @@
     struct load_arg *arg;
 {
     ID id;
-    int num = r_long(arg);
+    long num = r_long(arg);
 
     if (st_lookup(arg->symbol, num, &id)) {
 	return id;
@@ -699,7 +699,7 @@
     struct load_arg *arg;
 {
     char *buf;
-    int len;
+    long len;
 
     r_bytes2(buf, len, arg);
     return rb_str_new(buf, len);
@@ -723,7 +723,7 @@
     VALUE obj;
     struct load_arg *arg;
 {
-    int len;
+    long len;
 
     len = r_long(arg);
     if (len > 0) {
@@ -780,7 +780,7 @@
 
       case TYPE_FIXNUM:
 	{
-	    int i = r_long(arg);
+	    long i = r_long(arg);
 	    return INT2FIX(i);
 	}
 
@@ -795,7 +795,7 @@
 
       case TYPE_BIGNUM:
 	{
-	    int len;
+	    long len;
 	    BDIGIT *digits;
 
 	    NEWOBJ(big, struct RBignum);
@@ -808,7 +808,7 @@
 #if SIZEOF_BDIGITS > SIZEOF_SHORT
 		BDIGIT num = 0;
 		int shift = 0;
-		int i;
+		size_t i;
 
 		for (i=0; i<SIZEOF_BDIGITS; i+=sizeof(short)) {
 		    int j = r_short(arg);
@@ -835,7 +835,7 @@
       case TYPE_REGEXP:
 	{
 	    char *buf;
-	    int len;
+	    long len;
 	    int options;
 
 	    r_bytes2(buf, len, arg);
@@ -845,7 +845,7 @@
 
       case TYPE_ARRAY:
 	{
-	    volatile int len = r_long(arg); /* gcc 2.7.2.3 -O2 bug?? */
+	    volatile long len = r_long(arg); /* gcc 2.7.2.3 -O2 bug?? */
 
 	    v = rb_ary_new2(len);
 	    r_regist(v, arg);
@@ -858,7 +858,7 @@
       case TYPE_HASH:
       case TYPE_HASH_DEF:
 	{
-	    int len = r_long(arg);
+	    long len = r_long(arg);
 
 	    v = rb_hash_new();
 	    r_regist(v, arg);
@@ -876,8 +876,8 @@
       case TYPE_STRUCT:
 	{
 	    VALUE klass, mem, values;
-	    volatile int i;	/* gcc 2.7.2.3 -O2 bug?? */
-	    int len;
+	    volatile long i;	/* gcc 2.7.2.3 -O2 bug?? */
+	    long len;
 	    ID slot;
 
 	    klass = rb_path2class(r_unique(arg));
@@ -1001,7 +1001,7 @@
     VALUE *argv;
 {
     VALUE port, proc;
-    int major;
+    int major, minor;
     VALUE v;
     OpenFile *fptr;
     struct load_arg arg;
@@ -1030,17 +1030,25 @@
     if (major == MARSHAL_MAJOR) {
 	volatile VALUE hash;	/* protect from GC */
 
-	if (r_byte(&arg) != MARSHAL_MINOR) {
-	    rb_warn("Old marshal file format (can be read)");
+	minor = r_byte(&arg);
+	if (minor == MARSHAL_MINOR) {
+	    arg.symbol = st_init_numtable();
+	    arg.data   = hash = rb_hash_new();
+	    if (NIL_P(proc)) arg.proc = 0;
+	    else             arg.proc = proc;
+	    v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
+	}
+	else if (minor < MARSHAL_MINOR) {
+	    rb_warn("old marshal file format (can read)");
+	}
+	else {
+	    rb_warn("new marshal file format (can read)");
 	}
-	arg.symbol = st_init_numtable();
-	arg.data   = hash = rb_hash_new();
-	if (NIL_P(proc)) arg.proc = 0;
-	else             arg.proc = proc;
-	v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
     }
-    else {
+    else if (major < MARSHAL_MAJOR) {
 	rb_raise(rb_eTypeError, "old marshal file format (can't read)");
+    else {
+	rb_raise(rb_eTypeError, "new marshal file format (can't read)");
     }
 
     return v;


In This Thread

Prev Next