From: Michal Rokos Date: 2002-04-21T15:52:02+09:00 Subject: [Patch] clenup MACRO in eval.c 2 Hi, this patch adresses further MACROS in eval.c cleanup. (And some io.c, string.c isssues.) Please check Michal Index: eval.c =================================================================== RCS file: /src/ruby/eval.c,v retrieving revision 1.284 diff -u -r1.284 eval.c --- eval.c 2002/04/19 04:14:07 1.284 +++ eval.c 2002/04/19 15:39:10 @@ -117,7 +117,7 @@ #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; @@ -507,7 +507,7 @@ 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 +524,7 @@ ruby_sourcefile = _frame.file; \ ruby_sourceline = _frame.line; \ ruby_frame = _frame.prev; \ -} +} while (0) struct BLOCKTAG { struct RBasic super; @@ -565,7 +565,7 @@ 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 +590,10 @@ 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 +604,7 @@ FL_SET(_old, DVAR_DONT_RECYCLE); \ }\ ruby_dyna_vars = _old; \ -} +} while (0) #define DVAR_DONT_RECYCLE FL_USER2 @@ -747,7 +747,7 @@ #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 +755,7 @@ #define POP_ITER() \ ruby_iter = _iter.prev; \ -} +} while (0) struct tag { jmp_buf buf; @@ -769,7 +769,7 @@ }; 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 +796,11 @@ 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 +815,18 @@ 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 +858,7 @@ 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 +1756,7 @@ }\ } 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 +1766,7 @@ #define END_CALLARGS \ ruby_block = tmp_block;\ POP_ITER();\ -} +} while (0) #define MATCH_DATA *rb_svar(node->nd_cnt) @@ -2152,7 +2152,10 @@ 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); Index: io.c =================================================================== RCS file: /src/ruby/io.c,v retrieving revision 1.135 diff -u -r1.135 io.c --- io.c 2002/04/18 08:46:18 1.135 +++ io.c 2002/04/19 15:39:33 @@ -265,7 +265,7 @@ { OpenFile *fptr; FILE *f; - int n; + long n; rb_secure(4); if (TYPE(str) != T_STRING) @@ -284,7 +284,7 @@ #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 @@ fptr->mode |= FMODE_WBUF; } - return INT2FIX(n); + return LONG2FIX(n); } VALUE @@ -643,14 +643,14 @@ { 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); @@ -1470,7 +1470,7 @@ rb_io_modenum_flags(mode) int mode; { - int flags; + int flags = 0; switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) { case O_RDONLY: Index: string.c =================================================================== RCS file: /src/ruby/string.c,v retrieving revision 1.101 diff -u -r1.101 string.c --- string.c 2002/04/18 08:46:18 1.101 +++ string.c 2002/04/19 15:40:39 @@ -528,16 +528,18 @@ 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; } -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Michal Rokos Czech Technical University, Prague E-mail:m.rokos@sh.cvut.cz ICQ:36118339 Jabber:majkl@jabber.sh.cvut.cz -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-