summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-29 05:20:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-05-29 05:20:39 +0000
commit4ab1577db3bb1358af5fd387a59c541621f5df1e (patch)
tree568c351a894d8dfe24458b342b4e79d8df5444b2
parent99551555c8c957aca4ad01a776252acf3aa37775 (diff)
* parse.y: yyparse #defines moved from intern.h
* ruby.c (proc_options): access prefixed "ruby_yydebug". * applied modifies to pacify some of gcc -Wall warnings. * parse.y (arg): no more ugly hack for "**", so that "-2**2" to be parsed as "(-2)**2", whereas "- 2**2" or "-(2)**2" to be parsed as "-(2**2)". * parse.y (yylex): '-2' to be literal fixnum. [new] * time.c (time_succ): new method for Range support. * time.c (time_arg): nil test against v[6] (usec). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog24
-rw-r--r--doc/NEWS4
-rw-r--r--eval.c26
-rw-r--r--ext/etc/etc.c86
-rw-r--r--file.c6
-rw-r--r--hash.c13
-rw-r--r--intern.h6
-rw-r--r--io.c4
-rw-r--r--lib/thread.rb1
-rw-r--r--node.h2
-rw-r--r--pack.c4
-rw-r--r--parse.y9
-rw-r--r--range.c4
-rw-r--r--ruby.c6
-rw-r--r--st.c2
-rw-r--r--string.c2
-rw-r--r--time.c14
-rw-r--r--util.c8
-rw-r--r--version.h4
19 files changed, 166 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index b250a38..fce551e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,22 @@ Wed May 29 13:45:15 2002 Wakou Aoyama <wakou@ruby-lang.org>
* lib/cgi.rb: not use const if GET, HEAD. check multipart form head.
+Tue May 28 17:56:02 2002 Sean Chittenden <sean@ruby-lang.org>
+
+ * parse.y: yyparse #defines moved from intern.h
+
+ * ruby.c (proc_options): access prefixed "ruby_yydebug".
+
+ * applied modifies to pacify some of gcc -Wall warnings.
+
+Tue May 28 14:07:00 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (arg): no more ugly hack for "**", so that "-2**2" to be
+ parsed as "(-2)**2", whereas "- 2**2" or "-(2)**2" to be parsed
+ as "-(2**2)".
+
+ * parse.y (yylex): '-2' to be literal fixnum. [new]
+
Tue May 28 12:13:37 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (scope_node): trick to keep the node has a scope.
@@ -16,6 +32,14 @@ Tue May 28 12:13:37 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* node.h (NEW_DASGN, NEW_DASGN_CURR): remove surplus semicolons.
+Mon May 27 04:31:37 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * time.c (time_succ): new method for Range support.
+
+Fri May 24 09:06:29 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * time.c (time_arg): nil test against v[6] (usec).
+
Thu May 23 16:39:21 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* ruby.c (proc_options): option parsing problem.
diff --git a/doc/NEWS b/doc/NEWS
index 06552b9..7dce051 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -1,3 +1,7 @@
+: parser
+
+ Digits preceded minus sign is a literal integer.
+
: IO::sysopen
a new method to get a raw file descriptor.
diff --git a/eval.c b/eval.c
index 3f793f1..a2c0480 100644
--- a/eval.c
+++ b/eval.c
@@ -3075,6 +3075,7 @@ rb_eval(self, n)
ruby_errinfo = Qnil;
ruby_sourceline = nd_line(node);
ruby_in_eval++;
+ rb_dvar_push(0, 0);
list->nd_head = compile(list->nd_head->nd_lit,
ruby_sourcefile,
ruby_sourceline);
@@ -6627,7 +6628,7 @@ proc_to_s(self, other)
Data_Get_Struct(self, struct BLOCK, data);
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:nul */
- sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, data->tag);
+ sprintf(RSTRING(str)->ptr, "#<%s:0x%p>", cname, data->tag);
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(self)) OBJ_TAINT(str);
@@ -6642,6 +6643,28 @@ proc_to_proc(proc)
}
static VALUE
+proc_binding(proc)
+ VALUE proc;
+{
+ struct BLOCK *orig, *data;
+ VALUE bind;
+
+ Data_Get_Struct(proc, struct BLOCK, orig);
+ bind = Data_Make_Struct(rb_cBinding,struct BLOCK,blk_mark,blk_free,data);
+ MEMCPY(data, orig, struct BLOCK, 1);
+ frame_dup(&data->frame);
+
+ if (data->iter) {
+ blk_copy_prev(data);
+ }
+ else {
+ data->prev = 0;
+ }
+
+ return bind;
+}
+
+static VALUE
block_pass(self, node)
VALUE self;
NODE *node;
@@ -7149,6 +7172,7 @@ Init_Proc()
rb_define_method(rb_cProc, "==", proc_eq, 1);
rb_define_method(rb_cProc, "to_s", proc_to_s, 0);
rb_define_method(rb_cProc, "to_proc", proc_to_proc, 0);
+ rb_define_method(rb_cProc, "binding", proc_binding, 0);
rb_define_global_function("proc", rb_f_lambda, 0);
rb_define_global_function("lambda", rb_f_lambda, 0);
rb_define_global_function("binding", rb_f_binding, 0);
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 5c54237..76af10b 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -25,16 +25,17 @@
static VALUE sPasswd, sGroup;
+char *getenv();
+char *getlogin();
+
static VALUE
etc_getlogin(obj)
VALUE obj;
{
- char *getenv();
char *login;
+ rb_secure(4);
#ifdef HAVE_GETLOGIN
- char *getlogin();
-
login = getlogin();
if (!login) login = getenv("USER");
#else
@@ -91,11 +92,12 @@ etc_getpwuid(argc, argv, obj)
VALUE *argv;
VALUE obj;
{
-#ifdef HAVE_GETPWENT
- VALUE id;
+#if defined(HAVE_GETPWENT)
+ VALUE id, ary;
int uid;
struct passwd *pwd;
+ rb_secure(4);
if (rb_scan_args(argc, argv, "01", &id) == 1) {
uid = NUM2INT(id);
}
@@ -117,7 +119,7 @@ etc_getpwnam(obj, nam)
#ifdef HAVE_GETPWENT
struct passwd *pwd;
- StringValue(nam);
+ SafeStringValue(nam);
pwd = getpwnam(RSTRING(nam)->ptr);
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr);
return setup_passwd(pwd);
@@ -126,6 +128,29 @@ etc_getpwnam(obj, nam)
#endif
}
+#ifdef HAVE_GETPWENT
+static int passwd_blocking = 0;
+static VALUE
+passwd_ensure()
+{
+ passwd_blocking = Qfalse;
+ return Qnil;
+}
+
+static VALUE
+passwd_iterate()
+{
+ struct passwd *pw;
+
+ setpwent();
+ while (pw = getpwent()) {
+ rb_yield(setup_passwd(pw));
+ }
+ endpwent();
+ return Qnil;
+}
+#endif
+
static VALUE
etc_passwd(obj)
VALUE obj;
@@ -133,13 +158,13 @@ etc_passwd(obj)
#ifdef HAVE_GETPWENT
struct passwd *pw;
+ rb_secure(4);
if (rb_block_given_p()) {
- setpwent();
- while (pw = getpwent()) {
- rb_yield(setup_passwd(pw));
+ if (passwd_blocking) {
+ rb_raise(rb_eRuntimeError, "parallel passwd iteration");
}
- endpwent();
- return obj;
+ passwd_blocking = Qtrue;
+ rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
}
if (pw = getpwent()) {
return setup_passwd(pw);
@@ -178,6 +203,7 @@ etc_getgrgid(obj, id)
int gid;
struct group *grp;
+ rb_secure(4);
gid = NUM2INT(id);
grp = getgrgid(gid);
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", gid);
@@ -194,7 +220,8 @@ etc_getgrnam(obj, nam)
#ifdef HAVE_GETGRENT
struct group *grp;
- StringValue(nam);
+ rb_secure(4);
+ SafeStringValue(nam);
grp = getgrnam(RSTRING(nam)->ptr);
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING(nam)->ptr);
return setup_group(grp);
@@ -203,6 +230,29 @@ etc_getgrnam(obj, nam)
#endif
}
+#ifdef HAVE_GETGRENT
+static int group_blocking = 0;
+static VALUE
+group_ensure()
+{
+ group_blocking = Qfalse;
+ return Qnil;
+}
+
+static VALUE
+group_iterate()
+{
+ struct group *pw;
+
+ setpwent();
+ while (pw = getgrent()) {
+ rb_yield(setup_group(pw));
+ }
+ endpwent();
+ return Qnil;
+}
+#endif
+
static VALUE
etc_group(obj)
VALUE obj;
@@ -210,13 +260,13 @@ etc_group(obj)
#ifdef HAVE_GETGRENT
struct group *grp;
+ rb_secure(4);
if (rb_block_given_p()) {
- setgrent();
- while (grp = getgrent()) {
- rb_yield(setup_group(grp));
+ if (group_blocking) {
+ rb_raise(rb_eRuntimeError, "parallel group iteration");
}
- endgrent();
- return obj;
+ group_blocking = Qtrue;
+ rb_ensure(group_iterate, 0, group_ensure, 0);
}
if (grp = getgrent()) {
return setup_group(grp);
@@ -258,7 +308,7 @@ Init_etc()
"age",
#endif
#ifdef PW_CLASS
- "class",
+ "uclass",
#endif
#ifdef PW_COMMENT
"comment",
diff --git a/file.c b/file.c
index 6b8527b..718a380 100644
--- a/file.c
+++ b/file.c
@@ -294,7 +294,7 @@ rb_stat_inspect(self)
{
VALUE str;
int i;
- struct {
+ static struct {
char *name;
VALUE (*func)();
} member[] = {
@@ -329,13 +329,13 @@ rb_stat_inspect(self)
if (i == 2) { /* mode */
char buf[32];
- sprintf(buf, "0%o", NUM2INT(v));
+ sprintf(buf, "0%lo", NUM2INT(v));
rb_str_buf_cat2(str, buf);
}
else if (i == 0 || i == 6) { /* dev/rdev */
char buf[32];
- sprintf(buf, "0x%x", NUM2ULONG(v));
+ sprintf(buf, "0x%lx", NUM2ULONG(v));
rb_str_buf_cat2(str, buf);
}
else {
diff --git a/hash.c b/hash.c
index f51f46b..af1d832 100644
--- a/hash.c
+++ b/hash.c
@@ -55,19 +55,6 @@ eql(args)
return (VALUE)rb_eql(args[0], args[1]);
}
-static VALUE
-eql_failed()
-{
- return Qfalse;
-}
-
-static VALUE
-any_eql(args)
- VALUE *args;
-{
- return rb_rescue(eql, (VALUE)args, eql_failed, 0);
-}
-
static int
rb_any_cmp(a, b)
VALUE a, b;
diff --git a/intern.h b/intern.h
index cf3f628..eef7235 100644
--- a/intern.h
+++ b/intern.h
@@ -284,12 +284,6 @@ double rb_str_to_dbl _((VALUE, int));
/* parse.y */
EXTERN int ruby_sourceline;
EXTERN char *ruby_sourcefile;
-#define yyparse ruby_yyparse
-#define yylex ruby_yylex
-#define yyerror ruby_yyerror
-#define yylval ruby_yylval
-#define yychar ruby_yychar
-#define yydebug ruby_yydebug
int yyparse _((void));
ID rb_id_attrset _((ID));
void rb_parser_append_print _((void));
diff --git a/io.c b/io.c
index 8dff71b..6f14290 100644
--- a/io.c
+++ b/io.c
@@ -2081,7 +2081,7 @@ io_reopen(io, nfile)
OpenFile *fptr, *orig;
char *mode;
int fd;
- off_t pos;
+ off_t pos = 0;
nfile = rb_io_get_io(nfile);
if (rb_safe_level() >= 4 && (!OBJ_TAINTED(io) || !OBJ_TAINTED(nfile))) {
@@ -3508,7 +3508,7 @@ argf_read(argc, argv)
VALUE *argv;
{
VALUE tmp, str;
- int len;
+ int len = 0;
if (argc == 1) len = NUM2INT(argv[0]);
str = Qnil;
diff --git a/lib/thread.rb b/lib/thread.rb
index 34db9c3..a398317 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -215,6 +215,7 @@ end
class SizedQueue<Queue
def initialize(max)
+ raise ArgumentError, "queue size must be positive" unless max > 0
@max = max
@queue_wait = []
@queue_wait.taint # enable tainted comunication
diff --git a/node.h b/node.h
index ecf6145..722df09 100644
--- a/node.h
+++ b/node.h
@@ -138,7 +138,7 @@ typedef struct RNode {
union {
struct RNode *node;
ID id;
- long argc;
+ int argc;
VALUE value;
} u2;
union {
diff --git a/pack.c b/pack.c
index f43b748..8e072c9 100644
--- a/pack.c
+++ b/pack.c
@@ -1549,7 +1549,7 @@ pack_unpack(str, fmt)
{
VALUE str = infected_str_new(0, (send - s)*3/4, str);
char *ptr = RSTRING(str)->ptr;
- int a,b,c,d;
+ int a,b,c = 0,d;
static int first = 1;
static int b64_xtable[256];
@@ -1834,7 +1834,7 @@ utf8_to_uv(p, lenp)
if (n != 0) {
uv &= (1<<(BYTEWIDTH-2-n)) - 1;
while (n--) {
- uv = uv << 6 | *p++ & ((1<<6)-1);
+ uv = uv << 6 | (*p++ & ((1<<6)-1));
}
}
return uv;
diff --git a/parse.y b/parse.y
index 52d0f2a..935f678 100644
--- a/parse.y
+++ b/parse.y
@@ -13,14 +13,23 @@
%{
#define YYDEBUG 1
+
#include "ruby.h"
#include "env.h"
+#include "intern.h"
#include "node.h"
#include "st.h"
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
+#define yyparse ruby_yyparse
+#define yylex ruby_yylex
+#define yyerror ruby_yyerror
+#define yylval ruby_yylval
+#define yychar ruby_yychar
+#define yydebug ruby_yydebug
+
#define ID_SCOPE_SHIFT 3
#define ID_SCOPE_MASK 0x07
#define ID_LOCAL 0x01
diff --git a/range.c b/range.c
index 248c11b..f8596b7 100644
--- a/range.c
+++ b/range.c
@@ -22,9 +22,9 @@ static VALUE
range_check(args)
VALUE *args;
{
- rb_funcall(args[0], id_cmp, 1, args[1]);
if (!FIXNUM_P(args[0]) && !rb_obj_is_kind_of(args[0], rb_cNumeric)) {
- rb_funcall(args[0], id_succ, 0, 0);
+ rb_funcall(args[0], id_cmp, 1, args[1]);
+ /* rb_funcall(args[0], id_succ, 0, 0); */
}
return Qnil;
}
diff --git a/ruby.c b/ruby.c
index 0bc3788..42dbf6b 100644
--- a/ruby.c
+++ b/ruby.c
@@ -46,7 +46,7 @@ VALUE ruby_debug = Qfalse;
VALUE ruby_verbose = Qfalse;
static int sflag = 0;
static int xflag = 0;
-extern int yydebug;
+extern int ruby_yydebug;
char *ruby_inplace_mode = Qfalse;
@@ -436,7 +436,7 @@ proc_options(argc, argv)
goto reswitch;
case 'y':
- yydebug = 1;
+ ruby_yydebug = 1;
s++;
goto reswitch;
@@ -612,7 +612,7 @@ proc_options(argc, argv)
ruby_verbose = Qtrue;
}
else if (strcmp("yydebug", s) == 0)
- yydebug = 1;
+ ruby_yydebug = 1;
else if (strcmp("help", s) == 0) {
usage(origargv[0]);
exit(0);
diff --git a/st.c b/st.c
index 9fbb178..5ef0b7c 100644
--- a/st.c
+++ b/st.c
@@ -1,6 +1,6 @@
/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
-static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible";
+/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
#include "config.h"
#include <stdio.h>
diff --git a/string.c b/string.c
index fd58750..f3c3097 100644
--- a/string.c
+++ b/string.c
@@ -2444,7 +2444,7 @@ rb_str_split_m(argc, argv, str)
VALUE spat;
VALUE limit;
int char_sep = -1;
- long beg, end, i;
+ long beg, end, i = 0;
int lim = 0;
VALUE result, tmp;
diff --git a/time.c b/time.c
index d152af2..62865bf 100644
--- a/time.c
+++ b/time.c
@@ -254,7 +254,7 @@ time_arg(argc, argv, tm, usec)
}
else {
rb_scan_args(argc, argv, "16", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5],&v[6]);
- *usec = (argc == 7) ? NUM2INT(v[6]) : 0;
+ *usec = NIL_P(v[6]) ? 0 : obj2long(v[6]);
tm->tm_isdst = -1;
}
@@ -689,6 +689,16 @@ time_usec(time)
}
static VALUE
+time_succ(time)
+ VALUE time;
+{
+ struct time_object *tobj;
+
+ GetTimeval(time, tobj);
+ return rb_time_new(tobj->tv.tv_sec + 1, tobj->tv.tv_usec);
+}
+
+static VALUE
time_cmp(time1, time2)
VALUE time1, time2;
{
@@ -1437,6 +1447,8 @@ Init_Time()
rb_define_method(rb_cTime, "hash", time_hash, 0);
rb_define_method(rb_cTime, "clone", time_clone, 0);
rb_define_method(rb_cTime, "dup", time_dup, 0);
+ rb_define_method(rb_cTime, "succ", time_succ, 0);
+ rb_define_method(rb_cTime, "next", time_succ, 0);
rb_define_method(rb_cTime, "localtime", time_localtime, 0);
rb_define_method(rb_cTime, "gmtime", time_gmtime, 0);
diff --git a/util.c b/util.c
index 98d1619..678b8f7 100644
--- a/util.c
+++ b/util.c
@@ -12,6 +12,7 @@
#include "ruby.h"
+#include <ctype.h>
#include <stdio.h>
#include <errno.h>
@@ -747,8 +748,9 @@ ruby_strtod(string, endPtr)
* Strip off leading blanks and check for a sign.
*/
+ errno = 0;
p = string;
- while (isspace(*p)) {
+ while (ISSPACE(*p)) {
p += 1;
}
if (*p == '-') {
@@ -770,7 +772,7 @@ ruby_strtod(string, endPtr)
decPt = -1;
for (mantSize = 0; ; mantSize += 1) {
c = *p;
- if (!isdigit(c)) {
+ if (!ISDIGIT(c)) {
if ((c != '.') || (decPt >= 0)) {
break;
}
@@ -848,7 +850,7 @@ ruby_strtod(string, endPtr)
}
expSign = FALSE;
}
- while (isdigit(*p)) {
+ while (ISDIGIT(*p)) {
exp = exp * 10 + (*p - '0');
p += 1;
}
diff --git a/version.h b/version.h
index 431a752..b5b5a52 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2"
-#define RUBY_RELEASE_DATE "2002-05-28"
+#define RUBY_RELEASE_DATE "2002-05-29"
#define RUBY_VERSION_CODE 172
-#define RUBY_RELEASE_CODE 20020528
+#define RUBY_RELEASE_CODE 20020529