summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog36
-rw-r--r--README.EXT85
-rw-r--r--bignum.c9
-rw-r--r--configure94
-rw-r--r--configure.in44
-rw-r--r--dln.c2
-rw-r--r--error.c5
-rw-r--r--eval.c14
-rw-r--r--ext/Win32API/Win32API.c2
-rw-r--r--file.c126
-rw-r--r--gc.c4
-rw-r--r--hash.c2
-rw-r--r--intern.h6
-rw-r--r--io.c305
-rw-r--r--lib/complex.rb18
-rw-r--r--lib/e2mmap.rb2
-rw-r--r--lib/mutex_m.rb9
-rw-r--r--lib/sync.rb14
-rw-r--r--marshal.c9
-rw-r--r--numeric.c22
-rw-r--r--pack.c16
-rw-r--r--parse.c37
-rw-r--r--parse.y37
-rw-r--r--re.c23
-rw-r--r--ruby.c9
-rw-r--r--ruby.h6
-rw-r--r--sample/biorhythm.rb10
-rw-r--r--sample/list.rb16
-rw-r--r--sample/mine.rb36
-rw-r--r--sample/rbc.rb8
-rw-r--r--sample/rcs.rb10
-rw-r--r--sprintf.c6
-rw-r--r--string.c24
-rw-r--r--util.c2
-rw-r--r--variable.c2
-rw-r--r--version.h2
-rw-r--r--win32/config.h6
37 files changed, 682 insertions, 376 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e8189c711..7e1554c579 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+Tue Feb 9 01:22:49 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * parse.y (yylex): do not ignore newlines in mbchars.
+
+ * io.c (rb_file_s_open): mode can be specified by flags like
+ open(2), e.g. File::open(path, File::CREAT|File::WRONLY).
+
+ * io.c (rb_f_open): bit-wise mode flags for pipes
+
+ * io.c (Init_IO): bit flags for open.
+
+Sat Feb 6 22:56:21 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * string.c (rb_str_sub_bang): should not overwrite match data by
+ regexp match within the block.
+
+ * string.c (rb_str_gsub_bang): ditto.
+
+Sat Feb 6 03:06:17 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * re.c (match_getter): accessng $~ without matching caused SEGV.
+
+Fri Feb 5 22:11:08 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * parse.y (yylex): binary literal support, like 0b01001.
+
+ * parse.y (yylex): octal numbers can contain `_'s.
+
+ * parse.y (yylex): warns if non-octal number follows immediately
+ after octal literal.
+
+ * parse.y (yylex): now need at least one digit after prefix such
+ as 0x, or 0b.
+
+ * bignum.c (rb_str2inum): recognize binary numbers like 0b0101.
+
Fri Feb 5 03:26:56 1999 Yasuhiro Fukuma <yasuf@big.or.jp>
* ruby.c (proc_options): -e without program prints error.
diff --git a/README.EXT b/README.EXT
index 297b31b468..2f90c69423 100644
--- a/README.EXT
+++ b/README.EXT
@@ -109,25 +109,21 @@ bugs.
1.4 Convert C data into VALUE
-VALUEの実際の構造は
+To convert C data to the values of Ruby:
- * FIXNUMの場合
+ * FIXNUM
- 1bit右シフトして,LSBを立てる.
+ right shift 1 bit, and turn on LSB.
- * その他のポインタの場合
+ * Other pointer values
- そのままVALUEにキャストする.
+ cast to VALUE.
-となっています.よって,LSBをチェックすればVALUEがFIXNUMかど
-うかわかるわけです(ポインタのLSBが立っていないことを仮定して
-いる).
+You can determine whether VALUE is pointer or not, by checking LSB.
-ですから,FIXNUM以外のRubyのオブジェクトの構造体は単にVALUE
-にキャストするだけでVALUEに変換出来ます.ただし,任意の構造
-体がVALUEにキャスト出来るわけではありません.キャストするの
-はRubyの知っている構造体(ruby.hで定義されているstruct RXxxx
-のもの)だけにしておいてください.
+Notice Ruby does not allow arbitrary pointer value to be VALUE. They
+should be pointers to the structures which Ruby knows. The known
+structures are defined in <ruby.h>.
To convert C numbers to Ruby value, use these macros.
@@ -356,9 +352,8 @@ Ruby nil in C scope.
3.2 Global variables shared between C and Ruby
-CとRubyで大域変数を使って情報を共有できます.共有できる大域
-変数にはいくつかの種類があります.そのなかでもっとも良く使わ
-れると思われるのはrb_define_variable()です.
+Information can be shared between two worlds, using shared global
+variables. To define them, you can use functions listed below:
void rb_define_variable(char *name, VALUE *var)
@@ -371,28 +366,21 @@ function below.
void rb_define_readonly_variable(char *name, VALUE *var)
-これら変数の他にhookをつけた大域変数を定義できます.hook付き
-の大域変数は以下の関数を用いて定義します.hook付き大域変数の
-値の参照や設定はhookで行う必要があります.
+You can defined hooked variables. The accessor functions (getter and
+setter) are called on access to the hooked variables.
void rb_define_hooked_variable(char *name, VALUE *var,
VALUE (*getter)(), VALUE (*setter)())
-この関数はCの関数によってhookのつけられた大域変数を定義しま
-す.変数が参照された時には関数getterが,変数に値がセットされ
-た時には関数setterが呼ばれる.hookを指定しない場合はgetterや
-setterに0を指定します.
-
-# getterもsetterも0ならばrb_define_variable()と同じになる.
-
-それから,Cの関数によって実現されるRubyの大域変数を定義する
-関数があります.
+If you need to supply either setter or getter, just supply 0 for the
+hook you don't need. If both hooks are 0, rb_define_hooked_variable()
+works just like rb_define_variable().
void rb_define_virtual_variable(char *name,
VALUE (*getter)(), VALUE (*setter)())
-この関数によって定義されたRubyの大域変数が参照された時には
-getterが,変数に値がセットされた時にはsetterが呼ばれます.
+This function defines the Ruby global variable without corresponding C
+variable. The value of the variable will be set/get only by hooks.
The prototypes of the getter and setter functions are as following:
@@ -401,34 +389,25 @@ The prototypes of the getter and setter functions are as following:
3.3 Encapsulate C data into Ruby object
-Cの世界で定義されたデータ(構造体)をRubyのオブジェクトとして
-取り扱いたい場合がありえます.このような場合には,Dataという
-RubyオブジェクトにCの構造体(へのポインタ)をくるむことでRuby
-オブジェクトとして取り扱えるようになります.
-
-To wrapping and objectify the C pointer, use Data_Wrap_Struct().
+To wrapping and objectify the C pointer as Ruby object (so called
+DATA), use Data_Wrap_Struct().
Data_Wrap_Struct(class,mark,free,ptr)
-Data_Wrap_Struct() returns a created Data object.
-
-classはこのDataオブジェクトのクラスです.ptrはカプセル化する
-Cの構造体へのポインタです.markはこの構造体がRubyのオブジェ
-クトへの参照がある時に使う関数です.そのような参照を含まない
-時には0を指定します.
+Data_Wrap_Struct() returns a created DATA object. The class argument
+is the class for the DATA object. The mark argument is the function
+to mark Ruby objects pointed by this data. The free argument is the
+function to free the pointer allocation. The functions, mark and
+free, will be called from garbage collector.
-# そのような参照は勧められません.
-
-freeはこの構造体がもう不要になった時に呼ばれる関数です.この
-関数がガーベージコレクタから呼ばれます.
-
-Cの構造体の割当とDataオブジェクトの生成を同時に行うマクロと
-して以下のものが提供されています.
+You can allocate and wrap the structure in one step.
Data_Make_Struct(class, type, mark, free, sval)
This macro returns an allocated Data object, wrapping the pointer to
-the structure, which is also allocated.
+the structure, which is also allocated. This macro works like:
+
+ (sval = ALLOC(type), Data_Wrap_Struct(class, mark, free, sval))
Arguments, class, mark, free, works like thier counterpart of
Data_Wrap_Struct(). The pointer to allocated structure will be
@@ -445,9 +424,9 @@ See example below for detail.
4.Example - Create dbm module
-ここまでの説明でとりあえず拡張ライブラリは作れるはずです.
-Rubyのextディレクトリにすでに含まれているdbmモジュールを例に
-して段階的に説明します.
+OK, here's the example to make extension library. This is the
+extension to access dbm. The full source is included in ext/
+directory in the Ruby's source tree.
(1) make the directory
diff --git a/bignum.c b/bignum.c
index 3671dae8d9..120cceb7ec 100644
--- a/bignum.c
+++ b/bignum.c
@@ -191,6 +191,10 @@ rb_str2inum(str, base)
str++;
base = 16;
}
+ else if (*str == 'b' || *str == 'B') {
+ str++;
+ base = 2;
+ }
else {
base = 8;
}
@@ -204,10 +208,13 @@ rb_str2inum(str, base)
while (str[0] == '0') str++;
len = 3*strlen(str)*sizeof(char);
}
- else { /* base == 10 or 16 */
+ else { /* base == 10, 2 or 16 */
if (base == 16 && str[0] == '0' && (str[1] == 'x'||str[1] == 'X')) {
str += 2;
}
+ if (base == 2 && str[0] == '0' && (str[1] == 'b'||str[1] == 'B')) {
+ str += 2;
+ }
while (str[0] == '0') str++;
len = 4*strlen(str)*sizeof(char);
}
diff --git a/configure b/configure
index 5232591979..d5816b615f 100644
--- a/configure
+++ b/configure
@@ -3798,10 +3798,21 @@ echo "configure:3765: checking whether OS depend dynamic link works" >&5
rb_cv_dlopen=yes ;;
linux*) LDSHARED="gcc -shared"
rb_cv_dlopen=yes ;;
- freebsd*) LDSHARED="gcc -shared"
- test -x /usr/bin/objformat && LDFLAGS="-rdynamic"
+ freebsd*) LDSHARED="gcc -shared"
+ if test -x /usr/bin/objformat -a \
+ `/usr/bin/objformat` = "elf" ; then
+ LDFLAGS="-rdynamic"
+ DLDFLAGS='-Wl,-soname,$(.TARGET)'
+ rb_cv_freebsd_elf=yes
+ fi
rb_cv_dlopen=yes ;;
netbsd*) LDSHARED="ld -Bshareable"
+ case "$host_cpu" in
+ alpha|mips)
+ LDFLAGS="-export-dynamic" ;;
+ *)
+ ;;
+ esac
rb_cv_dlopen=yes ;;
openbsd*) LDSHARED="ld -Bforcearchive -Bshareable"
rb_cv_dlopen=yes ;;
@@ -3843,12 +3854,12 @@ if test "$ac_cv_header_a_out_h" = yes; then
if test "$with_dln_a_out" = yes || test "$rb_cv_dlopen" = unknown; then
cat confdefs.h > config.h
echo $ac_n "checking whether matz's dln works""... $ac_c" 1>&6
-echo "configure:3847: checking whether matz's dln works" >&5
+echo "configure:3858: checking whether matz's dln works" >&5
if eval "test \"`echo '$''{'rb_cv_dln_a_out'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3852 "configure"
+#line 3863 "configure"
#include "confdefs.h"
#define USE_DLN_A_OUT
@@ -3858,7 +3869,7 @@ int main() {
; return 0; }
EOF
-if { (eval echo configure:3862: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3873: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
rb_cv_dln_a_out=yes
else
@@ -3960,7 +3971,7 @@ fi
case "$host_os" in
human*)
echo $ac_n "checking for _harderr in -lsignal""... $ac_c" 1>&6
-echo "configure:3964: checking for _harderr in -lsignal" >&5
+echo "configure:3975: checking for _harderr in -lsignal" >&5
ac_lib_var=`echo signal'_'_harderr | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@@ -3968,7 +3979,7 @@ else
ac_save_LIBS="$LIBS"
LIBS="-lsignal $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3972 "configure"
+#line 3983 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
@@ -3979,7 +3990,7 @@ int main() {
_harderr()
; return 0; }
EOF
-if { (eval echo configure:3983: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3994: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
@@ -4007,7 +4018,7 @@ else
fi
echo $ac_n "checking for hmemset in -lhmem""... $ac_c" 1>&6
-echo "configure:4011: checking for hmemset in -lhmem" >&5
+echo "configure:4022: checking for hmemset in -lhmem" >&5
ac_lib_var=`echo hmem'_'hmemset | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@@ -4015,7 +4026,7 @@ else
ac_save_LIBS="$LIBS"
LIBS="-lhmem $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 4019 "configure"
+#line 4030 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
@@ -4026,7 +4037,7 @@ int main() {
hmemset()
; return 0; }
EOF
-if { (eval echo configure:4030: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4041: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
@@ -4056,12 +4067,12 @@ fi
for ac_func in select
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4060: checking for $ac_func" >&5
+echo "configure:4071: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4065 "configure"
+#line 4076 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -4084,7 +4095,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:4088: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4099: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@@ -4109,7 +4120,7 @@ fi
done
echo $ac_n "checking whether PD libc _dtos18 fail to convert big number""... $ac_c" 1>&6
-echo "configure:4113: checking whether PD libc _dtos18 fail to convert big number" >&5
+echo "configure:4124: checking whether PD libc _dtos18 fail to convert big number" >&5
if eval "test \"`echo '$''{'rb_cv_missing__dtos18'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -4117,7 +4128,7 @@ else
rb_cv_missing__dtos18=no
else
cat > conftest.$ac_ext <<EOF
-#line 4121 "configure"
+#line 4132 "configure"
#include "confdefs.h"
#include <stdio.h>
@@ -4129,7 +4140,7 @@ main ()
}
EOF
-if { (eval echo configure:4133: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4144: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
rb_cv_missing__dtos18=yes
else
@@ -4151,7 +4162,7 @@ EOF
fi
echo $ac_n "checking whether PD libc fconvert fail to round""... $ac_c" 1>&6
-echo "configure:4155: checking whether PD libc fconvert fail to round" >&5
+echo "configure:4166: checking whether PD libc fconvert fail to round" >&5
if eval "test \"`echo '$''{'rb_cv_missing_fconvert'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -4159,7 +4170,7 @@ else
rb_cv_missing_fconvert=no
else
cat > conftest.$ac_ext <<EOF
-#line 4163 "configure"
+#line 4174 "configure"
#include "confdefs.h"
#include <stdio.h>
@@ -4172,7 +4183,7 @@ main ()
}
EOF
-if { (eval echo configure:4176: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4187: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
rb_cv_missing_fconvert=yes
else
@@ -4249,9 +4260,16 @@ if test "$enable_shared" = 'yes'; then
LIBRUBYARG='-L./ -l$(RUBY_INSTALL_NAME)'
CFLAGS="$CFLAGS $CCDLFLAGS"
case "$host_os" in
- freebsd2*|sunos4*|linux*)
+ sunos4*|linux*)
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_INSTALL_NAME).so'
;;
+ freebsd*)
+ LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).so.$(MAJOR)$(MINOR)'
+ if test "$rb_cv_freebsd_elf" != "yes" ; then
+ LIBRUBY_SO="$LIBRUBY_SO.\$(TEENY)"
+ LIBRUBY_ALIASES=''
+ fi
+ ;;
hpux*)
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).sl.$(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_INSTALL_NAME).sl'
@@ -4293,12 +4311,13 @@ test "$program_suffix" != NONE &&
LIBSUFFIX=$ri_suffix
RUBY_INSTALL_NAME="${ri_prefix}ruby${ri_suffix}"
+RUBY_LIB_PATH="${prefix}/lib/${RUBY_INSTALL_NAME}/${MAJOR}.${MINOR}"
cat >> confdefs.h <<EOF
-#define RUBY_LIB "${prefix}/lib/${RUBY_INSTALL_NAME}"
+#define RUBY_LIB "${RUBY_LIB_PATH}"
EOF
cat >> confdefs.h <<EOF
-#define RUBY_SITE_LIB "${prefix}/lib/${RUBY_INSTALL_NAME}/site_ruby"
+#define RUBY_SITE_LIB "${RUBY_LIB_PATH}/site_ruby"
EOF
@@ -4306,42 +4325,29 @@ if test "$fat_binary" = yes ; then
arch="fat-${host_os}"
cat >> confdefs.h <<EOF
-#define RUBY_THIN_ARCHLIB "${prefix}/lib/${RUBY_INSTALL_NAME}/" __ARCHITECTURE__ "-${host_os}"
-EOF
-
-
- cat >> confdefs.h <<EOF
-#define RUBY_SITE_THIN_ARCHLIB "${prefix}/lib/${RUBY_INSTALL_NAME}/" __ARCHITECTURE__ "-${host_os}"
-EOF
-
-
- cat >> confdefs.h <<EOF
-#define RUBY_ARCHLIB "${prefix}/lib/${RUBY_INSTALL_NAME}/${arch}"
+#define RUBY_THIN_ARCHLIB "${RUBY_LIB_PATH}/" __ARCHITECTURE__ "-${host_os}"
EOF
- cat >> confdefs.h <<EOF
-#define RUBY_SITE_ARCHLIB "${prefix}/lib/${RUBY_INSTALL_NAME}/site_ruby/${arch}"
-EOF
cat >> confdefs.h <<EOF
-#define RUBY_PLATFORM __ARCHITECTURE__ "-${host_os}"
+#define RUBY_SITE_THIN_ARCHLIB "${RUBY_LIB_PATH}/" __ARCHITECTURE__ "-${host_os}"
EOF
else
arch="${host_cpu}-${host_os}"
- cat >> confdefs.h <<EOF
-#define RUBY_ARCHLIB "${prefix}/lib/${RUBY_INSTALL_NAME}/${arch}"
+fi
+cat >> confdefs.h <<EOF
+#define RUBY_ARCHLIB "${RUBY_LIB_PATH}/${arch}"
EOF
- cat >> confdefs.h <<EOF
-#define RUBY_SITE_ARCHLIB "${prefix}/lib/${RUBY_INSTALL_NAME}/site_ruby/${arch}"
+cat >> confdefs.h <<EOF
+#define RUBY_SITE_ARCHLIB "${RUBY_LIB_PATH}/site_ruby/${arch}"
EOF
- cat >> confdefs.h <<EOF
+cat >> confdefs.h <<EOF
#define RUBY_PLATFORM "${arch}"
EOF
-fi
echo "creating config.h"
cat confdefs.h > config.h
diff --git a/configure.in b/configure.in
index 60d860bdb3..e778bb6161 100644
--- a/configure.in
+++ b/configure.in
@@ -413,10 +413,21 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;;
linux*) LDSHARED="gcc -shared"
rb_cv_dlopen=yes ;;
- freebsd*) LDSHARED="gcc -shared"
- test -x /usr/bin/objformat && LDFLAGS="-rdynamic"
+ freebsd*) LDSHARED="gcc -shared"
+ if test -x /usr/bin/objformat -a \
+ `/usr/bin/objformat` = "elf" ; then
+ LDFLAGS="-rdynamic"
+ DLDFLAGS='-Wl,-soname,$(.TARGET)'
+ rb_cv_freebsd_elf=yes
+ fi
rb_cv_dlopen=yes ;;
netbsd*) LDSHARED="ld -Bshareable"
+ case "$host_cpu" in
+ alpha|mips)
+ LDFLAGS="-export-dynamic" ;;
+ *)
+ ;;
+ esac
rb_cv_dlopen=yes ;;
openbsd*) LDSHARED="ld -Bforcearchive -Bshareable"
rb_cv_dlopen=yes ;;
@@ -624,9 +635,16 @@ if test "$enable_shared" = 'yes'; then
LIBRUBYARG='-L./ -l$(RUBY_INSTALL_NAME)'
CFLAGS="$CFLAGS $CCDLFLAGS"
case "$host_os" in
- freebsd2*|sunos4*|linux*)
+ sunos4*|linux*)
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).so.$(MAJOR).$(MINOR) lib$(RUBY_INSTALL_NAME).so'
;;
+ freebsd*)
+ LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).so.$(MAJOR)$(MINOR)'
+ if test "$rb_cv_freebsd_elf" != "yes" ; then
+ LIBRUBY_SO="$LIBRUBY_SO.\$(TEENY)"
+ LIBRUBY_ALIASES=''
+ fi
+ ;;
hpux*)
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).sl.$(MAJOR).$(MINOR).$(TEENY)'
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).sl.$(MAJOR).$(MINOR) lib$(RUBY_INSTALL_NAME).sl'
@@ -666,30 +684,26 @@ ri_suffix=
test "$program_suffix" != NONE &&
ri_suffix=$program_suffix
-LIBSUFFIX=$ri_suffix
RUBY_INSTALL_NAME="${ri_prefix}ruby${ri_suffix}"
-AC_DEFINE_UNQUOTED(RUBY_LIB, "${prefix}/lib/${RUBY_INSTALL_NAME}")
-AC_DEFINE_UNQUOTED(RUBY_SITE_LIB, "${prefix}/lib/${RUBY_INSTALL_NAME}/site_ruby")
+RUBY_LIB_PATH="${prefix}/lib/${RUBY_INSTALL_NAME}/${MAJOR}.${MINOR}"
+AC_DEFINE_UNQUOTED(RUBY_LIB, "${RUBY_LIB_PATH}")
+AC_DEFINE_UNQUOTED(RUBY_SITE_LIB, "${RUBY_LIB_PATH}/site_ruby")
AC_SUBST(arch)dnl
if test "$fat_binary" = yes ; then
arch="fat-${host_os}"
AC_DEFINE_UNQUOTED(RUBY_THIN_ARCHLIB,
- "${prefix}/lib/${RUBY_INSTALL_NAME}/" __ARCHITECTURE__ "-${host_os}" )
+ "${RUBY_LIB_PATH}/" __ARCHITECTURE__ "-${host_os}" )
AC_DEFINE_UNQUOTED(RUBY_SITE_THIN_ARCHLIB,
- "${prefix}/lib/${RUBY_INSTALL_NAME}/" __ARCHITECTURE__ "-${host_os}" )
-
- AC_DEFINE_UNQUOTED(RUBY_ARCHLIB, "${prefix}/lib/${RUBY_INSTALL_NAME}/${arch}")
- AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${prefix}/lib/${RUBY_INSTALL_NAME}/site_ruby/${arch}")
- AC_DEFINE_UNQUOTED(RUBY_PLATFORM, __ARCHITECTURE__ "-${host_os}" )
+ "${RUBY_LIB_PATH}/" __ARCHITECTURE__ "-${host_os}" )
else
arch="${host_cpu}-${host_os}"
- AC_DEFINE_UNQUOTED(RUBY_ARCHLIB, "${prefix}/lib/${RUBY_INSTALL_NAME}/${arch}")
- AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${prefix}/lib/${RUBY_INSTALL_NAME}/site_ruby/${arch}")
- AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "${arch}")
fi
+AC_DEFINE_UNQUOTED(RUBY_ARCHLIB, "${RUBY_LIB_PATH}/${arch}")
+AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${RUBY_LIB_PATH}/site_ruby/${arch}")
+AC_DEFINE_UNQUOTED(RUBY_PLATFORM, "${arch}")
echo "creating config.h"
cat confdefs.h > config.h
diff --git a/dln.c b/dln.c
index 63b608815b..023a7e735a 100644
--- a/dln.c
+++ b/dln.c
@@ -79,7 +79,7 @@ int eaccess();
#endif
#ifndef FUNCNAME_PATTERN
-# if defined(__hp9000s300) || defined(__NetBSD__) || defined(__BORLANDC__) || (defined(__FreeBSD__) && __FreeBSD__ < 3) || defined(NeXT) || defined(__WATCOMC__)
+# if defined(__hp9000s300) || (defined(__NetBSD__) && (!defined(__alpha__) && !defined(__mips__))) || defined(__BORLANDC__) || (defined(__FreeBSD__) && __FreeBSD__ < 3) || defined(NeXT) || defined(__WATCOMC__)
# define FUNCNAME_PATTERN "_Init_%.200s"
# else
# define FUNCNAME_PATTERN "Init_%.200s"
diff --git a/error.c b/error.c
index b0eb716103..64e5183cca 100644
--- a/error.c
+++ b/error.c
@@ -337,7 +337,10 @@ static VALUE
exc_backtrace(exc)
VALUE exc;
{
- return rb_iv_get(exc, "bt");
+ ID bt = rb_intern("bt");
+
+ if (!rb_ivar_defined(exc, bt)) return Qnil;
+ return rb_ivar_get(exc, bt);
}
static VALUE
diff --git a/eval.c b/eval.c
index a7f42c6d81..dcccea0a65 100644
--- a/eval.c
+++ b/eval.c
@@ -2537,7 +2537,7 @@ rb_eval(self, node)
body = search_method(ruby_class, node->nd_mid, &origin);
if (body) {
if (origin == ruby_class) {
- if (safe_level >= 3) {
+ if (safe_level >= 4) {
rb_raise(rb_eSecurityError, "re-defining method prohibited");
}
if (RTEST(ruby_verbose)) {
@@ -2604,7 +2604,7 @@ rb_eval(self, node)
}
klass = rb_singleton_class(recv);
if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &body)) {
- if (safe_level >= 3) {
+ if (safe_level >= 4) {
rb_raise(rb_eSecurityError, "re-defining method prohibited");
}
if (RTEST(ruby_verbose)) {
@@ -2709,7 +2709,7 @@ rb_eval(self, node)
rb_id2name(node->nd_cname));
}
}
- if (safe_level >= 3) {
+ if (safe_level >= 4) {
rb_raise(rb_eSecurityError, "extending class prohibited");
}
rb_clear_cache();
@@ -2751,7 +2751,7 @@ rb_eval(self, node)
rb_raise(rb_eTypeError, "%s is not a module",
rb_id2name(node->nd_cname));
}
- if (safe_level >= 3) {
+ if (safe_level >= 4) {
rb_raise(rb_eSecurityError, "extending module prohibited");
}
}
@@ -5852,6 +5852,7 @@ thread_mark(th)
rb_gc_mark(th->errinfo);
rb_gc_mark(th->last_line);
rb_gc_mark(th->last_match);
+ rb_mark_tbl(th->locals);
/* mark data in copied stack */
if (th->status == THREAD_KILLED) return;
@@ -5878,7 +5879,6 @@ thread_mark(th)
}
block = block->prev;
}
- rb_mark_tbl(th->locals);
}
void
@@ -7008,13 +7008,11 @@ rb_thread_local_aset(thread, id, val)
ID id;
VALUE val;
{
- thread_t th;
-
+ thread_t th = rb_thread_check(thread);
if (safe_level >= 4 && !FL_TEST(thread, FL_TAINT))
rb_raise(rb_eSecurityError, "Insecure: can't modify thread values");
- th = rb_thread_check(thread);
if (!th->locals) {
th->locals = st_init_numtable();
}
diff --git a/ext/Win32API/Win32API.c b/ext/Win32API/Win32API.c
index d7aa0a6149..86d72769b7 100644
--- a/ext/Win32API/Win32API.c
+++ b/ext/Win32API/Win32API.c
@@ -2,9 +2,11 @@
Win32API - Ruby Win32 API Import Facility
*/
+#ifndef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
+#endif
#define _T_VOID 0
#define _T_NUMBER 1
diff --git a/file.c b/file.c
index f636d4b244..0296a46e88 100644
--- a/file.c
+++ b/file.c
@@ -65,101 +65,6 @@ VALUE rb_cFile;
VALUE rb_mFileTest;
static VALUE sStat;
-VALUE
-rb_file_open(fname, mode)
- char *fname, *mode;
-{
- OpenFile *fptr;
- NEWOBJ(port, struct RFile);
- OBJSETUP(port, rb_cFile, T_FILE);
- MakeOpenFile(port, fptr);
-
- fptr->mode = rb_io_mode_flags(mode);
- fptr->f = rb_fopen(fname, mode);
- fptr->path = strdup(fname);
- rb_obj_call_init((VALUE)port);
-
- return (VALUE)port;
-}
-
-static VALUE
-rb_file_s_open(argc, argv, klass)
- int argc;
- VALUE *argv;
- VALUE klass;
-{
- VALUE fname, vmode, file;
- char *mode;
-
- rb_scan_args(argc, argv, "11", &fname, &vmode);
- Check_SafeStr(fname);
- if (!NIL_P(vmode)) {
- mode = STR2CSTR(vmode);
- }
- else {
- mode = "r";
- }
- file = rb_file_open(RSTRING(fname)->ptr, mode);
-
- RBASIC(file)->klass = klass;
- rb_obj_call_init(file);
- if (rb_iterator_p()) {
- return rb_ensure(rb_yield, file, rb_io_close, file);
- }
-
- return file;
-}
-
-static VALUE
-rb_file_reopen(argc, argv, file)
- int argc;
- VALUE *argv;
- VALUE file;
-{
- VALUE fname, nmode;
- char *mode;
- OpenFile *fptr;
-
- rb_secure(4);
- if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
- if (TYPE(fname) == T_FILE) { /* fname must be IO */
- return rb_io_reopen(file, fname);
- }
- }
-
- Check_SafeStr(fname);
- if (!NIL_P(nmode)) {
- mode = STR2CSTR(nmode);
- }
- else {
- mode = "r";
- }
-
- GetOpenFile(file, fptr);
- if (fptr->path) free(fptr->path);
- fptr->path = strdup(RSTRING(fname)->ptr);
- fptr->mode = rb_io_mode_flags(mode);
- if (!fptr->f) {
- fptr->f = rb_fopen(RSTRING(fname)->ptr, mode);
- if (fptr->f2) {
- fclose(fptr->f2);
- fptr->f2 = NULL;
- }
- return file;
- }
-
- if (freopen(RSTRING(fname)->ptr, mode, fptr->f) == NULL) {
- rb_sys_fail(fptr->path);
- }
- if (fptr->f2) {
- if (freopen(RSTRING(fname)->ptr, "w", fptr->f2) == NULL) {
- rb_sys_fail(fptr->path);
- }
- }
-
- return file;
-}
-
static int
apply2files(func, vargs, arg)
int (*func)();
@@ -1601,11 +1506,20 @@ rb_f_test(argc, argv)
return Qnil; /* not reached */
}
+static VALUE rb_mConst;
+
void
-Init_File()
+rb_file_const(name, value)
+ char *name;
+ VALUE value;
{
- VALUE rb_mConst;
+ rb_define_const(rb_cFile, name, value);
+ rb_define_const(rb_mConst, name, value);
+}
+void
+Init_File()
+{
rb_mFileTest = rb_define_module("FileTest");
rb_define_module_function(rb_mFileTest, "directory?", test_d, 1);
@@ -1638,9 +1552,6 @@ Init_File()
rb_cFile = rb_define_class("File", rb_cIO);
rb_extend_object(rb_cFile, CLASS_OF(rb_mFileTest));
- rb_define_singleton_method(rb_cFile, "new", rb_file_s_open, -1);
- rb_define_singleton_method(rb_cFile, "open", rb_file_s_open, -1);
-
rb_define_singleton_method(rb_cFile, "stat", rb_file_s_stat, 1);
rb_define_singleton_method(rb_cFile, "lstat", rb_file_s_lstat, 1);
rb_define_singleton_method(rb_cFile, "ftype", rb_file_s_ftype, 1);
@@ -1672,8 +1583,6 @@ Init_File()
rb_define_singleton_method(rb_cFile, "split", rb_file_s_split, 1);
rb_define_singleton_method(rb_cFile, "join", rb_file_s_join, -2);
- rb_define_method(rb_cFile, "reopen", rb_file_reopen, -1);
-
rb_define_method(rb_cIO, "stat", rb_io_stat, 0); /* this is IO's method */
rb_define_method(rb_cFile, "lstat", rb_file_lstat, 0);
@@ -1688,15 +1597,10 @@ Init_File()
rb_define_method(rb_cFile, "flock", rb_file_flock, 1);
rb_mConst = rb_define_module_under(rb_cFile, "Constants");
- rb_define_const(rb_cFile, "LOCK_SH", INT2FIX(LOCK_SH));
- rb_define_const(rb_cFile, "LOCK_EX", INT2FIX(LOCK_EX));
- rb_define_const(rb_cFile, "LOCK_UN", INT2FIX(LOCK_UN));
- rb_define_const(rb_cFile, "LOCK_NB", INT2FIX(LOCK_NB));
-
- rb_define_const(rb_mConst, "LOCK_SH", INT2FIX(LOCK_SH));
- rb_define_const(rb_mConst, "LOCK_EX", INT2FIX(LOCK_EX));
- rb_define_const(rb_mConst, "LOCK_UN", INT2FIX(LOCK_UN));
- rb_define_const(rb_mConst, "LOCK_NB", INT2FIX(LOCK_NB));
+ rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
+ rb_file_const("LOCK_EX", INT2FIX(LOCK_EX));
+ rb_file_const("LOCK_UN", INT2FIX(LOCK_UN));
+ rb_file_const("LOCK_NB", INT2FIX(LOCK_NB));
rb_define_method(rb_cFile, "path", rb_file_path, 0);
diff --git a/gc.c b/gc.c
index 021989d185..6b265db6e9 100644
--- a/gc.c
+++ b/gc.c
@@ -42,10 +42,10 @@ static void run_final();
#if defined(MSDOS) || defined(__human68k__)
#define GC_MALLOC_LIMIT 100000
#else
-#define GC_MALLOC_LIMIT 200000
+#define GC_MALLOC_LIMIT 400000
#endif
#endif
-#define GC_NEWOBJ_LIMIT 1000
+#define GC_NEWOBJ_LIMIT 10000
static unsigned long malloc_memories = 0;
static unsigned long alloc_objects = 0;
diff --git a/hash.c b/hash.c
index 318bb66f50..5cd7af2551 100644
--- a/hash.c
+++ b/hash.c
@@ -504,7 +504,7 @@ rb_hash_aset(hash, key, val)
st_insert(RHASH(hash)->tbl, key, val);
}
else {
- st_add_direct(RHASH(hash)->tbl, rb_str_dup_frozen(key), val);
+ st_add_direct(RHASH(hash)->tbl, rb_str_new4(key), val);
}
return val;
}
diff --git a/intern.h b/intern.h
index 0628477821..44e79bbf5a 100644
--- a/intern.h
+++ b/intern.h
@@ -142,9 +142,9 @@ VALUE rb_thread_main _((void));
VALUE rb_thread_local_aref _((VALUE, ID));
VALUE rb_thread_local_aset _((VALUE, ID, VALUE));
/* file.c */
-VALUE rb_file_open _((char*, char*));
int eaccess _((char*, int));
VALUE rb_file_s_expand_path _((int, VALUE *));
+void rb_file_const _((char*, VALUE));
/* gc.c */
void rb_global_variable _((VALUE*));
void rb_gc_mark_locations _((VALUE*, VALUE*));
@@ -176,8 +176,7 @@ VALUE rb_io_ungetc _((VALUE, VALUE));
VALUE rb_io_close _((VALUE));
VALUE rb_io_eof _((VALUE));
VALUE rb_io_binmode _((VALUE));
-int rb_io_mode_flags _((char*));
-VALUE rb_io_reopen _((VALUE, VALUE));
+VALUE rb_file_open _((char*, char*));
VALUE rb_gets _((void));
void rb_str_setter _((VALUE, ID, VALUE*));
/* numeric.c */
@@ -272,7 +271,6 @@ VALUE rb_str_times _((VALUE, VALUE));
VALUE rb_str_substr _((VALUE, int, int));
void rb_str_modify _((VALUE));
VALUE rb_str_freeze _((VALUE));
-VALUE rb_str_dup_frozen _((VALUE));
VALUE rb_str_resize _((VALUE, int));
VALUE rb_str_cat _((VALUE, char*, int));
VALUE rb_str_concat _((VALUE, VALUE));
diff --git a/io.c b/io.c
index 8a2162c030..439800e40c 100644
--- a/io.c
+++ b/io.c
@@ -1026,7 +1026,7 @@ rb_io_binmode(io)
return io;
}
-int
+static int
rb_io_mode_flags(mode)
char *mode;
{
@@ -1043,7 +1043,8 @@ rb_io_mode_flags(mode)
flags |= FMODE_WRITABLE;
break;
default:
- rb_raise(rb_eArgError, "illegal access mode");
+ error:
+ rb_raise(rb_eArgError, "illegal access mode %s", mode);
}
if (mode[1] == 'b') {
@@ -1053,29 +1054,79 @@ rb_io_mode_flags(mode)
if (mode[1] == '+') {
flags |= FMODE_READWRITE;
+ if (mode[2] != 0) goto error;
+ }
+ else if (mode[1] != 0) goto error;
+
+ return flags;
+}
+
+static int
+rb_io_mode_flags2(mode)
+ int mode;
+{
+ int flags;
+
+ switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) {
+ case O_RDONLY:
+ flags = FMODE_READABLE;
+ break;
+ case O_WRONLY:
+ flags = FMODE_WRITABLE;
+ break;
+ case O_RDWR:
+ flags = FMODE_WRITABLE|FMODE_READABLE;
+ break;
}
+#ifdef O_BINARY
+ if (mode & O_BINARY) {
+ flags |= FMODE_BINMODE;
+ }
+#endif
+
return flags;
}
+static int
+rb_open(fname, flag, mode)
+ char *fname;
+ int flag;
+ mode_t mode;
+{
+ int fd;
+
+ fd = open(fname, flag, mode);
+ if (fd < 0) {
+ if (errno == EMFILE || errno == ENFILE) {
+ rb_gc();
+ fd = open(fname, flag, mode);
+ }
+ if (fd < 0) {
+ rb_sys_fail(fname);
+ }
+ }
+ return fd;
+}
+
FILE *
rb_fopen(fname, mode)
char *fname;
char *mode;
{
- FILE *f;
+ FILE *file;
- f = fopen(fname, mode);
- if (f == NULL) {
+ file = fopen(fname, mode);
+ if (file == NULL) {
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
- f = fopen(fname, mode);
+ file = fopen(fname, mode);
}
- if (f == NULL) {
+ if (file == NULL) {
rb_sys_fail(fname);
}
}
- return f;
+ return file;
}
FILE *
@@ -1083,18 +1134,57 @@ rb_fdopen(fd, mode)
int fd;
char *mode;
{
- FILE *f;
+ FILE *file;
- f = fdopen(fd, mode);
- if (f == NULL) {
- if (errno == EMFILE) {
- f = fdopen(fd, mode);
+ file = fdopen(fd, mode);
+ if (file == NULL) {
+ if (errno == EMFILE || errno == ENFILE) {
+ rb_gc();
+ file = fdopen(fd, mode);
}
- if (f == NULL) {
+ if (file == NULL) {
rb_sys_fail(0);
}
}
- return f;
+ return file;
+}
+
+VALUE
+rb_file_open(fname, mode)
+ char *fname, *mode;
+{
+ OpenFile *fptr;
+ NEWOBJ(port, struct RFile);
+ OBJSETUP(port, rb_cFile, T_FILE);
+ MakeOpenFile(port, fptr);
+
+ fptr->mode = rb_io_mode_flags(mode);
+ fptr->f = rb_fopen(fname, mode);
+ fptr->path = strdup(fname);
+ rb_obj_call_init((VALUE)port);
+
+ return (VALUE)port;
+}
+
+VALUE
+rb_file_sysopen(fname, flags, mode)
+ char *fname;
+ int flags, mode;
+{
+ OpenFile *fptr;
+ int fd;
+ char *m;
+ NEWOBJ(port, struct RFile);
+ OBJSETUP(port, rb_cFile, T_FILE);
+ MakeOpenFile(port, fptr);
+
+ fd = rb_open(fname, flags, mode);
+ fptr->mode = rb_io_mode_flags2(flags);
+ fptr->f = rb_fdopen(fd, m);
+ fptr->path = strdup(fname);
+ rb_obj_call_init((VALUE)port);
+
+ return (VALUE)port;
}
#if defined (NT) || defined(DJGPP) || defined(__CYGWIN32__) || defined(__human68k__)
@@ -1330,15 +1420,41 @@ rb_io_s_popen(argc, argv, self)
}
static VALUE
-rb_io_open(fname, mode)
- char *fname, *mode;
+rb_file_s_open(argc, argv, klass)
+ int argc;
+ VALUE *argv;
+ VALUE klass;
{
- if (fname[0] == '|') {
- return pipe_open(fname+1, mode);
+ VALUE fname, vmode, file, perm;
+ char *path, *mode;
+
+ rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
+ Check_SafeStr(fname);
+ path = RSTRING(fname)->ptr;
+
+ if (FIXNUM_P(vmode)) {
+ int flags = FIX2INT(vmode);
+ int fmode = NIL_P(perm) ? 0666 : FIX2INT(perm);
+
+ file = rb_file_sysopen(path, flags, fmode);
}
else {
- return rb_file_open(fname, mode);
+ if (!NIL_P(vmode)) {
+ mode = STR2CSTR(vmode);
+ }
+ else {
+ mode = "r";
+ }
+ file = rb_file_open(RSTRING(fname)->ptr, mode);
+ }
+
+ RBASIC(file)->klass = klass;
+ rb_obj_call_init(file);
+ if (rb_iterator_p()) {
+ return rb_ensure(rb_yield, file, rb_io_close, file);
}
+
+ return file;
}
static VALUE
@@ -1347,24 +1463,57 @@ rb_f_open(argc, argv)
VALUE *argv;
{
char *mode;
- VALUE pname, pmode;
+ VALUE pname, pmode, perm;
VALUE port;
- rb_scan_args(argc, argv, "11", &pname, &pmode);
+ rb_scan_args(argc, argv, "12", &pname, &pmode, &perm);
Check_SafeStr(pname);
+ if (RSTRING(pname)->ptr[0] != '|') /* open file */
+ return rb_file_s_open(argc, argv, rb_cFile);
+
+ /* open pipe */
if (NIL_P(pmode)) {
mode = "r";
}
+ else if (FIXNUM_P(pmode)) {
+ int flags = FIX2INT(pmode);
+ char *p;
+
+ mode = p = ALLOCA_N(char, 4);
+ switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) {
+ case O_RDONLY:
+ *p++ = 'r';
+ break;
+ case O_WRONLY:
+ *p++ = 'w';
+ break;
+ case O_RDWR:
+ *p++ = 'w';
+ *p++ = '+';
+ break;
+ }
+ *p++ = '\0';
+#ifdef O_BINARY
+ if (flags & O_BINARY) {
+ if (mode[1] == '+') {
+ mode[1] = 'b'; mode[2] = '+'; mode[3] = '\0';
+ }
+ else {
+ mode[1] = 'b'; mode[2] = '\0';
+ }
+ }
+#endif
+ }
else {
int len;
mode = STR2CSTR(pmode);
len = strlen(mode);
if (len == 0 || len > 3)
- rb_raise(rb_eArgError, "illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode %s", mode);
}
- port = rb_io_open(RSTRING(pname)->ptr, mode);
+ port = pipe_open(RSTRING(pname)->ptr, mode);
if (rb_iterator_p()) {
return rb_ensure(rb_yield, port, rb_io_close, port);
}
@@ -1373,6 +1522,18 @@ rb_f_open(argc, argv)
}
static VALUE
+rb_io_open(fname, mode)
+ char *fname, *mode;
+{
+ if (fname[0] == '|') {
+ return pipe_open(fname+1, mode);
+ }
+ else {
+ return rb_file_open(fname, mode);
+ }
+}
+
+static VALUE
rb_io_get_io(io)
VALUE io;
{
@@ -1394,7 +1555,7 @@ rb_io_mode_string(fptr)
}
}
-VALUE
+static VALUE
rb_io_reopen(io, nfile)
VALUE io, nfile;
{
@@ -1459,6 +1620,56 @@ rb_io_reopen(io, nfile)
}
static VALUE
+rb_file_reopen(argc, argv, file)
+ int argc;
+ VALUE *argv;
+ VALUE file;
+{
+ VALUE fname, nmode;
+ char *mode;
+ OpenFile *fptr;
+
+ rb_secure(4);
+ if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
+ if (TYPE(fname) == T_FILE) { /* fname must be IO */
+ return rb_io_reopen(file, fname);
+ }
+ }
+
+ Check_SafeStr(fname);
+ if (!NIL_P(nmode)) {
+ mode = STR2CSTR(nmode);
+ }
+ else {
+ mode = "r";
+ }
+
+ GetOpenFile(file, fptr);
+ if (fptr->path) free(fptr->path);
+ fptr->path = strdup(RSTRING(fname)->ptr);
+ fptr->mode = rb_io_mode_flags(mode);
+ if (!fptr->f) {
+ fptr->f = rb_fopen(RSTRING(fname)->ptr, mode);
+ if (fptr->f2) {
+ fclose(fptr->f2);
+ fptr->f2 = NULL;
+ }
+ return file;
+ }
+
+ if (freopen(RSTRING(fname)->ptr, mode, fptr->f) == NULL) {
+ rb_sys_fail(fptr->path);
+ }
+ if (fptr->f2) {
+ if (freopen(RSTRING(fname)->ptr, "w", fptr->f2) == NULL) {
+ rb_sys_fail(fptr->path);
+ }
+ }
+
+ return file;
+}
+
+static VALUE
rb_io_clone(io)
VALUE io;
{
@@ -1871,8 +2082,7 @@ next_argv()
#endif
}
fw = rb_fopen(fn, "w");
-#if !defined(MSDOS) && !defined(__CYGWIN32__) && !(NT) && !defined(__human68k__)\
- && !defined(USE_CWGUSI) && !defined(__BEOS__)
+#if !defined(MSDOS) && !defined(__CYGWIN32__) && !(NT) && !defined(__human68k__) && !defined(USE_CWGUSI) && !defined(__BEOS__)
fstat(fileno(fw), &st2);
fchmod(fileno(fw), st.st_mode);
if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
@@ -1901,7 +2111,12 @@ rb_f_gets_internal(argc, argv)
retry:
if (!next_argv()) return Qnil;
- line = rb_io_gets_internal(argc, argv, file);
+ if (rb_rs == rb_default_rs) {
+ line = rb_io_gets(file);
+ }
+ else {
+ line = rb_io_gets_internal(argc, argv, file);
+ }
if (NIL_P(line) && next_p != -1) {
rb_io_close(file);
next_p = 1;
@@ -1929,6 +2144,10 @@ rb_gets()
{
VALUE line;
+ if (rb_rs != rb_default_rs) {
+ return rb_f_gets(0, 0);
+ }
+
retry:
if (!next_argv()) return Qnil;
line = rb_io_gets(file);
@@ -2453,8 +2672,8 @@ rb_io_s_pipe()
#endif
rb_sys_fail(0);
- r = prep_stdio(fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO);
- w = prep_stdio(fdopen(pipes[1], "w"), FMODE_WRITABLE, rb_cIO);
+ r = prep_stdio(rb_fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO);
+ w = prep_stdio(rb_fdopen(pipes[1], "w"), FMODE_WRITABLE, rb_cIO);
ary = rb_ary_new2(2);
rb_ary_push(ary, r);
@@ -2867,4 +3086,30 @@ Init_IO()
#endif
Init_File();
+
+ rb_define_method(rb_cFile, "reopen", rb_file_reopen, -1);
+
+ rb_define_singleton_method(rb_cFile, "new", rb_file_s_open, -1);
+ rb_define_singleton_method(rb_cFile, "open", rb_file_s_open, -1);
+
+ rb_file_const("RDONLY", INT2FIX(O_RDONLY));
+ rb_file_const("WRONLY", INT2FIX(O_WRONLY));
+ rb_file_const("RDWR", INT2FIX(O_RDWR));
+ rb_file_const("APPEND", INT2FIX(O_APPEND));
+ rb_file_const("CREAT", INT2FIX(O_CREAT));
+ rb_file_const("EXCL", INT2FIX(O_EXCL));
+#if defined(O_NDELAY) || defined(O_NONBLOCK)
+# ifdef O_NONBLOCK
+ rb_file_const("NONBLOCK", INT2FIX(O_NONBLOCK));
+# else
+ rb_file_const("NONBLOCK", INT2FIX(O_NDELAY));
+# endif
+#endif
+ rb_file_const("TRUNC", INT2FIX(O_TRUNC));
+#ifdef O_NOCTTY
+ rb_file_const("NOCTTY", INT2FIX(O_NOCTTY));
+#endif
+#ifdef O_BINARY
+ rb_file_const("BINARY", INT2FIX(O_BINARY));
+#endif
}
diff --git a/lib/complex.rb b/lib/complex.rb
index 59caad6ebc..0af8c20b89 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -72,6 +72,8 @@ class Complex < Numeric
end
def initialize(a, b = 0)
+ raise "non numeric 1st arg `#{a.inspect}'" if !a.kind_of? Numeric
+ raise "non numeric 2nd arg `#{b.inspect}'" if !b.kind_of? Numeric
@real = a
@image = b
end
@@ -84,7 +86,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
Complex(@real + other, @image)
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x + y
end
end
@@ -97,7 +99,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
Complex(@real - other, @image)
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x - y
end
end
@@ -110,7 +112,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
Complex(@real * other, @image * other)
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x * y
end
end
@@ -121,7 +123,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
Complex(@real / other, @image / other)
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x / y
end
end
@@ -163,7 +165,7 @@ class Complex < Numeric
r, theta = polar
Complex.polar(r.power!(other), theta * other)
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x / y
end
end
@@ -174,7 +176,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
Complex(@real % other, @image % other)
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x % y
end
end
@@ -187,7 +189,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
Complex(@real.divmod(other), @image.divmod(other))
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x.divmod(y)
end
end
@@ -222,7 +224,7 @@ class Complex < Numeric
elsif Complex.generic?(other)
@real == other and @image == 0
else
- x , y = a.coerce(self)
+ x , y = other.coerce(self)
x == y
end
end
diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb
index bf860dc5c1..3d72aaf7f4 100644
--- a/lib/e2mmap.rb
+++ b/lib/e2mmap.rb
@@ -72,7 +72,7 @@ else
end
end
- # 過去の互換性のため
+ # backward compatibility
def self.fail(err = nil, *rest)
if form = E2MM_ErrorMSG[err]
$! = err.new(sprintf(form, *rest))
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
index 4b8d64438e..dd92ff9883 100644
--- a/lib/mutex_m.rb
+++ b/lib/mutex_m.rb
@@ -12,7 +12,7 @@
# obj = Object.new
# obj.extend Mutex_m
# ...
-# 後はMutexと同じ使い方
+# extended object can be handled like Mutex
#
require "finalize"
@@ -36,7 +36,7 @@ module Mutex_m
dummy = cl.new
Mutex_m.extendable_module(dummy)
rescue NameError
- # newが定義されていない時は, DATAとみなす.
+ # if new is not defined, cl must be Data.
For_primitive_object
end
end
@@ -44,8 +44,8 @@ module Mutex_m
def Mutex_m.extend_class(cl)
return super if cl.instance_of?(Module)
- # モジュールの時は何もしない. クラスの場合, 適切なモジュールの決定
- # とaliasを行う.
+ # do nothing for Modules
+ # make aliases and include the proper module.
real = includable_module(cl)
cl.module_eval %q{
include real
@@ -162,7 +162,6 @@ module Mutex_m
def For_primitive_object.mu_finalize(id)
Thread.critical = TRUE
if wait = Mu_Locked.delete(id)
- # wait == [] ときだけ GCされるので, for w in wait は意味なし.
Thread.critical = FALSE
for w in wait
w.run
diff --git a/lib/sync.rb b/lib/sync.rb
index 9f9706d9ee..dc54626b4f 100644
--- a/lib/sync.rb
+++ b/lib/sync.rb
@@ -1,5 +1,5 @@
#
-# sync.rb - カウント付2-フェーズロッククラス
+# sync.rb - 2 phase lock with counter
# $Release Version: 0.2$
# $Revision$
# $Date$
@@ -54,7 +54,7 @@ module Sync_m
SH = :SH
EX = :EX
- # 例外定義
+ # exceptions
class Err < StandardError
def Err.Fail(*opt)
fail self, sprintf(self::Message, *opt)
@@ -97,7 +97,7 @@ module Sync_m
dummy = cl.new
Sync_m.extendable_module(dummy)
rescue NameError
- # newが定義されていない時は, DATAとみなす.
+ # if new is not defined, cl must be Data.
For_primitive_object
end
end
@@ -105,8 +105,8 @@ module Sync_m
def Sync_m.extend_class(cl)
return super if cl.instance_of?(Module)
- # モジュールの時は何もしない. クラスの場合, 適切なモジュールの決定
- # とaliasを行う.
+ # do nothing for Modules
+ # make aliases and include the proper module.
real = includable_module(cl)
cl.module_eval %q{
include real
@@ -267,7 +267,7 @@ module Sync_m
sync_sh_locker[Thread.current] = count + 1
ret = TRUE
when EX
- # 既に, モードがEXである時は, 必ずEXロックとなる.
+ # in EX mode, lock will upgrade to EX lock
if sync_ex_locker == Thread.current
self.sync_ex_count = sync_ex_count + 1
ret = TRUE
@@ -342,7 +342,7 @@ module Sync_m
def For_primitive_object.sync_finalize(id)
wait = Sync_Locked.delete(id)
- # waiting == [] ときだけ GCされるので, 待ち行列の解放は意味がない.
+ # need not to free waiting
end
def sync_mode
diff --git a/marshal.c b/marshal.c
index 6a68b04352..0267e328cd 100644
--- a/marshal.c
+++ b/marshal.c
@@ -12,6 +12,10 @@
#include "rubyio.h"
#include "st.h"
+#ifndef atof
+double strtod();
+#endif
+
#define MARSHAL_MAJOR 4
#define MARSHAL_MINOR 0
@@ -641,13 +645,10 @@ r_object(arg)
case TYPE_FLOAT:
{
-#ifndef atof
- double atof();
-#endif
char *buf;
r_bytes(buf, arg);
- v = rb_float_new(atof(buf));
+ v = rb_float_new(strtod(buf, 0));
return r_regist(v, arg);
}
diff --git a/numeric.c b/numeric.c
index e9f72a1943..a6ab555991 100644
--- a/numeric.c
+++ b/numeric.c
@@ -794,14 +794,32 @@ static VALUE
rb_int_induced_from(klass, x)
VALUE klass, x;
{
- return rb_funcall(x, rb_intern("to_i"), 0);
+ switch (TYPE(x)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ return x;
+ case T_FLOAT:
+ return rb_funcall(x, rb_intern("to_i"), 0);
+ default:
+ rb_raise(rb_eTypeError, "failed to convert %s into Integer",
+ rb_class2name(CLASS_OF(x)));
+ }
}
static VALUE
rb_flo_induced_from(klass, x)
VALUE klass, x;
{
- return rb_funcall(x, rb_intern("to_f"), 0);
+ switch (TYPE(x)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ return rb_funcall(x, rb_intern("to_f"), 0);
+ case T_FLOAT:
+ return x;
+ default:
+ rb_raise(rb_eTypeError, "failed to convert %s into Float",
+ rb_class2name(CLASS_OF(x)));
+ }
}
static VALUE
diff --git a/pack.c b/pack.c
index 4f9efbe74a..f064cc4be6 100644
--- a/pack.c
+++ b/pack.c
@@ -14,6 +14,10 @@
#include <sys/types.h>
#include <ctype.h>
+#ifndef atof
+double strtod();
+#endif
+
#define define_swapx(x, xtype) \
static xtype \
TOKEN_PASTE(swap,x)(z) \
@@ -587,7 +591,7 @@ pack_pack(ary, fmt)
f = RFLOAT(from)->value;
break;
case T_STRING:
- f = atof(RSTRING(from)->ptr);
+ f = strtod(RSTRING(from)->ptr, 0);
default:
f = (float)NUM2INT(from);
break;
@@ -607,7 +611,7 @@ pack_pack(ary, fmt)
f = RFLOAT(from)->value;
break;
case T_STRING:
- f = atof(RSTRING(from)->ptr);
+ f = strtod(RSTRING(from)->ptr, 0);
default:
f = (float)NUM2INT(from);
break;
@@ -628,7 +632,7 @@ pack_pack(ary, fmt)
d = RFLOAT(from)->value;
break;
case T_STRING:
- d = atof(RSTRING(from)->ptr);
+ d = strtod(RSTRING(from)->ptr, 0);
default:
d = (double)NUM2INT(from);
break;
@@ -649,7 +653,7 @@ pack_pack(ary, fmt)
d = RFLOAT(from)->value;
break;
case T_STRING:
- d = atof(RSTRING(from)->ptr);
+ d = strtod(RSTRING(from)->ptr, 0);
default:
d = (double)NUM2INT(from);
break;
@@ -669,7 +673,7 @@ pack_pack(ary, fmt)
f = RFLOAT(from)->value;
break;
case T_STRING:
- f = atof(RSTRING(from)->ptr);
+ f = strtod(RSTRING(from)->ptr, 0);
default:
f = (float)NUM2INT(from);
break;
@@ -690,7 +694,7 @@ pack_pack(ary, fmt)
d = RFLOAT(from)->value;
break;
case T_STRING:
- d = atof(RSTRING(from)->ptr);
+ d = strtod(RSTRING(from)->ptr, 0);
default:
d = (double)NUM2INT(from);
break;
diff --git a/parse.c b/parse.c
index e7385cd5a6..379d0328bd 100644
--- a/parse.c
+++ b/parse.c
@@ -5376,7 +5376,7 @@ retry:
for (i = 0; i < len; i++) {
c = nextc();
if (c == '\n') {
- ruby_sourceline++;
+ pushback(c);
break;
}
}
@@ -5689,23 +5689,44 @@ retry:
c = nextc();
if (c == 'x' || c == 'X') {
/* hexadecimal */
- while (c = nextc()) {
+ c = nextc();
+ if (!ISXDIGIT(c)) {
+ yyerror("hexadecimal number without hex-digits");
+ }
+ do {
if (c == '_') continue;
if (!ISXDIGIT(c)) break;
tokadd(c);
- }
+ } while (c = nextc());
pushback(c);
tokfix();
yylval.val = rb_str2inum(tok(), 16);
return tINTEGER;
}
- else if (c >= '0' && c <= '7') {
- /* octal */
+ if (c == 'b' || c == 'B') {
+ /* binary */
+ c = nextc();
+ if (c != '0' && c != '1') {
+ yyerror("numeric constant with no digits");
+ }
do {
+ if (c == '_') continue;
+ if (c != '0'&& c != '1') break;
+ tokadd(c);
+ } while (c = nextc());
+ pushback(c);
+ tokfix();
+ yylval.val = rb_str2inum(tok(), 2);
+ return tINTEGER;
+ }
+ else if (c >= '0' && c <= '7' || c == '_') {
+ /* octal */
+ tokadd(c);
+ do {
+ if (c == '_') continue;
+ if (c < '0' || c > '7') break;
tokadd(c);
- while ((c = nextc()) == '_')
- ;
- } while (c >= '0' && c <= '9');
+ } while (c = nextc());
pushback(c);
tokfix();
yylval.val = rb_str2inum(tok(), 8);
diff --git a/parse.y b/parse.y
index f68740f2a1..ca3505e490 100644
--- a/parse.y
+++ b/parse.y
@@ -2465,7 +2465,7 @@ retry:
for (i = 0; i < len; i++) {
c = nextc();
if (c == '\n') {
- ruby_sourceline++;
+ pushback(c);
break;
}
}
@@ -2778,23 +2778,44 @@ retry:
c = nextc();
if (c == 'x' || c == 'X') {
/* hexadecimal */
- while (c = nextc()) {
+ c = nextc();
+ if (!ISXDIGIT(c)) {
+ yyerror("hexadecimal number without hex-digits");
+ }
+ do {
if (c == '_') continue;
if (!ISXDIGIT(c)) break;
tokadd(c);
- }
+ } while (c = nextc());
pushback(c);
tokfix();
yylval.val = rb_str2inum(tok(), 16);
return tINTEGER;
}
- else if (c >= '0' && c <= '7') {
- /* octal */
+ if (c == 'b' || c == 'B') {
+ /* binary */
+ c = nextc();
+ if (c != '0' && c != '1') {
+ yyerror("numeric constant with no digits");
+ }
do {
+ if (c == '_') continue;
+ if (c != '0'&& c != '1') break;
+ tokadd(c);
+ } while (c = nextc());
+ pushback(c);
+ tokfix();
+ yylval.val = rb_str2inum(tok(), 2);
+ return tINTEGER;
+ }
+ else if (c >= '0' && c <= '7' || c == '_') {
+ /* octal */
+ tokadd(c);
+ do {
+ if (c == '_') continue;
+ if (c < '0' || c > '7') break;
tokadd(c);
- while ((c = nextc()) == '_')
- ;
- } while (c >= '0' && c <= '9');
+ } while (c = nextc());
pushback(c);
tokfix();
yylval.val = rb_str2inum(tok(), 8);
diff --git a/re.c b/re.c
index 5f176bb719..7cf085adc9 100644
--- a/re.c
+++ b/re.c
@@ -392,6 +392,21 @@ match_clone(orig)
return (VALUE)match;
}
+#define MATCH_BUSY FL_USER2
+
+void
+rb_match_busy(match, busy)
+ VALUE match;
+ int busy;
+{
+ if (busy) {
+ FL_SET(match, MATCH_BUSY);
+ }
+ else {
+ FL_UNSET(match, MATCH_BUSY);
+ }
+}
+
int ruby_ignorecase;
static int may_need_recompile;
static VALUE matchcache;
@@ -462,7 +477,7 @@ rb_reg_search(reg, str, start, reverse)
#else
match = rb_backref_get();
#endif
- if (NIL_P(match)) {
+ if (NIL_P(match) || FL_TEST(match, MATCH_BUSY)) {
if (matchcache) {
match = matchcache;
matchcache = 0;
@@ -481,7 +496,6 @@ rb_reg_search(reg, str, start, reverse)
}
result = re_search(RREGEXP(reg)->ptr,RSTRING(str)->ptr,RSTRING(str)->len,
start, range, regs);
-
if (FL_TEST(reg, KCODE_FIXED))
kcode_reset_option();
@@ -1102,7 +1116,10 @@ ignorecase_setter(val)
static VALUE
match_getter()
{
- return match_clone(rb_backref_get());
+ VALUE match = rb_backref_get();
+
+ if (NIL_P(match)) return Qnil;
+ return match_clone(match);
}
static void
diff --git a/ruby.c b/ruby.c
index 9f60cff0f6..4f2ed550e1 100644
--- a/ruby.c
+++ b/ruby.c
@@ -279,7 +279,11 @@ proc_options(argcp, argvp)
case 'e':
forbid_setid("-e");
- if (!argv[1]) {
+ if (!*++s) {
+ s = argv[1];
+ argc--,argv++;
+ }
+ if (!s) {
fprintf(stderr, "%s: no code specified for -e\n", origargv[0]);
exit(2);
}
@@ -292,9 +296,8 @@ proc_options(argcp, argvp)
}
if (script == 0) script = e_tmpname;
}
- fputs(argv[1], e_fp);
+ fputs(s, e_fp);
putc('\n', e_fp);
- argc--, argv++;
break;
case 'r':
diff --git a/ruby.h b/ruby.h
index 54b272425f..2e470c640a 100644
--- a/ruby.h
+++ b/ruby.h
@@ -525,7 +525,11 @@ rb_type(VALUE obj)
extern __inline__ int
rb_special_const_p(VALUE obj)
{
- return (FIXNUM_P(obj)||obj == Qnil||obj == Qfalse||obj == Qtrue)?Qtrue:Qfalse;
+ if (FIXNUM_P(obj)) return Qtrue;
+ if (obj == Qnil) return Qtrue;
+ if (obj == Qfalse) return Qtrue;
+ if (obj == Qtrue) return Qtrue;;
+ return Qfalse;
}
extern __inline__ int
diff --git a/sample/biorhythm.rb b/sample/biorhythm.rb
index 50ad1f2ef7..d2cbb113ec 100644
--- a/sample/biorhythm.rb
+++ b/sample/biorhythm.rb
@@ -19,11 +19,11 @@ def usage()
print "Usage:\n"
print "biorhythm.rb [options]\n"
print " options...\n"
- print " -D YYYYMMDD(birthday) : すべて default 値を使う. \n"
- print " --sdate | --date YYYYMMDD : system date もしくは指定した日付を使う.\n"
- print " --birthday YYYYMMDD : 誕生日の指定をする. \n"
- print " -v | -g : Values or Graph の指定. \n"
- print " --days DAYS : 期間の指定をする(Graph の時のみ有効). \n"
+ print " -D YYYYMMDD(birthday) : use default values.\n"
+ print " --sdate | --date YYYYMMDD : use system date; use specified date.\n"
+ print " --birthday YYYYMMDD : specifies your birthday.\n"
+ print " -v | -g : show values or graph.\n"
+ print " --days DAYS : graph range (only in effect for graphs).\n"
print " --help : help\n"
end
$USAGE = 'usage'
diff --git a/sample/list.rb b/sample/list.rb
index 76035e67d6..17eefae85a 100644
--- a/sample/list.rb
+++ b/sample/list.rb
@@ -1,8 +1,8 @@
# Linked list example
class MyElem
- # オブジェクト生成時に自動的に呼ばれるメソッド
+ # object initializer called from Class#new
def initialize(item)
- # @変数はインスタンス変数(宣言は要らない)
+ # @variables are instance variable, no declaration needed
@data = item
@succ = nil
end
@@ -15,7 +15,7 @@ class MyElem
@succ
end
- # 「obj.data = val」としたときに暗黙に呼ばれるメソッド
+ # the method invoked by ``obj.data = val''
def succ=(new)
@succ = new
end
@@ -40,12 +40,12 @@ class MyList
end
end
- # オブジェクトを文字列に変換するメソッド
- # これを再定義するとprintでの表現が変わる
+ # the method to convert object into string.
+ # redefining this will affect print.
def to_s
str = "<MyList:\n";
for elt in self
- # 「str = str + elt.data.to_s + "\n"」の省略形
+ # short form of ``str = str + elt.data.to_s + "\n"''
str += elt.data.to_s + "\n"
end
str += ">"
@@ -64,7 +64,7 @@ class Point
end
end
-# 大域変数は`$'で始まる.
+# global variables are start with `$'.
$list1 = MyList.new
$list1.add_to_list(10)
$list1.add_to_list(20)
@@ -75,6 +75,6 @@ $list2.add_to_list(20)
$list2.add_to_list(Point.new(4, 5))
$list2.add_to_list($list1)
-# 曖昧でない限りメソッド呼び出しの括弧は省略できる
+# parenthesises around method arguments can be ommitted unless ambiguous.
print "list1:\n", $list1, "\n"
print "list2:\n", $list2, "\n"
diff --git a/sample/mine.rb b/sample/mine.rb
index b9557d54a2..96af32e7e4 100644
--- a/sample/mine.rb
+++ b/sample/mine.rb
@@ -10,19 +10,19 @@ class Board
end
def put(x, y, col, str)
pos(x,y); colorstr(43,str)
- pos(0,@hi); print "$B;D$j(B:",@mc,"/",@total," "
+ pos(0,@hi); print "残り:",@mc,"/",@total," "
pos(x,y)
end
private :clr, :pos, :colorstr, :put
- CHR=["$B!&(B","$B#1(B","$B#2(B","$B#3(B","$B#4(B","$B#5(B","$B#6(B","$B#7(B","$B#8(B","$B!z(B","$B!|(B","@@"]
+ CHR=["・","1","2","3","4","5","6","7","8","★","●","@@"]
COL=[46,43,45] # default,opened,over
def initialize(h,w,m)
- # $B%2!<%`HW$N@8@.(B(h:$B=D!$(Bw:$B2#!$(Bm:$BGzCF$N?t(B)
+ # ゲーム盤の生成(h:縦,w:横,m:爆弾の数)
@hi=h; @wi=w; @m=m
reset
end
def reset
- # $B%2!<%`HW$r(B($B:F(B)$B=i4|2=$9$k(B
+ # ゲーム盤を(再)初期化する
srand()
@cx=0; @cy=0; @mc=@m
@over=false
@@ -44,7 +44,7 @@ class Board
pos(@cx,@cy)
end
def mark
- # $B8=:_$N%+!<%=%k0LCV$K%^!<%/$r$D$1$k(B
+ # 現在のカーソル位置にマークをつける
if @state[@wi*@cy+@cx] != nil then return end
@state[@wi*@cy+@cx] = "MARK"
@mc=@mc-1;
@@ -52,8 +52,8 @@ class Board
put(@cx, @cy, COL[1], CHR[9])
end
def open(x=@cx,y=@cy)
- # $B8=:_$N%+!<%=%k0LCV$r%*!<%W%s$K$9$k(B
- # $BGzCF$,$"$l$P%2!<%`%*!<%P!<(B
+ # 現在のカーソル位置をオープンにする
+ # 爆弾があればゲームオーバー
if @state[@wi*y+x] =="OPEN" then return 0 end
if @state[@wi*y+x] == nil then @total=@total-1 end
if @state[@wi*y+x] =="MARK" then @mc=@mc+1 end
@@ -73,7 +73,7 @@ class Board
pos(@cx,@cy)
end
def fetch(x,y)
- # (x,y)$B$N0LCV$NGzCF$N?t(B(0 or 1)$B$rJV$9(B
+ # (x,y)の位置の爆弾の数(0 or 1)を返す
if x < 0 then 0
elsif x >= @wi then 0
elsif y < 0 then 0
@@ -83,13 +83,13 @@ class Board
end
end
def count(x,y)
- # (x,y)$B$KNY@\$9$kGzCF$N?t$rJV$9(B
+ # (x,y)に隣接する爆弾の数を返す
fetch(x-1,y-1)+fetch(x,y-1)+fetch(x+1,y-1)+
fetch(x-1,y) + fetch(x+1,y)+
fetch(x-1,y+1)+fetch(x,y+1)+fetch(x+1,y+1)
end
def over(win)
- # $B%2!<%`$N=*N;(B
+ # ゲームの終了
quit
unless win
pos(@cx,@cy); print CHR[11]
@@ -100,8 +100,8 @@ class Board
end
end
def over?
- # $B%2!<%`$N=*N;%A%'%C%/(B
- # $B=*N;=hM}$b8F$S=P$9(B
+ # ゲームの終了チェック
+ # 終了処理も呼び出す
remain = (@mc+@total == 0)
if @over || remain
over(remain)
@@ -111,8 +111,8 @@ class Board
end
end
def quit
- # $B%2!<%`$NCfCG(B($B$^$?$O=*N;(B)
- # $BHWLL$rA4$F8+$;$k(B
+ # ゲームの中断(または終了)
+ # 盤面を全て見せる
@hi.times do|y|
pos(0,y)
@wi.times do|x|
@@ -122,19 +122,19 @@ class Board
end
end
def down
- # $B%+!<%=%k$r2<$K(B
+ # カーソルを下に
if @cy < @hi-1 then @cy=@cy+1; pos(@cx, @cy) end
end
def up
- # $B%+!<%=%k$r>e$K(B
+ # カーソルを上に
if @cy > 0 then @cy=@cy-1; pos(@cx, @cy) end
end
def left
- # $B%+!<%=%k$r:8$K(B
+ # カーソルを左に
if @cx > 0 then @cx=@cx-1; pos(@cx, @cy) end
end
def right
- # $B%+!<%=%k$r1&$K(B
+ # カーソルを右に
if @cx < @wi-1 then @cx=@cx+1; pos(@cx, @cy) end
end
end
diff --git a/sample/rbc.rb b/sample/rbc.rb
index 83796255cc..9f1ab9443d 100644
--- a/sample/rbc.rb
+++ b/sample/rbc.rb
@@ -273,7 +273,7 @@ module BC_APPLICATION__
rests.unshift op
identify_number(rests)
else
- # obj.if などの対応
+ # handle ``obj.if'' and such
identify_identifier(rests, TRUE)
@lex_state = EXPR_ARG
end
@@ -344,7 +344,7 @@ module BC_APPLICATION__
@lex_state = EXPR_BEG
end
end
- @OP.def_rule('$') do
+ @OP.def_rule('$') do #'
|op, rests|
identify_gvar(rests)
end
@@ -466,7 +466,7 @@ module BC_APPLICATION__
print token, "\n" if CONFIG[:DEBUG]
if state = CLAUSE_STATE_TRANS[token]
if @lex_state != EXPR_BEG and token =~ /^(if|unless|while|until)/
- # 修飾子
+ # modifiers
else
if ENINDENT_CLAUSE.include?(token)
@indent += 1
@@ -640,7 +640,7 @@ module BC_APPLICATION__
def_exception :ErrNodeAlreadyExists, "node already exists"
class Node
- # postprocがなければ抽象ノード, nilじゃなければ具象ノード
+ # abstract node if postproc is nil.
def initialize(preproc = nil, postproc = nil)
@Tree = {}
@preproc = preproc
diff --git a/sample/rcs.rb b/sample/rcs.rb
index 3f74da9ef2..7c091936f3 100644
--- a/sample/rcs.rb
+++ b/sample/rcs.rb
@@ -1,12 +1,12 @@
# random dot steraogram
# usage: rcs.rb rcs.dat
-sw = 40.0 # p^[
-dw = 78.0 # Random Character Streogram
+sw = 40.0 # width of original pattern
+dw = 78.0 # width of generating Random Character Streogram
hdw = dw / 2.0
-w = 20.0 #
-h =1.0 #
-d = 0.2 # P
+w = 20.0 # distance between eyes
+h =1.0 # distance from screen and base plane
+d = 0.2 # z value unit
ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./"
rnd = srand()
diff --git a/sprintf.c b/sprintf.c
index 936a3d1960..eddb9024e5 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -13,6 +13,10 @@
#include "ruby.h"
#include <ctype.h>
+#ifndef atof
+double strtod();
+#endif
+
#ifdef USE_CWGUSI
static void fmt_setup();
#else
@@ -570,7 +574,7 @@ rb_f_sprintf(argc, argv)
fval = rb_big2dbl(val);
break;
case T_STRING:
- fval = atof(RSTRING(val)->ptr);
+ fval = strtod(RSTRING(val)->ptr, 0);
break;
default:
Check_Type(val, T_FLOAT);
diff --git a/string.c b/string.c
index 7ded9e33cf..18c876dcf3 100644
--- a/string.c
+++ b/string.c
@@ -22,6 +22,10 @@
#include <unistd.h>
#endif
+#ifndef atof
+double strtod();
+#endif
+
VALUE rb_cString;
#define STR_FREEZE FL_USER1
@@ -60,14 +64,20 @@ rb_tainted_str_new(ptr, len)
char *ptr;
int len;
{
- return rb_obj_taint(rb_str_new(ptr, len));
+ VALUE str = rb_str_new(ptr, len);
+
+ FL_SET(str, FL_TAINT);
+ return str;
}
VALUE
rb_tainted_str_new2(ptr)
char *ptr;
{
- return rb_obj_taint(rb_str_new2(ptr));
+ VALUE str = rb_str_new2(ptr);
+
+ FL_SET(str, FL_TAINT);
+ return str;
}
VALUE
@@ -102,7 +112,7 @@ rb_str_new4(orig)
str->ptr = RSTRING(orig)->ptr;
RSTRING(orig)->orig = (VALUE)str;
str->orig = 0;
- if (rb_safe_level() >= 3) {
+ if (FL_TEST(str, FL_TAINT)) {
FL_SET(str, FL_TAINT);
}
return (VALUE)str;
@@ -1028,7 +1038,10 @@ rb_str_sub_bang(argc, argv, str)
regs = RMATCH(match)->regs;
if (iter) {
+ rb_match_busy(match, Qtrue);
repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
+ rb_match_busy(match, Qfalse);
+ rb_backref_set(match);
}
else {
repl = rb_reg_regsub(repl, str, regs);
@@ -1102,7 +1115,10 @@ rb_str_gsub_bang(argc, argv, str)
match = rb_backref_get();
regs = RMATCH(match)->regs;
if (iter) {
+ rb_match_busy(match, Qtrue);
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
+ rb_match_busy(match, Qfalse);
+ rb_backref_set(match);
}
else {
val = rb_reg_regsub(repl, str, regs);
@@ -1313,7 +1329,7 @@ static VALUE
rb_str_to_f(str)
VALUE str;
{
- double f = atof(RSTRING(str)->ptr);
+ double f = strtod(RSTRING(str)->ptr, 0);
return rb_float_new(f);
}
diff --git a/util.c b/util.c
index d90fd08b19..fb82a1f190 100644
--- a/util.c
+++ b/util.c
@@ -761,7 +761,7 @@ void ruby_qsort (base, nel, size, cmp) void* base; int nel; int size; int (*cmp)
if (t < 0) {mmswap(L,l); l = L; goto loopB;} /*535-5*/
}
- loopA: eq_l = 1; eq_r = 1; /* splitting type A */ /* left <= median < right右*/
+ loopA: eq_l = 1; eq_r = 1; /* splitting type A */ /* left <= median < right */
for (;;) {
for (;;) {
if ((l += size) == r)
diff --git a/variable.c b/variable.c
index 3cd6122533..b4af07f9c2 100644
--- a/variable.c
+++ b/variable.c
@@ -873,8 +873,6 @@ rb_ivar_defined(obj, id)
VALUE obj;
ID id;
{
- if (!rb_is_instance_id(id)) return Qfalse;
-
switch (TYPE(obj)) {
case T_OBJECT:
case T_CLASS:
diff --git a/version.h b/version.h
index fa8f39fa69..bf3b49a355 100644
--- a/version.h
+++ b/version.h
@@ -1,2 +1,2 @@
#define RUBY_VERSION "1.3.1"
-#define VERSION_DATE "99/02/05"
+#define VERSION_DATE "99/02/09"
diff --git a/win32/config.h b/win32/config.h
index 56aade0e35..a4de1bfd70 100644
--- a/win32/config.h
+++ b/win32/config.h
@@ -46,3 +46,9 @@
#define RUBY_ARCHLIB "/usr/local/lib/ruby/i386-mswin32"
#define RUBY_PLATFORM "i386-mswin32"
+#define SIZEOF_INT 4
+#define SIZEOF_SHORT 2
+#define SIZEOF_LONG 4
+#define SIZEOF_VOIDP 4
+#define SIZEOF_FLOAT 4
+#define SIZEOF_DOUBLE 8