mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
1.4.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fcd020c830
commit
65a5162550
156 changed files with 21888 additions and 18301 deletions
49
marshal.c
49
marshal.c
|
|
@ -12,8 +12,12 @@
|
|||
#include "rubyio.h"
|
||||
#include "st.h"
|
||||
|
||||
#ifndef atof
|
||||
double strtod();
|
||||
#endif
|
||||
|
||||
#define MARSHAL_MAJOR 4
|
||||
#define MARSHAL_MINOR 0
|
||||
#define MARSHAL_MINOR 1
|
||||
|
||||
#define TYPE_NIL '0'
|
||||
#define TYPE_TRUE 'T'
|
||||
|
|
@ -37,8 +41,6 @@
|
|||
|
||||
#define TYPE_LINK '@'
|
||||
|
||||
VALUE rb_path2class _((char*));
|
||||
|
||||
static ID s_dump, s_load;
|
||||
|
||||
struct dump_arg {
|
||||
|
|
@ -164,7 +166,7 @@ w_unique(s, arg)
|
|||
static void w_object _((VALUE,struct dump_arg*,int));
|
||||
|
||||
static int
|
||||
rb_hash_each(key, value, arg)
|
||||
hash_each(key, value, arg)
|
||||
VALUE key, value;
|
||||
struct dump_call_arg *arg;
|
||||
{
|
||||
|
|
@ -174,7 +176,7 @@ rb_hash_each(key, value, arg)
|
|||
}
|
||||
|
||||
static int
|
||||
rb_obj_each(id, value, arg)
|
||||
obj_each(id, value, arg)
|
||||
ID id;
|
||||
VALUE value;
|
||||
struct dump_call_arg *arg;
|
||||
|
|
@ -249,9 +251,9 @@ w_object(obj, arg, limit)
|
|||
|
||||
w_byte(TYPE_USERDEF, arg);
|
||||
w_unique(rb_class2name(CLASS_OF(obj)), arg);
|
||||
v = rb_funcall(obj, s_dump, 1, limit);
|
||||
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
|
||||
if (TYPE(v) != T_STRING) {
|
||||
rb_raise(rb_eTypeError, "_dump_to must return String");
|
||||
rb_raise(rb_eTypeError, "_dump() must return String");
|
||||
}
|
||||
w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg);
|
||||
return;
|
||||
|
|
@ -320,7 +322,7 @@ w_object(obj, arg, limit)
|
|||
w_uclass(obj, rb_cHash, arg);
|
||||
w_byte(TYPE_HASH, arg);
|
||||
w_long(RHASH(obj)->tbl->num_entries, arg);
|
||||
st_foreach(RHASH(obj)->tbl, rb_hash_each, &c_arg);
|
||||
st_foreach(RHASH(obj)->tbl, hash_each, &c_arg);
|
||||
break;
|
||||
|
||||
case T_STRUCT:
|
||||
|
|
@ -357,7 +359,7 @@ w_object(obj, arg, limit)
|
|||
w_unique(path, arg);
|
||||
if (ROBJECT(obj)->iv_tbl) {
|
||||
w_long(ROBJECT(obj)->iv_tbl->num_entries, arg);
|
||||
st_foreach(ROBJECT(obj)->iv_tbl, rb_obj_each, &c_arg);
|
||||
st_foreach(ROBJECT(obj)->iv_tbl, obj_each, &c_arg);
|
||||
}
|
||||
else {
|
||||
w_long(0, arg);
|
||||
|
|
@ -455,9 +457,19 @@ static int
|
|||
r_byte(arg)
|
||||
struct load_arg *arg;
|
||||
{
|
||||
if (arg->fp) return getc(arg->fp);
|
||||
if (arg->ptr < arg->end) return *(unsigned char*)arg->ptr++;
|
||||
return EOF;
|
||||
int c;
|
||||
|
||||
if (arg->fp) {
|
||||
c = rb_getc(arg->fp);
|
||||
if (c == EOF) rb_eof_error();
|
||||
}
|
||||
else if (arg->ptr < arg->end) {
|
||||
c = *(unsigned char*)arg->ptr++;
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eArgError, "marshal data too short");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static unsigned short
|
||||
|
|
@ -602,10 +614,6 @@ r_object(arg)
|
|||
int type = r_byte(arg);
|
||||
|
||||
switch (type) {
|
||||
case EOF:
|
||||
rb_eof_error();
|
||||
return Qnil;
|
||||
|
||||
case TYPE_LINK:
|
||||
if (st_lookup(arg->data, r_long(arg), &v)) {
|
||||
return v;
|
||||
|
|
@ -641,13 +649,10 @@ r_object(arg)
|
|||
|
||||
case TYPE_FLOAT:
|
||||
{
|
||||
#ifndef atof
|
||||
double atof();
|
||||
#endif
|
||||
char *buf;
|
||||
|
||||
r_bytes(buf, arg);
|
||||
v = rb_float_new(atof(buf));
|
||||
v = rb_float_new(strtod(buf, 0));
|
||||
return r_regist(v, arg);
|
||||
}
|
||||
|
||||
|
|
@ -754,7 +759,7 @@ r_object(arg)
|
|||
v = rb_funcall(klass, s_load, 1, r_string(arg));
|
||||
return r_regist(v, arg);
|
||||
}
|
||||
rb_raise(rb_eTypeError, "class %s needs to have method `_load_from'",
|
||||
rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
|
||||
rb_class2name(klass));
|
||||
}
|
||||
break;
|
||||
|
|
@ -850,7 +855,7 @@ marshal_load(argc, argv)
|
|||
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eTypeError, "Old marshal file format (can't read)");
|
||||
rb_raise(rb_eTypeError, "old marshal file format (can't read)");
|
||||
}
|
||||
|
||||
return v;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue