summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-10-20 07:10:23 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-10-20 07:10:23 +0000
commit58ac90ff773d7fc5107d7f2a886dd475053115f9 (patch)
tree25f6e2a15a8e14b12ac653ac365d2fe34be0abd4
parent125ca1a11a53810ac311012352f5b0773fc2bbde (diff)
marshal load GC protect
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--array.c25
-rw-r--r--ext/nkf/nkf.c4
-rw-r--r--ext/socket/extconf.rb1
-rw-r--r--ext/socket/getaddrinfo.c5
-rw-r--r--ext/socket/socket.c4
-rw-r--r--marshal.c15
-rw-r--r--string.c136
8 files changed, 95 insertions, 104 deletions
diff --git a/ChangeLog b/ChangeLog
index 2b63da2b9b2..43538e42a24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Oct 20 15:14:24 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * marshal.c (marshal_load): should protect the generated object
+ table (arg->data) from GC.
+
Mon Oct 18 16:15:52 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* ext/nkf/nkf.c (rb_nkf_kconv): output should be NUL terminated.
@@ -6,6 +11,10 @@ Sun Oct 17 03:35:33 1999 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* array.c (rb_ary_pop): forgot some freeze checks.
+Sat Oct 16 12:57:53 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * array.c (rb_ary_sort): always returns the copied array.
+
Fri Oct 15 22:50:41 1999 WATANABE Hirofumi <eban@os.rim.or.jp>
* error.c (sys_nerr): on CYGWIN, it is _sys_nerr.
diff --git a/array.c b/array.c
index 793ea13baf1..0615da75515 100644
--- a/array.c
+++ b/array.c
@@ -930,8 +930,8 @@ rb_ary_sort(ary)
VALUE ary;
{
ary = rb_ary_dup(ary);
- if (RARRAY(ary)->len == 0) return ary;
- return rb_ary_sort_bang(ary);
+ rb_ary_sort_bang(ary);
+ return ary;
}
VALUE
@@ -1365,10 +1365,9 @@ static VALUE
rb_ary_uniq(ary)
VALUE ary;
{
- VALUE v = rb_ary_uniq_bang(rb_ary_dup(ary));
-
- if (NIL_P(v)) return ary;
- return v;
+ ary = rb_ary_dup(ary);
+ rb_ary_uniq_bang(ary);
+ return ary;
}
static VALUE
@@ -1397,10 +1396,9 @@ static VALUE
rb_ary_compact(ary)
VALUE ary;
{
- VALUE v = rb_ary_compact_bang(rb_ary_dup(ary));
-
- if (NIL_P(v)) return ary;
- return v;
+ ary = rb_ary_dup(ary);
+ rb_ary_compact_bang(ary);
+ return ary;
}
static VALUE
@@ -1442,10 +1440,9 @@ static VALUE
rb_ary_flatten(ary)
VALUE ary;
{
- VALUE v = rb_ary_flatten_bang(rb_ary_dup(ary));
-
- if (NIL_P(v)) return ary;
- return v;
+ ary = rb_ary_dup(ary);
+ rb_ary_flatten_bang(ary);
+ return ary;
}
void
diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c
index cde0f7a9a63..b59688cb032 100644
--- a/ext/nkf/nkf.c
+++ b/ext/nkf/nkf.c
@@ -49,6 +49,7 @@ rb_nkf_kconv(obj, opt, src)
{
int i;
char *opt_ptr, *opt_end;
+ volatile VALUE v;
reinit();
opt_ptr = str2cstr(opt, &i);
@@ -64,7 +65,8 @@ rb_nkf_kconv(obj, opt, src)
input_ctr = 0;
input = str2cstr(src, &i_len);
- dst = rb_str_new(0, i_len*3 + 10); /* large enough? */
+ dst = rb_str_new(0, i_len*3 + 10);
+ v = dst;
output_ctr = 0;
output = RSTRING(dst)->ptr;
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 467c052a851..6975994ef8b 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -148,7 +148,6 @@ EOF
$CFLAGS="-DHAVE_SA_LEN "+$CFLAGS
end
-have_header("sys/sysctl.h")
have_header("netinet/tcp.h")
have_header("netinet/udp.h")
diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c
index 501ebd5006e..ebb03fe959a 100644
--- a/ext/socket/getaddrinfo.c
+++ b/ext/socket/getaddrinfo.c
@@ -41,11 +41,6 @@
#include <sys/types.h>
#ifndef NT
#include <sys/param.h>
-#endif
-#ifdef HAVE_SYSCTL_H
-#include <sys/sysctl.h>
-#endif
-#ifndef NT
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 408257eeb63..b38cc48c98c 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -16,10 +16,10 @@
#ifndef NT
#include <sys/socket.h>
#include <netinet/in.h>
-#ifdef NETINET_TCP
+#ifdef HAVE_NETINET_TCP_H
# include <netinet/tcp.h>
#endif
-#ifdef NETINET_UDP
+#ifdef HAVE_NETINET_UDP_H
# include <netinet/udp.h>
#endif
#include <netdb.h>
diff --git a/marshal.c b/marshal.c
index 82d6907276b..657be5a1b4b 100644
--- a/marshal.c
+++ b/marshal.c
@@ -449,7 +449,7 @@ struct load_arg {
FILE *fp;
char *ptr, *end;
st_table *symbol;
- st_table *data;
+ VALUE data;
VALUE proc;
};
@@ -602,7 +602,7 @@ r_regist(v, arg)
if (arg->proc) {
rb_funcall(arg->proc, rb_intern("call"), 1, v);
}
- st_insert(arg->data, arg->data->num_entries, v);
+ rb_hash_aset(arg->data, INT2FIX(RHASH(arg->data)->tbl->num_entries), v);
return v;
}
@@ -612,14 +612,16 @@ r_object(arg)
{
VALUE v;
int type = r_byte(arg);
+ long id;
switch (type) {
case TYPE_LINK:
- if (st_lookup(arg->data, r_long(arg), &v)) {
+ id = r_long(arg);
+ if (v = rb_hash_aref(arg->data, INT2FIX(id))) {
return v;
}
rb_raise(rb_eArgError, "dump format error (unlinked)");
- break;
+ break;
case TYPE_UCLASS:
{
@@ -811,7 +813,6 @@ load_ensure(arg)
struct load_arg *arg;
{
st_free_table(arg->symbol);
- st_free_table(arg->data);
return 0;
}
@@ -846,11 +847,13 @@ marshal_load(argc, argv)
major = r_byte(&arg);
if (major == MARSHAL_MAJOR) {
+ volatile VALUE hash; /* protect from GC */
+
if (r_byte(&arg) != MARSHAL_MINOR) {
rb_warn("Old marshal file format (can be read)");
}
arg.symbol = st_init_numtable();
- arg.data = st_init_numtable();
+ arg.data = hash = rb_hash_new();
if (NIL_P(proc)) arg.proc = 0;
else arg.proc = proc;
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
diff --git a/string.c b/string.c
index 4a4532cb469..af2db491d07 100644
--- a/string.c
+++ b/string.c
@@ -1042,10 +1042,9 @@ rb_str_sub(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE val = rb_str_sub_bang(argc, argv, str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_sub_bang(argc, argv, str);
+ return str;
}
static VALUE
@@ -1149,10 +1148,9 @@ rb_str_gsub(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE val = rb_str_gsub_bang(argc, argv, str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_gsub_bang(argc, argv, str);
+ return str;
}
static VALUE
@@ -1194,13 +1192,13 @@ rb_f_sub(argc, argv)
int argc;
VALUE *argv;
{
- VALUE line, v;
+ VALUE line;
- line = uscore_get();
- v = rb_str_sub_bang(argc, argv, line = rb_str_dup(line));
- if (NIL_P(v)) return line;
- rb_lastline_set(v);
- return v;
+ line = rb_str_dup(uscore_get());
+ if (!NIL_P(rb_str_sub_bang(argc, argv, line))) {
+ rb_lastline_set(line);
+ }
+ return line;
}
static VALUE
@@ -1216,13 +1214,13 @@ rb_f_gsub(argc, argv)
int argc;
VALUE *argv;
{
- VALUE line, v;
+ VALUE line;
- line = uscore_get();
- v = rb_str_gsub_bang(argc, argv, line = rb_str_dup(line));
- if (NIL_P(v)) return line;
- rb_lastline_set(v);
- return v;
+ line = rb_str_dup(uscore_get());
+ if (!NIL_P(rb_str_gsub_bang(argc, argv, line = rb_str_dup(line)))) {
+ rb_lastline_set(line);
+ }
+ return line;
}
static VALUE
@@ -1523,10 +1521,9 @@ static VALUE
rb_str_upcase(str)
VALUE str;
{
- VALUE val = rb_str_upcase_bang(str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_upcase_bang(str);
+ return str;
}
static VALUE
@@ -1557,10 +1554,9 @@ static VALUE
rb_str_downcase(str)
VALUE str;
{
- VALUE val = rb_str_downcase_bang(str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_downcase_bang(str);
+ return str;
}
static VALUE
@@ -1593,10 +1589,9 @@ static VALUE
rb_str_capitalize(str)
VALUE str;
{
- VALUE val = rb_str_capitalize_bang(str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_capitalize_bang(str);
+ return str;
}
static VALUE
@@ -1631,10 +1626,9 @@ static VALUE
rb_str_swapcase(str)
VALUE str;
{
- VALUE val = rb_str_swapcase_bang(str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_swapcase_bang(str);
+ return str;
}
typedef unsigned char *USTR;
@@ -1782,10 +1776,9 @@ static VALUE
rb_str_tr(str, src, repl)
VALUE str, src, repl;
{
- VALUE val = tr_trans(str = rb_str_dup(str), src, repl, 0);
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ tr_trans(str, src, repl, 0);
+ return str;
}
static void
@@ -1866,10 +1859,9 @@ rb_str_delete(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE val = rb_str_delete_bang(argc, argv, str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_delete_bang(argc, argv, str);
+ return str;
}
static VALUE
@@ -1927,10 +1919,9 @@ rb_str_squeeze(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE val = rb_str_squeeze_bang(argc, argv, str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_squeeze_bang(argc, argv, str);
+ return str;
}
static VALUE
@@ -1944,10 +1935,9 @@ static VALUE
rb_str_tr_s(str, src, repl)
VALUE str, src, repl;
{
- VALUE val = tr_trans(str = rb_str_dup(str), src, repl, 1);
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ tr_trans(str, src, repl, 1);
+ return str;
}
static VALUE
@@ -2235,10 +2225,9 @@ static VALUE
rb_str_chop(str)
VALUE str;
{
- VALUE val = rb_str_chop_bang(str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_chop_bang(str);
+ return str;
}
static VALUE
@@ -2251,12 +2240,12 @@ rb_f_chop_bang(str)
static VALUE
rb_f_chop()
{
- VALUE str = uscore_get();
- VALUE val = rb_str_chop_bang(str = rb_str_dup(str));
+ VALUE str = rb_str_dup(uscore_get());
- if (NIL_P(val)) return str;
- rb_lastline_set(val);
- return val;
+ if (!NIL_P(rb_str_chop_bang(str))) {
+ rb_lastline_set(str);
+ }
+ return str;
}
static VALUE
@@ -2308,10 +2297,9 @@ rb_str_chomp(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE val = rb_str_chomp_bang(argc, argv, str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_chomp_bang(argc, argv, str);
+ return str;
}
static VALUE
@@ -2327,12 +2315,11 @@ rb_f_chomp(argc, argv)
int argc;
VALUE *argv;
{
- VALUE str = uscore_get();
- VALUE val = rb_str_chomp_bang(argc, argv, str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- rb_lastline_set(val);
- return val;
+ VALUE str = rb_str_dup(uscore_get());
+ if (!NIL_P(rb_str_chomp_bang(argc, argv, str))) {
+ rb_lastline_set(str);
+ }
+ return str;
}
static VALUE
@@ -2375,10 +2362,9 @@ static VALUE
rb_str_strip(str)
VALUE str;
{
- VALUE val = rb_str_strip_bang(str = rb_str_dup(str));
-
- if (NIL_P(val)) return str;
- return val;
+ str = rb_str_dup(str);
+ rb_str_strip_bang(str);
+ return str;
}
static VALUE