2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
marshal.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Thu Apr 27 16:30:01 JST 1995
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
|
|
|
|
**********************************************************************/
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/io.h"
|
|
|
|
#include "ruby/st.h"
|
|
|
|
#include "ruby/util.h"
|
2007-10-19 15:08:16 +04:00
|
|
|
#include "ruby/encoding.h"
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2003-01-15 09:29:05 +03:00
|
|
|
#include <math.h>
|
2003-04-20 19:11:20 +04:00
|
|
|
#ifdef HAVE_FLOAT_H
|
|
|
|
#include <float.h>
|
|
|
|
#endif
|
2003-12-22 11:23:55 +03:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
2003-01-15 09:29:05 +03:00
|
|
|
|
2001-08-29 10:28:51 +04:00
|
|
|
#define BITSPERSHORT (2*CHAR_BIT)
|
2000-10-31 11:37:47 +03:00
|
|
|
#define SHORTMASK ((1<<BITSPERSHORT)-1)
|
|
|
|
#define SHORTDN(x) RSHIFT(x,BITSPERSHORT)
|
|
|
|
|
|
|
|
#if SIZEOF_SHORT == SIZEOF_BDIGITS
|
|
|
|
#define SHORTLEN(x) (x)
|
|
|
|
#else
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
shortlen(long len, BDIGIT *ds)
|
2000-10-31 11:37:47 +03:00
|
|
|
{
|
|
|
|
BDIGIT num;
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
num = ds[len-1];
|
|
|
|
while (num) {
|
|
|
|
num = SHORTDN(num);
|
|
|
|
offset++;
|
|
|
|
}
|
2001-08-29 10:28:51 +04:00
|
|
|
return (len - 1)*sizeof(BDIGIT)/2 + offset;
|
2000-10-31 11:37:47 +03:00
|
|
|
}
|
|
|
|
#define SHORTLEN(x) shortlen((x),d)
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
#define MARSHAL_MAJOR 4
|
* parse.y, compile.c, gc.c, insns.def, intern.h, iseq.c, node.h,
object.c, string.c, variable.c, vm_macro.def: revert private
instance variable feature, which is postponed until next major
release.
* marshal.c: TYPE_SYMBOL2 removed; MARSHAL_MINOR reverted back to
8th version.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-23 05:49:41 +03:00
|
|
|
#define MARSHAL_MINOR 8
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
#define TYPE_NIL '0'
|
|
|
|
#define TYPE_TRUE 'T'
|
|
|
|
#define TYPE_FALSE 'F'
|
|
|
|
#define TYPE_FIXNUM 'i'
|
|
|
|
|
2002-09-05 13:42:56 +04:00
|
|
|
#define TYPE_EXTENDED 'e'
|
1998-01-16 15:19:09 +03:00
|
|
|
#define TYPE_UCLASS 'C'
|
|
|
|
#define TYPE_OBJECT 'o'
|
2002-09-05 13:42:56 +04:00
|
|
|
#define TYPE_DATA 'd'
|
1998-01-16 15:19:09 +03:00
|
|
|
#define TYPE_USERDEF 'u'
|
2003-04-20 19:11:20 +04:00
|
|
|
#define TYPE_USRMARSHAL 'U'
|
1998-01-16 15:19:09 +03:00
|
|
|
#define TYPE_FLOAT 'f'
|
|
|
|
#define TYPE_BIGNUM 'l'
|
|
|
|
#define TYPE_STRING '"'
|
|
|
|
#define TYPE_REGEXP '/'
|
|
|
|
#define TYPE_ARRAY '['
|
|
|
|
#define TYPE_HASH '{'
|
1999-12-01 12:24:48 +03:00
|
|
|
#define TYPE_HASH_DEF '}'
|
1998-01-16 15:19:09 +03:00
|
|
|
#define TYPE_STRUCT 'S'
|
1999-12-01 12:24:48 +03:00
|
|
|
#define TYPE_MODULE_OLD 'M'
|
|
|
|
#define TYPE_CLASS 'c'
|
|
|
|
#define TYPE_MODULE 'm'
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
#define TYPE_SYMBOL ':'
|
|
|
|
#define TYPE_SYMLINK ';'
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
#define TYPE_IVAR 'I'
|
1998-01-16 15:19:09 +03:00
|
|
|
#define TYPE_LINK '@'
|
|
|
|
|
2003-07-29 22:26:55 +04:00
|
|
|
static ID s_dump, s_load, s_mdump, s_mload;
|
2008-10-01 14:11:51 +04:00
|
|
|
static ID s_dump_data, s_load_data, s_alloc, s_call;
|
2008-01-25 19:37:53 +03:00
|
|
|
static ID s_getbyte, s_read, s_write, s_binmode;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2007-10-19 15:08:16 +04:00
|
|
|
ID rb_id_encoding(void);
|
|
|
|
|
2007-09-08 19:07:18 +04:00
|
|
|
typedef struct {
|
|
|
|
VALUE newclass;
|
|
|
|
VALUE oldclass;
|
|
|
|
VALUE (*dumper)(VALUE);
|
|
|
|
VALUE (*loader)(VALUE, VALUE);
|
|
|
|
} marshal_compat_t;
|
|
|
|
|
|
|
|
static st_table *compat_allocator_tbl;
|
2007-09-26 23:12:04 +04:00
|
|
|
static VALUE compat_allocator_tbl_wrapper;
|
|
|
|
|
|
|
|
static int
|
|
|
|
mark_marshal_compat_i(st_data_t key, st_data_t value)
|
|
|
|
{
|
|
|
|
marshal_compat_t *p = (marshal_compat_t *)value;
|
|
|
|
rb_gc_mark(p->newclass);
|
|
|
|
rb_gc_mark(p->oldclass);
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mark_marshal_compat_t(void *tbl)
|
|
|
|
{
|
|
|
|
if (!tbl) return;
|
|
|
|
st_foreach(tbl, mark_marshal_compat_i, 0);
|
|
|
|
}
|
2007-09-08 19:07:18 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE))
|
|
|
|
{
|
|
|
|
marshal_compat_t *compat;
|
|
|
|
rb_alloc_func_t allocator = rb_get_alloc_func(newclass);
|
|
|
|
|
|
|
|
if (!allocator) {
|
|
|
|
rb_raise(rb_eTypeError, "no allocator");
|
|
|
|
}
|
|
|
|
|
|
|
|
compat = ALLOC(marshal_compat_t);
|
|
|
|
compat->newclass = Qnil;
|
|
|
|
compat->oldclass = Qnil;
|
|
|
|
compat->newclass = newclass;
|
|
|
|
compat->oldclass = oldclass;
|
|
|
|
compat->dumper = dumper;
|
|
|
|
compat->loader = loader;
|
|
|
|
|
|
|
|
st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
struct dump_arg {
|
|
|
|
VALUE obj;
|
2002-10-17 14:20:52 +04:00
|
|
|
VALUE str, dest;
|
2003-08-07 01:50:06 +04:00
|
|
|
st_table *symbols;
|
1998-01-16 15:19:09 +03:00
|
|
|
st_table *data;
|
2000-07-21 12:45:34 +04:00
|
|
|
int taint;
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
int untrust;
|
2007-09-08 19:07:18 +04:00
|
|
|
st_table *compat_tbl;
|
2007-09-26 23:40:49 +04:00
|
|
|
VALUE wrapper;
|
2007-10-19 15:08:16 +04:00
|
|
|
st_table *encodings;
|
1998-01-16 15:19:09 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dump_call_arg {
|
|
|
|
VALUE obj;
|
|
|
|
struct dump_arg *arg;
|
|
|
|
int limit;
|
|
|
|
};
|
|
|
|
|
2008-05-22 15:20:56 +04:00
|
|
|
static void
|
2008-10-01 14:11:51 +04:00
|
|
|
check_dump_arg(struct dump_arg *arg, ID sym)
|
2008-05-22 15:20:56 +04:00
|
|
|
{
|
|
|
|
if (!DATA_PTR(arg->wrapper)) {
|
2008-10-01 14:11:51 +04:00
|
|
|
rb_raise(rb_eRuntimeError, "Marshal.dump reentered at %s",
|
|
|
|
rb_id2name(sym));
|
2008-05-22 15:20:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-26 23:40:49 +04:00
|
|
|
static void
|
|
|
|
mark_dump_arg(void *ptr)
|
|
|
|
{
|
|
|
|
struct dump_arg *p = ptr;
|
2007-11-18 14:50:25 +03:00
|
|
|
if (!ptr)
|
|
|
|
return;
|
2007-09-26 23:40:49 +04:00
|
|
|
rb_mark_set(p->data);
|
|
|
|
rb_mark_hash(p->compat_tbl);
|
|
|
|
}
|
|
|
|
|
2004-01-16 08:33:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
class2path(VALUE klass)
|
2004-01-16 08:33:39 +03:00
|
|
|
{
|
|
|
|
VALUE path = rb_class_path(klass);
|
2006-08-31 14:47:44 +04:00
|
|
|
char *n = RSTRING_PTR(path);
|
2004-01-16 08:33:39 +03:00
|
|
|
|
2004-01-17 18:23:59 +03:00
|
|
|
if (n[0] == '#') {
|
|
|
|
rb_raise(rb_eTypeError, "can't dump anonymous %s %s",
|
|
|
|
(TYPE(klass) == T_CLASS ? "class" : "module"),
|
|
|
|
n);
|
|
|
|
}
|
|
|
|
if (rb_path2class(n) != rb_class_real(klass)) {
|
2009-02-10 11:55:40 +03:00
|
|
|
rb_raise(rb_eTypeError, "%s can't be referred to", n);
|
2004-01-16 08:33:39 +03:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 10:32:32 +04:00
|
|
|
static void w_long(long, struct dump_arg*);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2002-10-17 14:20:52 +04:00
|
|
|
static void
|
2005-10-21 10:46:41 +04:00
|
|
|
w_nbyte(const char *s, int n, struct dump_arg *arg)
|
2002-10-17 14:20:52 +04:00
|
|
|
{
|
2003-03-03 10:20:17 +03:00
|
|
|
VALUE buf = arg->str;
|
|
|
|
rb_str_buf_cat(buf, s, n);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) {
|
2003-03-03 10:20:17 +03:00
|
|
|
if (arg->taint) OBJ_TAINT(buf);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (arg->untrust) OBJ_UNTRUST(buf);
|
2003-03-03 10:20:17 +03:00
|
|
|
rb_io_write(arg->dest, buf);
|
|
|
|
rb_str_resize(buf, 0);
|
2002-10-17 14:20:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_byte(char c, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2003-03-03 10:20:17 +03:00
|
|
|
w_nbyte(&c, 1, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-10-21 10:46:41 +04:00
|
|
|
w_bytes(const char *s, int n, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
w_long(n, arg);
|
2003-03-03 10:20:17 +03:00
|
|
|
w_nbyte(s, n, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_short(int x, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2007-03-21 14:38:42 +03:00
|
|
|
w_byte((char)((x >> 0) & 0xff), arg);
|
|
|
|
w_byte((char)((x >> 8) & 0xff), arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_long(long x, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
char buf[sizeof(long)+1];
|
|
|
|
int i, len = 0;
|
|
|
|
|
2000-12-05 12:36:54 +03:00
|
|
|
#if SIZEOF_LONG > 4
|
2001-08-29 10:28:51 +04:00
|
|
|
if (!(RSHIFT(x, 31) == 0 || RSHIFT(x, 31) == -1)) {
|
2000-12-05 12:36:54 +03:00
|
|
|
/* big long does not fit in 4 bytes */
|
|
|
|
rb_raise(rb_eTypeError, "long too big to dump");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
if (x == 0) {
|
|
|
|
w_byte(0, arg);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-05 12:36:54 +03:00
|
|
|
if (0 < x && x < 123) {
|
2007-03-21 14:38:42 +03:00
|
|
|
w_byte((char)(x + 5), arg);
|
2000-12-05 12:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (-124 < x && x < 0) {
|
2007-03-21 14:38:42 +03:00
|
|
|
w_byte((char)((x - 5)&0xff), arg);
|
2000-12-05 12:36:54 +03:00
|
|
|
return;
|
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
for (i=1;i<sizeof(long)+1;i++) {
|
|
|
|
buf[i] = x & 0xff;
|
|
|
|
x = RSHIFT(x,8);
|
|
|
|
if (x == 0) {
|
|
|
|
buf[0] = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (x == -1) {
|
|
|
|
buf[0] = -i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len = i;
|
|
|
|
for (i=0;i<=len;i++) {
|
|
|
|
w_byte(buf[i], arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-20 19:11:20 +04:00
|
|
|
#ifdef DBL_MANT_DIG
|
2003-04-22 14:08:57 +04:00
|
|
|
#define DECIMAL_MANT (53-16) /* from IEEE754 double precision */
|
|
|
|
|
|
|
|
#if DBL_MANT_DIG > 32
|
|
|
|
#define MANT_BITS 32
|
|
|
|
#elif DBL_MANT_DIG > 24
|
|
|
|
#define MANT_BITS 24
|
|
|
|
#elif DBL_MANT_DIG > 16
|
|
|
|
#define MANT_BITS 16
|
|
|
|
#else
|
|
|
|
#define MANT_BITS 8
|
|
|
|
#endif
|
|
|
|
|
2003-04-20 19:11:20 +04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
save_mantissa(double d, char *buf)
|
2003-04-20 19:11:20 +04:00
|
|
|
{
|
2003-04-22 14:08:57 +04:00
|
|
|
int e, i = 0;
|
|
|
|
unsigned long m;
|
|
|
|
double n;
|
|
|
|
|
|
|
|
d = modf(ldexp(frexp(fabs(d), &e), DECIMAL_MANT), &d);
|
|
|
|
if (d > 0) {
|
|
|
|
buf[i++] = 0;
|
|
|
|
do {
|
|
|
|
d = modf(ldexp(d, MANT_BITS), &n);
|
|
|
|
m = (unsigned long)n;
|
|
|
|
#if MANT_BITS > 24
|
|
|
|
buf[i++] = m >> 24;
|
|
|
|
#endif
|
|
|
|
#if MANT_BITS > 16
|
|
|
|
buf[i++] = m >> 16;
|
|
|
|
#endif
|
|
|
|
#if MANT_BITS > 8
|
|
|
|
buf[i++] = m >> 8;
|
|
|
|
#endif
|
|
|
|
buf[i++] = m;
|
|
|
|
} while (d > 0);
|
|
|
|
while (!buf[i - 1]) --i;
|
|
|
|
}
|
|
|
|
return i;
|
2003-04-20 19:11:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
load_mantissa(double d, const char *buf, int len)
|
2003-04-20 19:11:20 +04:00
|
|
|
{
|
2003-04-22 14:08:57 +04:00
|
|
|
if (--len > 0 && !*buf++) { /* binary mantissa mark */
|
|
|
|
int e, s = d < 0, dig = 0;
|
|
|
|
unsigned long m;
|
|
|
|
|
|
|
|
modf(ldexp(frexp(fabs(d), &e), DECIMAL_MANT), &d);
|
|
|
|
do {
|
|
|
|
m = 0;
|
|
|
|
switch (len) {
|
|
|
|
default: m = *buf++ & 0xff;
|
|
|
|
#if MANT_BITS > 24
|
|
|
|
case 3: m = (m << 8) | (*buf++ & 0xff);
|
|
|
|
#endif
|
|
|
|
#if MANT_BITS > 16
|
|
|
|
case 2: m = (m << 8) | (*buf++ & 0xff);
|
|
|
|
#endif
|
|
|
|
#if MANT_BITS > 8
|
|
|
|
case 1: m = (m << 8) | (*buf++ & 0xff);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
dig -= len < MANT_BITS / 8 ? 8 * (unsigned)len : MANT_BITS;
|
|
|
|
d += ldexp((double)m, dig);
|
|
|
|
} while ((len -= MANT_BITS / 8) > 0);
|
|
|
|
d = ldexp(d, e - DECIMAL_MANT);
|
2003-04-20 19:11:20 +04:00
|
|
|
if (s) d = -d;
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define load_mantissa(d, buf, len) (d)
|
|
|
|
#define save_mantissa(d, buf) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DBL_DIG
|
2003-04-21 17:02:08 +04:00
|
|
|
#define FLOAT_DIG (DBL_DIG+2)
|
2003-04-20 19:11:20 +04:00
|
|
|
#else
|
|
|
|
#define FLOAT_DIG 17
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_float(double d, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2007-09-12 10:19:06 +04:00
|
|
|
char buf[FLOAT_DIG + (DECIMAL_MANT + 7) / 8 + 10];
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2001-11-19 08:03:03 +03:00
|
|
|
if (isinf(d)) {
|
|
|
|
if (d < 0) strcpy(buf, "-inf");
|
|
|
|
else strcpy(buf, "inf");
|
|
|
|
}
|
|
|
|
else if (isnan(d)) {
|
|
|
|
strcpy(buf, "nan");
|
|
|
|
}
|
2001-11-27 13:00:35 +03:00
|
|
|
else if (d == 0.0) {
|
|
|
|
if (1.0/d < 0) strcpy(buf, "-0");
|
|
|
|
else strcpy(buf, "0");
|
|
|
|
}
|
2001-11-19 08:03:03 +03:00
|
|
|
else {
|
2003-04-20 19:11:20 +04:00
|
|
|
int len;
|
|
|
|
|
2001-11-19 08:03:03 +03:00
|
|
|
/* xxx: should not use system's sprintf(3) */
|
2007-09-12 10:19:06 +04:00
|
|
|
snprintf(buf, sizeof(buf), "%.*g", FLOAT_DIG, d);
|
2003-04-20 19:11:20 +04:00
|
|
|
len = strlen(buf);
|
|
|
|
w_bytes(buf, len + save_mantissa(d, buf + len), arg);
|
|
|
|
return;
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
w_bytes(buf, strlen(buf), arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_symbol(ID id, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2007-02-04 22:17:33 +03:00
|
|
|
const char *sym;
|
2003-08-16 18:58:34 +04:00
|
|
|
st_data_t num;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2003-08-07 01:50:06 +04:00
|
|
|
if (st_lookup(arg->symbols, id, &num)) {
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_SYMLINK, arg);
|
2003-08-16 18:58:34 +04:00
|
|
|
w_long((long)num, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
else {
|
* parse.y, compile.c, gc.c, insns.def, intern.h, iseq.c, node.h,
object.c, string.c, variable.c, vm_macro.def: revert private
instance variable feature, which is postponed until next major
release.
* marshal.c: TYPE_SYMBOL2 removed; MARSHAL_MINOR reverted back to
8th version.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-23 05:49:41 +03:00
|
|
|
sym = rb_id2name(id);
|
2007-09-26 23:12:04 +04:00
|
|
|
if (!sym) {
|
|
|
|
rb_raise(rb_eTypeError, "can't dump anonymous ID %ld", id);
|
|
|
|
}
|
* parse.y, compile.c, gc.c, insns.def, intern.h, iseq.c, node.h,
object.c, string.c, variable.c, vm_macro.def: revert private
instance variable feature, which is postponed until next major
release.
* marshal.c: TYPE_SYMBOL2 removed; MARSHAL_MINOR reverted back to
8th version.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-23 05:49:41 +03:00
|
|
|
w_byte(TYPE_SYMBOL, arg);
|
|
|
|
w_bytes(sym, strlen(sym), arg);
|
2003-08-07 01:50:06 +04:00
|
|
|
st_add_direct(arg->symbols, id, arg->symbols->num_entries);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-10-21 10:46:41 +04:00
|
|
|
w_unique(const char *s, struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2001-10-05 10:30:42 +04:00
|
|
|
if (s[0] == '#') {
|
2003-05-22 12:30:58 +04:00
|
|
|
rb_raise(rb_eTypeError, "can't dump anonymous class %s", s);
|
2001-10-05 10:30:42 +04:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
w_symbol(rb_intern(s), arg);
|
|
|
|
}
|
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 10:32:32 +04:00
|
|
|
static void w_object(VALUE,struct dump_arg*,int);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
hash_each(VALUE key, VALUE value, struct dump_call_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(key, arg->arg, arg->limit);
|
|
|
|
w_object(value, arg->arg, arg->limit);
|
1998-01-16 15:19:09 +03:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_extended(VALUE klass, struct dump_arg *arg, int check)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *path;
|
2002-08-27 12:31:08 +04:00
|
|
|
|
2007-03-20 17:00:07 +03:00
|
|
|
if (check && FL_TEST(klass, FL_SINGLETON)) {
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_M_TBL(klass)->num_entries ||
|
|
|
|
(RCLASS_IV_TBL(klass) && RCLASS_IV_TBL(klass)->num_entries > 1)) {
|
2002-08-27 12:31:08 +04:00
|
|
|
rb_raise(rb_eTypeError, "singleton can't be dumped");
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
klass = RCLASS_SUPER(klass);
|
2002-08-27 12:31:08 +04:00
|
|
|
}
|
2002-09-05 13:42:56 +04:00
|
|
|
while (BUILTIN_TYPE(klass) == T_ICLASS) {
|
|
|
|
path = rb_class2name(RBASIC(klass)->klass);
|
|
|
|
w_byte(TYPE_EXTENDED, arg);
|
|
|
|
w_unique(path, arg);
|
2007-09-28 10:21:46 +04:00
|
|
|
klass = RCLASS_SUPER(klass);
|
2002-09-05 13:42:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-10-21 10:46:41 +04:00
|
|
|
w_class(char type, VALUE obj, struct dump_arg *arg, int check)
|
2002-09-05 13:42:56 +04:00
|
|
|
{
|
2007-02-04 22:17:33 +03:00
|
|
|
volatile VALUE p;
|
2002-09-05 13:42:56 +04:00
|
|
|
char *path;
|
2007-09-26 23:12:04 +04:00
|
|
|
st_data_t real_obj;
|
2007-09-08 19:07:18 +04:00
|
|
|
VALUE klass;
|
2002-09-05 13:42:56 +04:00
|
|
|
|
2007-09-26 23:12:04 +04:00
|
|
|
if (st_lookup(arg->compat_tbl, (st_data_t)obj, &real_obj)) {
|
|
|
|
obj = (VALUE)real_obj;
|
2007-09-08 19:07:18 +04:00
|
|
|
}
|
|
|
|
klass = CLASS_OF(obj);
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
w_extended(klass, arg, check);
|
2002-09-05 13:42:56 +04:00
|
|
|
w_byte(type, arg);
|
2007-02-04 22:17:33 +03:00
|
|
|
p = class2path(rb_class_real(klass));
|
|
|
|
path = RSTRING_PTR(p);
|
2002-08-27 12:31:08 +04:00
|
|
|
w_unique(path, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-22 04:17:52 +03:00
|
|
|
w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
|
2002-08-27 12:31:08 +04:00
|
|
|
{
|
|
|
|
VALUE klass = CLASS_OF(obj);
|
|
|
|
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
w_extended(klass, arg, Qtrue);
|
2003-08-07 01:50:06 +04:00
|
|
|
klass = rb_class_real(klass);
|
2007-11-22 04:17:52 +03:00
|
|
|
if (klass != super) {
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_UCLASS, arg);
|
2006-08-31 14:47:44 +04:00
|
|
|
w_unique(RSTRING_PTR(class2path(klass)), arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-04 21:51:11 +04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_obj_each(ID id, VALUE value, struct dump_call_arg *arg)
|
2003-10-04 21:51:11 +04:00
|
|
|
{
|
2007-10-19 15:08:16 +04:00
|
|
|
if (id == rb_id_encoding()) return ST_CONTINUE;
|
2003-10-04 21:51:11 +04:00
|
|
|
w_symbol(id, arg->arg);
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(value, arg->arg, arg->limit);
|
2003-10-04 21:51:11 +04:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
static void
|
2007-10-19 15:08:16 +04:00
|
|
|
w_encoding(VALUE obj, long num, struct dump_call_arg *arg)
|
2000-01-05 07:41:21 +03:00
|
|
|
{
|
2007-10-19 15:08:16 +04:00
|
|
|
int encidx = rb_enc_get_index(obj);
|
|
|
|
rb_encoding *enc = 0;
|
|
|
|
st_data_t name;
|
|
|
|
|
|
|
|
if (encidx <= 0 || !(enc = rb_enc_from_index(encidx))) {
|
|
|
|
w_long(num, arg->arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
w_long(num + 1, arg->arg);
|
|
|
|
w_symbol(rb_id_encoding(), arg->arg);
|
|
|
|
do {
|
|
|
|
if (!arg->arg->encodings)
|
|
|
|
arg->arg->encodings = st_init_strcasetable();
|
|
|
|
else if (st_lookup(arg->arg->encodings, (st_data_t)rb_enc_name(enc), &name))
|
|
|
|
break;
|
|
|
|
name = (st_data_t)rb_str_new2(rb_enc_name(enc));
|
|
|
|
st_insert(arg->arg->encodings, (st_data_t)rb_enc_name(enc), name);
|
|
|
|
} while (0);
|
|
|
|
w_object(name, arg->arg, arg->limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
w_ivar(VALUE obj, st_table *tbl, struct dump_call_arg *arg)
|
|
|
|
{
|
|
|
|
long num = tbl ? tbl->num_entries : 0;
|
|
|
|
|
|
|
|
w_encoding(obj, num, arg);
|
2000-01-05 07:41:21 +03:00
|
|
|
if (tbl) {
|
2004-09-29 09:15:33 +04:00
|
|
|
st_foreach_safe(tbl, w_obj_each, (st_data_t)arg);
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
static void
|
|
|
|
w_objivar(VALUE obj, struct dump_call_arg *arg)
|
|
|
|
{
|
|
|
|
VALUE *ptr;
|
|
|
|
long i, len, num;
|
|
|
|
|
2008-02-25 19:18:18 +03:00
|
|
|
len = ROBJECT_NUMIV(obj);
|
|
|
|
ptr = ROBJECT_IVPTR(obj);
|
2007-09-28 10:21:46 +04:00
|
|
|
num = 0;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
if (ptr[i] != Qundef)
|
|
|
|
num += 1;
|
|
|
|
|
2007-10-19 15:08:16 +04:00
|
|
|
w_encoding(obj, num, arg);
|
2007-09-28 10:21:46 +04:00
|
|
|
if (num != 0) {
|
|
|
|
rb_ivar_foreach(obj, w_obj_each, (st_data_t)arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
w_object(VALUE obj, struct dump_arg *arg, int limit)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
struct dump_call_arg c_arg;
|
2000-01-17 11:37:53 +03:00
|
|
|
st_table *ivtbl = 0;
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
st_data_t num;
|
2007-10-19 15:08:16 +04:00
|
|
|
int hasiv = 0;
|
|
|
|
#define has_ivars(obj, ivtbl) ((ivtbl = rb_generic_ivar_table(obj)) != 0 || \
|
2008-01-07 05:49:01 +03:00
|
|
|
(!SPECIAL_CONST_P(obj) && !ENCODING_IS_ASCII8BIT(obj)))
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
if (limit == 0) {
|
2000-02-01 06:12:21 +03:00
|
|
|
rb_raise(rb_eArgError, "exceed depth limit");
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2003-08-07 01:50:06 +04:00
|
|
|
|
2003-08-08 07:48:33 +04:00
|
|
|
limit--;
|
|
|
|
c_arg.limit = limit;
|
|
|
|
c_arg.arg = arg;
|
|
|
|
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
if (st_lookup(arg->data, obj, &num)) {
|
|
|
|
w_byte(TYPE_LINK, arg);
|
|
|
|
w_long((long)num, arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-19 15:08:16 +04:00
|
|
|
if ((hasiv = has_ivars(obj, ivtbl)) != 0) {
|
2003-08-07 01:50:06 +04:00
|
|
|
w_byte(TYPE_IVAR, arg);
|
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
if (obj == Qnil) {
|
|
|
|
w_byte(TYPE_NIL, arg);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (obj == Qtrue) {
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_TRUE, arg);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (obj == Qfalse) {
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_FALSE, arg);
|
|
|
|
}
|
|
|
|
else if (FIXNUM_P(obj)) {
|
|
|
|
#if SIZEOF_LONG <= 4
|
|
|
|
w_byte(TYPE_FIXNUM, arg);
|
|
|
|
w_long(FIX2INT(obj), arg);
|
|
|
|
#else
|
2001-08-23 10:02:15 +04:00
|
|
|
if (RSHIFT((long)obj, 31) == 0 || RSHIFT((long)obj, 31) == -1) {
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_FIXNUM, arg);
|
1999-01-20 07:59:39 +03:00
|
|
|
w_long(FIX2LONG(obj), arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(rb_int2big(FIX2LONG(obj)), arg, limit);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2000-03-07 11:37:59 +03:00
|
|
|
else if (SYMBOL_P(obj)) {
|
2000-04-10 09:48:43 +04:00
|
|
|
w_symbol(SYM2ID(obj), arg);
|
2000-03-07 11:37:59 +03:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
else {
|
2000-07-21 12:45:34 +04:00
|
|
|
if (OBJ_TAINTED(obj)) arg->taint = Qtrue;
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (OBJ_UNTRUSTED(obj)) arg->untrust = Qtrue;
|
2000-07-21 12:45:34 +04:00
|
|
|
|
2008-06-18 07:05:33 +04:00
|
|
|
if (rb_respond_to(obj, s_mdump)) {
|
2008-04-11 03:10:49 +04:00
|
|
|
volatile VALUE v;
|
2003-07-29 22:26:55 +04:00
|
|
|
|
2008-04-10 12:41:46 +04:00
|
|
|
st_add_direct(arg->data, obj, arg->data->num_entries);
|
|
|
|
|
2003-07-30 11:24:11 +04:00
|
|
|
v = rb_funcall(obj, s_mdump, 0, 0);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_dump_arg(arg, s_mdump);
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
w_class(TYPE_USRMARSHAL, obj, arg, Qfalse);
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(v, arg, limit);
|
2007-10-19 15:08:16 +04:00
|
|
|
if (hasiv) w_ivar(obj, 0, &c_arg);
|
2003-07-29 22:26:55 +04:00
|
|
|
return;
|
|
|
|
}
|
2008-06-18 07:05:33 +04:00
|
|
|
if (rb_respond_to(obj, s_dump)) {
|
1998-01-16 15:19:09 +03:00
|
|
|
VALUE v;
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 12:09:38 +03:00
|
|
|
st_table *ivtbl2 = 0;
|
|
|
|
int hasiv2;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
|
2008-10-01 14:11:51 +04:00
|
|
|
check_dump_arg(arg, s_dump);
|
2003-07-31 12:42:44 +04:00
|
|
|
if (TYPE(v) != T_STRING) {
|
|
|
|
rb_raise(rb_eTypeError, "_dump() must return string");
|
|
|
|
}
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 12:09:38 +03:00
|
|
|
if ((hasiv2 = has_ivars(v, ivtbl2)) != 0 && !hasiv) {
|
2003-10-09 21:45:53 +04:00
|
|
|
w_byte(TYPE_IVAR, arg);
|
|
|
|
}
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
w_class(TYPE_USERDEF, obj, arg, Qfalse);
|
2006-08-31 14:47:44 +04:00
|
|
|
w_bytes(RSTRING_PTR(v), RSTRING_LEN(v), arg);
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 12:09:38 +03:00
|
|
|
if (hasiv2) {
|
2008-01-26 13:31:11 +03:00
|
|
|
w_ivar(v, ivtbl2, &c_arg);
|
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 12:09:38 +03:00
|
|
|
}
|
|
|
|
else if (hasiv) {
|
2007-10-19 15:08:16 +04:00
|
|
|
w_ivar(obj, ivtbl, &c_arg);
|
2003-10-09 21:45:53 +04:00
|
|
|
}
|
2008-04-10 12:41:46 +04:00
|
|
|
st_add_direct(arg->data, obj, arg->data->num_entries);
|
1998-01-16 15:19:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-10 12:41:46 +04:00
|
|
|
st_add_direct(arg->data, obj, arg->data->num_entries);
|
|
|
|
|
|
|
|
{
|
|
|
|
st_data_t compat_data;
|
|
|
|
rb_alloc_func_t allocator = rb_get_alloc_func(RBASIC(obj)->klass);
|
|
|
|
if (st_lookup(compat_allocator_tbl,
|
|
|
|
(st_data_t)allocator,
|
|
|
|
&compat_data)) {
|
|
|
|
marshal_compat_t *compat = (marshal_compat_t*)compat_data;
|
|
|
|
VALUE real_obj = obj;
|
|
|
|
obj = compat->dumper(real_obj);
|
|
|
|
st_insert(arg->compat_tbl, (st_data_t)obj, (st_data_t)real_obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
switch (BUILTIN_TYPE(obj)) {
|
|
|
|
case T_CLASS:
|
2001-05-11 09:24:59 +04:00
|
|
|
if (FL_TEST(obj, FL_SINGLETON)) {
|
|
|
|
rb_raise(rb_eTypeError, "singleton class can't be dumped");
|
|
|
|
}
|
1999-12-01 12:24:48 +03:00
|
|
|
w_byte(TYPE_CLASS, arg);
|
|
|
|
{
|
2007-02-04 22:17:33 +03:00
|
|
|
volatile VALUE path = class2path(obj);
|
2006-08-31 14:47:44 +04:00
|
|
|
w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
break;
|
1999-12-01 12:24:48 +03:00
|
|
|
|
|
|
|
case T_MODULE:
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_MODULE, arg);
|
|
|
|
{
|
2004-01-16 08:33:39 +03:00
|
|
|
VALUE path = class2path(obj);
|
2006-08-31 14:47:44 +04:00
|
|
|
w_bytes(RSTRING_PTR(path), RSTRING_LEN(path), arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case T_FLOAT:
|
|
|
|
w_byte(TYPE_FLOAT, arg);
|
* include/ruby/ruby.h: introduce 2 macros:
RFLOAT_VALUE(v), DOUBLE2NUM(dbl).
Rename RFloat#value -> RFloat#double_value.
Do not touch RFloat#double_value directly.
* bignum.c, insns.def, marshal.c, math.c, numeric.c, object.c,
pack.c, parse.y, process.c, random.c, sprintf.c, string.c,
time.c: apply above changes.
* ext/dl/mkcallback.rb, ext/json/ext/generator/generator.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 19:00:53 +03:00
|
|
|
w_float(RFLOAT_VALUE(obj), arg);
|
2000-01-05 07:41:21 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case T_BIGNUM:
|
|
|
|
w_byte(TYPE_BIGNUM, arg);
|
|
|
|
{
|
2007-09-01 16:02:36 +04:00
|
|
|
char sign = RBIGNUM_SIGN(obj) ? '+' : '-';
|
|
|
|
long len = RBIGNUM_LEN(obj);
|
|
|
|
BDIGIT *d = RBIGNUM_DIGITS(obj);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
w_byte(sign, arg);
|
2000-11-20 10:31:55 +03:00
|
|
|
w_long(SHORTLEN(len), arg); /* w_short? */
|
1998-01-16 15:19:09 +03:00
|
|
|
while (len--) {
|
2000-10-31 11:37:47 +03:00
|
|
|
#if SIZEOF_BDIGITS > SIZEOF_SHORT
|
|
|
|
BDIGIT num = *d;
|
|
|
|
int i;
|
|
|
|
|
2001-03-26 12:57:16 +04:00
|
|
|
for (i=0; i<SIZEOF_BDIGITS; i+=SIZEOF_SHORT) {
|
2000-10-31 11:37:47 +03:00
|
|
|
w_short(num & SHORTMASK, arg);
|
|
|
|
num = SHORTDN(num);
|
2001-03-26 12:57:16 +04:00
|
|
|
if (len == 0 && num == 0) break;
|
2000-10-31 11:37:47 +03:00
|
|
|
}
|
|
|
|
#else
|
1998-01-16 15:19:09 +03:00
|
|
|
w_short(*d, arg);
|
2000-10-31 11:37:47 +03:00
|
|
|
#endif
|
1998-01-16 15:19:09 +03:00
|
|
|
d++;
|
|
|
|
}
|
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case T_STRING:
|
1999-01-20 07:59:39 +03:00
|
|
|
w_uclass(obj, rb_cString, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_STRING, arg);
|
2006-08-31 14:47:44 +04:00
|
|
|
w_bytes(RSTRING_PTR(obj), RSTRING_LEN(obj), arg);
|
2000-01-05 07:41:21 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case T_REGEXP:
|
2008-06-28 16:25:45 +04:00
|
|
|
w_uclass(obj, rb_cRegexp, arg);
|
|
|
|
w_byte(TYPE_REGEXP, arg);
|
|
|
|
{
|
|
|
|
int opts = rb_reg_options(obj);
|
|
|
|
w_bytes(RREGEXP_SRC_PTR(obj), RREGEXP_SRC_LEN(obj), arg);
|
|
|
|
w_byte((char)opts, arg);
|
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case T_ARRAY:
|
1999-01-20 07:59:39 +03:00
|
|
|
w_uclass(obj, rb_cArray, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
w_byte(TYPE_ARRAY, arg);
|
|
|
|
{
|
2008-06-02 19:29:11 +04:00
|
|
|
long i, len = RARRAY_LEN(obj);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
w_long(len, arg);
|
2008-06-02 19:29:11 +04:00
|
|
|
for (i=0; i<RARRAY_LEN(obj); i++) {
|
|
|
|
w_object(RARRAY_PTR(obj)[i], arg, limit);
|
|
|
|
if (len != RARRAY_LEN(obj)) {
|
|
|
|
rb_raise(rb_eRuntimeError, "array modified during dump");
|
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_HASH:
|
1999-01-20 07:59:39 +03:00
|
|
|
w_uclass(obj, rb_cHash, arg);
|
2002-08-29 13:08:18 +04:00
|
|
|
if (NIL_P(RHASH(obj)->ifnone)) {
|
|
|
|
w_byte(TYPE_HASH, arg);
|
|
|
|
}
|
|
|
|
else if (FL_TEST(obj, FL_USER2)) {
|
|
|
|
/* FL_USER2 means HASH_PROC_DEFAULT (see hash.c) */
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't dump hash with default proc");
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-08-29 13:08:18 +04:00
|
|
|
w_byte(TYPE_HASH_DEF, arg);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
2007-08-30 03:12:21 +04:00
|
|
|
w_long(RHASH_SIZE(obj), arg);
|
2004-09-29 09:15:33 +04:00
|
|
|
rb_hash_foreach(obj, hash_each, (st_data_t)&c_arg);
|
1999-12-01 12:24:48 +03:00
|
|
|
if (!NIL_P(RHASH(obj)->ifnone)) {
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(RHASH(obj)->ifnone, arg, limit);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_STRUCT:
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
w_class(TYPE_STRUCT, obj, arg, Qtrue);
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2006-02-05 17:40:01 +03:00
|
|
|
long len = RSTRUCT_LEN(obj);
|
1998-01-16 15:19:09 +03:00
|
|
|
VALUE mem;
|
2000-11-20 10:31:55 +03:00
|
|
|
long i;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
w_long(len, arg);
|
2004-09-27 08:46:54 +04:00
|
|
|
mem = rb_struct_members(obj);
|
1998-01-16 15:19:09 +03:00
|
|
|
for (i=0; i<len; i++) {
|
2006-09-02 18:42:08 +04:00
|
|
|
w_symbol(SYM2ID(RARRAY_PTR(mem)[i]), arg);
|
2006-02-05 17:40:01 +03:00
|
|
|
w_object(RSTRUCT_PTR(obj)[i], arg, limit);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_OBJECT:
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
w_class(TYPE_OBJECT, obj, arg, Qtrue);
|
2007-09-28 10:21:46 +04:00
|
|
|
w_objivar(obj, &c_arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
break;
|
|
|
|
|
2003-04-09 09:08:25 +04:00
|
|
|
case T_DATA:
|
|
|
|
{
|
|
|
|
VALUE v;
|
|
|
|
|
2008-06-18 07:05:33 +04:00
|
|
|
if (!rb_respond_to(obj, s_dump_data)) {
|
2003-04-09 09:08:25 +04:00
|
|
|
rb_raise(rb_eTypeError,
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-22 07:00:03 +03:00
|
|
|
"no marshal_dump is defined for class %s",
|
2003-04-09 09:08:25 +04:00
|
|
|
rb_obj_classname(obj));
|
|
|
|
}
|
|
|
|
v = rb_funcall(obj, s_dump_data, 0);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_dump_arg(arg, s_dump_data);
|
2007-03-20 17:00:07 +03:00
|
|
|
w_class(TYPE_DATA, obj, arg, Qtrue);
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(v, arg, limit);
|
2003-04-09 09:08:25 +04:00
|
|
|
}
|
|
|
|
break;
|
2002-04-24 08:54:16 +04:00
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't dump %s",
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_obj_classname(obj));
|
1998-01-16 15:19:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-19 15:08:16 +04:00
|
|
|
if (hasiv) {
|
|
|
|
w_ivar(obj, ivtbl, &c_arg);
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
dump(struct dump_call_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2003-10-09 21:45:53 +04:00
|
|
|
w_object(arg->obj, arg->arg, arg->limit);
|
2002-10-17 14:20:52 +04:00
|
|
|
if (arg->arg->dest) {
|
|
|
|
rb_io_write(arg->arg->dest, arg->arg->str);
|
|
|
|
rb_str_resize(arg->arg->str, 0);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return 0;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
dump_ensure(struct dump_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2008-05-22 15:20:56 +04:00
|
|
|
if (!DATA_PTR(arg->wrapper)) return 0;
|
2003-08-07 01:50:06 +04:00
|
|
|
st_free_table(arg->symbols);
|
1998-01-16 15:19:09 +03:00
|
|
|
st_free_table(arg->data);
|
2007-09-26 23:12:04 +04:00
|
|
|
st_free_table(arg->compat_tbl);
|
2008-08-04 09:08:57 +04:00
|
|
|
if (arg->encodings) st_free_table(arg->encodings);
|
2007-09-26 23:40:49 +04:00
|
|
|
DATA_PTR(arg->wrapper) = 0;
|
|
|
|
arg->wrapper = 0;
|
2003-03-03 10:20:17 +03:00
|
|
|
if (arg->taint) {
|
2000-07-21 12:45:34 +04:00
|
|
|
OBJ_TAINT(arg->str);
|
|
|
|
}
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (arg->untrust) {
|
|
|
|
OBJ_UNTRUST(arg->str);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return 0;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 19:07:43 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* dump( obj [, anIO] , limit=--1 ) => anIO
|
|
|
|
*
|
|
|
|
* Serializes obj and all descendent objects. If anIO is
|
|
|
|
* specified, the serialized data will be written to it, otherwise the
|
|
|
|
* data will be returned as a String. If limit is specified, the
|
|
|
|
* traversal of subobjects will be limited to that depth. If limit is
|
|
|
|
* negative, no checking of depth will be performed.
|
|
|
|
*
|
|
|
|
* class Klass
|
|
|
|
* def initialize(str)
|
|
|
|
* @str = str
|
|
|
|
* end
|
|
|
|
* def sayHello
|
|
|
|
* @str
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* (produces no output)
|
|
|
|
*
|
|
|
|
* o = Klass.new("hello\n")
|
|
|
|
* data = Marshal.dump(o)
|
|
|
|
* obj = Marshal.load(data)
|
|
|
|
* obj.sayHello #=> "hello\n"
|
|
|
|
*/
|
1998-01-16 15:19:09 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
marshal_dump(int argc, VALUE *argv)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
VALUE obj, port, a1, a2;
|
|
|
|
int limit = -1;
|
|
|
|
struct dump_arg arg;
|
|
|
|
struct dump_call_arg c_arg;
|
|
|
|
|
2003-04-08 09:40:29 +04:00
|
|
|
port = Qnil;
|
1998-01-16 15:19:09 +03:00
|
|
|
rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
|
|
|
|
if (argc == 3) {
|
2000-04-12 09:06:23 +04:00
|
|
|
if (!NIL_P(a2)) limit = NUM2INT(a2);
|
2003-04-08 09:40:29 +04:00
|
|
|
if (NIL_P(a1)) goto type_error;
|
1998-01-16 15:19:09 +03:00
|
|
|
port = a1;
|
|
|
|
}
|
|
|
|
else if (argc == 2) {
|
|
|
|
if (FIXNUM_P(a1)) limit = FIX2INT(a1);
|
2003-04-08 09:40:29 +04:00
|
|
|
else if (NIL_P(a1)) goto type_error;
|
1998-01-16 15:19:09 +03:00
|
|
|
else port = a1;
|
|
|
|
}
|
2002-10-17 14:20:52 +04:00
|
|
|
arg.dest = 0;
|
2008-10-01 13:57:38 +04:00
|
|
|
arg.symbols = st_init_numtable();
|
|
|
|
arg.data = st_init_numtable();
|
|
|
|
arg.taint = Qfalse;
|
|
|
|
arg.untrust = Qfalse;
|
|
|
|
arg.compat_tbl = st_init_numtable();
|
|
|
|
arg.encodings = 0;
|
|
|
|
arg.str = rb_str_buf_new(0);
|
|
|
|
RBASIC(arg.str)->klass = 0;
|
|
|
|
arg.wrapper = Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, &arg);
|
2003-04-08 09:40:29 +04:00
|
|
|
if (!NIL_P(port)) {
|
2008-06-18 07:05:33 +04:00
|
|
|
if (!rb_respond_to(port, s_write)) {
|
2003-04-08 09:40:29 +04:00
|
|
|
type_error:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eTypeError, "instance of IO needed");
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2003-03-03 10:20:17 +03:00
|
|
|
arg.dest = port;
|
2008-06-18 07:05:33 +04:00
|
|
|
if (rb_respond_to(port, s_binmode)) {
|
2003-03-03 10:20:17 +03:00
|
|
|
rb_funcall2(port, s_binmode, 0, 0);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_dump_arg(&arg, s_binmode);
|
2003-03-03 10:20:17 +03:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-10-01 13:57:38 +04:00
|
|
|
port = arg.str;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
2003-08-07 01:50:06 +04:00
|
|
|
c_arg.obj = obj;
|
|
|
|
c_arg.arg = &arg;
|
1998-01-16 15:19:09 +03:00
|
|
|
c_arg.limit = limit;
|
|
|
|
|
|
|
|
w_byte(MARSHAL_MAJOR, &arg);
|
|
|
|
w_byte(MARSHAL_MINOR, &arg);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ensure(dump, (VALUE)&c_arg, dump_ensure, (VALUE)&arg);
|
2008-10-01 13:57:38 +04:00
|
|
|
RBASIC(arg.str)->klass = rb_cString;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct load_arg {
|
2004-10-05 05:37:46 +04:00
|
|
|
VALUE src;
|
|
|
|
long offset;
|
2003-08-07 01:50:06 +04:00
|
|
|
st_table *symbols;
|
2008-09-02 06:47:38 +04:00
|
|
|
st_table *data;
|
1998-01-16 15:19:09 +03:00
|
|
|
VALUE proc;
|
2000-07-21 12:45:34 +04:00
|
|
|
int taint;
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
int untrust;
|
2007-09-08 19:07:18 +04:00
|
|
|
st_table *compat_tbl;
|
2008-09-02 06:47:38 +04:00
|
|
|
VALUE wrapper;
|
1998-01-16 15:19:09 +03:00
|
|
|
};
|
|
|
|
|
2008-05-22 15:20:56 +04:00
|
|
|
static void
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(struct load_arg *arg, ID sym)
|
2008-05-22 15:20:56 +04:00
|
|
|
{
|
2008-09-02 06:47:38 +04:00
|
|
|
if (!DATA_PTR(arg->wrapper)) {
|
2008-10-01 14:11:51 +04:00
|
|
|
rb_raise(rb_eRuntimeError, "Marshal.load reentered at %s",
|
|
|
|
rb_id2name(sym));
|
2008-05-22 15:20:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-02 06:47:38 +04:00
|
|
|
static void
|
|
|
|
mark_load_arg(void *ptr)
|
|
|
|
{
|
|
|
|
struct load_arg *p = ptr;
|
|
|
|
if (!ptr)
|
|
|
|
return;
|
|
|
|
rb_mark_tbl(p->data);
|
|
|
|
rb_mark_hash(p->compat_tbl);
|
|
|
|
}
|
|
|
|
|
2007-02-04 22:17:33 +03:00
|
|
|
static VALUE r_entry(VALUE v, struct load_arg *arg);
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 10:32:32 +04:00
|
|
|
static VALUE r_object(struct load_arg *arg);
|
2007-02-04 22:17:33 +03:00
|
|
|
static VALUE path2class(const char *path);
|
2000-01-05 07:41:21 +03:00
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_byte(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
int c;
|
|
|
|
|
2004-10-05 05:37:46 +04:00
|
|
|
if (TYPE(arg->src) == T_STRING) {
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(arg->src) > arg->offset) {
|
|
|
|
c = (unsigned char)RSTRING_PTR(arg->src)[arg->offset++];
|
2004-10-05 05:37:46 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eArgError, "marshal data too short");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE src = arg->src;
|
2008-01-25 19:37:53 +03:00
|
|
|
VALUE v = rb_funcall2(src, s_getbyte, 0, 0);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(arg, s_getbyte);
|
2002-10-17 14:20:52 +04:00
|
|
|
if (NIL_P(v)) rb_eof_error();
|
2006-08-16 12:47:18 +04:00
|
|
|
c = (unsigned char)NUM2CHR(v);
|
2002-10-17 14:20:52 +04:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
return c;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
long_toobig(int size)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2008-07-12 17:17:29 +04:00
|
|
|
rb_raise(rb_eTypeError, "long too big for this architecture (size "
|
|
|
|
STRINGIZE(SIZEOF_LONG)", given %d)", size);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
2001-08-29 10:28:51 +04:00
|
|
|
#undef SIGN_EXTEND_CHAR
|
|
|
|
#if __STDC__
|
|
|
|
# define SIGN_EXTEND_CHAR(c) ((signed char)(c))
|
|
|
|
#else /* not __STDC__ */
|
|
|
|
/* As in Harbison and Steele. */
|
|
|
|
# define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static long
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_long(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
register long x;
|
2001-08-29 10:28:51 +04:00
|
|
|
int c = SIGN_EXTEND_CHAR(r_byte(arg));
|
|
|
|
long i;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
if (c == 0) return 0;
|
|
|
|
if (c > 0) {
|
2000-12-05 12:36:54 +03:00
|
|
|
if (4 < c && c < 128) {
|
|
|
|
return c - 5;
|
|
|
|
}
|
2000-11-20 10:31:55 +03:00
|
|
|
if (c > sizeof(long)) long_toobig(c);
|
1998-01-16 15:19:09 +03:00
|
|
|
x = 0;
|
|
|
|
for (i=0;i<c;i++) {
|
|
|
|
x |= (long)r_byte(arg) << (8*i);
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else {
|
2000-12-05 12:36:54 +03:00
|
|
|
if (-129 < c && c < -4) {
|
|
|
|
return c + 5;
|
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
c = -c;
|
2000-11-20 10:31:55 +03:00
|
|
|
if (c > sizeof(long)) long_toobig(c);
|
1998-01-16 15:19:09 +03:00
|
|
|
x = -1;
|
|
|
|
for (i=0;i<c;i++) {
|
2001-08-29 10:28:51 +04:00
|
|
|
x &= ~((long)0xff << (8*i));
|
1998-01-16 15:19:09 +03:00
|
|
|
x |= (long)r_byte(arg) << (8*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2002-09-04 10:37:39 +04:00
|
|
|
#define r_bytes(arg) r_bytes0(r_long(arg), (arg))
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2002-09-04 10:37:39 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_bytes0(long len, struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2002-09-04 10:37:39 +04:00
|
|
|
VALUE str;
|
|
|
|
|
2004-08-17 13:02:40 +04:00
|
|
|
if (len == 0) return rb_str_new(0, 0);
|
2004-10-05 05:37:46 +04:00
|
|
|
if (TYPE(arg->src) == T_STRING) {
|
2007-10-15 06:45:14 +04:00
|
|
|
if (RSTRING_LEN(arg->src) - arg->offset >= len) {
|
2006-08-31 14:47:44 +04:00
|
|
|
str = rb_str_new(RSTRING_PTR(arg->src)+arg->offset, len);
|
2004-10-05 05:37:46 +04:00
|
|
|
arg->offset += len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
too_short:
|
|
|
|
rb_raise(rb_eArgError, "marshal data too short");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE src = arg->src;
|
2002-10-17 14:20:52 +04:00
|
|
|
VALUE n = LONG2NUM(len);
|
|
|
|
str = rb_funcall2(src, s_read, 1, &n);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(arg, s_read);
|
2002-10-17 14:20:52 +04:00
|
|
|
if (NIL_P(str)) goto too_short;
|
2002-12-19 12:20:20 +03:00
|
|
|
StringValue(str);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) != len) goto too_short;
|
2002-10-17 14:20:52 +04:00
|
|
|
if (OBJ_TAINTED(str)) arg->taint = Qtrue;
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (OBJ_UNTRUSTED(str)) arg->untrust = Qtrue;
|
2002-10-17 14:20:52 +04:00
|
|
|
}
|
2002-09-04 10:37:39 +04:00
|
|
|
return str;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ID
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_symlink(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
ID id;
|
2000-11-20 10:31:55 +03:00
|
|
|
long num = r_long(arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2003-08-07 01:50:06 +04:00
|
|
|
if (st_lookup(arg->symbols, num, &id)) {
|
2000-04-10 09:48:43 +04:00
|
|
|
return id;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2003-05-22 12:30:58 +04:00
|
|
|
rb_raise(rb_eArgError, "bad symbol");
|
2000-04-10 09:48:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static ID
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_symreal(struct load_arg *arg)
|
2000-04-10 09:48:43 +04:00
|
|
|
{
|
2006-08-31 14:47:44 +04:00
|
|
|
volatile VALUE s = r_bytes(arg);
|
2007-02-04 22:17:33 +03:00
|
|
|
ID id = rb_intern(RSTRING_PTR(s));
|
|
|
|
|
|
|
|
st_insert(arg->symbols, arg->symbols->num_entries, id);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2000-04-10 09:48:43 +04:00
|
|
|
static ID
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_symbol(struct load_arg *arg)
|
2000-04-10 09:48:43 +04:00
|
|
|
{
|
2007-02-04 22:17:33 +03:00
|
|
|
int type;
|
|
|
|
|
|
|
|
switch ((type = r_byte(arg))) {
|
|
|
|
case TYPE_SYMBOL:
|
|
|
|
return r_symreal(arg);
|
|
|
|
case TYPE_SYMLINK:
|
2000-04-10 09:48:43 +04:00
|
|
|
return r_symlink(arg);
|
2007-02-04 22:17:33 +03:00
|
|
|
default:
|
|
|
|
rb_raise(rb_eArgError, "dump format error(0x%x)", type);
|
|
|
|
break;
|
2000-04-10 09:48:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
static const char*
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_unique(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
return rb_id2name(r_symbol(arg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_string(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2002-09-04 10:37:39 +04:00
|
|
|
return r_bytes(arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_entry(VALUE v, struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2007-09-26 23:12:04 +04:00
|
|
|
st_data_t real_obj = (VALUE)Qundef;
|
|
|
|
if (st_lookup(arg->compat_tbl, v, &real_obj)) {
|
2008-09-02 06:47:38 +04:00
|
|
|
st_insert(arg->data, arg->data->num_entries, (st_data_t)real_obj);
|
2007-09-08 19:07:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-02 06:47:38 +04:00
|
|
|
st_insert(arg->data, arg->data->num_entries, (st_data_t)v);
|
2007-09-08 19:07:18 +04:00
|
|
|
}
|
|
|
|
if (arg->taint) {
|
|
|
|
OBJ_TAINT(v);
|
2007-09-26 23:12:04 +04:00
|
|
|
if ((VALUE)real_obj != Qundef)
|
|
|
|
OBJ_TAINT((VALUE)real_obj);
|
2007-09-08 19:07:18 +04:00
|
|
|
}
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (arg->untrust) {
|
|
|
|
OBJ_UNTRUST(v);
|
|
|
|
if ((VALUE)real_obj != Qundef)
|
|
|
|
OBJ_UNTRUST((VALUE)real_obj);
|
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2007-09-08 19:07:18 +04:00
|
|
|
static VALUE
|
|
|
|
r_leave(VALUE v, struct load_arg *arg)
|
|
|
|
{
|
2007-09-26 23:12:04 +04:00
|
|
|
st_data_t data;
|
|
|
|
if (st_lookup(arg->compat_tbl, v, &data)) {
|
|
|
|
VALUE real_obj = (VALUE)data;
|
2007-09-08 19:07:18 +04:00
|
|
|
rb_alloc_func_t allocator = rb_get_alloc_func(CLASS_OF(real_obj));
|
|
|
|
st_data_t key = v;
|
2007-09-26 23:12:04 +04:00
|
|
|
if (st_lookup(compat_allocator_tbl, (st_data_t)allocator, &data)) {
|
|
|
|
marshal_compat_t *compat = (marshal_compat_t*)data;
|
2007-09-08 19:07:18 +04:00
|
|
|
compat->loader(real_obj, v);
|
|
|
|
}
|
|
|
|
st_delete(arg->compat_tbl, &key, 0);
|
2007-09-29 12:17:48 +04:00
|
|
|
v = real_obj;
|
|
|
|
}
|
|
|
|
if (arg->proc) {
|
2008-10-01 14:11:51 +04:00
|
|
|
v = rb_funcall(arg->proc, s_call, 1, v);
|
|
|
|
check_load_arg(arg, s_call);
|
2007-09-08 19:07:18 +04:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_ivar(VALUE obj, struct load_arg *arg)
|
2000-01-05 07:41:21 +03:00
|
|
|
{
|
2000-11-20 10:31:55 +03:00
|
|
|
long len;
|
2000-01-05 07:41:21 +03:00
|
|
|
|
|
|
|
len = r_long(arg);
|
|
|
|
if (len > 0) {
|
|
|
|
while (len--) {
|
|
|
|
ID id = r_symbol(arg);
|
|
|
|
VALUE val = r_object(arg);
|
2007-10-19 15:08:16 +04:00
|
|
|
if (id == rb_id_encoding()) {
|
|
|
|
int idx = rb_enc_find_index(StringValueCStr(val));
|
|
|
|
if (idx > 0) rb_enc_associate_index(obj, idx);
|
|
|
|
}
|
2007-11-09 07:37:36 +03:00
|
|
|
else {
|
|
|
|
rb_ivar_set(obj, id, val);
|
|
|
|
}
|
2000-01-05 07:41:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-05 13:42:56 +04:00
|
|
|
static VALUE
|
2005-10-21 10:46:41 +04:00
|
|
|
path2class(const char *path)
|
2002-09-05 13:42:56 +04:00
|
|
|
{
|
|
|
|
VALUE v = rb_path2class(path);
|
|
|
|
|
|
|
|
if (TYPE(v) != T_CLASS) {
|
2009-02-10 11:55:40 +03:00
|
|
|
rb_raise(rb_eArgError, "%s does not refer to class", path);
|
2002-09-05 13:42:56 +04:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2005-10-21 10:46:41 +04:00
|
|
|
path2module(const char *path)
|
2002-09-05 13:42:56 +04:00
|
|
|
{
|
|
|
|
VALUE v = rb_path2class(path);
|
|
|
|
|
|
|
|
if (TYPE(v) != T_MODULE) {
|
2009-02-10 11:55:40 +03:00
|
|
|
rb_raise(rb_eArgError, "%s does not refer to module", path);
|
2002-09-05 13:42:56 +04:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2007-09-08 19:07:18 +04:00
|
|
|
static VALUE
|
|
|
|
obj_alloc_by_path(const char *path, struct load_arg *arg)
|
|
|
|
{
|
|
|
|
VALUE klass;
|
2007-09-26 23:12:04 +04:00
|
|
|
st_data_t data;
|
2007-09-08 19:07:18 +04:00
|
|
|
rb_alloc_func_t allocator;
|
|
|
|
|
|
|
|
klass = path2class(path);
|
|
|
|
|
|
|
|
allocator = rb_get_alloc_func(klass);
|
2007-09-26 23:12:04 +04:00
|
|
|
if (st_lookup(compat_allocator_tbl, (st_data_t)allocator, &data)) {
|
|
|
|
marshal_compat_t *compat = (marshal_compat_t*)data;
|
2007-09-08 19:07:18 +04:00
|
|
|
VALUE real_obj = rb_obj_alloc(klass);
|
|
|
|
VALUE obj = rb_obj_alloc(compat->oldclass);
|
|
|
|
st_insert(arg->compat_tbl, (st_data_t)obj, (st_data_t)real_obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rb_obj_alloc(klass);
|
|
|
|
}
|
|
|
|
|
2009-03-12 12:09:15 +03:00
|
|
|
#if defined _MSC_VER && _MSC_VER >= 1300
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4723)
|
|
|
|
#endif
|
|
|
|
static double
|
|
|
|
div0(double x)
|
|
|
|
{
|
|
|
|
double t = 0.0;
|
|
|
|
return x / t;
|
|
|
|
}
|
|
|
|
#if defined _MSC_VER && _MSC_VER >= 1300
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static VALUE
|
2006-10-23 02:24:14 +04:00
|
|
|
r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2002-02-26 09:48:59 +03:00
|
|
|
VALUE v = Qnil;
|
1998-01-16 15:19:09 +03:00
|
|
|
int type = r_byte(arg);
|
1999-10-20 11:10:23 +04:00
|
|
|
long id;
|
2008-09-02 06:47:38 +04:00
|
|
|
st_data_t link;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_LINK:
|
1999-10-20 11:10:23 +04:00
|
|
|
id = r_long(arg);
|
2008-09-02 06:47:38 +04:00
|
|
|
if (!st_lookup(arg->data, (st_data_t)id, &link)) {
|
1999-10-27 08:20:00 +04:00
|
|
|
rb_raise(rb_eArgError, "dump format error (unlinked)");
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2008-09-02 06:47:38 +04:00
|
|
|
v = (VALUE)link;
|
2006-10-23 02:24:14 +04:00
|
|
|
if (arg->proc) {
|
2008-10-01 14:11:51 +04:00
|
|
|
v = rb_funcall(arg->proc, s_call, 1, v);
|
|
|
|
check_load_arg(arg, s_call);
|
2006-10-23 02:24:14 +04:00
|
|
|
}
|
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
case TYPE_IVAR:
|
2003-10-02 12:25:00 +04:00
|
|
|
{
|
|
|
|
int ivar = Qtrue;
|
|
|
|
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_object0(arg, &ivar, extmod);
|
2003-10-02 12:25:00 +04:00
|
|
|
if (ivar) r_ivar(v, arg);
|
|
|
|
}
|
2002-08-28 19:58:35 +04:00
|
|
|
break;
|
2000-01-05 07:41:21 +03:00
|
|
|
|
2002-09-05 13:42:56 +04:00
|
|
|
case TYPE_EXTENDED:
|
|
|
|
{
|
|
|
|
VALUE m = path2module(r_unique(arg));
|
|
|
|
|
2003-10-20 06:06:42 +04:00
|
|
|
if (NIL_P(extmod)) extmod = rb_ary_new2(0);
|
|
|
|
rb_ary_push(extmod, m);
|
2003-10-15 06:27:56 +04:00
|
|
|
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_object0(arg, 0, extmod);
|
2006-09-02 18:42:08 +04:00
|
|
|
while (RARRAY_LEN(extmod) > 0) {
|
2003-10-20 06:06:42 +04:00
|
|
|
m = rb_ary_pop(extmod);
|
2003-10-15 06:27:56 +04:00
|
|
|
rb_extend_object(v, m);
|
|
|
|
}
|
2002-09-05 13:42:56 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
case TYPE_UCLASS:
|
|
|
|
{
|
2002-09-05 13:42:56 +04:00
|
|
|
VALUE c = path2class(r_unique(arg));
|
2001-10-03 11:19:19 +04:00
|
|
|
|
2002-12-12 10:29:14 +03:00
|
|
|
if (FL_TEST(c, FL_SINGLETON)) {
|
|
|
|
rb_raise(rb_eTypeError, "singleton can't be loaded");
|
|
|
|
}
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_object0(arg, 0, extmod);
|
2001-10-22 10:48:18 +04:00
|
|
|
if (rb_special_const_p(v) || TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS) {
|
|
|
|
format_error:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "dump format error (user class)");
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2004-10-18 18:37:42 +04:00
|
|
|
if (TYPE(v) == T_MODULE || !RTEST(rb_class_inherited_p(c, RBASIC(v)->klass))) {
|
2001-10-22 10:48:18 +04:00
|
|
|
VALUE tmp = rb_obj_alloc(c);
|
|
|
|
|
|
|
|
if (TYPE(v) != TYPE(tmp)) goto format_error;
|
2001-10-03 11:19:19 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
RBASIC(v)->klass = c;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-08-28 19:58:35 +04:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_NIL:
|
2002-02-26 09:48:59 +03:00
|
|
|
v = Qnil;
|
2008-01-31 09:10:56 +03:00
|
|
|
v = r_leave(v, arg);
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_TRUE:
|
2002-02-26 09:48:59 +03:00
|
|
|
v = Qtrue;
|
2008-01-31 09:10:56 +03:00
|
|
|
v = r_leave(v, arg);
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_FALSE:
|
2002-02-26 09:48:59 +03:00
|
|
|
v = Qfalse;
|
2008-01-31 09:10:56 +03:00
|
|
|
v = r_leave(v, arg);
|
2002-02-28 09:53:33 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_FIXNUM:
|
|
|
|
{
|
2000-11-20 10:31:55 +03:00
|
|
|
long i = r_long(arg);
|
2002-08-21 19:47:54 +04:00
|
|
|
v = LONG2FIX(i);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2008-01-31 09:10:56 +03:00
|
|
|
v = r_leave(v, arg);
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_FLOAT:
|
|
|
|
{
|
2009-03-12 12:09:15 +03:00
|
|
|
double d;
|
2002-09-04 10:37:39 +04:00
|
|
|
VALUE str = r_bytes(arg);
|
2006-08-31 14:47:44 +04:00
|
|
|
const char *ptr = RSTRING_PTR(str);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2003-04-20 19:11:20 +04:00
|
|
|
if (strcmp(ptr, "nan") == 0) {
|
2009-03-12 12:09:15 +03:00
|
|
|
d = div0(0.0);
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
2003-04-20 19:11:20 +04:00
|
|
|
else if (strcmp(ptr, "inf") == 0) {
|
2009-03-12 12:09:15 +03:00
|
|
|
d = div0(+1.0);
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
2003-04-20 19:11:20 +04:00
|
|
|
else if (strcmp(ptr, "-inf") == 0) {
|
2009-03-12 12:09:15 +03:00
|
|
|
d = div0(-1.0);
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-04-20 19:11:20 +04:00
|
|
|
char *e;
|
|
|
|
d = strtod(ptr, &e);
|
2006-08-31 14:47:44 +04:00
|
|
|
d = load_mantissa(d, e, RSTRING_LEN(str) - (e - ptr));
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
2008-09-05 22:24:21 +04:00
|
|
|
v = DBL2NUM(d);
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_BIGNUM:
|
|
|
|
{
|
2000-11-20 10:31:55 +03:00
|
|
|
long len;
|
2000-10-31 11:37:47 +03:00
|
|
|
BDIGIT *digits;
|
2005-12-14 06:04:14 +03:00
|
|
|
volatile VALUE data;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
NEWOBJ(big, struct RBignum);
|
1999-01-20 07:59:39 +03:00
|
|
|
OBJSETUP(big, rb_cBignum, T_BIGNUM);
|
2007-09-01 16:02:36 +04:00
|
|
|
RBIGNUM_SET_SIGN(big, (r_byte(arg) == '+'));
|
2000-10-31 11:37:47 +03:00
|
|
|
len = r_long(arg);
|
2002-10-17 14:20:52 +04:00
|
|
|
data = r_bytes0(len * 2, arg);
|
2001-03-22 11:59:26 +03:00
|
|
|
#if SIZEOF_BDIGITS == SIZEOF_SHORT
|
2007-09-01 16:02:36 +04:00
|
|
|
rb_big_resize((VALUE)big, len);
|
2001-03-22 11:59:26 +03:00
|
|
|
#else
|
2007-09-01 16:02:36 +04:00
|
|
|
rb_big_resize((VALUE)big, (len + 1) * 2 / sizeof(BDIGIT));
|
2001-03-22 11:59:26 +03:00
|
|
|
#endif
|
2007-09-01 16:02:36 +04:00
|
|
|
digits = RBIGNUM_DIGITS(big);
|
2006-08-31 14:47:44 +04:00
|
|
|
MEMCPY(digits, RSTRING_PTR(data), char, len * 2);
|
2000-10-31 11:37:47 +03:00
|
|
|
#if SIZEOF_BDIGITS > SIZEOF_SHORT
|
2002-10-17 14:20:52 +04:00
|
|
|
MEMZERO((char *)digits + len * 2, char,
|
2007-09-01 16:02:36 +04:00
|
|
|
RBIGNUM_LEN(big) * sizeof(BDIGIT) - len * 2);
|
2002-10-17 14:20:52 +04:00
|
|
|
#endif
|
2007-09-01 16:02:36 +04:00
|
|
|
len = RBIGNUM_LEN(big);
|
2002-10-17 14:20:52 +04:00
|
|
|
while (len > 0) {
|
|
|
|
unsigned char *p = (unsigned char *)digits;
|
2000-10-31 11:37:47 +03:00
|
|
|
BDIGIT num = 0;
|
2002-10-17 14:20:52 +04:00
|
|
|
#if SIZEOF_BDIGITS > SIZEOF_SHORT
|
2000-10-31 11:37:47 +03:00
|
|
|
int shift = 0;
|
|
|
|
int i;
|
|
|
|
|
2002-10-17 14:20:52 +04:00
|
|
|
for (i=0; i<SIZEOF_BDIGITS; i++) {
|
|
|
|
num |= (int)p[i] << shift;
|
|
|
|
shift += 8;
|
2000-10-31 11:37:47 +03:00
|
|
|
}
|
|
|
|
#else
|
2002-10-17 14:20:52 +04:00
|
|
|
num = p[0] | (p[1] << 8);
|
2000-10-31 11:37:47 +03:00
|
|
|
#endif
|
2002-10-17 14:20:52 +04:00
|
|
|
*digits++ = num;
|
|
|
|
len--;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-27 07:52:21 +03:00
|
|
|
v = rb_big_norm((VALUE)big);
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_STRING:
|
2003-10-02 12:25:00 +04:00
|
|
|
v = r_entry(r_string(arg), arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_REGEXP:
|
|
|
|
{
|
2002-09-04 10:37:39 +04:00
|
|
|
volatile VALUE str = r_bytes(arg);
|
|
|
|
int options = r_byte(arg);
|
2008-01-04 19:30:33 +03:00
|
|
|
v = r_entry(rb_reg_new_str(str, options), arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_ARRAY:
|
|
|
|
{
|
2000-11-20 10:31:55 +03:00
|
|
|
volatile long len = r_long(arg); /* gcc 2.7.2.3 -O2 bug?? */
|
1999-08-24 12:21:56 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
v = rb_ary_new2(len);
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
while (len--) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(v, r_object(arg));
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_HASH:
|
1999-12-01 12:24:48 +03:00
|
|
|
case TYPE_HASH_DEF:
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2000-11-20 10:31:55 +03:00
|
|
|
long len = r_long(arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
v = rb_hash_new();
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
while (len--) {
|
|
|
|
VALUE key = r_object(arg);
|
|
|
|
VALUE value = r_object(arg);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_hash_aset(v, key, value);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
1999-12-02 09:58:52 +03:00
|
|
|
if (type == TYPE_HASH_DEF) {
|
1999-12-01 12:24:48 +03:00
|
|
|
RHASH(v)->ifnone = r_object(arg);
|
|
|
|
}
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
case TYPE_STRUCT:
|
|
|
|
{
|
2007-09-08 19:07:18 +04:00
|
|
|
VALUE klass, mem;
|
2007-09-08 20:29:50 +04:00
|
|
|
VALUE values;
|
2000-11-20 10:31:55 +03:00
|
|
|
volatile long i; /* gcc 2.7.2.3 -O2 bug?? */
|
|
|
|
long len;
|
1998-01-16 15:19:09 +03:00
|
|
|
ID slot;
|
|
|
|
|
2002-09-05 13:42:56 +04:00
|
|
|
klass = path2class(r_unique(arg));
|
1998-01-16 15:19:09 +03:00
|
|
|
len = r_long(arg);
|
|
|
|
|
2007-09-09 20:23:27 +04:00
|
|
|
v = rb_obj_alloc(klass);
|
|
|
|
if (TYPE(v) != T_STRUCT) {
|
|
|
|
rb_raise(rb_eTypeError, "class %s not a struct", rb_class2name(klass));
|
|
|
|
}
|
|
|
|
mem = rb_struct_s_members(klass);
|
2007-09-08 19:07:18 +04:00
|
|
|
if (RARRAY_LEN(mem) != len) {
|
|
|
|
rb_raise(rb_eTypeError, "struct %s not compatible (struct size differs)",
|
|
|
|
rb_class2name(klass));
|
|
|
|
}
|
|
|
|
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
values = rb_ary_new2(len);
|
1998-01-16 15:19:09 +03:00
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
slot = r_symbol(arg);
|
|
|
|
|
2006-09-02 18:42:08 +04:00
|
|
|
if (RARRAY_PTR(mem)[i] != ID2SYM(slot)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eTypeError, "struct %s not compatible (:%s for :%s)",
|
|
|
|
rb_class2name(klass),
|
|
|
|
rb_id2name(slot),
|
2006-09-02 18:42:08 +04:00
|
|
|
rb_id2name(SYM2ID(RARRAY_PTR(mem)[i])));
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2007-09-08 19:07:18 +04:00
|
|
|
rb_ary_push(values, r_object(arg));
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2007-09-08 20:19:13 +04:00
|
|
|
rb_struct_initialize(v, values);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_USERDEF:
|
|
|
|
{
|
2002-09-05 13:42:56 +04:00
|
|
|
VALUE klass = path2class(r_unique(arg));
|
2003-10-02 12:25:00 +04:00
|
|
|
VALUE data;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
2008-06-18 07:05:33 +04:00
|
|
|
if (!rb_respond_to(klass, s_load)) {
|
2002-02-26 09:48:59 +03:00
|
|
|
rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
|
|
|
|
rb_class2name(klass));
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2003-10-02 12:25:00 +04:00
|
|
|
data = r_string(arg);
|
|
|
|
if (ivp) {
|
|
|
|
r_ivar(data, arg);
|
|
|
|
*ivp = Qfalse;
|
|
|
|
}
|
|
|
|
v = rb_funcall(klass, s_load, 1, data);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(arg, s_load);
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-07-29 22:26:55 +04:00
|
|
|
case TYPE_USRMARSHAL:
|
|
|
|
{
|
|
|
|
VALUE klass = path2class(r_unique(arg));
|
2003-10-02 12:25:00 +04:00
|
|
|
VALUE data;
|
2003-07-29 22:26:55 +04:00
|
|
|
|
|
|
|
v = rb_obj_alloc(klass);
|
2007-03-20 17:00:07 +03:00
|
|
|
if (!NIL_P(extmod)) {
|
2006-09-02 18:42:08 +04:00
|
|
|
while (RARRAY_LEN(extmod) > 0) {
|
2003-10-20 06:06:42 +04:00
|
|
|
VALUE m = rb_ary_pop(extmod);
|
2003-10-15 06:27:56 +04:00
|
|
|
rb_extend_object(v, m);
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 07:05:33 +04:00
|
|
|
if (!rb_respond_to(v, s_mload)) {
|
2003-07-29 22:26:55 +04:00
|
|
|
rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'",
|
|
|
|
rb_class2name(klass));
|
|
|
|
}
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2003-10-02 12:25:00 +04:00
|
|
|
data = r_object(arg);
|
|
|
|
rb_funcall(v, s_mload, 1, data);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(arg, s_mload);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
2003-07-29 22:26:55 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
case TYPE_OBJECT:
|
|
|
|
{
|
2007-09-08 19:07:18 +04:00
|
|
|
v = obj_alloc_by_path(r_unique(arg), arg);
|
2001-10-03 11:19:19 +04:00
|
|
|
if (TYPE(v) != T_OBJECT) {
|
|
|
|
rb_raise(rb_eArgError, "dump format error");
|
|
|
|
}
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2000-01-05 07:41:21 +03:00
|
|
|
r_ivar(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
case TYPE_DATA:
|
|
|
|
{
|
2002-09-05 13:42:56 +04:00
|
|
|
VALUE klass = path2class(r_unique(arg));
|
2008-06-18 07:05:33 +04:00
|
|
|
if (rb_respond_to(klass, s_alloc)) {
|
2002-08-29 13:08:18 +04:00
|
|
|
static int warn = Qtrue;
|
|
|
|
if (warn) {
|
|
|
|
rb_warn("define `allocate' instead of `_alloc'");
|
|
|
|
warn = Qfalse;
|
|
|
|
}
|
|
|
|
v = rb_funcall(klass, s_alloc, 0);
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(arg, s_alloc);
|
2002-04-24 08:54:16 +04:00
|
|
|
}
|
2002-08-29 13:08:18 +04:00
|
|
|
else {
|
|
|
|
v = rb_obj_alloc(klass);
|
|
|
|
}
|
2002-04-24 08:54:16 +04:00
|
|
|
if (TYPE(v) != T_DATA) {
|
|
|
|
rb_raise(rb_eArgError, "dump format error");
|
|
|
|
}
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2008-06-18 07:05:33 +04:00
|
|
|
if (!rb_respond_to(v, s_load_data)) {
|
2002-04-24 08:54:16 +04:00
|
|
|
rb_raise(rb_eTypeError,
|
|
|
|
"class %s needs to have instance method `_load_data'",
|
|
|
|
rb_class2name(klass));
|
|
|
|
}
|
2006-10-23 02:24:14 +04:00
|
|
|
rb_funcall(v, s_load_data, 1, r_object0(arg, 0, extmod));
|
2008-10-01 14:11:51 +04:00
|
|
|
check_load_arg(arg, s_load_data);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
2002-04-24 08:54:16 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-01 12:24:48 +03:00
|
|
|
case TYPE_MODULE_OLD:
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2003-04-18 22:05:11 +04:00
|
|
|
volatile VALUE str = r_bytes(arg);
|
2002-09-05 13:42:56 +04:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
v = rb_path2class(RSTRING_PTR(str));
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1998-01-16 15:19:09 +03:00
|
|
|
|
1999-12-01 12:24:48 +03:00
|
|
|
case TYPE_CLASS:
|
|
|
|
{
|
2003-04-18 22:05:11 +04:00
|
|
|
volatile VALUE str = r_bytes(arg);
|
2002-09-05 13:42:56 +04:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
v = path2class(RSTRING_PTR(str));
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
1999-12-01 12:24:48 +03:00
|
|
|
|
|
|
|
case TYPE_MODULE:
|
|
|
|
{
|
2003-04-18 22:05:11 +04:00
|
|
|
volatile VALUE str = r_bytes(arg);
|
2002-09-05 13:42:56 +04:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
v = path2module(RSTRING_PTR(str));
|
2006-10-23 02:24:14 +04:00
|
|
|
v = r_entry(v, arg);
|
2007-09-08 19:07:18 +04:00
|
|
|
v = r_leave(v, arg);
|
1999-12-01 12:24:48 +03:00
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
break;
|
2000-04-10 09:48:43 +04:00
|
|
|
|
2000-03-07 11:37:59 +03:00
|
|
|
case TYPE_SYMBOL:
|
2002-02-26 09:48:59 +03:00
|
|
|
v = ID2SYM(r_symreal(arg));
|
2008-01-31 09:10:56 +03:00
|
|
|
v = r_leave(v, arg);
|
2002-02-27 07:52:21 +03:00
|
|
|
break;
|
2000-04-10 09:48:43 +04:00
|
|
|
|
|
|
|
case TYPE_SYMLINK:
|
2006-10-23 02:24:14 +04:00
|
|
|
v = ID2SYM(r_symlink(arg));
|
2006-10-28 02:57:19 +04:00
|
|
|
break;
|
1999-12-01 12:24:48 +03:00
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "dump format error(0x%x)", type);
|
1998-01-16 15:19:09 +03:00
|
|
|
break;
|
|
|
|
}
|
2002-02-26 09:48:59 +03:00
|
|
|
return v;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
2002-08-28 19:58:35 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
r_object(struct load_arg *arg)
|
2002-08-28 19:58:35 +04:00
|
|
|
{
|
2006-10-23 02:24:14 +04:00
|
|
|
return r_object0(arg, 0, Qnil);
|
2002-08-28 19:58:35 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
load(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
return r_object(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
load_ensure(struct load_arg *arg)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2008-09-02 06:47:38 +04:00
|
|
|
if (!DATA_PTR(arg->wrapper)) return 0;
|
2003-08-07 01:50:06 +04:00
|
|
|
st_free_table(arg->symbols);
|
2008-09-02 06:47:38 +04:00
|
|
|
st_free_table(arg->data);
|
2007-09-26 23:12:04 +04:00
|
|
|
st_free_table(arg->compat_tbl);
|
2008-09-02 06:47:38 +04:00
|
|
|
DATA_PTR(arg->wrapper) = 0;
|
|
|
|
arg->wrapper = 0;
|
1999-01-20 07:59:39 +03:00
|
|
|
return 0;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 19:07:43 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* load( source [, proc] ) => obj
|
|
|
|
* restore( source [, proc] ) => obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 19:07:43 +03:00
|
|
|
* Returns the result of converting the serialized data in source into a
|
|
|
|
* Ruby object (possibly with associated subordinate objects). source
|
|
|
|
* may be either an instance of IO or an object that responds to
|
|
|
|
* to_str. If proc is specified, it will be passed each object as it
|
|
|
|
* is deserialized.
|
|
|
|
*/
|
1998-01-16 15:19:09 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
marshal_load(int argc, VALUE *argv)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
|
|
|
VALUE port, proc;
|
2000-11-20 10:31:55 +03:00
|
|
|
int major, minor;
|
1998-01-16 15:19:09 +03:00
|
|
|
VALUE v;
|
|
|
|
struct load_arg arg;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &port, &proc);
|
2008-05-28 07:52:44 +04:00
|
|
|
v = rb_check_string_type(port);
|
|
|
|
if (!NIL_P(v)) {
|
2001-05-02 08:22:21 +04:00
|
|
|
arg.taint = OBJ_TAINTED(port); /* original taintedness */
|
2008-05-28 07:52:44 +04:00
|
|
|
port = v;
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2008-06-18 07:05:33 +04:00
|
|
|
else if (rb_respond_to(port, s_getbyte) && rb_respond_to(port, s_read)) {
|
|
|
|
if (rb_respond_to(port, s_binmode)) {
|
2003-03-03 10:20:17 +03:00
|
|
|
rb_funcall2(port, s_binmode, 0, 0);
|
|
|
|
}
|
2003-07-29 22:26:55 +04:00
|
|
|
arg.taint = Qtrue;
|
2002-10-17 14:20:52 +04:00
|
|
|
}
|
1998-01-16 15:19:09 +03:00
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eTypeError, "instance of IO needed");
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2008-08-13 13:42:22 +04:00
|
|
|
arg.untrust = OBJ_UNTRUSTED(port);
|
2004-10-05 05:37:46 +04:00
|
|
|
arg.src = port;
|
|
|
|
arg.offset = 0;
|
2008-09-02 06:47:38 +04:00
|
|
|
arg.symbols = st_init_numtable();
|
|
|
|
arg.data = st_init_numtable();
|
2007-09-08 19:07:18 +04:00
|
|
|
arg.compat_tbl = st_init_numtable();
|
2008-09-02 06:47:38 +04:00
|
|
|
arg.proc = 0;
|
|
|
|
arg.wrapper = Data_Wrap_Struct(rb_cData, mark_load_arg, 0, &arg);
|
1998-01-16 15:19:09 +03:00
|
|
|
|
|
|
|
major = r_byte(&arg);
|
2000-11-20 10:31:55 +03:00
|
|
|
minor = r_byte(&arg);
|
2000-11-21 17:31:11 +03:00
|
|
|
if (major != MARSHAL_MAJOR || minor > MARSHAL_MINOR) {
|
2000-11-20 10:31:55 +03:00
|
|
|
rb_raise(rb_eTypeError, "incompatible marshal file format (can't be read)\n\
|
|
|
|
\tformat version %d.%d required; %d.%d given",
|
|
|
|
MARSHAL_MAJOR, MARSHAL_MINOR, major, minor);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2001-07-31 10:24:45 +04:00
|
|
|
if (RTEST(ruby_verbose) && minor != MARSHAL_MINOR) {
|
2000-11-20 10:31:55 +03:00
|
|
|
rb_warn("incompatible marshal file format (can be read)\n\
|
|
|
|
\tformat version %d.%d required; %d.%d given",
|
|
|
|
MARSHAL_MAJOR, MARSHAL_MINOR, major, minor);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
|
|
|
|
2008-09-02 06:47:38 +04:00
|
|
|
if (!NIL_P(proc)) arg.proc = proc;
|
2000-11-20 10:31:55 +03:00
|
|
|
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2003-12-27 19:07:43 +03:00
|
|
|
/*
|
|
|
|
* The marshaling library converts collections of Ruby objects into a
|
|
|
|
* byte stream, allowing them to be stored outside the currently
|
|
|
|
* active script. This data may subsequently be read and the original
|
|
|
|
* objects reconstituted.
|
|
|
|
* Marshaled data has major and minor version numbers stored along
|
|
|
|
* with the object information. In normal use, marshaling can only
|
|
|
|
* load data written with the same major version number and an equal
|
|
|
|
* or lower minor version number. If Ruby's ``verbose'' flag is set
|
|
|
|
* (normally using -d, -v, -w, or --verbose) the major and minor
|
|
|
|
* numbers must match exactly. Marshal versioning is independent of
|
|
|
|
* Ruby's version numbers. You can extract the version by reading the
|
|
|
|
* first two bytes of marshaled data.
|
|
|
|
*
|
|
|
|
* str = Marshal.dump("thing")
|
2008-03-09 04:04:46 +03:00
|
|
|
* RUBY_VERSION #=> "1.9.0"
|
|
|
|
* str[0].ord #=> 4
|
|
|
|
* str[1].ord #=> 8
|
2003-12-27 19:07:43 +03:00
|
|
|
*
|
|
|
|
* Some objects cannot be dumped: if the objects to be dumped include
|
|
|
|
* bindings, procedure or method objects, instances of class IO, or
|
|
|
|
* singleton objects, a TypeError will be raised.
|
|
|
|
* If your class has special serialization needs (for example, if you
|
|
|
|
* want to serialize in some specific format), or if it contains
|
|
|
|
* objects that would otherwise not be serializable, you can implement
|
|
|
|
* your own serialization strategy by defining two methods, _dump and
|
|
|
|
* _load:
|
|
|
|
* The instance method _dump should return a String object containing
|
|
|
|
* all the information necessary to reconstitute objects of this class
|
|
|
|
* and all referenced objects up to a maximum depth given as an integer
|
|
|
|
* parameter (a value of -1 implies that you should disable depth checking).
|
|
|
|
* The class method _load should take a String and return an object of this class.
|
|
|
|
*/
|
1999-01-20 07:59:39 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
Init_marshal(void)
|
1998-01-16 15:19:09 +03:00
|
|
|
{
|
2008-06-09 13:25:32 +04:00
|
|
|
#undef rb_intern
|
2008-08-16 04:20:31 +04:00
|
|
|
#define rb_intern(str) rb_intern_const(str)
|
2008-06-09 13:25:32 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_mMarshal = rb_define_module("Marshal");
|
1998-01-16 15:19:09 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
s_dump = rb_intern("_dump");
|
|
|
|
s_load = rb_intern("_load");
|
2003-07-29 22:26:55 +04:00
|
|
|
s_mdump = rb_intern("marshal_dump");
|
|
|
|
s_mload = rb_intern("marshal_load");
|
2002-04-24 08:54:16 +04:00
|
|
|
s_dump_data = rb_intern("_dump_data");
|
|
|
|
s_load_data = rb_intern("_load_data");
|
|
|
|
s_alloc = rb_intern("_alloc");
|
2008-10-01 14:11:51 +04:00
|
|
|
s_call = rb_intern("call");
|
2008-01-25 19:37:53 +03:00
|
|
|
s_getbyte = rb_intern("getbyte");
|
2002-10-17 14:20:52 +04:00
|
|
|
s_read = rb_intern("read");
|
|
|
|
s_write = rb_intern("write");
|
2003-03-03 10:20:17 +03:00
|
|
|
s_binmode = rb_intern("binmode");
|
2002-10-17 14:20:52 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_module_function(rb_mMarshal, "dump", marshal_dump, -1);
|
|
|
|
rb_define_module_function(rb_mMarshal, "load", marshal_load, -1);
|
2000-06-23 11:05:59 +04:00
|
|
|
rb_define_module_function(rb_mMarshal, "restore", marshal_load, -1);
|
2001-07-31 10:24:45 +04:00
|
|
|
|
2001-07-31 12:33:17 +04:00
|
|
|
rb_define_const(rb_mMarshal, "MAJOR_VERSION", INT2FIX(MARSHAL_MAJOR));
|
|
|
|
rb_define_const(rb_mMarshal, "MINOR_VERSION", INT2FIX(MARSHAL_MINOR));
|
2007-09-08 19:07:18 +04:00
|
|
|
|
|
|
|
compat_allocator_tbl = st_init_numtable();
|
2007-09-26 23:12:04 +04:00
|
|
|
compat_allocator_tbl_wrapper =
|
|
|
|
Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl);
|
* gc.c, include/ruby/ruby.h: rename rb_register_mark_object()
to rb_gc_register_mark_object().
* eval.c, vm.c: initialize vm->mark_object_ary at
Init_top_self().
* bignum.c, complex.c, encoding.c, ext/win32ole/win32ole.c,
io.c, load.c, marshal.c, rational.c, ruby.c, vm.c:
use rb_gc_register_mark_object() instead of
rb_global_variable() or rb_gc_register_address().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-15 18:59:14 +04:00
|
|
|
rb_gc_register_mark_object(compat_allocator_tbl_wrapper);
|
1998-01-16 15:19:09 +03:00
|
|
|
}
|
2001-07-03 11:29:00 +04:00
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_marshal_dump(VALUE obj, VALUE port)
|
2001-07-03 11:29:00 +04:00
|
|
|
{
|
|
|
|
int argc = 1;
|
|
|
|
VALUE argv[2];
|
|
|
|
|
|
|
|
argv[0] = obj;
|
|
|
|
argv[1] = port;
|
|
|
|
if (!NIL_P(port)) argc = 2;
|
|
|
|
return marshal_dump(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_marshal_load(VALUE port)
|
2001-07-03 11:29:00 +04:00
|
|
|
{
|
|
|
|
return marshal_load(1, &port);
|
|
|
|
}
|