summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog55
-rw-r--r--array.c7
-rw-r--r--error.c48
-rw-r--r--eval.c62
-rw-r--r--file.c9
-rw-r--r--gc.c40
-rw-r--r--intern.h2
-rw-r--r--io.c61
-rw-r--r--lib/mkmf.rb2
-rw-r--r--marshal.c57
-rw-r--r--numeric.c217
-rw-r--r--object.c5
-rw-r--r--parse.y84
-rw-r--r--range.c2
-rw-r--r--re.c66
-rw-r--r--regex.c10
-rw-r--r--regex.h6
-rw-r--r--ruby.h15
-rw-r--r--rubysig.h43
-rw-r--r--signal.c92
-rw-r--r--string.c23
-rw-r--r--time.c4
-rw-r--r--variable.c5
-rw-r--r--version.h4
24 files changed, 485 insertions, 434 deletions
diff --git a/ChangeLog b/ChangeLog
index a79f4b4776..b162165f8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Apr 24 06:48:31 2002 Koji Arai <jca02266@nifty.ne.jp>
+
+ * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
+
+ * io.c (rb_io_mode_modenum): ditto.
+
Wed Apr 24 01:16:14 2002 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_mark): must check if ptr is NULL
@@ -14,12 +20,61 @@ Wed Apr 24 00:37:12 2002 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (create_makefile): add `{$(srcdir)}' when including depend
file.
+Tue Apr 23 12:58:18 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * gc.c (rb_memerror): rename from mem_error, and exported.
+
+ * gc.c (Init_GC): pre-allocate NoMemoryError instance.
+
+ * object.c (convert_type): error message changed from "failed to
+ convert" to "cannot convert", since it does not try to convert
+ if an object does not respond to the converting method.
+
+Mon Apr 22 09:31:30 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (block_pass): convert Method to Proc using
+ rb_check_convert_type().
+
+ * object.c (rb_check_convert_type): always convert T_DATA
+
+ * eval.c (rb_thread_cleanup): should not terminate main_thread by
+ Fatal error.
+
+ * regex.c (is_in_list): need to not exclude NUL and NEWLINE.
+
+Sat Apr 20 00:19:13 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * re.c (rb_reg_expr_str): wrong backslash escapement.
+
+ * re.c (rb_reg_expr_str): do not escape embedded space
+ characters.
+
Fri Apr 19 22:03:40 2002 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub: add -DNT to $CFLAGS instead of $CPPFLAGS.
* win32/setup.mak: ditto.
+Fri Apr 19 17:24:22 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * marshal.c (w_object): T_DATA process patch from Joel VanderWerf
+ <vjoel@PATH.Berkeley.EDU>. This is temporary hack; it remains
+ undocumented, and it will be removed when marshaling is
+ re-designed.
+
+ * marshal.c (r_object): ditto.
+
+Fri Apr 19 17:10:55 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * numeric.c (num_step): Integer#step is moved to Numeric#step;
+ Fixnum#step is merged into this method.
+
+ * numeric.c (int_dotimes): Fixnum#times is merged.
+
+ * numeric.c (int_upto): Fixnum#upto is merged.
+
+ * numeric.c (int_downto): Fixnum#downto is merged.
+
Fri Apr 19 16:22:55 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/socket/extconf.rb: include <windows.h>, <winsock.h> on _WIN32.
diff --git a/array.c b/array.c
index ff5ded0e5c..59dfe31ce2 100644
--- a/array.c
+++ b/array.c
@@ -207,13 +207,6 @@ to_ary(ary)
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
-static VALUE
-to_ary_failed(failed)
- int *failed;
-{
- *failed = Qtrue;
-}
-
static VALUE rb_ary_replace _((VALUE, VALUE));
static VALUE
diff --git a/error.c b/error.c
index 936079a659..65f4ec3745 100644
--- a/error.c
+++ b/error.c
@@ -182,30 +182,30 @@ static struct types {
int type;
const char *name;
} builtin_types[] = {
- T_NIL, "nil",
- T_OBJECT, "Object",
- T_CLASS, "Class",
- T_ICLASS, "iClass", /* internal use: mixed-in module holder */
- T_MODULE, "Module",
- T_FLOAT, "Float",
- T_STRING, "String",
- T_REGEXP, "Regexp",
- T_ARRAY, "Array",
- T_FIXNUM, "Fixnum",
- T_HASH, "Hash",
- T_STRUCT, "Struct",
- T_BIGNUM, "Bignum",
- T_FILE, "File",
- T_TRUE, "true",
- T_FALSE, "false",
- T_SYMBOL, "Symbol", /* :symbol */
- T_DATA, "Data", /* internal use: wrapped C pointers */
- T_MATCH, "MatchData", /* data of $~ */
- T_VARMAP, "Varmap", /* internal use: dynamic variables */
- T_SCOPE, "Scope", /* internal use: variable scope */
- T_NODE, "Node", /* internal use: syntax tree node */
- T_UNDEF, "undef", /* internal use: #undef; should not happen */
- -1, 0,
+ {T_NIL, "nil"},
+ {T_OBJECT, "Object"},
+ {T_CLASS, "Class"},
+ {T_ICLASS, "iClass"}, /* internal use: mixed-in module holder */
+ {T_MODULE, "Module"},
+ {T_FLOAT, "Float"},
+ {T_STRING, "String"},
+ {T_REGEXP, "Regexp"},
+ {T_ARRAY, "Array"},
+ {T_FIXNUM, "Fixnum"},
+ {T_HASH, "Hash"},
+ {T_STRUCT, "Struct"},
+ {T_BIGNUM, "Bignum"},
+ {T_FILE, "File"},
+ {T_TRUE, "true"},
+ {T_FALSE, "false"},
+ {T_SYMBOL, "Symbol"}, /* :symbol */
+ {T_DATA, "Data"}, /* internal use: wrapped C pointers */
+ {T_MATCH, "MatchData"}, /* data of $~ */
+ {T_VARMAP, "Varmap"}, /* internal use: dynamic variables */
+ {T_SCOPE, "Scope"}, /* internal use: variable scope */
+ {T_NODE, "Node"}, /* internal use: syntax tree node */
+ {T_UNDEF, "undef"}, /* internal use: #undef; should not happen */
+ {-1, 0}
};
void
diff --git a/eval.c b/eval.c
index d3a3d76dcf..820ab40292 100644
--- a/eval.c
+++ b/eval.c
@@ -105,7 +105,6 @@ static void rb_f_END _((void));
static VALUE rb_f_block_given_p _((void));
static VALUE block_pass _((VALUE,NODE*));
static VALUE rb_cMethod;
-static VALUE method_proc _((VALUE));
static VALUE method_call _((int, VALUE*, VALUE));
static VALUE rb_cUnboundMethod;
static VALUE umethod_bind _((VALUE, VALUE));
@@ -117,7 +116,7 @@ static int scope_vmode;
#define SCOPE_PROTECTED 2
#define SCOPE_MODFUNC 5
#define SCOPE_MASK 7
-#define SCOPE_SET(f) do {scope_vmode=(f);} while(0)
+#define SCOPE_SET(f) scope_vmode=(f)
#define SCOPE_TEST(f) (scope_vmode&(f))
int ruby_safe_level = 0;
@@ -440,7 +439,7 @@ rb_method_boundp(klass, id, ex)
return Qfalse;
}
-static ID init, alloc, eqq, each, aref, aset, match, to_ary, missing;
+static ID init, alloc, eqq, each, aref, aset, match, missing;
static ID added, singleton_added;
static ID __id__, __send__;
@@ -507,7 +506,7 @@ struct SCOPE *ruby_scope;
static struct FRAME *top_frame;
static struct SCOPE *top_scope;
-#define PUSH_FRAME() { \
+#define PUSH_FRAME() do { \
struct FRAME _frame; \
_frame.prev = ruby_frame; \
_frame.tmp = 0; \
@@ -524,7 +523,7 @@ static struct SCOPE *top_scope;
ruby_sourcefile = _frame.file; \
ruby_sourceline = _frame.line; \
ruby_frame = _frame.prev; \
-}
+} while (0)
struct BLOCKTAG {
struct RBasic super;
@@ -565,7 +564,7 @@ new_blktag()
return blktag;
}
-#define PUSH_BLOCK(v,b) { \
+#define PUSH_BLOCK(v,b) do { \
struct BLOCK _block; \
_block.tag = new_blktag(); \
_block.var = v; \
@@ -590,10 +589,10 @@ new_blktag()
else if (!(_block.scope->flags & SCOPE_DONT_RECYCLE)) \
rb_gc_force_recycle((VALUE)_block.tag); \
ruby_block = _block.prev; \
-}
+} while (0)
struct RVarmap *ruby_dyna_vars;
-#define PUSH_VARS() { \
+#define PUSH_VARS() do { \
struct RVarmap * volatile _old; \
_old = ruby_dyna_vars; \
ruby_dyna_vars = 0
@@ -604,7 +603,7 @@ struct RVarmap *ruby_dyna_vars;
FL_SET(_old, DVAR_DONT_RECYCLE); \
}\
ruby_dyna_vars = _old; \
-}
+} while (0)
#define DVAR_DONT_RECYCLE FL_USER2
@@ -747,7 +746,7 @@ static struct iter *ruby_iter;
#define ITER_PRE 1
#define ITER_CUR 2
-#define PUSH_ITER(i) { \
+#define PUSH_ITER(i) do { \
struct iter _iter; \
_iter.prev = ruby_iter; \
_iter.iter = (i); \
@@ -755,7 +754,7 @@ static struct iter *ruby_iter;
#define POP_ITER() \
ruby_iter = _iter.prev; \
-}
+} while (0)
struct tag {
jmp_buf buf;
@@ -769,7 +768,7 @@ struct tag {
};
static struct tag *prot_tag;
-#define PUSH_TAG(ptag) { \
+#define PUSH_TAG(ptag) do { \
struct tag _tag; \
_tag.retval = Qnil; \
_tag.frame = ruby_frame; \
@@ -796,11 +795,11 @@ static struct tag *prot_tag;
if (_tag.prev) \
_tag.prev->retval = _tag.retval;\
prot_tag = _tag.prev; \
-}
+} while (0)
#define POP_TMPTAG() \
prot_tag = _tag.prev; \
-}
+} while (0)
#define TAG_RETURN 0x1
#define TAG_BREAK 0x2
@@ -815,18 +814,18 @@ static struct tag *prot_tag;
VALUE ruby_class;
static VALUE ruby_wrapper; /* security wrapper */
-#define PUSH_CLASS() { \
+#define PUSH_CLASS() do { \
VALUE _class = ruby_class
#define POP_CLASS() ruby_class = _class; \
-}
+} while (0)
static NODE *ruby_cref = 0;
static NODE *top_cref;
#define PUSH_CREF(c) ruby_cref = rb_node_newnode(NODE_CREF,(c),0,ruby_cref)
#define POP_CREF() ruby_cref = ruby_cref->nd_next
-#define PUSH_SCOPE() { \
+#define PUSH_SCOPE() do { \
volatile int _vmode = scope_vmode; \
struct SCOPE * volatile _old; \
NEWOBJ(_scope, struct SCOPE); \
@@ -858,7 +857,7 @@ static void scope_dup _((struct SCOPE *));
ruby_scope->flags |= SCOPE_NOSTACK; \
ruby_scope = _old; \
scope_vmode = _vmode; \
-}
+} while (0)
static VALUE rb_eval _((VALUE,NODE*));
static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
@@ -1756,7 +1755,7 @@ copy_node_scope(node, rval)
}\
} while (0)
-#define BEGIN_CALLARGS {\
+#define BEGIN_CALLARGS do {\
struct BLOCK *tmp_block = ruby_block;\
if (ruby_iter->iter == ITER_PRE) {\
ruby_block = ruby_block->prev;\
@@ -1766,7 +1765,7 @@ copy_node_scope(node, rval)
#define END_CALLARGS \
ruby_block = tmp_block;\
POP_ITER();\
-}
+} while (0)
#define MATCH_DATA *rb_svar(node->nd_cnt)
@@ -2152,7 +2151,10 @@ rb_eval(self, n)
int state;
volatile VALUE result = Qnil;
-#define RETURN(v) { result = (v); goto finish; }
+#define RETURN(v) do { \
+ result = (v); \
+ goto finish; \
+} while (0)
again:
if (!node) RETURN(Qnil);
@@ -4929,7 +4931,7 @@ eval(self, src, scope, file, line)
char *file;
int line;
{
- struct BLOCK *data;
+ struct BLOCK *data = NULL;
volatile VALUE result = Qnil;
struct SCOPE * volatile old_scope;
struct BLOCK * volatile old_block;
@@ -5472,7 +5474,6 @@ rb_f_require(obj, fname)
{
VALUE feature, tmp;
char *ext, *ftptr; /* OK */
- volatile VALUE load;
int state;
volatile int safe = ruby_safe_level;
@@ -6019,7 +6020,6 @@ Init_eval()
aref = rb_intern("[]");
aset = rb_intern("[]=");
match = rb_intern("=~");
- to_ary = rb_intern("to_ary");
missing = rb_intern("method_missing");
added = rb_intern("method_added");
singleton_added = rb_intern("singleton_method_added");
@@ -6590,6 +6590,7 @@ block_pass(self, node)
NODE *node;
{
VALUE block = rb_eval(self, node->nd_body); /* OK */
+ VALUE b;
struct BLOCK * volatile old_block;
struct BLOCK _block;
struct BLOCK *data;
@@ -6604,13 +6605,12 @@ block_pass(self, node)
POP_ITER();
return result;
}
- if (rb_obj_is_kind_of(block, rb_cMethod)) {
- block = method_proc(block);
- }
- else if (!rb_obj_is_proc(block)) {
+ b = rb_check_convert_type(block, T_DATA, "Proc", "to_proc");
+ if (!rb_obj_is_proc(b)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc)",
rb_class2name(CLASS_OF(block)));
}
+ block = b;
if (rb_safe_level() >= 1 && OBJ_TAINTED(block)) {
if (rb_safe_level() > proc_get_safe_level(block)) {
@@ -8697,8 +8697,10 @@ rb_thread_cleanup()
rb_thread_ready(th);
th->gid = 0;
th->priority = 0;
- th->status = THREAD_TO_KILL;
- RDATA(th->thread)->dfree = NULL;
+ if (th != main_thread) {
+ th->status = THREAD_TO_KILL;
+ RDATA(th->thread)->dfree = NULL;
+ }
}
}
END_FOREACH(th);
diff --git a/file.c b/file.c
index 3a7f5e393f..064cc78259 100644
--- a/file.c
+++ b/file.c
@@ -1587,7 +1587,7 @@ rb_file_s_basename(argc, argv)
VALUE *argv;
{
VALUE fname, fext, basename;
- char *name, *p, *ext;
+ char *name, *p, *ext = NULL;
int f;
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
@@ -1998,7 +1998,7 @@ static VALUE
rb_stat_clone(obj)
VALUE obj;
{
- struct stat st, *nst;
+ struct stat *nst;
VALUE clone;
@@ -2403,7 +2403,7 @@ rb_find_file_ext(filep, ext)
VALUE *filep;
const char * const *ext;
{
- char *path, *e, *found;
+ char *path, *found;
char *f = RSTRING(*filep)->ptr;
VALUE fname;
int i, j;
@@ -2454,10 +2454,9 @@ VALUE
rb_find_file(path)
VALUE path;
{
- VALUE tmp, fname;
+ VALUE tmp;
char *f = RSTRING(path)->ptr;
char *lpath;
- struct stat st;
if (f[0] == '~') {
path = rb_file_s_expand_path(1, &path);
diff --git a/gc.c b/gc.c
index e95f38e6b3..6cd0222f2f 100644
--- a/gc.c
+++ b/gc.c
@@ -66,22 +66,19 @@ static void run_final();
#endif
static unsigned long malloc_memories = 0;
+static VALUE nomem_error;
-static void
-mem_error(mesg)
- char *mesg;
+void
+rb_memerror()
{
static int recurse = 0;
- if (rb_safe_level() >= 4) {
- rb_raise(rb_eNoMemError, mesg);
+ if (recurse > 0 && rb_safe_level() < 4) {
+ fprintf(stderr, "[FATAL] failed to allocate memory\n");
+ exit(1);
}
- if (recurse == 0) {
- recurse++;
- rb_fatal(mesg);
- }
- fprintf(stderr, "[FATAL] failed to allocate memory\n");
- exit(1);
+ recurse++;
+ rb_exc_raise(nomem_error);
}
void *
@@ -104,10 +101,7 @@ ruby_xmalloc(size)
rb_gc();
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
- if (size >= 10 * 1024 * 1024) {
- mem_error("tried to allocate too big memory");
- }
- mem_error("failed to allocate memory");
+ rb_memerror();
}
}
@@ -144,10 +138,7 @@ ruby_xrealloc(ptr, size)
rb_gc();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
- if (size >= 10 * 1024 * 1024) {
- rb_raise(rb_eNoMemError, "tried to re-allocate too big memory");
- }
- mem_error("failed to allocate memory(realloc)");
+ rb_memerror();
}
}
@@ -287,11 +278,11 @@ add_heap()
RUBY_CRITICAL(heaps = (heaps_used>0)?
(RVALUE**)realloc(heaps, heaps_length*sizeof(RVALUE*)):
(RVALUE**)malloc(heaps_length*sizeof(RVALUE*)));
- if (heaps == 0) mem_error("heaps: can't alloc memory");
+ if (heaps == 0) rb_memerror();
RUBY_CRITICAL(heaps_limits = (heaps_used>0)?
(int*)realloc(heaps_limits, heaps_length*sizeof(int)):
(int*)malloc(heaps_length*sizeof(int)));
- if (heaps_limits == 0) mem_error("heaps_limits: can't alloc memory");
+ if (heaps_limits == 0) rb_memerror();
}
for (;;) {
@@ -299,7 +290,7 @@ add_heap()
heaps_limits[heaps_used] = heap_slots;
if (p == 0) {
if (heap_slots == HEAP_MIN_SLOTS) {
- mem_error("add_heap: can't alloc memory");
+ rb_memerror();
}
heap_slots = HEAP_MIN_SLOTS;
continue;
@@ -396,8 +387,6 @@ int
ruby_stack_length(p)
VALUE **p;
{
- int ret;
-
SET_STACK_END;
if (p) *p = STACK_END;
return STACK_LENGTH;
@@ -1558,4 +1547,7 @@ Init_GC()
finalizers = rb_ary_new();
source_filenames = st_init_strtable();
+
+ nomem_error = rb_exc_new(rb_eNoMemError, "failed to allocate memory");
+ rb_global_variable(&nomem_error);
}
diff --git a/intern.h b/intern.h
index 2ca00ace4a..733f1c1029 100644
--- a/intern.h
+++ b/intern.h
@@ -202,6 +202,7 @@ void rb_file_const _((const char*, VALUE));
int rb_find_file_ext _((VALUE*, const char* const*));
VALUE rb_find_file _((VALUE));
/* gc.c */
+NORETURN(void rb_memerror __((void)));
int ruby_stack_check _((void));
int ruby_stack_length _((VALUE**));
char *rb_source_filename _((const char*));
@@ -254,7 +255,6 @@ VALUE rb_num_coerce_bin _((VALUE, VALUE));
VALUE rb_float_new _((double));
VALUE rb_num2fix _((VALUE));
VALUE rb_fix2str _((VALUE, int));
-VALUE rb_fix_upto _((VALUE, VALUE));
/* object.c */
int rb_eql _((VALUE, VALUE));
VALUE rb_any_to_s _((VALUE));
diff --git a/io.c b/io.c
index 97f950a1ee..2754988aaa 100644
--- a/io.c
+++ b/io.c
@@ -265,7 +265,7 @@ io_write(io, str)
{
OpenFile *fptr;
FILE *f;
- int n;
+ long n;
rb_secure(4);
if (TYPE(str) != T_STRING)
@@ -284,7 +284,7 @@ io_write(io, str)
#ifdef __human68k__
{
register char *ptr = RSTRING(str)->ptr;
- n = (int)RSTRING(str)->len;
+ n = RSTRING(str)->len;
while (--n >= 0)
if (fputc(*ptr++, f) == EOF)
break;
@@ -305,7 +305,7 @@ io_write(io, str)
fptr->mode |= FMODE_WBUF;
}
- return INT2FIX(n);
+ return LONG2FIX(n);
}
VALUE
@@ -613,8 +613,7 @@ remain_size(fptr)
{
struct stat st;
off_t siz = BUFSIZ;
- long bytes = 0;
- int n;
+ off_t pos;
if (feof(fptr->f)) return 0;
if (fstat(fileno(fptr->f), &st) == 0 && S_ISREG(st.st_mode)
@@ -623,8 +622,6 @@ remain_size(fptr)
#endif
)
{
- off_t pos;
-
pos = ftello(fptr->f);
if (st.st_size > pos && pos >= 0) {
siz = st.st_size - pos + 1;
@@ -643,14 +640,14 @@ read_all(fptr, siz)
{
VALUE str;
long bytes = 0;
- int n;
+ long n;
if (feof(fptr->f)) return Qnil;
READ_CHECK(fptr->f);
if (!siz) siz = BUFSIZ;
str = rb_tainted_str_new(0, siz);
for (;;) {
- n = io_fread(RSTRING(str)->ptr+bytes, (long)siz-bytes, fptr->f);
+ n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
if (n == 0 && bytes == 0) {
if (feof(fptr->f)) return Qnil;
rb_sys_fail(fptr->path);
@@ -1003,7 +1000,7 @@ rb_io_readlines(argc, argv, io)
VALUE io;
{
VALUE line, ary;
- VALUE rs, str;
+ VALUE rs;
OpenFile *fptr;
if (argc == 0) {
@@ -1452,16 +1449,18 @@ rb_io_mode_flags(mode)
rb_raise(rb_eArgError, "illegal access mode %s", mode);
}
- if (*m == 'b') {
- flags |= FMODE_BINMODE;
- m++;
- }
-
- if (*m == '+') {
- flags |= FMODE_READWRITE;
- if (m[1] != 0) goto error;
+ while (*m) {
+ switch (*m++) {
+ case 'b':
+ flags |= FMODE_BINMODE;
+ break;
+ case '+':
+ flags |= FMODE_READWRITE;
+ break;
+ default:
+ goto error;
+ }
}
- else if (*m != 0) goto error;
return flags;
}
@@ -1470,7 +1469,7 @@ static int
rb_io_modenum_flags(mode)
int mode;
{
- int flags;
+ int flags = 0;
switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) {
case O_RDONLY:
@@ -1515,18 +1514,20 @@ rb_io_mode_modenum(mode)
rb_raise(rb_eArgError, "illegal access mode %s", mode);
}
- if (*m == 'b') {
+ while (*m) {
+ switch (*m++) {
+ case 'b':
#ifdef O_BINARY
- flags |= O_BINARY;
+ flags |= O_BINARY;
#endif
- m++;
- }
-
- if (*m == '+') {
- flags |= O_RDWR;
- if (m[1] != 0) goto error;
+ break;
+ case '+':
+ flags |= O_RDWR;
+ break;
+ default:
+ goto error;
+ }
}
- else if (*m != 0) goto error;
return flags;
}
@@ -3554,8 +3555,6 @@ argf_readchar()
static VALUE
argf_eof()
{
- int first = first_p;
-
if (!next_argv()) return Qtrue;
if (next_p == 1) {
return Qtrue;
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 8889ca17ca..e669343eef 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -185,7 +185,7 @@ def install_files(mfile, ifiles, map = INSTALL_DIRS, srcprefix = nil)
path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
ifiles.each do |files, dir, prefix|
dir = map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)} if map
- prefix = %r"\A#{Regexp.quote(prefix)}/" if prefix
+ prefix = %r"\A#{Regexp.quote(prefix)}/?" if prefix
if( files[0,2] == "./" )
# install files which are in current working directory.
Dir.glob(files) do |f|
diff --git a/marshal.c b/marshal.c
index b15af3b620..738f7edd62 100644
--- a/marshal.c
+++ b/marshal.c
@@ -55,6 +55,7 @@ shortlen(len, ds)
#define TYPE_UCLASS 'C'
#define TYPE_OBJECT 'o'
+#define TYPE_DATA 'd'
#define TYPE_USERDEF 'u'
#define TYPE_USRMARHAL 'U'
#define TYPE_FLOAT 'f'
@@ -76,6 +77,7 @@ shortlen(len, ds)
#define TYPE_LINK '@'
static ID s_dump, s_load;
+static ID s_dump_data, s_load_data, s_alloc;
struct dump_arg {
VALUE obj;
@@ -490,6 +492,34 @@ w_object(obj, arg, limit)
}
break;
+ case T_DATA:
+ w_byte(TYPE_DATA, arg);
+ {
+ VALUE klass = CLASS_OF(obj);
+ char *path;
+
+ if (FL_TEST(klass, FL_SINGLETON)) {
+ if (RCLASS(klass)->m_tbl->num_entries > 0 ||
+ RCLASS(klass)->iv_tbl->num_entries > 1) {
+ rb_raise(rb_eTypeError, "singleton can't be dumped");
+ }
+ }
+ path = rb_class2name(klass);
+ w_unique(path, arg);
+ }
+ {
+ VALUE v;
+
+ if (!rb_respond_to(obj, s_dump_data)) {
+ rb_raise(rb_eTypeError,
+ "class %s needs to have instance method `_dump_data'",
+ rb_class2name(CLASS_OF(obj)));
+ }
+ v = rb_funcall(obj, s_dump_data, 0);
+ w_object(v, arg, limit);
+ }
+ break;
+
default:
rb_raise(rb_eTypeError, "can't dump %s",
rb_class2name(CLASS_OF(obj)));
@@ -1010,6 +1040,30 @@ r_object(arg)
}
break;
+ case TYPE_DATA:
+ {
+ VALUE klass;
+
+ klass = rb_path2class(r_unique(arg));
+ if (!rb_respond_to(klass, s_alloc)) {
+ rb_raise(rb_eTypeError,
+ "class %s needs to have class method `_alloc'",
+ rb_class2name(klass));
+ }
+ v = rb_funcall(klass, s_alloc, 0);
+ if (TYPE(v) != T_DATA) {
+ rb_raise(rb_eArgError, "dump format error");
+ }
+ r_regist(v, arg);
+ if (!rb_respond_to(v, s_load_data)) {
+ rb_raise(rb_eTypeError,
+ "class %s needs to have instance method `_load_data'",
+ rb_class2name(klass));
+ }
+ rb_funcall(v, s_load_data, 1, r_object(arg));
+ }
+ break;
+
case TYPE_MODULE_OLD:
{
char *buf;
@@ -1134,6 +1188,9 @@ Init_marshal()
s_dump = rb_intern("_dump");
s_load = rb_intern("_load");
+ s_dump_data = rb_intern("_dump_data");
+ s_load_data = rb_intern("_load_data");
+ s_alloc = rb_intern("_alloc");
rb_define_module_function(rb_mMarshal, "dump", marshal_dump, -1);
rb_define_module_function(rb_mMarshal, "load", marshal_load, -1);
rb_define_module_function(rb_mMarshal, "restore", marshal_load, -1);
diff --git a/numeric.c b/numeric.c
index c24c49d9c7..58961d78ef 100644
--- a/numeric.c
+++ b/numeric.c
@@ -153,7 +153,7 @@ num_remainder(x, y)
{
VALUE z = rb_funcall(x, '%', 1, y);
- if ((!RTEST(rb_equal(z, INT2FIX(0)))) &&
+ if ((!rb_equal(z, INT2FIX(0))) &&
((RTEST(rb_funcall(x, '<', 1, INT2FIX(0))) &&
RTEST(rb_funcall(y, '>', 1, INT2FIX(0)))) ||
(RTEST(rb_funcall(x, '>', 1, INT2FIX(0))) &&
@@ -184,7 +184,7 @@ static VALUE
num_zero_p(num)
VALUE num;
{
- if (RTEST(rb_equal(num, INT2FIX(0)))) {
+ if (rb_equal(num, INT2FIX(0))) {
return Qtrue;
}
return Qfalse;
@@ -762,6 +762,59 @@ num_truncate(num)
return flo_truncate(rb_Float(num));
}
+static VALUE
+num_step(argc, argv, from)
+ int argc;
+ VALUE *argv;
+ VALUE from;
+{
+ VALUE to, step;
+ VALUE i = from;
+ ID cmp;
+
+ if (rb_scan_args(argc, argv, "11", &to, &step) == 1) {
+ step = INT2FIX(1);
+ }
+ else if (rb_equal(step, INT2FIX(0))) {
+ rb_raise(rb_eArgError, "step cannot be 0");
+ }
+
+ if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) {
+ long i, end, diff;
+
+ i = FIX2LONG(from);
+ end = FIX2LONG(to);
+ diff = FIX2LONG(step);
+
+ if (diff > 0) {
+ while (i <= end) {
+ rb_yield(INT2FIX(i));
+ i += diff;
+ }
+ }
+ else {
+ while (i >= end) {
+ rb_yield(INT2FIX(i));
+ i += diff;
+ }
+ }
+ return from;
+ }
+
+ if (RTEST(rb_funcall(step, '>', 1, INT2FIX(0)))) {
+ cmp = '>';
+ }
+ else {
+ cmp = '<';
+ }
+ for (;;) {
+ if (RTEST(rb_funcall(i, cmp, 1, to))) break;
+ rb_yield(i);
+ i = rb_funcall(i, '+', 1, step);
+ }
+ return from;
+}
+
long
rb_num2long(val)
VALUE val;
@@ -1452,51 +1505,46 @@ static VALUE
int_upto(from, to)
VALUE from, to;
{
- VALUE i = from;
+ if (FIXNUM_P(from) && FIXNUM_P(to)) {
+ long i, end;
- for (;;) {
- if (RTEST(rb_funcall(i, '>', 1, to))) break;
- rb_yield(i);
- i = rb_funcall(i, '+', 1, INT2FIX(1));
+ end = FIX2LONG(to);
+ for (i = FIX2LONG(from); i <= end; i++) {
+ rb_yield(INT2FIX(i));
+ }
}
- return from;
-}
-
-static VALUE
-int_downto(from, to)
- VALUE from, to;
-{
- VALUE i = from;
+ else {
+ VALUE i = from;
- for (;;) {
- if (RTEST(rb_funcall(i, '<', 1, to))) break;
- rb_yield(i);
- i = rb_funcall(i, '-', 1, INT2FIX(1));
+ for (;;) {
+ if (RTEST(rb_funcall(i, '>', 1, to))) break;
+ rb_yield(i);
+ i = rb_funcall(i, '+', 1, INT2FIX(1));
+ }
}
return from;
}
static VALUE
-int_step(from, to, step)
- VALUE from, to, step;
+int_downto(from, to)
+ VALUE from, to;
{
- VALUE i = from;
- ID cmp;
-
- if (rb_equal(step, INT2FIX(0))) {
- rb_raise(rb_eArgError, "step cannot be 0");
- }
+ if (FIXNUM_P(from) && FIXNUM_P(to)) {
+ long i, end;
- if (RTEST(rb_funcall(step, '>', 1, INT2FIX(0)))) {
- cmp = '>';
+ end = FIX2LONG(to);
+ for (i=FIX2LONG(from); i >= end; i--) {
+ rb_yield(INT2FIX(i));
+ }
}
else {
- cmp = '<';
- }
- for (;;) {
- if (RTEST(rb_funcall(i, cmp, 1, to))) break;
- rb_yield(i);
- i = rb_funcall(i, '+', 1, step);
+ VALUE i = from;
+
+ for (;;) {
+ if (RTEST(rb_funcall(i, '<', 1, to))) break;
+ rb_yield(i);
+ i = rb_funcall(i, '-', 1, INT2FIX(1));
+ }
}
return from;
}
@@ -1505,93 +1553,22 @@ static VALUE
int_dotimes(num)
VALUE num;
{
- VALUE i = INT2FIX(0);
-
- for (;;) {
- if (!RTEST(rb_funcall(i, '<', 1, num))) break;
- rb_yield(i);
- i = rb_funcall(i, '+', 1, INT2FIX(1));
- }
- return num;
-}
-
-static VALUE
-fix_upto(from, to)
- VALUE from, to;
-{
- long i, end;
-
- if (!FIXNUM_P(to)) return int_upto(from, to);
- end = FIX2LONG(to);
- for (i = FIX2LONG(from); i <= end; i++) {
- rb_yield(INT2FIX(i));
- }
-
- return from;
-}
-
-VALUE
-rb_fix_upto(from, to)
- VALUE from, to;
-{
- return fix_upto(from, to);
-}
-
-static VALUE
-fix_downto(from, to)
- VALUE from, to;
-{
- long i, end;
-
- if (!FIXNUM_P(to)) return int_downto(from, to);
- end = FIX2LONG(to);
- for (i=FIX2LONG(from); i >= end; i--) {
- rb_yield(INT2FIX(i));
- }
-
- return from;
-}
-
-static VALUE
-fix_step(from, to, step)
- VALUE from, to, step;
-{
- long i, end, diff;
-
- if (!FIXNUM_P(to) || !FIXNUM_P(step))
- return int_step(from, to, step);
-
- i = FIX2LONG(from);
- end = FIX2LONG(to);
- diff = FIX2LONG(step);
+ if (FIXNUM_P(num)) {
+ long i, end;
- if (diff == 0) {
- rb_raise(rb_eArgError, "step cannot be 0");
- }
- if (diff > 0) {
- while (i <= end) {
+ end = FIX2LONG(num);
+ for (i=0; i<end; i++) {
rb_yield(INT2FIX(i));
- i += diff;
}
}
else {
- while (i >= end) {
- rb_yield(INT2FIX(i));
- i += diff;
- }
- }
- return from;
-}
+ VALUE i = INT2FIX(0);
-static VALUE
-fix_dotimes(num)
- VALUE num;
-{
- long i, end;
-
- end = FIX2LONG(num);
- for (i=0; i<end; i++) {
- rb_yield(INT2FIX(i));
+ for (;;) {
+ if (!RTEST(rb_funcall(i, '<', 1, num))) break;
+ rb_yield(i);
+ i = rb_funcall(i, '+', 1, INT2FIX(1));
+ }
}
return num;
}
@@ -1643,6 +1620,7 @@ Init_Numeric()
rb_define_method(rb_cNumeric, "ceil", num_ceil, 0);
rb_define_method(rb_cNumeric, "round", num_round, 0);
rb_define_method(rb_cNumeric, "truncate", num_truncate, 0);
+ rb_define_method(rb_cNumeric, "step", num_step, -1);
rb_cInteger = rb_define_class("Integer", rb_cNumeric);
rb_undef_method(CLASS_OF(rb_cInteger), "allocate");
@@ -1651,7 +1629,6 @@ Init_Numeric()
rb_define_method(rb_cInteger, "integer?", int_int_p, 0);
rb_define_method(rb_cInteger, "upto", int_upto, 1);
rb_define_method(rb_cInteger, "downto", int_downto, 1);
- rb_define_method(rb_cInteger, "step", int_step, 2);
rb_define_method(rb_cInteger, "times", int_dotimes, 0);
rb_include_module(rb_cInteger, rb_mPrecision);
rb_define_method(rb_cInteger, "succ", int_succ, 0);
@@ -1703,13 +1680,7 @@ Init_Numeric()
rb_define_method(rb_cFixnum, ">>", fix_rshift, 1);
rb_define_method(rb_cFixnum, "to_f", fix_to_f, 0);
-
rb_define_method(rb_cFixnum, "size", fix_size, 0);
-
- rb_define_method(rb_cFixnum, "upto", fix_upto, 1);
- rb_define_method(rb_cFixnum, "downto", fix_downto, 1);
- rb_define_method(rb_cFixnum, "step", fix_step, 2);
- rb_define_method(rb_cFixnum, "times", fix_dotimes, 0);
rb_define_method(rb_cFixnum, "zero?", fix_zero_p, 0);
rb_cFloat = rb_define_class("Float", rb_cNumeric);
diff --git a/object.c b/object.c
index dd3ad41664..99b8767895 100644
--- a/object.c
+++ b/object.c
@@ -867,7 +867,7 @@ convert_type(val, tname, method, raise)
m = rb_intern(method);
if (!rb_respond_to(val, m)) {
if (raise) {
- rb_raise(rb_eTypeError, "failed to convert %s into %s",
+ rb_raise(rb_eTypeError, "cannot convert %s into %s",
NIL_P(val) ? "nil" :
val == Qtrue ? "true" :
val == Qfalse ? "false" :
@@ -906,7 +906,8 @@ rb_check_convert_type(val, type, tname, method)
{
VALUE v;
- if (TYPE(val) == type) return val;
+ /* always convert T_DATA */
+ if (TYPE(val) == type && type != T_DATA) return val;
v = convert_type(val, tname, method, Qfalse);
if (NIL_P(v)) return Qnil;
if (TYPE(v) != type) {
diff --git a/parse.y b/parse.y
index 213edbbd92..2afc4ded5d 100644
--- a/parse.y
+++ b/parse.y
@@ -472,7 +472,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
}
| primary_value '[' aref_args ']' tOP_ASGN command_call
{
- NODE *tmp, *args = NEW_LIST($6);
+ NODE *args = NEW_LIST($6);
$3 = list_append($3, NEW_NIL());
list_concat(args, $3);
@@ -836,7 +836,7 @@ arg : lhs '=' arg
}
| primary_value '[' aref_args ']' tOP_ASGN arg
{
- NODE *tmp, *args = NEW_LIST($6);
+ NODE *args = NEW_LIST($6);
$3 = list_append($3, NEW_NIL());
list_concat(args, $3);
@@ -5203,46 +5203,46 @@ static struct {
ID token;
char *name;
} op_tbl[] = {
- tDOT2, "..",
- tDOT3, "...",
- '+', "+",
- '-', "-",
- '+', "+(binary)",
- '-', "-(binary)",
- '*', "*",
- '/', "/",
- '%', "%",
- tPOW, "**",
- tUPLUS, "+@",
- tUMINUS, "-@",
- tUPLUS, "+(unary)",
- tUMINUS, "-(unary)",
- '|', "|",
- '^', "^",
- '&', "&",
- tCMP, "<=>",
- '>', ">",
- tGEQ, ">=",
- '<', "<",
- tLEQ, "<=",
- tEQ, "==",
- tEQQ, "===",
- tNEQ, "!=",
- tMATCH, "=~",
- tNMATCH, "!~",
- '!', "!",
- '~', "~",
- '!', "!(unary)",
- '~', "~(unary)",
- '!', "!@",
- '~', "~@",
- tAREF, "[]",
- tASET, "[]=",
- tLSHFT, "<<",
- tRSHFT, ">>",
- tCOLON2, "::",
- '`', "`",
- 0, 0,
+ {tDOT2, ".."},
+ {tDOT3, "..."},
+ {'+', "+"},
+ {'-', "-"},
+ {'+', "+(binary)"},
+ {'-', "-(binary)"},
+ {'*', "*"},
+ {'/', "/"},
+ {'%', "%"},
+ {tPOW, "**"},
+ {tUPLUS, "+@"},
+ {tUMINUS, "-@"},
+ {tUPLUS, "+(unary)"},
+ {tUMINUS, "-(unary)"},
+ {'|', "|"},
+ {'^', "^"},
+ {'&', "&"},
+ {tCMP, "<=>"},
+ {'>', ">"},
+ {tGEQ, ">="},
+ {'<', "<"},
+ {tLEQ, "<="},
+ {tEQ, "=="},
+ {tEQQ, "==="},
+ {tNEQ, "!="},
+ {tMATCH, "=~"},
+ {tNMATCH, "!~"},
+ {'!', "!"},
+ {'~', "~"},
+ {'!', "!(unary)"},
+ {'~', "~(unary)"},
+ {'!', "!@"},
+ {'~', "~@"},
+ {tAREF, "[]"},
+ {tASET, "[]="},
+ {tLSHFT, "<<"},
+ {tRSHFT, ">>"},
+ {tCOLON2, "::"},
+ {'`', "`"},
+ {0, 0}
};
static st_table *sym_tbl;
diff --git a/range.c b/range.c
index 684566e3b5..109dd722cc 100644
--- a/range.c
+++ b/range.c
@@ -109,8 +109,6 @@ static int
r_eq(a, b)
VALUE a, b;
{
- VALUE r;
-
if (a == b) return Qtrue;
if (rb_funcall(a, id_cmp, 1, b) == INT2FIX(0))
diff --git a/re.c b/re.c
index fa048cb210..c3da5f1015 100644
--- a/re.c
+++ b/re.c
@@ -90,8 +90,6 @@ rb_memcmp(p1, p2, len)
char *p1, *p2;
long len;
{
- int tmp;
-
if (!ruby_ignorecase) {
return memcmp(p1, p2, len);
}
@@ -230,7 +228,7 @@ rb_reg_expr_str(str, s, len)
need_escape = 1;
break;
}
- p++;
+ p += mbclen(*p);
}
if (!need_escape) {
rb_str_buf_cat(str, s, len);
@@ -238,13 +236,7 @@ rb_reg_expr_str(str, s, len)
else {
p = s;
while (p<pend) {
- if (*p == '\\') {
- rb_str_buf_cat(str, p++, 1);
- if (p<pend) {
- rb_str_buf_cat(str, p, 1);
- }
- }
- else if (*p == '/') {
+ if (*p == '/' && (s == p || p[-1] != '\\')) {
char c = '\\';
rb_str_buf_cat(str, &c, 1);
rb_str_buf_cat(str, p, 1);
@@ -257,35 +249,14 @@ rb_reg_expr_str(str, s, len)
else if (ISPRINT(*p)) {
rb_str_buf_cat(str, p, 1);
}
- else {
+ else if (!ISSPACE(*p)) {
char b[8];
- switch (*p) {
- case '\r':
- rb_str_buf_cat(str, "\\r", 2);
- break;
- case '\n':
- rb_str_buf_cat(str, "\\n", 2);
- break;
- case '\t':
- rb_str_buf_cat(str, "\\t", 2);
- break;
- case '\f':
- rb_str_buf_cat(str, "\\f", 2);
- break;
- case 007:
- rb_str_buf_cat(str, "\\a", 2);
- break;
- case 013:
- rb_str_buf_cat(str, "\\v", 2);
- break;
- case 033:
- rb_str_buf_cat(str, "\\e", 2);
- break;
- default:
- sprintf(b, "\\%03o", *p & 0377);
- rb_str_buf_cat(str, b, 4);
- break;
- }
+
+ sprintf(b, "\\%03o", *p & 0377);
+ rb_str_buf_cat(str, b, 4);
+ }
+ else {
+ rb_str_buf_cat(str, p, 1);
}
p++;
}
@@ -367,10 +338,11 @@ rb_reg_to_s(re)
options = RREGEXP(re)->ptr->options;
ptr = RREGEXP(re)->str;
len = RREGEXP(re)->len;
- if (len >= 4 && ptr[0] == '(' && ptr[1] == '?' && ptr[len-1] == ')') {
+ again:
+ if (len >= 4 && ptr[0] == '(' && ptr[1] == '?') {
int err = 1;
ptr += 2;
- if ((len -= 3) > 0) {
+ if ((len -= 2) > 0) {
do {
if (*ptr == 'm') {
options |= RE_OPTION_MULTILINE;
@@ -402,11 +374,17 @@ rb_reg_to_s(re)
++ptr;
} while (--len > 0);
}
- if (*ptr == ':') {
- Regexp *rp = ALLOC(Regexp);
- MEMZERO((char *)rp, Regexp, 1);
+ if (*ptr == ')') {
+ --len;
+ ++ptr;
+ goto again;
+ }
+ if (*ptr == ':' && ptr[len-1] == ')') {
+ Regexp *rp;
kcode_set_option(re);
- err = re_compile_pattern(++ptr, --len, rp) != 0;
+ rp = ALLOC(Regexp);
+ MEMZERO((char *)rp, Regexp, 1);
+ err = re_compile_pattern(++ptr, len -= 2, rp) != 0;
kcode_reset_option();
re_free_pattern(rp);
}
diff --git a/regex.c b/regex.c
index 96f16de7e2..020b8c8d43 100644
--- a/regex.c
+++ b/regex.c
@@ -720,9 +720,9 @@ is_in_list(c, b)
else
j = k;
}
- if (i < size && EXTRACT_MBC(&b[i*8]) <= c
- && ((unsigned char)c != '\n' && (unsigned char)c != '\0'))
+ if (i < size && EXTRACT_MBC(&b[i*8]) <= c)
return 1;
+
return 0;
}
@@ -832,7 +832,7 @@ print_partial_compiled_pattern(start, end)
unsigned bit;
unsigned char map_byte = p[c];
- putchar ('/');
+ putchar('/');
for (bit = 0; bit < BYTEWIDTH; bit++)
if (map_byte & (1 << bit))
@@ -840,10 +840,10 @@ print_partial_compiled_pattern(start, end)
}
p += mcnt;
mcnt = EXTRACT_UNSIGNED_AND_INCR(p);
- printf("/");
+ putchar('/');
while (mcnt--) {
print_mbc(EXTRACT_MBC_AND_INCR(p));
- printf("-");
+ putchar('-');
print_mbc(EXTRACT_MBC_AND_INCR(p));
}
break;
diff --git a/regex.h b/regex.h
index fbc29b20ae..668cac925c 100644
--- a/regex.h
+++ b/regex.h
@@ -23,8 +23,8 @@
Last change: May 21, 1993 by t^2 */
/* modified for Ruby by matz@netlab.co.jp */
-#ifndef __REGEXP_LIBRARY
-#define __REGEXP_LIBRARY
+#ifndef REGEX_H
+#define REGEX_H
/* symbol mangling for ruby */
#ifdef RUBY
@@ -222,4 +222,4 @@ extern void re_free_registers ();
#endif /* __STDC__ */
-#endif /* !__REGEXP_LIBRARY */
+#endif /* !REGEX_H */
diff --git a/ruby.h b/ruby.h
index 940896476d..0bbc77f21b 100644
--- a/ruby.h
+++ b/ruby.h
@@ -66,7 +66,7 @@ extern "C" {
#endif
#if SIZEOF_LONG != SIZEOF_VOIDP
----->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
+# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
#endif
typedef unsigned long VALUE;
typedef unsigned long ID;
@@ -271,11 +271,11 @@ char *rb_str2cstr _((VALUE,int*));
VALUE rb_newobj _((void));
#define NEWOBJ(obj,type) type *obj = (type*)rb_newobj()
-#define OBJSETUP(obj,c,t) {\
+#define OBJSETUP(obj,c,t) do {\
RBASIC(obj)->flags = (t);\
RBASIC(obj)->klass = (c);\
if (rb_safe_level() >= 3) FL_SET(obj, FL_TAINT);\
-}
+} while (0)
#define CLONESETUP(clone,obj) do {\
OBJSETUP(clone,rb_singleton_class_clone(RBASIC(obj)->klass),RBASIC(obj)->flags);\
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);\
@@ -365,9 +365,8 @@ typedef void (*RUBY_DATA_FUNC) _((void*));
VALUE rb_data_object_alloc _((VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC));
-#define Data_Wrap_Struct(klass,mark,free,sval) (\
- rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)\
-)
+#define Data_Wrap_Struct(klass,mark,free,sval)\
+ rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)
#define Data_Make_Struct(klass,type,mark,free,sval) (\
sval = ALLOC(type),\
@@ -375,10 +374,10 @@ VALUE rb_data_object_alloc _((VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC));
Data_Wrap_Struct(klass,mark,free,sval)\
)
-#define Data_Get_Struct(obj,type,sval) {\
+#define Data_Get_Struct(obj,type,sval) do {\
Check_Type(obj, T_DATA); \
sval = (type*)DATA_PTR(obj);\
-}
+} while (0)
struct RStruct {
struct RBasic basic;
diff --git a/rubysig.h b/rubysig.h
index 7b8e71a62e..777bef31f2 100644
--- a/rubysig.h
+++ b/rubysig.h
@@ -23,8 +23,9 @@ typedef LONG rb_atomic_t;
/* Windows doesn't allow interrupt while system calls */
# define TRAP_BEG do {\
- rb_atomic_t trap_immediate = ATOMIC_SET(rb_trap_immediate, 1);
-# define TRAP_END ATOMIC_SET(rb_trap_immediate, trap_immediate);\
+ rb_atomic_t trap_immediate = ATOMIC_SET(rb_trap_immediate, 1)
+# define TRAP_END\
+ ATOMIC_SET(rb_trap_immediate, trap_immediate);\
} while (0)
# define RUBY_CRITICAL(statements) do {\
win32_enter_critical();\
@@ -41,7 +42,7 @@ typedef int rb_atomic_t;
# define TRAP_BEG do {\
int trap_immediate = rb_trap_immediate;\
- rb_trap_immediate = 1;
+ rb_trap_immediate = 1
# define TRAP_END rb_trap_immediate = trap_immediate;\
} while (0)
@@ -55,9 +56,12 @@ typedef int rb_atomic_t;
EXTERN rb_atomic_t rb_trap_immediate;
EXTERN int rb_prohibit_interrupt;
-#define DEFER_INTS {rb_prohibit_interrupt++;}
-#define ALLOW_INTS {rb_prohibit_interrupt--; CHECK_INTS;}
-#define ENABLE_INTS {rb_prohibit_interrupt--;}
+#define DEFER_INTS (rb_prohibit_interrupt++)
+#define ALLOW_INTS do {\
+ rb_prohibit_interrupt--;\
+ CHECK_INTS;\
+} while (0)
+#define ENABLE_INTS (rb_prohibit_interrupt--)
VALUE rb_with_disable_interrupt _((VALUE(*)(ANYARGS),VALUE));
@@ -68,23 +72,28 @@ EXTERN int rb_thread_critical;
void rb_thread_schedule _((void));
#if defined(HAVE_SETITIMER) && !defined(__BOW__)
EXTERN int rb_thread_pending;
-# define CHECK_INTS if (!rb_prohibit_interrupt) {\
- if (rb_trap_pending) rb_trap_exec();\
- if (rb_thread_pending && !rb_thread_critical) rb_thread_schedule();\
-}
+# define CHECK_INTS do {\
+ if (!rb_prohibit_interrupt) {\
+ if (rb_trap_pending) rb_trap_exec();\
+ if (rb_thread_pending && !rb_thread_critical)\
+ rb_thread_schedule();\
+ }\
+} while (0)
#else
/* pseudo preemptive thread switching */
EXTERN int rb_thread_tick;
#define THREAD_TICK 500
-#define CHECK_INTS if (!rb_prohibit_interrupt) {\
- if (rb_trap_pending) rb_trap_exec();\
- if (!rb_thread_critical) {\
- if (rb_thread_tick-- <= 0) {\
- rb_thread_tick = THREAD_TICK;\
- rb_thread_schedule();\
+#define CHECK_INTS do {\
+ if (!rb_prohibit_interrupt) {\
+ if (rb_trap_pending) rb_trap_exec();\
+ if (!rb_thread_critical) {\
+ if (rb_thread_tick-- <= 0) {\
+ rb_thread_tick = THREAD_TICK;\
+ rb_thread_schedule();\
+ }\
}\
}\
-}
+} while (0)
#endif
#endif
diff --git a/signal.c b/signal.c
index c643fd48c2..5c635cc94c 100644
--- a/signal.c
+++ b/signal.c
@@ -34,139 +34,139 @@ static struct signals {
int signo;
} siglist [] = {
#ifdef SIGHUP
- "HUP", SIGHUP,
+ {"HUP", SIGHUP},
#endif
#ifdef SIGINT
- "INT", SIGINT,
+ {"INT", SIGINT},
#endif
#ifdef SIGQUIT
- "QUIT", SIGQUIT,
+ {"QUIT", SIGQUIT},
#endif
#ifdef SIGILL
- "ILL", SIGILL,
+ {"ILL", SIGILL},
#endif
#ifdef SIGTRAP
- "TRAP", SIGTRAP,
+ {"TRAP", SIGTRAP},
#endif
#ifdef SIGIOT
- "IOT", SIGIOT,
+ {"IOT", SIGIOT},
#endif
#ifdef SIGABRT
- "ABRT", SIGABRT,
+ {"ABRT", SIGABRT},
#endif
#ifdef SIGEMT
- "EMT", SIGEMT,
+ {"EMT", SIGEMT},
#endif
#ifdef SIGFPE
- "FPE", SIGFPE,
+ {"FPE", SIGFPE},
#endif
#ifdef SIGKILL
- "KILL", SIGKILL,
+ {"KILL", SIGKILL},
#endif
#ifdef SIGBUS
- "BUS", SIGBUS,
+ {"BUS", SIGBUS},
#endif
#ifdef SIGSEGV
- "SEGV", SIGSEGV,
+ {"SEGV", SIGSEGV},
#endif
#ifdef SIGSYS
- "SYS", SIGSYS,
+ {"SYS", SIGSYS},
#endif
#ifdef SIGPIPE
- "PIPE", SIGPIPE,
+ {"PIPE", SIGPIPE},
#endif
#ifdef SIGALRM
- "ALRM", SIGALRM,
+ {"ALRM", SIGALRM},
#endif
#ifdef SIGTERM
- "TERM", SIGTERM,
+ {"TERM", SIGTERM},
#endif
#ifdef SIGURG
- "URG", SIGURG,
+ {"URG", SIGURG},
#endif
#ifdef SIGSTOP
- "STOP", SIGSTOP,
+ {"STOP", SIGSTOP},
#endif
#ifdef SIGTSTP
- "TSTP", SIGTSTP,
+ {"TSTP", SIGTSTP},
#endif
#ifdef SIGCONT
- "CONT", SIGCONT,
+ {"CONT", SIGCONT},
#endif
#ifdef SIGCHLD
- "CHLD", SIGCHLD,
+ {"CHLD", SIGCHLD},
#endif
#ifdef SIGCLD
- "CLD", SIGCLD,
+ {"CLD", SIGCLD},
#else
# ifdef SIGCHLD
- "CLD", SIGCHLD,
+ {"CLD", SIGCHLD},
# endif
#endif
#ifdef SIGTTIN
- "TTIN", SIGTTIN,
+ {"TTIN", SIGTTIN},
#endif
#ifdef SIGTTOU
- "TTOU", SIGTTOU,
+ {"TTOU", SIGTTOU},
#endif
#ifdef SIGIO
- "IO", SIGIO,
+ {"IO", SIGIO},
#endif
#ifdef SIGXCPU
- "XCPU", SIGXCPU,
+ {"XCPU", SIGXCPU},
#endif
#ifdef SIGXFSZ
- "XFSZ", SIGXFSZ,
+ {"XFSZ", SIGXFSZ},
#endif
#ifdef SIGVTALRM
- "VTALRM", SIGVTALRM,
+ {"VTALRM", SIGVTALRM},
#endif
#ifdef SIGPROF
- "PROF", SIGPROF,
+ {"PROF", SIGPROF},
#endif
#ifdef SIGWINCH
- "WINCH", SIGWINCH,
+ {"WINCH", SIGWINCH},
#endif
#ifdef SIGUSR1
- "USR1", SIGUSR1,
+ {"USR1", SIGUSR1},
#endif
#ifdef SIGUSR2
- "USR2", SIGUSR2,
+ {"USR2", SIGUSR2},
#endif
#ifdef SIGLOST
- "LOST", SIGLOST,
+ {"LOST", SIGLOST},
#endif
#ifdef SIGMSG
- "MSG", SIGMSG,
+ {"MSG", SIGMSG},
#endif
#ifdef SIGPWR
- "PWR", SIGPWR,
+ {"PWR", SIGPWR},
#endif
#ifdef SIGPOLL
- "POLL", SIGPOLL,
+ {"POLL", SIGPOLL},
#endif
#ifdef SIGDANGER
- "DANGER", SIGDANGER,
+ {"DANGER", SIGDANGER},
#endif
#ifdef SIGMIGRATE
- "MIGRATE", SIGMIGRATE,
+ {"MIGRATE", SIGMIGRATE},
#endif
#ifdef SIGPRE
- "PRE", SIGPRE,
+ {"PRE", SIGPRE},
#endif
#ifdef SIGGRANT
- "GRANT", SIGGRANT,
+ {"GRANT", SIGGRANT},
#endif
#ifdef SIGRETRACT
- "RETRACT", SIGRETRACT,
+ {"RETRACT", SIGRETRACT},
#endif
#ifdef SIGSOUND
- "SOUND", SIGSOUND,
+ {"SOUND", SIGSOUND},
#endif
#ifdef SIGINFO
- "INFO", SIGINFO,
+ {"INFO", SIGINFO},
#endif
- NULL, 0,
+ {NULL, 0}
};
static int
@@ -481,7 +481,7 @@ trap(arg)
{
sighandler_t func;
VALUE command, old;
- int sig;
+ int sig = -1;
char *s;
func = sighandler;
diff --git a/string.c b/string.c
index 4eb2bb9966..399f04c859 100644
--- a/string.c
+++ b/string.c
@@ -293,7 +293,6 @@ str_copy(str, clone)
int clone;
{
VALUE str2;
- VALUE klass;
int flags;
StringValue(str);
@@ -528,16 +527,18 @@ rb_str_resize(str, len)
VALUE str;
long len;
{
+ if (len < 0) {
+ rb_raise(rb_eArgError, "negative string size (or size too big)");
+ }
+
if (len != RSTRING(str)->len) {
rb_str_modify(str);
- if (len >= 0) {
- if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) {
- RESIZE_CAPA(str, len);
- }
- RSTRING(str)->len = len;
- RSTRING(str)->ptr[len] = '\0'; /* sentinel */
+ if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) {
+ RESIZE_CAPA(str, len);
}
+ RSTRING(str)->len = len;
+ RSTRING(str)->ptr[len] = '\0'; /* sentinel */
}
return str;
}
@@ -548,7 +549,7 @@ rb_str_buf_cat(str, ptr, len)
const char *ptr;
long len;
{
- long i, capa, total;
+ long capa, total;
if (FL_TEST(str, ELTS_SHARED)) {
rb_str_modify(str);
@@ -582,8 +583,6 @@ rb_str_cat(str, ptr, len)
const char *ptr;
long len;
{
- long i, capa;
-
rb_str_modify(str);
if (len > 0) {
if (!FL_TEST(str, ELTS_SHARED) && !FL_TEST(str, STR_ASSOC)) {
@@ -615,7 +614,7 @@ VALUE
rb_str_buf_append(str, str2)
VALUE str, str2;
{
- long i, capa, len;
+ long capa, len;
if (FL_TEST(str, ELTS_SHARED)) {
rb_str_modify(str);
@@ -641,7 +640,7 @@ VALUE
rb_str_append(str, str2)
VALUE str, str2;
{
- long i, capa, len;
+ long len;
StringValue(str2);
rb_str_modify(str);
diff --git a/time.c b/time.c
index 9bfaba1ad9..d152af2516 100644
--- a/time.c
+++ b/time.c
@@ -1153,9 +1153,11 @@ time_zone(time)
VALUE time;
{
struct time_object *tobj;
+#if !defined(HAVE_TM_ZONE) && (!defined(HAVE_TZNAME) || !defined(HAVE_DAYLIGHT))
char buf[64];
int len;
-
+#endif
+
GetTimeval(time, tobj);
if (tobj->tm_got == 0) {
time_get_tm(time, tobj->gmt);
diff --git a/variable.c b/variable.c
index 339df10db1..62cfc41616 100644
--- a/variable.c
+++ b/variable.c
@@ -69,8 +69,6 @@ fc_i(key, value, res)
VALUE value;
struct fc_result *res;
{
- VALUE path;
-
if (!rb_is_const_id(key)) return ST_CONTINUE;
if (value == res->klass) {
@@ -1150,8 +1148,7 @@ rb_const_get(klass, id)
rb_id2name(id),
RSTRING(rb_class_path(klass))->ptr);
}
- else {
- global_uninitialized:
+ else { /* global_uninitialized */
rb_name_error(id, "uninitialized constant %s",rb_id2name(id));
}
return Qnil; /* not reached */
diff --git a/version.h b/version.h
index 6f4edbced3..0f11639135 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
-#define RUBY_RELEASE_DATE "2002-04-23"
+#define RUBY_RELEASE_DATE "2002-04-24"
#define RUBY_VERSION_CODE 172
-#define RUBY_RELEASE_CODE 20020423
+#define RUBY_RELEASE_CODE 20020424