···
At Thu, 17 Oct 2002 03:24:27 +0900, Tom Payne wrote:
Anyone on the Ruby dev team care to modifiy marshal.c so that objects
like ARGF can be used (i.e. use rb_funcall(obj, rb_intern(“read”),
…) rather than hardcoded calls to rb_io_fread, etc.)?
Dirty hack.
Index: marshal.c
RCS file: /cvs/ruby/src/ruby/marshal.c,v
retrieving revision 1.72
diff -u -2 -p -r1.72 marshal.c
— marshal.c 25 Sep 2002 14:52:37 -0000 1.72
+++ marshal.c 17 Oct 2002 02:31:20 -0000
@@ -77,9 +77,10 @@ shortlen(len, ds)
static ID s_dump, s_load;
static ID s_dump_data, s_load_data, s_alloc;
+static ID s_getc, s_read;
struct dump_arg {
VALUE obj;
FILE *fp;
- VALUE str, dest;
st_table *symbol;
st_table *data;
@@ -96,10 +97,28 @@ static void w_long ((long, struct dump
static void
+w_byten(s, n, arg)
+static void
w_byte(c, arg)
char c;
struct dump_arg *arg;
{
- if (arg->fp) putc(c, arg->fp);
- else rb_str_buf_cat(arg->str, &c, 1);
@@ -111,10 +130,5 @@ w_bytes(s, n, arg)
{
w_long(n, arg);
- if (arg->fp) {
- fwrite(s, 1, n, arg->fp);
- }
- else {
- rb_str_buf_cat(arg->str, s, n);
- }
@@ -587,4 +601,5 @@ marshal_dump(argc, argv)
else port = a1;
}
- arg.dest = 0;
if (port) {
if (rb_obj_is_kind_of(port, rb_cIO)) {
@@ -597,5 +612,7 @@ marshal_dump(argc, argv)
}
else {
-static unsigned short
-r_short(arg)
- struct load_arg *arg;
-{
- unsigned short x;
- x = r_byte(arg);
- x |= r_byte(arg)<<8;
- return x;
-}
static void
long_toobig(size)
@@ -729,4 +740,12 @@ r_bytes0(len, arg)
}
}
@@ -939,4 +959,5 @@ r_object0(arg, proc)
big->sign = (r_byte(arg) == ‘+’);
len = r_long(arg);
#if SIZEOF_BDIGITS == SIZEOF_SHORT
big->len = len;
@@ -945,21 +966,26 @@ r_object0(arg, proc)
#endif
big->digits = digits = ALLOC_N(BDIGIT, big->len);
#if SIZEOF_BDIGITS > SIZEOF_SHORT
-
MEMZERO((char *)digits + len * 2, char,
-
big->len * sizeof(BDIGIT) - len * 2);
+#endif
+#if SIZEOF_BDIGITS > SIZEOF_SHORT
int shift = 0;
int i;
#else
#endif
@@ -1191,5 +1217,8 @@ marshal_load(argc, argv)
}
else {
- rb_raise(rb_eTypeError, “instance of IO needed”);
- arg.taint = OBJ_TAINTED(port); /* original taintedness */
- arg.fp = 0;
- arg.ptr = (char *)port;
- arg.end = 0;
}
@@ -1226,4 +1255,7 @@ Init_marshal()
s_load_data = rb_intern(“_load_data”);
s_alloc = rb_intern(“_alloc”);
- s_getc = rb_intern(“getc”);
- s_read = rb_intern(“read”);
- rb_define_module_function(rb_mMarshal, “dump”, marshal_dump, -1);
rb_define_module_function(rb_mMarshal, “load”, marshal_load, -1);
–
Nobu Nakada