From 758cb647c7ac9e02a9ee0d7cb0934a5c963481e0 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 4 Oct 1999 04:51:08 +0000 Subject: [PATCH] 19991004 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 22 +++++++++++++ Makefile.in | 14 ++++---- README.EXT | 7 ++-- README.EXT.jp | 10 ++++-- README.jp | 2 +- ToDo | 1 + eval.c | 7 ++-- ext/nkf/nkf.c | 2 +- ext/nkf/nkf1.7/nkf.c | 3 +- ext/socket/getaddrinfo.c | 4 +++ ext/socket/getnameinfo.c | 4 +++ ext/socket/socket.c | 17 ++++++++++ misc/ruby-mode.el | 7 ++-- misc/rubydb3x.el | 2 ++ missing/strftime.c | 1 + pack.c | 69 +++++++++++++++++++++------------------- parse.y | 2 +- regex.c | 2 +- time.c | 2 +- variable.c | 12 +++---- 20 files changed, 125 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 068b093929..e7f5706162 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +Mon Oct 4 12:42:32 1999 Kazuhiko Izawa + + * pack.c (pack_unpack): % in printf format should be %%. + +Mon Oct 4 10:01:40 1999 Yukihiro Matsumoto + + * variable.c (rb_obj_instance_variables): should always return + array for all object can have instance variables now. + +Mon Oct 4 00:08:34 1999 Yukihiro Matsumoto + + * pack.c (OFF16): need to adjust pointer address to pack/unpack on + 64bit machines. + +Sun Oct 03 03:05:59 1999 WATANABE Hirofumi + + * time.c (time_arg): mktime y2k problem. + +Sun Sep 26 16:54:45 1999 WATANABE Hirofumi + + * parse.y (here_document): `\r' handling for here documents. + Wed Sep 22 09:20:11 1999 Masahiro Tomita * ext/socket/socket.c: SOCKS5 support. diff --git a/Makefile.in b/Makefile.in index 865318ba70..4b1f2696aa 100644 --- a/Makefile.in +++ b/Makefile.in @@ -38,7 +38,7 @@ LIBRUBY_ALIASES= @LIBRUBY_ALIASES@ LIBRUBY = @LIBRUBY@ LIBRUBYARG = @LIBRUBYARG@ -EXTOBJS = +EXTOBJS = dmyext.@OBJEXT@ MAINOBJ = main.@OBJEXT@ @@ -83,20 +83,20 @@ OBJS = array.@OBJEXT@ \ all: miniruby$(EXEEXT) rbconfig.rb @./miniruby$(EXEEXT) -Xext extmk.rb @EXTSTATIC@ -miniruby$(EXEEXT): config.status $(LIBRUBY_A) $(MAINOBJ) dmyext.@OBJEXT@ +miniruby$(EXEEXT): config.status $(LIBRUBY_A) $(MAINOBJ) $(EXTOBJS) @rm -f $@ - $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) dmyext.@OBJEXT@ $(LIBRUBY_A) $(LIBS) -o $@ + $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBY_A) $(LIBS) -o $@ $(PROGRAM): $(LIBRUBY) $(MAINOBJ) $(EXTOBJS) @rm -f $@ $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ -$(LIBRUBY_A): $(OBJS) dmyext.@OBJEXT@ - @AR@ rcu $@ $(OBJS) dmyext.@OBJEXT@ +$(LIBRUBY_A): $(OBJS) + @AR@ rcu $@ $(OBJS) @-@RANLIB@ $@ 2> /dev/null || true -$(LIBRUBY_SO): $(OBJS) dmyext.@OBJEXT@ - $(LDSHARED) $(DLDFLAGS) $(SOLIBS) $(OBJS) dmyext.@OBJEXT@ -o $@ +$(LIBRUBY_SO): $(OBJS) + $(LDSHARED) $(DLDFLAGS) $(SOLIBS) $(OBJS) -o $@ @-./miniruby -e 'ARGV.each{|link| File.delete link if File.exist? link; \ File.symlink "$(LIBRUBY_SO)", link}' \ $(LIBRUBY_ALIASES) || true diff --git a/README.EXT b/README.EXT index c0f7048bdf..f850f01097 100644 --- a/README.EXT +++ b/README.EXT @@ -892,7 +892,6 @@ Sets the value of the instance variable. Calls the function func1, supplying func2 as the block. func1 will be called with the argument arg1. func2 receives the value from yield as the first argument, arg2 as the second argument. - VALUE rb_yield(VALUE val) @@ -942,10 +941,14 @@ exception handling nor ensure execution will be done. The embedding API are below (not needed for extension libraries): - void ruby_init(int argc, char **argv, char **envp) + void ruby_init() Initializes the interpreter. + void ruby_options(int argc, char **argv) + +Process command line arguments for the interpreter. + void ruby_run() Starts execution of the interpreter. diff --git a/README.EXT.jp b/README.EXT.jp index da3902b8cc..5305f92df4 100644 --- a/README.EXT.jp +++ b/README.EXT.jp @@ -245,8 +245,8 @@ Ruby クラスやモジュールを他のクラスの内部にネストして定義する時に は以下の関数を使います. - VALUE rb_define_class(VALUE outer, char *name, VALUE super) - VALUE rb_define_module(VALUE outer, char *name) + VALUE rb_define_class_under(VALUE outer, char *name, VALUE super) + VALUE rb_define_module_under(VALUE outer, char *name) 2.1.2 メソッド/特異メソッド定義 @@ -1099,10 +1099,14 @@ void rb_bug(char *fmt, ...) Rubyをアプリケーションに埋め込む場合には以下のインタフェース を使う.通常の拡張ライブラリには必要ない. -void ruby_init(int argc, char **argv, char **envp) +void ruby_init() Rubyインタプリタの初期化を行なう. +void ruby_options(int argc, char **argv) + + Rubyインタプリタのコマンドライン引数の処理を行なう. + void ruby_run() Rubyインタプリタを実行する. diff --git a/README.jp b/README.jp index 64610577f2..19e5e0c896 100644 --- a/README.jp +++ b/README.jp @@ -136,7 +136,7 @@ UNIX * 配布条件 Rubyはフリーソフトウェアです.GPL(the GNU General Public -Licence)または以下に示す条件でRubyを再配布できます.GPLにつ +License)または以下に示す条件でRubyを再配布できます.GPLにつ いてはCOPYINGファイルを参照して下さい. 1. 複製は制限なく自由です. diff --git a/ToDo b/ToDo index 1fa2f396ae..1014ab51c7 100644 --- a/ToDo +++ b/ToDo @@ -15,6 +15,7 @@ Language Spec. Hacking Interpreter +* RUBYOPT environment variable * non-blocking open (e.g. named pipe) for thread * avoid blocking with gethostbyname/gethostbyaddr * objectify interpreters diff --git a/eval.c b/eval.c index d22cf137ee..7a6bff985c 100644 --- a/eval.c +++ b/eval.c @@ -1185,9 +1185,9 @@ rb_eval_string_wrap(str, state) POP_CLASS(); if (state) { *state = status; - if (status) { - JUMP_TAG(status); - } + } + else if (status) { + JUMP_TAG(status); } return val; } @@ -6414,7 +6414,6 @@ rb_thread_schedule() fd_set readfds; struct timeval delay_tv, *delay_ptr; double delay, now; /* OK */ - int n, max; do { diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c index 35d9295a74..80d0d2e4be 100644 --- a/ext/nkf/nkf.c +++ b/ext/nkf/nkf.c @@ -10,7 +10,7 @@ #undef getc #undef ungetc -#define getc(f) (input_ctr>i_len?-1:input[input_ctr++]) +#define getc(f) (input_ctr #include +#ifdef SOCKS5 +#include +#endif + #include "config.h" #include "addrinfo.h" #include "sockport.h" diff --git a/ext/socket/getnameinfo.c b/ext/socket/getnameinfo.c index abadd8f442..cb65e4c070 100644 --- a/ext/socket/getnameinfo.c +++ b/ext/socket/getnameinfo.c @@ -56,6 +56,10 @@ #include #include +#ifdef SOCKS5 +#include +#endif + #include "config.h" #include "addrinfo.h" #include "sockport.h" diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 3ff6af441e..f7840948f8 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -780,6 +780,20 @@ socks_s_open(class, host, serv) Check_SafeStr(host); return open_inet(class, host, serv, INET_SOCKS); } + +#ifdef SOCKS5 +static VALUE +socks_s_close(sock) + VALUE sock; +{ + OpenFile *fptr; + + GetOpenFile(sock, fptr); + shutdown(fileno(fptr->f), 2); + shutdown(fileno(fptr->f2), 2); + return rb_io_close(sock); +} +#endif #endif /* @@ -1876,6 +1890,9 @@ Init_socket() rb_define_global_const("SOCKSsocket", rb_cSOCKSSocket); rb_define_singleton_method(rb_cSOCKSSocket, "open", socks_s_open, 2); rb_define_singleton_method(rb_cSOCKSSocket, "new", socks_s_open, 2); +#ifdef SOCKS5 + rb_define_method(rb_cSOCKSSocket, "close", socks_s_close, 0); +#endif #endif rb_cTCPServer = rb_define_class("TCPServer", rb_cTCPSocket); diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index 2875608f07..50e4f50e87 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -576,12 +576,11 @@ An end of a defun is found by moving forward from the beginning of one." (defun ruby-reindent-then-newline-and-indent () (interactive "*") - (save-excursion - (delete-region (point) (progn (skip-chars-backward " \t") (point)))) (newline) (save-excursion - (forward-line -1) - (indent-according-to-mode)) + (end-of-line 0) + (indent-according-to-mode) + (delete-region (point) (progn (skip-chars-backward " \t") (point)))) (indent-according-to-mode)) (fset 'ruby-encomment-region (symbol-function 'comment-region)) diff --git a/misc/rubydb3x.el b/misc/rubydb3x.el index 14e3dac83b..98ce1a1978 100644 --- a/misc/rubydb3x.el +++ b/misc/rubydb3x.el @@ -108,6 +108,8 @@ and source-file directory for your debugger." (gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.") (setq comint-prompt-regexp "^(rdb:-) ") + (if (boundp 'comint-last-output-start) + (set-marker comint-last-output-start (point))) (set (make-local-variable 'paragraph-start) comint-prompt-regexp) (run-hooks 'rubydb-mode-hook) ) diff --git a/missing/strftime.c b/missing/strftime.c index cc3f1a8070..6bce490249 100644 --- a/missing/strftime.c +++ b/missing/strftime.c @@ -425,6 +425,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) */ off = -(daylight ? timezone : altzone) / 60; #else /* !HAVE_TZNAME */ + gettimeofday(&tv, &zone); off = -zone.tz_minuteswest; #endif /* !HAVE_TZNAME */ #endif /* !HAVE_TM_ZONE */ diff --git a/pack.c b/pack.c index 1a4f645396..999f93a0e7 100644 --- a/pack.c +++ b/pack.c @@ -23,10 +23,19 @@ #ifdef NATINT_PACK # define NATINT_LEN(type,len) (natint?sizeof(type):(len)) +# ifndef WORDS_BIGENDIAN +# define OFF16(p) ((char*)(p) + (natint?(sizeof(short) - 2):0)) +# define OFF32(p) ((char*)(p) + (natint?(sizeof(long) - 4):0)) +# endif #else # define NATINT_LEN(type,len) sizeof(type) #endif +#ifndef OFF16 +# define OFF16(p) (char*)(p) +# define OFF32(p) (char*)(p) +#endif + #define define_swapx(x, xtype) \ static xtype \ TOKEN_PASTE(swap,x)(z) \ @@ -546,7 +555,7 @@ pack_pack(ary, fmt) else { s = NUM2INT(from); } - rb_str_cat(res, (char*)&s, NATINT_LEN(short,2)); + rb_str_cat(res, OFF16(&s), NATINT_LEN(short,2)); } break; @@ -574,7 +583,7 @@ pack_pack(ary, fmt) else { l = NUM2ULONG(from); } - rb_str_cat(res, (char*)&l, NATINT_LEN(long,4)); + rb_str_cat(res, OFF32(&l), NATINT_LEN(long,4)); } break; @@ -588,7 +597,7 @@ pack_pack(ary, fmt) s = NUM2INT(from); } s = htons(s); - rb_str_cat(res, (char*)&s, NATINT_LEN(short,2)); + rb_str_cat(res, OFF16(&s), NATINT_LEN(short,2)); } break; @@ -602,7 +611,7 @@ pack_pack(ary, fmt) l = NUM2ULONG(from); } l = htonl(l); - rb_str_cat(res, (char*)&l, NATINT_LEN(long,4)); + rb_str_cat(res, OFF32(&l), NATINT_LEN(long,4)); } break; @@ -616,7 +625,7 @@ pack_pack(ary, fmt) s = NUM2INT(from); } s = htovs(s); - rb_str_cat(res, (char*)&s, NATINT_LEN(short,2)); + rb_str_cat(res, OFF16(&s), NATINT_LEN(short,2)); } break; @@ -630,7 +639,7 @@ pack_pack(ary, fmt) l = NUM2ULONG(from); } l = htovl(l); - rb_str_cat(res, (char*)&l, NATINT_LEN(long,4)); + rb_str_cat(res, OFF32(&l), NATINT_LEN(long,4)); } break; @@ -783,7 +792,7 @@ pack_pack(ary, fmt) break; case '%': - rb_raise(rb_eArgError, "% may only be used in unpack"); + rb_raise(rb_eArgError, "%% is not supported"); break; case 'U': @@ -1062,7 +1071,7 @@ pack_unpack(str, fmt) switch (type) { case '%': - rb_raise(rb_eArgError, "% is not supported(yet)"); + rb_raise(rb_eArgError, "%% is not supported"); break; case 'A': @@ -1204,8 +1213,8 @@ pack_unpack(str, fmt) case 's': PACK_LENGTH_ADJUST(short,2); while (len-- > 0) { - short tmp; - memcpy(&tmp, s, NATINT_LEN(short,2)); + short tmp = 0; + memcpy(OFF16(&tmp), s, NATINT_LEN(short,2)); s += NATINT_LEN(short,2); rb_ary_push(ary, INT2FIX(tmp)); } @@ -1215,8 +1224,8 @@ pack_unpack(str, fmt) case 'S': PACK_LENGTH_ADJUST(unsigned short,2); while (len-- > 0) { - unsigned short tmp; - memcpy(&tmp, s, NATINT_LEN(unsigned short,2)); + unsigned short tmp = 0; + memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2)); s += NATINT_LEN(unsigned short,2); rb_ary_push(ary, INT2FIX(tmp)); } @@ -1248,8 +1257,8 @@ pack_unpack(str, fmt) case 'l': PACK_LENGTH_ADJUST(long,4); while (len-- > 0) { - long tmp; - memcpy(&tmp, s, NATINT_LEN(long,4)); + long tmp = 0; + memcpy(OFF32(&tmp), s, NATINT_LEN(long,4)); s += NATINT_LEN(long,4); rb_ary_push(ary, rb_int2inum(tmp)); } @@ -1259,8 +1268,8 @@ pack_unpack(str, fmt) case 'L': PACK_LENGTH_ADJUST(unsigned long,4); while (len-- > 0) { - unsigned long tmp; - memcpy(&tmp, s, NATINT_LEN(unsigned long,4)); + unsigned long tmp = 0; + memcpy(OFF32(&tmp), s, NATINT_LEN(unsigned long,4)); s += NATINT_LEN(unsigned long,4); rb_ary_push(ary, rb_uint2inum(tmp)); } @@ -1270,11 +1279,10 @@ pack_unpack(str, fmt) case 'n': PACK_LENGTH_ADJUST(unsigned short,2); while (len-- > 0) { - unsigned short tmp; - memcpy(&tmp, s, NATINT_LEN(unsigned short,2)); + unsigned short tmp = 0; + memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2)); s += NATINT_LEN(unsigned short,2); - tmp = ntohs(tmp); - rb_ary_push(ary, rb_uint2inum(tmp)); + rb_ary_push(ary, rb_uint2inum(ntohs(tmp))); } PACK_ITEM_ADJUST(); break; @@ -1282,11 +1290,10 @@ pack_unpack(str, fmt) case 'N': PACK_LENGTH_ADJUST(unsigned long,4); while (len-- > 0) { - unsigned long tmp; - memcpy(&tmp, s, NATINT_LEN(unsigned long,4)); + unsigned long tmp = 0; + memcpy(OFF32(&tmp), s, NATINT_LEN(unsigned long,4)); s += NATINT_LEN(unsigned long,4); - tmp = ntohl(tmp); - rb_ary_push(ary, rb_uint2inum(tmp)); + rb_ary_push(ary, rb_uint2inum(ntohl(tmp))); } PACK_ITEM_ADJUST(); break; @@ -1294,11 +1301,10 @@ pack_unpack(str, fmt) case 'v': PACK_LENGTH_ADJUST(unsigned short,2); while (len-- > 0) { - unsigned short tmp; - memcpy(&tmp, s, NATINT_LEN(unsigned short,2)); + unsigned short tmp = 0; + memcpy(OFF16(&tmp), s, NATINT_LEN(unsigned short,2)); s += NATINT_LEN(unsigned short,2); - tmp = vtohs(tmp); - rb_ary_push(ary, rb_uint2inum(tmp)); + rb_ary_push(ary, rb_uint2inum(vtohs(tmp))); } PACK_ITEM_ADJUST(); break; @@ -1306,11 +1312,10 @@ pack_unpack(str, fmt) case 'V': PACK_LENGTH_ADJUST(unsigned long,4); while (len-- > 0) { - unsigned long tmp; - memcpy(&tmp, s, NATINT_LEN(long,4)); + unsigned long tmp = 0; + memcpy(OFF32(&tmp), s, NATINT_LEN(long,4)); s += NATINT_LEN(long,4); - tmp = vtohl(tmp); - rb_ary_push(ary, rb_uint2inum(tmp)); + rb_ary_push(ary, rb_uint2inum(vtohl(tmp))); } PACK_ITEM_ADJUST(); break; diff --git a/parse.y b/parse.y index 1603a0b6d6..1108539909 100644 --- a/parse.y +++ b/parse.y @@ -2387,7 +2387,7 @@ here_document(term, indent) p++; } } - if (strncmp(eos, p, len) == 0 && p[len] == '\n') { + if (strncmp(eos, p, len) == 0 && (p[len] == '\n' || p[len] == '\r')) { break; } diff --git a/regex.c b/regex.c index d6687b97eb..fd8a447b05 100644 --- a/regex.c +++ b/regex.c @@ -2877,7 +2877,7 @@ re_compile_fastmap(bufp) break; } for (j = 0,c = 0;j < (int)size; j++) { - int cc = EXTRACT_MBC(&p[j*8]); + unsigned int cc = EXTRACT_MBC(&p[j*8]); beg = WC2MBC1ST(cc); while (c < beg) { if (ismbchar(c)) diff --git a/time.c b/time.c index 8a6d562a87..dd22c499dd 100644 --- a/time.c +++ b/time.c @@ -208,7 +208,7 @@ time_arg(argc, argv, tm) } tm->tm_year = obj2long(v[0]); - if (0 < tm->tm_year && tm->tm_year < 69) tm->tm_year += 100; + if (0 <= tm->tm_year && tm->tm_year < 69) tm->tm_year += 100; if (tm->tm_year >= 1900) tm->tm_year -= 1900; if (NIL_P(v[1])) { tm->tm_mon = 0; diff --git a/variable.c b/variable.c index 23ae945870..7b273933ac 100644 --- a/variable.c +++ b/variable.c @@ -916,7 +916,7 @@ VALUE rb_obj_instance_variables(obj) VALUE obj; { - VALUE ary; + VALUE ary = rb_ary_new(); if (!FL_TEST(obj, FL_TAINT) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't get metainfo"); @@ -924,24 +924,22 @@ rb_obj_instance_variables(obj) case T_OBJECT: case T_CLASS: case T_MODULE: - ary = rb_ary_new(); if (ROBJECT(obj)->iv_tbl) { st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, ary); } - return ary; + break; default: - if (!generic_iv_tbl) return Qnil; + if (!generic_iv_tbl) break; if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj)) { st_table *tbl; if (st_lookup(generic_iv_tbl, obj, &tbl)) { - ary = rb_ary_new(); st_foreach(tbl, ivar_i, ary); - return ary; } } + break; } - return Qnil; + return ary; } VALUE