summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog72
-rw-r--r--Makefile.in6
-rw-r--r--README3
-rw-r--r--README.EXT60
-rw-r--r--README.EXT.jp58
-rw-r--r--README.jp32
-rw-r--r--ToDo1
-rw-r--r--array.c547
-rw-r--r--bignum.c342
-rw-r--r--class.c126
-rw-r--r--compar.c42
-rw-r--r--dir.c79
-rw-r--r--dln.c43
-rw-r--r--enum.c106
-rw-r--r--env.h10
-rw-r--r--error.c313
-rw-r--r--eval.c2523
-rw-r--r--ext/curses/curses.c18
-rw-r--r--ext/dbm/dbm.c88
-rw-r--r--ext/etc/etc.c84
-rw-r--r--ext/gtk/gtk.c745
-rw-r--r--ext/kconv/kconv.c8
-rw-r--r--ext/md5/md5init.c6
-rw-r--r--ext/socket/extconf.rb1
-rw-r--r--ext/socket/socket.c624
-rw-r--r--ext/tcltklib/tcltklib.c40
-rw-r--r--ext/tkutil/tkutil.c16
-rw-r--r--file.c546
-rw-r--r--gc.c216
-rw-r--r--hash.c476
-rw-r--r--intern.h416
-rw-r--r--io.c921
-rw-r--r--lib/debug.rb4
-rw-r--r--lib/ftools.rb28
-rw-r--r--lib/tempfile.rb4
-rw-r--r--lib/tk.rb8
-rw-r--r--marshal.c133
-rw-r--r--math.c54
-rw-r--r--node.h183
-rw-r--r--numeric.c650
-rw-r--r--object.c623
-rw-r--r--pack.c144
-rw-r--r--parse.y449
-rw-r--r--process.c172
-rw-r--r--random.c18
-rw-r--r--range.c70
-rw-r--r--re.c398
-rw-r--r--re.h9
-rw-r--r--regex.c1
-rw-r--r--ruby.c192
-rw-r--r--ruby.h275
-rw-r--r--rubyio.h13
-rw-r--r--rubysig.h48
-rw-r--r--sample/freq.rb8
-rw-r--r--sample/occur.rb8
-rw-r--r--sample/ruby-mode.el10
-rw-r--r--signal.c59
-rw-r--r--sprintf.c44
-rw-r--r--st.c14
-rw-r--r--st.h2
-rw-r--r--string.c1248
-rw-r--r--struct.c250
-rw-r--r--time.c192
-rw-r--r--util.c35
-rw-r--r--util.h9
-rw-r--r--variable.c263
-rw-r--r--version.c8
67 files changed, 7309 insertions, 6885 deletions
diff --git a/ChangeLog b/ChangeLog
index 177f1ae..b58806c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Tue Sep 8 01:42:30 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * enum.c (Init_Enumerable): Enumerable#reverse removed.
+
+ * eval.c (call_trace_func): profiler support.
+
+ * eval.c (rb_call0): ditto.
+
+Thu Sep 3 16:34:39 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * bignum.c (bigadd): proper sign combination.
+
+ * eval.c (dvar_asgn_push): modify calling block to create dvar,
+ not insert it next to dummy dvar slot.
+
+ * eval.c (eval): save calling block in (thread local) global
+ variable. no dummy dvar slot is generated by yield.
+
Thu Sep 3 14:08:14 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* version 1.1c4 released.
@@ -41,10 +59,25 @@ Fri Aug 28 12:25:33 1998 Hiroshi Igarashi <igarashi@ueda.info.waseda.ac.jp>
* ruby.c (ruby_require_modules): load modules in appearing order.
+Fri Aug 28 01:57:04 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * regex.c (re_compile_pattern): accepts (?ix-ix) and (?ix-ix:...).
+
Thu Aug 27 12:54:28 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* version 1.1c3 released.
+Wed Aug 26 14:40:56 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (rb_eval): check whether ruby_class is properly set,
+ before accessing it.
+
+ * eval.c (rb_obj_instance_eval): ruby_class should be Qnil for
+ special objects like Fixnums.
+
+ * ext/tkutil/tkutil.c (Init_tkutil): removes calls to
+ rb_yield_0(). used instance_eval() instead in the tk.rb.
+
Wed Aug 26 11:47:00 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* regex.c (re_match): pop non-greedy stack elements on success.
@@ -53,6 +86,10 @@ Wed Aug 26 09:25:35 1998 WATANABE Hirofumi <watanabe@ase.ptg.sony.co.jp>
* ruby.h: add #define environ for cygwin32.
+Tue Aug 25 08:57:41 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * array.c (rb_ary_sort_bang): temporarily freeze sorting array.
+
Mon Aug 24 18:46:44 1998 WATANABE Hirofumi <watanabe@ase.ptg.sony.co.jp>
* dln.c (dln_find_1): path check was too strict.
@@ -61,6 +98,23 @@ Mon Aug 24 15:28:11 1998 WATANABE Hirofumi <watanabe@ase.ptg.sony.co.jp>
* parse.y (f_arglist): opt_nl added after f_args.
+Fri Aug 21 01:06:01 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * ext/socket/socket.c: grand renaming on socket.c.
+
+ * ext/socket/socket.c (inet_aton): supply inet_aton for those
+ systems that do not have it.
+
+ * ext/socket/socket.c (setipaddr): use inet_aton instead of
+ inet_addr.
+
+ * ext/socket/socket.c (tcp_s_gethostbyname): new method: works
+ like Socket.gethostbyname but returning array contains ip-addrs
+ as octet decimal string format like "127.0.0.1".
+
+ * ext/socket/socket.c (mkhostent): return format changed to
+ [host, aliases, type, ipaddr..] as documented.
+
Wed Aug 19 00:31:09 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* io.c (io_ctl): forgot to place TRAP_END at right position.
@@ -89,6 +143,24 @@ Fri Aug 7 17:44:44 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
with snprintf to avoid buffer over-run. For systems which does
dot provide snprintf, missing/snprintf.c added.
+Wed Aug 5 00:47:35 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * re.c (rb_reg_search): recycle match object.
+
+Mon Aug 3 09:17:55 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * string.c (rb_str_gsub_bang): do not allocate temporary string.
+
+ * string.c (rb_str_sub_bang): use inline replace.
+
+Wed Jul 29 00:36:08 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * hash.c (hash_s_new): the default value can be specified.
+
+ * hash.c (hash_default): method to set the default value.
+
+ * hash.c (hash_aref): now returns the default value.
+
Tue Jul 28 13:03:25 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* array.c (ary_s_new): argument to specify initial value is added.
diff --git a/Makefile.in b/Makefile.in
index 010f8de..730b3ad 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -74,9 +74,9 @@ OBJS = array.o \
all: miniruby$(binsuffix) rbconfig.rb
@./miniruby$(binsuffix) -Xext extmk.rb @EXTSTATIC@
-miniruby$(binsuffix): $(OBJS) $(MAINOBJ) dmyext.o
+miniruby$(binsuffix): $(LIBRUBY) $(MAINOBJ) dmyext.o
@rm -f $@
- $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(OBJS) dmyext.o $(LIBS) -o $@
+ $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) dmyext.o $(LIBRUBYARG) $(LIBS) -o $@
ruby$(binsuffix): $(LIBRUBY) $(MAINOBJ) $(EXTOBJS)
@rm -f $@
@@ -213,7 +213,7 @@ random.o: random.c ruby.h config.h defines.h intern.h
range.o: range.c ruby.h config.h defines.h intern.h
re.o: re.c ruby.h config.h defines.h intern.h re.h regex.h
regex.o: regex.c config.h regex.h util.h
-ruby.o: ruby.c ruby.h config.h defines.h intern.h dln.h
+ruby.o: ruby.c ruby.h config.h defines.h intern.h dln.h util.h
signal.o: signal.c ruby.h config.h defines.h intern.h rubysig.h
sprintf.o: sprintf.c ruby.h config.h defines.h intern.h
st.o: st.c config.h st.h
diff --git a/README b/README
index 47012a3..dd93c59 100644
--- a/README
+++ b/README
@@ -15,7 +15,8 @@ Perl). It is simple, straight-forward, and extensible.
+ Iterators and Closures
+ Garbage Collection
+ Dynamic Loading of Object files(on some architecture)
- + Highly Portable(works on many UNIX machines)
+ + Highly Portable(works on many UNIX machines, and on DOS,
+ Windows, Mac, BeOS etc.)
* How to get Ruby
diff --git a/README.EXT b/README.EXT
index fb041bc..a6d6cdb 100644
--- a/README.EXT
+++ b/README.EXT
@@ -159,43 +159,43 @@ Rubyが用意している関数を用いてください.
String funtions
- str_new(char *ptr, int len)
+ rb_str_new(char *ptr, int len)
Creates a new Ruby string.
- str_new2(char *ptr)
+ rb_str_new2(char *ptr)
Creates a new Ruby string from C string. This is equivalent to
- str_new(ptr, strlen(ptr)).
+ rb_str_new(ptr, strlen(ptr)).
- str_cat(VALUE str, char *ptr, int len)
+ rb_str_cat(VALUE str, char *ptr, int len)
Appends len bytes data from ptr to the Ruby string.
Array functions
- ary_new()
+ rb_ary_new()
Creates an array with no element.
- ary_new2(int len)
+ rb_ary_new2(int len)
Creates an array with no element, with allocating internal buffer
for len elements.
- ary_new3(int n, ...)
+ rb_ary_new3(int n, ...)
Creates an n-elements array from arguments.
- ary_new4(int n, VALUE *elts)
+ rb_ary_new4(int n, VALUE *elts)
Creates an n-elements array from C array.
- ary_push(VALUE ary, VALUE val)
- ary_pop(VALUE ary)
- ary_shift(VALUE ary)
- ary_unshift(VALUE ary, VALUE val)
- ary_entry(VALUE ary, int idx)
+ rb_ary_push(VALUE ary, VALUE val)
+ rb_ary_pop(VALUE ary)
+ rb_ary_shift(VALUE ary)
+ rb_ary_unshift(VALUE ary, VALUE val)
+ rb_ary_entry(VALUE ary, int idx)
Array operations. The first argument to each functions must be an
array. They may dump core if other types given.
@@ -376,10 +376,10 @@ C言語とRubyの間で情報を共有する方法について解説します.
Following Ruby constants can be referred from C.
- TRUE
- FALSE
+ Qtrue
+ Qfalse
-Boolean values. FALSE is false in the C also (i.e. 0).
+Boolean values. Qfalse is false in the C also (i.e. 0).
Qnil
@@ -526,9 +526,9 @@ Rubyは拡張モジュールをロードする時に「Init_モジュール名」と
Init_dbm()
{
/* DBMクラスを定義する */
- cDBM = rb_define_class("DBM", cObject);
+ cDBM = rb_define_class("DBM", rb_cObject);
/* DBMはEnumerateモジュールをインクルードする */
- rb_include_module(cDBM, mEnumerable);
+ rb_include_module(cDBM, rb_mEnumerable);
/* DBMクラスのクラスメソッドopen(): 引数はCの配列で受ける */
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
@@ -704,9 +704,9 @@ Rubyのディレクトリでmakeを実行するとMakefileを生成からmake,
してくれます.extconf.rbを書き換えるなどしてMakefileの再生成
が必要な時はまたRubyディレクトリでmakeしてください.
-(9) debug
+(9) rb_debug
-You may need to debug the module. The modules can be linked
+You may need to rb_debug the module. The modules can be linked
statically by adding directory name in the ext/Setup file,
so that you can inspect the module by the debugger.
@@ -792,13 +792,13 @@ Rubyオブジェクトを表現する型.必要に応じてキャストして用いる.
const: nil object
- TRUE
+ Qtrue
-const: TRUE object(default true value)
+const: Qtrue object(default true value)
- FALSE
+ Qfalse
-const: FALSE object
+const: Qfalse object
** Cデータのカプセル化
@@ -988,21 +988,21 @@ valを値としてイテレータブロックを呼び出す.
** 例外・エラー
- void Warning(char *fmt, ...)
+ void rb_warning(char *fmt, ...)
-verbose時に標準エラー出力に警告情報を表示する.引数はprintf()と同じ.
+rb_verbose時に標準エラー出力に警告情報を表示する.引数はprintf()と同じ.
- void Fail(char *fmt, ...)
+ void rb_raise(rb_eRuntimeError, char *fmt, ...)
例外を発生させる.引数はprintf()と同じ.
- void Fatal(char *fmt, ...)
+ void rb_fatal(char *fmt, ...)
致命的例外を発生させる.通常の例外処理は行なわれず, インター
プリタが終了する(ただしensureで指定されたコードは終了前に実
行される).
- void Bug(char *fmt, ...)
+ void rb_bug(char *fmt, ...)
インタープリタなどプログラムのバグでしか発生するはずのない状
況の時呼ぶ.インタープリタはコアダンプし直ちに終了する.例外
@@ -1034,7 +1034,7 @@ extconf.rbの中では利用可能なコンパイル条件チェックの関数は以
have_library(lib, func)
関数funcを定義しているライブラリlibの存在をチェックする.ラ
-イブラリが存在する時,TRUEを返す.
+イブラリが存在する時,Qtrueを返す.
have_func(func)
diff --git a/README.EXT.jp b/README.EXT.jp
index 09983b5..9dbd845 100644
--- a/README.EXT.jp
+++ b/README.EXT.jp
@@ -171,43 +171,43 @@ Rubyが用意している関数を用いてください.
文字列に対する関数
- str_new(char *ptr, int len)
+ rb_str_new(char *ptr, int len)
新しいRubyの文字列を生成する.
- str_new2(char *ptr)
+ rb_str_new2(char *ptr)
Cの文字列からRubyの文字列を生成する.この関数の機能は
- str_new(ptr, strlen(ptr))と同等である.
+ rb_str_new(ptr, strlen(ptr))と同等である.
- str_cat(VALUE str, char *ptr, int len)
+ rb_str_cat(VALUE str, char *ptr, int len)
Rubyの文字列strにlenバイトの文字列ptrを追加する.
配列に対する関数
- ary_new()
+ rb_ary_new()
要素が0の配列を生成する.
- ary_new2(int len)
+ rb_ary_new2(int len)
要素が0の配列を生成する.len要素分の領域をあらかじめ割り
当てておく.
- ary_new3(int n, ...)
+ rb_ary_new3(int n, ...)
引数で指定したn要素を含む配列を生成する.
- ary_new4(int n, VALUE *elts)
+ rb_ary_new4(int n, VALUE *elts)
配列で与えたn要素の配列を生成する.
- ary_push(VALUE ary, VALUE val)
- ary_pop(VALUE ary)
- ary_shift(VALUE ary)
- ary_unshift(VALUE ary, VALUE val)
- ary_entry(VALUE ary, int idx)
+ rb_ary_push(VALUE ary, VALUE val)
+ rb_ary_pop(VALUE ary)
+ rb_ary_shift(VALUE ary)
+ rb_ary_unshift(VALUE ary, VALUE val)
+ rb_ary_entry(VALUE ary, int idx)
Arrayの同名のメソッドと同じ働きをする関数.第1引数は必ず
配列でなければならない.
@@ -403,10 +403,10 @@ C言語とRubyの間で情報を共有する方法について解説します.
以下のRubyの定数はCのレベルから参照できる.
- TRUE
- FALSE
+ Qtrue
+ Qfalse
-真偽値.FALSEはC言語でも偽とみなされる(つまり0).
+真偽値.QfalseはC言語でも偽とみなされる(つまり0).
Qnil
@@ -557,9 +557,9 @@ Rubyは拡張モジュールをロードする時に「Init_モジュール名」と
Init_dbm()
{
/* DBMクラスを定義する */
- cDBM = rb_define_class("DBM", cObject);
+ cDBM = rb_define_class("DBM", rb_cObject);
/* DBMはEnumerateモジュールをインクルードする */
- rb_include_module(cDBM, mEnumerable);
+ rb_include_module(cDBM, rb_mEnumerable);
/* DBMクラスのクラスメソッドopen(): 引数はCの配列で受ける */
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
@@ -855,11 +855,11 @@ Rubyオブジェクトを表現する型.必要に応じてキャストして用いる.
定数: nilオブジェクト
- TRUE
+ Qtrue
定数: trueオブジェクト(真のデフォルト値)
- FALSE
+ Qfalse
定数: falseオブジェクト
@@ -897,9 +897,9 @@ dataからtype型のポインタを取り出し変数svalに代入するマクロ.
NUM2INT(value)
INT2NUM(i)
NUM2DBL(value)
- float_new(f)
+ rb_float_new(f)
STR2CSTR(value)
- str_new2(s)
+ rb_str_new2(s)
** クラス/モジュール定義
@@ -1071,25 +1071,25 @@ valを値としてイテレータブロックを呼び出す.
** 例外・エラー
- void Warning(char *fmt, ...)
+ void rb_warning(char *fmt, ...)
-verbose時に標準エラー出力に警告情報を表示する.引数はprintf()と同じ.
+rb_verbose時に標準エラー出力に警告情報を表示する.引数はprintf()と同じ.
- void Fail(char *fmt, ...)
+ void rb_raise(rb_eRuntimeError, char *fmt, ...)
RuntimeError例外を発生させる.引数はprintf()と同じ.
- void Raise(VALUE exception, char *fmt, ...)
+ void rb_raise(VALUE exception, char *fmt, ...)
exceptionで指定した例外を発生させる.fmt以下の引数はprintf()と同じ.
- void Fatal(char *fmt, ...)
+ void rb_fatal(char *fmt, ...)
致命的例外を発生させる.通常の例外処理は行なわれず, インター
プリタが終了する(ただしensureで指定されたコードは終了前に実
行される).
- void Bug(char *fmt, ...)
+ void rb_bug(char *fmt, ...)
インタープリタなどプログラムのバグでしか発生するはずのない状
況の時呼ぶ.インタープリタはコアダンプし直ちに終了する.例外
@@ -1121,7 +1121,7 @@ extconf.rbの中では利用可能なコンパイル条件チェックの関数は以
have_library(lib, func)
関数funcを定義しているライブラリlibの存在をチェックする.ラ
-イブラリが存在する時,TRUEを返す.
+イブラリが存在する時,Qtrueを返す.
have_func(func)
diff --git a/README.jp b/README.jp
index 0ef0065..1b63f71 100644
--- a/README.jp
+++ b/README.jp
@@ -20,7 +20,8 @@ Rubyはテキスト処理関係の能力などに優れ,Perlと同じくらい強力
+ イテレータとクロージャ
+ ガーベージコレクタ
+ ダイナミックローディング (アーキテクチャによる)
- + 移植性が高い.多くのUNIX上で動く
+ + 移植性が高い.多くのUNIX上で動くだけでなく,DOSやWindows,
+ Mac,BeOSなどの上でも動く
* 入手法
@@ -41,14 +42,14 @@ Rubyはテキスト処理関係の能力などに優れ,Perlと同じくらい強力
です.
-* メイリングリスト
+* メーリングリスト
- Rubyに関わる話題のためのメイリングリストを開設しました.ア
+ Rubyに関わる話題のためのメーリングリストを開設しました.ア
ドレスは
ruby-list@netlab.co.jp
- です.このアドレスにメイルを送れば,自動的に登録されます.
+ です.このアドレスにメールを送れば,自動的に登録されます.
* コンパイル・インストール
@@ -122,34 +123,37 @@ Licence)または以下に示す条件でRubyを再配布できます.GPLにつ
由に変更できます.
(a) ネットニューズにポストしたり,作者に変更を送付する
- などの方法で,変更を公開する
+ などの方法で,変更を公開する.
- (b) 変更したRubyを自分の所属する組織内部だけで使う
+ (b) 変更したRubyを自分の所属する組織内部だけで使う.
(c) 変更点を明示したうえ,ソフトウェアの名前を変更する.
- そのソフトウェアを配布する時にはもとのRubyも同時に
- 配布する
+ そのソフトウェアを配布する時には変更前のRubyも同時
+ に配布する.または変更前のRubyのソースの入手法を明
+ 示する.
- (d) その他の変更条件を作者と合意する
+ (d) その他の変更条件を作者と合意する.
3. 以下の条件のいずれかを満たす時にRubyをオブジェクトコー
ドや実行形式でも配布できます.
- (a) バイナリを受け取った人がソースを入手できるようにソー
- スの入手法を明示する
+ (a) バイナリを受け取った人がソースを入手できるように,
+ ソースの入手法を明示する.
- (b) 機械可読なソースコードを添付する
+ (b) 機械可読なソースコードを添付する.
(c) 変更を行ったバイナリは名前を変更したうえ,ソースの
- 入手法を明示する
+ 入手法を明示する.
- (d) その他の配布条件を作者と合意する
+ (d) その他の配布条件を作者と合意する.
4. 他のプログラムへの引用はいかなる目的であれ自由です.た
だし,Rubyに含まれる他の作者によるコードは,それぞれの
作者の意向による制限が加えられます.具体的にはgc.c(一部),
util.c(一部),st.[ch],regex.[ch], fnmatch.[ch], glob.c
および./missingディレクトリ下のファイル群が該当します.
+ それぞれの配布条件などに付いては各ファイルを参照してく
+ ださい.
5. Rubyへの入力となるスクリプトおよび,Rubyからの出力の権
利はRubyの作者ではなく,それぞれの入出力を生成した人に
diff --git a/ToDo b/ToDo
index 462bc47..9710c42 100644
--- a/ToDo
+++ b/ToDo
@@ -1,4 +1,3 @@
-* remove Enumerable#reverse at 1.2
* non-blocking open/write for thread
* package or access control for global variables
* format
diff --git a/array.c b/array.c
index 6150d86..ce4553b 100644
--- a/array.c
+++ b/array.c
@@ -12,13 +12,12 @@
#include "ruby.h"
-
-VALUE cArray;
+VALUE rb_cArray;
#define ARY_DEFAULT_SIZE 16
void
-memclear(mem, size)
+rb_mem_clear(mem, size)
register VALUE *mem;
register int size;
{
@@ -39,19 +38,20 @@ memfill(mem, size, val)
}
#define ARY_FREEZE FL_USER1
+#define ARY_TMPLOCK FL_USER2
static void
-ary_modify(ary)
+rb_ary_modify(ary)
VALUE ary;
{
rb_secure(5);
- if (FL_TEST(ary, ARY_FREEZE)) {
- TypeError("can't modify frozen array");
+ if (FL_TEST(ary, ARY_FREEZE|ARY_TMPLOCK)) {
+ rb_raise(rb_eTypeError, "can't modify frozen array");
}
}
VALUE
-ary_freeze(ary)
+rb_ary_freeze(ary)
VALUE ary;
{
FL_SET(ary, ARY_FREEZE);
@@ -59,40 +59,39 @@ ary_freeze(ary)
}
static VALUE
-ary_frozen_p(ary)
+rb_ary_frozen_p(ary)
VALUE ary;
{
- if (FL_TEST(ary, ARY_FREEZE))
- return TRUE;
- return FALSE;
+ if (FL_TEST(ary, ARY_FREEZE|ARY_TMPLOCK))
+ return Qtrue;
+ return Qfalse;
}
VALUE
-ary_new2(len)
+rb_ary_new2(len)
int len;
{
NEWOBJ(ary, struct RArray);
- OBJSETUP(ary, cArray, T_ARRAY);
+ OBJSETUP(ary, rb_cArray, T_ARRAY);
if (len < 0) {
- ArgError("negative array size (or size too big)");
+ rb_raise(rb_eArgError, "negative array size (or size too big)");
}
if (len > 0 && len*sizeof(VALUE) <= 0) {
- ArgError("array size too big");
+ rb_raise(rb_eArgError, "array size too big");
}
ary->len = 0;
ary->capa = len;
ary->ptr = 0;
ary->ptr = ALLOC_N(VALUE, len);
- memclear(ary->ptr, len);
return (VALUE)ary;
}
VALUE
-ary_new()
+rb_ary_new()
{
- return ary_new2(ARY_DEFAULT_SIZE);
+ return rb_ary_new2(ARY_DEFAULT_SIZE);
}
#ifdef HAVE_STDARG_PROTOTYPES
@@ -105,9 +104,9 @@ ary_new()
VALUE
#ifdef HAVE_STDARG_PROTOTYPES
-ary_new3(int n, ...)
+rb_ary_new3(int n, ...)
#else
-ary_new3(n, va_alist)
+rb_ary_new3(n, va_alist)
int n;
va_dcl
#endif
@@ -117,9 +116,9 @@ ary_new3(n, va_alist)
int i;
if (n < 0) {
- IndexError("Negative number of items(%d)", n);
+ rb_raise(rb_eIndexError, "Negative number of items(%d)", n);
}
- ary = ary_new2(n<ARY_DEFAULT_SIZE?ARY_DEFAULT_SIZE:n);
+ ary = rb_ary_new2(n<ARY_DEFAULT_SIZE?ARY_DEFAULT_SIZE:n);
va_init_list(ar, n);
for (i=0; i<n; i++) {
@@ -132,13 +131,13 @@ ary_new3(n, va_alist)
}
VALUE
-ary_new4(n, elts)
+rb_ary_new4(n, elts)
int n;
VALUE *elts;
{
VALUE ary;
- ary = ary_new2(n);
+ ary = rb_ary_new2(n);
if (elts) {
MEMCPY(RARRAY(ary)->ptr, elts, VALUE, n);
}
@@ -148,12 +147,12 @@ ary_new4(n, elts)
}
VALUE
-assoc_new(car, cdr)
+rb_assoc_new(car, cdr)
VALUE car, cdr;
{
VALUE ary;
- ary = ary_new2(2);
+ ary = rb_ary_new2(2);
RARRAY(ary)->ptr[0] = car;
RARRAY(ary)->ptr[1] = cdr;
RARRAY(ary)->len = 2;
@@ -162,7 +161,7 @@ assoc_new(car, cdr)
}
static VALUE
-ary_s_new(argc, argv, klass)
+rb_ary_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -181,10 +180,10 @@ ary_s_new(argc, argv, klass)
int capa = NUM2INT(size);
if (capa < 0) {
- ArgError("negative array size");
+ rb_raise(rb_eArgError, "negative array size");
}
if (capa > 0 && capa*sizeof(VALUE) <= 0) {
- ArgError("array size too big");
+ rb_raise(rb_eArgError, "array size too big");
}
ary->capa = capa;
len = capa;
@@ -192,13 +191,13 @@ ary_s_new(argc, argv, klass)
ary->ptr = ALLOC_N(VALUE, ary->capa);
memfill(ary->ptr, len, val);
ary->len = len;
- obj_call_init((VALUE)ary);
+ rb_obj_call_init((VALUE)ary);
return (VALUE)ary;
}
static VALUE
-ary_s_create(argc, argv, klass)
+rb_ary_s_create(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -220,14 +219,14 @@ ary_s_create(argc, argv, klass)
}
void
-ary_store(ary, idx, val)
+rb_ary_store(ary, idx, val)
VALUE ary;
int idx;
VALUE val;
{
- ary_modify(ary);
+ rb_ary_modify(ary);
if (idx < 0) {
- IndexError("negative index for array");
+ rb_raise(rb_eIndexError, "negative index for array");
}
if (idx >= RARRAY(ary)->capa) {
@@ -235,7 +234,8 @@ ary_store(ary, idx, val)
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
if (idx > RARRAY(ary)->len) {
- memclear(RARRAY(ary)->ptr+RARRAY(ary)->len, idx-RARRAY(ary)->len+1);
+ rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len,
+ idx-RARRAY(ary)->len+1);
}
if (idx >= RARRAY(ary)->len) {
@@ -245,28 +245,28 @@ ary_store(ary, idx, val)
}
VALUE
-ary_push(ary, item)
+rb_ary_push(ary, item)
VALUE ary;
VALUE item;
{
- ary_store(ary, RARRAY(ary)->len, item);
+ rb_ary_store(ary, RARRAY(ary)->len, item);
return ary;
}
static VALUE
-ary_push_method(argc, argv, ary)
+rb_ary_push_method(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
{
while (argc--) {
- ary_store(ary, RARRAY(ary)->len, *argv++);
+ rb_ary_store(ary, RARRAY(ary)->len, *argv++);
}
return ary;
}
VALUE
-ary_pop(ary)
+rb_ary_pop(ary)
VALUE ary;
{
if (RARRAY(ary)->len == 0) return Qnil;
@@ -278,7 +278,7 @@ ary_pop(ary)
}
VALUE
-ary_shift(ary)
+rb_ary_shift(ary)
VALUE ary;
{
VALUE top;
@@ -299,10 +299,10 @@ ary_shift(ary)
}
VALUE
-ary_unshift(ary, item)
+rb_ary_unshift(ary, item)
VALUE ary, item;
{
- ary_modify(ary);
+ rb_ary_modify(ary);
if (RARRAY(ary)->len >= RARRAY(ary)->capa) {
RARRAY(ary)->capa+=ARY_DEFAULT_SIZE;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
@@ -316,7 +316,7 @@ ary_unshift(ary, item)
}
VALUE
-ary_entry(ary, offset)
+rb_ary_entry(ary, offset)
VALUE ary;
int offset;
{
@@ -333,7 +333,7 @@ ary_entry(ary, offset)
}
static VALUE
-ary_subseq(ary, beg, len)
+rb_ary_subseq(ary, beg, len)
VALUE ary;
int beg, len;
{
@@ -344,10 +344,10 @@ ary_subseq(ary, beg, len)
if (beg < 0) beg = 0;
}
if (len < 0) {
- IndexError("negative length %d", RARRAY(ary)->len);
+ rb_raise(rb_eIndexError, "negative length %d", RARRAY(ary)->len);
}
if (len == 0) {
- return ary_new2(0);
+ return rb_ary_new2(0);
}
if (beg + len > RARRAY(ary)->len) {
len = RARRAY(ary)->len - beg;
@@ -356,7 +356,7 @@ ary_subseq(ary, beg, len)
len = 0;
}
- ary2 = ary_new2(len);
+ ary2 = rb_ary_new2(len);
MEMCPY(RARRAY(ary2)->ptr, RARRAY(ary)->ptr+beg, VALUE, len);
RARRAY(ary2)->len = len;
@@ -371,10 +371,10 @@ beg_len(range, begp, lenp, len)
{
int beg, end;
- if (!range_beg_end(range, &beg, &end)) return FALSE;
+ if (!rb_range_beg_end(range, &beg, &end)) return Qfalse;
if ((beg > 0 && end > 0 || beg < 0 && end < 0) && beg > end) {
- IndexError("end smaller than beg [%d..%d]", beg, end);
+ rb_raise(rb_eIndexError, "end smaller than beg [%d..%d]", beg, end);
}
if (beg < 0) {
@@ -397,11 +397,11 @@ beg_len(range, begp, lenp, len)
*lenp = end - beg +1;
}
}
- return TRUE;
+ return Qtrue;
}
VALUE
-ary_aref(argc, argv, ary)
+rb_ary_aref(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
@@ -413,27 +413,27 @@ ary_aref(argc, argv, ary)
beg = NUM2INT(arg1);
len = NUM2INT(arg2);
if (len <= 0) {
- return ary_new();
+ return rb_ary_new();
}
- return ary_subseq(ary, beg, len);
+ return rb_ary_subseq(ary, beg, len);
}
/* special case - speeding up */
if (FIXNUM_P(arg1)) {
- return ary_entry(ary, FIX2INT(arg1));
+ return rb_ary_entry(ary, FIX2INT(arg1));
}
else if (TYPE(arg1) == T_BIGNUM) {
- IndexError("index too big");
+ rb_raise(rb_eIndexError, "index too big");
}
else if (beg_len(arg1, &beg, &len, RARRAY(ary)->len)) {
/* check if idx is Range */
- return ary_subseq(ary, beg, len);
+ return rb_ary_subseq(ary, beg, len);
}
- return ary_entry(ary, NUM2INT(arg1));
+ return rb_ary_entry(ary, NUM2INT(arg1));
}
static VALUE
-ary_index(ary, val)
+rb_ary_index(ary, val)
VALUE ary;
VALUE val;
{
@@ -447,7 +447,7 @@ ary_index(ary, val)
}
static VALUE
-ary_rindex(ary, val)
+rb_ary_rindex(ary, val)
VALUE ary;
VALUE val;
{
@@ -461,7 +461,7 @@ ary_rindex(ary, val)
}
static VALUE
-ary_indexes(argc, argv, ary)
+rb_ary_indexes(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
@@ -469,20 +469,20 @@ ary_indexes(argc, argv, ary)
VALUE new_ary;
int i;
- new_ary = ary_new2(argc);
+ new_ary = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
- ary_store(new_ary, i, ary_entry(ary, NUM2INT(argv[i])));
+ rb_ary_store(new_ary, i, rb_ary_entry(ary, NUM2INT(argv[i])));
}
return new_ary;
}
static void
-ary_replace(ary, beg, len, rpl)
+rb_ary_replace(ary, beg, len, rpl)
VALUE ary, rpl;
int beg, len;
{
- ary_modify(ary);
+ rb_ary_modify(ary);
if (TYPE(rpl) != T_ARRAY) {
rpl = rb_Array(rpl);
}
@@ -496,7 +496,7 @@ ary_replace(ary, beg, len, rpl)
RARRAY(ary)->capa=len;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
- memclear(RARRAY(ary)->ptr+RARRAY(ary)->len, beg-RARRAY(ary)->len);
+ rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len, beg-RARRAY(ary)->len);
MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, RARRAY(rpl)->len);
RARRAY(ary)->len = len;
}
@@ -507,7 +507,7 @@ ary_replace(ary, beg, len, rpl)
len = RARRAY(ary)->len - beg;
}
if (len < 0) {
- IndexError("negative length %d", RARRAY(ary)->len);
+ rb_raise(rb_eIndexError, "negative length %d", RARRAY(ary)->len);
}
alen = RARRAY(ary)->len + RARRAY(rpl)->len - len;
@@ -526,7 +526,7 @@ ary_replace(ary, beg, len, rpl)
}
static VALUE
-ary_aset(argc, argv, ary)
+rb_ary_aset(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
@@ -538,7 +538,7 @@ ary_aset(argc, argv, ary)
if (rb_scan_args(argc, argv, "21", &arg1, &arg2, &arg3) == 3) {
beg = NUM2INT(arg1);
len = NUM2INT(arg2);
- ary_replace(ary, beg, len, arg3);
+ rb_ary_replace(ary, beg, len, arg3);
return arg3;
}
else if (FIXNUM_P(arg1)) {
@@ -547,11 +547,11 @@ ary_aset(argc, argv, ary)
}
else if (beg_len(arg1, &beg, &len, RARRAY(ary)->len)) {
/* check if idx is Range */
- ary_replace(ary, beg, len, arg2);
+ rb_ary_replace(ary, beg, len, arg2);
return arg2;
}
if (TYPE(arg1) == T_BIGNUM) {
- IndexError("index too big");
+ rb_raise(rb_eIndexError, "index too big");
}
offset = NUM2INT(arg1);
@@ -559,12 +559,12 @@ ary_aset(argc, argv, ary)
if (offset < 0) {
offset = RARRAY(ary)->len + offset;
}
- ary_store(ary, offset, arg2);
+ rb_ary_store(ary, offset, arg2);
return arg2;
}
VALUE
-ary_each(ary)
+rb_ary_each(ary)
VALUE ary;
{
int i;
@@ -576,7 +576,7 @@ ary_each(ary)
}
static VALUE
-ary_each_index(ary)
+rb_ary_each_index(ary)
VALUE ary;
{
int i;
@@ -588,7 +588,7 @@ ary_each_index(ary)
}
static VALUE
-ary_reverse_each(ary)
+rb_ary_reverse_each(ary)
VALUE ary;
{
int len = RARRAY(ary)->len;
@@ -600,26 +600,26 @@ ary_reverse_each(ary)
}
static VALUE
-ary_length(ary)
+rb_ary_length(ary)
VALUE ary;
{
return INT2FIX(RARRAY(ary)->len);
}
static VALUE
-ary_empty_p(ary)
+rb_ary_empty_p(ary)
VALUE ary;
{
if (RARRAY(ary)->len == 0)
- return TRUE;
- return FALSE;
+ return Qtrue;
+ return Qfalse;
}
static VALUE
-ary_clone(ary)
+rb_ary_clone(ary)
VALUE ary;
{
- VALUE ary2 = ary_new2(RARRAY(ary)->len);
+ VALUE ary2 = rb_ary_new2(RARRAY(ary)->len);
CLONESETUP(ary2, ary);
MEMCPY(RARRAY(ary2)->ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
@@ -628,10 +628,10 @@ ary_clone(ary)
}
static VALUE
-ary_dup(ary)
+rb_ary_dup(ary)
VALUE ary;
{
- return ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr);
+ return rb_ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr);
}
static VALUE
@@ -641,26 +641,26 @@ to_ary(ary)
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
-extern VALUE OFS;
+extern VALUE rb_output_fs;
VALUE
-ary_join(ary, sep)
+rb_ary_join(ary, sep)
VALUE ary;
VALUE sep;
{
int i;
VALUE result, tmp;
- if (RARRAY(ary)->len == 0) return str_new(0, 0);
+ if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
switch (TYPE(RARRAY(ary)->ptr[0])) {
case T_STRING:
- result = str_dup(RARRAY(ary)->ptr[0]);
+ result = rb_str_dup(RARRAY(ary)->ptr[0]);
break;
case T_ARRAY:
- result = ary_join(RARRAY(ary)->ptr[0], sep);
+ result = rb_ary_join(RARRAY(ary)->ptr[0], sep);
break;
default:
- result = obj_as_string(RARRAY(ary)->ptr[0]);
+ result = rb_obj_as_string(RARRAY(ary)->ptr[0]);
break;
}
@@ -670,21 +670,21 @@ ary_join(ary, sep)
case T_STRING:
break;
case T_ARRAY:
- tmp = ary_join(tmp, sep);
+ tmp = rb_ary_join(tmp, sep);
break;
default:
- tmp = obj_as_string(tmp);
+ tmp = rb_obj_as_string(tmp);
}
- if (!NIL_P(sep)) str_concat(result, sep);
- str_cat(result, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
- if (str_tainted(tmp)) str_taint(result);
+ if (!NIL_P(sep)) rb_str_concat(result, sep);
+ rb_str_cat(result, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
+ if (rb_str_tainted(tmp)) rb_str_taint(result);
}
return result;
}
static VALUE
-ary_join_method(argc, argv, ary)
+rb_ary_join_method(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
@@ -692,51 +692,51 @@ ary_join_method(argc, argv, ary)
VALUE sep;
rb_scan_args(argc, argv, "01", &sep);
- if (NIL_P(sep)) sep = OFS;
+ if (NIL_P(sep)) sep = rb_output_fs;
- return ary_join(ary, sep);
+ return rb_ary_join(ary, sep);
}
VALUE
-ary_to_s(ary)
+rb_ary_to_s(ary)
VALUE ary;
{
- VALUE str = ary_join(ary, OFS);
- if (NIL_P(str)) return str_new(0, 0);
+ VALUE str = rb_ary_join(ary, rb_output_fs);
+ if (NIL_P(str)) return rb_str_new(0, 0);
return str;
}
static VALUE
-ary_inspect(ary)
+rb_ary_inspect(ary)
VALUE ary;
{
int i, len;
VALUE s, str;
- if (RARRAY(ary)->len == 0) return str_new2("[]");
- str = str_new2("[");
+ if (RARRAY(ary)->len == 0) return rb_str_new2("[]");
+ str = rb_str_new2("[");
len = 1;
for (i=0; i<RARRAY(ary)->len; i++) {
s = rb_inspect(RARRAY(ary)->ptr[i]);
- if (i > 0) str_cat(str, ", ", 2);
- str_cat(str, RSTRING(s)->ptr, RSTRING(s)->len);
+ if (i > 0) rb_str_cat(str, ", ", 2);
+ rb_str_cat(str, RSTRING(s)->ptr, RSTRING(s)->len);
len += RSTRING(s)->len + 2;
}
- str_cat(str, "]", 1);
+ rb_str_cat(str, "]", 1);
return str;
}
static VALUE
-ary_to_a(ary)
+rb_ary_to_a(ary)
VALUE ary;
{
return ary;
}
VALUE
-ary_reverse(ary)
+rb_ary_reverse(ary)
VALUE ary;
{
VALUE *p1, *p2;
@@ -758,10 +758,10 @@ ary_reverse(ary)
}
static VALUE
-ary_reverse_method(ary)
+rb_ary_reverse_method(ary)
VALUE ary;
{
- return ary_reverse(ary_dup(ary));
+ return rb_ary_reverse(rb_ary_dup(ary));
}
static ID cmp;
@@ -770,7 +770,7 @@ static int
sort_1(a, b)
VALUE *a, *b;
{
- VALUE retval = rb_yield(assoc_new(*a, *b));
+ VALUE retval = rb_yield(rb_assoc_new(*a, *b));
return NUM2INT(retval);
}
@@ -783,42 +783,59 @@ sort_2(a, b)
if (FIXNUM_P(*a)) {
if (FIXNUM_P(*b)) return *a - *b;
}
- else if (TYPE(*a) == T_STRING) {
- if (TYPE(*b) == T_STRING) return str_cmp(*a, *b);
+ else if (TYPE(*a) == T_STRING && TYPE(*b) == T_STRING) {
+ return rb_str_cmp(*a, *b);
}
retval = rb_funcall(*a, cmp, 1, *b);
return NUM2INT(retval);
}
+static VALUE
+sort_internal(ary)
+ VALUE ary;
+{
+ qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
+ rb_iterator_p()?sort_1:sort_2);
+ return ary;
+}
+
+static VALUE
+sort_unlock(ary)
+ VALUE ary;
+{
+ FL_UNSET(ary, ARY_TMPLOCK);
+ return ary;
+}
+
VALUE
-ary_sort_bang(ary)
+rb_ary_sort_bang(ary)
VALUE ary;
{
if (RARRAY(ary)->len == 0) return ary;
- ary_modify(ary);
- qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
- iterator_p()?sort_1:sort_2);
+ rb_ary_modify(ary);
+ FL_SET(ary, ARY_TMPLOCK); /* prohibit modification during sort */
+ rb_ensure(sort_internal, ary, sort_unlock, ary);
return ary;
}
VALUE
-ary_sort(ary)
+rb_ary_sort(ary)
VALUE ary;
{
if (RARRAY(ary)->len == 0) return ary;
- return ary_sort_bang(ary_dup(ary));
+ return rb_ary_sort_bang(rb_ary_dup(ary));
}
VALUE
-ary_delete(ary, item)
+rb_ary_delete(ary, item)
VALUE ary;
VALUE item;
{
int i1, i2;
- ary_modify(ary);
+ rb_ary_modify(ary);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
if (rb_equal(RARRAY(ary)->ptr[i1], item)) continue;
if (i1 != i2) {
@@ -827,7 +844,7 @@ ary_delete(ary, item)
i2++;
}
if (RARRAY(ary)->len == i2) {
- if (iterator_p()) {
+ if (rb_iterator_p()) {
return rb_yield(item);
}
return Qnil;
@@ -840,14 +857,14 @@ ary_delete(ary, item)
}
VALUE
-ary_delete_at(ary, at)
+rb_ary_delete_at(ary, at)
VALUE ary;
VALUE at;
{
int i1, i2, pos;
VALUE del = Qnil;
- ary_modify(ary);
+ rb_ary_modify(ary);
pos = NUM2INT(at);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
if (i1 == pos) {
@@ -865,12 +882,12 @@ ary_delete_at(ary, at)
}
static VALUE
-ary_delete_if(ary)
+rb_ary_delete_if(ary)
VALUE ary;
{
int i1, i2;
- ary_modify(ary);
+ rb_ary_modify(ary);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
if (rb_yield(RARRAY(ary)->ptr[i1])) continue;
if (i1 != i2) {
@@ -884,12 +901,12 @@ ary_delete_if(ary)
}
static VALUE
-ary_filter(ary)
+rb_ary_filter(ary)
VALUE ary;
{
int i;
- ary_modify(ary);
+ rb_ary_modify(ary);
for (i = 0; i < RARRAY(ary)->len; i++) {
RARRAY(ary)->ptr[i] = rb_yield(RARRAY(ary)->ptr[i]);
}
@@ -897,16 +914,16 @@ ary_filter(ary)
}
static VALUE
-ary_replace_method(ary, ary2)
+rb_ary_replace_method(ary, ary2)
VALUE ary, ary2;
{
ary2 = to_ary(ary2);
- ary_replace(ary, 0, RARRAY(ary2)->len, ary2);
+ rb_ary_replace(ary, 0, RARRAY(ary2)->len, ary2);
return ary;
}
static VALUE
-ary_clear(ary)
+rb_ary_clear(ary)
VALUE ary;
{
RARRAY(ary)->len = 0;
@@ -918,7 +935,7 @@ ary_clear(ary)
}
static VALUE
-ary_fill(argc, argv, ary)
+rb_ary_fill(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
@@ -939,6 +956,7 @@ ary_fill(argc, argv, ary)
}
len = NIL_P(arg2)?RARRAY(ary)->len - beg:NUM2INT(arg2);
}
+ rb_ary_modify(ary);
end = beg + len;
if (end > RARRAY(ary)->len) {
if (end >= RARRAY(ary)->capa) {
@@ -946,7 +964,7 @@ ary_fill(argc, argv, ary)
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
}
if (beg > RARRAY(ary)->len) {
- memclear(RARRAY(ary)->ptr+RARRAY(ary)->len,end-RARRAY(ary)->len);
+ rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len,end-RARRAY(ary)->len);
}
RARRAY(ary)->len = end;
}
@@ -959,16 +977,16 @@ ary_fill(argc, argv, ary)
}
VALUE
-ary_plus(x, y)
+rb_ary_plus(x, y)
VALUE x, y;
{
VALUE z;
if (TYPE(y) != T_ARRAY) {
- return ary_plus(x, rb_Array(y));
+ return rb_ary_plus(x, rb_Array(y));
}
- z = ary_new2(RARRAY(x)->len + RARRAY(y)->len);
+ z = rb_ary_new2(RARRAY(x)->len + RARRAY(y)->len);
MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len);
MEMCPY(RARRAY(z)->ptr+RARRAY(x)->len, RARRAY(y)->ptr, VALUE, RARRAY(y)->len);
RARRAY(z)->len = RARRAY(x)->len + RARRAY(y)->len;
@@ -976,26 +994,26 @@ ary_plus(x, y)
}
VALUE
-ary_concat(x, y)
+rb_ary_concat(x, y)
VALUE x, y;
{
VALUE *p, *pend;
if (TYPE(y) != T_ARRAY) {
- return ary_concat(x, rb_Array(y));
+ return rb_ary_concat(x, rb_Array(y));
}
p = RARRAY(y)->ptr;
pend = p + RARRAY(y)->len;
while (p < pend) {
- ary_store(x, RARRAY(x)->len, *p);
+ rb_ary_store(x, RARRAY(x)->len, *p);
p++;
}
return x;
}
static VALUE
-ary_times(ary, times)
+rb_ary_times(ary, times)
VALUE ary;
VALUE times;
{
@@ -1003,16 +1021,16 @@ ary_times(ary, times)
int i, len;
if (TYPE(times) == T_STRING) {
- return ary_join(ary, times);
+ return rb_ary_join(ary, times);
}
len = NUM2INT(times);
if (len < 0) {
- ArgError("negative argument");
+ rb_raise(rb_eArgError, "negative argument");
}
len *= RARRAY(ary)->len;
- ary2 = ary_new2(len);
+ ary2 = rb_ary_new2(len);
RARRAY(ary2)->len = len;
for (i=0; i<len; i+=RARRAY(ary)->len) {
@@ -1023,7 +1041,7 @@ ary_times(ary, times)
}
VALUE
-ary_assoc(ary, key)
+rb_ary_assoc(ary, key)
VALUE ary;
VALUE key;
{
@@ -1041,7 +1059,7 @@ ary_assoc(ary, key)
}
VALUE
-ary_rassoc(ary, value)
+rb_ary_rassoc(ary, value)
VALUE ary;
VALUE value;
{
@@ -1059,65 +1077,66 @@ ary_rassoc(ary, value)
}
static VALUE
-ary_equal(ary1, ary2)
+rb_ary_equal(ary1, ary2)
VALUE ary1, ary2;
{
int i;
- if (TYPE(ary2) != T_ARRAY) return FALSE;
- if (RARRAY(ary1)->len != RARRAY(ary2)->len) return FALSE;
+ if (TYPE(ary2) != T_ARRAY) return Qfalse;
+ if (RARRAY(ary1)->len != RARRAY(ary2)->len) return Qfalse;
for (i=0; i<RARRAY(ary1)->len; i++) {
if (!rb_equal(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
- return FALSE;
+ return Qfalse;
}
- return TRUE;
+ return Qtrue;
}
static VALUE
-ary_eql(ary1, ary2)
+rb_ary_eql(ary1, ary2)
VALUE ary1, ary2;
{
int i;
- if (TYPE(ary2) != T_ARRAY) return FALSE;
+ if (TYPE(ary2) != T_ARRAY) return Qfalse;
if (RARRAY(ary1)->len != RARRAY(ary2)->len)
- return FALSE;
+ return Qfalse;
for (i=0; i<RARRAY(ary1)->len; i++) {
if (!rb_eql(RARRAY(ary1)->ptr[i], RARRAY(ary2)->ptr[i]))
- return FALSE;
+ return Qfalse;
}
- return TRUE;
+ return Qtrue;
}
static VALUE
-ary_hash(ary)
+rb_ary_hash(ary)
VALUE ary;
{
int h, i;
h = RARRAY(ary)->len;
for (i=0; i<RARRAY(ary)->len; i++) {
- h ^= rb_hash(RARRAY(ary)->ptr[i]);
+ int n = rb_hash(RARRAY(ary)->ptr[i]);
+ h ^= NUM2LONG(n);
}
return INT2FIX(h);
}
VALUE
-ary_includes(ary, item)
+rb_ary_includes(ary, item)
VALUE ary;
VALUE item;
{
int i;
for (i=0; i<RARRAY(ary)->len; i++) {
if (rb_equal(RARRAY(ary)->ptr[i], item)) {
- return TRUE;
+ return Qtrue;
}
}
- return FALSE;
+ return Qfalse;
}
-VALUE
-ary_cmp(ary, ary2)
+static VALUE
+rb_ary_cmp(ary, ary2)
VALUE ary;
VALUE ary2;
{
@@ -1141,72 +1160,72 @@ ary_cmp(ary, ary2)
}
static VALUE
-ary_diff(ary1, ary2)
+rb_ary_diff(ary1, ary2)
VALUE ary1, ary2;
{
VALUE ary3;
int i;
ary2 = to_ary(ary2);
- ary3 = ary_new();
+ ary3 = rb_ary_new();
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (ary_includes(ary2, RARRAY(ary1)->ptr[i])) continue;
- if (ary_includes(ary3, RARRAY(ary1)->ptr[i])) continue;
- ary_push(ary3, RARRAY(ary1)->ptr[i]);
+ if (rb_ary_includes(ary2, RARRAY(ary1)->ptr[i])) continue;
+ if (rb_ary_includes(ary3, RARRAY(ary1)->ptr[i])) continue;
+ rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
}
return ary3;
}
static VALUE
-ary_and(ary1, ary2)
+rb_ary_and(ary1, ary2)
VALUE ary1, ary2;
{
VALUE ary3;
int i;
ary2 = to_ary(ary2);
- ary3 = ary_new();
+ ary3 = rb_ary_new();
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (ary_includes(ary2, RARRAY(ary1)->ptr[i])
- && !ary_includes(ary3, RARRAY(ary1)->ptr[i])) {
- ary_push(ary3, RARRAY(ary1)->ptr[i]);
+ if (rb_ary_includes(ary2, RARRAY(ary1)->ptr[i])
+ && !rb_ary_includes(ary3, RARRAY(ary1)->ptr[i])) {
+ rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
}
}
return ary3;
}
static VALUE
-ary_or(ary1, ary2)
+rb_ary_or(ary1, ary2)
VALUE ary1, ary2;
{
VALUE ary3;
int i;
if (TYPE(ary2) != T_ARRAY) {
- if (ary_includes(ary1, ary2)) return ary1;
- else return ary_plus(ary1, ary2);
+ if (rb_ary_includes(ary1, ary2)) return ary1;
+ else return rb_ary_plus(ary1, ary2);
}
- ary3 = ary_new();
+ ary3 = rb_ary_new();
for (i=0; i<RARRAY(ary1)->len; i++) {
- if (!ary_includes(ary3, RARRAY(ary1)->ptr[i]))
- ary_push(ary3, RARRAY(ary1)->ptr[i]);
+ if (!rb_ary_includes(ary3, RARRAY(ary1)->ptr[i]))
+ rb_ary_push(ary3, RARRAY(ary1)->ptr[i]);
}
for (i=0; i<RARRAY(ary2)->len; i++) {
- if (!ary_includes(ary3, RARRAY(ary2)->ptr[i]))
- ary_push(ary3, RARRAY(ary2)->ptr[i]);
+ if (!rb_ary_includes(ary3, RARRAY(ary2)->ptr[i]))
+ rb_ary_push(ary3, RARRAY(ary2)->ptr[i]);
}
return ary3;
}
static VALUE
-ary_uniq_bang(ary)
+rb_ary_uniq_bang(ary)
VALUE ary;
{
VALUE *p, *q, *t, *end;
VALUE v;
- ary_modify(ary);
+ rb_ary_modify(ary);
p = RARRAY(ary)->ptr;
end = p + RARRAY(ary)->len;
@@ -1229,22 +1248,22 @@ ary_uniq_bang(ary)
}
static VALUE
-ary_uniq(ary)
+rb_ary_uniq(ary)
VALUE ary;
{
- VALUE v = ary_uniq_bang(ary_dup(ary));
+ VALUE v = rb_ary_uniq_bang(rb_ary_dup(ary));
if (NIL_P(v)) return ary;
return v;
}
static VALUE
-ary_compact_bang(ary)
+rb_ary_compact_bang(ary)
VALUE ary;
{
VALUE *p, *t, *end;
- ary_modify(ary);
+ rb_ary_modify(ary);
p = t = RARRAY(ary)->ptr;
end = p + RARRAY(ary)->len;
while (t < end) {
@@ -1261,17 +1280,17 @@ ary_compact_bang(ary)
}
static VALUE
-ary_compact(ary)
+rb_ary_compact(ary)
VALUE ary;
{
- VALUE v = ary_compact_bang(ary_dup(ary));
+ VALUE v = rb_ary_compact_bang(rb_ary_dup(ary));
if (NIL_P(v)) return ary;
return v;
}
static VALUE
-ary_nitems(ary)
+rb_ary_nitems(ary)
VALUE ary;
{
int n = 0;
@@ -1287,17 +1306,17 @@ ary_nitems(ary)
}
static VALUE
-ary_flatten_bang(ary)
+rb_ary_flatten_bang(ary)
VALUE ary;
{
int i;
int mod = 0;
- ary_modify(ary);
+ rb_ary_modify(ary);
for (i=0; i<RARRAY(ary)->len; i++) {
VALUE ary2 = RARRAY(ary)->ptr[i];
if (TYPE(ary2) == T_ARRAY) {
- ary_replace(ary, i--, 1, ary2);
+ rb_ary_replace(ary, i--, 1, ary2);
mod = 1;
}
}
@@ -1306,10 +1325,10 @@ ary_flatten_bang(ary)
}
static VALUE
-ary_flatten(ary)
+rb_ary_flatten(ary)
VALUE ary;
{
- VALUE v = ary_flatten_bang(ary_dup(ary));
+ VALUE v = rb_ary_flatten_bang(rb_ary_dup(ary));
if (NIL_P(v)) return ary;
return v;
@@ -1318,76 +1337,76 @@ ary_flatten(ary)
void
Init_Array()
{
- cArray = rb_define_class("Array", cObject);
- rb_include_module(cArray, mEnumerable);
-
- rb_define_singleton_method(cArray, "new", ary_s_new, -1);
- rb_define_singleton_method(cArray, "[]", ary_s_create, -1);
- rb_define_method(cArray, "to_s", ary_to_s, 0);
- rb_define_method(cArray, "inspect", ary_inspect, 0);
- rb_define_method(cArray, "to_a", ary_to_a, 0);
- rb_define_method(cArray, "to_ary", ary_to_a, 0);
-
- rb_define_method(cArray, "freeze", ary_freeze, 0);
- rb_define_method(cArray, "frozen?", ary_frozen_p, 0);
-
- rb_define_method(cArray, "==", ary_equal, 1);
- rb_define_method(cArray, "eql?", ary_eql, 1);
- rb_define_method(cArray, "hash", ary_hash, 0);
-
- rb_define_method(cArray, "[]", ary_aref, -1);
- rb_define_method(cArray, "[]=", ary_aset, -1);
- rb_define_method(cArray, "concat", ary_concat, 1);
- rb_define_method(cArray, "<<", ary_push, 1);
- rb_define_method(cArray, "push", ary_push_method, -1);
- rb_define_method(cArray, "pop", ary_pop, 0);
- rb_define_method(cArray, "shift", ary_shift, 0);
- rb_define_method(cArray, "unshift", ary_unshift, 1);
- rb_define_method(cArray, "each", ary_each, 0);
- rb_define_method(cArray, "each_index", ary_each_index, 0);
- rb_define_method(cArray, "reverse_each", ary_reverse_each, 0);
- rb_define_method(cArray, "length", ary_length, 0);
- rb_define_alias(cArray, "size", "length");
- rb_define_method(cArray, "empty?", ary_empty_p, 0);
- rb_define_method(cArray, "index", ary_index, 1);
- rb_define_method(cArray, "rindex", ary_rindex, 1);
- rb_define_method(cArray, "indexes", ary_indexes, -1);
- rb_define_method(cArray, "indices", ary_indexes, -1);
- rb_define_method(cArray, "clone", ary_clone, 0);
- rb_define_method(cArray, "dup", ary_dup, 0);
- rb_define_method(cArray, "join", ary_join_method, -1);
- rb_define_method(cArray, "reverse", ary_reverse_method, 0);
- rb_define_method(cArray, "reverse!", ary_reverse, 0);
- rb_define_method(cArray, "sort", ary_sort, 0);
- rb_define_method(cArray, "sort!", ary_sort_bang, 0);
- rb_define_method(cArray, "delete", ary_delete, 1);
- rb_define_method(cArray, "delete_at", ary_delete_at, 1);
- rb_define_method(cArray, "delete_if", ary_delete_if, 0);
- rb_define_method(cArray, "filter", ary_filter, 0);
- rb_define_method(cArray, "replace", ary_replace_method, 1);
- rb_define_method(cArray, "clear", ary_clear, 0);
- rb_define_method(cArray, "fill", ary_fill, -1);
- rb_define_method(cArray, "include?", ary_includes, 1);
- rb_define_method(cArray, "===", ary_includes, 1);
- rb_define_method(cArray, "<=>", ary_cmp, 1);
-
- rb_define_method(cArray, "assoc", ary_assoc, 1);
- rb_define_method(cArray, "rassoc", ary_rassoc, 1);
-
- rb_define_method(cArray, "+", ary_plus, 1);
- rb_define_method(cArray, "*", ary_times, 1);
-
- rb_define_method(cArray, "-", ary_diff, 1);
- rb_define_method(cArray, "&", ary_and, 1);
- rb_define_method(cArray, "|", ary_or, 1);
-
- rb_define_method(cArray, "uniq", ary_uniq, 0);
- rb_define_method(cArray, "uniq!", ary_uniq_bang, 0);
- rb_define_method(cArray, "compact", ary_compact, 0);
- rb_define_method(cArray, "compact!", ary_compact_bang, 0);
- rb_define_method(cArray, "flatten", ary_flatten, 0);
- rb_define_method(cArray, "flatten!", ary_flatten_bang, 0);
- rb_define_method(cArray, "nitems", ary_nitems, 0);
+ rb_cArray = rb_define_class("Array", rb_cObject);
+ rb_include_module(rb_cArray, rb_mEnumerable);
+
+ rb_define_singleton_method(rb_cArray, "new", rb_ary_s_new, -1);
+ rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
+ rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0);
+ rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0);
+ rb_define_method(rb_cArray, "to_a", rb_ary_to_a, 0);
+ rb_define_method(rb_cArray, "to_ary", rb_ary_to_a, 0);
+
+ rb_define_method(rb_cArray, "freeze", rb_ary_freeze, 0);
+ rb_define_method(rb_cArray, "frozen?", rb_ary_frozen_p, 0);
+
+ rb_define_method(rb_cArray, "==", rb_ary_equal, 1);
+ rb_define_method(rb_cArray, "eql?", rb_ary_eql, 1);
+ rb_define_method(rb_cArray, "hash", rb_ary_hash, 0);
+
+ rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
+ rb_define_method(rb_cArray, "[]=", rb_ary_aset, -1);
+ rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
+ rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
+ rb_define_method(rb_cArray, "push", rb_ary_push_method, -1);
+ rb_define_method(rb_cArray, "pop", rb_ary_pop, 0);
+ rb_define_method(rb_cArray, "shift", rb_ary_shift, 0);
+ rb_define_method(rb_cArray, "unshift", rb_ary_unshift, 1);
+ rb_define_method(rb_cArray, "each", rb_ary_each, 0);
+ rb_define_method(rb_cArray, "each_index", rb_ary_each_index, 0);
+ rb_define_method(rb_cArray, "reverse_each", rb_ary_reverse_each, 0);
+ rb_define_method(rb_cArray, "length", rb_ary_length, 0);
+ rb_define_alias(rb_cArray, "size", "length");
+ rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
+ rb_define_method(rb_cArray, "index", rb_ary_index, 1);
+ rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
+ rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
+ rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
+ rb_define_method(rb_cArray, "clone", rb_ary_clone, 0);
+ rb_define_method(rb_cArray, "dup", rb_ary_dup, 0);
+ rb_define_method(rb_cArray, "join", rb_ary_join_method, -1);
+ rb_define_method(rb_cArray, "reverse", rb_ary_reverse_method, 0);
+ rb_define_method(rb_cArray, "reverse!", rb_ary_reverse, 0);
+ rb_define_method(rb_cArray, "sort", rb_ary_sort, 0);
+ rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0);
+ rb_define_method(rb_cArray, "delete", rb_ary_delete, 1);
+ rb_define_method(rb_cArray, "delete_at", rb_ary_delete_at, 1);
+ rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0);
+ rb_define_method(rb_cArray, "filter", rb_ary_filter, 0);
+ rb_define_method(rb_cArray, "replace", rb_ary_replace_method, 1);
+ rb_define_method(rb_cArray, "clear", rb_ary_clear, 0);
+ rb_define_method(rb_cArray, "fill", rb_ary_fill, -1);
+ rb_define_method(rb_cArray, "include?", rb_ary_includes, 1);
+ rb_define_method(rb_cArray, "===", rb_ary_includes, 1);
+ rb_define_method(rb_cArray, "<=>", rb_ary_cmp, 1);
+
+ rb_define_method(rb_cArray, "assoc", rb_ary_assoc, 1);
+ rb_define_method(rb_cArray, "rassoc", rb_ary_rassoc, 1);
+
+ rb_define_method(rb_cArray, "+", rb_ary_plus, 1);
+ rb_define_method(rb_cArray, "*", rb_ary_times, 1);
+
+ rb_define_method(rb_cArray, "-", rb_ary_diff, 1);
+ rb_define_method(rb_cArray, "&", rb_ary_and, 1);
+ rb_define_method(rb_cArray, "|", rb_ary_or, 1);
+
+ rb_define_method(rb_cArray, "uniq", rb_ary_uniq, 0);
+ rb_define_method(rb_cArray, "uniq!", rb_ary_uniq_bang, 0);
+ rb_define_method(rb_cArray, "compact", rb_ary_compact, 0);
+ rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
+ rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
+ rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, 0);
+ rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
cmp = rb_intern("<=>");
}
diff --git a/bignum.c b/bignum.c
index 4318760..876193b 100644
--- a/bignum.c
+++ b/bignum.c
@@ -12,7 +12,7 @@
#include <math.h>
#include <ctype.h>
-VALUE cBignum;
+VALUE rb_cBignum;
typedef unsigned short USHORT;
#define BDIGITS(x) RBIGNUM(x)->digits
@@ -38,10 +38,10 @@ bignew_1(klass, len, sign)
return (VALUE)big;
}
-#define bignew(len,sign) bignew_1(cBignum,len,sign)
+#define bignew(len,sign) bignew_1(rb_cBignum,len,sign)
VALUE
-big_clone(x)
+rb_big_clone(x)
VALUE x;
{
VALUE z = bignew_1(CLASS_OF(x), RBIGNUM(x)->len, RBIGNUM(x)->sign);
@@ -51,7 +51,7 @@ big_clone(x)
}
void
-big_2comp(x) /* get 2's complement */
+rb_big_2comp(x) /* get 2's complement */
VALUE x;
{
unsigned int i = RBIGNUM(x)->len;
@@ -101,14 +101,14 @@ bignorm(x)
}
VALUE
-big_norm(x)
+rb_big_norm(x)
VALUE x;
{
- return bignorm(RBIGNUM(x));
+ return bignorm(x);
}
VALUE
-uint2big(n)
+rb_uint2big(n)
unsigned long n;
{
unsigned int i = 0;
@@ -130,7 +130,7 @@ uint2big(n)
}
VALUE
-int2big(n)
+rb_int2big(n)
long n;
{
long neg = 0;
@@ -140,7 +140,7 @@ int2big(n)
n = -n;
neg = 1;
}
- big = uint2big(n);
+ big = rb_uint2big(n);
if (neg) {
RBIGNUM(big)->sign = 0;
}
@@ -148,23 +148,23 @@ int2big(n)
}
VALUE
-uint2inum(n)
+rb_uint2inum(n)
unsigned long n;
{
if (POSFIXABLE(n)) return INT2FIX(n);
- return uint2big(n);
+ return rb_uint2big(n);
}
VALUE
-int2inum(n)
+rb_int2inum(n)
long n;
{
if (FIXABLE(n)) return INT2FIX(n);
- return int2big(n);
+ return rb_int2big(n);
}
VALUE
-str2inum(str, base)
+rb_str2inum(str, base)
char *str;
int base;
{
@@ -222,7 +222,7 @@ str2inum(str, base)
}
}
else {
- VALUE big = uint2big(val);
+ VALUE big = rb_uint2big(val);
RBIGNUM(big)->sign = sign;
return big;
}
@@ -271,7 +271,7 @@ str2inum(str, base)
static char hexmap[] = "0123456789abcdef";
VALUE
-big2str(x, base)
+rb_big2str(x, base)
VALUE x;
int base;
{
@@ -282,10 +282,10 @@ big2str(x, base)
char *s, c;
if (FIXNUM_P(x)) {
- return fix2str(x, base);
+ return rb_fix2str(x, base);
}
i = RBIGNUM(x)->len;
- if (i == 0) return str_new2("0");
+ if (i == 0) return rb_str_new2("0");
if (base == 10) {
j = (sizeof(USHORT)/sizeof(char)*CHAR_BIT*i*241L)/800+2;
hbase = 10000;
@@ -305,12 +305,12 @@ big2str(x, base)
else {
j = 0;
hbase = 0;
- Fail("bignum cannot treat base %d", base);
+ rb_raise(rb_eArgError, "bignum cannot treat base %d", base);
}
- t = big_clone(x);
+ t = rb_big_clone(x);
ds = BDIGITS(t);
- ss = str_new(0, j);
+ ss = rb_str_new(0, j);
s = RSTRING(ss)->ptr;
s[0] = RBIGNUM(x)->sign ? '+' : '-';
@@ -340,14 +340,14 @@ big2str(x, base)
}
static VALUE
-big_to_s(x)
+rb_big_to_s(x)
VALUE x;
{
- return big2str(x, 10);
+ return rb_big2str(x, 10);
}
unsigned long
-big2ulong(x)
+rb_big2ulong(x)
VALUE x;
{
unsigned long num;
@@ -355,7 +355,7 @@ big2ulong(x)
USHORT *ds;
if (len > sizeof(long)/sizeof(USHORT))
- ArgError("bignum too big to convert into `uint'");
+ rb_raise(rb_eArgError, "bignum too big to convert into `uint'");
ds = BDIGITS(x);
num = 0;
while (len--) {
@@ -366,27 +366,27 @@ big2ulong(x)
}
long
-big2long(x)
+rb_big2long(x)
VALUE x;
{
- unsigned long num = big2ulong(x);
+ unsigned long num = rb_big2ulong(x);
if ((long)num < 0) {
- ArgError("bignum too big to convert into `int'");
+ rb_raise(rb_eArgError, "bignum too big to convert into `int'");
}
if (!RBIGNUM(x)->sign) return -num;
return num;
}
-VALUE
-big_to_i(x)
+static VALUE
+rb_big_to_i(x)
VALUE x;
{
return bignorm(x);
}
VALUE
-dbl2big(d)
+rb_dbl2big(d)
double d;
{
unsigned int i = 0;
@@ -412,7 +412,7 @@ dbl2big(d)
}
double
-big2dbl(x)
+rb_big2dbl(x)
VALUE x;
{
double d = 0.0;
@@ -426,29 +426,29 @@ big2dbl(x)
return d;
}
-VALUE
-big_to_f(x)
+static VALUE
+rb_big_to_f(x)
VALUE x;
{
- return float_new(big2dbl(x));
+ return rb_float_new(rb_big2dbl(x));
}
static VALUE
-big_cmp(x, y)
+rb_big_cmp(x, y)
VALUE x, y;
{
int xlen = RBIGNUM(x)->len;
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
break;
case T_BIGNUM:
break;
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
if (RBIGNUM(x)->sign > RBIGNUM(y)->sign) return INT2FIX(1);
@@ -466,18 +466,18 @@ big_cmp(x, y)
}
static VALUE
-big_eq(x, y)
+rb_big_eq(x, y)
VALUE x, y;
{
- if (big_cmp(x, y) == INT2FIX(0)) return TRUE;
- return FALSE;
+ if (rb_big_cmp(x, y) == INT2FIX(0)) return Qtrue;
+ return Qfalse;
}
static VALUE
-big_uminus(x)
+rb_big_uminus(x)
VALUE x;
{
- VALUE z = big_clone(x);
+ VALUE z = rb_big_clone(x);
RBIGNUM(z)->sign = !RBIGNUM(x)->sign;
@@ -485,16 +485,16 @@ big_uminus(x)
}
static VALUE
-big_neg(x)
+rb_big_neg(x)
VALUE x;
{
- VALUE z = big_clone(x);
+ VALUE z = rb_big_clone(x);
unsigned int i = RBIGNUM(x)->len;
USHORT *ds = BDIGITS(z);
- if (!RBIGNUM(x)->sign) big_2comp(z);
+ if (!RBIGNUM(x)->sign) rb_big_2comp(z);
while (i--) ds[i] = ~ds[i];
- if (RBIGNUM(x)->sign) big_2comp(z);
+ if (RBIGNUM(x)->sign) rb_big_2comp(z);
RBIGNUM(z)->sign = !RBIGNUM(z)->sign;
return bignorm(z);
@@ -557,22 +557,11 @@ bigadd(x, y, sign)
long num;
unsigned int i, len;
- if (RBIGNUM(x)->sign == (RBIGNUM(y)->sign ^ sign)) {
- if (RBIGNUM(y)->sign == sign) return bigsub(y, x);
+ sign = (sign == RBIGNUM(y)->sign);
+ if (RBIGNUM(x)->sign != sign) {
+ if (sign) return bigsub(y, x);
return bigsub(x, y);
}
- else if (sign == 0) {
- /* x - y */
- if ((RBIGNUM(x)->sign == 0) && (RBIGNUM(y)->sign == 1)) {
- /* x is negative and y is positive. */
- /* return -(abs(x) + y) */
- VALUE ret;
- RBIGNUM(x)->sign = 1; /* x = abs(x) */
- ret = bigadd(x, y, 1); /* ret = x + y (recursive call) */
- RBIGNUM(ret)->sign = 0; /* ret = -ret */
- return ret;
- }
- }
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
len = RBIGNUM(x)->len + 1;
@@ -581,7 +570,7 @@ bigadd(x, y, sign)
else {
len = RBIGNUM(y)->len + 1;
}
- z = bignew(len, sign==RBIGNUM(y)->sign);
+ z = bignew(len, sign);
len = RBIGNUM(x)->len;
for (i = 0, num = 0; i < len; i++) {
@@ -605,45 +594,45 @@ bigadd(x, y, sign)
}
VALUE
-big_plus(x, y)
+rb_big_plus(x, y)
VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
/* fall through */
case T_BIGNUM:
return bigadd(x, y, 1);
case T_FLOAT:
- return float_new(big2dbl(x) + RFLOAT(y)->value);
+ return rb_float_new(rb_big2dbl(x) + RFLOAT(y)->value);
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
}
VALUE
-big_minus(x, y)
+rb_big_minus(x, y)
VALUE x, y;
{
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
/* fall through */
case T_BIGNUM:
return bigadd(x, y, 0);
case T_FLOAT:
- return float_new(big2dbl(x) - RFLOAT(y)->value);
+ return rb_float_new(rb_big2dbl(x) - RFLOAT(y)->value);
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
}
VALUE
-big_mul(x, y)
+rb_big_mul(x, y)
VALUE x, y;
{
unsigned int i = 0, j;
@@ -651,20 +640,20 @@ big_mul(x, y)
VALUE z;
USHORT *zds;
- if (FIXNUM_P(x)) x = int2big(FIX2LONG(x));
+ if (FIXNUM_P(x)) x = rb_int2big(FIX2LONG(x));
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
break;
case T_BIGNUM:
break;
case T_FLOAT:
- return float_new(big2dbl(x) * RFLOAT(y)->value);
+ return rb_float_new(rb_big2dbl(x) * RFLOAT(y)->value);
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
j = RBIGNUM(x)->len + RBIGNUM(y)->len + 1;
@@ -703,7 +692,7 @@ bigdivmod(x, y, div, mod, modulo)
USHORT dd, q;
yds = BDIGITS(y);
- if (ny == 0 && yds[0] == 0) num_zerodiv();
+ if (ny == 0 && yds[0] == 0) rb_num_zerodiv();
if (nx < ny || nx == ny && BDIGITS(x)[nx - 1] < BDIGITS(y)[ny - 1]) {
if (div) *div = INT2FIX(0);
if (mod) *mod = bignorm(x);
@@ -712,7 +701,7 @@ bigdivmod(x, y, div, mod, modulo)
xds = BDIGITS(x);
if (ny == 1) {
dd = yds[0];
- z = big_clone(x);
+ z = rb_big_clone(x);
zds = BDIGITS(z);
t2 = 0; i = nx;
while (i--) {
@@ -732,7 +721,7 @@ bigdivmod(x, y, div, mod, modulo)
if (nx==ny) zds[nx+1] = 0;
while (!yds[ny-1]) ny--;
if ((dd = BIGRAD/(int)(yds[ny-1]+1)) != 1) {
- yy = big_clone(y);
+ yy = rb_big_clone(y);
tds = BDIGITS(yy);
j = 0;
num = 0;
@@ -786,7 +775,7 @@ bigdivmod(x, y, div, mod, modulo)
zds[j] = q;
} while (--j >= ny);
if (div) { /* move quotient down in z */
- *div = big_clone(z);
+ *div = rb_big_clone(z);
zds = BDIGITS(*div);
j = (nx==ny ? nx+2 : nx+1) - ny;
for (i = 0;i < j;i++) zds[i] = zds[i+ny];
@@ -794,7 +783,7 @@ bigdivmod(x, y, div, mod, modulo)
*div = bignorm(*div);
}
if (mod) { /* just normalize remainder */
- *mod = big_clone(z);
+ *mod = rb_big_clone(z);
if (dd) {
zds = BDIGITS(*mod);
t2 = 0; i = ny;
@@ -820,24 +809,24 @@ bigdivmod(x, y, div, mod, modulo)
}
static VALUE
-big_div(x, y)
+rb_big_div(x, y)
VALUE x, y;
{
VALUE z;
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
break;
case T_BIGNUM:
break;
case T_FLOAT:
- return float_new(big2dbl(x) / RFLOAT(y)->value);
+ return rb_float_new(rb_big2dbl(x) / RFLOAT(y)->value);
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
bigdivmod(x, y, &z, 0, 0);
@@ -846,7 +835,7 @@ big_div(x, y)
static VALUE
-big_modulo(x, y, modulo)
+rb_big_modulo(x, y, modulo)
VALUE x, y;
int modulo;
{
@@ -854,18 +843,18 @@ big_modulo(x, y, modulo)
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
break;
case T_BIGNUM:
break;
case T_FLOAT:
- y = dbl2big(RFLOAT(y)->value);
+ y = rb_dbl2big(RFLOAT(y)->value);
break;
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
bigdivmod(x, y, 0, &z, modulo);
@@ -873,47 +862,47 @@ big_modulo(x, y, modulo)
}
static VALUE
-big_mod(x, y)
+rb_big_mod(x, y)
VALUE x, y;
{
- return big_modulo(x, y, 1);
+ return rb_big_modulo(x, y, 1);
}
static VALUE
-big_remainder(x, y)
+rb_big_remainder(x, y)
VALUE x, y;
{
- return big_modulo(x, y, 0);
+ return rb_big_modulo(x, y, 0);
}
static VALUE
-big_divmod(x, y)
+rb_big_divmod(x, y)
VALUE x, y;
{
VALUE div, mod;
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
break;
case T_FLOAT:
- y = dbl2big(RFLOAT(y)->value);
+ y = rb_dbl2big(RFLOAT(y)->value);
break;
case T_BIGNUM:
break;
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
bigdivmod(x, y, &div, &mod, 1);
- return assoc_new(div, mod);;
+ return rb_assoc_new(div, mod);;
}
VALUE
-big_pow(x, y)
+rb_big_pow(x, y)
VALUE x, y;
{
double d;
@@ -926,8 +915,8 @@ big_pow(x, y)
break;
case T_BIGNUM:
- Warn("in a**b, b may be too big");
- d = big2dbl(y);
+ rb_warn("in a**b, b may be too big");
+ d = rb_big2dbl(y);
break;
case T_FIXNUM:
@@ -941,9 +930,9 @@ big_pow(x, y)
if (yy == 0) break;
while (yy % 2 == 0) {
yy = yy / 2;
- x = big_mul(x, x);
+ x = rb_big_mul(x, x);
}
- z = big_mul(z, x);
+ z = rb_big_mul(z, x);
}
return z;
}
@@ -951,13 +940,13 @@ big_pow(x, y)
break;
default:
- return num_coerce_bin(x, y);
+ return rb_num_coerce_bin(x, y);
}
- return float_new(pow(big2dbl(x), d));
+ return rb_float_new(pow(rb_big2dbl(x), d));
}
VALUE
-big_and(x, y)
+rb_big_and(x, y)
VALUE x, y;
{
VALUE z;
@@ -966,19 +955,19 @@ big_and(x, y)
char sign;
if (FIXNUM_P(y)) {
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
}
else {
Check_Type(y, T_BIGNUM);
}
if (!RBIGNUM(y)->sign) {
- y = big_clone(y);
- big_2comp(y);
+ y = rb_big_clone(y);
+ rb_big_2comp(y);
}
if (!RBIGNUM(x)->sign) {
- x = big_clone(x);
- big_2comp(x);
+ x = rb_big_clone(x);
+ rb_big_2comp(x);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@@ -1003,12 +992,12 @@ big_and(x, y)
for (; i<l2; i++) {
zds[i] = sign?0:ds2[i];
}
- if (!RBIGNUM(z)->sign) big_2comp(z);
+ if (!RBIGNUM(z)->sign) rb_big_2comp(z);
return bignorm(z);
}
VALUE
-big_or(x, y)
+rb_big_or(x, y)
VALUE x, y;
{
VALUE z;
@@ -1017,19 +1006,19 @@ big_or(x, y)
char sign;
if (FIXNUM_P(y)) {
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
}
else {
Check_Type(y, T_BIGNUM);
}
if (!RBIGNUM(y)->sign) {
- y = big_clone(y);
- big_2comp(y);
+ y = rb_big_clone(y);
+ rb_big_2comp(y);
}
if (!RBIGNUM(x)->sign) {
- x = big_clone(x);
- big_2comp(x);
+ x = rb_big_clone(x);
+ rb_big_2comp(x);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@@ -1054,13 +1043,13 @@ big_or(x, y)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:(BIGRAD-1);
}
- if (!RBIGNUM(z)->sign) big_2comp(z);
+ if (!RBIGNUM(z)->sign) rb_big_2comp(z);
return bignorm(z);
}
VALUE
-big_xor(x, y)
+rb_big_xor(x, y)
VALUE x, y;
{
VALUE z;
@@ -1069,19 +1058,19 @@ big_xor(x, y)
char sign;
if (FIXNUM_P(y)) {
- y = int2big(FIX2LONG(y));
+ y = rb_int2big(FIX2LONG(y));
}
else {
Check_Type(y, T_BIGNUM);
}
if (!RBIGNUM(y)->sign) {
- y = big_clone(y);
- big_2comp(y);
+ y = rb_big_clone(y);
+ rb_big_2comp(y);
}
if (!RBIGNUM(x)->sign) {
- x = big_clone(x);
- big_2comp(x);
+ x = rb_big_clone(x);
+ rb_big_2comp(x);
}
if (RBIGNUM(x)->len > RBIGNUM(y)->len) {
l1 = RBIGNUM(y)->len;
@@ -1108,15 +1097,15 @@ big_xor(x, y)
for (; i<l2; i++) {
zds[i] = sign?ds2[i]:~ds2[i];
}
- if (!RBIGNUM(z)->sign) big_2comp(z);
+ if (!RBIGNUM(z)->sign) rb_big_2comp(z);
return bignorm(z);
}
-static VALUE big_rshift _((VALUE,VALUE));
+static VALUE rb_big_rshift _((VALUE,VALUE));
VALUE
-big_lshift(x, y)
+rb_big_lshift(x, y)
VALUE x, y;
{
USHORT *xds, *zds;
@@ -1127,7 +1116,7 @@ big_lshift(x, y)
unsigned long num = 0;
unsigned int len, i;
- if (shift < 0) return big_rshift(x, INT2FIX(-shift));
+ if (shift < 0) return rb_big_rshift(x, INT2FIX(-shift));
xds = BDIGITS(x);
len = RBIGNUM(x)->len;
z = bignew(len+s1+1, RBIGNUM(x)->sign);
@@ -1145,7 +1134,7 @@ big_lshift(x, y)
}
static VALUE
-big_rshift(x, y)
+rb_big_rshift(x, y)
VALUE x, y;
{
USHORT *xds, *zds;
@@ -1157,7 +1146,7 @@ big_rshift(x, y)
unsigned int i = RBIGNUM(x)->len;
unsigned int j;
- if (shift < 0) return big_lshift(x, INT2FIX(-shift));
+ if (shift < 0) return rb_big_lshift(x, INT2FIX(-shift));
if (s1 > RBIGNUM(x)->len) {
if (RBIGNUM(x)->sign)
return INT2FIX(0);
@@ -1177,7 +1166,7 @@ big_rshift(x, y)
}
static VALUE
-big_aref(x, y)
+rb_big_aref(x, y)
VALUE x, y;
{
USHORT *xds;
@@ -1190,8 +1179,8 @@ big_aref(x, y)
if (!RBIGNUM(x)->sign) {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(1);
- x = big_clone(x);
- big_2comp(x);
+ x = rb_big_clone(x);
+ rb_big_2comp(x);
}
else {
if (s1 >= RBIGNUM(x)->len) return INT2FIX(0);
@@ -1203,7 +1192,7 @@ big_aref(x, y)
}
static VALUE
-big_hash(x)
+rb_big_hash(x)
VALUE x;
{
int i, len, key;
@@ -1217,24 +1206,25 @@ big_hash(x)
}
static VALUE
-big_coerce(x, y)
+rb_big_coerce(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- return assoc_new(int2big(FIX2LONG(y)), x);
+ return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
}
else {
- TypeError("can't coerce %s to Bignum", rb_class2name(CLASS_OF(y)));
+ rb_raise(rb_eTypeError, "can't coerce %s to Bignum",
+ rb_class2name(CLASS_OF(y)));
}
/* not reached */
}
static VALUE
-big_abs(x)
+rb_big_abs(x)
VALUE x;
{
if (!RBIGNUM(x)->sign) {
- x = big_clone(x);
+ x = rb_big_clone(x);
RBIGNUM(x)->sign = 1;
}
return x;
@@ -1245,7 +1235,7 @@ big_abs(x)
*/
VALUE
-big_rand(max)
+rb_big_rand(max)
VALUE max;
{
struct RBignum *v;
@@ -1261,56 +1251,56 @@ big_rand(max)
#endif
}
- return big_mod(v, max);
+ return rb_big_mod((VALUE)v, max);
}
static VALUE
-big_size(big)
+rb_big_size(big)
VALUE big;
{
return INT2FIX(RBIGNUM(big)->len*sizeof(USHORT));
}
static VALUE
-big_zero_p(big)
+rb_big_zero_p(big)
VALUE big;
{
- return FALSE;
+ return Qfalse;
}
void
Init_Bignum()
{
- cBignum = rb_define_class("Bignum", cInteger);
-
- rb_undef_method(CLASS_OF(cBignum), "new");
-
- rb_define_method(cBignum, "to_s", big_to_s, 0);
- rb_define_method(cBignum, "coerce", big_coerce, 1);
- rb_define_method(cBignum, "-@", big_uminus, 0);
- rb_define_method(cBignum, "+", big_plus, 1);
- rb_define_method(cBignum, "-", big_minus, 1);
- rb_define_method(cBignum, "*", big_mul, 1);
- rb_define_method(cBignum, "/", big_div, 1);
- rb_define_method(cBignum, "%", big_mod, 1);
- rb_define_method(cBignum, "divmod", big_divmod, 1);
- rb_define_method(cBignum, "remainder", big_remainder, 1);
- rb_define_method(cBignum, "**", big_pow, 1);
- rb_define_method(cBignum, "&", big_and, 1);
- rb_define_method(cBignum, "|", big_or, 1);
- rb_define_method(cBignum, "^", big_xor, 1);
- rb_define_method(cBignum, "~", big_neg, 0);
- rb_define_method(cBignum, "<<", big_lshift, 1);
- rb_define_method(cBignum, ">>", big_rshift, 1);
- rb_define_method(cBignum, "[]", big_aref, 1);
-
- rb_define_method(cBignum, "<=>", big_cmp, 1);
- rb_define_method(cBignum, "==", big_eq, 1);
- rb_define_method(cBignum, "eql?", big_eq, 1);
- rb_define_method(cBignum, "hash", big_hash, 0);
- rb_define_method(cBignum, "to_i", big_to_i, 0);
- rb_define_method(cBignum, "to_f", big_to_f, 0);
- rb_define_method(cBignum, "abs", big_abs, 0);
- rb_define_method(cBignum, "size", big_size, 0);
- rb_define_method(cBignum, "zero?", big_zero_p, 0);
+ rb_cBignum = rb_define_class("Bignum", rb_cInteger);
+
+ rb_undef_method(CLASS_OF(rb_cBignum), "new");
+
+ rb_define_method(rb_cBignum, "to_s", rb_big_to_s, 0);
+ rb_define_method(rb_cBignum, "coerce", rb_big_coerce, 1);
+ rb_define_method(rb_cBignum, "-@", rb_big_uminus, 0);
+ rb_define_method(rb_cBignum, "+", rb_big_plus, 1);
+ rb_define_method(rb_cBignum, "-", rb_big_minus, 1);
+ rb_define_method(rb_cBignum, "*", rb_big_mul, 1);
+ rb_define_method(rb_cBignum, "/", rb_big_div, 1);
+ rb_define_method(rb_cBignum, "%", rb_big_mod, 1);
+ rb_define_method(rb_cBignum, "divmod", rb_big_divmod, 1);
+ rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1);
+ rb_define_method(rb_cBignum, "**", rb_big_pow, 1);
+ rb_define_method(rb_cBignum, "&", rb_big_and, 1);
+ rb_define_method(rb_cBignum, "|", rb_big_or, 1);
+ rb_define_method(rb_cBignum, "^", rb_big_xor, 1);
+ rb_define_method(rb_cBignum, "~", rb_big_neg, 0);
+ rb_define_method(rb_cBignum, "<<", rb_big_lshift, 1);
+ rb_define_method(rb_cBignum, ">>", rb_big_rshift, 1);
+ rb_define_method(rb_cBignum, "[]", rb_big_aref, 1);
+
+ rb_define_method(rb_cBignum, "<=>", rb_big_cmp, 1);
+ rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
+ rb_define_method(rb_cBignum, "eql?", rb_big_eq, 1);
+ rb_define_method(rb_cBignum, "hash", rb_big_hash, 0);
+ rb_define_method(rb_cBignum, "to_i", rb_big_to_i, 0);
+ rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0);
+ rb_define_method(rb_cBignum, "abs", rb_big_abs, 0);
+ rb_define_method(rb_cBignum, "size", rb_big_size, 0);
+ rb_define_method(rb_cBignum, "zero?", rb_big_zero_p, 0);
}
diff --git a/class.c b/class.c
index fefc99d..3ad4dba 100644
--- a/class.c
+++ b/class.c
@@ -22,25 +22,25 @@
extern st_table *rb_class_tbl;
VALUE
-class_new(super)
+rb_class_new(super)
VALUE super;
{
NEWOBJ(klass, struct RClass);
- OBJSETUP(klass, cClass, T_CLASS);
+ OBJSETUP(klass, rb_cClass, T_CLASS);
klass->super = super;
klass->iv_tbl = 0;
klass->m_tbl = 0; /* safe GC */
- klass->m_tbl = new_idhash();
+ klass->m_tbl = st_init_numtable();
return (VALUE)klass;
}
VALUE
-singleton_class_new(super)
+rb_singleton_class_new(super)
VALUE super;
{
- VALUE klass = class_new(super);
+ VALUE klass = rb_class_new(super);
FL_SET(klass, FL_SINGLETON);
return klass;
@@ -57,7 +57,7 @@ clone_method(mid, body, tbl)
}
VALUE
-singleton_class_clone(klass)
+rb_singleton_class_clone(klass)
VALUE klass;
{
if (!FL_TEST(klass, FL_SINGLETON))
@@ -70,7 +70,7 @@ singleton_class_clone(klass)
clone->super = RCLASS(klass)->super;
clone->iv_tbl = 0;
clone->m_tbl = 0;
- clone->m_tbl = new_idhash();
+ clone->m_tbl = st_init_numtable();
st_foreach(RCLASS(klass)->m_tbl, clone_method, clone->m_tbl);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
@@ -78,7 +78,7 @@ singleton_class_clone(klass)
}
void
-singleton_class_attached(klass, obj)
+rb_singleton_class_attached(klass, obj)
VALUE klass, obj;
{
if (FL_TEST(klass, FL_SINGLETON))
@@ -92,12 +92,12 @@ rb_define_class_id(id, super)
{
VALUE klass;
- if (!super) super = cObject;
- klass = class_new(super);
+ if (!super) super = rb_cObject;
+ klass = rb_class_new(super);
rb_name_class(klass, id);
/* make metaclass */
- RBASIC(klass)->klass = singleton_class_new(RBASIC(super)->klass);
- singleton_class_attached(RBASIC(klass)->klass, klass);
+ RBASIC(klass)->klass = rb_singleton_class_new(RBASIC(super)->klass);
+ rb_singleton_class_attached(RBASIC(klass)->klass, klass);
rb_funcall(super, rb_intern("inherited"), 1, klass);
return klass;
@@ -136,15 +136,15 @@ rb_define_class_under(outer, name, super)
}
VALUE
-module_new()
+rb_module_new()
{
NEWOBJ(mdl, struct RClass);
- OBJSETUP(mdl, cModule, T_MODULE);
+ OBJSETUP(mdl, rb_cModule, T_MODULE);
mdl->super = 0;
mdl->iv_tbl = 0;
mdl->m_tbl = 0;
- mdl->m_tbl = new_idhash();
+ mdl->m_tbl = st_init_numtable();
return (VALUE)mdl;
}
@@ -154,7 +154,7 @@ rb_define_module_id(id)
ID id;
{
extern st_table *rb_class_tbl;
- VALUE mdl = module_new();
+ VALUE mdl = rb_module_new();
rb_name_class(mdl, id);
@@ -192,11 +192,11 @@ rb_define_module_under(outer, name)
}
static VALUE
-include_class_new(module, super)
+include_rb_class_new(module, super)
VALUE module, super;
{
NEWOBJ(klass, struct RClass);
- OBJSETUP(klass, cClass, T_ICLASS);
+ OBJSETUP(klass, rb_cClass, T_ICLASS);
klass->m_tbl = RCLASS(module)->m_tbl;
klass->iv_tbl = RCLASS(module)->iv_tbl;
@@ -241,7 +241,7 @@ rb_include_module(klass, module)
}
}
RCLASS(klass)->super =
- include_class_new(module, RCLASS(klass)->super);
+ include_rb_class_new(module, RCLASS(klass)->super);
klass = RCLASS(klass)->super;
module = RCLASS(module)->super;
}
@@ -249,35 +249,35 @@ rb_include_module(klass, module)
}
VALUE
-mod_included_modules(mod)
+rb_mod_included_modules(mod)
VALUE mod;
{
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
VALUE p;
for (p = RCLASS(mod)->super; p; p = RCLASS(p)->super) {
if (BUILTIN_TYPE(p) == T_ICLASS) {
- ary_push(ary, RBASIC(p)->klass);
+ rb_ary_push(ary, RBASIC(p)->klass);
}
}
return ary;
}
VALUE
-mod_ancestors(mod)
+rb_mod_ancestors(mod)
VALUE mod;
{
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
VALUE p;
for (p = mod; p; p = RCLASS(p)->super) {
if (FL_TEST(p, FL_SINGLETON))
continue;
if (BUILTIN_TYPE(p) == T_ICLASS) {
- ary_push(ary, RBASIC(p)->klass);
+ rb_ary_push(ary, RBASIC(p)->klass);
}
else {
- ary_push(ary, p);
+ rb_ary_push(ary, p);
}
}
return ary;
@@ -290,18 +290,18 @@ ins_methods_i(key, body, ary)
VALUE ary;
{
if ((body->nd_noex&(NOEX_PRIVATE|NOEX_PROTECTED)) == 0) {
- VALUE name = str_new2(rb_id2name(key));
+ VALUE name = rb_str_new2(rb_id2name(key));
- if (!ary_includes(ary, name)) {
+ if (!rb_ary_includes(ary, name)) {
if (!body->nd_body) {
- ary_push(ary, Qnil);
+ rb_ary_push(ary, Qnil);
}
- ary_push(ary, name);
+ rb_ary_push(ary, name);
}
}
else if (body->nd_body && nd_type(body->nd_body) == NODE_ZSUPER) {
- ary_push(ary, Qnil);
- ary_push(ary, str_new2(rb_id2name(key)));
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
return ST_CONTINUE;
}
@@ -313,19 +313,19 @@ ins_methods_prot_i(key, body, ary)
VALUE ary;
{
if (!body->nd_body) {
- ary_push(ary, Qnil);
- ary_push(ary, str_new2(rb_id2name(key)));
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
else if (body->nd_noex & NOEX_PROTECTED) {
- VALUE name = str_new2(rb_id2name(key));
+ VALUE name = rb_str_new2(rb_id2name(key));
- if (!ary_includes(ary, name)) {
- ary_push(ary, name);
+ if (!rb_ary_includes(ary, name)) {
+ rb_ary_push(ary, name);
}
}
else if (nd_type(body->nd_body) == NODE_ZSUPER) {
- ary_push(ary, Qnil);
- ary_push(ary, str_new2(rb_id2name(key)));
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
return ST_CONTINUE;
}
@@ -337,19 +337,19 @@ ins_methods_priv_i(key, body, ary)
VALUE ary;
{
if (!body->nd_body) {
- ary_push(ary, Qnil);
- ary_push(ary, str_new2(rb_id2name(key)));
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
else if (body->nd_noex & NOEX_PRIVATE) {
- VALUE name = str_new2(rb_id2name(key));
+ VALUE name = rb_str_new2(rb_id2name(key));
- if (!ary_includes(ary, name)) {
- ary_push(ary, name);
+ if (!rb_ary_includes(ary, name)) {
+ rb_ary_push(ary, name);
}
}
else if (nd_type(body->nd_body) == NODE_ZSUPER) {
- ary_push(ary, Qnil);
- ary_push(ary, str_new2(rb_id2name(key)));
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
return ST_CONTINUE;
}
@@ -364,7 +364,7 @@ method_list(mod, option, func)
VALUE klass;
VALUE *p, *q, *pend;
- ary = ary_new();
+ ary = rb_ary_new();
for (klass = mod; klass; klass = RCLASS(klass)->super) {
st_foreach(RCLASS(klass)->m_tbl, func, ary);
if (!option) break;
@@ -382,7 +382,7 @@ method_list(mod, option, func)
}
VALUE
-class_instance_methods(argc, argv, mod)
+rb_class_instance_methods(argc, argv, mod)
int argc;
VALUE *argv;
VALUE mod;
@@ -394,7 +394,7 @@ class_instance_methods(argc, argv, mod)
}
VALUE
-class_protected_instance_methods(argc, argv, mod)
+rb_class_protected_instance_methods(argc, argv, mod)
int argc;
VALUE *argv;
VALUE mod;
@@ -406,7 +406,7 @@ class_protected_instance_methods(argc, argv, mod)
}
VALUE
-class_private_instance_methods(argc, argv, mod)
+rb_class_private_instance_methods(argc, argv, mod)
int argc;
VALUE *argv;
VALUE mod;
@@ -418,14 +418,14 @@ class_private_instance_methods(argc, argv, mod)
}
VALUE
-obj_singleton_methods(obj)
+rb_obj_singleton_methods(obj)
VALUE obj;
{
VALUE ary;
VALUE klass;
VALUE *p, *q, *pend;
- ary = ary_new();
+ ary = rb_ary_new();
klass = CLASS_OF(obj);
while (klass && FL_TEST(klass, FL_SINGLETON)) {
st_foreach(RCLASS(klass)->m_tbl, ins_methods_i, ary);
@@ -503,13 +503,13 @@ rb_singleton_class(obj)
VALUE obj;
{
if (rb_special_const_p(obj)) {
- TypeError("cannot define singleton");
+ rb_raise(rb_eTypeError, "cannot define singleton");
}
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON)) {
return RBASIC(obj)->klass;
}
- RBASIC(obj)->klass = singleton_class_new(RBASIC(obj)->klass);
- singleton_class_attached(RBASIC(obj)->klass, obj);
+ RBASIC(obj)->klass = rb_singleton_class_new(RBASIC(obj)->klass);
+ rb_singleton_class_attached(RBASIC(obj)->klass, obj);
return RBASIC(obj)->klass;
}
@@ -540,7 +540,7 @@ rb_define_global_function(name, func, argc)
VALUE (*func)();
int argc;
{
- rb_define_private_method(mKernel, name, func, argc);
+ rb_define_private_method(rb_mKernel, name, func, argc);
}
void
@@ -557,7 +557,7 @@ rb_define_attr(klass, name, read, write)
char *name;
int read, write;
{
- rb_attr(klass, rb_intern(name), read, write, FALSE);
+ rb_attr(klass, rb_intern(name), read, write, Qfalse);
}
#ifdef HAVE_STDARG_PROTOTYPES
@@ -588,14 +588,14 @@ rb_scan_args(argc, argv, fmt, va_alist)
if (*p == '*') {
var = va_arg(vargs, VALUE*);
- *var = ary_new4(argc, argv);
+ *var = rb_ary_new4(argc, argv);
return argc;
}
if (ISDIGIT(*p)) {
n = *p - '0';
if (n > argc)
- ArgError("Wrong # of arguments (%d for %d)", argc, n);
+ rb_raise(rb_eArgError, "Wrong # of arguments (%d for %d)", argc, n);
for (i=0; i<n; i++) {
var = va_arg(vargs, VALUE*);
*var = argv[i];
@@ -623,15 +623,15 @@ rb_scan_args(argc, argv, fmt, va_alist)
if(*p == '*') {
var = va_arg(vargs, VALUE*);
if (argc > i) {
- *var = ary_new4(argc-i, argv+i);
+ *var = rb_ary_new4(argc-i, argv+i);
}
else {
- *var = ary_new();
+ *var = rb_ary_new();
}
}
else if (*p == '\0') {
if (argc > i) {
- ArgError("Wrong # of arguments(%d for %d)", argc, i);
+ rb_raise(rb_eArgError, "Wrong # of arguments(%d for %d)", argc, i);
}
}
else {
@@ -642,6 +642,6 @@ rb_scan_args(argc, argv, fmt, va_alist)
return argc;
error:
- Fatal("bad scan arg format: %s", fmt);
+ rb_fatal("bad scan arg format: %s", fmt);
return 0;
}
diff --git a/compar.c b/compar.c
index 846364e..a6212a8 100644
--- a/compar.c
+++ b/compar.c
@@ -12,7 +12,7 @@
#include "ruby.h"
-VALUE mComparable;
+VALUE rb_mComparable;
static ID cmp;
@@ -23,8 +23,8 @@ cmp_eq(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
- if (t == 0) return TRUE;
- return FALSE;
+ if (t == 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -34,8 +34,8 @@ cmp_gt(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
- if (t > 0) return TRUE;
- return FALSE;
+ if (t > 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -45,8 +45,8 @@ cmp_ge(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
- if (t >= 0) return TRUE;
- return FALSE;
+ if (t >= 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -56,8 +56,8 @@ cmp_lt(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
- if (t < 0) return TRUE;
- return FALSE;
+ if (t < 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -67,8 +67,8 @@ cmp_le(x, y)
VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
- if (t <= 0) return TRUE;
- return FALSE;
+ if (t <= 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -77,24 +77,24 @@ cmp_between(x, min, max)
{
VALUE c = rb_funcall(x, cmp, 1, min);
long t = NUM2LONG(c);
- if (t < 0) return FALSE;
+ if (t < 0) return Qfalse;
c = rb_funcall(x, cmp, 1, max);
t = NUM2LONG(c);
- if (t > 0) return FALSE;
- return TRUE;
+ if (t > 0) return Qfalse;
+ return Qtrue;
}
void
Init_Comparable()
{
- mComparable = rb_define_module("Comparable");
- rb_define_method(mComparable, "==", cmp_eq, 1);
- rb_define_method(mComparable, ">", cmp_gt, 1);
- rb_define_method(mComparable, ">=", cmp_ge, 1);
- rb_define_method(mComparable, "<", cmp_lt, 1);
- rb_define_method(mComparable, "<=", cmp_le, 1);
- rb_define_method(mComparable, "between?", cmp_between, 2);
+ rb_mComparable = rb_define_module("Comparable");
+ rb_define_method(rb_mComparable, "==", cmp_eq, 1);
+ rb_define_method(rb_mComparable, ">", cmp_gt, 1);
+ rb_define_method(rb_mComparable, ">=", cmp_ge, 1);
+ rb_define_method(rb_mComparable, "<", cmp_lt, 1);
+ rb_define_method(rb_mComparable, "<=", cmp_le, 1);
+ rb_define_method(rb_mComparable, "between?", cmp_between, 2);
cmp = rb_intern("<=>");
}
diff --git a/dir.c b/dir.c
index 31524dd..6c670b8 100644
--- a/dir.c
+++ b/dir.c
@@ -57,7 +57,7 @@ char *getenv();
# include <sys/errno.h>
#endif
-static VALUE cDir;
+VALUE rb_cDir;
static void
free_dir(dir)
@@ -80,7 +80,7 @@ dir_s_open(dir_class, dirname)
dirp = opendir(RSTRING(dirname)->ptr);
if (dirp == NULL) {
if (errno == EMFILE || errno == ENFILE) {
- gc_gc();
+ rb_gc();
dirp = opendir(RSTRING(dirname)->ptr);
}
if (dirp == NULL) {
@@ -90,7 +90,7 @@ dir_s_open(dir_class, dirname)
obj = Data_Wrap_Struct(dir_class, 0, free_dir, dirp);
- if (iterator_p()) {
+ if (rb_iterator_p()) {
return rb_ensure(rb_yield, obj, dir_close, obj);
}
@@ -100,7 +100,7 @@ dir_s_open(dir_class, dirname)
static void
dir_closed()
{
- Fail("closed directory");
+ rb_raise(rb_eIOError, "closed directory");
}
#define GetDIR(obj, dirp) {\
@@ -119,7 +119,7 @@ dir_read(dir)
errno = 0;
dp = readdir(dirp);
if (dp)
- return str_taint(str_new(dp->d_name, NAMLEN(dp)));
+ return rb_str_taint(rb_str_new(dp->d_name, NAMLEN(dp)));
else if (errno == 0) { /* end of stream */
return Qnil;
}
@@ -138,7 +138,7 @@ dir_each(dir)
GetDIR(dir, dirp);
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- file = str_taint(str_new(dp->d_name, NAMLEN(dp)));
+ file = rb_str_taint(rb_str_new(dp->d_name, NAMLEN(dp)));
rb_yield(file);
}
return dir;
@@ -154,7 +154,7 @@ dir_tell(dir)
#if !defined(__CYGWIN32__) && !defined(__BEOS__)
GetDIR(dir, dirp);
pos = telldir(dirp);
- return int2inum(pos);
+ return rb_int2inum(pos);
#else
rb_notimplement();
#endif
@@ -240,7 +240,7 @@ dir_s_getwd(dir)
if (getwd(path) == 0) rb_sys_fail(path);
#endif
- return str_taint(str_new2(path));
+ return rb_str_taint(rb_str_new2(path));
}
static VALUE
@@ -298,7 +298,7 @@ dir_s_rmdir(obj, dir)
if (rmdir(RSTRING(dir)->ptr) < 0)
rb_sys_fail(RSTRING(dir)->ptr);
- return TRUE;
+ return Qtrue;
}
#define isdelim(c) ((c)==' '||(c)=='\t'||(c)=='\n'||(c)=='\0')
@@ -317,7 +317,7 @@ push_globs(ary, s)
if (fnames == (char**)-1) rb_sys_fail(s);
ff = fnames;
while (*ff) {
- ary_push(ary, str_taint(str_new2(*ff)));
+ rb_ary_push(ary, rb_str_taint(rb_str_new2(*ff)));
free(*ff);
ff++;
}
@@ -384,9 +384,10 @@ dir_s_glob(dir, str)
Check_SafeStr(str);
if (RSTRING(str)->len > MAXPATHLEN) {
- ArgError("pathname too long (%d bytes)", RSTRING(str)->len);
+ rb_raise(rb_eArgError, "pathname too long (%d bytes)",
+ RSTRING(str)->len);
}
- ary = ary_new();
+ ary = rb_ary_new();
p = RSTRING(str)->ptr;
pend = p + RSTRING(str)->len;
@@ -422,37 +423,37 @@ dir_foreach(io, dirname)
{
VALUE dir;
- dir = rb_funcall(cDir, rb_intern("open"), 1, dirname);
+ dir = rb_funcall(rb_cDir, rb_intern("open"), 1, dirname);
return rb_ensure(dir_each, dir, dir_close, dir);
}
void
Init_Dir()
{
- cDir = rb_define_class("Dir", cObject);
-
- rb_include_module(cDir, mEnumerable);
-
- rb_define_singleton_method(cDir, "new", dir_s_open, 1);
- rb_define_singleton_method(cDir, "open", dir_s_open, 1);
- rb_define_singleton_method(cDir, "foreach", dir_foreach, 1);
-
- rb_define_method(cDir,"read", dir_read, 0);
- rb_define_method(cDir,"each", dir_each, 0);
- rb_define_method(cDir,"rewind", dir_rewind, 0);
- rb_define_method(cDir,"tell", dir_tell, 0);
- rb_define_method(cDir,"seek", dir_seek, 1);
- rb_define_method(cDir,"close", dir_close, 0);
-
- rb_define_singleton_method(cDir,"chdir", dir_s_chdir, -1);
- rb_define_singleton_method(cDir,"getwd", dir_s_getwd, 0);
- rb_define_singleton_method(cDir,"pwd", dir_s_getwd, 0);
- rb_define_singleton_method(cDir,"chroot", dir_s_chroot, 1);
- rb_define_singleton_method(cDir,"mkdir", dir_s_mkdir, -1);
- rb_define_singleton_method(cDir,"rmdir", dir_s_rmdir, 1);
- rb_define_singleton_method(cDir,"delete", dir_s_rmdir, 1);
- rb_define_singleton_method(cDir,"unlink", dir_s_rmdir, 1);
-
- rb_define_singleton_method(cDir,"glob", dir_s_glob, 1);
- rb_define_singleton_method(cDir,"[]", dir_s_glob, 1);
+ rb_cDir = rb_define_class("Dir", rb_cObject);
+
+ rb_include_module(rb_cDir, rb_mEnumerable);
+
+ rb_define_singleton_method(rb_cDir, "new", dir_s_open, 1);
+ rb_define_singleton_method(rb_cDir, "open", dir_s_open, 1);
+ rb_define_singleton_method(rb_cDir, "foreach", dir_foreach, 1);
+
+ rb_define_method(rb_cDir,"read", dir_read, 0);
+ rb_define_method(rb_cDir,"each", dir_each, 0);
+ rb_define_method(rb_cDir,"rewind", dir_rewind, 0);
+ rb_define_method(rb_cDir,"tell", dir_tell, 0);
+ rb_define_method(rb_cDir,"seek", dir_seek, 1);
+ rb_define_method(rb_cDir,"close", dir_close, 0);
+
+ rb_define_singleton_method(rb_cDir,"chdir", dir_s_chdir, -1);
+ rb_define_singleton_method(rb_cDir,"getwd", dir_s_getwd, 0);
+ rb_define_singleton_method(rb_cDir,"pwd", dir_s_getwd, 0);
+ rb_define_singleton_method(rb_cDir,"chroot", dir_s_chroot, 1);
+ rb_define_singleton_method(rb_cDir,"mkdir", dir_s_mkdir, -1);
+ rb_define_singleton_method(rb_cDir,"rmdir", dir_s_rmdir, 1);
+ rb_define_singleton_method(rb_cDir,"delete", dir_s_rmdir, 1);
+ rb_define_singleton_method(rb_cDir,"unlink", dir_s_rmdir, 1);
+
+ rb_define_singleton_method(rb_cDir,"glob", dir_s_glob, 1);
+ rb_define_singleton_method(rb_cDir,"[]", dir_s_glob, 1);
}
diff --git a/dln.c b/dln.c
index 95d8270..a52b9c6 100644
--- a/dln.c
+++ b/dln.c
@@ -423,7 +423,7 @@ load_text_data(fd, hdrp, bss, disp)
}
static int
-undef_print(key, value)
+underb_f_print(key, value)
char *key, *value;
{
fprintf(stderr, " %s\n", key);
@@ -434,7 +434,7 @@ static void
dln_print_undef()
{
fprintf(stderr, " Undefined symbols:\n");
- st_foreach(undef_tbl, undef_print, NULL);
+ st_foreach(undef_tbl, underb_f_print, NULL);
}
static void
@@ -830,7 +830,7 @@ load_1(fd, disp, need_init)
for (sym = syms; sym<end; sym++) {
char *name = sym->n_un.n_name;
if (name[0] == '_' && sym->n_value >= block) {
- if (strcmp(name+1, "libs_to_be_linked") == 0) {
+ if (strcmp(name+1, "dln_libs_to_be_linked") == 0) {
libs_to_be_linked = (char**)sym->n_value;
}
else if (strcmp(name+1, buf) == 0) {
@@ -885,11 +885,11 @@ search_undef(key, value, lib_tbl)
}
struct symdef {
- int str_index;
+ int rb_str_index;
int lib_offset;
};
-char *dln_library_path = DLN_DEFAULT_LIB_PATH;
+char *dln_librrb_ary_path = DLN_DEFAULT_LIB_PATH;
static int
load_lib(lib)
@@ -920,10 +920,10 @@ load_lib(lib)
/* library search path: */
/* look for environment variable DLN_LIBRARY_PATH first. */
- /* then variable dln_library_path. */
+ /* then variable dln_librrb_ary_path. */
/* if path is still NULL, use "." for path. */
path = getenv("DLN_LIBRARY_PATH");
- if (path == NULL) path = dln_library_path;
+ if (path == NULL) path = dln_librrb_ary_path;
file = dln_find_file(lib, path);
fd = open(file, O_RDONLY);
@@ -952,7 +952,7 @@ load_lib(lib)
base = (struct symdef*)(data + 1);
name_base = (char*)(base + nsym) + sizeof(int);
while (nsym > 0) {
- char *name = name_base + base->str_index;
+ char *name = name_base + base->rb_str_index;
st_insert(lib_tbl, name, base->lib_offset + sizeof(ahdr));
nsym--;
@@ -1186,7 +1186,7 @@ aix_loaderror(char *pathname)
ERRBUF_APPEND("\n");
}
errbuf[strlen(errbuf)-1] = '\0'; /* trim off last newline */
- LoadError(errbuf);
+ rb_loaderror(errbuf);
return;
}
#endif
@@ -1281,14 +1281,14 @@ dln_load(file)
lib = shl_load(file, flags, 0);
if (lib == NULL) {
extern int errno;
- LoadError("%s - %s", strerror(errno), file);
+ rb_loaderror("%s - %s", strerror(errno), file);
}
shl_findsym(&lib, buf, TYPE_PROCEDURE, (void*)&init_fct);
if (init_fct == NULL) {
shl_findsym(&lib, buf, TYPE_UNDEFINED, (void*)&init_fct);
if (init_fct == NULL) {
errno = ENOSYM;
- LoadError("%s - %s", strerror(ENOSYM), file);
+ rb_loaderror("%s - %s", strerror(ENOSYM), file);
}
}
(*init_fct)();
@@ -1331,12 +1331,12 @@ dln_load(file)
/* Load object file, if return value ==0 , load failed*/
if(rld_load(NULL, NULL, object_files, NULL) == 0) {
- LoadError("Failed to load %.200s", file);
+ rb_loaderror("Failed to load %.200s", file);
}
/* lookup the initial function */
if(rld_lookup(NULL, buf, &init_address) == 0) {
- LoadError("Failed to lookup Init function %.200s",file);
+ rb_loaderror("Failed to lookup Init function %.200s", file);
}
/* Cannot call *init_address directory, so copy this value to
@@ -1363,7 +1363,7 @@ dln_load(file)
LoadError("Failed to load %.200s", file);
}
- NSLinkModule(obj_file, file, TRUE);
+ NSLinkModule(obj_file, file, Qtrue);
/* lookup the initial function */
@@ -1394,7 +1394,7 @@ dln_load(file)
/* load extention module */
img_id = load_add_on(file);
if (img_id <= 0) {
- LoadError("Failed to load %.200s", file);
+ rb_loaderror("Failed to load %.200s", file);
}
/* find symbol for module initialize function. */
@@ -1416,12 +1416,12 @@ dln_load(file)
if ((B_BAD_IMAGE_ID == err_stat) || (B_BAD_INDEX == err_stat)) {
unload_add_on(img_id);
- LoadError("Failed to lookup Init function %.200s", file);
+ rb_loaderror("Failed to lookup Init function %.200s", file);
}
else if (B_NO_ERROR != err_stat) {
char errmsg[] = "Internal of BeOS version. %.200s (symbol_name = %s)";
unload_add_on(img_id);
- LoadError(errmsg, strerror(err_stat), buf);
+ rb_loaderror(errmsg, strerror(err_stat), buf);
}
/* call module initialize function. */
@@ -1444,7 +1444,6 @@ dln_load(file)
CFragSymbolClass class;
void (*init_fct)();
char fullpath[MAXPATHLEN];
- extern LoadError();
strcpy(fullpath, file);
@@ -1453,7 +1452,7 @@ dln_load(file)
(void)FSMakeFSSpec(0, 0, fullpath, &libspec);
err = ResolveAliasFile(&libspec, 1, &isfolder, &didsomething);
if ( err ) {
- LoadError("Unresolved Alias - %s", file);
+ rb_loaderror("Unresolved Alias - %s", file);
}
/* Load the fragment (or return the connID if it is already loaded */
@@ -1463,14 +1462,14 @@ dln_load(file)
errMessage);
if ( err ) {
p2cstr(errMessage);
- LoadError("%s - %s",errMessage , file);
+ rb_loaderror("%s - %s",errMessage , file);
}
/* Locate the address of the correct init function */
c2pstr(buf);
err = FindSymbol(connID, buf, &symAddr, &class);
if ( err ) {
- LoadError("Unresolved symbols - %s" , file);
+ rb_loaderror("Unresolved symbols - %s" , file);
}
init_fct = (void (*)())symAddr;
@@ -1487,7 +1486,7 @@ dln_load(file)
#endif
#if !defined(_AIX) && !defined(NeXT)
failed:
- LoadError("%s - %s", dln_strerror(), file);
+ rb_loaderror("%s - %s", dln_strerror(), file);
#endif
}
diff --git a/enum.c b/enum.c
index 4cf490e..ca76d2a 100644
--- a/enum.c
+++ b/enum.c
@@ -12,7 +12,7 @@
#include "ruby.h"
-VALUE mEnumerable;
+VALUE rb_mEnumerable;
static ID id_each, id_eqq, id_cmp;
VALUE
@@ -27,7 +27,7 @@ grep_i(i, arg)
VALUE i, *arg;
{
if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
- ary_push(arg[1], i);
+ rb_ary_push(arg[1], i);
}
return Qnil;
}
@@ -46,14 +46,14 @@ static VALUE
enum_grep(obj, pat)
VALUE obj, pat;
{
- if (iterator_p()) {
+ if (rb_iterator_p()) {
rb_iterate(rb_each, obj, grep_iter_i, pat);
return obj;
}
else {
VALUE tmp, arg[2];
- arg[0] = pat; arg[1] = tmp = ary_new();
+ arg[0] = pat; arg[1] = tmp = rb_ary_new();
rb_iterate(rb_each, obj, grep_i, (VALUE)arg);
return tmp;
@@ -71,7 +71,7 @@ find_i(i, arg)
struct find_arg *arg;
{
if (RTEST(rb_yield(i))) {
- arg->found = TRUE;
+ arg->found = Qtrue;
arg->val = i;
rb_iter_break();
}
@@ -88,7 +88,7 @@ enum_find(argc, argv, obj)
VALUE if_none;
rb_scan_args(argc, argv, "01", &if_none);
- arg.found = FALSE;
+ arg.found = Qfalse;
rb_iterate(rb_each, obj, find_i, (VALUE)&arg);
if (arg.found) {
return arg.val;
@@ -104,7 +104,7 @@ find_all_i(i, tmp)
VALUE i, tmp;
{
if (RTEST(rb_yield(i))) {
- ary_push(tmp, i);
+ rb_ary_push(tmp, i);
}
return Qnil;
}
@@ -115,7 +115,7 @@ enum_find_all(obj)
{
VALUE tmp;
- tmp = ary_new();
+ tmp = rb_ary_new();
rb_iterate(rb_each, obj, find_all_i, tmp);
return tmp;
@@ -125,7 +125,7 @@ static VALUE
collect_i(i, tmp)
VALUE i, tmp;
{
- ary_push(tmp, rb_yield(i));
+ rb_ary_push(tmp, rb_yield(i));
return Qnil;
}
@@ -135,37 +135,17 @@ enum_collect(obj)
{
VALUE tmp;
- tmp = ary_new();
+ tmp = rb_ary_new();
rb_iterate(rb_each, obj, collect_i, tmp);
return tmp;
}
static VALUE
-reverse_i(i, tmp)
- VALUE i, tmp;
-{
- ary_unshift(tmp, i);
- return Qnil;
-}
-
-static VALUE
-enum_reverse(obj)
- VALUE obj;
-{
- VALUE tmp;
-
- tmp = ary_new();
- rb_iterate(rb_each, obj, reverse_i, tmp);
-
- return tmp;
-}
-
-static VALUE
enum_all(i, ary)
VALUE i, ary;
{
- ary_push(ary, i);
+ rb_ary_push(ary, i);
return Qnil;
}
@@ -175,7 +155,7 @@ enum_to_a(obj)
{
VALUE ary;
- ary = ary_new();
+ ary = rb_ary_new();
rb_iterate(rb_each, obj, enum_all, ary);
return ary;
@@ -185,7 +165,7 @@ static VALUE
enum_sort(obj)
VALUE obj;
{
- return ary_sort(enum_to_a(obj));
+ return rb_ary_sort(enum_to_a(obj));
}
static VALUE
@@ -213,7 +193,7 @@ min_ii(i, min)
if (NIL_P(*min))
*min = i;
else {
- cmp = rb_yield(assoc_new(i, *min));
+ cmp = rb_yield(rb_assoc_new(i, *min));
if (FIX2LONG(cmp) < 0)
*min = i;
}
@@ -226,7 +206,7 @@ enum_min(obj)
{
VALUE min = Qnil;
- rb_iterate(rb_each, obj, iterator_p()?min_ii:min_i, (VALUE)&min);
+ rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)&min);
return min;
}
@@ -255,7 +235,7 @@ max_ii(i, max)
if (NIL_P(*max))
*max = i;
else {
- cmp = rb_yield(assoc_new(i, *max));
+ cmp = rb_yield(rb_assoc_new(i, *max));
if (FIX2LONG(cmp) > 0)
*max = i;
}
@@ -268,7 +248,7 @@ enum_max(obj)
{
VALUE max = Qnil;
- rb_iterate(rb_each, obj, iterator_p()?max_ii:max_i, (VALUE)&max);
+ rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)&max);
return max;
}
@@ -328,8 +308,8 @@ enum_member(obj, val)
iv.i = 0;
iv.v = val;
rb_iterate(rb_each, obj, member_i, (VALUE)&iv);
- if (iv.i) return TRUE;
- return FALSE;
+ if (iv.i) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -341,7 +321,7 @@ length_i(i, length)
return Qnil;
}
-VALUE
+static VALUE
enum_length(obj)
VALUE obj;
{
@@ -351,17 +331,24 @@ enum_length(obj)
return INT2FIX(length);
}
+VALUE
+rb_enum_length(obj)
+ VALUE obj;
+{
+ return enum_length(obj);
+}
+
static VALUE
each_with_index_i(val, indexp)
VALUE val;
int *indexp;
{
- rb_yield(assoc_new(val, INT2FIX(*indexp)));
+ rb_yield(rb_assoc_new(val, INT2FIX(*indexp)));
(*indexp)++;
return Qnil;
}
-VALUE
+static VALUE
enum_each_with_index(obj)
VALUE obj;
{
@@ -374,24 +361,23 @@ enum_each_with_index(obj)
void
Init_Enumerable()
{
- mEnumerable = rb_define_module("Enumerable");
-
- rb_define_method(mEnumerable,"to_a", enum_to_a, 0);
-
- rb_define_method(mEnumerable,"sort", enum_sort, 0);
- rb_define_method(mEnumerable,"grep", enum_grep, 1);
- rb_define_method(mEnumerable,"find", enum_find, -1);
- rb_define_method(mEnumerable,"find_all", enum_find_all, 0);
- rb_define_method(mEnumerable,"collect", enum_collect, 0);
- rb_define_method(mEnumerable,"reverse", enum_reverse, 0);
- rb_define_method(mEnumerable,"min", enum_min, 0);
- rb_define_method(mEnumerable,"max", enum_max, 0);
- rb_define_method(mEnumerable,"index", enum_index, 1);
- rb_define_method(mEnumerable,"member?", enum_member, 1);
- rb_define_method(mEnumerable,"include?", enum_member, 1);
- rb_define_method(mEnumerable,"length", enum_length, 0);
- rb_define_method(mEnumerable,"size", enum_length, 0);
- rb_define_method(mEnumerable,"each_with_index", enum_each_with_index, 0);
+ rb_mEnumerable = rb_define_module("Enumerable");
+
+ rb_define_method(rb_mEnumerable,"to_a", enum_to_a, 0);
+
+ rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
+ rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
+ rb_define_method(rb_mEnumerable,"find", enum_find, -1);
+ rb_define_method(rb_mEnumerable,"find_all", enum_find_all, 0);
+ rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
+ rb_define_method(rb_mEnumerable,"min", enum_min, 0);
+ rb_define_method(rb_mEnumerable,"max", enum_max, 0);
+ rb_define_method(rb_mEnumerable,"index", enum_index, 1);
+ rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
+ rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
+ rb_define_method(rb_mEnumerable,"length", enum_length, 0);
+ rb_define_method(rb_mEnumerable,"size", enum_length, 0);
+ rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);
id_eqq = rb_intern("===");
id_each = rb_intern("each");
diff --git a/env.h b/env.h
index b254dde..79fdfc2 100644
--- a/env.h
+++ b/env.h
@@ -22,16 +22,16 @@ extern struct FRAME {
char *file;
int line;
int iter;
-} *the_frame;
+} *ruby_frame;
-void gc_mark_frame _((struct FRAME *));
+void rb_gc_mark_frame _((struct FRAME *));
extern struct SCOPE {
struct RBasic super;
ID *local_tbl;
VALUE *local_vars;
int flag;
-} *the_scope;
+} *ruby_scope;
#define SCOPE_ALLOCA 0
#define SCOPE_MALLOC 1
@@ -39,7 +39,7 @@ extern struct SCOPE {
extern int rb_in_eval;
-extern VALUE the_class;
+extern VALUE ruby_class;
struct RVarmap {
struct RBasic super;
@@ -47,6 +47,6 @@ struct RVarmap {
VALUE val;
struct RVarmap *next;
};
-extern struct RVarmap *the_dyna_vars;
+extern struct RVarmap *ruby_dyna_vars;
#endif /* ENV_H */
diff --git a/error.c b/error.c
index 564358c..a7f8ac8 100644
--- a/error.c
+++ b/error.c
@@ -26,10 +26,7 @@
int sys_nerr = 256;
#endif
-extern char *sourcefile;
-extern int sourceline;
-
-int nerrs;
+int ruby_nerrs;
static void
err_snprintf(buf, len, fmt, args)
@@ -37,11 +34,11 @@ err_snprintf(buf, len, fmt, args)
int len;
va_list args;
{
- if (!sourcefile) {
+ if (!ruby_sourcefile) {
vsnprintf(buf, len, fmt, args);
}
else {
- int n = snprintf(buf, len, "%s:%d: ", sourcefile, sourceline);
+ int n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
if (len > n) {
vsnprintf((char*)buf+n, len-n, fmt, args);
}
@@ -62,9 +59,9 @@ err_print(fmt, args)
void
#ifdef HAVE_STDARG_PROTOTYPES
-Error(char *fmt, ...)
+rb_compile_error(char *fmt, ...)
#else
-Error(fmt, va_alist)
+rb_compile_error(fmt, va_alist)
char *fmt;
va_dcl
#endif
@@ -74,14 +71,14 @@ Error(fmt, va_alist)
va_init_list(args, fmt);
err_print(fmt, args);
va_end(args);
- nerrs++;
+ ruby_nerrs++;
}
void
#ifdef HAVE_STDARG_PROTOTYPES
-Error_Append(char *fmt, ...)
+rb_compile_error_append(char *fmt, ...)
#else
-Error_Append(fmt, va_alist)
+rb_compile_error_append(fmt, va_alist)
char *fmt;
va_dcl
#endif
@@ -97,9 +94,9 @@ Error_Append(fmt, va_alist)
void
#ifdef HAVE_STDARG_PROTOTYPES
-Warn(char *fmt, ...)
+rb_warn(char *fmt, ...)
#else
-Warn(fmt, va_alist)
+rb_warn(fmt, va_alist)
char *fmt;
va_dcl
#endif
@@ -114,12 +111,12 @@ Warn(fmt, va_alist)
va_end(args);
}
-/* Warning() reports only in verbose mode */
+/* rb_warning() reports only in verbose mode */
void
#ifdef HAVE_STDARG_PROTOTYPES
-Warning(char *fmt, ...)
+rb_warning(char *fmt, ...)
#else
-Warning(fmt, va_alist)
+rb_warning(fmt, va_alist)
char *fmt;
va_dcl
#endif
@@ -127,7 +124,7 @@ Warning(fmt, va_alist)
char buf[BUFSIZ];
va_list args;
- if (!RTEST(verbose)) return;
+ if (!RTEST(rb_verbose)) return;
snprintf(buf, BUFSIZ, "warning: %s", fmt);
@@ -138,9 +135,9 @@ Warning(fmt, va_alist)
void
#ifdef HAVE_STDARG_PROTOTYPES
-Bug(char *fmt, ...)
+rb_bug(char *fmt, ...)
#else
-Bug(fmt, va_alist)
+rb_bug(fmt, va_alist)
char *fmt;
va_dcl
#endif
@@ -205,68 +202,68 @@ rb_check_type(x, t)
etype = "Fixnum";
}
else if (rb_special_const_p(x)) {
- etype = RSTRING(obj_as_string(x))->ptr;
+ etype = RSTRING(rb_obj_as_string(x))->ptr;
}
else {
etype = rb_class2name(CLASS_OF(x));
}
- TypeError("wrong argument type %s (expected %s)",
- etype, type->name);
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
+ etype, type->name);
}
type++;
}
- Bug("unknown type 0x%x", t);
+ rb_bug("unknown type 0x%x", t);
}
}
/* exception classes */
#include <errno.h>
-VALUE eException;
-VALUE eSystemExit, eInterrupt, eFatal;
-VALUE eStandardError;
-VALUE eRuntimeError;
-VALUE eSyntaxError;
-VALUE eTypeError;
-VALUE eArgError;
-VALUE eNameError;
-VALUE eIndexError;
-VALUE eLoadError;
-VALUE eSecurityError;
-VALUE eNotImpError;
-
-VALUE eSystemCallError;
-VALUE mErrno;
+VALUE rb_eException;
+VALUE rb_eSystemExit, rb_eInterrupt, rb_eFatal;
+VALUE rb_eStandardError;
+VALUE rb_eRuntimeError;
+VALUE rb_eSyntaxError;
+VALUE rb_eTypeError;
+VALUE rb_eArgError;
+VALUE rb_eNameError;
+VALUE rb_eIndexError;
+VALUE rb_eLoadError;
+VALUE rb_eSecurityError;
+VALUE rb_eNotImpError;
+
+VALUE rb_eSystemCallError;
+VALUE rb_mErrno;
VALUE
-exc_new(etype, ptr, len)
+rb_exc_new(etype, ptr, len)
VALUE etype;
char *ptr;
unsigned len;
{
- VALUE exc = obj_alloc(etype);
+ VALUE exc = rb_obj_alloc(etype);
- rb_iv_set(exc, "mesg", str_new(ptr, len));
+ rb_iv_set(exc, "mesg", rb_str_new(ptr, len));
return exc;
}
VALUE
-exc_new2(etype, s)
+rb_exc_new2(etype, s)
VALUE etype;
char *s;
{
- return exc_new(etype, s, strlen(s));
+ return rb_exc_new(etype, s, strlen(s));
}
VALUE
-exc_new3(etype, str)
+rb_exc_new3(etype, str)
VALUE etype, str;
{
char *s;
int len;
s = str2cstr(str, &len);
- return exc_new(etype, s, len);
+ return rb_exc_new(etype, s, len);
}
static VALUE
@@ -278,7 +275,7 @@ exc_initialize(argc, argv, exc)
VALUE mesg;
if (rb_scan_args(argc, argv, "01", &mesg) == 0) {
- mesg = str_new(0, 0);
+ mesg = rb_str_new(0, 0);
}
else {
STR2CSTR(mesg); /* ensure mesg can be converted to String */
@@ -289,7 +286,7 @@ exc_initialize(argc, argv, exc)
}
static VALUE
-exc_new_method(argc, argv, self)
+exc_new(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
@@ -301,8 +298,8 @@ exc_new_method(argc, argv, self)
while (FL_TEST(etype, FL_SINGLETON)) {
etype = RCLASS(etype)->super;
}
- exc = obj_alloc(etype);
- obj_call_init(exc);
+ exc = rb_obj_alloc(etype);
+ rb_obj_call_init(exc);
return exc;
}
@@ -321,17 +318,17 @@ exc_inspect(exc)
VALUE str, klass;
klass = CLASS_OF(exc);
- exc = obj_as_string(exc);
+ exc = rb_obj_as_string(exc);
if (RSTRING(exc)->len == 0) {
- return str_dup(rb_class_path(klass));
+ return rb_str_dup(rb_class_path(klass));
}
- str = str_new2("#<");
+ str = rb_str_new2("#<");
klass = rb_class_path(klass);
- str_concat(str, klass);
- str_cat(str, ":", 1);
- str_concat(str, exc);
- str_cat(str, ">", 1);
+ rb_str_concat(str, klass);
+ rb_str_cat(str, ":", 1);
+ rb_str_concat(str, exc);
+ rb_str_cat(str, ">", 1);
return str;
}
@@ -353,13 +350,13 @@ check_backtrace(bt)
if (!NIL_P(bt)) {
int t = TYPE(bt);
- if (t == T_STRING) return ary_new3(1, bt);
+ if (t == T_STRING) return rb_ary_new3(1, bt);
if (t != T_ARRAY) {
- TypeError(err);
+ rb_raise(rb_eTypeError, err);
}
for (i=0;i<RARRAY(bt)->len;i++) {
if (TYPE(RARRAY(bt)->ptr[i]) != T_STRING) {
- TypeError(err);
+ rb_raise(rb_eTypeError, err);
}
}
}
@@ -379,34 +376,35 @@ exception(argc, argv)
VALUE *argv;
{
VALUE v = Qnil;
- VALUE etype = eStandardError;
+ VALUE etype = rb_eStandardError;
int i;
ID id;
if (argc == 0) {
- ArgError("wrong # of arguments");
+ rb_raise(rb_eArgError, "wrong # of arguments");
}
- Warn("Exception() is now obsolete");
+ rb_warn("Exception() is now obsolete");
if (TYPE(argv[argc-1]) == T_CLASS) {
etype = argv[argc-1];
argc--;
- if (!rb_funcall(etype, '<', 1, eException)) {
- TypeError("exception should be subclass of Exception");
+ if (!rb_funcall(etype, '<', 1, rb_eException)) {
+ rb_raise(rb_eTypeError, "exception should be subclass of Exception");
}
}
for (i=0; i<argc; i++) { /* argument check */
id = rb_to_id(argv[i]);
if (!rb_id2name(id)) {
- ArgError("argument needs to be symbol or string");
+ rb_raise(rb_eArgError, "argument needs to be symbol or string");
}
if (!rb_is_const_id(id)) {
- ArgError("identifier `%s' needs to be constant", rb_id2name(id));
+ rb_raise(rb_eArgError, "identifier `%s' needs to be constant",
+ rb_id2name(id));
}
}
for (i=0; i<argc; i++) {
- v = rb_define_class_under(the_class,
+ v = rb_define_class_under(ruby_class,
rb_id2name(rb_to_id(argv[i])),
- eStandardError);
+ rb_eStandardError);
}
return v;
}
@@ -479,7 +477,7 @@ set_syserr(i, name)
VALUE *list;
int ix, offset;
#endif
- VALUE error = rb_define_class_under(mErrno, name, eSystemCallError);
+ VALUE error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
rb_define_const(error, "Errno", INT2FIX(i));
#ifdef __BEOS__
i -= B_GENERAL_ERROR_BASE;
@@ -534,144 +532,87 @@ static void init_syserr _((void));
void
Init_Exception()
{
- eException = rb_define_class("Exception", cObject);
- rb_define_method(eException, "new", exc_new_method, -1);
- rb_define_method(eException, "initialize", exc_initialize, -1);
- rb_define_method(eException, "to_s", exc_to_s, 0);
- rb_define_method(eException, "to_str", exc_to_s, 0);
- rb_define_method(eException, "message", exc_to_s, 0);
- rb_define_method(eException, "inspect", exc_inspect, 0);
- rb_define_method(eException, "backtrace", exc_backtrace, 0);
- rb_define_method(eException, "set_backtrace", exc_set_backtrace, 1);
-
- eSystemExit = rb_define_class("SystemExit", eException);
- eFatal = rb_define_class("fatal", eException);
- eInterrupt = rb_define_class("Interrupt", eException);
-
- eStandardError = rb_define_class("StandardError", eException);
- eSyntaxError = rb_define_class("SyntaxError", eStandardError);
- eTypeError = rb_define_class("TypeError", eStandardError);
- eArgError = rb_define_class("ArgumentError", eStandardError);
- eNameError = rb_define_class("NameError", eStandardError);
- eIndexError = rb_define_class("IndexError", eStandardError);
- eLoadError = rb_define_class("LoadError", eStandardError);
-
- eRuntimeError = rb_define_class("RuntimeError", eStandardError);
- eSecurityError = rb_define_class("SecurityError", eStandardError);
- eNotImpError = rb_define_class("NotImplementError", eException);
+ rb_eException = rb_define_class("Exception", rb_cObject);
+ rb_define_method(rb_eException, "new", exc_new, -1);
+ rb_define_method(rb_eException, "initialize", exc_initialize, -1);
+ rb_define_method(rb_eException, "to_s", exc_to_s, 0);
+ rb_define_method(rb_eException, "to_str", exc_to_s, 0);
+ rb_define_method(rb_eException, "message", exc_to_s, 0);
+ rb_define_method(rb_eException, "inspect", exc_inspect, 0);
+ rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
+ rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
+
+ rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
+ rb_eFatal = rb_define_class("fatal", rb_eException);
+ rb_eInterrupt = rb_define_class("Interrupt", rb_eException);
+
+ rb_eStandardError = rb_define_class("StandardError", rb_eException);
+ rb_eSyntaxError = rb_define_class("SyntaxError", rb_eStandardError);
+ rb_eTypeError = rb_define_class("TypeError", rb_eStandardError);
+ rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
+ rb_eNameError = rb_define_class("NameError", rb_eStandardError);
+ rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
+ rb_eLoadError = rb_define_class("LoadError", rb_eStandardError);
+
+ rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
+ rb_eSecurityError = rb_define_class("SecurityError", rb_eStandardError);
+ rb_eNotImpError = rb_define_class("NotImplementError", rb_eException);
init_syserr();
rb_define_global_function("Exception", exception, -1);
}
-#define RAISE_ERROR(klass,fmt) {\
- va_list args;\
- char buf[BUFSIZ];\
- va_init_list(args,fmt);\
- vsnprintf(buf, BUFSIZ, fmt, args);\
- va_end(args);\
- rb_raise(exc_new2(klass, buf));\
-}
-
void
#ifdef HAVE_STDARG_PROTOTYPES
-Raise(VALUE exc, char *fmt, ...)
+rb_raise(VALUE exc, char *fmt, ...)
#else
-Raise(exc, fmt, va_alist)
+rb_raise(exc, fmt, va_alist)
VALUE exc;
char *fmt;
va_dcl
#endif
{
- RAISE_ERROR(exc, fmt);
-}
-
-void
-#ifdef HAVE_STDARG_PROTOTYPES
-TypeError(char *fmt, ...)
-#else
-TypeError(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- RAISE_ERROR(eTypeError, fmt);
-}
-
-void
-#ifdef HAVE_STDARG_PROTOTYPES
-ArgError(char *fmt, ...)
-#else
-ArgError(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- RAISE_ERROR(eArgError, fmt);
-}
+ va_list args;
+ char buf[BUFSIZ];
-void
-#ifdef HAVE_STDARG_PROTOTYPES
-NameError(char *fmt, ...)
-#else
-NameError(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- RAISE_ERROR(eNameError, fmt);
+ va_init_list(args,fmt);
+ vsnprintf(buf, BUFSIZ, fmt, args);
+ va_end(args);
+ rb_exc_raise(rb_exc_new2(exc, buf));
}
void
#ifdef HAVE_STDARG_PROTOTYPES
-IndexError(char *fmt, ...)
+rb_loaderror(char *fmt, ...)
#else
-IndexError(fmt, va_alist)
+rb_loaderror(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
- RAISE_ERROR(eIndexError, fmt);
-}
+ va_list args;
+ char buf[BUFSIZ];
-void
-#ifdef HAVE_STDARG_PROTOTYPES
-Fail(char *fmt, ...)
-#else
-Fail(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- RAISE_ERROR(eRuntimeError, fmt);
+ va_init_list(args, fmt);
+ vsnprintf(buf, BUFSIZ, fmt, args);
+ va_end(args);
+ rb_exc_raise(rb_exc_new2(rb_eLoadError, buf));
}
void
rb_notimplement()
{
- Raise(eNotImpError,
- "The %s() function is unimplemented on this machine",
- rb_id2name(the_frame->last_func));
-}
-
-void
-#ifdef HAVE_STDARG_PROTOTYPES
-LoadError(char *fmt, ...)
-#else
-LoadError(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- RAISE_ERROR(eLoadError, fmt);
+ rb_raise(rb_eNotImpError,
+ "The %s() function is unimplemented on this machine",
+ rb_id2name(ruby_frame->last_func));
}
void
#ifdef HAVE_STDARG_PROTOTYPES
-Fatal(char *fmt, ...)
+rb_fatal(char *fmt, ...)
#else
-Fatal(fmt, va_alist)
+rb_fatal(fmt, va_alist)
char *fmt;
va_dcl
#endif
@@ -684,7 +625,7 @@ Fatal(fmt, va_alist)
va_end(args);
rb_in_eval = 0;
- rb_fatal(exc_new2(eFatal, buf));
+ rb_exc_fatal(rb_exc_new2(rb_eFatal, buf));
}
void
@@ -702,7 +643,7 @@ rb_sys_fail(mesg)
err = strerror(errno);
if (mesg) {
- buf = ALLOCA_N(char, strlen(err)+strlen(mesg)+1);
+ buf = ALLOCA_N(char, strlen(err)+strlen(mesg)+4);
sprintf(buf, "%s - %s", err, mesg);
}
else {
@@ -740,10 +681,10 @@ rb_sys_fail(mesg)
else {
ee = syserr_list[n];
}
- ee = exc_new2(ee, buf);
+ ee = rb_exc_new2(ee, buf);
#endif
rb_iv_set(ee, "errno", INT2FIX(n));
- rb_raise(ee);
+ rb_exc_raise(ee);
}
static void
@@ -752,10 +693,10 @@ init_syserr()
#ifdef __BEOS__
int i, ix, offset;
#endif
- eSystemCallError = rb_define_class("SystemCallError", eStandardError);
- rb_define_method(eSystemCallError, "errno", syserr_errno, 0);
+ rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
+ rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
- mErrno = rb_define_module("Errno");
+ rb_mErrno = rb_define_module("Errno");
#ifdef __BEOS__
for (i = 0; syserr_index[i].n != 0; i++) {
ix = syserr_index[i].ix;
@@ -1140,18 +1081,18 @@ static void
err_append(s)
char *s;
{
- extern VALUE errinfo;
+ extern VALUE rb_errinfo;
if (rb_in_eval) {
- if (NIL_P(errinfo)) {
- errinfo = exc_new2(eSyntaxError, s);
+ if (NIL_P(rb_errinfo)) {
+ rb_errinfo = rb_exc_new2(rb_eSyntaxError, s);
}
else {
- VALUE str = str_to_str(errinfo);
+ VALUE str = rb_str_to_str(rb_errinfo);
- str_cat(str, "\n", 1);
- str_cat(str, s, strlen(s));
- errinfo = exc_new3(eSyntaxError, str);
+ rb_str_cat(str, "\n", 1);
+ rb_str_cat(str, s, strlen(s));
+ rb_errinfo = rb_exc_new3(rb_eSyntaxError, str);
}
}
else {
diff --git a/eval.c b/eval.c
index 7697213..c0a69bf 100644
--- a/eval.c
+++ b/eval.c
@@ -51,14 +51,14 @@ char *strrchr _((char*,char));
#define RUBY_LIB_SEP ":"
#endif
-VALUE cProc;
-static VALUE cBinding;
+VALUE rb_cProc;
+static VALUE rb_cBinding;
static VALUE proc_call _((VALUE,VALUE));
-static VALUE f_binding _((VALUE));
-static void f_END _((void));
-static VALUE f_iterator_p _((void));
+static VALUE rb_f_binding _((VALUE));
+static void rb_f_END _((void));
+static VALUE rb_f_iterator_p _((void));
static VALUE block_pass _((VALUE,NODE*));
-static VALUE cMethod;
+static VALUE rb_cMethod;
static VALUE method_proc _((VALUE));
static int scope_vmode;
@@ -121,7 +121,7 @@ rb_add_method(klass, mid, node, noex)
{
NODE *body;
- if (NIL_P(klass)) klass = cObject;
+ if (NIL_P(klass)) klass = rb_cObject;
body = NEW_METHOD(node, noex);
st_insert(RCLASS(klass)->m_tbl, mid, body);
}
@@ -194,12 +194,12 @@ rb_alias(klass, name, def)
orig = search_method(klass, def, &origin);
if (!orig || !orig->nd_body) {
if (TYPE(klass) == T_MODULE) {
- orig = search_method(cObject, def, &origin);
+ orig = search_method(rb_cObject, def, &origin);
}
}
if (!orig || !orig->nd_body) {
- NameError("undefined method `%s' for `%s'",
- rb_id2name(def), rb_class2name(klass));
+ rb_raise(rb_eNameError, "undefined method `%s' for `%s'",
+ rb_id2name(def), rb_class2name(klass));
}
body = orig->nd_body;
if (nd_type(body) == NODE_FBODY) { /* was alias */
@@ -220,8 +220,8 @@ remove_method(klass, mid)
NODE *body;
if (!st_delete(RCLASS(klass)->m_tbl, &mid, &body)) {
- NameError("method `%s' not defined in %s",
- rb_id2name(mid), rb_class2name(klass));
+ rb_raise(rb_eNameError, "method `%s' not defined in %s",
+ rb_id2name(mid), rb_class2name(klass));
}
rb_clear_cache_by_id(mid);
}
@@ -245,15 +245,15 @@ rb_disable_super(klass, name)
body = search_method(klass, mid, &origin);
if (!body || !body->nd_body) {
- NameError("undefined method `%s' for `%s'",
- rb_id2name(mid), rb_class2name(klass));
+ rb_raise(rb_eNameError, "undefined method `%s' for `%s'",
+ rb_id2name(mid), rb_class2name(klass));
}
if (origin == klass) {
body->nd_noex |= NOEX_UNDEF;
}
else {
rb_clear_cache_by_id(mid);
- rb_add_method(the_class, mid, 0, NOEX_UNDEF);
+ rb_add_method(ruby_class, mid, 0, NOEX_UNDEF);
}
}
@@ -268,8 +268,8 @@ rb_enable_super(klass, name)
body = search_method(klass, mid, &origin);
if (!body || !body->nd_body || origin != klass) {
- NameError("undefined method `%s' for `%s'",
- rb_id2name(mid), rb_class2name(klass));
+ rb_raise(rb_eNameError, "undefined method `%s' for `%s'",
+ rb_id2name(mid), rb_class2name(klass));
}
body->nd_noex &= ~NOEX_UNDEF;
}
@@ -285,11 +285,11 @@ rb_export_method(klass, name, noex)
body = search_method(klass, name, &origin);
if (!body && TYPE(klass) == T_MODULE) {
- body = search_method(cObject, name, &origin);
+ body = search_method(rb_cObject, name, &origin);
}
if (!body) {
- NameError("undefined method `%s' for `%s'",
- rb_id2name(name), rb_class2name(klass));
+ rb_raise(rb_eNameError, "undefined method `%s' for `%s'",
+ rb_id2name(name), rb_class2name(klass));
}
if (body->nd_noex != noex) {
if (klass == origin) {
@@ -312,10 +312,10 @@ rb_method_boundp(klass, id, ex)
if (rb_get_method_body(&klass, &id, &noex)) {
if (ex && noex & NOEX_PRIVATE)
- return FALSE;
- return TRUE;
+ return Qfalse;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
void
@@ -333,7 +333,7 @@ rb_attr(klass, id, read, write, ex)
else {
if (SCOPE_TEST(SCOPE_PRIVATE)) {
noex = NOEX_PRIVATE;
- Warning("private attribute?");
+ rb_warning("private attribute?");
}
else if (SCOPE_TEST(SCOPE_PROTECTED)) {
noex = NOEX_PROTECTED;
@@ -345,7 +345,7 @@ rb_attr(klass, id, read, write, ex)
name = rb_id2name(id);
if (!name) {
- ArgError("argument needs to be symbol or string");
+ rb_raise(rb_eArgError, "argument needs to be symbol or string");
}
buf = ALLOCA_N(char,strlen(name)+2);
sprintf(buf, "@%s", name);
@@ -361,31 +361,31 @@ rb_attr(klass, id, read, write, ex)
}
static ID init, eqq, each, aref, aset, match;
-VALUE errinfo = Qnil;
-extern NODE *eval_tree_begin;
-extern NODE *eval_tree;
-extern int nerrs;
+VALUE rb_errinfo = Qnil;
+extern NODE *ruby_eval_tree_begin;
+extern NODE *ruby_eval_tree;
+extern int ruby_nerrs;
-static VALUE eLocalJumpError;
-static VALUE eSysStackError;
+static VALUE rb_eLocalJumpError;
+static VALUE rb_eSysStackError;
-extern VALUE TopSelf;
+extern VALUE rb_top_self;
-struct FRAME *the_frame;
-struct SCOPE *the_scope;
+struct FRAME *ruby_frame;
+struct SCOPE *ruby_scope;
static struct FRAME *top_frame;
static struct SCOPE *top_scope;
#define PUSH_FRAME() { \
struct FRAME _frame; \
- _frame.prev = the_frame; \
- _frame.file = sourcefile; \
- _frame.line = sourceline; \
- _frame.iter = the_iter->iter; \
- _frame.cbase = the_frame->cbase; \
- the_frame = &_frame; \
+ _frame.prev = ruby_frame; \
+ _frame.file = ruby_sourcefile; \
+ _frame.line = ruby_sourceline; \
+ _frame.iter = ruby_iter->iter; \
+ _frame.cbase = ruby_frame->cbase; \
+ ruby_frame = &_frame; \
-#define POP_FRAME() the_frame = _frame.prev; }
+#define POP_FRAME() ruby_frame = _frame.prev; }
struct BLOCK {
NODE *var;
@@ -403,7 +403,8 @@ struct BLOCK {
#endif
struct BLOCK *prev;
};
-static struct BLOCK *the_block;
+static struct BLOCK *ruby_block;
+static struct BLOCK *ruby_calling_block;
#define PUSH_BLOCK(v,b) { \
struct BLOCK _block; \
@@ -411,35 +412,42 @@ static struct BLOCK *the_block;
_block.var = v; \
_block.body = b; \
_block.self = self; \
- _block.frame = *the_frame; \
- _block.klass = the_class; \
- _block.frame.file = sourcefile; \
- _block.frame.line = sourceline; \
- _block.scope = the_scope; \
- _block.d_vars = the_dyna_vars; \
- _block.prev = the_block; \
- _block.iter = the_iter->iter; \
+ _block.frame = *ruby_frame; \
+ _block.klass = ruby_class; \
+ _block.frame.file = ruby_sourcefile; \
+ _block.frame.line = ruby_sourceline; \
+ _block.scope = ruby_scope; \
+ _block.d_vars = ruby_dyna_vars; \
+ _block.prev = ruby_block; \
+ _block.iter = ruby_iter->iter; \
_block.vmode = scope_vmode; \
- the_block = &_block;
+ ruby_block = &_block;
+
+#define POP_BLOCK() \
+ ruby_block = _block.prev; \
+}
#define PUSH_BLOCK2(b) { \
- struct BLOCK _block; \
- _block = *b; \
- _block.prev = the_block; \
- the_block = &_block;
+ struct BLOCK * volatile _old; \
+ struct BLOCK * volatile _old_call; \
+ _old = ruby_block; \
+ _old_call = ruby_calling_block; \
+ ruby_calling_block = b; \
+ ruby_block = b;
-#define POP_BLOCK() \
- the_block = _block.prev; \
+#define POP_BLOCK2() \
+ ruby_calling_block = _old_call; \
+ ruby_block = _old; \
}
-struct RVarmap *the_dyna_vars;
+struct RVarmap *ruby_dyna_vars;
#define PUSH_VARS() { \
struct RVarmap * volatile _old; \
- _old = the_dyna_vars; \
- the_dyna_vars = 0;
+ _old = ruby_dyna_vars; \
+ ruby_dyna_vars = 0;
#define POP_VARS() \
- the_dyna_vars = _old; \
+ ruby_dyna_vars = _old; \
}
static struct RVarmap*
@@ -451,37 +459,29 @@ new_dvar(id, value)
OBJSETUP(vars, 0, T_VARMAP);
vars->id = id;
vars->val = value;
- vars->next = the_dyna_vars;
+ vars->next = ruby_dyna_vars;
return vars;
}
-static void
-mark_dvar(vars)
- struct RVarmap *vars;
-{
- the_dyna_vars = new_dvar(0, 0);
- the_dyna_vars->next = vars;
-}
-
VALUE
-dyna_var_defined(id)
+rb_dvar_defined(id)
ID id;
{
- struct RVarmap *vars = the_dyna_vars;
+ struct RVarmap *vars = ruby_dyna_vars;
while (vars) {
- if (vars->id == id) return TRUE;
+ if (vars->id == id) return Qtrue;
vars = vars->next;
}
- return FALSE;
+ return Qfalse;
}
VALUE
-dyna_var_ref(id)
+rb_dvar_ref(id)
ID id;
{
- struct RVarmap *vars = the_dyna_vars;
+ struct RVarmap *vars = ruby_dyna_vars;
while (vars) {
if (vars->id == id) {
@@ -493,29 +493,29 @@ dyna_var_ref(id)
}
void
-dyna_var_push(id, value)
+rb_dvar_push(id, value)
ID id;
VALUE value;
{
- the_dyna_vars = new_dvar(id, value);
+ ruby_dyna_vars = new_dvar(id, value);
}
-VALUE
-dyna_var_asgn(id, value)
+void
+rb_dvar_asgn(id, value)
ID id;
VALUE value;
{
- struct RVarmap *vars = the_dyna_vars;
+ struct RVarmap *vars = ruby_dyna_vars;
while (vars) {
if (vars->id == id) {
vars->val = value;
- return value;
+ return;
}
vars = vars->next;
}
- dyna_var_push(id, value);
- return value;
+ rb_dvar_push(id, value);
+ return;
}
static void
@@ -523,14 +523,9 @@ dvar_asgn_push(id, value)
ID id;
VALUE value;
{
- if (the_dyna_vars && the_dyna_vars->id == 0) {
- struct RVarmap* vars = new_dvar(id, value);
-
- vars->next = the_dyna_vars->next;
- the_dyna_vars->next = vars;
- }
- else {
- dyna_var_push(id, value);
+ rb_dvar_push(id, value);
+ if (ruby_calling_block) {
+ ruby_calling_block->d_vars = ruby_dyna_vars;
}
}
@@ -538,7 +533,7 @@ struct iter {
int iter;
struct iter *prev;
};
-static struct iter *the_iter;
+static struct iter *ruby_iter;
#define ITER_NOT 0
#define ITER_PRE 1
@@ -546,12 +541,12 @@ static struct iter *the_iter;
#define PUSH_ITER(i) { \
struct iter _iter; \
- _iter.prev = the_iter; \
+ _iter.prev = ruby_iter; \
_iter.iter = (i); \
- the_iter = &_iter; \
+ ruby_iter = &_iter; \
#define POP_ITER() \
- the_iter = _iter.prev; \
+ ruby_iter = _iter.prev; \
}
struct tag {
@@ -568,8 +563,8 @@ static struct tag *prot_tag;
#define PUSH_TAG(ptag) { \
struct tag _tag; \
_tag.retval = Qnil; \
- _tag.frame = the_frame; \
- _tag.iter = the_iter; \
+ _tag.frame = ruby_frame; \
+ _tag.iter = ruby_iter; \
_tag.prev = prot_tag; \
_tag.retval = Qnil; \
_tag.tag = ptag; \
@@ -583,8 +578,8 @@ static struct tag *prot_tag;
#define EXEC_TAG() setjmp(prot_tag->buf)
#define JUMP_TAG(st) { \
- the_frame = prot_tag->frame; \
- the_iter = prot_tag->iter; \
+ ruby_frame = prot_tag->frame; \
+ ruby_iter = prot_tag->iter; \
longjmp(prot_tag->buf,(st)); \
}
@@ -604,12 +599,12 @@ static struct tag *prot_tag;
#define TAG_FATAL 0x8
#define TAG_MASK 0xf
-VALUE the_class;
+VALUE ruby_class;
#define PUSH_CLASS() { \
- VALUE _class = the_class; \
+ VALUE _class = ruby_class; \
-#define POP_CLASS() the_class = _class; }
+#define POP_CLASS() ruby_class = _class; }
#define PUSH_SCOPE() { \
int volatile _vmode = scope_vmode; \
@@ -619,30 +614,31 @@ VALUE the_class;
_scope->local_tbl = 0; \
_scope->local_vars = 0; \
_scope->flag = 0; \
- _old = the_scope; \
- the_scope = _scope; \
+ _old = ruby_scope; \
+ ruby_scope = _scope; \
scope_vmode = SCOPE_PUBLIC;
#define POP_SCOPE() \
- if (the_scope->flag == SCOPE_ALLOCA) {\
- the_scope->local_vars = 0;\
- the_scope->local_tbl = 0;\
- if (the_scope != top_scope)\
- gc_force_recycle(the_scope);\
+ if (ruby_scope->flag == SCOPE_ALLOCA) {\
+ ruby_scope->local_vars = 0;\
+ ruby_scope->local_tbl = 0;\
+ if (ruby_scope != top_scope)\
+ rb_gc_force_recycle(ruby_scope);\
}\
else {\
- the_scope->flag |= SCOPE_NOSTACK;\
+ ruby_scope->flag |= SCOPE_NOSTACK;\
}\
- the_scope = _old;\
+ ruby_scope = _old;\
scope_vmode = _vmode;\
}
static VALUE rb_eval _((VALUE,NODE*));
static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
static NODE *compile _((VALUE,char*));
+static VALUE rb_yield_0 _((VALUE, VALUE, VALUE));
static VALUE rb_call _((VALUE,VALUE,ID,int,VALUE*,int));
-static VALUE module_setup _((VALUE,NODE*));
+static VALUE rb_module_setup _((VALUE,NODE*));
static VALUE massign _((VALUE,NODE*,VALUE));
static void assign _((VALUE,NODE*,VALUE));
@@ -685,8 +681,8 @@ safe_setter(val)
int level = NUM2INT(val);
if (level < safe_level) {
- Raise(eSecurityError, "tried to downgrade safe level from %d to %d",
- safe_level, level);
+ rb_raise(rb_eSecurityError, "tried to downgrade safe level from %d to %d",
+ safe_level, level);
}
safe_level = level;
}
@@ -696,17 +692,17 @@ rb_check_safe_str(x)
VALUE x;
{
if (TYPE(x)!= T_STRING) {
- TypeError("wrong argument type %s (expected String)",
- rb_class2name(CLASS_OF(x)));
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected String)",
+ rb_class2name(CLASS_OF(x)));
}
- if (str_tainted(x)) {
+ if (rb_str_tainted(x)) {
if (safe_level > 0){
- Raise(eSecurityError, "Insecure operation - %s",
- rb_id2name(the_frame->last_func));
+ rb_raise(rb_eSecurityError, "Insecure operation - %s",
+ rb_id2name(ruby_frame->last_func));
}
- if (verbose) {
- Warning("Insecure operation - %s",
- rb_id2name(the_frame->last_func));
+ if (rb_verbose) {
+ rb_warning("Insecure operation - %s",
+ rb_id2name(ruby_frame->last_func));
}
}
}
@@ -716,27 +712,24 @@ rb_secure(level)
int level;
{
if (level <= safe_level) {
- Raise(eSecurityError, "Insecure operation `%s' for level %d",
- rb_id2name(the_frame->last_func), level);
+ rb_raise(rb_eSecurityError, "Insecure operation `%s' for level %d",
+ rb_id2name(ruby_frame->last_func), level);
}
}
-extern int sourceline;
-extern char *sourcefile;
-
static VALUE trace_func = 0;
-static void call_trace_func _((char*,char*,int,VALUE,ID));
+static void call_trace_func _((char*,char*,int,VALUE,ID,VALUE));
static void
error_pos()
{
- if (sourcefile) {
- if (the_frame->last_func) {
- fprintf(stderr, "%s:%d:in `%s'", sourcefile, sourceline,
- rb_id2name(the_frame->last_func));
+ if (ruby_sourcefile) {
+ if (ruby_frame->last_func) {
+ fprintf(stderr, "%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline,
+ rb_id2name(ruby_frame->last_func));
}
else {
- fprintf(stderr, "%s:%d", sourcefile, sourceline);
+ fprintf(stderr, "%s:%d", ruby_sourcefile, ruby_sourceline);
}
}
}
@@ -763,9 +756,9 @@ error_print()
VALUE eclass;
VALUE einfo;
- if (NIL_P(errinfo)) return;
+ if (NIL_P(rb_errinfo)) return;
- errat = get_backtrace(errinfo);
+ errat = get_backtrace(rb_errinfo);
if (!NIL_P(errat)) {
VALUE mesg = RARRAY(errat)->ptr[0];
@@ -775,9 +768,9 @@ error_print()
}
}
- eclass = CLASS_OF(errinfo);
- einfo = obj_as_string(errinfo);
- if (eclass == eRuntimeError && RSTRING(einfo)->len == 0) {
+ eclass = CLASS_OF(rb_errinfo);
+ einfo = rb_obj_as_string(rb_errinfo);
+ if (eclass == rb_eRuntimeError && RSTRING(einfo)->len == 0) {
fprintf(stderr, ": unhandled exception\n");
}
else {
@@ -835,13 +828,11 @@ error_print()
#if !defined(NT) && !defined(__MACOS__)
extern char **environ;
#endif
-char **origenviron;
void rb_call_inits _((void));
-void init_stack _((void));
-void init_heap _((void));
+void Init_stack _((void));
+void Init_heap _((void));
void Init_ext _((void));
-void gc_call_finalizer_at_exit _((void));
void
ruby_init()
@@ -850,36 +841,30 @@ ruby_init()
static struct iter iter;
int state;
- the_frame = top_frame = &frame;
- the_iter = &iter;
+ ruby_frame = top_frame = &frame;
+ ruby_iter = &iter;
-#ifdef __MACOS__
- origenviron = 0;
-#else
- origenviron = environ;
-#endif
-
- init_heap();
+ Init_heap();
PUSH_SCOPE();
- the_scope->local_vars = 0;
- the_scope->local_tbl = 0;
- top_scope = the_scope;
+ ruby_scope->local_vars = 0;
+ ruby_scope->local_tbl = 0;
+ top_scope = ruby_scope;
/* default visibility is private at toplevel */
SCOPE_SET(SCOPE_PRIVATE);
PUSH_TAG(PROT_NONE)
if ((state = EXEC_TAG()) == 0) {
rb_call_inits();
- the_class = cObject;
- the_frame->self = TopSelf;
- the_frame->cbase = (VALUE)node_newnode(NODE_CREF,cObject,0,0);
- rb_define_global_const("TOPLEVEL_BINDING", f_binding(TopSelf));
+ ruby_class = rb_cObject;
+ ruby_frame->self = rb_top_self;
+ ruby_frame->cbase = (VALUE)rb_node_newnode(NODE_CREF,rb_cObject,0,0);
+ rb_define_global_const("TOPLEVEL_BINDING", rb_f_binding(rb_top_self));
ruby_prog_init();
}
POP_TAG();
if (state) error_print();
POP_SCOPE();
- the_scope = top_scope;
+ ruby_scope = top_scope;
}
static int ext_init = 0;
@@ -897,12 +882,13 @@ ruby_options(argc, argv)
ruby_process_options(argc, argv);
ext_init = 1; /* Init_ext() called in ruby_process_options */
- save = eval_tree;
+ save = ruby_eval_tree;
ruby_require_modules();
- eval_tree = save;
+ ruby_eval_tree = save;
}
POP_TAG();
if (state) {
+ trace_func = 0;
error_print();
exit(1);
}
@@ -915,16 +901,16 @@ eval_node(self)
VALUE result = Qnil;
NODE *tree;
- if (eval_tree_begin) {
- tree = eval_tree_begin;
- eval_tree_begin = 0;
+ if (ruby_eval_tree_begin) {
+ tree = ruby_eval_tree_begin;
+ ruby_eval_tree_begin = 0;
rb_eval(self, tree);
}
- if (!eval_tree) return Qnil;
+ if (!ruby_eval_tree) return Qnil;
- tree = eval_tree;
- eval_tree = 0;
+ tree = ruby_eval_tree;
+ ruby_eval_tree = 0;
result = rb_eval(self, tree);
return result;
@@ -933,9 +919,9 @@ eval_node(self)
int rb_in_eval;
#ifdef THREAD
-static void thread_cleanup _((void));
-static void thread_wait_other_threads _((void));
-static VALUE thread_current _((void));
+static void rb_thread_cleanup _((void));
+static void rb_thread_wait_other_threads _((void));
+static VALUE rb_thread_current _((void));
#endif
static int exit_status;
@@ -948,15 +934,15 @@ ruby_run()
int state;
static int ex;
- if (nerrs > 0) exit(nerrs);
+ if (ruby_nerrs > 0) exit(ruby_nerrs);
- init_stack();
+ Init_stack();
PUSH_TAG(PROT_NONE);
PUSH_ITER(ITER_NOT);
if ((state = EXEC_TAG()) == 0) {
if (!ext_init) Init_ext();
- eval_node(TopSelf);
+ eval_node(rb_top_self);
}
POP_ITER();
POP_TAG();
@@ -967,11 +953,11 @@ ruby_run()
if ((state = EXEC_TAG()) == 0) {
rb_trap_exit();
#ifdef THREAD
- thread_cleanup();
- thread_wait_other_threads();
+ rb_thread_cleanup();
+ rb_thread_wait_other_threads();
#endif
exec_end_proc();
- gc_call_finalizer_at_exit();
+ rb_gc_call_finalizer_at_exit();
}
else {
ex = state;
@@ -1010,14 +996,14 @@ ruby_run()
break;
case TAG_RAISE:
case TAG_FATAL:
- if (obj_is_kind_of(errinfo, eSystemExit)) {
+ if (rb_obj_is_kind_of(rb_errinfo, rb_eSystemExit)) {
exit(exit_status);
}
error_print();
exit(1);
break;
default:
- Bug("Unknown longjmp status %d", ex);
+ rb_bug("Unknown longjmp status %d", ex);
break;
}
}
@@ -1030,16 +1016,16 @@ compile_error(at)
char *mesg;
int len;
- mesg = str2cstr(errinfo, &len);
- nerrs = 0;
- str = str_new2("compile error");
+ mesg = str2cstr(rb_errinfo, &len);
+ ruby_nerrs = 0;
+ str = rb_str_new2("compile error");
if (at) {
- str_cat(str, " in ", 4);
- str_cat(str, at, strlen(at));
+ rb_str_cat(str, " in ", 4);
+ rb_str_cat(str, at, strlen(at));
}
- str_cat(str, "\n", 1);
- str_cat(str, mesg, len);
- rb_raise(exc_new3(eSyntaxError, str));
+ rb_str_cat(str, "\n", 1);
+ rb_str_cat(str, mesg, len);
+ rb_exc_raise(rb_exc_new3(rb_eSyntaxError, str));
}
VALUE
@@ -1047,11 +1033,11 @@ rb_eval_string(str)
char *str;
{
VALUE v;
- char *oldsrc = sourcefile;
+ char *oldsrc = ruby_sourcefile;
- sourcefile = "(eval)";
- v = eval(TopSelf, str_new2(str), Qnil, 0, 0);
- sourcefile = oldsrc;
+ ruby_sourcefile = "(eval)";
+ v = eval(rb_top_self, rb_str_new2(str), Qnil, 0, 0);
+ ruby_sourcefile = oldsrc;
return v;
}
@@ -1073,19 +1059,19 @@ rb_eval_cmd(cmd, arg)
PUSH_CLASS();
PUSH_TAG(PROT_NONE);
- saved_scope = the_scope;
- the_scope = top_scope;
+ saved_scope = ruby_scope;
+ ruby_scope = top_scope;
- the_class = cObject;
- if (str_tainted(cmd)) {
+ ruby_class = rb_cObject;
+ if (rb_str_tainted(cmd)) {
safe_level = 5;
}
if ((state = EXEC_TAG()) == 0) {
- val = eval(TopSelf, cmd, Qnil, 0, 0);
+ val = eval(rb_top_self, cmd, Qnil, 0, 0);
}
- the_scope = saved_scope;
+ ruby_scope = saved_scope;
safe_level = safe;
POP_TAG();
POP_CLASS();
@@ -1094,19 +1080,19 @@ rb_eval_cmd(cmd, arg)
case 0:
break;
case TAG_RETURN:
- Raise(eLocalJumpError, "unexpected return");
+ rb_raise(rb_eLocalJumpError, "unexpected return");
break;
case TAG_NEXT:
- Raise(eLocalJumpError, "unexpected next");
+ rb_raise(rb_eLocalJumpError, "unexpected next");
break;
case TAG_BREAK:
- Raise(eLocalJumpError, "unexpected break");
+ rb_raise(rb_eLocalJumpError, "unexpected break");
break;
case TAG_REDO:
- Raise(eLocalJumpError, "unexpected redo");
+ rb_raise(rb_eLocalJumpError, "unexpected redo");
break;
case TAG_RETRY:
- Raise(eLocalJumpError, "retry outside of rescue clause");
+ rb_raise(rb_eLocalJumpError, "retry outside of rescue clause");
break;
default:
JUMP_TAG(state);
@@ -1125,11 +1111,11 @@ rb_trap_eval(cmd, sig)
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- val = rb_eval_cmd(cmd, ary_new3(1, INT2FIX(sig)));
+ val = rb_eval_cmd(cmd, rb_ary_new3(1, INT2FIX(sig)));
}
POP_TAG();
if (state) {
- trap_immediate = 0;
+ rb_trap_immediate = 0;
JUMP_TAG(state);
}
return val;
@@ -1152,17 +1138,19 @@ superclass(self, node)
superclass_error:
switch (nd_type(node)) {
case NODE_COLON2:
- TypeError("undefined superclass `%s'", rb_id2name(node->nd_mid));
+ rb_raise(rb_eTypeError, "undefined superclass `%s'",
+ rb_id2name(node->nd_mid));
case NODE_CVAR:
- TypeError("undefined superclass `%s'", rb_id2name(node->nd_vid));
+ rb_raise(rb_eTypeError, "undefined superclass `%s'",
+ rb_id2name(node->nd_vid));
default:
- TypeError("superclass undefined");
+ rb_raise(rb_eTypeError, "superclass undefined");
}
JUMP_TAG(state);
}
if (TYPE(val) != T_CLASS) goto superclass_error;
if (FL_TEST(val, FL_SINGLETON)) {
- TypeError("can't make subclass of virtual class");
+ rb_raise(rb_eTypeError, "can't make subclass of virtual class");
}
return val;
@@ -1175,12 +1163,12 @@ ev_const_defined(cref, id)
{
NODE *cbase = cref;
- while (cbase && cbase->nd_clss != cObject) {
+ while (cbase && cbase->nd_clss != rb_cObject) {
struct RClass *klass = RCLASS(cbase->nd_clss);
if (klass->iv_tbl &&
st_lookup(klass->iv_tbl, id, 0)) {
- return TRUE;
+ return Qtrue;
}
cbase = cbase->nd_next;
}
@@ -1195,7 +1183,7 @@ ev_const_get(cref, id)
NODE *cbase = cref;
VALUE result;
- while (cbase && cbase->nd_clss != cObject) {
+ while (cbase && cbase->nd_clss != rb_cObject) {
struct RClass *klass = RCLASS(cbase->nd_clss);
if (klass->iv_tbl &&
@@ -1208,35 +1196,35 @@ ev_const_get(cref, id)
}
static VALUE
-mod_nesting()
+rb_mod_nesting()
{
- NODE *cbase = (NODE*)the_frame->cbase;
- VALUE ary = ary_new();
+ NODE *cbase = (NODE*)ruby_frame->cbase;
+ VALUE ary = rb_ary_new();
- while (cbase && cbase->nd_clss != cObject) {
- ary_push(ary, cbase->nd_clss);
+ while (cbase && cbase->nd_clss != rb_cObject) {
+ rb_ary_push(ary, cbase->nd_clss);
cbase = cbase->nd_next;
}
return ary;
}
static VALUE
-mod_s_constants()
+rb_mod_s_constants()
{
- NODE *cbase = (NODE*)the_frame->cbase;
- VALUE ary = ary_new();
+ NODE *cbase = (NODE*)ruby_frame->cbase;
+ VALUE ary = rb_ary_new();
- while (cbase && cbase->nd_clss != cObject) {
- mod_const_at(cbase->nd_clss, ary);
+ while (cbase && cbase->nd_clss != rb_cObject) {
+ rb_mod_const_at(cbase->nd_clss, ary);
cbase = cbase->nd_next;
}
- mod_const_of(((NODE*)the_frame->cbase)->nd_clss, ary);
+ rb_mod_const_of(((NODE*)ruby_frame->cbase)->nd_clss, ary);
return ary;
}
static VALUE
-mod_remove_method(mod, name)
+rb_mod_remove_method(mod, name)
VALUE mod, name;
{
remove_method(mod, rb_to_id(name));
@@ -1244,7 +1232,7 @@ mod_remove_method(mod, name)
}
static VALUE
-mod_undef_method(mod, name)
+rb_mod_undef_method(mod, name)
VALUE mod, name;
{
ID id = rb_to_id(name);
@@ -1255,7 +1243,7 @@ mod_undef_method(mod, name)
}
static VALUE
-mod_alias_method(mod, newname, oldname)
+rb_mod_alias_method(mod, newname, oldname)
VALUE mod, newname, oldname;
{
ID id = rb_to_id(newname);
@@ -1268,8 +1256,8 @@ mod_alias_method(mod, newname, oldname)
#if defined(C_ALLOCA) && defined(THREAD)
# define TMP_PROTECT NODE *__protect_tmp=0
# define TMP_ALLOC(type,n) \
- (__protect_tmp = node_newnode(NODE_ALLOCA, \
- str_new(0,sizeof(type)*(n)),0,__protect_tmp), \
+ (__protect_tmp = rb_node_newnode(NODE_ALLOCA, \
+ rb_str_new(0,sizeof(type)*(n)),0,__protect_tmp), \
(void*)RSTRING(__protect_tmp->nd_head)->ptr)
#else
# define TMP_PROTECT typedef int foobazzz
@@ -1285,8 +1273,8 @@ mod_alias_method(mod, newname, oldname)
else if (nd_type(n) == NODE_ARRAY) {\
argc=n->nd_alen;\
if (argc > 0) {\
- char *file = sourcefile;\
- int line = sourceline;\
+ char *file = ruby_sourcefile;\
+ int line = ruby_sourceline;\
int i;\
n = anode;\
argv = TMP_ALLOC(VALUE,argc);\
@@ -1294,8 +1282,8 @@ mod_alias_method(mod, newname, oldname)
argv[i] = rb_eval(self,n->nd_head);\
n=n->nd_next;\
}\
- sourcefile = file;\
- sourceline = line;\
+ ruby_sourcefile = file;\
+ ruby_sourceline = line;\
}\
else {\
argc = 0;\
@@ -1304,31 +1292,31 @@ mod_alias_method(mod, newname, oldname)
}\
else {\
VALUE args = rb_eval(self,n);\
- char *file = sourcefile;\
- int line = sourceline;\
+ char *file = ruby_sourcefile;\
+ int line = ruby_sourceline;\
if (TYPE(args) != T_ARRAY)\
args = rb_Array(args);\
argc = RARRAY(args)->len;\
argv = ALLOCA_N(VALUE, argc);\
MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\
- sourcefile = file;\
- sourceline = line;\
+ ruby_sourcefile = file;\
+ ruby_sourceline = line;\
}\
}
#define BEGIN_CALLARGS {\
- struct BLOCK *tmp_block = the_block;\
- if (the_iter->iter == ITER_PRE) {\
- the_block = the_block->prev;\
+ struct BLOCK *tmp_block = ruby_block;\
+ if (ruby_iter->iter == ITER_PRE) {\
+ ruby_block = ruby_block->prev;\
}\
PUSH_ITER(ITER_NOT);
#define END_CALLARGS \
- the_block = tmp_block;\
+ ruby_block = tmp_block;\
POP_ITER();\
}
-#define MATCH_DATA the_scope->local_vars[node->nd_cnt]
+#define MATCH_DATA ruby_scope->local_vars[node->nd_cnt]
static char* is_defined _((VALUE, NODE*, char*));
@@ -1371,9 +1359,9 @@ is_defined(self, node, buf)
switch (nd_type(node)) {
case NODE_SUPER:
case NODE_ZSUPER:
- if (the_frame->last_func == 0) return 0;
- else if (rb_method_boundp(RCLASS(the_frame->last_class)->super,
- the_frame->last_func, 1)) {
+ if (ruby_frame->last_func == 0) return 0;
+ else if (rb_method_boundp(RCLASS(ruby_frame->last_class)->super,
+ ruby_frame->last_func, 1)) {
if (nd_type(node) == NODE_SUPER) {
return arg_defined(self, node->nd_args, buf, "super");
}
@@ -1394,9 +1382,7 @@ is_defined(self, node, buf)
val = CLASS_OF(val);
}
POP_TAG();
- if (state) {
- return 0;
- }
+ if (state) return 0;
check_bound:
if (rb_method_boundp(val, node->nd_mid, nd_type(node)== NODE_CALL)) {
return arg_defined(self, node->nd_args, buf, "method");
@@ -1408,7 +1394,7 @@ is_defined(self, node, buf)
return "method";
case NODE_YIELD:
- if (iterator_p()) {
+ if (rb_iterator_p()) {
return "yield";
}
break;
@@ -1455,7 +1441,7 @@ is_defined(self, node, buf)
break;
case NODE_CVAR:
- if (ev_const_defined((NODE*)the_frame->cbase, node->nd_vid)) {
+ if (ev_const_defined((NODE*)ruby_frame->cbase, node->nd_vid)) {
return "constant";
}
break;
@@ -1466,9 +1452,7 @@ is_defined(self, node, buf)
val = rb_eval(self, node->nd_head);
}
POP_TAG();
- if (state) {
- return 0;
- }
+ if (state) return 0;
else {
switch (TYPE(val)) {
case T_CLASS:
@@ -1480,14 +1464,14 @@ is_defined(self, node, buf)
break;
case NODE_NTH_REF:
- if (reg_nth_defined(node->nd_nth, MATCH_DATA)) {
+ if (rb_reg_nth_defined(node->nd_nth, MATCH_DATA)) {
sprintf(buf, "$%d", node->nd_nth);
return buf;
}
break;
case NODE_BACK_REF:
- if (reg_nth_defined(0, MATCH_DATA)) {
+ if (rb_reg_nth_defined(0, MATCH_DATA)) {
sprintf(buf, "$%c", node->nd_nth);
return buf;
}
@@ -1512,23 +1496,23 @@ static int handle_rescue _((VALUE,NODE*));
static void blk_free();
static VALUE
-obj_is_block(block)
+rb_obj_is_block(block)
VALUE block;
{
if (TYPE(block) == T_DATA && RDATA(block)->dfree == blk_free) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
-obj_is_proc(proc)
+rb_obj_is_proc(proc)
VALUE proc;
{
- if (obj_is_block(proc) && obj_is_kind_of(proc, cProc)) {
- return TRUE;
+ if (rb_obj_is_block(proc) && rb_obj_is_kind_of(proc, rb_cProc)) {
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -1539,58 +1523,67 @@ set_trace_func(obj, trace)
trace_func = 0;
return Qnil;
}
- if (!obj_is_proc(trace)) {
- TypeError("trace_func needs to be Proc");
+ if (!rb_obj_is_proc(trace)) {
+ rb_raise(rb_eTypeError, "trace_func needs to be Proc");
}
return trace_func = trace;
}
static void
-call_trace_func(event, file, line, self, id)
+call_trace_func(event, file, line, self, id, klass)
char *event;
char *file;
int line;
VALUE self;
ID id;
+ VALUE klass;
{
int state;
volatile VALUE trace;
struct FRAME *prev;
- char *file_save = sourcefile;
- int line_save = sourceline;
+ char *file_save = ruby_sourcefile;
+ int line_save = ruby_sourceline;
if (!trace_func) return;
trace = trace_func;
trace_func = 0;
#ifdef THREAD
- thread_critical++;
+ rb_thread_critical++;
#endif
- prev = the_frame;
+ prev = ruby_frame;
PUSH_FRAME();
- *the_frame = *_frame.prev;
- the_frame->prev = prev;
+ *ruby_frame = *_frame.prev;
+ ruby_frame->prev = prev;
- the_frame->line = sourceline = line;
- the_frame->file = sourcefile = file;
+ if (file) {
+ ruby_frame->line = ruby_sourceline = line;
+ ruby_frame->file = ruby_sourcefile = file;
+ }
+ if (klass) {
+ if (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
+ klass = self;
+ }
+ }
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- proc_call(trace, ary_new3(5, str_new2(event),
- str_new2(sourcefile),
- INT2FIX(sourceline),
- INT2FIX(id),
- self?f_binding(self):Qnil));
+ proc_call(trace, rb_ary_new3(6, rb_str_new2(event),
+ rb_str_new2(ruby_sourcefile),
+ INT2FIX(ruby_sourceline),
+ INT2FIX(id),
+ self?rb_f_binding(self):Qnil,
+ klass));
}
POP_TAG();
POP_FRAME();
#ifdef THREAD
- thread_critical--;
+ rb_thread_critical--;
#endif
if (!trace_func) trace_func = trace;
- sourceline = line_save;
- sourcefile = file_save;
+ ruby_sourceline = line_save;
+ ruby_sourcefile = file_save;
if (state) JUMP_TAG(state);
}
@@ -1619,7 +1612,7 @@ rb_eval(self, node)
break;
case NODE_POSTEXE:
- f_END();
+ rb_f_END();
nd_set_type(node, NODE_NIL); /* exec just once */
result = Qnil;
break;
@@ -1631,12 +1624,12 @@ rb_eval(self, node)
/* nodes for speed-up(default match) */
case NODE_MATCH:
- result = reg_match2(node->nd_head->nd_lit);
+ result = rb_reg_match2(node->nd_head->nd_lit);
break;
/* nodes for speed-up(literal match) */
case NODE_MATCH2:
- result = reg_match(rb_eval(self,node->nd_recv),
+ result = rb_reg_match(rb_eval(self,node->nd_recv),
rb_eval(self,node->nd_value));
break;
@@ -1646,7 +1639,7 @@ rb_eval(self, node)
VALUE r = rb_eval(self,node->nd_recv);
VALUE l = rb_eval(self,node->nd_value);
if (TYPE(r) == T_STRING) {
- result = reg_match(l, r);
+ result = rb_reg_match(l, r);
}
else {
result = rb_funcall(r, match, 1, l);
@@ -1656,7 +1649,7 @@ rb_eval(self, node)
/* nodes for speed-up(top-level loop for -n/-p) */
case NODE_OPT_N:
- while (!NIL_P(f_gets())) {
+ while (!NIL_P(rb_f_gets())) {
rb_eval(self, node->nd_body);
}
RETURN(Qnil);
@@ -1668,13 +1661,13 @@ rb_eval(self, node)
RETURN(Qnil);
case NODE_TRUE:
- RETURN(TRUE);
+ RETURN(Qtrue);
case NODE_FALSE:
- RETURN(FALSE);
+ RETURN(Qfalse);
case NODE_IF:
- sourceline = nd_line(node);
+ ruby_sourceline = nd_line(node);
if (RTEST(rb_eval(self, node->nd_cond))) {
node = node->nd_body;
}
@@ -1699,9 +1692,10 @@ rb_eval(self, node)
while (tag) {
if (trace_func) {
call_trace_func("line", tag->nd_file, nd_line(tag),
- self, the_frame->last_func);
+ self, ruby_frame->last_func, 0);
}
- sourceline = nd_line(tag);
+ ruby_sourcefile = tag->nd_file;
+ ruby_sourceline = nd_line(tag);
if (RTEST(rb_funcall2(rb_eval(self, tag->nd_head),eqq,1,&val))){
node = node->nd_body;
goto again;
@@ -1717,7 +1711,7 @@ rb_eval(self, node)
PUSH_TAG(PROT_NONE);
switch (state = EXEC_TAG()) {
case 0:
- sourceline = nd_line(node);
+ ruby_sourceline = nd_line(node);
if (node->nd_state && !RTEST(rb_eval(self, node->nd_cond)))
goto while_out;
do {
@@ -1741,9 +1735,7 @@ rb_eval(self, node)
}
while_out:
POP_TAG();
- if (state) {
- JUMP_TAG(state);
- }
+ if (state) JUMP_TAG(state);
RETURN(Qnil);
case NODE_UNTIL:
@@ -1773,9 +1765,7 @@ rb_eval(self, node)
}
until_out:
POP_TAG();
- if (state) {
- JUMP_TAG(state);
- }
+ if (state) JUMP_TAG(state);
RETURN(Qnil);
case NODE_BLOCK_PASS:
@@ -1798,13 +1788,13 @@ rb_eval(self, node)
}
else {
VALUE recv;
- char *file = sourcefile;
- int line = sourceline;
+ char *file = ruby_sourcefile;
+ int line = ruby_sourceline;
recv = rb_eval(self, node->nd_iter);
PUSH_ITER(ITER_PRE);
- sourcefile = file;
- sourceline = line;
+ ruby_sourcefile = file;
+ ruby_sourceline = line;
result = rb_call(CLASS_OF(recv),recv,each,0,0,0);
POP_ITER();
}
@@ -1853,13 +1843,13 @@ rb_eval(self, node)
break;
case NODE_YIELD:
- result = rb_yield_0(rb_eval(self, node->nd_stts), 0);
+ result = rb_yield_0(rb_eval(self, node->nd_stts), 0, 0);
break;
case NODE_RESCUE:
retry_entry:
{
- volatile VALUE e_info = errinfo;
+ volatile VALUE e_info = rb_errinfo;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
@@ -1878,7 +1868,7 @@ rb_eval(self, node)
}
POP_TAG();
if (state == 0) {
- errinfo = e_info;
+ rb_errinfo = e_info;
}
else if (state == TAG_RETRY) {
state = 0;
@@ -1889,9 +1879,7 @@ rb_eval(self, node)
resq = resq->nd_head; /* next rescue */
}
}
- if (state) {
- JUMP_TAG(state);
- }
+ if (state) JUMP_TAG(state);
}
break;
@@ -1907,9 +1895,7 @@ rb_eval(self, node)
rb_eval(self, node->nd_ensr);
return_value(retval);
}
- if (state) {
- JUMP_TAG(state);
- }
+ if (state) JUMP_TAG(state);
break;
case NODE_AND:
@@ -1925,29 +1911,29 @@ rb_eval(self, node)
goto again;
case NODE_NOT:
- if (RTEST(rb_eval(self, node->nd_body))) result = FALSE;
- else result = TRUE;
+ if (RTEST(rb_eval(self, node->nd_body))) result = Qfalse;
+ else result = Qtrue;
break;
case NODE_DOT2:
case NODE_DOT3:
- RETURN(range_new(rb_eval(self, node->nd_beg), rb_eval(self, node->nd_end)));
+ RETURN(rb_range_new(rb_eval(self, node->nd_beg), rb_eval(self, node->nd_end)));
case NODE_FLIP2: /* like AWK */
if (node->nd_state == 0) {
if (RTEST(rb_eval(self, node->nd_beg))) {
node->nd_state = rb_eval(self, node->nd_end)?0:1;
- result = TRUE;
+ result = Qtrue;
}
else {
- result = FALSE;
+ result = Qfalse;
}
}
else {
if (RTEST(rb_eval(self, node->nd_end))) {
node->nd_state = 0;
}
- result = TRUE;
+ result = Qtrue;
}
break;
@@ -1955,15 +1941,15 @@ rb_eval(self, node)
if (node->nd_state == 0) {
if (RTEST(rb_eval(self, node->nd_beg))) {
node->nd_state = 1;
- result = TRUE;
+ result = Qtrue;
}
- result = FALSE;
+ result = Qfalse;
}
else {
if (RTEST(rb_eval(self, node->nd_end))) {
node->nd_state = 0;
}
- result = TRUE;
+ result = Qtrue;
}
break;
@@ -2013,13 +1999,13 @@ rb_eval(self, node)
int argc; VALUE *argv; /* used in SETUP_ARGS */
TMP_PROTECT;
- if (the_frame->last_class == 0) {
- NameError("superclass method `%s' disabled",
- rb_id2name(the_frame->last_func));
+ if (ruby_frame->last_class == 0) {
+ rb_raise(rb_eNameError, "superclass method `%s' disabled",
+ rb_id2name(ruby_frame->last_func));
}
if (nd_type(node) == NODE_ZSUPER) {
- argc = the_frame->argc;
- argv = the_frame->argv;
+ argc = ruby_frame->argc;
+ argv = ruby_frame->argv;
}
else {
BEGIN_CALLARGS;
@@ -2027,9 +2013,9 @@ rb_eval(self, node)
END_CALLARGS;
}
- PUSH_ITER(the_iter->iter?ITER_PRE:ITER_NOT);
- result = rb_call(RCLASS(the_frame->last_class)->super,
- the_frame->self, the_frame->last_func,
+ PUSH_ITER(ruby_iter->iter?ITER_PRE:ITER_NOT);
+ result = rb_call(RCLASS(ruby_frame->last_class)->super,
+ ruby_frame->self, ruby_frame->last_func,
argc, argv, 3);
POP_ITER();
}
@@ -2037,28 +2023,28 @@ rb_eval(self, node)
case NODE_SCOPE:
{
- VALUE save = the_frame->cbase;
+ VALUE save = ruby_frame->cbase;
PUSH_SCOPE();
PUSH_TAG(PROT_NONE);
- if (node->nd_rval) the_frame->cbase = node->nd_rval;
+ if (node->nd_rval) ruby_frame->cbase = node->nd_rval;
if (node->nd_tbl) {
VALUE *vars = ALLOCA_N(VALUE, node->nd_tbl[0]+1);
*vars++ = (VALUE)node;
- the_scope->local_vars = vars;
- memclear(the_scope->local_vars, node->nd_tbl[0]);
- the_scope->local_tbl = node->nd_tbl;
+ ruby_scope->local_vars = vars;
+ rb_mem_clear(ruby_scope->local_vars, node->nd_tbl[0]);
+ ruby_scope->local_tbl = node->nd_tbl;
}
else {
- the_scope->local_vars = 0;
- the_scope->local_tbl = 0;
+ ruby_scope->local_vars = 0;
+ ruby_scope->local_tbl = 0;
}
if ((state = EXEC_TAG()) == 0) {
result = rb_eval(self, node->nd_body);
}
POP_TAG();
POP_SCOPE();
- the_frame->cbase = save;
+ ruby_frame->cbase = save;
if (state) JUMP_TAG(state);
}
break;
@@ -2135,14 +2121,15 @@ rb_eval(self, node)
break;
case NODE_LASGN:
- if (the_scope->local_vars == 0)
- Bug("unexpected local variable assignment");
+ if (ruby_scope->local_vars == 0)
+ rb_bug("unexpected local variable assignment");
result = rb_eval(self, node->nd_value);
- the_scope->local_vars[node->nd_cnt] = result;
+ ruby_scope->local_vars[node->nd_cnt] = result;
break;
case NODE_DASGN:
- result = dyna_var_asgn(node->nd_vid, rb_eval(self, node->nd_value));
+ result = rb_eval(self, node->nd_value);
+ rb_dvar_asgn(node->nd_vid, result);
break;
case NODE_DASGN_PUSH:
@@ -2174,27 +2161,32 @@ rb_eval(self, node)
{
VALUE val;
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no class/module to define constant");
+ }
val = rb_eval(self, node->nd_value);
/* check for static scope constants */
- if (RTEST(verbose) &&
- ev_const_defined((NODE*)the_frame->cbase, node->nd_vid)) {
- Warning("already initialized constant %s",
- rb_id2name(node->nd_vid));
+ if (RTEST(rb_verbose) &&
+ ev_const_defined((NODE*)ruby_frame->cbase, node->nd_vid)) {
+ if (rb_verbose) {
+ rb_warning("already initialized constant %s",
+ rb_id2name(node->nd_vid));
+ }
}
- rb_const_set(the_class, node->nd_vid, val);
+ rb_const_set(ruby_class, node->nd_vid, val);
result = val;
}
break;
case NODE_LVAR:
- if (the_scope->local_vars == 0) {
- Bug("unexpected local variable");
+ if (ruby_scope->local_vars == 0) {
+ rb_bug("unexpected local variable");
}
- result = the_scope->local_vars[node->nd_cnt];
+ result = ruby_scope->local_vars[node->nd_cnt];
break;
case NODE_DVAR:
- result = dyna_var_ref(node->nd_vid);
+ result = rb_dvar_ref(node->nd_vid);
break;
case NODE_GVAR:
@@ -2206,15 +2198,15 @@ rb_eval(self, node)
break;
case NODE_CVAR:
- result = ev_const_get((NODE*)the_frame->cbase, node->nd_vid);
+ result = ev_const_get((NODE*)ruby_frame->cbase, node->nd_vid);
break;
case NODE_BLOCK_ARG:
- if (the_scope->local_vars == 0)
- Bug("unexpected block argument");
- if (iterator_p()) {
- result = f_lambda();
- the_scope->local_vars[node->nd_cnt] = result;
+ if (ruby_scope->local_vars == 0)
+ rb_bug("unexpected block argument");
+ if (rb_iterator_p()) {
+ result = rb_f_lambda();
+ ruby_scope->local_vars[node->nd_cnt] = result;
}
else {
result = Qnil;
@@ -2239,36 +2231,36 @@ rb_eval(self, node)
break;
case NODE_COLON3:
- result = rb_const_get_at(cObject, node->nd_mid);
+ result = rb_const_get_at(rb_cObject, node->nd_mid);
break;
case NODE_NTH_REF:
- result = reg_nth_match(node->nd_nth, MATCH_DATA);
+ result = rb_reg_nth_match(node->nd_nth, MATCH_DATA);
break;
case NODE_BACK_REF:
switch (node->nd_nth) {
case '&':
- result = reg_last_match(MATCH_DATA);
+ result = rb_reg_last_match(MATCH_DATA);
break;
case '`':
- result = reg_match_pre(MATCH_DATA);
+ result = rb_reg_match_pre(MATCH_DATA);
break;
case '\'':
- result = reg_match_post(MATCH_DATA);
+ result = rb_reg_match_post(MATCH_DATA);
break;
case '+':
- result = reg_match_last(MATCH_DATA);
+ result = rb_reg_match_last(MATCH_DATA);
break;
default:
- Bug("unexpected back-ref");
+ rb_bug("unexpected back-ref");
}
break;
case NODE_HASH:
{
NODE *list;
- VALUE hash = hash_new();
+ VALUE hash = rb_hash_new();
VALUE key, val;
list = node->nd_head;
@@ -2276,17 +2268,17 @@ rb_eval(self, node)
key = rb_eval(self, list->nd_head);
list = list->nd_next;
if (list == 0)
- Bug("odd number list for Hash");
+ rb_bug("odd number list for Hash");
val = rb_eval(self, list->nd_head);
list = list->nd_next;
- hash_aset(hash, key, val);
+ rb_hash_aset(hash, key, val);
}
result = hash;
}
break;
case NODE_ZARRAY: /* zero length list */
- result = ary_new();
+ result = rb_ary_new();
break;
case NODE_ARRAY:
@@ -2295,7 +2287,7 @@ rb_eval(self, node)
int i;
i = node->nd_alen;
- ary = ary_new2(i);
+ ary = rb_ary_new2(i);
for (i=0;node;node=node->nd_next) {
RARRAY(ary)->ptr[i++] = rb_eval(self, node->nd_head);
RARRAY(ary)->len = i;
@@ -2306,7 +2298,7 @@ rb_eval(self, node)
break;
case NODE_STR:
- result = str_new3(node->nd_lit);
+ result = rb_str_new3(node->nd_lit);
break;
case NODE_DSTR:
@@ -2317,7 +2309,7 @@ rb_eval(self, node)
VALUE str, str2;
NODE *list = node->nd_next;
- str = str_new3(node->nd_lit);
+ str = rb_str_new3(node->nd_lit);
while (list) {
if (nd_type(list->nd_head) == NODE_STR) {
str2 = list->nd_head->nd_lit;
@@ -2326,27 +2318,27 @@ rb_eval(self, node)
if (nd_type(list->nd_head) == NODE_EVSTR) {
rb_in_eval++;
list->nd_head = compile(list->nd_head->nd_lit,0);
- eval_tree = 0;
+ ruby_eval_tree = 0;
rb_in_eval--;
- if (nerrs > 0) {
+ if (ruby_nerrs > 0) {
compile_error("string expansion");
}
}
str2 = rb_eval(self, list->nd_head);
- str2 = obj_as_string(str2);
+ str2 = rb_obj_as_string(str2);
}
if (str2) {
- str_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
+ rb_str_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
}
list = list->nd_next;
}
switch (nd_type(node)) {
case NODE_DREGX:
- result = reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
+ result = rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
node->nd_cflag);
break;
case NODE_DREGX_ONCE: /* regexp expand once */
- result = reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
+ result = rb_reg_new(RSTRING(str)->ptr, RSTRING(str)->len,
node->nd_cflag);
nd_set_type(node, NODE_LIT);
node->nd_lit = result;
@@ -2370,9 +2362,10 @@ rb_eval(self, node)
break;
case NODE_ATTRSET:
- if (the_frame->argc != 1)
- ArgError("Wrong # of arguments(%d for 1)", the_frame->argc);
- result = rb_ivar_set(self, node->nd_vid, the_frame->argv[0]);
+ if (ruby_frame->argc != 1)
+ rb_raise(rb_eArgError, "Wrong # of arguments(%d for 1)",
+ ruby_frame->argc);
+ result = rb_ivar_set(self, node->nd_vid, ruby_frame->argv[0]);
break;
case NODE_DEFN:
@@ -2381,13 +2374,16 @@ rb_eval(self, node)
VALUE origin;
int noex;
- if (the_class == cObject && node->nd_mid == init) {
- Warn("re-defining Object#initialize may cause infinite loop");
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no class to add method");
+ }
+ if (ruby_class == rb_cObject && node->nd_mid == init) {
+ rb_warn("re-defining Object#initialize may cause infinite loop");
}
- body = search_method(the_class, node->nd_mid, &origin);
+ body = search_method(ruby_class, node->nd_mid, &origin);
if (body) {
- if (origin == the_class) {
- Warning("discarding old %s", rb_id2name(node->nd_mid));
+ if (origin == ruby_class && rb_verbose) {
+ rb_warning("discarding old %s", rb_id2name(node->nd_mid));
}
rb_clear_cache_by_id(node->nd_mid);
}
@@ -2401,23 +2397,23 @@ rb_eval(self, node)
else {
noex = NOEX_PUBLIC;
}
- if (body && origin == the_class && body->nd_noex & NOEX_UNDEF) {
+ if (body && origin == ruby_class && body->nd_noex & NOEX_UNDEF) {
noex |= NOEX_UNDEF;
}
- rb_add_method(the_class, node->nd_mid, node->nd_defn, noex);
+ rb_add_method(ruby_class, node->nd_mid, node->nd_defn, noex);
if (scope_vmode == SCOPE_MODFUNC) {
- rb_add_method(rb_singleton_class(the_class),
+ rb_add_method(rb_singleton_class(ruby_class),
node->nd_mid, node->nd_defn, NOEX_PUBLIC);
- rb_funcall(the_class, rb_intern("singleton_method_added"),
+ rb_funcall(ruby_class, rb_intern("singleton_method_added"),
1, INT2FIX(node->nd_mid));
}
- if (FL_TEST(the_class, FL_SINGLETON)) {
- rb_funcall(rb_iv_get(the_class, "__attached__"),
+ if (FL_TEST(ruby_class, FL_SINGLETON)) {
+ rb_funcall(rb_iv_get(ruby_class, "__attached__"),
rb_intern("singleton_method_added"),
1, INT2FIX(node->nd_mid));
}
else {
- rb_funcall(the_class, rb_intern("method_added"),
+ rb_funcall(ruby_class, rb_intern("method_added"),
1, INT2FIX(node->nd_mid));
}
result = Qnil;
@@ -2431,21 +2427,23 @@ rb_eval(self, node)
NODE *body = 0;
if (FIXNUM_P(recv)) {
- TypeError("Can't define method \"%s\" for Fixnum",
- rb_id2name(node->nd_mid));
+ rb_raise(rb_eTypeError, "Can't define method \"%s\" for Fixnum",
+ rb_id2name(node->nd_mid));
}
if (NIL_P(recv)) {
- TypeError("Can't define method \"%s\" for nil",
- rb_id2name(node->nd_mid));
+ rb_raise(rb_eTypeError, "Can't define method \"%s\" for nil",
+ rb_id2name(node->nd_mid));
}
if (rb_special_const_p(recv)) {
- TypeError("Can't define method \"%s\" for special constants",
- rb_id2name(node->nd_mid));
+ rb_raise(rb_eTypeError,
+ "Can't define method \"%s\" for special constants",
+ rb_id2name(node->nd_mid));
}
klass = rb_singleton_class(recv);
- if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &body)) {
- Warning("redefine %s", rb_id2name(node->nd_mid));
+ if (st_lookup(RCLASS(klass)->m_tbl, node->nd_mid, &body)
+ && rb_verbose) {
+ rb_warning("redefine %s", rb_id2name(node->nd_mid));
}
rb_clear_cache_by_id(node->nd_mid);
rb_add_method(klass, node->nd_mid, node->nd_defn,
@@ -2461,13 +2459,16 @@ rb_eval(self, node)
VALUE origin;
NODE *body;
- body = search_method(the_class, node->nd_mid, &origin);
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no class to undef method");
+ }
+ body = search_method(ruby_class, node->nd_mid, &origin);
if (!body || !body->nd_body) {
char *s0 = " class";
- VALUE klass = the_class;
+ VALUE klass = ruby_class;
- if (FL_TEST(the_class, FL_SINGLETON)) {
- VALUE obj = rb_iv_get(the_class, "__attached__");
+ if (FL_TEST(ruby_class, FL_SINGLETON)) {
+ VALUE obj = rb_iv_get(ruby_class, "__attached__");
switch (TYPE(obj)) {
case T_MODULE:
case T_CLASS:
@@ -2475,18 +2476,21 @@ rb_eval(self, node)
s0 = "";
}
}
- NameError("undefined method `%s' for%s `%s'",
- rb_id2name(node->nd_mid),s0,rb_class2name(klass));
+ rb_raise(rb_eNameError, "undefined method `%s' for%s `%s'",
+ rb_id2name(node->nd_mid),s0,rb_class2name(klass));
}
rb_clear_cache_by_id(node->nd_mid);
- rb_add_method(the_class, node->nd_mid, 0, NOEX_PUBLIC);
+ rb_add_method(ruby_class, node->nd_mid, 0, NOEX_PUBLIC);
result = Qnil;
}
break;
case NODE_ALIAS:
- rb_alias(the_class, node->nd_new, node->nd_old);
- rb_funcall(the_class, rb_intern("method_added"),
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no class to make alias");
+ }
+ rb_alias(ruby_class, node->nd_new, node->nd_old);
+ rb_funcall(ruby_class, rb_intern("method_added"),
1, INT2FIX(node->nd_mid));
result = Qnil;
break;
@@ -2500,6 +2504,9 @@ rb_eval(self, node)
{
VALUE super, klass, tmp;
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no outer class/module");
+ }
if (node->nd_super) {
super = superclass(self, node->nd_super);
}
@@ -2507,13 +2514,14 @@ rb_eval(self, node)
super = 0;
}
- if (rb_const_defined_at(the_class, node->nd_cname) &&
- (the_class != cObject ||
+ if (rb_const_defined_at(ruby_class,node->nd_cname) &&
+ (ruby_class != rb_cObject ||
!rb_autoload_defined(node->nd_cname))) {
- klass = rb_const_get_at(the_class, node->nd_cname);
+ klass = rb_const_get_at(ruby_class, node->nd_cname);
if (TYPE(klass) != T_CLASS) {
- TypeError("%s is not a class", rb_id2name(node->nd_cname));
+ rb_raise(rb_eTypeError, "%s is not a class",
+ rb_id2name(node->nd_cname));
}
if (super) {
tmp = RCLASS(klass)->super;
@@ -2524,24 +2532,24 @@ rb_eval(self, node)
tmp = RCLASS(tmp)->super;
}
if (tmp != super) {
- TypeError("superclass mismatch for %s",
- rb_id2name(node->nd_cname));
+ rb_raise(rb_eTypeError, "superclass mismatch for %s",
+ rb_id2name(node->nd_cname));
}
}
if (safe_level >= 3) {
- Raise(eSecurityError, "extending class prohibited");
+ rb_raise(rb_eSecurityError, "extending class prohibited");
}
rb_clear_cache();
}
else {
- if (!super) super = cObject;
+ if (!super) super = rb_cObject;
klass = rb_define_class_id(node->nd_cname, super);
- rb_const_set(the_class, node->nd_cname, klass);
- rb_set_class_path(klass,the_class,rb_id2name(node->nd_cname));
- obj_call_init(klass);
+ rb_const_set(ruby_class, node->nd_cname, klass);
+ rb_set_class_path(klass,ruby_class,rb_id2name(node->nd_cname));
+ rb_obj_call_init(klass);
}
- return module_setup(klass, node->nd_body);
+ return rb_module_setup(klass, node->nd_body);
}
break;
@@ -2549,26 +2557,30 @@ rb_eval(self, node)
{
VALUE module;
- if (rb_const_defined_at(the_class, node->nd_cname) &&
- (the_class != cObject ||
+ if (NIL_P(ruby_class)) {
+ rb_raise(rb_eTypeError, "no outer class/module");
+ }
+ if (rb_const_defined_at(ruby_class, node->nd_cname) &&
+ (ruby_class != rb_cObject ||
!rb_autoload_defined(node->nd_cname))) {
- module = rb_const_get_at(the_class, node->nd_cname);
+ module = rb_const_get_at(ruby_class, node->nd_cname);
if (TYPE(module) != T_MODULE) {
- TypeError("%s is not a module", rb_id2name(node->nd_cname));
+ rb_raise(rb_eTypeError, "%s is not a module",
+ rb_id2name(node->nd_cname));
}
if (safe_level >= 3) {
- Raise(eSecurityError, "extending module prohibited");
+ rb_raise(rb_eSecurityError, "extending module prohibited");
}
}
else {
module = rb_define_module_id(node->nd_cname);
- rb_const_set(the_class, node->nd_cname, module);
- rb_set_class_path(module,the_class,rb_id2name(node->nd_cname));
- obj_call_init(module);
+ rb_const_set(ruby_class, node->nd_cname, module);
+ rb_set_class_path(module,ruby_class,rb_id2name(node->nd_cname));
+ rb_obj_call_init(module);
}
- result = module_setup(module, node->nd_body);
+ result = rb_module_setup(module, node->nd_body);
}
break;
@@ -2578,20 +2590,20 @@ rb_eval(self, node)
klass = rb_eval(self, node->nd_recv);
if (FIXNUM_P(klass)) {
- TypeError("No virtual class for Fixnums");
+ rb_raise(rb_eTypeError, "No virtual class for Fixnums");
}
if (NIL_P(klass)) {
- TypeError("No virtual class for nil");
+ rb_raise(rb_eTypeError, "No virtual class for nil");
}
if (rb_special_const_p(klass)) {
- TypeError("No virtual class for special constants");
+ rb_raise(rb_eTypeError, "No virtual class for special constants");
}
if (FL_TEST(CLASS_OF(klass), FL_SINGLETON)) {
rb_clear_cache();
}
klass = rb_singleton_class(klass);
- result = module_setup(klass, node->nd_body);
+ result = rb_module_setup(klass, node->nd_body);
}
break;
@@ -2600,23 +2612,23 @@ rb_eval(self, node)
char buf[20];
char *desc = is_defined(self, node->nd_head, buf);
- if (desc) result = str_new2(desc);
- else result = FALSE;
+ if (desc) result = rb_str_new2(desc);
+ else result = Qfalse;
}
break;
case NODE_NEWLINE:
- sourcefile = node->nd_file;
- sourceline = node->nd_nth;
+ ruby_sourcefile = node->nd_file;
+ ruby_sourceline = node->nd_nth;
if (trace_func) {
- call_trace_func("line", sourcefile, sourceline,
- self, the_frame->last_func);
+ call_trace_func("line", ruby_sourcefile, ruby_sourceline,
+ self, ruby_frame->last_func, 0);
}
node = node->nd_next;
goto again;
default:
- Bug("unknown node type %d", nd_type(node));
+ rb_bug("unknown node type %d", nd_type(node));
}
finish:
CHECK_INTS;
@@ -2624,15 +2636,15 @@ rb_eval(self, node)
}
static VALUE
-module_setup(module, node)
+rb_module_setup(module, node)
VALUE module;
NODE * volatile node;
{
int state;
- VALUE save = the_frame->cbase;
+ VALUE save = ruby_frame->cbase;
VALUE result; /* OK */
- char *file = sourcefile;
- int line = sourceline;
+ char *file = ruby_sourcefile;
+ int line = ruby_sourceline;
TMP_PROTECT;
/* fill c-ref */
@@ -2640,37 +2652,37 @@ module_setup(module, node)
node = node->nd_body;
PUSH_CLASS();
- the_class = module;
+ ruby_class = module;
PUSH_SCOPE();
- if (node->nd_rval) the_frame->cbase = node->nd_rval;
+ if (node->nd_rval) ruby_frame->cbase = node->nd_rval;
if (node->nd_tbl) {
VALUE *vars = TMP_ALLOC(VALUE, node->nd_tbl[0]+1);
*vars++ = (VALUE)node;
- the_scope->local_vars = vars;
- memclear(the_scope->local_vars, node->nd_tbl[0]);
- the_scope->local_tbl = node->nd_tbl;
+ ruby_scope->local_vars = vars;
+ rb_mem_clear(ruby_scope->local_vars, node->nd_tbl[0]);
+ ruby_scope->local_tbl = node->nd_tbl;
}
else {
- the_scope->local_vars = 0;
- the_scope->local_tbl = 0;
+ ruby_scope->local_vars = 0;
+ ruby_scope->local_tbl = 0;
}
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
if (trace_func) {
call_trace_func("class", file, line,
- the_class, the_frame->last_func);
+ ruby_class, ruby_frame->last_func, 0);
}
- result = rb_eval(the_class, node->nd_body);
+ result = rb_eval(ruby_class, node->nd_body);
}
POP_TAG();
POP_SCOPE();
POP_CLASS();
- the_frame->cbase = save;
+ ruby_frame->cbase = save;
if (trace_func) {
- call_trace_func("end", file, line, 0, the_frame->last_func);
+ call_trace_func("end", file, line, 0, ruby_frame->last_func, 0);
}
if (state) JUMP_TAG(state);
@@ -2683,13 +2695,13 @@ rb_respond_to(obj, id)
ID id;
{
if (rb_method_boundp(CLASS_OF(obj), id, 0)) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
-obj_respond_to(argc, argv, obj)
+rb_obj_respond_to(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -2700,19 +2712,19 @@ obj_respond_to(argc, argv, obj)
rb_scan_args(argc, argv, "11", &mid, &priv);
id = rb_to_id(mid);
if (rb_method_boundp(CLASS_OF(obj), id, !RTEST(priv))) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
-mod_method_defined(mod, mid)
+rb_mod_method_defined(mod, mid)
VALUE mod, mid;
{
if (rb_method_boundp(mod, rb_to_id(mid), 1)) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
void
@@ -2721,13 +2733,13 @@ rb_exit(status)
{
if (prot_tag) {
exit_status = status;
- rb_raise(exc_new(eSystemExit, 0, 0));
+ rb_exc_raise(rb_exc_new(rb_eSystemExit, 0, 0));
}
exit(status);
}
static VALUE
-f_exit(argc, argv, obj)
+rb_f_exit(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -2746,10 +2758,10 @@ f_exit(argc, argv, obj)
}
static VALUE
-f_abort()
+rb_f_abort()
{
rb_secure(2);
- if (errinfo) {
+ if (rb_errinfo) {
error_print();
}
rb_exit(1);
@@ -2772,43 +2784,44 @@ rb_longjmp(tag, mesg)
{
VALUE at;
- if (NIL_P(mesg)) mesg = errinfo;
+ if (NIL_P(mesg)) mesg = rb_errinfo;
if (NIL_P(mesg)) {
- mesg = exc_new(eRuntimeError, 0, 0);
+ mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
}
at = get_backtrace(mesg);
- if (NIL_P(at) && sourcefile && !NIL_P(mesg)) {
+ if (NIL_P(at) && ruby_sourcefile && !NIL_P(mesg)) {
at = make_backtrace();
set_backtrace(mesg, at);
}
if (!NIL_P(mesg)) {
- errinfo = mesg;
+ rb_errinfo = mesg;
}
- if (debug && !NIL_P(errinfo) && !obj_is_kind_of(errinfo, eSystemExit)) {
+ if (rb_debug && !NIL_P(rb_errinfo)
+ && !rb_obj_is_kind_of(rb_errinfo, rb_eSystemExit)) {
fprintf(stderr, "Exception `%s' at %s:%d\n",
- rb_class2name(CLASS_OF(errinfo)),
- sourcefile, sourceline);
+ rb_class2name(CLASS_OF(rb_errinfo)),
+ ruby_sourcefile, ruby_sourceline);
}
- trap_restore_mask();
+ rb_trap_restore_mask();
if (trace_func && tag != TAG_FATAL) {
- call_trace_func("raise", sourcefile, sourceline,
- the_frame->self, the_frame->last_func);
+ call_trace_func("raise", ruby_sourcefile, ruby_sourceline,
+ ruby_frame->self, ruby_frame->last_func, 0);
}
JUMP_TAG(tag);
}
void
-rb_raise(mesg)
+rb_exc_raise(mesg)
VALUE mesg;
{
rb_longjmp(TAG_RAISE, mesg);
}
void
-rb_fatal(mesg)
+rb_exc_fatal(mesg)
VALUE mesg;
{
rb_longjmp(TAG_FATAL, mesg);
@@ -2817,11 +2830,11 @@ rb_fatal(mesg)
void
rb_interrupt()
{
- Raise(eInterrupt, "");
+ rb_raise(rb_eInterrupt, "");
}
static VALUE
-f_raise(argc, argv)
+rb_f_raise(argc, argv)
int argc;
VALUE *argv;
{
@@ -2829,7 +2842,7 @@ f_raise(argc, argv)
VALUE etype, mesg;
int n;
- etype = eRuntimeError;
+ etype = rb_eRuntimeError;
mesg = Qnil;
switch (n = rb_scan_args(argc, argv, "03", &arg1, &arg2, &arg3)) {
case 1:
@@ -2847,38 +2860,37 @@ f_raise(argc, argv)
mesg = rb_funcall(etype, rb_intern("new"), 1, mesg);
}
else if (TYPE(mesg) == T_STRING) {
- mesg = exc_new3(eRuntimeError, mesg);
+ mesg = rb_exc_new3(rb_eRuntimeError, mesg);
}
- if (!obj_is_kind_of(mesg, eException)) {
- TypeError("casting non-exception");
+ if (!rb_obj_is_kind_of(mesg, rb_eException)) {
+ rb_raise(rb_eTypeError, "exception object expected");
}
set_backtrace(mesg, arg3);
}
PUSH_FRAME(); /* fake frame */
- *the_frame = *_frame.prev->prev;
+ *ruby_frame = *_frame.prev->prev;
rb_longjmp(TAG_RAISE, mesg);
POP_FRAME();
}
int
-iterator_p()
+rb_iterator_p()
{
- if (the_frame->iter) return TRUE;
- return FALSE;
+ if (ruby_frame->iter) return Qtrue;
+ return Qfalse;
}
static VALUE
-f_iterator_p()
+rb_f_iterator_p()
{
- if (the_frame->prev && the_frame->prev->iter) return TRUE;
- return FALSE;
+ if (ruby_frame->prev && ruby_frame->prev->iter) return Qtrue;
+ return Qfalse;
}
-VALUE
-rb_yield_0(val, self)
- VALUE val;
- volatile VALUE self;
+static VALUE
+rb_yield_0(val, self, klass)
+ VALUE val, self, klass;
{
NODE *node;
volatile VALUE result = Qnil;
@@ -2888,21 +2900,21 @@ rb_yield_0(val, self)
int state;
static unsigned serial = 1;
- if (!iterator_p() || !the_block) {
- Raise(eLocalJumpError, "yield called out of iterator");
+ if (!rb_iterator_p() || !ruby_block) {
+ rb_raise(rb_eLocalJumpError, "yield called out of iterator");
}
PUSH_VARS();
PUSH_CLASS();
- block = the_block;
+ block = ruby_block;
frame = block->frame;
- frame.prev = the_frame;
- the_frame = &(frame);
- old_scope = the_scope;
- the_scope = block->scope;
- the_block = block->prev;
- mark_dvar(block->d_vars);
- the_class = block->klass;
+ frame.prev = ruby_frame;
+ ruby_frame = &(frame);
+ old_scope = ruby_scope;
+ ruby_scope = block->scope;
+ ruby_block = block->prev;
+ ruby_dyna_vars = block->d_vars;
+ ruby_class = klass?klass:block->klass;
if (!self) self = block->self;
node = block->body;
if (block->var) {
@@ -2948,9 +2960,9 @@ rb_yield_0(val, self)
POP_ITER();
POP_CLASS();
POP_VARS();
- the_block = block;
- the_frame = the_frame->prev;
- the_scope = old_scope;
+ ruby_block = block;
+ ruby_frame = ruby_frame->prev;
+ ruby_scope = old_scope;
if (state) JUMP_TAG(state);
return result;
}
@@ -2959,13 +2971,13 @@ VALUE
rb_yield(val)
VALUE val;
{
- return rb_yield_0(val, 0);
+ return rb_yield_0(val, 0, 0);
}
static VALUE
-f_loop()
+rb_f_loop()
{
- for (;;) { rb_yield(Qnil); }
+ for (;;) { rb_yield_0(Qnil, 0, 0); }
}
static VALUE
@@ -2990,10 +3002,10 @@ massign(self, node, val)
}
if (node->nd_args) {
if (!list && i<len) {
- assign(self, node->nd_args, ary_new4(len-i, RARRAY(val)->ptr+i));
+ assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i));
}
else {
- assign(self, node->nd_args, ary_new2(0));
+ assign(self, node->nd_args, rb_ary_new2(0));
}
}
}
@@ -3023,13 +3035,13 @@ assign(self, lhs, val)
break;
case NODE_LASGN:
- if (the_scope->local_vars == 0)
- Bug("unexpected iterator variable assignment");
- the_scope->local_vars[lhs->nd_cnt] = val;
+ if (ruby_scope->local_vars == 0)
+ rb_bug("unexpected iterator variable assignment");
+ ruby_scope->local_vars[lhs->nd_cnt] = val;
break;
case NODE_DASGN:
- dyna_var_asgn(lhs->nd_vid, val);
+ rb_dvar_asgn(lhs->nd_vid, val);
break;
case NODE_DASGN_PUSH:
@@ -3037,7 +3049,7 @@ assign(self, lhs, val)
break;
case NODE_CASGN:
- rb_const_set(the_class, lhs->nd_vid, val);
+ rb_const_set(ruby_class, lhs->nd_vid, val);
break;
case NODE_MASGN:
@@ -3064,7 +3076,7 @@ assign(self, lhs, val)
break;
default:
- Bug("bug in variable assignment");
+ rb_bug("bug in variable assignment");
break;
}
}
@@ -3077,7 +3089,7 @@ rb_iterate(it_proc, data1, bl_proc, data2)
int state;
volatile VALUE retval = Qnil;
NODE *node = NEW_CFUNC(bl_proc, data2);
- VALUE self = TopSelf;
+ VALUE self = rb_top_self;
iter_retry:
PUSH_ITER(ITER_PRE);
@@ -3088,7 +3100,7 @@ rb_iterate(it_proc, data1, bl_proc, data2)
if (state == 0) {
retval = (*it_proc)(data1);
}
- if (the_block->tag->dst == state) {
+ if (ruby_block->tag->dst == state) {
state &= TAG_MASK;
if (state == TAG_RETURN) {
retval = prot_tag->retval;
@@ -3127,7 +3139,7 @@ handle_rescue(self, node)
TMP_PROTECT;
if (!node->nd_args) {
- return obj_is_kind_of(errinfo, eStandardError);
+ return rb_obj_is_kind_of(rb_errinfo, rb_eStandardError);
}
BEGIN_CALLARGS;
@@ -3135,10 +3147,10 @@ handle_rescue(self, node)
END_CALLARGS;
while (argc--) {
- if (!obj_is_kind_of(argv[0], cModule)) {
- TypeError("class or module required for rescue clause");
+ if (!rb_obj_is_kind_of(argv[0], rb_cModule)) {
+ rb_raise(rb_eTypeError, "class or module required for rescue clause");
}
- if (obj_is_kind_of(errinfo, argv[0])) return 1;
+ if (rb_obj_is_kind_of(rb_errinfo, argv[0])) return 1;
argv++;
}
return 0;
@@ -3151,18 +3163,18 @@ rb_rescue(b_proc, data1, r_proc, data2)
{
int state;
volatile VALUE result;
- volatile VALUE e_info = errinfo;
+ volatile VALUE e_info = rb_errinfo;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
retry_entry:
result = (*b_proc)(data1);
}
- else if (state == TAG_RAISE && obj_is_kind_of(errinfo, eStandardError)) {
+ else if (state == TAG_RAISE && rb_obj_is_kind_of(rb_errinfo, rb_eStandardError)) {
if (r_proc) {
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- result = (*r_proc)(data2, errinfo);
+ result = (*r_proc)(data2, rb_errinfo);
}
POP_TAG();
if (state == TAG_RETRY) {
@@ -3175,7 +3187,7 @@ rb_rescue(b_proc, data1, r_proc, data2)
state = 0;
}
if (state == 0) {
- errinfo = e_info;
+ rb_errinfo = e_info;
}
}
POP_TAG();
@@ -3203,9 +3215,7 @@ rb_ensure(b_proc, data1, e_proc, data2)
(*e_proc)(data2);
return_value(retval);
- if (state) {
- JUMP_TAG(state);
- }
+ if (state) JUMP_TAG(state);
return result;
}
@@ -3216,7 +3226,7 @@ static int last_call_status;
#define CSTAT_VCALL 4
static VALUE
-f_missing(argc, argv, obj)
+rb_f_missing(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -3224,8 +3234,8 @@ f_missing(argc, argv, obj)
ID id;
VALUE desc = 0;
char *format = 0;
- char *file = sourcefile;
- int line = sourceline;
+ char *file = ruby_sourcefile;
+ int line = ruby_sourceline;
id = FIX2INT(argv[0]);
argc--; argv++;
@@ -3235,13 +3245,13 @@ f_missing(argc, argv, obj)
format = "undefined method `%s' for nil";
break;
case T_TRUE:
- format = "undefined method `%s' for TRUE";
+ format = "undefined method `%s' for Qtrue";
break;
case T_FALSE:
- format = "undefined method `%s' for FALSE";
+ format = "undefined method `%s' for Qfalse";
break;
case T_OBJECT:
- desc = any_to_s(obj);
+ desc = rb_any_to_s(obj);
break;
default:
desc = rb_inspect(obj);
@@ -3254,7 +3264,7 @@ f_missing(argc, argv, obj)
if (last_call_status & CSTAT_PROT) {
format = "protected method `%s' called for %s";
}
- else if (iterator_p()) {
+ else if (rb_iterator_p()) {
format = "undefined iterator `%s' for %s";
}
else if (last_call_status & CSTAT_VCALL) {
@@ -3268,18 +3278,18 @@ f_missing(argc, argv, obj)
format = "undefined method `%s' for %s";
}
if (RSTRING(desc)->len > 65) {
- desc = any_to_s(obj);
+ desc = rb_any_to_s(obj);
}
}
- sourcefile = file;
- sourceline = line;
+ ruby_sourcefile = file;
+ ruby_sourceline = line;
PUSH_FRAME(); /* fake frame */
- *the_frame = *_frame.prev->prev;
+ *ruby_frame = *_frame.prev->prev;
- NameError(format,
- rb_id2name(id),
- desc?(char*)RSTRING(desc)->ptr:"");
+ rb_raise(rb_eNameError, format,
+ rb_id2name(id),
+ desc?(char*)RSTRING(desc)->ptr:"");
POP_FRAME();
return Qnil; /* not reached */
@@ -3311,24 +3321,111 @@ rb_undefined(obj, id, argc, argv, call_status)
extern int _stacksize;
# define STACK_LEVEL_MAX (_stacksize - 4096)
#else
-# define STACK_LEVEL_MAX 655350
+# define STACK_LEVEL_MAX 655300
#endif
#endif
-extern VALUE *gc_stack_start;
+extern VALUE *rb_gc_stack_start;
static int
stack_length()
{
VALUE pos;
#ifdef sparc
- return gc_stack_start - &pos + 0x80;
+ return rb_gc_stack_start - &pos + 0x80;
#else
- return (&pos < gc_stack_start) ? gc_stack_start - &pos
- : &pos - gc_stack_start;
+ return (&pos < rb_gc_stack_start) ? rb_gc_stack_start - &pos
+ : &pos - rb_gc_stack_start;
#endif
}
static VALUE
+call_cfunc(func, recv, len, argc, argv)
+ VALUE (*func)();
+ VALUE recv;
+ int len, argc;
+ VALUE *argv;
+{
+ if (len >= 0 && argc != len) {
+ rb_raise(rb_eArgError, "Wrong # of arguments(%d for %d)",
+ argc, len);
+ }
+
+ switch (len) {
+ case -2:
+ return (*func)(recv, rb_ary_new4(argc, argv));
+ break;
+ case -1:
+ return (*func)(argc, argv, recv);
+ break;
+ case 0:
+ return (*func)(recv);
+ break;
+ case 1:
+ return (*func)(recv, argv[0]);
+ break;
+ case 2:
+ return (*func)(recv, argv[0], argv[1]);
+ break;
+ case 3:
+ return (*func)(recv, argv[0], argv[1], argv[2]);
+ break;
+ case 4:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3]);
+ break;
+ case 5:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4]);
+ break;
+ case 6:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5]);
+ break;
+ case 7:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6]);
+ break;
+ case 8:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7]);
+ break;
+ case 9:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8]);
+ break;
+ case 10:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8], argv[9]);
+ break;
+ case 11:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]);
+ break;
+ case 12:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8], argv[9],
+ argv[10], argv[11]);
+ break;
+ case 13:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8], argv[9], argv[10],
+ argv[11], argv[12]);
+ break;
+ case 14:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8], argv[9], argv[10],
+ argv[11], argv[12], argv[13]);
+ break;
+ case 15:
+ return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4],
+ argv[5], argv[6], argv[7], argv[8], argv[9], argv[10],
+ argv[11], argv[12], argv[13], argv[14]);
+ break;
+ default:
+ rb_raise(rb_eArgError, "too many arguments(%d)", len);
+ break;
+ }
+}
+
+static VALUE
rb_call0(klass, recv, id, argc, argv, body, nosuper)
VALUE klass, recv;
ID id;
@@ -3343,7 +3440,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
static int tick;
TMP_PROTECT;
- switch (the_iter->iter) {
+ switch (ruby_iter->iter) {
case ITER_PRE:
itr = ITER_CUR;
break;
@@ -3354,125 +3451,46 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
}
if ((++tick & 0xfff) == 0 && stack_length() > STACK_LEVEL_MAX)
- Raise(eSysStackError, "stack level too deep");
+ rb_raise(rb_eSysStackError, "stack level too deep");
PUSH_ITER(itr);
PUSH_FRAME();
- the_frame->last_func = id;
- the_frame->last_class = nosuper?0:klass;
- the_frame->self = recv;
- the_frame->argc = argc;
- the_frame->argv = argv;
+
+ ruby_frame->last_func = id;
+ ruby_frame->last_class = nosuper?0:klass;
+ ruby_frame->self = recv;
+ ruby_frame->argc = argc;
+ ruby_frame->argv = argv;
switch (nd_type(body)) {
case NODE_CFUNC:
{
int len = body->nd_argc;
- if (len >= 0 && argc != len) {
- ArgError("Wrong # of arguments(%d for %d)", argc, len);
+ if (len < -2) {
+ rb_bug("bad argc(%d) specified for `%s(%s)'",
+ len, rb_class2name(klass), rb_id2name(id));
}
-
- switch (len) {
- case -2:
- result = (*body->nd_cfnc)(recv, ary_new4(argc, argv));
- break;
- case -1:
- result = (*body->nd_cfnc)(argc, argv, recv);
- break;
- case 0:
- result = (*body->nd_cfnc)(recv);
- break;
- case 1:
- result = (*body->nd_cfnc)(recv, argv[0]);
- break;
- case 2:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1]);
- break;
- case 3:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2]);
- break;
- case 4:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3]);
- break;
- case 5:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4]);
- break;
- case 6:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5]);
- break;
- case 7:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6]);
- break;
- case 8:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7]);
- break;
- case 9:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8]);
- break;
- case 10:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8],
- argv[6], argv[7], argv[8],
- argv[9]);
- break;
- case 11:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8],
- argv[6], argv[7], argv[8],
- argv[9], argv[10]);
- break;
- case 12:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8],
- argv[6], argv[7], argv[8],
- argv[9], argv[10], argv[11]);
- break;
- case 13:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8],
- argv[6], argv[7], argv[8],
- argv[9], argv[10], argv[11],
- argv[12]);
- break;
- case 14:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8],
- argv[6], argv[7], argv[8],
- argv[9], argv[10], argv[11],
- argv[12], argv[13]);
- break;
- case 15:
- result = (*body->nd_cfnc)(recv, argv[0], argv[1], argv[2],
- argv[3], argv[4], argv[5],
- argv[6], argv[7], argv[8],
- argv[6], argv[7], argv[8],
- argv[9], argv[10], argv[11],
- argv[12], argv[13], argv[14]);
- break;
- default:
- if (len < 0) {
- Bug("bad argc(%d) specified for `%s(%s)'",
- len, rb_class2name(klass), rb_id2name(id));
+ if (trace_func) {
+ int state;
+ char *file = ruby_frame->prev->file;
+ int line = ruby_frame->prev->line;
+ if (!file) {
+ file = ruby_sourcefile;
+ line = ruby_sourceline;
}
- else {
- ArgError("too many arguments(%d)", len);
+
+ call_trace_func("c-call", 0, 0, 0, id, 0);
+ PUSH_TAG(PROT_FUNC);
+ if ((state = EXEC_TAG()) == 0) {
+ result = call_cfunc(body->nd_cfnc, recv, len, argc, argv);
}
- break;
+ POP_TAG();
+ call_trace_func("c-return", 0, 0, recv, id, klass);
+ if (state) JUMP_TAG(state);
+ }
+ else {
+ result = call_cfunc(body->nd_cfnc, recv, len, argc, argv);
}
}
break;
@@ -3492,17 +3510,17 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
PUSH_SCOPE();
- if (body->nd_rval) the_frame->cbase = body->nd_rval;
+ if (body->nd_rval) ruby_frame->cbase = body->nd_rval;
if (body->nd_tbl) {
local_vars = TMP_ALLOC(VALUE, body->nd_tbl[0]+1);
*local_vars++ = (VALUE)body;
- memclear(local_vars, body->nd_tbl[0]);
- the_scope->local_tbl = body->nd_tbl;
- the_scope->local_vars = local_vars;
+ rb_mem_clear(local_vars, body->nd_tbl[0]);
+ ruby_scope->local_tbl = body->nd_tbl;
+ ruby_scope->local_vars = local_vars;
}
else {
- local_vars = the_scope->local_vars = 0;
- the_scope->local_tbl = 0;
+ local_vars = ruby_scope->local_vars = 0;
+ ruby_scope->local_tbl = 0;
}
b2 = body = body->nd_body;
@@ -3523,12 +3541,13 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
}
if (node) {
if (nd_type(node) != NODE_ARGS) {
- Bug("no argument-node");
+ rb_bug("no argument-node");
}
i = node->nd_cnt;
if (i > argc) {
- ArgError("Wrong # of arguments(%d for %d)", argc, i);
+ rb_raise(rb_eArgError, "Wrong # of arguments(%d for %d)",
+ argc, i);
}
if (node->nd_rest == -1) {
int opt = argc - i;
@@ -3539,7 +3558,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
optnode = optnode->nd_next;
}
if (opt > 0) {
- ArgError("Wrong # of arguments(%d for %d)",
+ rb_raise(rb_eArgError, "Wrong # of arguments(%d for %d)",
argc, argc-opt);
}
}
@@ -3562,16 +3581,16 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
}
if (node->nd_rest >= 0) {
if (argc > 0)
- local_vars[node->nd_rest]=ary_new4(argc,argv);
+ local_vars[node->nd_rest]=rb_ary_new4(argc,argv);
else
- local_vars[node->nd_rest]=ary_new2(0);
+ local_vars[node->nd_rest]=rb_ary_new2(0);
}
}
}
if (trace_func) {
call_trace_func("call", b2->nd_file, nd_line(b2),
- recv, the_frame->last_func);
+ recv, ruby_frame->last_func, 0);
}
result = rb_eval(recv, body);
}
@@ -3583,30 +3602,31 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
POP_TAG();
POP_SCOPE();
if (trace_func) {
- char *file = the_frame->prev->file;
- int line = the_frame->prev->line;
+ char *file = ruby_frame->prev->file;
+ int line = ruby_frame->prev->line;
if (!file) {
- file = sourcefile;
- line = sourceline;
+ file = ruby_sourcefile;
+ line = ruby_sourceline;
}
- call_trace_func("return", file, line, 0, the_frame->last_func);
+ call_trace_func("return", file, line, recv,
+ ruby_frame->last_func, klass);
}
switch (state) {
case 0:
break;
case TAG_NEXT:
- Raise(eLocalJumpError, "unexpected next");
+ rb_raise(rb_eLocalJumpError, "unexpected next");
break;
case TAG_BREAK:
- Raise(eLocalJumpError, "unexpected break");
+ rb_raise(rb_eLocalJumpError, "unexpected break");
break;
case TAG_REDO:
- Raise(eLocalJumpError, "unexpected redo");
+ rb_raise(rb_eLocalJumpError, "unexpected redo");
break;
case TAG_RETRY:
- if (!iterator_p()) {
- Raise(eLocalJumpError, "retry outside of rescue clause");
+ if (!rb_iterator_p()) {
+ rb_raise(rb_eLocalJumpError, "retry outside of rescue clause");
}
default:
JUMP_TAG(state);
@@ -3641,7 +3661,8 @@ rb_call(klass, recv, mid, argc, argv, scope)
}
else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
if (scope == 3) {
- NameError("super: no superclass method `%s'", rb_id2name(mid));
+ rb_raise(rb_eNameError, "super: no superclass method `%s'",
+ rb_id2name(mid));
}
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
}
@@ -3651,7 +3672,7 @@ rb_call(klass, recv, mid, argc, argv, scope)
return rb_undefined(recv, mid, argc, argv, CSTAT_PRIV);
/* self must be kind of a specified form for private method */
- if ((noex & NOEX_PROTECTED) && !obj_is_kind_of(the_frame->self, klass))
+ if ((noex & NOEX_PROTECTED) && !rb_obj_is_kind_of(ruby_frame->self, klass))
return rb_undefined(recv, mid, argc, argv, CSTAT_PROT);
return rb_call0(klass, recv, id, argc, argv, body, noex & NOEX_UNDEF);
@@ -3673,17 +3694,17 @@ rb_apply(recv, mid, args)
}
static VALUE
-f_send(argc, argv, recv)
+rb_f_send(argc, argv, recv)
int argc;
VALUE *argv;
VALUE recv;
{
VALUE vid;
- if (argc == 0) ArgError("no method name given");
+ if (argc == 0) rb_raise(rb_eArgError, "no method name given");
vid = *argv++; argc--;
- PUSH_ITER(iterator_p()?ITER_PRE:ITER_NOT);
+ PUSH_ITER(rb_iterator_p()?ITER_PRE:ITER_NOT);
vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, 1);
POP_ITER();
@@ -3745,22 +3766,23 @@ static VALUE
backtrace(lev)
int lev;
{
- struct FRAME *frame = the_frame;
+ struct FRAME *frame = ruby_frame;
char buf[BUFSIZ];
VALUE ary;
int slev = safe_level;
safe_level = 0;
- ary = ary_new();
+ ary = rb_ary_new();
if (lev < 0) {
if (frame->last_func) {
- snprintf(buf, BUFSIZ, "%s:%d:in `%s'", sourcefile, sourceline,
- rb_id2name(frame->last_func));
+ snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
+ ruby_sourcefile, ruby_sourceline,
+ rb_id2name(frame->last_func));
}
else {
- snprintf(buf, BUFSIZ, "%s:%d", sourcefile, sourceline);
+ snprintf(buf, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline);
}
- ary_push(ary, str_new2(buf));
+ rb_ary_push(ary, rb_str_new2(buf));
}
else {
while (lev-- > 0) {
@@ -3771,13 +3793,13 @@ backtrace(lev)
while (frame && frame->file) {
if (frame->prev && frame->prev->last_func) {
snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
- frame->file, frame->line,
- rb_id2name(frame->prev->last_func));
+ frame->file, frame->line,
+ rb_id2name(frame->prev->last_func));
}
else {
snprintf(buf, BUFSIZ, "%s:%d", frame->file, frame->line);
}
- ary_push(ary, str_new2(buf));
+ rb_ary_push(ary, rb_str_new2(buf));
frame = frame->prev;
}
safe_level = slev;
@@ -3785,7 +3807,7 @@ backtrace(lev)
}
static VALUE
-f_caller(argc, argv)
+rb_f_caller(argc, argv)
int argc;
VALUE *argv;
{
@@ -3796,7 +3818,7 @@ f_caller(argc, argv)
if (NIL_P(level)) lev = 1;
else lev = NUM2INT(level);
- if (lev < 0) ArgError("negative level(%d)", lev);
+ if (lev < 0) rb_raise(rb_eArgError, "negative level(%d)", lev);
return backtrace(lev);
}
@@ -3826,7 +3848,7 @@ make_backtrace()
ID
rb_frame_last_func()
{
- return the_frame->last_func;
+ return ruby_frame->last_func;
}
static NODE*
@@ -3837,10 +3859,10 @@ compile(src, place)
NODE *node;
Check_Type(src, T_STRING);
- if (place == 0) place = sourcefile;
- node = compile_string(place, RSTRING(src)->ptr, RSTRING(src)->len);
+ if (place == 0) place = ruby_sourcefile;
+ node = rb_compile_string(place, RSTRING(src)->ptr, RSTRING(src)->len);
- if (nerrs == 0) return node;
+ if (ruby_nerrs == 0) return node;
return 0;
}
@@ -3854,60 +3876,63 @@ eval(self, src, scope, file, line)
volatile VALUE result = Qnil;
struct SCOPE * volatile old_scope;
struct BLOCK * volatile old_block;
+ struct BLOCK * volatile old_call_block;
struct RVarmap * volatile old_d_vars;
int volatile old_vmode;
struct FRAME frame;
- char *filesave = sourcefile;
- int linesave = sourceline;
- volatile int iter = the_frame->iter;
+ char *filesave = ruby_sourcefile;
+ int linesave = ruby_sourceline;
+ volatile int iter = ruby_frame->iter;
int state;
if (file == 0) {
- file = sourcefile;
- line = sourceline;
+ file = ruby_sourcefile;
+ line = ruby_sourceline;
}
if (!NIL_P(scope)) {
- if (!obj_is_block(scope)) {
- TypeError("wrong argument type %s (expected Proc/Binding)",
- rb_class2name(CLASS_OF(scope)));
+ if (!rb_obj_is_block(scope)) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
+ rb_class2name(CLASS_OF(scope)));
}
Data_Get_Struct(scope, struct BLOCK, data);
/* PUSH BLOCK from data */
frame = data->frame;
- frame.prev = the_frame;
- the_frame = &(frame);
- old_scope = the_scope;
- the_scope = data->scope;
- old_block = the_block;
- the_block = data->prev;
- old_d_vars = the_dyna_vars;
- the_dyna_vars = data->d_vars;
+ frame.prev = ruby_frame;
+ ruby_frame = &(frame);
+ old_scope = ruby_scope;
+ ruby_scope = data->scope;
+ old_call_block = ruby_calling_block;
+ ruby_calling_block = data;
+ old_block = ruby_block;
+ ruby_block = data->prev;
+ old_d_vars = ruby_dyna_vars;
+ ruby_dyna_vars = data->d_vars;
old_vmode = scope_vmode;
scope_vmode = data->vmode;
self = data->self;
- the_frame->iter = data->iter;
+ ruby_frame->iter = data->iter;
}
else {
- if (the_frame->prev) {
- the_frame->iter = the_frame->prev->iter;
+ if (ruby_frame->prev) {
+ ruby_frame->iter = ruby_frame->prev->iter;
}
}
PUSH_CLASS();
- the_class = ((NODE*)the_frame->cbase)->nd_clss;
+ ruby_class = ((NODE*)ruby_frame->cbase)->nd_clss;
rb_in_eval++;
- if (TYPE(the_class) == T_ICLASS) {
- the_class = RBASIC(the_class)->klass;
+ if (TYPE(ruby_class) == T_ICLASS) {
+ ruby_class = RBASIC(ruby_class)->klass;
}
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- sourcefile = file;
- sourceline = line;
+ ruby_sourcefile = file;
+ ruby_sourceline = line;
compile(src, file);
- if (nerrs > 0) {
+ if (ruby_nerrs > 0) {
compile_error(0);
}
result = eval_node(self);
@@ -3916,38 +3941,39 @@ eval(self, src, scope, file, line)
POP_CLASS();
rb_in_eval--;
if (!NIL_P(scope)) {
- the_frame = the_frame->prev;
- the_scope = old_scope;
- the_block = old_block;
- data->d_vars = the_dyna_vars;
- the_dyna_vars = old_d_vars;
+ ruby_frame = ruby_frame->prev;
+ ruby_scope = old_scope;
+ ruby_block = old_block;
+ ruby_calling_block = old_call_block;
+ data->d_vars = ruby_dyna_vars;
+ ruby_dyna_vars = old_d_vars;
data->vmode = scope_vmode; /* write back visibility mode */
scope_vmode = old_vmode;
}
else {
- the_frame->iter = iter;
+ ruby_frame->iter = iter;
}
- sourcefile = filesave;
- sourceline = linesave;
+ ruby_sourcefile = filesave;
+ ruby_sourceline = linesave;
if (state) {
if (state == TAG_RAISE) {
VALUE err;
VALUE errat;
- errat = get_backtrace(errinfo);
+ errat = get_backtrace(rb_errinfo);
if (strcmp(file, "(eval)") == 0) {
- if (sourceline > 1) {
+ if (ruby_sourceline > 1) {
err = RARRAY(errat)->ptr[0];
- str_cat(err, ": ", 2);
- str_concat(err, errinfo);
+ rb_str_cat(err, ": ", 2);
+ rb_str_concat(err, rb_errinfo);
}
else {
- err = str_dup(errinfo);
+ err = rb_str_dup(rb_errinfo);
}
errat = Qnil;
- rb_raise(exc_new3(CLASS_OF(errinfo), err));
+ rb_exc_raise(rb_exc_new3(CLASS_OF(rb_errinfo), err));
}
- rb_raise(errinfo);
+ rb_exc_raise(rb_errinfo);
}
JUMP_TAG(state);
}
@@ -3956,7 +3982,7 @@ eval(self, src, scope, file, line)
}
static VALUE
-f_eval(argc, argv, self)
+rb_f_eval(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
@@ -3987,16 +4013,16 @@ exec_under(func, under, args)
VALUE val; /* OK */
int state;
int mode;
- VALUE cbase = the_frame->cbase;
+ VALUE cbase = ruby_frame->cbase;
PUSH_CLASS();
- the_class = under;
+ ruby_class = under;
PUSH_FRAME();
- the_frame->last_func = _frame.prev->last_func;
- the_frame->last_class = _frame.prev->last_class;
- the_frame->argc = _frame.prev->argc;
- the_frame->argv = _frame.prev->argv;
- the_frame->cbase = (VALUE)node_newnode(NODE_CREF,under,0,cbase);
+ ruby_frame->last_func = _frame.prev->last_func;
+ ruby_frame->last_class = _frame.prev->last_class;
+ ruby_frame->argc = _frame.prev->argc;
+ ruby_frame->argv = _frame.prev->argv;
+ ruby_frame->cbase = (VALUE)rb_node_newnode(NODE_CREF,under,0,cbase);
mode = scope_vmode;
SCOPE_SET(SCOPE_PUBLIC);
PUSH_TAG(PROT_NONE);
@@ -4038,7 +4064,7 @@ static VALUE
yield_under_i(self)
VALUE self;
{
- return rb_yield_0(self, self);
+ return rb_yield_0(self, self, ruby_class);
}
static VALUE
@@ -4049,17 +4075,18 @@ yield_under(under, self)
}
static VALUE
-obj_instance_eval(argc, argv, self)
+rb_obj_instance_eval(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
{
char *file = 0;
int line = 0;
+ VALUE klass;
if (argc == 0) {
- if (!iterator_p()) {
- ArgError("block not supplied");
+ if (!rb_iterator_p()) {
+ rb_raise(rb_eArgError, "block not supplied");
}
}
else if (argc < 4) {
@@ -4068,21 +4095,27 @@ obj_instance_eval(argc, argv, self)
if (argc > 2) line = NUM2INT(argv[2]);
}
else {
- ArgError("Wrong # of arguments: %s(src) or %s{..}",
- rb_id2name(the_frame->last_func),
- rb_id2name(the_frame->last_func));
+ rb_raise(rb_eArgError, "Wrong # of arguments: %s(src) or %s{..}",
+ rb_id2name(ruby_frame->last_func),
+ rb_id2name(ruby_frame->last_func));
}
+ if (rb_special_const_p(self)) {
+ klass = Qnil;
+ }
+ else {
+ klass = rb_singleton_class(self);
+ }
if (argc == 0) {
- return yield_under(rb_singleton_class(self), self);
+ return yield_under(klass, self);
}
else {
- return eval_under(rb_singleton_class(self), self, argv[0], file, line);
+ return eval_under(klass, self, argv[0], file, line);
}
}
static VALUE
-mod_module_eval(argc, argv, mod)
+rb_mod_module_eval(argc, argv, mod)
int argc;
VALUE *argv;
VALUE mod;
@@ -4091,8 +4124,8 @@ mod_module_eval(argc, argv, mod)
int line = 0;
if (argc == 0) {
- if (!iterator_p()) {
- ArgError("block not supplied");
+ if (!rb_iterator_p()) {
+ rb_raise(rb_eArgError, "block not supplied");
}
}
else if (argc < 4) {
@@ -4101,9 +4134,9 @@ mod_module_eval(argc, argv, mod)
if (argc > 2) line = NUM2INT(argv[2]);
}
else {
- ArgError("Wrong # of arguments: %s(src) or %s{..}",
- rb_id2name(the_frame->last_func),
- rb_id2name(the_frame->last_func));
+ rb_raise(rb_eArgError, "Wrong # of arguments: %s(src) or %s{..}",
+ rb_id2name(ruby_frame->last_func),
+ rb_id2name(ruby_frame->last_func));
}
if (argc == 0) {
@@ -4151,7 +4184,7 @@ find_file(file)
for (i=0;i<RARRAY(rb_load_path)->len;i++) {
Check_SafeStr(RARRAY(rb_load_path)->ptr[i]);
}
- vpath = ary_join(rb_load_path, str_new2(RUBY_LIB_SEP));
+ vpath = rb_ary_join(rb_load_path, rb_str_new2(RUBY_LIB_SEP));
Check_SafeStr(vpath);
path = RSTRING(vpath)->ptr;
}
@@ -4163,7 +4196,7 @@ find_file(file)
}
VALUE
-f_load(obj, fname)
+rb_f_load(obj, fname)
VALUE obj, fname;
{
int state;
@@ -4174,16 +4207,19 @@ f_load(obj, fname)
Check_SafeStr(fname);
#ifndef __MACOS__
if (RSTRING(fname)->ptr[0] == '~') {
- fname = file_s_expand_path(1, &fname);
+ fname = rb_file_s_expand_path(1, &fname);
}
#endif
file = find_file(RSTRING(fname)->ptr);
- if (!file) LoadError("No such file to load -- %s", RSTRING(fname)->ptr);
+ if (!file) {
+ rb_raise(rb_eLoadError, "No such file to load -- %s",
+ RSTRING(fname)->ptr);
+ }
PUSH_VARS();
PUSH_TAG(PROT_NONE);
PUSH_CLASS();
- the_class = cObject;
+ ruby_class = rb_cObject;
PUSH_SCOPE();
if (top_scope->local_tbl) {
int len = top_scope->local_tbl[0]+1;
@@ -4192,37 +4228,37 @@ f_load(obj, fname)
*vars++ = 0;
MEMCPY(tbl, top_scope->local_tbl, ID, len);
MEMCPY(vars, top_scope->local_vars, ID, len-1);
- the_scope->local_tbl = tbl;
- the_scope->local_vars = vars;
+ ruby_scope->local_tbl = tbl;
+ ruby_scope->local_vars = vars;
}
/* default visibility is private at loading toplevel */
SCOPE_SET(SCOPE_PRIVATE);
state = EXEC_TAG();
- last_func = the_frame->last_func;
- the_frame->last_func = 0;
+ last_func = ruby_frame->last_func;
+ ruby_frame->last_func = 0;
if (state == 0) {
rb_in_eval++;
rb_load_file(file);
rb_in_eval--;
- if (nerrs == 0) {
- eval_node(TopSelf);
+ if (ruby_nerrs == 0) {
+ eval_node(rb_top_self);
}
}
- the_frame->last_func = last_func;
- if (the_scope->flag == SCOPE_ALLOCA && the_scope->local_tbl) {
- free(the_scope->local_tbl);
+ ruby_frame->last_func = last_func;
+ if (ruby_scope->flag == SCOPE_ALLOCA && ruby_scope->local_tbl) {
+ free(ruby_scope->local_tbl);
}
POP_SCOPE();
POP_CLASS();
POP_TAG();
POP_VARS();
- if (nerrs > 0) {
- rb_raise(errinfo);
+ if (ruby_nerrs > 0) {
+ rb_exc_raise(rb_errinfo);
}
if (state) JUMP_TAG(state);
- return TRUE;
+ return Qtrue;
}
static VALUE rb_features;
@@ -4239,20 +4275,20 @@ rb_provided(feature)
pend = p + RARRAY(rb_features)->len;
while (p < pend) {
f = STR2CSTR(*p);
- if (strcmp(f, feature) == 0) return TRUE;
+ if (strcmp(f, feature) == 0) return Qtrue;
len = strlen(feature);
if (strncmp(f, feature, len) == 0
&& (strcmp(f+len, ".rb") == 0 ||strcmp(f+len, ".o") == 0)) {
- return TRUE;
+ return Qtrue;
}
p++;
}
- return FALSE;
+ return Qfalse;
}
#ifdef THREAD
-static int thread_loading _((char*));
-static void thread_loading_done _((void));
+static int rb_thread_loading _((char*));
+static void rb_thread_loading_done _((void));
#endif
void
@@ -4270,12 +4306,12 @@ rb_provide(feature)
strcpy(ext, ".o");
feature = buf;
}
- ary_push(rb_features, str_new2(feature));
+ rb_ary_push(rb_features, rb_str_new2(feature));
}
}
VALUE
-f_require(obj, fname)
+rb_f_require(obj, fname)
VALUE obj, fname;
{
char *ext, *file, *feature, *buf; /* OK */
@@ -4283,7 +4319,7 @@ f_require(obj, fname)
Check_SafeStr(fname);
if (rb_provided(RSTRING(fname)->ptr))
- return FALSE;
+ return Qfalse;
ext = strrchr(RSTRING(fname)->ptr, '.');
if (ext) {
@@ -4310,60 +4346,63 @@ f_require(obj, fname)
}
}
buf = ALLOCA_N(char, strlen(RSTRING(fname)->ptr) + 5);
- sprintf(buf, "%s.rb", RSTRING(fname)->ptr);
+ strcpy(buf, RSTRING(fname)->ptr);
+ strcat(buf, ".rb");
file = find_file(buf);
if (file) {
- fname = str_new2(file);
+ fname = rb_str_new2(file);
feature = buf;
goto rb_load;
}
- sprintf(buf, "%s%s", RSTRING(fname)->ptr, DLEXT);
+ strcpy(buf, RSTRING(fname)->ptr);
+ strcat(buf, DLEXT);
file = find_file(buf);
if (file) {
feature = buf;
goto dyna_load;
}
- LoadError("No such file to load -- %s", RSTRING(fname)->ptr);
+ rb_raise(rb_eLoadError, "No such file to load -- %s",
+ RSTRING(fname)->ptr);
dyna_load:
#ifdef THREAD
- if (thread_loading(feature)) return FALSE;
+ if (rb_thread_loading(feature)) return Qfalse;
else {
int state;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
#endif
- load = str_new2(file);
+ load = rb_str_new2(file);
file = RSTRING(load)->ptr;
dln_load(file);
rb_provide(feature);
#ifdef THREAD
}
POP_TAG();
- thread_loading_done();
+ rb_thread_loading_done();
if (state) JUMP_TAG(state);
}
#endif
- return TRUE;
+ return Qtrue;
rb_load:
#ifdef THREAD
- if (thread_loading(feature)) return FALSE;
+ if (rb_thread_loading(feature)) return Qfalse;
else {
int state;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
#endif
- f_load(obj, fname);
+ rb_f_load(obj, fname);
rb_provide(feature);
#ifdef THREAD
}
POP_TAG();
- thread_loading_done();
+ rb_thread_loading_done();
if (state) JUMP_TAG(state);
}
#endif
- return TRUE;
+ return Qtrue;
}
static void
@@ -4381,7 +4420,7 @@ set_method_visibility(self, argc, argv, ex)
}
static VALUE
-mod_public(argc, argv, module)
+rb_mod_public(argc, argv, module)
int argc;
VALUE *argv;
VALUE module;
@@ -4396,7 +4435,7 @@ mod_public(argc, argv, module)
}
static VALUE
-mod_protected(argc, argv, module)
+rb_mod_protected(argc, argv, module)
int argc;
VALUE *argv;
VALUE module;
@@ -4411,7 +4450,7 @@ mod_protected(argc, argv, module)
}
static VALUE
-mod_private(argc, argv, module)
+rb_mod_private(argc, argv, module)
int argc;
VALUE *argv;
VALUE module;
@@ -4426,7 +4465,7 @@ mod_private(argc, argv, module)
}
static VALUE
-mod_public_method(argc, argv, obj)
+rb_mod_public_method(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -4436,7 +4475,7 @@ mod_public_method(argc, argv, obj)
}
static VALUE
-mod_private_method(argc, argv, obj)
+rb_mod_private_method(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -4450,7 +4489,7 @@ top_public(argc, argv)
int argc;
VALUE *argv;
{
- return mod_public(argc, argv, cObject);
+ return rb_mod_public(argc, argv, rb_cObject);
}
static VALUE
@@ -4458,11 +4497,11 @@ top_private(argc, argv)
int argc;
VALUE *argv;
{
- return mod_private(argc, argv, cObject);
+ return rb_mod_private(argc, argv, rb_cObject);
}
static VALUE
-mod_modfunc(argc, argv, module)
+rb_mod_modfunc(argc, argv, module)
int argc;
VALUE *argv;
VALUE module;
@@ -4481,8 +4520,8 @@ mod_modfunc(argc, argv, module)
id = rb_to_id(argv[i]);
body = search_method(module, id, 0);
if (body == 0 || body->nd_body == 0) {
- NameError("undefined method `%s' for module `%s'",
- rb_id2name(id), rb_class2name(module));
+ rb_raise(rb_eNameError, "undefined method `%s' for module `%s'",
+ rb_id2name(id), rb_class2name(module));
}
rb_clear_cache_by_id(id);
rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC);
@@ -4491,7 +4530,7 @@ mod_modfunc(argc, argv, module)
}
static VALUE
-mod_append_features(module, include)
+rb_mod_append_features(module, include)
VALUE module, include;
{
switch (TYPE(include)) {
@@ -4508,7 +4547,7 @@ mod_append_features(module, include)
}
static VALUE
-mod_include(argc, argv, module)
+rb_mod_include(argc, argv, module)
int argc;
VALUE *argv;
VALUE module;
@@ -4523,16 +4562,16 @@ mod_include(argc, argv, module)
}
void
-obj_call_init(obj)
+rb_obj_call_init(obj)
VALUE obj;
{
- PUSH_ITER(iterator_p()?ITER_PRE:ITER_NOT);
- rb_funcall2(obj, init, the_frame->argc, the_frame->argv);
+ PUSH_ITER(rb_iterator_p()?ITER_PRE:ITER_NOT);
+ rb_funcall2(obj, init, ruby_frame->argc, ruby_frame->argv);
POP_ITER();
}
VALUE
-class_new_instance(argc, argv, klass)
+rb_class_new_instance(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -4540,10 +4579,10 @@ class_new_instance(argc, argv, klass)
VALUE obj;
if (FL_TEST(klass, FL_SINGLETON)) {
- TypeError("can't create instance of virtual class");
+ rb_raise(rb_eTypeError, "can't create instance of virtual class");
}
- obj = obj_alloc(klass);
- obj_call_init(obj);
+ obj = rb_obj_alloc(klass);
+ rb_obj_call_init(obj);
return obj;
}
@@ -4554,7 +4593,7 @@ top_include(argc, argv)
VALUE *argv;
{
rb_secure(4);
- return mod_include(argc, argv, cObject);
+ return rb_mod_include(argc, argv, rb_cObject);
}
void
@@ -4565,7 +4604,7 @@ rb_extend_object(obj, module)
}
static VALUE
-mod_extend_object(mod, obj)
+rb_mod_extend_object(mod, obj)
VALUE mod, obj;
{
rb_extend_object(obj, mod);
@@ -4573,7 +4612,7 @@ mod_extend_object(mod, obj)
}
static VALUE
-obj_extend(argc, argv, obj)
+rb_obj_extend(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -4587,8 +4626,8 @@ obj_extend(argc, argv, obj)
return obj;
}
-VALUE f_trace_var();
-VALUE f_untrace_var();
+VALUE rb_f_trace_var();
+VALUE rb_f_untrace_var();
static void
errinfo_setter(val, id, var)
@@ -4596,8 +4635,8 @@ errinfo_setter(val, id, var)
ID id;
VALUE *var;
{
- if (!obj_is_kind_of(val, eException)) {
- TypeError("assigning non-exception to $!");
+ if (!rb_obj_is_kind_of(val, rb_eException)) {
+ rb_raise(rb_eTypeError, "assigning non-exception to $!");
}
*var = val;
}
@@ -4606,7 +4645,7 @@ static VALUE
errat_getter(id)
ID id;
{
- return get_backtrace(errinfo);
+ return get_backtrace(rb_errinfo);
}
static void
@@ -4615,35 +4654,35 @@ errat_setter(val, id, var)
ID id;
VALUE *var;
{
- if (NIL_P(errinfo)) {
- ArgError("$! not set");
+ if (NIL_P(rb_errinfo)) {
+ rb_raise(rb_eArgError, "$! not set");
}
- set_backtrace(errinfo, val);
+ set_backtrace(rb_errinfo, val);
}
-VALUE f_global_variables();
+VALUE rb_f_global_variables();
VALUE f_instance_variables();
-VALUE
-f_local_variables()
+static VALUE
+rb_f_local_variables()
{
ID *tbl;
int n, i;
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
struct RVarmap *vars;
- tbl = the_scope->local_tbl;
+ tbl = ruby_scope->local_tbl;
if (tbl) {
n = *tbl++;
for (i=2; i<n; i++) { /* skip first 2 ($_ and $~) */
- ary_push(ary, str_new2(rb_id2name(tbl[i])));
+ rb_ary_push(ary, rb_str_new2(rb_id2name(tbl[i])));
}
}
- vars = the_dyna_vars;
+ vars = ruby_dyna_vars;
while (vars) {
if (vars->id) {
- ary_push(ary, str_new2(rb_id2name(vars->id)));
+ rb_ary_push(ary, rb_str_new2(rb_id2name(vars->id)));
}
vars = vars->next;
}
@@ -4651,14 +4690,15 @@ f_local_variables()
return ary;
}
-static VALUE f_catch();
-static VALUE f_throw();
+static VALUE rb_f_catch _((VALUE,VALUE));
+static VALUE rb_f_throw _((int,VALUE*)) NORETURN;
struct end_proc_data {
void (*func)();
VALUE data;
struct end_proc_data *next;
-} *end_proc_data;
+};
+static struct end_proc_data *end_proc_data;
void
rb_set_end_proc(func, data)
@@ -4682,19 +4722,20 @@ call_end_proc(data)
}
static void
-f_END()
+rb_f_END()
{
PUSH_FRAME();
- rb_set_end_proc(call_end_proc, f_lambda());
+ ruby_frame->argc = 0;
+ rb_set_end_proc(call_end_proc, rb_f_lambda());
POP_FRAME();
}
static VALUE
-f_at_exit()
+rb_f_at_exit()
{
VALUE proc;
- proc = f_lambda();
+ proc = rb_f_lambda();
rb_set_end_proc(call_end_proc, proc);
return proc;
@@ -4723,90 +4764,90 @@ Init_eval()
match = rb_intern("=~");
rb_global_variable((VALUE*)&top_scope);
- rb_global_variable((VALUE*)&eval_tree_begin);
+ rb_global_variable((VALUE*)&ruby_eval_tree_begin);
- rb_global_variable((VALUE*)&eval_tree);
- rb_global_variable((VALUE*)&the_dyna_vars);
+ rb_global_variable((VALUE*)&ruby_eval_tree);
+ rb_global_variable((VALUE*)&ruby_dyna_vars);
rb_define_virtual_variable("$@", errat_getter, errat_setter);
- rb_define_hooked_variable("$!", &errinfo, 0, errinfo_setter);
+ rb_define_hooked_variable("$!", &rb_errinfo, 0, errinfo_setter);
- rb_define_global_function("eval", f_eval, -1);
- rb_define_global_function("iterator?", f_iterator_p, 0);
- rb_define_global_function("method_missing", f_missing, -1);
- rb_define_global_function("loop", f_loop, 0);
+ rb_define_global_function("eval", rb_f_eval, -1);
+ rb_define_global_function("iterator?", rb_f_iterator_p, 0);
+ rb_define_global_function("method_missing", rb_f_missing, -1);
+ rb_define_global_function("loop", rb_f_loop, 0);
- rb_define_method(mKernel, "respond_to?", obj_respond_to, -1);
+ rb_define_method(rb_mKernel, "respond_to?", rb_obj_respond_to, -1);
- rb_define_global_function("raise", f_raise, -1);
- rb_define_alias(mKernel, "fail", "raise");
+ rb_define_global_function("raise", rb_f_raise, -1);
+ rb_define_alias(rb_mKernel, "fail", "raise");
- rb_define_global_function("caller", f_caller, -1);
+ rb_define_global_function("caller", rb_f_caller, -1);
- rb_define_global_function("exit", f_exit, -1);
- rb_define_global_function("abort", f_abort, 0);
+ rb_define_global_function("exit", rb_f_exit, -1);
+ rb_define_global_function("abort", rb_f_abort, 0);
- rb_define_global_function("at_exit", f_at_exit, 0);
+ rb_define_global_function("at_exit", rb_f_at_exit, 0);
- rb_define_global_function("catch", f_catch, 1);
- rb_define_global_function("throw", f_throw, -1);
- rb_define_global_function("global_variables", f_global_variables, 0);
- rb_define_global_function("local_variables", f_local_variables, 0);
+ rb_define_global_function("catch", rb_f_catch, 1);
+ rb_define_global_function("throw", rb_f_throw, -1);
+ rb_define_global_function("global_variables", rb_f_global_variables, 0);
+ rb_define_global_function("local_variables", rb_f_local_variables, 0);
- rb_define_method(mKernel, "send", f_send, -1);
- rb_define_method(mKernel, "__send__", f_send, -1);
- rb_define_method(mKernel, "instance_eval", obj_instance_eval, -1);
+ rb_define_method(rb_mKernel, "send", rb_f_send, -1);
+ rb_define_method(rb_mKernel, "__send__", rb_f_send, -1);
+ rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);
- rb_define_private_method(cModule, "append_features", mod_append_features, 1);
- rb_define_private_method(cModule, "extend_object", mod_extend_object, 1);
- rb_define_private_method(cModule, "include", mod_include, -1);
- rb_define_private_method(cModule, "public", mod_public, -1);
- rb_define_private_method(cModule, "protected", mod_protected, -1);
- rb_define_private_method(cModule, "private", mod_private, -1);
- rb_define_private_method(cModule, "module_function", mod_modfunc, -1);
- rb_define_method(cModule, "method_defined?", mod_method_defined, 1);
- rb_define_method(cModule, "public_class_method", mod_public_method, -1);
- rb_define_method(cModule, "private_class_method", mod_private_method, -1);
- rb_define_method(cModule, "module_eval", mod_module_eval, -1);
- rb_define_method(cModule, "class_eval", mod_module_eval, -1);
+ rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1);
+ rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1);
+ rb_define_private_method(rb_cModule, "include", rb_mod_include, -1);
+ rb_define_private_method(rb_cModule, "public", rb_mod_public, -1);
+ rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1);
+ rb_define_private_method(rb_cModule, "private", rb_mod_private, -1);
+ rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1);
+ rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1);
+ rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1);
+ rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1);
+ rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
+ rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
- rb_define_private_method(cModule, "remove_method", mod_remove_method, 1);
- rb_define_private_method(cModule, "undef_method", mod_undef_method, 1);
- rb_define_private_method(cModule, "alias_method", mod_alias_method, 2);
+ rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, 1);
+ rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, 1);
+ rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);
- rb_define_singleton_method(cModule, "nesting", mod_nesting, 0);
- rb_define_singleton_method(cModule, "constants", mod_s_constants, 0);
+ rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
+ rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, 0);
- rb_define_singleton_method(TopSelf, "include", top_include, -1);
- rb_define_singleton_method(TopSelf, "public", top_public, -1);
- rb_define_singleton_method(TopSelf, "private", top_private, -1);
+ rb_define_singleton_method(rb_top_self, "include", top_include, -1);
+ rb_define_singleton_method(rb_top_self, "public", top_public, -1);
+ rb_define_singleton_method(rb_top_self, "private", top_private, -1);
- rb_define_method(mKernel, "extend", obj_extend, -1);
+ rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
- rb_define_global_function("trace_var", f_trace_var, -1);
- rb_define_global_function("untrace_var", f_untrace_var, -1);
+ rb_define_global_function("trace_var", rb_f_trace_var, -1);
+ rb_define_global_function("untrace_var", rb_f_untrace_var, -1);
rb_define_global_function("set_trace_func", set_trace_func, 1);
rb_define_virtual_variable("$SAFE", safe_getter, safe_setter);
}
-VALUE f_autoload();
+VALUE rb_f_autoload();
void
Init_load()
{
- rb_load_path = ary_new();
+ rb_load_path = rb_ary_new();
rb_define_readonly_variable("$:", &rb_load_path);
rb_define_readonly_variable("$-I", &rb_load_path);
rb_define_readonly_variable("$LOAD_PATH", &rb_load_path);
- rb_features = ary_new();
+ rb_features = rb_ary_new();
rb_define_readonly_variable("$\"", &rb_features);
- rb_define_global_function("load", f_load, 1);
- rb_define_global_function("require", f_require, 1);
- rb_define_global_function("autoload", f_autoload, 2);
+ rb_define_global_function("load", rb_f_load, 1);
+ rb_define_global_function("require", rb_f_require, 1);
+ rb_define_global_function("autoload", rb_f_autoload, 2);
}
static void
@@ -4836,12 +4877,12 @@ blk_mark(data)
struct BLOCK *data;
{
while (data) {
- gc_mark_frame(&data->frame);
- gc_mark(data->scope);
- gc_mark(data->var);
- gc_mark(data->body);
- gc_mark(data->self);
- gc_mark(data->d_vars);
+ rb_gc_mark_frame(&data->frame);
+ rb_gc_mark(data->scope);
+ rb_gc_mark(data->var);
+ rb_gc_mark(data->body);
+ rb_gc_mark(data->self);
+ rb_gc_mark(data->d_vars);
data = data->prev;
}
}
@@ -4901,25 +4942,25 @@ bind_clone(self)
}
static VALUE
-f_binding(self)
+rb_f_binding(self)
VALUE self;
{
struct BLOCK *data;
VALUE bind;
PUSH_BLOCK(0,0);
- bind = Data_Make_Struct(cBinding,struct BLOCK,blk_mark,blk_free,data);
- MEMCPY(data, the_block, struct BLOCK, 1);
+ bind = Data_Make_Struct(rb_cBinding,struct BLOCK,blk_mark,blk_free,data);
+ *data = *ruby_block;
#ifdef THREAD
- data->orig_thread = thread_current();
+ data->orig_thread = rb_thread_current();
#endif
- data->iter = f_iterator_p();
- if (the_frame->prev) {
- data->frame.last_func = the_frame->prev->last_func;
+ data->iter = rb_f_iterator_p();
+ if (ruby_frame->prev) {
+ data->frame.last_func = ruby_frame->prev->last_func;
}
data->frame.argv = ALLOC_N(VALUE, data->frame.argc);
- MEMCPY(data->frame.argv, the_block->frame.argv, VALUE, data->frame.argc);
+ MEMCPY(data->frame.argv, ruby_block->frame.argv, VALUE, data->frame.argc);
if (data->iter) {
blk_copy_prev(data);
@@ -4947,19 +4988,19 @@ proc_s_new(klass)
volatile VALUE proc;
struct BLOCK *data;
- if (!iterator_p() && !f_iterator_p()) {
- ArgError("tryed to create Procedure-Object out of iterator");
+ if (!rb_iterator_p() && !rb_f_iterator_p()) {
+ rb_raise(rb_eArgError, "tryed to create Procedure-Object out of iterator");
}
proc = Data_Make_Struct(klass, struct BLOCK, blk_mark, blk_free, data);
- *data = *the_block;
+ *data = *ruby_block;
#ifdef THREAD
- data->orig_thread = thread_current();
+ data->orig_thread = rb_thread_current();
#endif
- data->iter = data->prev?TRUE:FALSE;
+ data->iter = data->prev?Qtrue:Qfalse;
data->frame.argv = ALLOC_N(VALUE, data->frame.argc);
- MEMCPY(data->frame.argv, the_block->frame.argv, VALUE, data->frame.argc);
+ MEMCPY(data->frame.argv, ruby_block->frame.argv, VALUE, data->frame.argc);
if (data->iter) {
blk_copy_prev(data);
}
@@ -4982,15 +5023,15 @@ proc_s_new(klass)
break;
}
}
- obj_call_init(proc);
+ rb_obj_call_init(proc);
return proc;
}
VALUE
-f_lambda()
+rb_f_lambda()
{
- return proc_s_new(cProc);
+ return proc_s_new(rb_cProc);
}
static int
@@ -5002,7 +5043,7 @@ blk_orphan(data)
return 1;
}
#ifdef THREAD
- if (data->orig_thread != thread_current()) {
+ if (data->orig_thread != rb_thread_current()) {
return 1;
}
#endif
@@ -5036,14 +5077,14 @@ proc_call(proc, args)
/* PUSH BLOCK from data */
PUSH_BLOCK2(data);
PUSH_ITER(ITER_CUR);
- the_frame->iter = ITER_CUR;
+ ruby_frame->iter = ITER_CUR;
if (orphan) {/* orphan procedure */
- if (iterator_p()) {
- the_block->frame.iter = ITER_CUR;
+ if (rb_iterator_p()) {
+ ruby_block->frame.iter = ITER_CUR;
}
else {
- the_block->frame.iter = ITER_NOT;
+ ruby_block->frame.iter = ITER_NOT;
}
}
@@ -5064,28 +5105,28 @@ proc_call(proc, args)
PUSH_TAG(PROT_NONE);
state = EXEC_TAG();
if (state == 0) {
- result = rb_yield(args);
+ result = rb_yield_0(args, 0, 0);
}
POP_TAG();
POP_ITER();
- if (the_block->tag->dst == state) {
+ if (ruby_block->tag->dst == state) {
state &= TAG_MASK;
}
- POP_BLOCK();
+ POP_BLOCK2();
safe_level = safe;
if (state) {
if (orphan) {/* orphan procedure */
switch (state) {
case TAG_BREAK:
- Raise(eLocalJumpError, "break from proc-closure");
+ rb_raise(rb_eLocalJumpError, "break from proc-closure");
break;
case TAG_RETRY:
- Raise(eLocalJumpError, "retry from proc-closure");
+ rb_raise(rb_eLocalJumpError, "retry from proc-closure");
break;
case TAG_RETURN:
- Raise(eLocalJumpError, "return from proc-closure");
+ rb_raise(rb_eLocalJumpError, "return from proc-closure");
break;
}
}
@@ -5109,12 +5150,12 @@ block_pass(self, node)
if (NIL_P(block)) {
return rb_eval(self, node->nd_iter);
}
- if (obj_is_kind_of(block, cMethod)) {
+ if (rb_obj_is_kind_of(block, rb_cMethod)) {
block = method_proc(block);
}
- else if (!obj_is_proc(block)) {
- TypeError("wrong argument type %s (expected Proc)",
- rb_class2name(CLASS_OF(block)));
+ else if (!rb_obj_is_proc(block)) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc)",
+ rb_class2name(CLASS_OF(block)));
}
Data_Get_Struct(block, struct BLOCK, data);
@@ -5123,7 +5164,7 @@ block_pass(self, node)
/* PUSH BLOCK from data */
PUSH_BLOCK2(data);
PUSH_ITER(ITER_PRE);
- the_frame->iter = ITER_PRE;
+ ruby_frame->iter = ITER_PRE;
if (FL_TEST(block, PROC_TAINT)) {
switch (RBASIC(block)->flags & PROC_TMASK) {
case PROC_T3:
@@ -5146,24 +5187,24 @@ block_pass(self, node)
POP_TAG();
POP_ITER();
- if (the_block->tag->dst == state) {
+ if (ruby_block->tag->dst == state) {
state &= TAG_MASK;
orphan = 2;
}
- POP_BLOCK();
+ POP_BLOCK2();
safe_level = safe;
if (state) {
if (orphan == 2) {/* escape from orphan procedure */
switch (state) {
case TAG_BREAK:
- Raise(eLocalJumpError, "break from proc-closure");
+ rb_raise(rb_eLocalJumpError, "break from proc-closure");
break;
case TAG_RETRY:
- Raise(eLocalJumpError, "retry from proc-closure");
+ rb_raise(rb_eLocalJumpError, "retry from proc-closure");
break;
case TAG_RETURN:
- Raise(eLocalJumpError, "return from proc-closure");
+ rb_raise(rb_eLocalJumpError, "return from proc-closure");
break;
}
}
@@ -5183,14 +5224,14 @@ static void
bm_mark(data)
struct METHOD *data;
{
- gc_mark(data->oklass);
- gc_mark(data->klass);
- gc_mark(data->recv);
- gc_mark(data->body);
+ rb_gc_mark(data->oklass);
+ rb_gc_mark(data->klass);
+ rb_gc_mark(data->recv);
+ rb_gc_mark(data->body);
}
static VALUE
-obj_method(obj, vid)
+rb_obj_method(obj, vid)
VALUE obj;
VALUE vid;
{
@@ -5213,7 +5254,7 @@ obj_method(obj, vid)
goto again;
}
- method = Data_Make_Struct(cMethod, struct METHOD, bm_mark, free, data);
+ method = Data_Make_Struct(rb_cMethod, struct METHOD, bm_mark, free, data);
data->klass = klass;
data->recv = obj;
data->id = id;
@@ -5234,7 +5275,7 @@ method_call(argc, argv, method)
struct METHOD *data;
Data_Get_Struct(method, struct METHOD, data);
- PUSH_ITER(iterator_p()?ITER_PRE:ITER_NOT);
+ PUSH_ITER(rb_iterator_p()?ITER_PRE:ITER_NOT);
result = rb_call0(data->klass, data->recv, data->id,
argc, argv, data->body, 0);
POP_ITER();
@@ -5250,16 +5291,16 @@ method_inspect(method)
char *s;
Data_Get_Struct(method, struct METHOD, data);
- str = str_new2("#<");
+ str = rb_str_new2("#<");
s = rb_class2name(CLASS_OF(method));
- str_cat(str, s, strlen(s));
- str_cat(str, ": ", 2);
+ rb_str_cat(str, s, strlen(s));
+ rb_str_cat(str, ": ", 2);
s = rb_class2name(data->oklass);
- str_cat(str, s, strlen(s));
- str_cat(str, "#", 1);
+ rb_str_cat(str, s, strlen(s));
+ rb_str_cat(str, "#", 1);
s = rb_id2name(data->oid);
- str_cat(str, s, strlen(s));
- str_cat(str, ">", 1);
+ rb_str_cat(str, s, strlen(s));
+ rb_str_cat(str, ">", 1);
return str;
}
@@ -5272,7 +5313,7 @@ mproc()
/* emulate ruby's method call */
PUSH_ITER(ITER_CUR);
PUSH_FRAME();
- proc = f_lambda();
+ proc = rb_f_lambda();
POP_FRAME();
POP_ITER();
@@ -5299,36 +5340,36 @@ method_proc(method)
void
Init_Proc()
{
- eLocalJumpError = rb_define_class("LocalJumpError", eStandardError);
- eSysStackError = rb_define_class("SystemStackError", eStandardError);
+ rb_eLocalJumpError = rb_define_class("LocalJumpError", rb_eStandardError);
+ rb_eSysStackError = rb_define_class("SystemStackError", rb_eStandardError);
- cProc = rb_define_class("Proc", cObject);
- rb_define_singleton_method(cProc, "new", proc_s_new, 0);
+ rb_cProc = rb_define_class("Proc", rb_cObject);
+ rb_define_singleton_method(rb_cProc, "new", proc_s_new, 0);
- rb_define_method(cProc, "call", proc_call, -2);
- rb_define_global_function("proc", f_lambda, 0);
- rb_define_global_function("lambda", f_lambda, 0);
- rb_define_global_function("binding", f_binding, 0);
- cBinding = rb_define_class("Binding", cObject);
- rb_undef_method(CLASS_OF(cMethod), "new");
- rb_define_method(cBinding, "clone", bind_clone, 0);
+ rb_define_method(rb_cProc, "call", proc_call, -2);
+ 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);
+ rb_cBinding = rb_define_class("Binding", rb_cObject);
+ rb_undef_method(CLASS_OF(rb_cMethod), "new");
+ rb_define_method(rb_cBinding, "clone", bind_clone, 0);
- cMethod = rb_define_class("Method", cObject);
- rb_undef_method(CLASS_OF(cMethod), "new");
- rb_define_method(cMethod, "call", method_call, -1);
- rb_define_method(cMethod, "inspect", method_inspect, 0);
- rb_define_method(cMethod, "to_s", method_inspect, 0);
- rb_define_method(cMethod, "to_proc", method_proc, 0);
- rb_define_method(mKernel, "method", obj_method, 1);
+ rb_cMethod = rb_define_class("Method", rb_cObject);
+ rb_undef_method(CLASS_OF(rb_cMethod), "new");
+ rb_define_method(rb_cMethod, "call", method_call, -1);
+ rb_define_method(rb_cMethod, "inspect", method_inspect, 0);
+ rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
+ rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
+ rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
}
#ifdef THREAD
-static VALUE eThreadError;
+static VALUE rb_eThreadError;
-int thread_pending = 0;
+int rb_thread_pending = 0;
-VALUE cThread;
+VALUE rb_cThread;
#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
@@ -5348,7 +5389,7 @@ struct timeval {
#include <sys/select.h>
#endif
-extern VALUE last_status;
+extern VALUE rb_last_status;
enum thread_status {
THREAD_RUNNABLE,
@@ -5381,17 +5422,18 @@ struct thread {
struct SCOPE *scope;
struct RVarmap *dyna_vars;
struct BLOCK *block;
+ struct BLOCK *cblock;
struct iter *iter;
struct tag *tag;
VALUE klass;
VALUE trace;
- int misc; /* misc. states (vmode/trap_immediate) */
+ int misc; /* misc. states (vmode/rb_trap_immediate) */
char *file;
int line;
- VALUE errinfo;
+ VALUE rb_errinfo;
VALUE last_status;
VALUE last_line;
VALUE last_match;
@@ -5435,35 +5477,35 @@ static thread_t main_thread;
#define STACK(addr) (th->stk_pos<(addr) && (addr)<th->stk_pos+th->stk_len)
static void
-thread_mark(th)
+rb_thread_mark(th)
thread_t th;
{
struct FRAME *frame;
struct BLOCK *block;
- gc_mark(th->result);
- gc_mark(th->thread);
- if (th->join) gc_mark(th->join->thread);
+ rb_gc_mark(th->result);
+ rb_gc_mark(th->thread);
+ if (th->join) rb_gc_mark(th->join->thread);
- gc_mark(th->scope);
- gc_mark(th->dyna_vars);
- gc_mark(th->errinfo);
- gc_mark(th->last_line);
- gc_mark(th->last_match);
+ rb_gc_mark(th->scope);
+ rb_gc_mark(th->dyna_vars);
+ rb_gc_mark(th->rb_errinfo);
+ rb_gc_mark(th->last_line);
+ rb_gc_mark(th->last_match);
/* mark data in copied stack */
if (th->stk_len == 0) return; /* stack not active, no need to mark. */
if (th->stk_ptr) {
- gc_mark_locations(th->stk_ptr, th->stk_ptr+th->stk_len);
+ rb_gc_mark_locations(th->stk_ptr, th->stk_ptr+th->stk_len);
#if defined(THINK_C) || defined(__human68k__)
- gc_mark_locations(th->stk_ptr+2, th->stk_ptr+th->stk_len+2);
+ rb_gc_mark_locations(th->stk_ptr+2, th->stk_ptr+th->stk_len+2);
#endif
}
frame = th->frame;
while (frame && frame != top_frame) {
frame = ADJ(frame);
if (frame->argv && !STACK(frame->argv)) {
- gc_mark_frame(frame);
+ rb_gc_mark_frame(frame);
}
frame = frame->prev;
}
@@ -5471,25 +5513,25 @@ thread_mark(th)
while (block) {
block = ADJ(block);
if (block->frame.argv && !STACK(block->frame.argv)) {
- gc_mark_frame(&block->frame);
+ rb_gc_mark_frame(&block->frame);
}
block = block->prev;
}
}
void
-gc_mark_threads()
+rb_gc_mark_threads()
{
thread_t th;
if (!curr_thread) return;
FOREACH_THREAD(th) {
- thread_mark(th);
+ rb_thread_mark(th);
} END_FOREACH(th);
}
static void
-thread_free(th)
+rb_thread_free(th)
thread_t th;
{
if (th->stk_ptr) free(th->stk_ptr);
@@ -5498,26 +5540,26 @@ thread_free(th)
}
static thread_t
-thread_check(data)
+rb_thread_check(data)
VALUE data;
{
- if (TYPE(data) != T_DATA || RDATA(data)->dfree != thread_free) {
- TypeError("wrong argument type %s (expected Thread)",
- rb_class2name(CLASS_OF(data)));
+ if (TYPE(data) != T_DATA || RDATA(data)->dfree != rb_thread_free) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Thread)",
+ rb_class2name(CLASS_OF(data)));
}
return (thread_t)RDATA(data)->data;
}
static void
-thread_save_context(th)
+rb_thread_save_context(th)
thread_t th;
{
VALUE v;
int len = stack_length();
th->stk_len = 0;
- th->stk_pos = (gc_stack_start<(VALUE*)&v)?gc_stack_start
- :gc_stack_start - len;
+ th->stk_pos = (rb_gc_stack_start<(VALUE*)&v)?rb_gc_stack_start
+ :rb_gc_stack_start - len;
if (len > th->stk_max) {
REALLOC_N(th->stk_ptr, VALUE, len);
th->stk_max = len;
@@ -5526,26 +5568,27 @@ thread_save_context(th)
FLUSH_REGISTER_WINDOWS;
MEMCPY(th->stk_ptr, th->stk_pos, VALUE, th->stk_len);
- th->frame = the_frame;
- th->scope = the_scope;
- th->klass = the_class;
- th->dyna_vars = the_dyna_vars;
- th->block = the_block;
- th->misc = scope_vmode | (trap_immediate<<8);
- th->iter = the_iter;
+ th->frame = ruby_frame;
+ th->scope = ruby_scope;
+ th->klass = ruby_class;
+ th->dyna_vars = ruby_dyna_vars;
+ th->block = ruby_block;
+ th->cblock = ruby_calling_block;
+ th->misc = scope_vmode | (rb_trap_immediate<<8);
+ th->iter = ruby_iter;
th->tag = prot_tag;
- th->errinfo = errinfo;
- th->last_status = last_status;
- th->last_line = lastline_get();
- th->last_match = backref_get();
+ th->rb_errinfo = rb_errinfo;
+ th->last_status = rb_last_status;
+ th->last_line = rb_lastline_get();
+ th->last_match = rb_backref_get();
th->safe = safe_level;
th->trace = trace_func;
- th->file = sourcefile;
- th->line = sourceline;
+ th->file = ruby_sourcefile;
+ th->line = ruby_sourceline;
}
-static void thread_restore_context _((thread_t,int));
+static void rb_thread_restore_context _((thread_t,int));
static void
stack_extend(th, exit)
@@ -5555,7 +5598,7 @@ stack_extend(th, exit)
VALUE space[1024];
memset(space, 0, 1); /* prevent array from optimization */
- thread_restore_context(th, exit);
+ rb_thread_restore_context(th, exit);
}
static int th_raise_argc;
@@ -5566,7 +5609,7 @@ static VALUE th_cmd;
static int th_sig;
static void
-thread_restore_context(th, exit)
+rb_thread_restore_context(th, exit)
thread_t th;
int exit;
{
@@ -5574,9 +5617,9 @@ thread_restore_context(th, exit)
static thread_t tmp;
static int ex;
- if (!th->stk_ptr) Bug("unsaved context");
+ if (!th->stk_ptr) rb_bug("unsaved context");
- if (&v < gc_stack_start) {
+ if (&v < rb_gc_stack_start) {
/* Stack grows downward */
if (&v > th->stk_pos) stack_extend(th, exit);
}
@@ -5585,30 +5628,31 @@ thread_restore_context(th, exit)
if (&v < th->stk_pos + th->stk_len) stack_extend(th, exit);
}
- the_frame = th->frame;
- the_scope = th->scope;
- the_class = th->klass;
- the_dyna_vars = th->dyna_vars;
- the_block = th->block;
+ ruby_frame = th->frame;
+ ruby_scope = th->scope;
+ ruby_class = th->klass;
+ ruby_dyna_vars = th->dyna_vars;
+ ruby_block = th->block;
+ ruby_calling_block = th->cblock;
scope_vmode = th->misc&SCOPE_MASK;
- trap_immediate = th->misc>>8;
- the_iter = th->iter;
+ rb_trap_immediate = th->misc>>8;
+ ruby_iter = th->iter;
prot_tag = th->tag;
- errinfo = th->errinfo;
- last_status = th->last_status;
+ rb_errinfo = th->rb_errinfo;
+ rb_last_status = th->last_status;
safe_level = th->safe;
trace_func = th->trace;
- sourcefile = th->file;
- sourceline = th->line;
+ ruby_sourcefile = th->file;
+ ruby_sourceline = th->line;
tmp = th;
ex = exit;
FLUSH_REGISTER_WINDOWS;
MEMCPY(tmp->stk_pos, tmp->stk_ptr, VALUE, tmp->stk_len);
- lastline_set(tmp->last_line);
- backref_set(tmp->last_match);
+ rb_lastline_set(tmp->last_line);
+ rb_backref_set(tmp->last_match);
switch (ex) {
case 1:
@@ -5625,10 +5669,10 @@ thread_restore_context(th, exit)
break;
case 4:
- the_frame->last_func = 0;
- sourcefile = th_raise_file;
- sourceline = th_raise_line;
- f_raise(th_raise_argc, th_raise_argv);
+ ruby_frame->last_func = 0;
+ ruby_sourcefile = th_raise_file;
+ ruby_sourceline = th_raise_line;
+ rb_f_raise(th_raise_argc, th_raise_argv);
break;
default:
@@ -5637,7 +5681,7 @@ thread_restore_context(th, exit)
}
static void
-thread_ready(th)
+rb_thread_ready(th)
thread_t th;
{
/* The thread is no longer waiting on anything */
@@ -5655,41 +5699,41 @@ thread_ready(th)
}
static void
-thread_remove()
+rb_thread_remove()
{
- thread_ready(curr_thread);
+ rb_thread_ready(curr_thread);
curr_thread->status = THREAD_KILLED;
curr_thread->prev->next = curr_thread->next;
curr_thread->next->prev = curr_thread->prev;
}
static int
-thread_dead(th)
+rb_thread_dead(th)
thread_t th;
{
return th->status == THREAD_KILLED;
}
static void
-thread_deadlock()
+rb_thread_deadlock()
{
curr_thread = main_thread;
th_raise_argc = 1;
- th_raise_argv[0] = exc_new2(eFatal, "Thread: deadlock");
- th_raise_file = sourcefile;
- th_raise_line = sourceline;
- f_abort();
+ th_raise_argv[0] = rb_exc_new2(rb_eFatal, "Thread: deadlock");
+ th_raise_file = ruby_sourcefile;
+ th_raise_line = ruby_sourceline;
+ rb_f_abort();
}
void
-thread_schedule()
+rb_thread_schedule()
{
thread_t next; /* OK */
thread_t th;
thread_t curr;
select_err:
- thread_pending = 0;
+ rb_thread_pending = 0;
if (curr_thread == curr_thread->next) return;
next = 0;
@@ -5709,7 +5753,7 @@ thread_schedule()
if (num_waiting_on_join) {
FOREACH_THREAD_FROM(curr, th) {
- if ((th->wait_for&WAIT_JOIN) && thread_dead(th->join)) {
+ if ((th->wait_for&WAIT_JOIN) && rb_thread_dead(th->join)) {
th->join = 0;
th->wait_for &= ~WAIT_JOIN;
th->status = THREAD_RUNNABLE;
@@ -5779,7 +5823,7 @@ thread_schedule()
n = select(max+1, &readfds, 0, 0, delay_ptr);
if (n < 0) {
- if (trap_pending) rb_trap_exec();
+ if (rb_trap_pending) rb_trap_exec();
goto select_err;
}
if (n > 0) {
@@ -5806,8 +5850,8 @@ thread_schedule()
}
if (!next) {
- curr_thread->file = sourcefile;
- curr_thread->line = sourceline;
+ curr_thread->file = ruby_sourcefile;
+ curr_thread->line = ruby_sourceline;
FOREACH_THREAD_FROM(curr, th) {
fprintf(stderr, "%s:%d:deadlock 0x%x: %d:%d %s\n",
th->file, th->line, th->thread, th->status,
@@ -5815,7 +5859,7 @@ thread_schedule()
}
END_FOREACH_FROM(curr, th);
/* raise fatal error to main thread */
- thread_deadlock();
+ rb_thread_deadlock();
}
if (next->status == THREAD_RUNNABLE && next == curr_thread) {
return;
@@ -5823,7 +5867,7 @@ thread_schedule()
/* context switch */
if (curr == curr_thread) {
- thread_save_context(curr);
+ rb_thread_save_context(curr);
if (setjmp(curr->context)) {
return;
}
@@ -5832,13 +5876,13 @@ thread_schedule()
curr_thread = next;
if (next->status == THREAD_TO_KILL) {
/* execute ensure-clause if any */
- thread_restore_context(next, 1);
+ rb_thread_restore_context(next, 1);
}
- thread_restore_context(next, 0);
+ rb_thread_restore_context(next, 0);
}
void
-thread_wait_fd(fd)
+rb_thread_wait_fd(fd)
int fd;
{
if (curr_thread == curr_thread->next) return;
@@ -5847,11 +5891,11 @@ thread_wait_fd(fd)
curr_thread->fd = fd;
num_waiting_on_fd++;
curr_thread->wait_for |= WAIT_FD;
- thread_schedule();
+ rb_thread_schedule();
}
void
-thread_fd_writable(fd)
+rb_thread_fd_writable(fd)
int fd;
{
struct timeval zero;
@@ -5864,12 +5908,12 @@ thread_fd_writable(fd)
FD_ZERO(&fds);
FD_SET(fd, &fds);
if (select(fd+1, 0, &fds, 0, &zero) == 1) break;
- thread_schedule();
+ rb_thread_schedule();
}
}
void
-thread_wait_for(time)
+rb_thread_wait_for(time)
struct timeval time;
{
double date;
@@ -5905,19 +5949,19 @@ thread_wait_for(time)
curr_thread->delay = date;
num_waiting_on_timer++;
curr_thread->wait_for |= WAIT_TIME;
- thread_schedule();
+ rb_thread_schedule();
}
-void thread_sleep_forever _((void));
+void rb_thread_sleep_forever _((void));
int
-thread_alone()
+rb_thread_alone()
{
return curr_thread == curr_thread->next;
}
int
-thread_select(max, read, write, except, timeout)
+rb_thread_select(max, read, write, except, timeout)
int max;
fd_set *read, *write, *except;
struct timeval *timeout;
@@ -5929,10 +5973,10 @@ thread_select(max, read, write, except, timeout)
if (!read && !write && !except) {
if (!timeout) {
- thread_sleep_forever();
+ rb_thread_sleep_forever();
return 0;
}
- thread_wait_for(*timeout);
+ rb_thread_wait_for(*timeout);
return 0;
}
@@ -5999,117 +6043,118 @@ thread_select(max, read, write, except, timeout)
if (limit <= timeofday()) return 0;
}
- thread_schedule();
+ rb_thread_schedule();
CHECK_INTS;
}
}
static VALUE
-thread_join(dmy, thread)
+rb_thread_join(dmy, thread)
VALUE dmy;
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- if (thread_dead(th)) return thread;
+ if (rb_thread_dead(th)) return thread;
if ((th->wait_for & WAIT_JOIN) && th->join == curr_thread)
- Raise(eThreadError, "Thread.join: deadlock");
+ rb_raise(rb_eThreadError, "Thread.join: deadlock");
curr_thread->status = THREAD_STOPPED;
curr_thread->join = th;
num_waiting_on_join++;
curr_thread->wait_for |= WAIT_JOIN;
- thread_schedule();
+ rb_thread_schedule();
return thread;
}
static VALUE
-thread_current()
+rb_thread_current()
{
return curr_thread->thread;
}
static VALUE
-thread_main()
+rb_thread_main()
{
return main_thread->thread;
}
static VALUE
-thread_wakeup(thread)
+rb_thread_wakeup(thread)
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- if (th->status == THREAD_KILLED) Raise(eThreadError, "killed thread");
- thread_ready(th);
+ if (th->status == THREAD_KILLED)
+ rb_raise(rb_eThreadError, "killed thread");
+ rb_thread_ready(th);
return thread;
}
static VALUE
-thread_run(thread)
+rb_thread_run(thread)
VALUE thread;
{
- thread_wakeup(thread);
- if (!thread_critical) thread_schedule();
+ rb_thread_wakeup(thread);
+ if (!rb_thread_critical) rb_thread_schedule();
return thread;
}
static VALUE
-thread_kill(thread)
+rb_thread_kill(thread)
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
if (th->status == THREAD_TO_KILL || th->status == THREAD_KILLED)
return thread;
if (th == th->next || th == main_thread) rb_exit(0);
- thread_ready(th);
+ rb_thread_ready(th);
th->status = THREAD_TO_KILL;
- thread_schedule();
+ rb_thread_schedule();
return Qnil; /* not reached */
}
static VALUE
-thread_s_kill(obj, th)
+rb_thread_s_kill(obj, th)
VALUE obj, th;
{
- return thread_kill(th);
+ return rb_thread_kill(th);
}
static VALUE
-thread_exit()
+rb_thread_exit()
{
- return thread_kill(curr_thread->thread);
+ return rb_thread_kill(curr_thread->thread);
}
static VALUE
-thread_pass()
+rb_thread_pass()
{
- thread_schedule();
+ rb_thread_schedule();
return Qnil;
}
static VALUE
-thread_stop()
+rb_thread_stop()
{
- thread_critical = 0;
+ rb_thread_critical = 0;
curr_thread->status = THREAD_STOPPED;
if (curr_thread == curr_thread->next) {
- Raise(eThreadError, "stopping only thread");
+ rb_raise(rb_eThreadError, "stopping only thread");
}
- thread_schedule();
+ rb_thread_schedule();
return Qnil;
}
-struct timeval time_timeval();
+struct timeval rb_time_timeval();
void
-thread_sleep(sec)
+rb_thread_sleep(sec)
int sec;
{
if (curr_thread == curr_thread->next) {
@@ -6118,11 +6163,11 @@ thread_sleep(sec)
TRAP_END;
return;
}
- thread_wait_for(time_timeval(INT2FIX(sec)));
+ rb_thread_wait_for(rb_time_timeval(INT2FIX(sec)));
}
void
-thread_sleep_forever()
+rb_thread_sleep_forever()
{
if (curr_thread == curr_thread->next) {
TRAP_BEG;
@@ -6135,46 +6180,46 @@ thread_sleep_forever()
curr_thread->delay = DELAY_INFTY;
curr_thread->wait_for |= WAIT_TIME;
curr_thread->status = THREAD_STOPPED;
- thread_schedule();
+ rb_thread_schedule();
}
-static int thread_abort;
+static int rb_thread_abort;
static VALUE
-thread_s_abort_exc()
+rb_thread_s_abort_exc()
{
- return thread_abort?TRUE:FALSE;
+ return rb_thread_abort?Qtrue:Qfalse;
}
static VALUE
-thread_s_abort_exc_set(self, val)
+rb_thread_s_abort_exc_set(self, val)
VALUE self, val;
{
- thread_abort = RTEST(val);
+ rb_thread_abort = RTEST(val);
return val;
}
static VALUE
-thread_abort_exc(thread)
+rb_thread_abort_exc(thread)
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- return th->abort?TRUE:FALSE;
+ return th->abort?Qtrue:Qfalse;
}
static VALUE
-thread_abort_exc_set(thread, val)
+rb_thread_abort_exc_set(thread, val)
VALUE thread, val;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
th->abort = RTEST(val);
return val;
}
static thread_t
-thread_alloc()
+rb_thread_alloc()
{
thread_t th;
@@ -6183,7 +6228,7 @@ thread_alloc()
th->status = 0;
th->result = 0;
- th->errinfo = Qnil;
+ th->rb_errinfo = Qnil;
th->stk_ptr = 0;
th->stk_len = 0;
@@ -6200,13 +6245,13 @@ thread_alloc()
th->block = 0;
th->iter = 0;
th->tag = 0;
- th->errinfo = 0;
+ th->rb_errinfo = 0;
th->last_status = 0;
th->last_line = 0;
th->last_match = 0;
th->abort = 0;
- th->thread = data_object_alloc(cThread, th, 0, thread_free);
+ th->thread = Data_Wrap_Struct(rb_cThread, 0, rb_thread_free, th);
if (curr_thread) {
th->prev = curr_thread;
@@ -6230,25 +6275,27 @@ catch_timer(sig)
#if !defined(POSIX_SIGNAL) && !defined(BSD_SIGNAL)
signal(sig, catch_timer);
#endif
- if (!thread_critical) {
- if (trap_immediate) {
- thread_schedule();
+ if (!rb_thread_critical) {
+ if (rb_trap_immediate) {
+ rb_thread_schedule();
}
- else thread_pending = 1;
+ else rb_thread_pending = 1;
}
}
#else
-int thread_tick = THREAD_TICK;
+int thread_tick = rb_THREAD_TICK;
#endif
-static VALUE thread_raise _((int, VALUE*, VALUE));
+static VALUE rb_thread_raise _((int, VALUE*, VALUE));
+
+#define SCOPE_SHARED FL_USER1
VALUE
-thread_create(fn, arg)
+rb_thread_create(fn, arg)
VALUE (*fn)();
void *arg;
{
- thread_t th = thread_alloc();
+ thread_t th = rb_thread_alloc();
int state;
#if defined(HAVE_SETITIMER) && !defined(__BOW__)
@@ -6273,118 +6320,125 @@ thread_create(fn, arg)
}
#endif
- thread_save_context(curr_thread);
+ FL_SET(ruby_scope, SCOPE_SHARED);
+ rb_thread_save_context(curr_thread);
if (setjmp(curr_thread->context)) {
return th->thread;
}
PUSH_TAG(PROT_THREAD);
if ((state = EXEC_TAG()) == 0) {
- thread_save_context(th);
+ rb_thread_save_context(th);
if (setjmp(th->context) == 0) {
curr_thread = th;
th->result = (*fn)(arg, th);
}
}
POP_TAG();
- thread_remove();
- if (state && th->status != THREAD_TO_KILL && !NIL_P(errinfo)) {
+ rb_thread_remove();
+ if (state && th->status != THREAD_TO_KILL && !NIL_P(rb_errinfo)) {
if (state == TAG_FATAL) {
/* fatal error within this thread, need to stop whole script */
- main_thread->errinfo = errinfo;
- thread_cleanup();
+ main_thread->rb_errinfo = rb_errinfo;
+ rb_thread_cleanup();
}
- else if (obj_is_kind_of(errinfo, eSystemExit)) {
+ else if (rb_obj_is_kind_of(rb_errinfo, rb_eSystemExit)) {
/* delegate exception to main_thread */
- thread_raise(1, &errinfo, main_thread->thread);
+ rb_thread_raise(1, &rb_errinfo, main_thread->thread);
}
- else if (thread_abort || curr_thread->abort || RTEST(debug)) {
- VALUE err = exc_new(eSystemExit, 0, 0);
+ else if (rb_thread_abort || curr_thread->abort || RTEST(rb_debug)) {
+ VALUE err = rb_exc_new(rb_eSystemExit, 0, 0);
error_print();
/* exit on main_thread */
- thread_raise(1, &err, main_thread->thread);
+ rb_thread_raise(1, &err, main_thread->thread);
}
else {
- curr_thread->errinfo = errinfo;
+ curr_thread->rb_errinfo = rb_errinfo;
}
}
- thread_schedule();
+ rb_thread_schedule();
return 0; /* not reached */
}
+int
+rb_thread_scope_shared_p()
+{
+ return FL_TEST(ruby_scope, SCOPE_SHARED);
+}
+
static VALUE
-thread_yield(arg, th)
+rb_thread_yield(arg, th)
int arg;
thread_t th;
{
- scope_dup(the_block->scope);
- return rb_yield(th->thread);
+ scope_dup(ruby_block->scope);
+ return rb_yield_0(th->thread, 0, 0);
}
static VALUE
-thread_start()
+rb_thread_start()
{
- if (!iterator_p()) {
- Raise(eThreadError, "must be called as iterator");
+ if (!rb_iterator_p()) {
+ rb_raise(rb_eThreadError, "must be called as iterator");
}
- return thread_create(thread_yield, 0);
+ return rb_thread_create(rb_thread_yield, 0);
}
static VALUE
-thread_value(thread)
+rb_thread_value(thread)
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- thread_join(0, thread);
- if (!NIL_P(th->errinfo)) {
- VALUE oldbt = get_backtrace(th->errinfo);
+ rb_thread_join(0, thread);
+ if (!NIL_P(th->rb_errinfo)) {
+ VALUE oldbt = get_backtrace(th->rb_errinfo);
VALUE errat = make_backtrace();
- ary_unshift(errat, ary_entry(oldbt, 0));
- set_backtrace(th->errinfo, errat);
- rb_raise(th->errinfo);
+ rb_ary_unshift(errat, rb_ary_entry(oldbt, 0));
+ set_backtrace(th->rb_errinfo, errat);
+ rb_exc_raise(th->rb_errinfo);
}
return th->result;
}
static VALUE
-thread_status(thread)
+rb_thread_status(thread)
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- if (thread_dead(th)) {
- if (NIL_P(th->errinfo)) return FALSE;
+ if (rb_thread_dead(th)) {
+ if (NIL_P(th->rb_errinfo)) return Qfalse;
return Qnil;
}
- return TRUE;
+ return Qtrue;
}
static VALUE
-thread_stop_p(thread)
+rb_thread_stop_p(thread)
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- if (thread_dead(th)) return TRUE;
- if (th->status == THREAD_STOPPED) return TRUE;
- return FALSE;
+ if (rb_thread_dead(th)) return Qtrue;
+ if (th->status == THREAD_STOPPED) return Qtrue;
+ return Qfalse;
}
static void
-thread_wait_other_threads()
+rb_thread_wait_other_threads()
{
/* wait other threads to terminate */
while (curr_thread != curr_thread->next) {
- thread_schedule();
+ rb_thread_schedule();
}
}
static void
-thread_cleanup()
+rb_thread_cleanup()
{
thread_t th;
@@ -6401,87 +6455,87 @@ thread_cleanup()
END_FOREACH(th);
}
-int thread_critical;
+int rb_thread_critical;
static VALUE
-thread_get_critical()
+rb_thread_get_critical()
{
- return thread_critical?TRUE:FALSE;
+ return rb_thread_critical?Qtrue:Qfalse;
}
static VALUE
-thread_set_critical(obj, val)
+rb_thread_set_critical(obj, val)
VALUE obj, val;
{
- thread_critical = RTEST(val);
+ rb_thread_critical = RTEST(val);
return val;
}
void
-thread_interrupt()
+rb_thread_interrupt()
{
- thread_critical = 0;
- thread_ready(main_thread);
+ rb_thread_critical = 0;
+ rb_thread_ready(main_thread);
if (curr_thread == main_thread) {
rb_interrupt();
}
- thread_save_context(curr_thread);
+ rb_thread_save_context(curr_thread);
if (setjmp(curr_thread->context)) {
return;
}
curr_thread = main_thread;
- thread_restore_context(curr_thread, 2);
+ rb_thread_restore_context(curr_thread, 2);
}
void
-thread_trap_eval(cmd, sig)
+rb_thread_trap_eval(cmd, sig)
VALUE cmd;
int sig;
{
- thread_critical = 0;
- if (!thread_dead(curr_thread)) {
- thread_ready(curr_thread);
+ rb_thread_critical = 0;
+ if (!rb_thread_dead(curr_thread)) {
+ rb_thread_ready(curr_thread);
rb_trap_eval(cmd, sig);
return;
}
- thread_ready(main_thread);
- thread_save_context(curr_thread);
+ rb_thread_ready(main_thread);
+ rb_thread_save_context(curr_thread);
if (setjmp(curr_thread->context)) {
return;
}
th_cmd = cmd;
th_sig = sig;
curr_thread = main_thread;
- thread_restore_context(curr_thread, 3);
+ rb_thread_restore_context(curr_thread, 3);
}
static VALUE
-thread_raise(argc, argv, thread)
+rb_thread_raise(argc, argv, thread)
int argc;
VALUE *argv;
VALUE thread;
{
- thread_t th = thread_check(thread);
+ thread_t th = rb_thread_check(thread);
- if (thread_dead(th)) return thread;
+ if (rb_thread_dead(th)) return thread;
if (curr_thread == th) {
- f_raise(argc, argv);
+ rb_f_raise(argc, argv);
}
if (curr_thread->status != THREAD_KILLED)
- thread_save_context(curr_thread);
+ rb_thread_save_context(curr_thread);
if (setjmp(curr_thread->context)) {
return thread;
}
rb_scan_args(argc, argv, "11", &th_raise_argv[0], &th_raise_argv[1]);
- thread_ready(th);
+ rb_thread_ready(th);
curr_thread = th;
th_raise_argc = argc;
- th_raise_file = sourcefile;
- th_raise_line = sourceline;
- thread_restore_context(curr_thread, 4);
+ th_raise_file = ruby_sourcefile;
+ th_raise_line = ruby_sourceline;
+ rb_thread_restore_context(curr_thread, 4);
return Qnil; /* not reached */
}
@@ -6489,25 +6543,25 @@ static thread_t loading_thread;
static int loading_nest;
static int
-thread_loading(feature)
+rb_thread_loading(feature)
char *feature;
{
if (curr_thread != curr_thread->next && loading_thread) {
while (loading_thread != curr_thread) {
- thread_schedule();
+ rb_thread_schedule();
CHECK_INTS;
}
- if (rb_provided(feature)) return TRUE; /* no need to load */
+ if (rb_provided(feature)) return Qtrue; /* no need to load */
}
loading_thread = curr_thread;
loading_nest++;
- return FALSE;
+ return Qfalse;
}
static void
-thread_loading_done()
+rb_thread_loading_done()
{
if (--loading_nest == 0) {
loading_thread = 0;
@@ -6517,46 +6571,46 @@ thread_loading_done()
void
Init_Thread()
{
- eThreadError = rb_define_class("ThreadError", eStandardError);
- cThread = rb_define_class("Thread", cObject);
+ rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
+ rb_cThread = rb_define_class("Thread", rb_cObject);
- rb_define_singleton_method(cThread, "new", thread_start, 0);
- rb_define_singleton_method(cThread, "start", thread_start, 0);
- rb_define_singleton_method(cThread, "fork", thread_start, 0);
+ rb_define_singleton_method(rb_cThread, "new", rb_thread_start, 0);
+ rb_define_singleton_method(rb_cThread, "start", rb_thread_start, 0);
+ rb_define_singleton_method(rb_cThread, "fork", rb_thread_start, 0);
- rb_define_singleton_method(cThread, "stop", thread_stop, 0);
- rb_define_singleton_method(cThread, "kill", thread_s_kill, 1);
- rb_define_singleton_method(cThread, "exit", thread_exit, 0);
- rb_define_singleton_method(cThread, "pass", thread_pass, 0);
- rb_define_singleton_method(cThread, "join", thread_join, 1);
- rb_define_singleton_method(cThread, "current", thread_current, 0);
- rb_define_singleton_method(cThread, "main", thread_main, 0);
+ rb_define_singleton_method(rb_cThread, "stop", rb_thread_stop, 0);
+ rb_define_singleton_method(rb_cThread, "kill", rb_thread_s_kill, 1);
+ rb_define_singleton_method(rb_cThread, "exit", rb_thread_exit, 0);
+ rb_define_singleton_method(rb_cThread, "pass", rb_thread_pass, 0);
+ rb_define_singleton_method(rb_cThread, "join", rb_thread_join, 1);
+ rb_define_singleton_method(rb_cThread, "current", rb_thread_current, 0);
+ rb_define_singleton_method(rb_cThread, "main", rb_thread_main, 0);
- rb_define_singleton_method(cThread, "critical", thread_get_critical, 0);
- rb_define_singleton_method(cThread, "critical=", thread_set_critical, 1);
+ rb_define_singleton_method(rb_cThread, "critical", rb_thread_get_critical, 0);
+ rb_define_singleton_method(rb_cThread, "critical=", rb_thread_set_critical, 1);
- rb_define_singleton_method(cThread, "abort_on_exception", thread_s_abort_exc, 0);
- rb_define_singleton_method(cThread, "abort_on_exception=", thread_s_abort_exc_set, 1);
+ rb_define_singleton_method(rb_cThread, "abort_on_exception", rb_thread_s_abort_exc, 0);
+ rb_define_singleton_method(rb_cThread, "abort_on_exception=", rb_thread_s_abort_exc_set, 1);
- rb_define_method(cThread, "run", thread_run, 0);
- rb_define_method(cThread, "wakeup", thread_wakeup, 0);
- rb_define_method(cThread, "exit", thread_kill, 0);
- rb_define_method(cThread, "value", thread_value, 0);
- rb_define_method(cThread, "status", thread_status, 0);
- rb_define_method(cThread, "alive?", thread_status, 0);
- rb_define_method(cThread, "stop?", thread_stop_p, 0);
- rb_define_method(cThread, "raise", thread_raise, -1);
+ rb_define_method(rb_cThread, "run", rb_thread_run, 0);
+ rb_define_method(rb_cThread, "wakeup", rb_thread_wakeup, 0);
+ rb_define_method(rb_cThread, "exit", rb_thread_kill, 0);
+ rb_define_method(rb_cThread, "value", rb_thread_value, 0);
+ rb_define_method(rb_cThread, "status", rb_thread_status, 0);
+ rb_define_method(rb_cThread, "alive?", rb_thread_status, 0);
+ rb_define_method(rb_cThread, "stop?", rb_thread_stop_p, 0);
+ rb_define_method(rb_cThread, "raise", rb_thread_raise, -1);
- rb_define_method(cThread, "abort_on_exception", thread_abort_exc, 0);
- rb_define_method(cThread, "abort_on_exception=", thread_abort_exc_set, 1);
+ rb_define_method(rb_cThread, "abort_on_exception", rb_thread_abort_exc, 0);
+ rb_define_method(rb_cThread, "abort_on_exception=", rb_thread_abort_exc_set, 1);
/* allocate main thread */
- main_thread = thread_alloc();
+ main_thread = rb_thread_alloc();
}
#endif
static VALUE
-f_catch(dmy, tag)
+rb_f_catch(dmy, tag)
VALUE dmy, tag;
{
int state;
@@ -6566,7 +6620,7 @@ f_catch(dmy, tag)
t = rb_to_id(tag);
PUSH_TAG(t);
if ((state = EXEC_TAG()) == 0) {
- val = rb_yield(tag);
+ val = rb_yield_0(tag, 0, 0);
}
else if (state == TAG_THROW && t == prot_tag->dst) {
val = prot_tag->retval;
@@ -6582,7 +6636,7 @@ static VALUE
catch_i(tag)
ID tag;
{
- return f_catch(0, FIX2INT(tag));
+ return rb_f_catch(0, FIX2INT(tag));
}
VALUE
@@ -6594,11 +6648,8 @@ rb_catch(tag, proc, data)
return rb_iterate(catch_i, rb_intern(tag), proc, data);
}
-
-static VALUE f_throw _((int,VALUE*)) NORETURN;
-
static VALUE
-f_throw(argc, argv)
+rb_f_throw(argc, argv)
int argc;
VALUE *argv;
{
@@ -6616,18 +6667,18 @@ f_throw(argc, argv)
}
#ifdef THREAD
if (tt->tag == PROT_THREAD) {
- Raise(eThreadError, "uncaught throw `%s' in thread 0x%x",
- rb_id2name(t),
- curr_thread);
+ rb_raise(rb_eThreadError, "uncaught throw `%s' in thread 0x%x",
+ rb_id2name(t),
+ curr_thread);
}
#endif
tt = tt->prev;
}
if (!tt) {
- NameError("uncaught throw `%s'", rb_id2name(t));
+ rb_raise(rb_eNameError, "uncaught throw `%s'", rb_id2name(t));
}
return_value(value);
- trap_restore_mask();
+ rb_trap_restore_mask();
JUMP_TAG(TAG_THROW);
/* not reached */
}
@@ -6642,7 +6693,7 @@ rb_throw(tag, val)
argv[0] = FIX2INT(t);
argv[1] = val;
- f_throw(2, argv);
+ rb_f_throw(2, argv);
}
static void
@@ -6656,8 +6707,8 @@ return_check()
break;
}
if (tt->tag == PROT_THREAD) {
- Raise(eThreadError, "return from within thread 0x%x",
- curr_thread);
+ rb_raise(rb_eThreadError, "return from within thread 0x%x",
+ curr_thread);
}
tt = tt->prev;
}
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index 69b5636..edf677a 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -41,7 +41,7 @@ struct windata {
static void
no_window()
{
- Fail("already closed window");
+ rb_raise(rb_eRuntimeError, "already closed window");
}
#define GetWINDOW(obj, winp) {\
@@ -69,7 +69,7 @@ prep_window(class, window)
struct windata *winp;
if (window == NULL) {
- Fail("failed to create window");
+ rb_raise(rb_eRuntimeError, "failed to create window");
}
obj = Data_Make_Struct(class, struct windata, 0, free_window, winp);
@@ -86,7 +86,7 @@ curses_init_screen()
{
initscr();
if (stdscr == 0) {
- Fail("cannot initialize curses");
+ rb_raise(rb_eRuntimeError, "cannot initialize curses");
}
clear();
rb_stdscr = prep_window(cWindow, stdscr);
@@ -129,9 +129,9 @@ curses_closed()
{
#ifdef HAVE_ISENDWIN
if (isendwin()) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
#else
rb_notimplement();
#endif
@@ -354,7 +354,7 @@ curses_getstr(obj)
{
char rtn[1024]; /* This should be big enough.. I hope */
getstr(rtn);
- return str_taint(str_new2(rtn));
+ return rb_str_taint(rb_str_new2(rtn));
}
/* def delch */
@@ -404,7 +404,7 @@ window_s_new(class, lines, cols, top, left)
window = newwin(NUM2INT(lines), NUM2INT(cols), NUM2INT(top), NUM2INT(left));
wclear(window);
w = prep_window(class, window);
- obj_call_init(w);
+ rb_obj_call_init(w);
return w;
}
@@ -723,7 +723,7 @@ window_getstr(obj)
GetWINDOW(obj, winp);
wgetstr(winp->window, rtn);
- return str_taint(str_new2(rtn));
+ return rb_str_taint(rb_str_new2(rtn));
}
/* def delch */
@@ -789,7 +789,7 @@ Init_curses()
rb_define_module_function(mCurses, "lines", curses_lines, 0);
rb_define_module_function(mCurses, "cols", curses_cols, 0);
- cWindow = rb_define_class_under(mCurses, "Window", cObject);
+ cWindow = rb_define_class_under(mCurses, "Window", rb_cObject);
rb_define_singleton_method(cWindow, "new", window_s_new, 4);
rb_define_method(cWindow, "subwin", window_subwin, 4);
rb_define_method(cWindow, "close", window_close, 0);
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 9bd9818..eb1f5c9 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -21,7 +21,7 @@
VALUE cDBM;
-extern VALUE mEnumerable;
+extern VALUE rb_mEnumerable;
struct dbmdata {
int di_size;
@@ -31,7 +31,7 @@ struct dbmdata {
static void
closed_dbm()
{
- Fail("closed DBM file");
+ rb_raise(rb_eRuntimeError, "closed DBM file");
}
#define GetDBM(obj, dbmp) {\
@@ -86,7 +86,7 @@ fdbm_s_open(argc, argv, class)
obj = Data_Make_Struct(class,struct dbmdata,0,free_dbm,dbmp);
dbmp->di_dbm = dbm;
dbmp->di_size = -1;
- obj_call_init(obj);
+ rb_obj_call_init(obj);
return obj;
}
@@ -123,7 +123,7 @@ fdbm_fetch(obj, keystr)
if (value.dptr == 0) {
return Qnil;
}
- return str_taint(str_new(value.dptr, value.dsize));
+ return rb_str_taint(rb_str_new(value.dptr, value.dsize));
}
static VALUE
@@ -135,9 +135,9 @@ fdbm_indexes(argc, argv, obj)
VALUE new;
int i;
- new = ary_new2(argc);
+ new = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
- ary_push(new, fdbm_fetch(obj, argv[i]));
+ rb_ary_push(new, fdbm_fetch(obj, argv[i]));
}
return new;
@@ -161,13 +161,13 @@ fdbm_delete(obj, keystr)
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
- if (iterator_p()) rb_yield(keystr);
+ if (rb_iterator_p()) rb_yield(keystr);
return Qnil;
}
if (dbm_delete(dbm, key)) {
dbmp->di_size = -1;
- Fail("dbm_delete failed");
+ rb_raise(rb_eRuntimeError, "dbm_delete failed");
}
else if (dbmp->di_size >= 0) {
dbmp->di_size--;
@@ -193,9 +193,9 @@ fdbm_shift(obj)
val = dbm_fetch(dbm, key);
dbm_delete(dbm, key);
- keystr = str_taint(str_new(key.dptr, key.dsize));
- valstr = str_taint(str_new(val.dptr, val.dsize));
- return assoc_new(keystr, valstr);
+ keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize));
+ valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize));
+ return rb_assoc_new(keystr, valstr);
}
static VALUE
@@ -212,11 +212,11 @@ fdbm_delete_if(obj)
dbm = dbmp->di_dbm;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- keystr = str_taint(str_new(key.dptr, key.dsize));
- valstr = str_taint(str_new(val.dptr, val.dsize));
- if (RTEST(rb_yield(assoc_new(keystr, valstr)))) {
+ keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize));
+ valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize));
+ if (RTEST(rb_yield(rb_assoc_new(keystr, valstr)))) {
if (dbm_delete(dbm, key)) {
- Fail("dbm_delete failed");
+ rb_raise(rb_eRuntimeError, "dbm_delete failed");
}
}
}
@@ -237,7 +237,7 @@ fdbm_clear(obj)
dbmp->di_size = -1;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
if (dbm_delete(dbm, key)) {
- Fail("dbm_delete failed");
+ rb_raise(rb_eRuntimeError, "dbm_delete failed");
}
}
return obj;
@@ -251,15 +251,15 @@ fdbm_invert(obj)
struct dbmdata *dbmp;
DBM *dbm;
VALUE keystr, valstr;
- VALUE hash = hash_new();
+ VALUE hash = rb_hash_new();
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- keystr = str_taint(str_new(key.dptr, key.dsize));
- valstr = str_taint(str_new(val.dptr, val.dsize));
- hash_aset(hash, valstr, keystr);
+ keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize));
+ valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize));
+ rb_hash_aset(hash, valstr, keystr);
}
return obj;
}
@@ -279,7 +279,7 @@ update_i(pair, dbm)
{
Check_Type(pair, T_ARRAY);
if (RARRAY(pair)->len < 2) {
- ArgError("pair must be [key, value]");
+ rb_raise(rb_eArgError, "pair must be [key, value]");
}
fdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
return Qnil;
@@ -316,14 +316,14 @@ fdbm_store(obj, keystr, valstr)
}
rb_secure(4);
- keystr = obj_as_string(keystr);
+ keystr = rb_obj_as_string(keystr);
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
if (NIL_P(valstr)) return fdbm_delete(obj, keystr);
- valstr = obj_as_string(valstr);
+ valstr = rb_obj_as_string(valstr);
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
@@ -335,7 +335,7 @@ fdbm_store(obj, keystr, valstr)
dbm_clearerr(dbm);
#endif
if (errno == EPERM) rb_sys_fail(0);
- Fail("dbm_store failed");
+ rb_raise(rb_eRuntimeError, "dbm_store failed");
}
return valstr;
@@ -382,8 +382,8 @@ fdbm_empty_p(obj)
else {
i = dbmp->di_size;
}
- if (i == 0) return TRUE;
- return FALSE;
+ if (i == 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -398,7 +398,7 @@ fdbm_each_value(obj)
dbm = dbmp->di_dbm;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- rb_yield(str_taint(str_new(val.dptr, val.dsize)));
+ rb_yield(rb_str_taint(rb_str_new(val.dptr, val.dsize)));
}
return obj;
}
@@ -414,7 +414,7 @@ fdbm_each_key(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
- rb_yield(str_taint(str_new(key.dptr, key.dsize)));
+ rb_yield(rb_str_taint(rb_str_new(key.dptr, key.dsize)));
}
return obj;
}
@@ -433,9 +433,9 @@ fdbm_each_pair(obj)
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- keystr = str_taint(str_new(key.dptr, key.dsize));
- valstr = str_taint(str_new(val.dptr, val.dsize));
- rb_yield(assoc_new(keystr, valstr));
+ keystr = rb_str_taint(rb_str_new(key.dptr, key.dsize));
+ valstr = rb_str_taint(rb_str_new(val.dptr, val.dsize));
+ rb_yield(rb_assoc_new(keystr, valstr));
}
return obj;
@@ -453,9 +453,9 @@ fdbm_keys(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
- ary = ary_new();
+ ary = rb_ary_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
- ary_push(ary, str_taint(str_new(key.dptr, key.dsize)));
+ rb_ary_push(ary, rb_str_taint(rb_str_new(key.dptr, key.dsize)));
}
return ary;
@@ -473,10 +473,10 @@ fdbm_values(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
- ary = ary_new();
+ ary = rb_ary_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- ary_push(ary, str_taint(str_new(val.dptr, val.dsize)));
+ rb_ary_push(ary, rb_str_taint(rb_str_new(val.dptr, val.dsize)));
}
return ary;
@@ -497,8 +497,8 @@ fdbm_has_key(obj, keystr)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
val = dbm_fetch(dbm, key);
- if (val.dptr) return TRUE;
- return FALSE;
+ if (val.dptr) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -519,9 +519,9 @@ fdbm_has_value(obj, valstr)
val = dbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0)
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -536,11 +536,11 @@ fdbm_to_a(obj)
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
- ary = ary_new();
+ ary = rb_ary_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
- ary_push(ary, assoc_new(str_taint(str_new(key.dptr, key.dsize)),
- str_taint(str_new(val.dptr, val.dsize))));
+ rb_ary_push(ary, rb_assoc_new(rb_str_taint(rb_str_new(key.dptr, key.dsize)),
+ rb_str_taint(rb_str_new(val.dptr, val.dsize))));
}
return ary;
@@ -548,8 +548,8 @@ fdbm_to_a(obj)
Init_dbm()
{
- cDBM = rb_define_class("DBM", cObject);
- rb_include_module(cDBM, mEnumerable);
+ cDBM = rb_define_class("DBM", rb_cObject);
+ rb_include_module(cDBM, rb_mEnumerable);
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
rb_define_singleton_method(cDBM, "new", fdbm_s_open, -1);
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 7bb7796..5315166 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -37,7 +37,7 @@ etc_getlogin(obj)
#endif
if (login)
- return str_new2(login);
+ return rb_str_new2(login);
return Qnil;
}
@@ -47,36 +47,36 @@ setup_passwd(pwd)
struct passwd *pwd;
{
if (pwd == 0) rb_sys_fail("/etc/passwd");
- return struct_new(sPasswd,
- str_new2(pwd->pw_name),
- str_new2(pwd->pw_passwd),
- INT2FIX(pwd->pw_uid),
- INT2FIX(pwd->pw_gid),
+ return rb_struct_new(sPasswd,
+ rb_str_new2(pwd->pw_name),
+ rb_str_new2(pwd->pw_passwd),
+ INT2FIX(pwd->pw_uid),
+ INT2FIX(pwd->pw_gid),
#ifdef PW_GECOS
- str_new2(pwd->pw_gecos),
+ rb_str_new2(pwd->pw_gecos),
#endif
- str_new2(pwd->pw_dir),
- str_new2(pwd->pw_shell),
+ rb_str_new2(pwd->pw_dir),
+ rb_str_new2(pwd->pw_shell),
#ifdef PW_CHANGE
- INT2FIX(pwd->pw_change),
+ INT2FIX(pwd->pw_change),
#endif
#ifdef PW_QUOTA
- INT2FIX(pwd->pw_quota),
+ INT2FIX(pwd->pw_quota),
#endif
#ifdef PW_AGE
- INT2FIX(pwd->pw_age),
+ INT2FIX(pwd->pw_age),
#endif
#ifdef PW_CLASS
- str_new2(pwd->pw_class),
+ rb_str_new2(pwd->pw_class),
#endif
#ifdef PW_COMMENT
- str_new2(pwd->pw_comment),
+ rb_str_new2(pwd->pw_comment),
#endif
#ifdef PW_EXPIRE
- INT2FIX(pwd->pw_expire),
+ INT2FIX(pwd->pw_expire),
#endif
- 0 /*dummy*/
- );
+ 0 /*dummy*/
+ );
}
#endif
@@ -98,7 +98,7 @@ etc_getpwuid(argc, argv, obj)
uid = getuid();
}
pwd = getpwuid(uid);
- if (pwd == 0) Fail("can't find user for %d", uid);
+ if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %d", uid);
return setup_passwd(pwd);
#else
return Qnil;
@@ -114,7 +114,7 @@ etc_getpwnam(obj, nam)
Check_Type(nam, T_STRING);
pwd = getpwnam(RSTRING(nam)->ptr);
- if (pwd == 0) Fail("can't find user for %s", RSTRING(nam)->ptr);
+ if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr);
return setup_passwd(pwd);
#else
return Qnil;
@@ -128,7 +128,7 @@ etc_passwd(obj)
#if defined(HAVE_GETPWENT)
struct passwd *pw;
- if (iterator_p()) {
+ if (rb_iterator_p()) {
setpwent();
while (pw = getpwent()) {
rb_yield(setup_passwd(pw));
@@ -137,7 +137,7 @@ etc_passwd(obj)
return obj;
}
pw = getpwent();
- if (pw == 0) Fail("can't fetch next -- /etc/passwd");
+ if (pw == 0) rb_raise(rb_eRuntimeError, "can't fetch next -- /etc/passwd");
return setup_passwd(pw);
#else
return Qnil;
@@ -152,17 +152,17 @@ setup_group(grp)
VALUE mem;
char **tbl;
- mem = ary_new();
+ mem = rb_ary_new();
tbl = grp->gr_mem;
while (*tbl) {
- ary_push(mem, str_new2(*tbl));
+ rb_ary_push(mem, rb_str_new2(*tbl));
tbl++;
}
- return struct_new(sGroup,
- str_new2(grp->gr_name),
- str_new2(grp->gr_passwd),
- INT2FIX(grp->gr_gid),
- mem);
+ return rb_struct_new(sGroup,
+ rb_str_new2(grp->gr_name),
+ rb_str_new2(grp->gr_passwd),
+ INT2FIX(grp->gr_gid),
+ mem);
}
#endif
@@ -176,7 +176,7 @@ etc_getgrgid(obj, id)
gid = NUM2INT(id);
grp = getgrgid(gid);
- if (grp == 0) Fail("can't find group for %d", gid);
+ if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", gid);
return setup_group(grp);
#else
return Qnil;
@@ -192,7 +192,7 @@ etc_getgrnam(obj, nam)
Check_Type(nam, T_STRING);
grp = getgrnam(RSTRING(nam)->ptr);
- if (grp == 0) Fail("can't find group for %s", RSTRING(nam)->ptr);
+ if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING(nam)->ptr);
return setup_group(grp);
#else
return Qnil;
@@ -206,7 +206,7 @@ etc_group(obj)
#ifdef HAVE_GETGRENT
struct group *grp;
- if (iterator_p()) {
+ if (rb_iterator_p()) {
setgrent();
while (grp = getgrent()) {
rb_yield(setup_group(grp));
@@ -237,32 +237,32 @@ Init_etc()
rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
rb_define_module_function(mEtc, "group", etc_group, 0);
- sPasswd = struct_define("Passwd",
- "name", "passwd", "uid", "gid",
- "gecos", "dir", "shell",
+ sPasswd = rb_struct_define("Passwd",
+ "name", "passwd", "uid", "gid",
+ "gecos", "dir", "shell",
#ifdef PW_CHANGE
- "change",
+ "change",
#endif
#ifdef PW_QUOTA
- "quota",
+ "quota",
#endif
#ifdef PW_AGE
- "age",
+ "age",
#endif
#ifdef PW_CLASS
- "class",
+ "class",
#endif
#ifdef PW_COMMENT
- "comment",
+ "comment",
#endif
#ifdef PW_EXPIRE
- "expire",
+ "expire",
#endif
- 0);
+ 0);
rb_global_variable(&sPasswd);
#ifdef HAVE_GETGRENT
- sGroup = struct_define("Group", "name", "passwd", "gid", "mem", 0);
+ sGroup = rb_struct_define("Group", "name", "passwd", "gid", "mem", 0);
rb_global_variable(&sGroup);
#endif
}
diff --git a/ext/gtk/gtk.c b/ext/gtk/gtk.c
index 6c14fdd..d2a6739 100644
--- a/ext/gtk/gtk.c
+++ b/ext/gtk/gtk.c
@@ -15,7 +15,7 @@
#include <signal.h>
extern VALUE rb_argv, rb_argv0;
-extern VALUE cData;
+extern VALUE rb_cData;
static VALUE mGtk;
@@ -100,7 +100,7 @@ static VALUE gAcceleratorTable;
static VALUE gStyle;
static VALUE gPreviewInfo;
static VALUE gAllocation;
-static VALUE gRequisiton;
+static VALUE gRequisition;
static VALUE mRC;
@@ -163,14 +163,14 @@ get_gobject(obj)
Check_Type(obj, T_OBJECT);
data = RDATA(rb_ivar_get(obj, id_gtkdata));
if (NIL_P(data) || data->dmark != gobj_mark) {
- TypeError("not a Gtk object");
+ rb_raise(rb_eTypeError, "not a Gtk object");
}
Data_Get_Struct(data, GtkObject, gtkp);
if (!gtkp) {
- ArgError("destroyed GtkObject");
+ rb_raise(rb_eArgError, "destroyed GtkObject");
}
if (!GTK_IS_OBJECT(gtkp)) {
- TypeError("not a GtkObject");
+ rb_raise(rb_eTypeError, "not a GtkObject");
}
return gtkp;
@@ -206,10 +206,10 @@ add_relative(obj, relative)
VALUE ary = rb_ivar_get(obj, id_relatives);
if (NIL_P(ary) || TYPE(ary) != T_ARRAY) {
- ary = ary_new();
+ ary = rb_ary_new();
rb_ivar_set(obj, id_relatives, ary);
}
- ary_push(ary, relative);
+ rb_ary_push(ary, relative);
}
static VALUE gtk_object_list;
@@ -228,7 +228,7 @@ delete_gobject(gtkobj, obj)
{
struct RData *data;
- ary_delete(gtk_object_list, obj);
+ rb_ary_delete(gtk_object_list, obj);
data = RDATA(rb_ivar_get(obj, id_gtkdata));
data->dfree = 0;
data->data = 0;
@@ -241,13 +241,13 @@ set_gobject(obj, gtkobj)
{
VALUE data;
- data = Data_Wrap_Struct(cData, gobj_mark, 0, gtkobj);
+ data = Data_Wrap_Struct(rb_cData, gobj_mark, 0, gtkobj);
gtk_object_set_user_data(gtkobj, (gpointer)obj);
rb_ivar_set(obj, id_gtkdata, data);
gtk_signal_connect(gtkobj, "destroy",
(GtkSignalFunc)delete_gobject, (gpointer)obj);
- ary_push(gtk_object_list, obj);
+ rb_ary_push(gtk_object_list, obj);
}
static VALUE
@@ -255,7 +255,7 @@ make_gobject(klass, gtkobj)
VALUE klass;
GtkObject *gtkobj;
{
- VALUE obj = obj_alloc(klass);
+ VALUE obj = rb_obj_alloc(klass);
set_gobject(obj, gtkobj);
return obj;
@@ -294,8 +294,8 @@ get_gstyle(style)
GtkStyle *gstyle;
if (NIL_P(style)) return NULL;
- if (!obj_is_instance_of(style, gStyle)) {
- TypeError("not a GtkStyle");
+ if (!rb_obj_is_instance_of(style, gStyle)) {
+ rb_raise(rb_eTypeError, "not a GtkStyle");
}
Data_Get_Struct(style, GtkStyle, gstyle);
@@ -321,8 +321,8 @@ get_gtkacceltbl(value)
if (NIL_P(value)) return NULL;
- if (!obj_is_instance_of(value, gAcceleratorTable)) {
- TypeError("not an AcceleratorTable");
+ if (!rb_obj_is_instance_of(value, gAcceleratorTable)) {
+ rb_raise(rb_eTypeError, "not an AcceleratorTable");
}
Data_Get_Struct(value, GtkAcceleratorTable, tbl);
@@ -344,8 +344,8 @@ get_gtkprevinfo(value)
if (NIL_P(value)) return NULL;
- if (!obj_is_instance_of(value, gPreviewInfo)) {
- TypeError("not a PreviewInfo");
+ if (!rb_obj_is_instance_of(value, gPreviewInfo)) {
+ rb_raise(rb_eTypeError, "not a PreviewInfo");
}
Data_Get_Struct(value, GtkPreviewInfo, info);
@@ -372,8 +372,8 @@ get_gdkfont(font)
if (NIL_P(font)) return NULL;
- if (!obj_is_instance_of(font, gdkFont)) {
- TypeError("not a GdkFont");
+ if (!rb_obj_is_instance_of(font, gdkFont)) {
+ rb_raise(rb_eTypeError, "not a GdkFont");
}
Data_Get_Struct(font, GdkFont, gfont);
@@ -381,12 +381,62 @@ get_gdkfont(font)
}
static VALUE
+gdkfnt_load_font(self, name)
+ VALUE self, name;
+{
+ GdkFont *font;
+
+ font = gdk_font_load(STR2CSTR(name));
+ return Data_Wrap_Struct(gdkFont, 0, gdk_font_unref, font);
+ /* return make_gdkfont(new); */
+}
+static VALUE
+gdkfnt_load_fontset(self, name)
+ VALUE self, name;
+{
+ GdkFont *new;
+
+ new = gdk_fontset_load(STR2CSTR(name));
+ return make_gdkfont(new);
+}
+static VALUE
+gdkfnt_new(self, name)
+ VALUE self, name;
+{
+ char *cname = STR2CSTR(name);
+ return (strchr(cname, ',') == NULL)
+ ? gdkfnt_load_font(self, name)
+ : gdkfnt_load_fontset(self, name);
+}
+static VALUE
+gdkfnt_string_width(self, str)
+ VALUE self, str;
+{
+ int w;
+
+ w = gdk_string_width(get_gdkfont(self), STR2CSTR(str));
+ return INT2NUM(w);
+}
+static VALUE
+gdkfnt_ascent(self)
+ VALUE self;
+{
+ return INT2NUM(get_gdkfont(self)->ascent);
+}
+static VALUE
+gdkfnt_descent(self)
+ VALUE self;
+{
+ return INT2NUM(get_gdkfont(self)->descent);
+}
+
+static VALUE
gdkfnt_equal(fn1, fn2)
VALUE fn1, fn2;
{
if (gdk_font_equal(get_gdkfont(fn1), get_gdkfont(fn2)))
- return TRUE;
- return FALSE;
+ return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -413,8 +463,8 @@ get_tobj(obj, klass)
if (NIL_P(obj)) return NULL;
- if (!obj_is_instance_of(obj, klass)) {
- TypeError("not a %s", rb_class2name(klass));
+ if (!rb_obj_is_instance_of(obj, klass)) {
+ rb_raise(rb_eTypeError, "not a %s", rb_class2name(klass));
}
Data_Get_Struct(obj, void, ptr);
@@ -436,8 +486,8 @@ get_tobj(obj, klass)
#define make_gallocation(c) make_tobj(c, gAllocation, sizeof(GtkAllocation))
#define get_gallocation(c) ((GtkAllocation*)get_tobj(c, gAllocation))
-#define make_grequisiton(c) make_tobj(c, gRequisiton, sizeof(GtkRequisition))
-#define get_grequisiton(c) ((GtkRequisition*)get_tobj(c, gRequisiton))
+#define make_grequisition(c) make_tobj(c, gRequisition, sizeof(GtkRequisition))
+#define get_grequisition(c) ((GtkRequisition*)get_tobj(c, gRequisition))
#define make_gdkrectangle(r) make_tobj(r, gdkRectangle, sizeof(GdkRectangle))
#define get_gdkrectangle(r) ((GdkRectangle*)get_tobj(r, gdkRectangle))
@@ -458,8 +508,8 @@ get_gdkcmap(cmap)
if (NIL_P(cmap)) return NULL;
- if (!obj_is_kind_of(cmap, gdkColormap)) {
- TypeError("not a GdkColormap");
+ if (!rb_obj_is_kind_of(cmap, gdkColormap)) {
+ rb_raise(rb_eTypeError, "not a GdkColormap");
}
Data_Get_Struct(cmap, GdkColormap, gcmap);
@@ -482,8 +532,8 @@ get_gdkvisual(visual)
if (NIL_P(visual)) return NULL;
- if (!obj_is_kind_of(visual, gdkVisual)) {
- TypeError("not a GdkVisual");
+ if (!rb_obj_is_kind_of(visual, gdkVisual)) {
+ rb_raise(rb_eTypeError, "not a GdkVisual");
}
Data_Get_Struct(visual, GdkVisual, gvisual);
@@ -517,8 +567,8 @@ get_gdkdraw(draw, klass, kname)
if (NIL_P(draw)) return NULL;
- if (!obj_is_kind_of(draw, klass)) {
- TypeError("not a %s", kname);
+ if (!rb_obj_is_kind_of(draw, klass)) {
+ rb_raise(rb_eTypeError, "not a %s", kname);
}
Data_Get_Struct(draw, GdkDrawable, d);
@@ -538,7 +588,7 @@ gdkdraw_get_geometry(self)
gdk_window_get_geometry(get_gdkdrawable(self),
&x, &y, &width, &height, &depth);
- return ary_new3(5, INT2NUM(x), INT2NUM(y),
+ return rb_ary_new3(5, INT2NUM(x), INT2NUM(y),
INT2NUM(width), INT2NUM(height), INT2NUM(depth));
}
@@ -582,9 +632,9 @@ gdkpmap_create_from_xpm(self, win, tcolor, fname)
get_gdkcolor(tcolor),
STR2CSTR(fname));
if (!new) {
- ArgError("Pixmap not created from %s", STR2CSTR(fname));
+ rb_raise(rb_eArgError, "Pixmap not created from %s", STR2CSTR(fname));
}
- return assoc_new(make_gdkpixmap2(self,new),
+ return rb_assoc_new(make_gdkpixmap2(self,new),
make_gdkbitmap(mask));
}
@@ -608,7 +658,7 @@ gdkpmap_create_from_xpm_d(self, win, tcolor, data)
get_gdkcolor(tcolor),
buf);
- return assoc_new(make_gdkpixmap2(self,new),
+ return rb_assoc_new(make_gdkpixmap2(self,new),
make_gdkbitmap(mask));
}
@@ -652,12 +702,12 @@ get_gdkimage(image)
if (NIL_P(image)) return NULL;
- if (!obj_is_instance_of(image, gdkImage)) {
- TypeError("not a GdkImage");
+ if (!rb_obj_is_instance_of(image, gdkImage)) {
+ rb_raise(rb_eTypeError, "not a GdkImage");
}
Data_Get_Struct(image, GdkImage, gimage);
if (gimage == 0) {
- ArgError("destroyed GdkImage");
+ rb_raise(rb_eArgError, "destroyed GdkImage");
}
return gimage;
@@ -671,7 +721,7 @@ gdkimage_s_newbmap(klass, visual, data, w, h)
Check_Type(data, T_STRING);
if (RSTRING(data)->len < w * h) {
- ArgError("data too short");
+ rb_raise(rb_eArgError, "data too short");
}
return make_gdkimage(gdk_image_new_bitmap(get_gdkvisual(visual),
RSTRING(data)->ptr,
@@ -735,7 +785,7 @@ gdkwin_get_pointer(self)
int x, y;
GdkModifierType state;
gdk_window_get_pointer(get_gdkwindow(self), &x, &y, &state);
- return ary_new3(3, INT2FIX(x), INT2FIX(y), INT2FIX((int)state));
+ return rb_ary_new3(3, INT2FIX(x), INT2FIX(y), INT2FIX((int)state));
}
@@ -776,6 +826,49 @@ gdkwin_root_window(self)
return INT2NUM(GDK_ROOT_WINDOW() );
}
+static VALUE
+gdkwin_clear(self)
+ VALUE self;
+{
+ gdk_window_clear(get_gdkwindow(self));
+ return self;
+}
+static VALUE
+gdkwin_clear_area(self, x,y,w,h)
+ VALUE self,x,y,w,h;
+{
+ gdk_window_clear_area(get_gdkwindow(self),
+ NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
+ return self;
+}
+static VALUE
+gdkwin_clear_area_e(self, x,y,w,h)
+ VALUE self,x,y,w,h;
+{
+ gdk_window_clear_area_e(get_gdkwindow(self),
+ NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
+ return self;
+}
+
+static VALUE
+gdkwin_set_background(self, c)
+ VALUE self, c;
+{
+ GdkColor color;
+ color.pixel = NUM2INT(c);
+ gdk_window_set_background(get_gdkwindow(self), &color);
+ return self;
+}
+
+static VALUE
+gdkwin_set_back_pixmap(self, pixmap, parent_relative)
+ VALUE self, pixmap, parent_relative;
+{
+ gdk_window_set_back_pixmap(get_gdkwindow(self), get_gdkpixmap(pixmap),
+ NUM2INT(parent_relative));
+ return self;
+}
+
static VALUE
make_gdkevent(event)
@@ -808,8 +901,8 @@ get_gdkevent(event)
if (NIL_P(event)) return NULL;
- if (!obj_is_kind_of(event, gdkEvent)) {
- TypeError("not a GdkEvent... ");
+ if (!rb_obj_is_instance_of(event, gdkEvent)) {
+ rb_raise(rb_eTypeError, "not a GdkEvent");
}
Data_Get_Struct(event, GdkEvent, gevent);
@@ -832,12 +925,12 @@ get_gdkgc(gc)
if (NIL_P(gc)) return NULL;
- if (!obj_is_instance_of(gc, gdkGC)) {
- TypeError("not a GdkGC");
+ if (!rb_obj_is_instance_of(gc, gdkGC)) {
+ rb_raise(rb_eTypeError, "not a GdkGC");
}
Data_Get_Struct(gc, GdkGC, ggc);
if (ggc == 0) {
- ArgError("destroyed GdkGC");
+ rb_raise(rb_eArgError, "destroyed GdkGC");
}
return ggc;
@@ -868,13 +961,75 @@ gdkgc_destroy(self)
}
static VALUE
+gdkgc_set_function(self, func)
+ VALUE func;
+{
+ GdkFunction f;
+ f = (GdkFunction) NUM2INT(func);
+ if (f != GDK_COPY && f != GDK_INVERT && f != GDK_XOR)
+ ArgError("function out of range");
+
+ gdk_gc_set_function(get_gdkgc(self), f);
+ return func;
+}
+
+static VALUE
+gdkgc_set_foreground(self, pix)
+ VALUE pix;
+{
+ GdkColor c;
+ c.pixel = NUM2INT(pix);
+ gdk_gc_set_foreground(get_gdkgc(self), &c);
+ return pix;
+}
+static VALUE
+gdkgc_set_background(self, pix)
+ VALUE pix;
+{
+ GdkColor c;
+ c.pixel = NUM2INT(pix);
+ gdk_gc_set_background(get_gdkgc(self), &c);
+ return pix;
+}
+static VALUE
+gdkgc_set_clip_mask(self, mask)
+ VALUE mask;
+{
+ gdk_gc_set_clip_mask(get_gdkgc(self), get_gdkbitmap(mask));
+ return mask;
+}
+static VALUE
+gdkgc_set_clip_origin(self, x, y)
+ VALUE x, y;
+{
+ gdk_gc_set_clip_origin(get_gdkgc(self), NUM2INT(x), NUM2INT(y));
+ return self;
+}
+static VALUE
+gdkgc_set_clip_rectangle(self, rectangle)
+ VALUE rectangle;
+{
+ gdk_gc_set_clip_rectangle(get_gdkgc(self), get_gdkrectangle(rectangle));
+ return rectangle;
+}
+/*
+static VALUE
+gdkgc_set_clip_region(self, region)
+ VALUE region;
+{
+ gdk_gc_set_clip_region(get_gdkgc(self), get_gdkregion(region));
+ return region;
+}
+*/
+
+static VALUE
glist2ary(list)
GList *list;
{
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
while (list) {
- ary_push(ary, get_value_from_gobject(GTK_OBJECT(list->data)));
+ rb_ary_push(ary, get_value_from_gobject(GTK_OBJECT(list->data)));
list = list->next;
}
@@ -916,10 +1071,10 @@ static VALUE
gslist2ary(list)
GSList *list;
{
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
while (list) {
- ary_push(ary, get_value_from_gobject(GTK_OBJECT(list->data)));
+ rb_ary_push(ary, get_value_from_gobject(GTK_OBJECT(list->data)));
list = list->next;
}
@@ -953,11 +1108,11 @@ arg_to_value(arg)
break;
case GTK_TYPE_FLOAT:
- return float_new(GTK_VALUE_FLOAT(*arg));
+ return rb_float_new(GTK_VALUE_FLOAT(*arg));
break;
case GTK_TYPE_STRING:
- return str_new2(GTK_VALUE_STRING(*arg));
+ return rb_str_new2(GTK_VALUE_STRING(*arg));
break;
case GTK_TYPE_OBJECT:
@@ -1023,7 +1178,7 @@ arg_to_value(arg)
case GTK_TYPE_C_CALLBACK:
unsupported:
default:
- TypeError("unsupported arg type %s (fundamental type %s)",
+ rb_raise(rb_eTypeError, "unsupported arg type %s (fundamental type %s)",
gtk_type_name(arg->type),
gtk_type_name(GTK_FUNDAMENTAL_TYPE(arg->type)));
break;
@@ -1041,58 +1196,54 @@ signal_setup_args(obj, sig, argc, params, args)
int i;
char *signame = rb_id2name(sig);
- if (obj_is_kind_of(obj, gWidget)) {
+ if (rb_obj_is_kind_of(obj, gWidget)) {
if (strcmp(signame, "draw") == 0) {
- ary_push(args, make_gdkrectangle(GTK_VALUE_POINTER(params[0])));
+ rb_ary_push(args, make_gdkrectangle(GTK_VALUE_POINTER(params[0])));
return;
}
if (strcmp(signame, "size_request") == 0) {
- ary_push(args, make_grequisiton(GTK_VALUE_POINTER(params[0])));
+ rb_ary_push(args, make_grequisition(GTK_VALUE_POINTER(params[0])));
return;
}
if (strcmp(signame, "size_allocate") == 0) {
- ary_push(args, make_gallocation(GTK_VALUE_POINTER(params[0])));
+ rb_ary_push(args, make_gallocation(GTK_VALUE_POINTER(params[0])));
return;
}
}
- else if (obj_is_kind_of(obj, gWindow)) {
+ if (rb_obj_is_kind_of(obj, gWindow)) {
if (strcmp(signame, "move_resize") == 0) {
- ary_push(args, NUM2INT(*GTK_RETLOC_INT(params[0])));
- ary_push(args, NUM2INT(*GTK_RETLOC_INT(params[1])));
- ary_push(args, NUM2INT(GTK_VALUE_INT(params[3])));
- ary_push(args, NUM2INT(GTK_VALUE_INT(params[4])));
+ rb_ary_push(args, INT2NUM(*GTK_RETLOC_INT(params[0])));
+ rb_ary_push(args, INT2NUM(*GTK_RETLOC_INT(params[1])));
+ rb_ary_push(args, INT2NUM(GTK_VALUE_INT(params[3])));
+ rb_ary_push(args, INT2NUM(GTK_VALUE_INT(params[4])));
return;
}
if (strcmp(signame, "set_focus") == 0) {
- ary_push(args, get_value_from_gobject(GTK_VALUE_POINTER(params[0])));
+ rb_ary_push(args, get_value_from_gobject(GTK_VALUE_POINTER(params[0])));
return;
}
}
- else if (obj_is_kind_of(obj, gEntry)) {
+ if (rb_obj_is_kind_of(obj, gEntry)) {
if (strcmp(signame, "insert_position") == 0) {
- ary_push(args, NUM2INT(*GTK_RETLOC_INT(params[0])));
+ rb_ary_push(args, INT2NUM(*GTK_RETLOC_INT(params[0])));
return;
}
}
- else if (obj_is_kind_of(obj, gCList)) {
- if (strcmp(signame, "select_row") == 0) {
- if (GTK_VALUE_POINTER(params[0]))
- ary_push(args, make_gdkevent(GTK_VALUE_POINTER(params[0])));
- else
- ary_push(args, Qnil);
- return;
- }
- if (strcmp(signame, "unselect_row") == 0) {
- if (GTK_VALUE_POINTER(params[0]))
- ary_push(args, make_gdkevent(GTK_VALUE_POINTER(params[0])));
+ if (rb_obj_is_kind_of(obj, gCList)) {
+ if (strcmp(signame, "select_row") == 0 ||
+ strcmp(signame, "unselect_row") == 0) {
+ rb_ary_push(args, INT2NUM(GTK_VALUE_INT(params[0])));
+ rb_ary_push(args, INT2NUM(GTK_VALUE_INT(params[1])));
+ if (GTK_VALUE_POINTER(params[2]))
+ rb_ary_push(args, make_gdkevent(GTK_VALUE_POINTER(params[2])));
else
- ary_push(args, Qnil);
+ rb_ary_push(args, Qnil);
return;
}
}
for (i=0; i<argc; i++) {
- ary_push(args, arg_to_value(params));
+ rb_ary_push(args, arg_to_value(params));
params++;
}
}
@@ -1186,7 +1337,7 @@ arg_set_value(arg, value)
case GTK_TYPE_SIGNAL:
case GTK_TYPE_C_CALLBACK:
default:
- TypeError("unsupported return type %s (fundamental type %s)",
+ rb_raise(rb_eTypeError, "unsupported return type %s (fundamental type %s)",
gtk_type_name(arg->type),
gtk_type_name(GTK_FUNDAMENTAL_TYPE(arg->type)));
break;
@@ -1205,12 +1356,12 @@ signal_callback(widget, data, nparams, params)
VALUE a = RARRAY(data)->ptr[2];
ID id = NUM2INT(RARRAY(data)->ptr[1]);
VALUE result = Qnil;
- VALUE args = ary_new2(nparams+1+RARRAY(a)->len);
+ VALUE args = rb_ary_new2(nparams+1+RARRAY(a)->len);
int i;
signal_setup_args(self, id, nparams, params, args);
for (i=0; i<RARRAY(a)->len; i++) {
- ary_push(args, RARRAY(a)->ptr[i]);
+ rb_ary_push(args, RARRAY(a)->ptr[i]);
}
if (NIL_P(proc)) {
if (rb_respond_to(self, id)) {
@@ -1218,7 +1369,7 @@ signal_callback(widget, data, nparams, params)
}
}
else {
- ary_unshift(args, self);
+ rb_ary_unshift(args, self);
result = rb_apply(proc, id_call, args);
}
arg_set_value(params+nparams, result);
@@ -1238,7 +1389,7 @@ gobj_initialize(argc, argv, self)
VALUE *argv;
VALUE self;
{
- Fail("can't instantiate class %s", rb_class2name(self));
+ rb_raise(rb_eRuntimeError, "can't instantiate class %s", rb_class2name(self));
}
static VALUE
@@ -1249,7 +1400,7 @@ gobj_smethod_added(self, id)
char *name = rb_id2name(NUM2INT(id));
if (gtk_signal_lookup(name, GTK_OBJECT_TYPE(obj))) {
- VALUE data = ary_new3(3, Qnil, id, ary_new2(0));
+ VALUE data = rb_ary_new3(3, Qnil, id, rb_ary_new2(0));
add_relative(self, data);
gtk_signal_connect_interp(obj, name,
@@ -1273,12 +1424,12 @@ try_get_gobject(self)
}
static VALUE
-gobj_equal(self, other)
+grb_obj_equal(self, other)
VALUE self, other;
{
- if (self == other) return TRUE;
- if (get_gobject(self) == try_get_gobject(other)) return TRUE;
- return FALSE;
+ if (self == other) return Qtrue;
+ if (get_gobject(self) == try_get_gobject(other)) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -1296,7 +1447,7 @@ gobj_inspect(self)
else {
sprintf(s, "#<%s: id=0x%x>", cname, get_gobject(self));
}
- return str_new2(s);
+ return rb_str_new2(s);
}
static VALUE
@@ -1344,7 +1495,7 @@ gobj_sig_connect(argc, argv, self)
rb_scan_args(argc, argv, "1*", &sig, &args);
id = rb_intern(STR2CSTR(sig));
- data = ary_new3(3, f_lambda(), INT2NUM(id), args);
+ data = rb_ary_new3(3, rb_f_lambda(), INT2NUM(id), args);
add_relative(self, data);
i = gtk_signal_connect_interp(GTK_OBJECT(get_widget(self)),
STR2CSTR(sig),
@@ -1366,7 +1517,7 @@ gobj_sig_connect_after(argc, argv, self)
rb_scan_args(argc, argv, "1*", &sig, &args);
id = rb_intern(STR2CSTR(sig));
- data = ary_new3(3, f_lambda(), INT2NUM(id), args);
+ data = rb_ary_new3(3, rb_f_lambda(), INT2NUM(id), args);
add_relative(self, data);
i = gtk_signal_connect_interp(GTK_OBJECT(get_widget(self)),
STR2CSTR(sig),
@@ -1443,7 +1594,7 @@ cont_foreach(argc, argv, self)
rb_scan_args(argc, argv, "01", &callback);
if (NIL_P(callback)) {
- callback = f_lambda();
+ callback = rb_f_lambda();
}
gtk_container_foreach(GTK_CONTAINER(get_widget(self)),
exec_callback, (gpointer)callback);
@@ -1482,14 +1633,14 @@ cont_children_callback(widget, data)
{
VALUE ary = (VALUE)data;
- ary_push(ary, get_value_from_gobject(GTK_OBJECT(widget)));
+ rb_ary_push(ary, get_value_from_gobject(GTK_OBJECT(widget)));
}
static VALUE
cont_children(self, direction)
VALUE self, direction;
{
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
gtk_container_foreach(GTK_CONTAINER(get_widget(self)),
cont_children_callback,
@@ -1537,6 +1688,31 @@ misc_set_padding(self, xpad, ypad)
}
static VALUE
+misc_get_xalign(self)
+ VALUE self;
+{
+ return float_new(GTK_MISC(get_widget(self))->xalign);
+}
+static VALUE
+misc_get_yalign(self)
+ VALUE self;
+{
+ return float_new(GTK_MISC(get_widget(self))->yalign);
+}
+static VALUE
+misc_get_xpad(self)
+ VALUE self;
+{
+ return INT2NUM(GTK_MISC(get_widget(self))->xpad);
+}
+static VALUE
+misc_get_ypad(self)
+ VALUE self;
+{
+ return INT2NUM(GTK_MISC(get_widget(self))->ypad);
+}
+
+static VALUE
arrow_initialize(self, arrow_t, shadow_t)
VALUE self, arrow_t, shadow_t;
{
@@ -1707,9 +1883,14 @@ widget_queue_resize(self)
}
static VALUE
-widget_draw(self, rect)
- VALUE self, rect;
+widget_draw(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
{
+ VALUE rect;
+
+ rb_scan_args(argc, argv, "01", &rect);
gtk_widget_draw(get_widget(self), get_gdkrectangle(rect));
return self;
}
@@ -1742,7 +1923,7 @@ static VALUE
widget_size_request(self, req)
VALUE self, req;
{
- gtk_widget_size_request(get_widget(self), get_grequisiton(req));
+ gtk_widget_size_request(get_widget(self), get_grequisition(req));
return self;
}
@@ -1813,8 +1994,8 @@ widget_visible(self)
VALUE self;
{
if (GTK_WIDGET_VISIBLE(get_widget(self)))
- return TRUE;
- return FALSE;
+ return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -1824,6 +2005,14 @@ widget_reparent(self, parent)
gtk_widget_reparent(get_widget(self), get_widget(parent));
return self;
}
+static VALUE
+widget_mapped(self)
+ VALUE self;
+{
+ if (GTK_WIDGET_MAPPED(get_widget(self)))
+ return TRUE;
+ return FALSE;
+}
static VALUE
widget_popup(self, x, y)
@@ -1890,7 +2079,7 @@ widget_get_name(self)
{
char *name = gtk_widget_get_name(get_widget(self));
- return str_new2(name);
+ return rb_str_new2(name);
}
static VALUE
@@ -1962,7 +2151,7 @@ widget_get_ancestor(self, type)
{
GtkWidget *widget = get_widget(self);
#if 0
- if (obj_is_kind_of(type, cClass)) {
+ if (rb_obj_is_kind_of(type, rb_cClass)) {
}
#endif
widget = gtk_widget_get_ancestor(widget, NUM2INT(type));
@@ -2004,7 +2193,7 @@ widget_get_pointer(self)
int x, y;
gtk_widget_get_pointer(get_widget(self), &x, &y);
- return assoc_new(INT2FIX(x), INT2FIX(y));
+ return rb_assoc_new(INT2FIX(x), INT2FIX(y));
}
static VALUE
@@ -2012,9 +2201,9 @@ widget_is_ancestor(self, ancestor)
VALUE self, ancestor;
{
if (gtk_widget_is_ancestor(get_widget(self), get_widget(ancestor))) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -2022,9 +2211,9 @@ widget_is_child(self, child)
VALUE self, child;
{
if (gtk_widget_is_child(get_widget(self), get_widget(child))) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -2169,6 +2358,23 @@ widget_get_alloc(self)
}
static VALUE
+widget_get_requisition(self)
+ VALUE self;
+{
+ return make_grequisition(&(get_widget(self)->requisition));
+}
+
+static VALUE
+widget_set_requisition(self, w,h)
+ VALUE self,w,h;
+{
+ GtkRequisition *r = &(get_widget(self)->requisition);
+ r->width = NUM2INT(w);
+ r->height = NUM2INT(h);
+ return self;
+}
+
+static VALUE
widget_state(self)
VALUE self;
{
@@ -2183,7 +2389,7 @@ bbox_get_child_size_default(self)
gtk_button_box_get_child_size_default(&min_width, &max_width);
- return assoc_new(INT2FIX(min_width), INT2FIX(max_width));
+ return rb_assoc_new(INT2FIX(min_width), INT2FIX(max_width));
}
static VALUE
@@ -2193,7 +2399,7 @@ bbox_get_child_ipadding_default(self)
int ipad_x, ipad_y;
gtk_button_box_get_child_ipadding_default(&ipad_x, &ipad_y);
- return assoc_new(INT2FIX(ipad_x), INT2FIX(ipad_y));
+ return rb_assoc_new(INT2FIX(ipad_x), INT2FIX(ipad_y));
}
static VALUE
@@ -2240,7 +2446,7 @@ bbox_get_child_size(self)
gtk_button_box_get_child_size(GTK_BUTTON_BOX(get_widget(self)),
&min_width, &max_width);
- return assoc_new(INT2FIX(min_width), INT2FIX(max_width));
+ return rb_assoc_new(INT2FIX(min_width), INT2FIX(max_width));
}
static VALUE
@@ -2251,7 +2457,7 @@ bbox_get_child_ipadding(self)
gtk_button_box_get_child_ipadding(GTK_BUTTON_BOX(get_widget(self)),
&ipad_x, &ipad_y);
- return assoc_new(INT2FIX(ipad_x), INT2FIX(ipad_y));
+ return rb_assoc_new(INT2FIX(ipad_x), INT2FIX(ipad_y));
}
static VALUE
@@ -2541,7 +2747,7 @@ clist_append(self, text)
Check_Type(text, T_ARRAY);
len = GTK_CLIST(get_widget(self))->columns;
if (len > RARRAY(text)->len) {
- ArgError("text too short");
+ rb_raise(rb_eArgError, "text too short");
}
buf = ALLOCA_N(char*, len);
for (i=0; i<len; i++) {
@@ -2561,7 +2767,7 @@ clist_insert(self, row, text)
Check_Type(text, T_ARRAY);
len = GTK_CLIST(get_widget(self))->columns;
if (len > RARRAY(text)->len) {
- ArgError("text too short");
+ rb_raise(rb_eArgError, "text too short");
}
buf = ALLOCA_N(char*, len);
for (i=0; i<len; i++) {
@@ -2763,7 +2969,7 @@ fsel_get_fname(self)
fname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(get_widget(self)));
- return str_new2(fname);
+ return rb_str_new2(fname);
}
static VALUE
@@ -2818,6 +3024,21 @@ label_initialize(self, label)
set_widget(self, gtk_label_new(STR2CSTR(label)));
return Qnil;
}
+static VALUE
+label_get_jtype(self)
+ VALUE self;
+{
+ return(INT2FIX(GTK_LABEL(get_widget(self))->jtype));
+}
+static VALUE
+label_set_jtype(self, jtype)
+ VALUE self, jtype;
+{
+ GtkJustification j;
+ j = (GtkJustification) NUM2INT(jtype);
+ gtk_label_set_justify(GTK_LABEL(get_widget(self)), j);
+ return self;
+}
static VALUE
label_get(self)
@@ -2825,7 +3046,7 @@ label_get(self)
{
gchar** str;
gtk_label_get(GTK_LABEL(get_widget(self)), str);
- return str_new2(*str);
+ return rb_str_new2(*str);
}
static VALUE
@@ -3237,7 +3458,7 @@ mitem_accelerator_text(self)
char buf[1024]; /* enough? */
gtk_menu_item_accelerator_text(GTK_MENU_ITEM(get_widget(self)), buf);
- return str_new2(buf);
+ return rb_str_new2(buf);
}
static VALUE
@@ -3345,7 +3566,7 @@ rmitem_initialize(argc, argv, self)
if (!NIL_P(arg2)) {
label = STR2CSTR(arg2);
}
- if (obj_is_kind_of(arg1, gRMenuItem)) {
+ if (rb_obj_is_kind_of(arg1, gRMenuItem)) {
GtkWidget *b = get_widget(arg1);
list = GTK_RADIO_MENU_ITEM(b)->group;
}
@@ -3475,7 +3696,7 @@ static VALUE
note_show_tabs(self)
VALUE self;
{
- return GTK_NOTEBOOK(get_widget(self))->show_tabs?TRUE:FALSE;
+ return GTK_NOTEBOOK(get_widget(self))->show_tabs?Qtrue:Qfalse;
}
static VALUE
@@ -3490,7 +3711,7 @@ static VALUE
note_show_border(self)
VALUE self;
{
- return GTK_NOTEBOOK(get_widget(self))->show_border?TRUE:FALSE;
+ return GTK_NOTEBOOK(get_widget(self))->show_border?Qtrue:Qfalse;
}
static VALUE
@@ -3562,7 +3783,7 @@ image_get(self)
gtk_image_get(GTK_IMAGE(get_widget(self)), &val, &mask);
- return assoc_new(make_gdkimage(self, val),
+ return rb_assoc_new(make_gdkimage(self, val),
make_gdkpixmap(mask));
}
@@ -3606,13 +3827,13 @@ preview_put_row(self, src, dst, x, y, w)
}
Check_Type(src, T_STRING);
if (RSTRING(src)->len < dlen) {
- ArgError("src too short");
+ rb_raise(rb_eArgError, "src too short");
}
Check_Type(dst, T_STRING);
if (RSTRING(dst)->len < dlen) {
- ArgError("dst too short");
+ rb_raise(rb_eArgError, "dst too short");
}
- str_modify(dst);
+ rb_str_modify(dst);
gtk_preview_put_row(GTK_PREVIEW(get_widget(self)),
RSTRING(src)->ptr, RSTRING(dst)->ptr,
NUM2INT(x), NUM2INT(y), width);
@@ -3631,7 +3852,7 @@ preview_draw_row(self, data, x, y, w)
}
Check_Type(data, T_STRING);
if (RSTRING(data)->len < dlen) {
- ArgError("data too short");
+ rb_raise(rb_eArgError, "data too short");
}
gtk_preview_draw_row(GTK_PREVIEW(get_widget(self)), RSTRING(data)->ptr,
@@ -3960,7 +4181,7 @@ tbar_append_item(self, text, ttext, ptext, icon, func)
VALUE self, text, ttext, ptext, icon, func;
{
if (NIL_P(func)) {
- func = f_lambda();
+ func = rb_f_lambda();
}
gtk_toolbar_append_item(GTK_TOOLBAR(get_widget(self)),
NIL_P(text)?NULL:STR2CSTR(text),
@@ -3977,7 +4198,7 @@ tbar_prepend_item(self, text, ttext, ptext, icon, func)
VALUE self, text, ttext, ptext, icon, func;
{
if (NIL_P(func)) {
- func = f_lambda();
+ func = rb_f_lambda();
}
gtk_toolbar_prepend_item(GTK_TOOLBAR(get_widget(self)),
NIL_P(text)?NULL:STR2CSTR(text),
@@ -3994,7 +4215,7 @@ tbar_insert_item(self, text, ttext, ptext, icon, func, pos)
VALUE self, text, ttext, ptext, icon, func, pos;
{
if (NIL_P(func)) {
- func = f_lambda();
+ func = rb_f_lambda();
}
gtk_toolbar_insert_item(GTK_TOOLBAR(get_widget(self)),
NIL_P(text)?NULL:STR2CSTR(text),
@@ -4389,8 +4610,8 @@ tbtn_active(self)
VALUE self;
{
if (GTK_TOGGLE_BUTTON(get_widget(self))->active)
- return TRUE;
- return FALSE;
+ return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -4430,7 +4651,7 @@ rbtn_initialize(argc, argv, self)
if (!NIL_P(arg2)) {
label = STR2CSTR(arg2);
}
- if (obj_is_kind_of(arg1, gRButton)) {
+ if (rb_obj_is_kind_of(arg1, gRButton)) {
GtkWidget *b = get_widget(arg1);
list = GTK_RADIO_BUTTON(b)->group;
}
@@ -4468,7 +4689,7 @@ box_pack_start_or_end(argc, argv, self, start)
gint expand, fill, padding;
GtkWidget *widget, *child;
- expand = fill = TRUE; padding = 0;
+ expand = fill = Qtrue; padding = 0;
switch (rb_scan_args(argc, argv, "13", &arg0, &arg1, &arg2, &arg3)) {
case 4:
padding = NUM2INT(arg3);
@@ -4556,7 +4777,7 @@ colorsel_set_color(self, color)
Check_Type(color, T_ARRAY);
if (RARRAY(color)->len < 3) {
- ArgError("color array too small");
+ rb_raise(rb_eArgError, "color array too small");
}
buf[0] = NUM2DBL(RARRAY(color)->ptr[0]);
buf[1] = NUM2DBL(RARRAY(color)->ptr[1]);
@@ -4574,10 +4795,10 @@ colorsel_get_color(self)
VALUE ary;
gtk_color_selection_get_color(GTK_COLOR_SELECTION(get_widget(self)), buf);
- ary = ary_new2(3);
- ary_push(ary, NUM2DBL(buf[0]));
- ary_push(ary, NUM2DBL(buf[1]));
- ary_push(ary, NUM2DBL(buf[2]));
+ ary = rb_ary_new2(3);
+ rb_ary_push(ary, NUM2DBL(buf[0]));
+ rb_ary_push(ary, NUM2DBL(buf[1]));
+ rb_ary_push(ary, NUM2DBL(buf[2]));
return ary;
}
@@ -4616,7 +4837,7 @@ pixmap_get(self)
gtk_pixmap_get(GTK_PIXMAP(get_widget(self)), &val, &mask);
- return assoc_new(make_gdkpixmap(val),
+ return rb_assoc_new(make_gdkpixmap(val),
make_gdkbitmap(mask));
}
@@ -4677,7 +4898,7 @@ edit_get_chars(self, start, end)
s = gtk_editable_get_chars(GTK_EDITABLE(get_widget(self)),
NUM2INT(start), NUM2INT(end));
- return str_new2(s);
+ return rb_str_new2(s);
}
static VALUE
@@ -4776,7 +4997,7 @@ entry_get_text(self)
{
gchar* text;
text = gtk_entry_get_text(GTK_ENTRY(get_widget(self)));
- return str_new2(text);
+ return rb_str_new2(text);
}
static VALUE
@@ -4847,7 +5068,7 @@ static VALUE
gamma_gamma(self)
VALUE self;
{
- return float_new(GTK_GAMMA_CURVE(get_widget(self))->gamma);
+ return rb_float_new(GTK_GAMMA_CURVE(get_widget(self))->gamma);
}
static VALUE
@@ -5492,6 +5713,13 @@ style_s_new(klass)
}
static VALUE
+style_copy(self)
+ VALUE self;
+{
+ return make_gstyle(gtk_style_copy(get_gstyle(self)));
+}
+
+static VALUE
style_attach(self, win)
VALUE self, win;
{
@@ -5506,7 +5734,7 @@ style_detach(self)
}
static VALUE
-style_set_bg(self, win, state_type)
+style_set_background(self, win, state_type)
VALUE self, win, state_type;
{
gtk_style_set_background(get_gstyle(self), get_gdkwindow(win),
@@ -5520,7 +5748,7 @@ style_fg(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->fg[i]);
}
@@ -5530,7 +5758,7 @@ style_bg(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->bg[i]);
}
@@ -5540,7 +5768,7 @@ style_light(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->light[i]);
}
@@ -5550,7 +5778,7 @@ style_dark(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->dark[i]);
}
@@ -5560,7 +5788,7 @@ style_mid(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->mid[i]);
}
@@ -5570,7 +5798,7 @@ style_text(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->text[i]);
}
@@ -5580,10 +5808,37 @@ style_base(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkcolor(get_gstyle(self)->base[i]);
}
+#define DEFINE_STYLE_SET_COLOR(FUNC, TYPE) \
+static VALUE \
+FUNC(self, idx, r, g, b) \
+ VALUE self, idx, r, g, b; \
+{ \
+ GtkStyle *style; \
+ GdkColor *color; \
+ int i = NUM2INT(idx); \
+ \
+ if (i < 0 || 5 < i) ArgError("state out of range"); \
+ style = get_gstyle(self); \
+ if (style->fg_gc[0] != NULL) ArgError("you must not change widget style."); \
+ color = &(style-> TYPE [i]); \
+ color->red = NUM2INT(r); \
+ color->green = NUM2INT(g); \
+ color->blue = NUM2INT(b); \
+ return(make_gdkcolor(*color)); \
+} \
+
+DEFINE_STYLE_SET_COLOR(style_set_fg, fg)
+DEFINE_STYLE_SET_COLOR(style_set_bg, bg)
+DEFINE_STYLE_SET_COLOR(style_set_light, light)
+DEFINE_STYLE_SET_COLOR(style_set_dark, dark)
+DEFINE_STYLE_SET_COLOR(style_set_mid, mid)
+DEFINE_STYLE_SET_COLOR(style_set_text, text)
+DEFINE_STYLE_SET_COLOR(style_set_base, base)
+
static VALUE
style_black(self)
{
@@ -5603,12 +5858,29 @@ style_font(self)
}
static VALUE
+style_set_font(self, f)
+ VALUE f;
+{
+ GdkFont *font = get_gdkfont(f);
+ GtkStyle *style = get_gstyle(self);
+
+ if (style->fg_gc[0] != NULL) ArgError("you must not change widget style.");
+ if (style->font != NULL)
+ gdk_font_unref(style->font);
+
+ gdk_font_ref(font);
+ style->font = font;
+
+ return self;
+}
+
+static VALUE
style_fg_gc(self, idx)
VALUE self, idx;
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->fg_gc[i]);
}
@@ -5618,7 +5890,7 @@ style_bg_gc(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->bg_gc[i]);
}
@@ -5628,7 +5900,7 @@ style_light_gc(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->light_gc[i]);
}
@@ -5638,7 +5910,7 @@ style_dark_gc(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->dark_gc[i]);
}
@@ -5648,7 +5920,7 @@ style_mid_gc(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->mid_gc[i]);
}
@@ -5658,7 +5930,7 @@ style_text_gc(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->text_gc[i]);
}
@@ -5668,7 +5940,7 @@ style_base_gc(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkgc(get_gstyle(self)->base_gc[i]);
}
@@ -5690,7 +5962,7 @@ style_bg_pixmap(self, idx)
{
int i = NUM2INT(idx);
- if (i < 0 || 5 < i) ArgError("state out of range");
+ if (i < 0 || 5 < i) rb_raise(rb_eArgError, "state out of range");
return make_gdkpixmap(get_gstyle(self)->bg_pixmap[i]);
}
@@ -5740,7 +6012,7 @@ style_draw_polygon(self,win,state_type,shadow_type,pnts,fill)
for (i=0; i<RARRAY(pnts)->len; i++) {
Check_Type(RARRAY(pnts)->ptr[i], T_ARRAY);
if (RARRAY(RARRAY(pnts)->ptr[i])->len < 2) {
- ArgError("point %d should be array of size 2", i);
+ rb_raise(rb_eArgError, "point %d should be array of size 2", i);
}
points[i].x = NUM2INT(RARRAY(RARRAY(pnts)->ptr[i])->ptr[0]);
points[i].y = NUM2INT(RARRAY(RARRAY(pnts)->ptr[i])->ptr[1]);
@@ -5805,6 +6077,32 @@ gallocation_h(self)
return INT2NUM(get_gallocation(self)->height);
}
+static VALUE
+grequisition_w(self)
+{
+ return INT2NUM(get_grequisition(self)->width);
+}
+static VALUE
+grequisition_h(self)
+{
+ return INT2NUM(get_grequisition(self)->height);
+}
+/*
+static VALUE
+grequisition_set_w(self, w)
+ VALUE self, w;
+{
+ get_grequisition(self)->width = NUM2INT(w);
+ return self;
+}
+static VALUE
+grequisition_set_h(self, h)
+ VALUE self, h;
+{
+ get_grequisition(self)->height = NUM2INT(h);
+ return self;
+}
+*/
static VALUE
gtk_m_main(self)
@@ -5908,7 +6206,7 @@ gdkdraw_draw_poly(self, gc, filled, pnts)
for (i=0; i<RARRAY(pnts)->len; i++) {
Check_Type(RARRAY(pnts)->ptr[i], T_ARRAY);
if (RARRAY(RARRAY(pnts)->ptr[i])->len < 2) {
- ArgError("point %d should be array of size 2", i);
+ rb_raise(rb_eArgError, "point %d should be array of size 2", i);
}
points[i].x = NUM2INT(RARRAY(RARRAY(pnts)->ptr[i])->ptr[0]);
points[i].y = NUM2INT(RARRAY(RARRAY(pnts)->ptr[i])->ptr[1]);
@@ -5980,7 +6278,7 @@ gdkdraw_draw_pnts(self, gc, pnts)
for (i=0; i<RARRAY(pnts)->len; i++) {
Check_Type(RARRAY(pnts)->ptr[i], T_ARRAY);
if (RARRAY(RARRAY(pnts)->ptr[i])->len < 2) {
- ArgError("point %d should be array of size 2", i);
+ rb_raise(rb_eArgError, "point %d should be array of size 2", i);
}
points[i].x = NUM2INT(RARRAY(RARRAY(pnts)->ptr[i])->ptr[0]);
points[i].y = NUM2INT(RARRAY(RARRAY(pnts)->ptr[i])->ptr[1]);
@@ -6003,7 +6301,7 @@ gdkdraw_draw_segs(self, gc, segs)
for (i=0; i<RARRAY(segs)->len; i++) {
Check_Type(RARRAY(segs)->ptr[i], T_ARRAY);
if (RARRAY(RARRAY(segs)->ptr[i])->len < 4) {
- ArgError("segment %d should be array of size 4", i);
+ rb_raise(rb_eArgError, "segment %d should be array of size 4", i);
}
segments[i].x1 = NUM2INT(RARRAY(RARRAY(segs)->ptr[i])->ptr[0]);
segments[i].y1 = NUM2INT(RARRAY(RARRAY(segs)->ptr[i])->ptr[1]);
@@ -6119,9 +6417,9 @@ idle()
{
CHECK_INTS;
#ifdef THREAD
- if (!thread_critical) thread_schedule();
+ if (!rb_thread_critical) rb_thread_schedule();
#endif
- return TRUE;
+ return Qtrue;
}
static void
@@ -6138,7 +6436,7 @@ timeout_add(self, interval)
int id;
id = gtk_timeout_add_interp(NUM2INT(interval), exec_interval,
- (gpointer)f_lambda(), 0);
+ (gpointer)rb_f_lambda(), 0);
return INT2FIX(id);
}
@@ -6156,7 +6454,7 @@ idle_add(self)
{
int id;
- id = gtk_idle_add_interp(exec_interval, (gpointer)f_lambda(), 0);
+ id = gtk_idle_add_interp(exec_interval, (gpointer)rb_f_lambda(), 0);
return INT2FIX(id);
}
@@ -6176,21 +6474,21 @@ static void
gtkwarn(mesg)
char *mesg;
{
- rb_funcall(warn_handler, id_call, 1, str_new2(mesg));
+ rb_funcall(warn_handler, id_call, 1, rb_str_new2(mesg));
}
static void
gtkmesg(mesg)
char *mesg;
{
- rb_funcall(mesg_handler, id_call, 1, str_new2(mesg));
+ rb_funcall(mesg_handler, id_call, 1, rb_str_new2(mesg));
}
static void
gtkprint(mesg)
char *mesg;
{
- rb_funcall(print_handler, id_call, 1, str_new2(mesg));
+ rb_funcall(print_handler, id_call, 1, rb_str_new2(mesg));
}
static VALUE
@@ -6203,7 +6501,7 @@ set_warning_handler(argc, argv, self)
rb_scan_args(argc, argv, "01", &handler);
if (NIL_P(handler)) {
- handler = f_lambda();
+ handler = rb_f_lambda();
}
g_set_warning_handler(gtkwarn);
return handler;
@@ -6219,7 +6517,7 @@ set_message_handler(argc, argv, self)
rb_scan_args(argc, argv, "01", &handler);
if (NIL_P(handler)) {
- handler = f_lambda();
+ handler = rb_f_lambda();
}
g_set_message_handler(gtkmesg);
return handler;
@@ -6235,7 +6533,7 @@ set_print_handler(argc, argv, self)
rb_scan_args(argc, argv, "01", &handler);
if (NIL_P(handler)) {
- handler = f_lambda();
+ handler = rb_f_lambda();
}
g_set_print_handler(gtkprint);
return handler;
@@ -6245,7 +6543,7 @@ static void
gtkerr(mesg)
char *mesg;
{
- Fail("%s", mesg);
+ rb_raise(rb_eRuntimeError, "%s", mesg);
}
void
@@ -6255,12 +6553,12 @@ Init_gtk()
char **argv;
gtk_set_locale();
- gtk_object_list = ary_new();
+ gtk_object_list = rb_ary_new();
rb_global_variable(&gtk_object_list);
mGtk = rb_define_module("Gtk");
- gObject = rb_define_class_under(mGtk, "Object", cObject);
+ gObject = rb_define_class_under(mGtk, "Object", rb_cObject);
gWidget = rb_define_class_under(mGtk, "Widget", gObject);
gContainer = rb_define_class_under(mGtk, "Container", gWidget);
gBin = rb_define_class_under(mGtk, "Bin", gContainer);
@@ -6332,38 +6630,38 @@ Init_gtk()
gTable = rb_define_class_under(mGtk, "Table", gContainer);
gText = rb_define_class_under(mGtk, "Text", gEditable);
gToolbar = rb_define_class_under(mGtk, "Toolbar", gContainer);
- gTooltips = rb_define_class_under(mGtk, "Tooltips", cData);
+ gTooltips = rb_define_class_under(mGtk, "Tooltips", rb_cData);
gTree = rb_define_class_under(mGtk, "Tree", gContainer);
gTreeItem = rb_define_class_under(mGtk, "TreeItem", gItem);
gViewPort = rb_define_class_under(mGtk, "ViewPort", gBin);
- gAcceleratorTable = rb_define_class_under(mGtk, "AcceleratorTable", cData);
- gStyle = rb_define_class_under(mGtk, "Style", cData);
- gPreviewInfo = rb_define_class_under(mGtk, "PreviewInfo", cData);
- gRequisiton = rb_define_class_under(mGtk, "Requisiton", cData);
- gAllocation = rb_define_class_under(mGtk, "Allocation", cData);
+ gAcceleratorTable = rb_define_class_under(mGtk, "AcceleratorTable", rb_cData);
+ gStyle = rb_define_class_under(mGtk, "Style", rb_cData);
+ gPreviewInfo = rb_define_class_under(mGtk, "PreviewInfo", rb_cData);
+ gRequisition = rb_define_class_under(mGtk, "Requisition", rb_cData);
+ gAllocation = rb_define_class_under(mGtk, "Allocation", rb_cData);
mRC = rb_define_module_under(mGtk, "RC");
mGdk = rb_define_module("Gdk");
- gdkFont = rb_define_class_under(mGdk, "Font", cData);
- gdkColor = rb_define_class_under(mGdk, "Color", cData);
- gdkDrawable = rb_define_class_under(mGdk, "Drawable", cData);
+ gdkFont = rb_define_class_under(mGdk, "Font", rb_cData);
+ gdkColor = rb_define_class_under(mGdk, "Color", rb_cData);
+ gdkDrawable = rb_define_class_under(mGdk, "Drawable", rb_cData);
gdkPixmap = rb_define_class_under(mGdk, "Pixmap", gdkDrawable);
gdkBitmap = rb_define_class_under(mGdk, "Bitmap", gdkPixmap);
gdkWindow = rb_define_class_under(mGdk, "Window", gdkDrawable);
- gdkImage = rb_define_class_under(mGdk, "Image", cData);
- gdkVisual = rb_define_class_under(mGdk, "Visual", cData);
- gdkGC = rb_define_class_under(mGdk, "GC", cData);
- gdkGCValues = rb_define_class_under(mGdk, "GCValues", cData);
- gdkRectangle = rb_define_class_under(mGdk, "Rectangle", cData);
- gdkSegment = rb_define_class_under(mGdk, "Segment", cData);
- gdkWindowAttr = rb_define_class_under(mGdk, "WindowAttr", cData);
- gdkCursor = rb_define_class_under(mGdk, "Cursor", cData);
- gdkAtom = rb_define_class_under(mGdk, "Atom", cData);
- gdkColorContext = rb_define_class_under(mGdk, "ColorContext", cData);
- gdkEvent = rb_define_class_under(mGdk, "gdkEvent", cData);
+ gdkImage = rb_define_class_under(mGdk, "Image", rb_cData);
+ gdkVisual = rb_define_class_under(mGdk, "Visual", rb_cData);
+ gdkGC = rb_define_class_under(mGdk, "GC", rb_cData);
+ gdkGCValues = rb_define_class_under(mGdk, "GCValues", rb_cData);
+ gdkRectangle = rb_define_class_under(mGdk, "Rectangle", rb_cData);
+ gdkSegment = rb_define_class_under(mGdk, "Segment", rb_cData);
+ gdkWindowAttr = rb_define_class_under(mGdk, "WindowAttr", rb_cData);
+ gdkCursor = rb_define_class_under(mGdk, "Cursor", rb_cData);
+ gdkAtom = rb_define_class_under(mGdk, "Atom", rb_cData);
+ gdkColorContext = rb_define_class_under(mGdk, "ColotContext", rb_cData);
+ gdkEvent = rb_define_class_under(mGdk, "gdkEvent", rb_cData);
gdkEventType = rb_define_class_under(mGdk, "gdkEventType", gdkEvent);
gdkEventAny = rb_define_class_under(mGdk, "gdkEventAny", gdkEvent);
@@ -6396,7 +6694,7 @@ Init_gtk()
rb_define_method(gObject, "signal_connect", gobj_sig_connect, -1);
rb_define_method(gObject, "signal_connect_after", gobj_sig_connect_after, -1);
rb_define_method(gObject, "singleton_method_added", gobj_smethod_added, 1);
- rb_define_method(gObject, "==", gobj_equal, 1);
+ rb_define_method(gObject, "==", grb_obj_equal, 1);
rb_define_method(gObject, "inspect", gobj_inspect, 0);
/* Widget */
@@ -6410,7 +6708,7 @@ Init_gtk()
rb_define_method(gWidget, "unrealize", widget_unrealize, 0);
rb_define_method(gWidget, "queue_draw", widget_queue_draw, 0);
rb_define_method(gWidget, "queue_resize", widget_queue_resize, 0);
- rb_define_method(gWidget, "draw", widget_draw, 1);
+ rb_define_method(gWidget, "draw", widget_draw, -1);
rb_define_method(gWidget, "draw_focus", widget_draw_focus, 0);
rb_define_method(gWidget, "draw_default", widget_draw_default, 0);
rb_define_method(gWidget, "draw_children", widget_draw_children, 0);
@@ -6424,6 +6722,7 @@ Init_gtk()
rb_define_method(gWidget, "grab_default", widget_grab_default, 0);
rb_define_method(gWidget, "set_state", widget_set_state, 1);
rb_define_method(gWidget, "visible?", widget_visible, 0);
+ rb_define_method(gWidget, "mapped?", widget_mapped, 0);
rb_define_method(gWidget, "reparent", widget_reparent, 1);
rb_define_method(gWidget, "popup", widget_popup, 2);
rb_define_method(gWidget, "intersect", widget_intersect, 2);
@@ -6439,6 +6738,8 @@ Init_gtk()
rb_define_method(gWidget, "set_extension_events", widget_set_eevents, 1);
rb_define_method(gWidget, "unparent", widget_unparent, 0);
rb_define_method(gWidget, "allocation", widget_get_alloc, 0);
+ rb_define_method(gWidget, "requisition", widget_get_requisition, 0);
+ rb_define_method(gWidget, "set_requisition", widget_set_requisition, 2);
rb_define_method(gWidget, "state", widget_state, 0);
rb_define_method(gWidget, "get_toplevel", widget_get_toplevel, 0);
rb_define_method(gWidget, "get_ancestor", widget_get_ancestor, 1);
@@ -6509,6 +6810,10 @@ Init_gtk()
/* Misc */
rb_define_method(gMisc, "set_alignment", misc_set_align, 2);
rb_define_method(gMisc, "set_padding", misc_set_padding, 2);
+ rb_define_method(gMisc, "xalign", misc_get_xalign, 0);
+ rb_define_method(gMisc, "yalign", misc_get_yalign, 0);
+ rb_define_method(gMisc, "xpad", misc_get_xpad, 0);
+ rb_define_method(gMisc, "ypad", misc_get_ypad, 0);
/* Arrow */
rb_define_method(gArrow, "initialize", arrow_initialize, 2);
@@ -6818,6 +7123,8 @@ Init_gtk()
rb_define_method(gLabel, "initialize", label_initialize, 1);
rb_define_method(gLabel, "get", label_get, 0);
rb_define_method(gLabel, "set", label_set, 1);
+ rb_define_method(gLabel, "jtype", label_get_jtype, 0);
+ rb_define_method(gLabel, "jtype=", label_set_jtype, 1);
/* List */
rb_define_method(gList, "initialize", list_initialize, 0);
@@ -7011,9 +7318,12 @@ Init_gtk()
/* AcceleratorTable */
/* Style */
rb_define_singleton_method(gStyle, "new", style_s_new, 0);
+ rb_define_method(gStyle, "copy", style_copy, 0);
+ rb_define_method(gStyle, "clone", style_copy, 0);
+ rb_define_method(gStyle, "dup", style_copy, 0);
rb_define_method(gStyle, "attach", style_attach, 1);
rb_define_method(gStyle, "detach", style_detach, 0);
- rb_define_method(gStyle, "set_background", style_set_bg, 0);
+ rb_define_method(gStyle, "set_background", style_set_background, 1);
rb_define_method(gStyle, "fg", style_fg, 1);
rb_define_method(gStyle, "bg", style_bg, 1);
rb_define_method(gStyle, "light", style_light, 1);
@@ -7021,9 +7331,18 @@ Init_gtk()
rb_define_method(gStyle, "mid", style_mid, 1);
rb_define_method(gStyle, "text", style_text, 1);
rb_define_method(gStyle, "base", style_base, 1);
+ rb_define_method(gStyle, "set_fg", style_set_fg, 4);
+ rb_define_method(gStyle, "set_bg", style_set_bg, 4);
+ rb_define_method(gStyle, "set_light", style_set_light, 4);
+ rb_define_method(gStyle, "set_dark", style_set_dark, 4);
+ rb_define_method(gStyle, "set_mid", style_set_mid, 4);
+ rb_define_method(gStyle, "set_text", style_set_text, 4);
+ rb_define_method(gStyle, "set_base", style_set_base, 4);
+
rb_define_method(gStyle, "black", style_black, 0);
rb_define_method(gStyle, "white", style_white, 0);
rb_define_method(gStyle, "font", style_font, 0);
+ rb_define_method(gStyle, "set_font", style_set_font, 1);
rb_define_method(gStyle, "fg_gc", style_fg_gc, 1);
rb_define_method(gStyle, "bg_gc", style_bg_gc, 1);
rb_define_method(gStyle, "light_gc", style_light_gc, 1);
@@ -7050,6 +7369,13 @@ Init_gtk()
rb_define_method(gAllocation, "width", gallocation_w, 0);
rb_define_method(gAllocation, "height", gallocation_h, 0);
+ rb_define_method(gRequisition, "width", grequisition_w, 0);
+ rb_define_method(gRequisition, "height", grequisition_h, 0);
+ /*
+ rb_define_method(gRequisition, "width=", grequisition_set_w, 1);
+ rb_define_method(gRequisition, "height=", grequisition_set_h, 1);
+ */
+
/* Gtk module */
rb_define_module_function(mGtk, "main", gtk_m_main, 0);
rb_define_module_function(mGtk, "timeout_add", timeout_add, 1);
@@ -7075,6 +7401,12 @@ Init_gtk()
/* Gdk module */
/* GdkFont */
+ rb_define_singleton_method(gdkFont, "load_font", gdkfnt_load_font, 1);
+ rb_define_singleton_method(gdkFont, "new", gdkfnt_new, 1);
+ rb_define_singleton_method(gdkFont, "load_fontset", gdkfnt_load_fontset, 1);
+ rb_define_method(gdkFont, "string_width", gdkfnt_string_width, 1);
+ rb_define_method(gdkFont, "ascent", gdkfnt_ascent, 0);
+ rb_define_method(gdkFont, "descent", gdkfnt_descent, 0);
rb_define_method(gdkFont, "==", gdkfnt_equal, 1);
/* GdkDrawable */
@@ -7112,11 +7444,23 @@ Init_gtk()
rb_define_method(gdkWindow, "pointer_ungrab", gdkwin_pointer_ungrab, 1);
rb_define_singleton_method(gdkWindow, "foreign_new", gdkwin_foreign_new, 1);
rb_define_singleton_method(gdkWindow, "root_window", gdkwin_root_window, 0);
+ rb_define_method(gdkWindow, "clear", gdkwin_clear, 0);
+ rb_define_method(gdkWindow, "clear_area", gdkwin_clear_area, 4);
+ rb_define_method(gdkWindow, "clear_area_e", gdkwin_clear, 4);
+ rb_define_method(gdkWindow, "set_background", gdkwin_set_background, 1);
+ rb_define_method(gdkWindow, "set_back_pixmap", gdkwin_set_back_pixmap, 2);
/* GdkGC */
rb_define_singleton_method(gdkGC, "new", gdkgc_s_new, 1);
rb_define_method(gdkGC, "copy", gdkgc_copy, 1);
rb_define_method(gdkGC, "destroy", gdkgc_destroy, 0);
+ rb_define_method(gdkGC, "set_function", gdkgc_set_function, 1);
+ rb_define_method(gdkGC, "set_foreground", gdkgc_set_foreground, 1);
+ rb_define_method(gdkGC, "set_background", gdkgc_set_background, 1);
+ rb_define_method(gdkGC, "set_clip_mask", gdkgc_set_clip_mask, 1);
+ rb_define_method(gdkGC, "set_clip_origin", gdkgc_set_clip_origin, 2);
+ rb_define_method(gdkGC, "set_clip_rectangle", gdkgc_set_clip_rectangle, 1);
+ /* rb_define_method(gdkGC, "set_clip_region", gdkgc_set_clip_region, 1); */
/* GdkImage */
rb_define_singleton_method(gdkImage, "new_bitmap", gdkimage_s_newbmap, 4);
@@ -7185,6 +7529,12 @@ Init_gtk()
rb_define_const(mGtk, "POLICY_ALWAYS", INT2FIX(GTK_POLICY_ALWAYS));
rb_define_const(mGtk, "POLICY_AUTOMATIC", INT2FIX(GTK_POLICY_AUTOMATIC));
+ /* GtkJustification */
+ rb_define_const(mGtk, "JUSTIFY_LEFT", INT2FIX(GTK_JUSTIFY_LEFT));
+ rb_define_const(mGtk, "JUSTIFY_RIGHT", INT2FIX(GTK_JUSTIFY_RIGHT));
+ rb_define_const(mGtk, "JUSTIFY_CENTER", INT2FIX(GTK_JUSTIFY_CENTER));
+ rb_define_const(mGtk, "JUSTIFY_FILL", INT2FIX(GTK_JUSTIFY_FILL));
+
/* GtkSelectionMode */
rb_define_const(mGtk, "SELECTION_SINGLE", INT2FIX(GTK_SELECTION_SINGLE));
rb_define_const(mGtk, "SELECTION_BROWSE", INT2FIX(GTK_SELECTION_BROWSE));
@@ -7248,6 +7598,11 @@ Init_gtk()
rb_define_const(mGtk, "ORIENTATION_HORIZONTAL", INT2FIX(GTK_ORIENTATION_HORIZONTAL));
rb_define_const(mGtk, "ORIENTATION_VERTICAL", INT2FIX(GTK_ORIENTATION_VERTICAL));
+ /* GdkMiscMode */
+ rb_define_const(mGdk, "FUNCTION_COPY", INT2FIX(GDK_COPY));
+ rb_define_const(mGdk, "FUNCTION_INVERT", INT2FIX(GDK_INVERT));
+ rb_define_const(mGdk, "FUNCTION_XOR", INT2FIX(GDK_XOR));
+
/* GdkExtensionMode */
rb_define_const(mGdk, "EXTENSION_EVENTS_NONE", INT2FIX(GDK_EXTENSION_EVENTS_NONE));
rb_define_const(mGdk, "EXTENSION_EVENTS_ALL", INT2FIX(GDK_EXTENSION_EVENTS_ALL));
@@ -7336,7 +7691,7 @@ Init_gtk()
}
for (i=1;i<argc;i++) {
- RARRAY(rb_argv)->ptr[i] = str_taint(str_new2(argv[i]));
+ RARRAY(rb_argv)->ptr[i-1] = rb_str_taint(rb_str_new2(argv[i]));
}
RARRAY(rb_argv)->len = argc-1;
diff --git a/ext/kconv/kconv.c b/ext/kconv/kconv.c
index fb229c6..d9bb2b4 100644
--- a/ext/kconv/kconv.c
+++ b/ext/kconv/kconv.c
@@ -1833,7 +1833,7 @@ kconv_kconv(argc, argv)
if (in_code == _NOCONV) return (VALUE)src;
}
- dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ dst = rb_str_new(0, RSTRING(src)->len*3+10); /* large enough? */
RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, out_code, in_code);
return dst;
@@ -1847,7 +1847,7 @@ kconv_tojis(obj, src)
Check_Type(src, T_STRING);
- dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ dst = rb_str_new(0, RSTRING(src)->len*3+10); /* large enough? */
RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, _JIS, _AUTO);
return dst;
@@ -1861,7 +1861,7 @@ kconv_toeuc(obj, src)
Check_Type(src, T_STRING);
- dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ dst = rb_str_new(0, RSTRING(src)->len*3+10); /* large enough? */
RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, _EUC, _AUTO);
return (VALUE)dst;
@@ -1875,7 +1875,7 @@ kconv_tosjis(obj, src)
Check_Type(src, T_STRING);
- dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ dst = rb_str_new(0, RSTRING(src)->len*3+10); /* large enough? */
RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, _SJIS, _AUTO);
return dst;
diff --git a/ext/md5/md5init.c b/ext/md5/md5init.c
index 65fd996..9562646 100644
--- a/ext/md5/md5init.c
+++ b/ext/md5/md5init.c
@@ -42,7 +42,7 @@ md5_digest(obj)
ctx = *md5;
MD5Final(digest, &ctx);
- return str_new(digest, 16);
+ return rb_str_new(digest, 16);
}
static VALUE
@@ -77,14 +77,14 @@ md5_new(argc, argv, class)
if (!NIL_P(arg)) {
md5_update(obj, arg);
}
- obj_call_init(obj);
+ rb_obj_call_init(obj);
return obj;
}
Init_md5()
{
- cMD5 = rb_define_class("MD5", cObject);
+ cMD5 = rb_define_class("MD5", rb_cObject);
rb_define_singleton_method(cMD5, "new", md5_new, -1);
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 2dc7d38..85c41d2 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -17,6 +17,7 @@ else
end
have_header("sys/un.h")
if have_func(test_func)
+ have_func("inet_aton")
have_func("hsterror")
unless have_func("gethostname")
have_func("uname")
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index bd9bae8..f3cfafb 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -25,7 +25,7 @@
#ifdef USE_CWGUSI
extern int fileno(FILE *stream); /* <unix.mac.h> */
-extern int thread_select(int, fd_set*, fd_set*, fd_set*, struct timeval*); /* thread.c */
+extern int rb_thread_select(int, fd_set*, fd_set*, fd_set*, struct timeval*); /* thread.c */
# include <sys/errno.h>
# include <GUSI.h>
#endif
@@ -42,26 +42,25 @@ extern int thread_select(int, fd_set*, fd_set*, fd_set*, struct timeval*); /* th
#define EWOULDBLOCK EAGAIN
#endif
-VALUE cBasicSocket;
-VALUE cIPsocket;
-VALUE cTCPsocket;
-VALUE cTCPserver;
-VALUE cUDPsocket;
+VALUE rb_cBasicSocket;
+VALUE rb_cIPsocket;
+VALUE rb_cTCPsocket;
+VALUE rb_cTCPserver;
+VALUE rb_cUDPsocket;
#ifdef AF_UNIX
-VALUE cUNIXsocket;
-VALUE cUNIXserver;
+VALUE rb_cUNIXsocket;
+VALUE rb_cUNIXserver;
#endif
-VALUE cSocket;
+VALUE rb_cSocket;
-static VALUE eSocket;
+static VALUE rb_eSocket;
#ifdef SOCKS
-VALUE cSOCKSsocket;
+VALUE rb_cSOCKSsocket;
void SOCKSinit();
int Rconnect();
#endif
-FILE *rb_fdopen();
char *strdup();
#define INET_CLIENT 0
@@ -97,8 +96,8 @@ sock_new(class, fd)
#endif
fp->f2 = rb_fdopen(fd, "w");
fp->mode = FMODE_READWRITE;
- io_unbuffered(fp);
- obj_call_init((VALUE)sock);
+ rb_io_unbuffered(fp);
+ rb_obj_call_init((VALUE)sock);
return (VALUE)sock;
}
@@ -119,9 +118,9 @@ bsock_shutdown(argc, argv, sock)
how = 2;
else {
how = NUM2INT(howto);
-#if 0
- if (how < 0 || 2 < how) how = 2;
-#endif
+ if (how < 0 || 2 < how) {
+ rb_raise(rb_eArgError, "`how' should be either 0, 1, 2");
+ }
}
GetOpenFile(sock, fptr);
if (shutdown(fileno(fptr->f), how) == -1)
@@ -156,7 +155,7 @@ bsock_setsockopt(sock, lev, optname, val)
v = (char*)&i; vlen = sizeof(i);
break;
default:
- v = str2cstr(val, &vlen);
+ v = rb_str2cstr(val, &vlen);
}
GetOpenFile(sock, fptr);
@@ -184,7 +183,7 @@ bsock_getsockopt(sock, lev, optname)
if (getsockopt(fileno(fptr->f), level, option, buf, &len) < 0)
rb_sys_fail(fptr->path);
- return str_new(buf, len);
+ return rb_str_new(buf, len);
#else
rb_notimplement();
#endif
@@ -201,7 +200,7 @@ bsock_getsockname(sock)
GetOpenFile(sock, fptr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
rb_sys_fail("getsockname(2)");
- return str_new(buf, len);
+ return rb_str_new(buf, len);
}
static VALUE
@@ -215,7 +214,7 @@ bsock_getpeername(sock)
GetOpenFile(sock, fptr);
if (getpeername(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0)
rb_sys_fail("getpeername(2)");
- return str_new(buf, len);
+ return rb_str_new(buf, len);
}
static VALUE
@@ -240,11 +239,11 @@ bsock_send(argc, argv, sock)
fd = fileno(f);
retry:
#ifdef THREAD
- thread_fd_writable(fd);
+ rb_thread_fd_writable(fd);
#endif
- m = str2cstr(msg, &mlen);
+ m = rb_str2cstr(msg, &mlen);
if (RTEST(to)) {
- t = str2cstr(to, &tlen);
+ t = rb_str2cstr(to, &tlen);
n = sendto(fd, m, mlen, NUM2INT(flags),
(struct sockaddr*)t, tlen);
}
@@ -259,7 +258,7 @@ bsock_send(argc, argv, sock)
case EAGAIN:
#endif
#ifdef THREAD
- thread_schedule();
+ rb_thread_schedule();
#endif
goto retry;
}
@@ -289,7 +288,6 @@ s_recv(sock, argc, argv, from)
enum sock_recv_type from;
{
OpenFile *fptr;
- FILE f;
VALUE str;
char buf[1024];
int fd, alen = sizeof buf;
@@ -301,12 +299,12 @@ s_recv(sock, argc, argv, from)
if (flg == Qnil) flags = 0;
else flags = NUM2INT(flg);
- str = str_new(0, NUM2INT(len));
+ str = rb_str_new(0, NUM2INT(len));
GetOpenFile(sock, fptr);
fd = fileno(fptr->f);
#ifdef THREAD
- thread_wait_fd(fd);
+ rb_thread_wait_fd(fd);
#endif
TRAP_BEG;
retry:
@@ -322,37 +320,34 @@ s_recv(sock, argc, argv, from)
case EAGAIN:
#endif
#ifdef THREAD
- thread_schedule();
+ rb_thread_schedule();
#endif
goto retry;
}
rb_sys_fail("recvfrom(2)");
}
- str_taint(str);
+ rb_str_taint(str);
switch (from) {
case RECV_RECV:
return (VALUE)str;
case RECV_TCP:
if (alen != sizeof(struct sockaddr_in)) {
- TypeError("sockaddr size differs - should not happen");
+ rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
- return assoc_new(str, ipaddr((struct sockaddr_in *)buf));
+ return rb_assoc_new(str, ipaddr((struct sockaddr_in *)buf));
case RECV_UDP:
{
VALUE addr = ipaddr((struct sockaddr_in *)buf);
- return assoc_new(str, assoc_new(RARRAY(addr)->ptr[2],
- RARRAY(addr)->ptr[1]));
+ return rb_assoc_new(str, rb_assoc_new(RARRAY(addr)->ptr[2],
+ RARRAY(addr)->ptr[1]));
}
#ifdef HAVE_SYS_UN_H
case RECV_UNIX:
- if (alen != sizeof(struct sockaddr_un)) {
- TypeError("sockaddr size differs - should not happen");
- }
- return assoc_new(str, unixaddr((struct sockaddr_un *)buf));
+ return rb_assoc_new(str, unixaddr((struct sockaddr_un *)buf));
#endif
case RECV_SOCKET:
- return assoc_new(str, str_new(buf, alen));
+ return rb_assoc_new(str, rb_str_new(buf, alen));
}
}
@@ -365,6 +360,95 @@ bsock_recv(argc, argv, sock)
return s_recv(sock, argc, argv, RECV_RECV);
}
+static VALUE
+mkipaddr(x)
+ unsigned long x;
+{
+ char buf[16];
+
+ x = ntohl(x);
+ sprintf(buf, "%d.%d.%d.%d",
+ (int) (x>>24) & 0xff, (int) (x>>16) & 0xff,
+ (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff);
+ return rb_str_new2(buf);
+}
+
+static VALUE
+ipaddr(sockaddr)
+ struct sockaddr_in *sockaddr;
+{
+ VALUE family, port, addr1, addr2;
+ VALUE ary;
+ struct hostent *hostent;
+
+ family = rb_str_new2("AF_INET");
+ hostent = gethostbyaddr((char*)&sockaddr->sin_addr.s_addr,
+ sizeof(sockaddr->sin_addr),
+ AF_INET);
+ addr1 = 0;
+ if (hostent) {
+ addr1 = rb_str_new2(hostent->h_name);
+ }
+ addr2 = mkipaddr(sockaddr->sin_addr.s_addr);
+ if (!addr1) addr1 = addr2;
+
+ port = INT2FIX(ntohs(sockaddr->sin_port));
+ ary = rb_ary_new3(4, family, port, addr1, addr2);
+
+ return ary;
+}
+
+#ifndef HAVE_INET_ATON
+static unsigned long
+inet_aton(host, inp)
+ char *host;
+ struct in_addr *inp;
+{
+ int d1, d2, d3, d4;
+ char ch;
+
+ if (sscanf(host, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 &&
+ 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 &&
+ 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) {
+ inp->s_addr = htonl(
+ ((long) d1 << 24) | ((long) d2 << 16) |
+ ((long) d3 << 8) | ((long) d4 << 0));
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+static void
+setipaddr(name, addr)
+ char *name;
+ struct sockaddr_in *addr;
+{
+ struct hostent *hp;
+
+ if (name[0] == 0) {
+ addr->sin_addr.s_addr = INADDR_ANY;
+ }
+ else if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
+ addr->sin_addr.s_addr = INADDR_BROADCAST;
+ }
+ else if (inet_aton(name, &addr->sin_addr) != 0) {
+ /* ok to set addr->sin_addr */
+ }
+ else {
+ hp = gethostbyname(name);
+ if (!hp) {
+#ifdef HAVE_HSTRERROR
+ extern int h_errno;
+ rb_raise(rb_eSocket, (char *)hstrerror(h_errno));
+#else
+ rb_raise(rb_eSocket, "host not found");
+#endif
+ }
+ memcpy((char *) &addr->sin_addr, hp->h_addr, hp->h_length);
+ }
+}
+
#if defined(THREAD) && defined(HAVE_FCNTL)
static int
thread_connect(fd, sockaddr, len, type)
@@ -408,7 +492,7 @@ thread_connect(fd, sockaddr, len, type)
#endif
FD_ZERO(&fds);
FD_SET(fd, &fds);
- thread_select(fd+1, 0, &fds, 0, 0);
+ rb_thread_select(fd+1, 0, &fds, 0, 0);
continue;
#endif
@@ -446,27 +530,23 @@ open_inet(class, h, serv, type)
int hostaddr, hostaddrPtr[2];
int servport;
char *syscall;
- VALUE sock;
if (h) {
Check_SafeStr(h);
host = RSTRING(h)->ptr;
hostent = gethostbyname(host);
if (hostent == NULL) {
-#ifndef USE_CWGUSI
- hostaddr = inet_addr(host);
-#else
- hostaddr = inet_addr(host).s_addr;
-#endif
+ inet_aton(host, &sockaddr.sin_addr);
+ hostaddr = sockaddr.sin_addr.s_addr;
if (hostaddr == -1) {
if (type == INET_SERVER && !strlen(host))
hostaddr = INADDR_ANY;
else {
#ifdef HAVE_HSTRERROR
extern int h_errno;
- Raise(eSocket, (char *)hstrerror(h_errno));
+ rb_raise(rb_eSocket, (char *)hstrerror(h_errno));
#else
- Raise(eSocket, "host not found");
+ rb_raise(rb_eSocket, "host not found");
#endif
}
}
@@ -490,7 +570,7 @@ open_inet(class, h, serv, type)
servport = strtoul(s, &end, 0);
if (*end != '\0') {
- Raise(eSocket, "no such servce %s", s);
+ rb_raise(rb_eSocket, "no such servce %s", s);
}
setup_servent:
_servent.s_port = htons(servport);
@@ -502,7 +582,7 @@ open_inet(class, h, serv, type)
#else
protoent = getprotobyname(servent->s_proto);
if (protoent == NULL) {
- Raise(eSocket, "no such proto %s", servent->s_proto);
+ rb_raise(rb_eSocket, "no such proto %s", servent->s_proto);
}
fd = socket(AF_INET, SOCK_STREAM, protoent->p_proto);
@@ -545,7 +625,7 @@ open_inet(class, h, serv, type)
}
if (status < 0) {
- close (fd);
+ close(fd);
rb_sys_fail(syscall);
}
if (type == INET_SERVER) listen(fd, 5);
@@ -580,6 +660,49 @@ socks_s_open(class, host, serv)
#endif
static VALUE
+tcp_s_gethostbyname(obj, host)
+ VALUE obj, host;
+{
+ struct sockaddr_in addr;
+ struct hostent *h;
+ char **pch;
+ VALUE ary, names;
+
+ setipaddr(STR2CSTR(host), &addr);
+ h = gethostbyaddr((char *)&addr.sin_addr,
+ sizeof(addr.sin_addr),
+ AF_INET);
+
+ if (h == NULL) {
+#ifdef HAVE_HSTRERROR
+ extern int h_errno;
+ rb_raise(rb_eSocket, (char *)hstrerror(h_errno));
+#else
+ rb_raise(rb_eSocket, "host not found");
+#endif
+ }
+ ary = rb_ary_new();
+ rb_ary_push(ary, rb_str_new2(h->h_name));
+ names = rb_ary_new();
+ rb_ary_push(ary, names);
+ for (pch = h->h_aliases; *pch; pch++) {
+ rb_ary_push(names, rb_str_new2(*pch));
+ }
+ rb_ary_push(ary, NUM2INT(h->h_addrtype));
+#ifdef h_addr
+ for (pch = h->h_addr_list; *pch; pch++) {
+ memcpy((char *) &addr.sin_addr, *pch, h->h_length);
+ rb_ary_push(ary, mkipaddr(addr.sin_addr.s_addr));
+ }
+#else
+ memcpy((char *)&addr.sin_addr, h->h_addr, h->h_length);
+ rb_ary_push(ary, mkipaddr(addr.sin_addr.s_addr));
+#endif
+
+ return ary;
+}
+
+static VALUE
tcp_svr_s_open(argc, argv, class)
int argc;
VALUE *argv;
@@ -604,7 +727,7 @@ s_accept(class, fd, sockaddr, len)
retry:
#ifdef THREAD
- thread_wait_fd(fd);
+ rb_thread_wait_fd(fd);
#endif
TRAP_BEG;
fd2 = accept(fd, sockaddr, len);
@@ -617,7 +740,7 @@ s_accept(class, fd, sockaddr, len)
case EAGAIN:
#endif
#ifdef THREAD
- thread_schedule();
+ rb_thread_schedule();
#endif
goto retry;
}
@@ -636,7 +759,7 @@ tcp_accept(sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_in);
- return s_accept(cTCPsocket, fileno(fptr->f),
+ return s_accept(rb_cTCPsocket, fileno(fptr->f),
(struct sockaddr*)&from, &fromlen);
}
@@ -692,81 +815,6 @@ open_unix(class, path, server)
}
#endif
-static void
-setipaddr(name, addr)
- char *name;
- struct sockaddr_in *addr;
-{
- int d1, d2, d3, d4;
- char ch;
- struct hostent *hp;
- long x;
-
- if (name[0] == 0) {
- addr->sin_addr.s_addr = INADDR_ANY;
- }
- else if (name[0] == '<' && strcmp(name, "<broadcast>") == 0) {
- addr->sin_addr.s_addr = INADDR_BROADCAST;
- }
- else if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 &&
- 0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 &&
- 0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) {
- addr->sin_addr.s_addr = htonl(
- ((long) d1 << 24) | ((long) d2 << 16) |
- ((long) d3 << 8) | ((long) d4 << 0));
- }
- else {
- hp = gethostbyname(name);
- if (!hp) {
-#ifdef HAVE_HSTRERROR
- extern int h_errno;
- Raise(eSocket, (char *)hstrerror(h_errno));
-#else
- Raise(eSocket, "host not found");
-#endif
- }
- memcpy((char *) &addr->sin_addr, hp->h_addr, hp->h_length);
- }
-}
-
-static VALUE
-mkipaddr(x)
- unsigned long x;
-{
- char buf[16];
-
- x = ntohl(x);
- sprintf(buf, "%d.%d.%d.%d",
- (int) (x>>24) & 0xff, (int) (x>>16) & 0xff,
- (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff);
- return str_new2(buf);
-}
-
-static VALUE
-ipaddr(sockaddr)
- struct sockaddr_in *sockaddr;
-{
- VALUE family, port, addr1, addr2;
- VALUE ary;
- struct hostent *hostent;
-
- family = str_new2("AF_INET");
- hostent = gethostbyaddr((char*)&sockaddr->sin_addr.s_addr,
- sizeof(sockaddr->sin_addr),
- AF_INET);
- addr1 = 0;
- if (hostent) {
- addr1 = str_new2(hostent->h_name);
- }
- addr2 = mkipaddr(sockaddr->sin_addr.s_addr);
- if (!addr1) addr1 = addr2;
-
- port = INT2FIX(ntohs(sockaddr->sin_port));
- ary = ary_new3(4, family, port, addr1, addr2);
-
- return ary;
-}
-
static VALUE
ip_addr(sock)
VALUE sock;
@@ -803,7 +851,7 @@ ip_s_getaddress(obj, host)
{
struct sockaddr_in addr;
- if (obj_is_kind_of(host, cInteger)) {
+ if (rb_obj_is_kind_of(host, rb_cInteger)) {
int i = NUM2INT(host);
addr.sin_addr.s_addr = htonl(i);
}
@@ -826,14 +874,12 @@ udp_addrsetup(host, port, addr)
VALUE host, port;
struct sockaddr_in *addr;
{
- struct hostent *hostent;
-
memset(addr, 0, sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
if (NIL_P(host)) {
addr->sin_addr.s_addr = INADDR_ANY;
}
- else if (obj_is_kind_of(host, cInteger)) {
+ else if (rb_obj_is_kind_of(host, rb_cInteger)) {
int i = NUM2INT(host);
addr->sin_addr.s_addr = htonl(i);
}
@@ -857,7 +903,7 @@ udp_addrsetup(host, port, addr)
portno = strtoul(s, &end, 0);
if (*end != '\0') {
- Raise(eSocket, "no such servce %s", s);
+ rb_raise(rb_eSocket, "no such servce %s", s);
}
addr->sin_port = htons(port);
}
@@ -882,7 +928,7 @@ udp_connect(sock, host, port)
case EAGAIN:
#endif
#ifdef THREAD
- thread_schedule();
+ rb_thread_schedule();
#endif
goto retry;
}
@@ -929,7 +975,7 @@ udp_send(argc, argv, sock)
udp_addrsetup(host, port, &addr);
GetOpenFile(sock, fptr);
f = fptr->f2?fptr->f2:fptr->f;
- m = str2cstr(mesg, &mlen);
+ m = rb_str2cstr(mesg, &mlen);
retry:
n = sendto(fileno(f), m, mlen, NUM2INT(flags),
(struct sockaddr*)&addr, sizeof(addr));
@@ -941,7 +987,7 @@ udp_send(argc, argv, sock)
case EAGAIN:
#endif
#ifdef THREAD
- thread_schedule();
+ rb_thread_schedule();
#endif
goto retry;
}
@@ -981,7 +1027,7 @@ unix_path(sock)
rb_sys_fail(0);
fptr->path = strdup(addr.sun_path);
}
- return str_new2(fptr->path);
+ return rb_str_new2(fptr->path);
}
static VALUE
@@ -1010,7 +1056,7 @@ unix_accept(sock)
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
- return s_accept(cUNIXsocket, fileno(fptr->f),
+ return s_accept(rb_cUNIXsocket, fileno(fptr->f),
(struct sockaddr*)&from, &fromlen);
}
@@ -1018,7 +1064,7 @@ static VALUE
unixaddr(sockaddr)
struct sockaddr_un *sockaddr;
{
- return assoc_new(str_new2("AF_UNIX"),str_new2(sockaddr->sun_path));
+ return rb_assoc_new(rb_str_new2("AF_UNIX"),rb_str_new2(sockaddr->sun_path));
}
static VALUE
@@ -1102,7 +1148,7 @@ setup_domain_and_type(domain, dv, type, tv)
*dv = PF_IPX;
#endif
else
- Raise(eSocket, "Unknown socket domain %s", ptr);
+ rb_raise(rb_eSocket, "Unknown socket domain %s", ptr);
}
else {
*dv = NUM2INT(domain);
@@ -1130,7 +1176,7 @@ setup_domain_and_type(domain, dv, type, tv)
*tv = SOCK_PACKET;
#endif
else
- Raise(eSocket, "Unknown socket type %s", ptr);
+ rb_raise(rb_eSocket, "Unknown socket type %s", ptr);
}
else {
*tv = NUM2INT(type);
@@ -1143,7 +1189,6 @@ sock_s_open(class, domain, type, protocol)
{
int fd;
int d, t;
- VALUE s;
setup_domain_and_type(domain, &d, type, &t);
fd = socket(d, t, NUM2INT(protocol));
@@ -1164,14 +1209,13 @@ sock_s_socketpair(class, domain, type, protocol)
VALUE class, domain, type, protocol;
{
#if !defined(NT) && !defined(__BEOS__)
- int fd;
int d, t, sp[2];
setup_domain_and_type(domain, &d, type, &t);
if (socketpair(d, t, NUM2INT(protocol), sp) < 0)
rb_sys_fail("socketpair(2)");
- return assoc_new(sock_new(class, sp[0]), sock_new(class, sp[1]));
+ return rb_assoc_new(sock_new(class, sp[0]), sock_new(class, sp[1]));
#else
rb_notimplement();
#endif
@@ -1184,7 +1228,7 @@ sock_connect(sock, addr)
OpenFile *fptr;
Check_Type(addr, T_STRING);
- str_modify(addr);
+ rb_str_modify(addr);
GetOpenFile(sock, fptr);
retry:
@@ -1196,7 +1240,7 @@ sock_connect(sock, addr)
case EAGAIN:
#endif
#ifdef THREAD
- thread_schedule();
+ rb_thread_schedule();
#endif
goto retry;
}
@@ -1213,7 +1257,7 @@ sock_bind(sock, addr)
OpenFile *fptr;
Check_Type(addr, T_STRING);
- str_modify(addr);
+ rb_str_modify(addr);
GetOpenFile(sock, fptr);
if (bind(fileno(fptr->f), (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len) < 0)
@@ -1254,9 +1298,9 @@ sock_accept(sock)
int len = sizeof buf;
GetOpenFile(sock, fptr);
- sock2 = s_accept(cSocket,fileno(fptr->f),(struct sockaddr*)buf,&len);
+ sock2 = s_accept(rb_cSocket,fileno(fptr->f),(struct sockaddr*)buf,&len);
- return assoc_new(sock2, str_new(buf, len));
+ return rb_assoc_new(sock2, rb_str_new(buf, len));
}
#ifdef HAVE_GETHOSTNAME
@@ -1270,7 +1314,7 @@ sock_gethostname(obj)
rb_sys_fail("gethostname");
buf[sizeof buf - 1] = '\0';
- return str_new2(buf);
+ return rb_str_new2(buf);
}
#else
#ifdef HAVE_UNAME
@@ -1284,7 +1328,7 @@ sock_gethostname(obj)
struct utsname un;
uname(&un);
- return str_new2(un.nodename);
+ return rb_str_new2(un.nodename);
}
#else
static VALUE
@@ -1300,32 +1344,31 @@ static VALUE
mkhostent(h)
struct hostent *h;
{
- struct sockaddr_in addr;
char **pch;
VALUE ary, names;
if (h == NULL) {
#ifdef HAVE_HSTRERROR
extern int h_errno;
- Raise(eSocket, (char *)hstrerror(h_errno));
+ rb_raise(rb_eSocket, (char *)hstrerror(h_errno));
#else
- Raise(eSocket, "host not found");
+ rb_raise(rb_eSocket, "host not found");
#endif
}
- ary = ary_new();
- ary_push(ary, str_new2(h->h_name));
- names = ary_new();
- ary_push(ary, names);
+ ary = rb_ary_new();
+ rb_ary_push(ary, rb_str_new2(h->h_name));
+ names = rb_ary_new();
+ rb_ary_push(ary, names);
for (pch = h->h_aliases; *pch; pch++) {
- ary_push(names, str_new2(*pch));
+ rb_ary_push(names, rb_str_new2(*pch));
}
- ary_push(ary, INT2FIX(h->h_length));
+ rb_ary_push(ary, NUM2INT(h->h_addrtype));
#ifdef h_addr
for (pch = h->h_addr_list; *pch; pch++) {
- ary_push(ary, str_new(*pch, h->h_length));
+ rb_ary_push(ary, rb_str_new(*pch, h->h_length));
}
#else
- ary_push(ary, str_new(h->h_addr, h->h_length));
+ rb_ary_push(ary, rb_str_new(h->h_addr, h->h_length));
#endif
return ary;
@@ -1338,7 +1381,7 @@ sock_s_gethostbyname(obj, host)
struct sockaddr_in addr;
struct hostent *h;
- if (obj_is_kind_of(host, cInteger)) {
+ if (rb_obj_is_kind_of(host, rb_cInteger)) {
int i = NUM2INT(host);
addr.sin_addr.s_addr = htonl(i);
}
@@ -1359,12 +1402,12 @@ sock_s_gethostbyaddr(argc, argv)
{
VALUE vaddr, vtype;
int type;
- char *addr;
int alen;
+ char *addr;
struct hostent *h;
rb_scan_args(argc, argv, "11", &vaddr, &vtype);
- addr = str2cstr(vaddr, &alen);
+ addr = rb_str2cstr(vaddr, &alen);
if (!NIL_P(vtype)) {
type = NUM2INT(vtype);
}
@@ -1401,7 +1444,7 @@ sock_s_getservbyaname(argc, argv)
port = strtoul(s, &end, 0);
if (*end != '\0') {
- Raise(eSocket, "no such servce %s/%s", s, proto);
+ rb_raise(rb_eSocket, "no such servce %s/%s", s, proto);
}
}
@@ -1411,237 +1454,238 @@ sock_s_getservbyaname(argc, argv)
static VALUE mConst;
static void
-sock_define_const(name, value)
+sock_rb_define_const(name, value)
char *name;
int value;
{
- rb_define_const(cSocket, name, INT2FIX(value));
+ rb_define_const(rb_cSocket, name, INT2FIX(value));
rb_define_const(mConst, name, INT2FIX(value));
}
Init_socket()
{
- eSocket = rb_define_class("SocketError", eStandardError);
-
- cBasicSocket = rb_define_class("BasicSocket", cIO);
- rb_undef_method(CLASS_OF(cBasicSocket), "new");
- rb_undef_method(CLASS_OF(cBasicSocket), "open");
- rb_define_method(cBasicSocket, "shutdown", bsock_shutdown, -1);
- rb_define_method(cBasicSocket, "setsockopt", bsock_setsockopt, 3);
- rb_define_method(cBasicSocket, "getsockopt", bsock_getsockopt, 2);
- rb_define_method(cBasicSocket, "getsockname", bsock_getsockname, 0);
- rb_define_method(cBasicSocket, "getpeername", bsock_getpeername, 0);
- rb_define_method(cBasicSocket, "send", bsock_send, -1);
- rb_define_method(cBasicSocket, "recv", bsock_recv, -1);
-
- cIPsocket = rb_define_class("IPsocket", cBasicSocket);
- rb_define_method(cIPsocket, "addr", ip_addr, 0);
- rb_define_method(cIPsocket, "peeraddr", ip_peeraddr, 0);
- rb_define_singleton_method(cIPsocket, "getaddress", ip_s_getaddress, 1);
-
- cTCPsocket = rb_define_class("TCPsocket", cIPsocket);
- rb_define_singleton_method(cTCPsocket, "open", tcp_s_open, 2);
- rb_define_singleton_method(cTCPsocket, "new", tcp_s_open, 2);
- rb_define_method(cTCPsocket, "recvfrom", tcp_recvfrom, -1);
+ rb_eSocket = rb_define_class("SocketError", rb_eStandardError);
+
+ rb_cBasicSocket = rb_define_class("BasicSocket", rb_cIO);
+ rb_undef_method(CLASS_OF(rb_cBasicSocket), "new");
+ rb_undef_method(CLASS_OF(rb_cBasicSocket), "open");
+ rb_define_method(rb_cBasicSocket, "shutdown", bsock_shutdown, -1);
+ rb_define_method(rb_cBasicSocket, "setsockopt", bsock_setsockopt, 3);
+ rb_define_method(rb_cBasicSocket, "getsockopt", bsock_getsockopt, 2);
+ rb_define_method(rb_cBasicSocket, "getsockname", bsock_getsockname, 0);
+ rb_define_method(rb_cBasicSocket, "getpeername", bsock_getpeername, 0);
+ rb_define_method(rb_cBasicSocket, "send", bsock_send, -1);
+ rb_define_method(rb_cBasicSocket, "recv", bsock_recv, -1);
+
+ rb_cIPsocket = rb_define_class("IPsocket", rb_cBasicSocket);
+ rb_define_method(rb_cIPsocket, "addr", ip_addr, 0);
+ rb_define_method(rb_cIPsocket, "peeraddr", ip_peeraddr, 0);
+ rb_define_singleton_method(rb_cIPsocket, "getaddress", ip_s_getaddress, 1);
+
+ rb_cTCPsocket = rb_define_class("TCPsocket", rb_cIPsocket);
+ rb_define_singleton_method(rb_cTCPsocket, "open", tcp_s_open, 2);
+ rb_define_singleton_method(rb_cTCPsocket, "new", tcp_s_open, 2);
+ rb_define_singleton_method(rb_cTCPsocket, "gethostbyname", tcp_s_gethostbyname, 1);
+ rb_define_method(rb_cTCPsocket, "recvfrom", tcp_recvfrom, -1);
#ifdef SOCKS
- cSOCKSsocket = rb_define_class("SOCKSsocket", cTCPsocket);
- rb_define_singleton_method(cSOCKSsocket, "open", socks_s_open, 2);
- rb_define_singleton_method(cSOCKSsocket, "new", socks_s_open, 2);
+ rb_cSOCKSsocket = rb_define_class("SOCKSsocket", rb_cTCPsocket);
+ rb_define_singleton_method(rb_cSOCKSsocket, "open", socks_s_open, 2);
+ rb_define_singleton_method(rb_cSOCKSsocket, "new", socks_s_open, 2);
#endif
- cTCPserver = rb_define_class("TCPserver", cTCPsocket);
- rb_define_singleton_method(cTCPserver, "open", tcp_svr_s_open, -1);
- rb_define_singleton_method(cTCPserver, "new", tcp_svr_s_open, -1);
- rb_define_method(cTCPserver, "accept", tcp_accept, 0);
+ rb_cTCPserver = rb_define_class("TCPserver", rb_cTCPsocket);
+ rb_define_singleton_method(rb_cTCPserver, "open", tcp_svr_s_open, -1);
+ rb_define_singleton_method(rb_cTCPserver, "new", tcp_svr_s_open, -1);
+ rb_define_method(rb_cTCPserver, "accept", tcp_accept, 0);
- cUDPsocket = rb_define_class("UDPsocket", cIPsocket);
- rb_define_singleton_method(cUDPsocket, "open", udp_s_open, 0);
- rb_define_singleton_method(cUDPsocket, "new", udp_s_open, 0);
- rb_define_method(cUDPsocket, "connect", udp_connect, 2);
- rb_define_method(cUDPsocket, "bind", udp_bind, 2);
- rb_define_method(cUDPsocket, "send", udp_send, -1);
- rb_define_method(cUDPsocket, "recvfrom", udp_recvfrom, -1);
+ rb_cUDPsocket = rb_define_class("UDPsocket", rb_cIPsocket);
+ rb_define_singleton_method(rb_cUDPsocket, "open", udp_s_open, 0);
+ rb_define_singleton_method(rb_cUDPsocket, "new", udp_s_open, 0);
+ rb_define_method(rb_cUDPsocket, "connect", udp_connect, 2);
+ rb_define_method(rb_cUDPsocket, "bind", udp_bind, 2);
+ rb_define_method(rb_cUDPsocket, "send", udp_send, -1);
+ rb_define_method(rb_cUDPsocket, "recvfrom", udp_recvfrom, -1);
#ifdef HAVE_SYS_UN_H
- cUNIXsocket = rb_define_class("UNIXsocket", cBasicSocket);
- rb_define_singleton_method(cUNIXsocket, "open", unix_s_sock_open, 1);
- rb_define_singleton_method(cUNIXsocket, "new", unix_s_sock_open, 1);
- rb_define_method(cUNIXsocket, "path", unix_path, 0);
- rb_define_method(cUNIXsocket, "addr", unix_addr, 0);
- rb_define_method(cUNIXsocket, "peeraddr", unix_peeraddr, 0);
- rb_define_method(cUNIXsocket, "recvfrom", unix_recvfrom, -1);
-
- cUNIXserver = rb_define_class("UNIXserver", cUNIXsocket);
- rb_define_singleton_method(cUNIXserver, "open", unix_svr_s_open, 1);
- rb_define_singleton_method(cUNIXserver, "new", unix_svr_s_open, 1);
- rb_define_method(cUNIXserver, "accept", unix_accept, 0);
-#endif
-
- cSocket = rb_define_class("Socket", cBasicSocket);
- rb_define_singleton_method(cSocket, "open", sock_s_open, 3);
- rb_define_singleton_method(cSocket, "new", sock_s_open, 3);
- rb_define_singleton_method(cSocket, "for_fd", sock_s_for_fd, 1);
-
- rb_define_method(cSocket, "connect", sock_connect, 1);
- rb_define_method(cSocket, "bind", sock_bind, 1);
- rb_define_method(cSocket, "listen", sock_listen, 1);
- rb_define_method(cSocket, "accept", sock_accept, 0);
-
- rb_define_method(cSocket, "recvfrom", sock_recvfrom, -1);
-
- rb_define_singleton_method(cSocket, "socketpair", sock_s_socketpair, 3);
- rb_define_singleton_method(cSocket, "pair", sock_s_socketpair, 3);
- rb_define_singleton_method(cSocket, "gethostname", sock_gethostname, 0);
- rb_define_singleton_method(cSocket, "gethostbyname", sock_s_gethostbyname, 1);
- rb_define_singleton_method(cSocket, "gethostbyaddr", sock_s_gethostbyaddr, -1);
- rb_define_singleton_method(cSocket, "getservbyname", sock_s_getservbyaname, -1);
+ rb_cUNIXsocket = rb_define_class("UNIXsocket", rb_cBasicSocket);
+ rb_define_singleton_method(rb_cUNIXsocket, "open", unix_s_sock_open, 1);
+ rb_define_singleton_method(rb_cUNIXsocket, "new", unix_s_sock_open, 1);
+ rb_define_method(rb_cUNIXsocket, "path", unix_path, 0);
+ rb_define_method(rb_cUNIXsocket, "addr", unix_addr, 0);
+ rb_define_method(rb_cUNIXsocket, "peeraddr", unix_peeraddr, 0);
+ rb_define_method(rb_cUNIXsocket, "recvfrom", unix_recvfrom, -1);
+
+ rb_cUNIXserver = rb_define_class("UNIXserver", rb_cUNIXsocket);
+ rb_define_singleton_method(rb_cUNIXserver, "open", unix_svr_s_open, 1);
+ rb_define_singleton_method(rb_cUNIXserver, "new", unix_svr_s_open, 1);
+ rb_define_method(rb_cUNIXserver, "accept", unix_accept, 0);
+#endif
+
+ rb_cSocket = rb_define_class("Socket", rb_cBasicSocket);
+ rb_define_singleton_method(rb_cSocket, "open", sock_s_open, 3);
+ rb_define_singleton_method(rb_cSocket, "new", sock_s_open, 3);
+ rb_define_singleton_method(rb_cSocket, "for_fd", sock_s_for_fd, 1);
+
+ rb_define_method(rb_cSocket, "connect", sock_connect, 1);
+ rb_define_method(rb_cSocket, "bind", sock_bind, 1);
+ rb_define_method(rb_cSocket, "listen", sock_listen, 1);
+ rb_define_method(rb_cSocket, "accept", sock_accept, 0);
+
+ rb_define_method(rb_cSocket, "recvfrom", sock_recvfrom, -1);
+
+ rb_define_singleton_method(rb_cSocket, "socketpair", sock_s_socketpair, 3);
+ rb_define_singleton_method(rb_cSocket, "pair", sock_s_socketpair, 3);
+ rb_define_singleton_method(rb_cSocket, "gethostname", sock_gethostname, 0);
+ rb_define_singleton_method(rb_cSocket, "gethostbyname", sock_s_gethostbyname, 1);
+ rb_define_singleton_method(rb_cSocket, "gethostbyaddr", sock_s_gethostbyaddr, -1);
+ rb_define_singleton_method(rb_cSocket, "getservbyname", sock_s_getservbyaname, -1);
/* constants */
- mConst = rb_define_module_under(cSocket, "Constants");
- sock_define_const("SOCK_STREAM", SOCK_STREAM);
- sock_define_const("SOCK_DGRAM", SOCK_DGRAM);
+ mConst = rb_define_module_under(rb_cSocket, "Constants");
+ sock_rb_define_const("SOCK_STREAM", SOCK_STREAM);
+ sock_rb_define_const("SOCK_DGRAM", SOCK_DGRAM);
#ifdef SOCK_RAW
- sock_define_const("SOCK_RAW", SOCK_RAW);
+ sock_rb_define_const("SOCK_RAW", SOCK_RAW);
#endif
#ifdef SOCK_RDM
- sock_define_const("SOCK_RDM", SOCK_RDM);
+ sock_rb_define_const("SOCK_RDM", SOCK_RDM);
#endif
#ifdef SOCK_SEQPACKET
- sock_define_const("SOCK_SEQPACKET", SOCK_SEQPACKET);
+ sock_rb_define_const("SOCK_SEQPACKET", SOCK_SEQPACKET);
#endif
#ifdef SOCK_PACKET
- sock_define_const("SOCK_PACKET", SOCK_PACKET);
+ sock_rb_define_const("SOCK_PACKET", SOCK_PACKET);
#endif
- sock_define_const("AF_INET", AF_INET);
+ sock_rb_define_const("AF_INET", AF_INET);
#ifdef PF_INET
- sock_define_const("PF_INET", PF_INET);
+ sock_rb_define_const("PF_INET", PF_INET);
#endif
#ifdef AF_UNIX
- sock_define_const("AF_UNIX", AF_UNIX);
- sock_define_const("PF_UNIX", PF_UNIX);
+ sock_rb_define_const("AF_UNIX", AF_UNIX);
+ sock_rb_define_const("PF_UNIX", PF_UNIX);
#endif
#ifdef AF_AX25
- sock_define_const("AF_AX25", AF_AX25);
- sock_define_const("PF_AX25", PF_AX25);
+ sock_rb_define_const("AF_AX25", AF_AX25);
+ sock_rb_define_const("PF_AX25", PF_AX25);
#endif
#ifdef AF_IPX
- sock_define_const("AF_IPX", AF_IPX);
- sock_define_const("PF_IPX", PF_IPX);
+ sock_rb_define_const("AF_IPX", AF_IPX);
+ sock_rb_define_const("PF_IPX", PF_IPX);
#endif
#ifdef AF_APPLETALK
- sock_define_const("AF_APPLETALK", AF_APPLETALK);
- sock_define_const("PF_APPLETALK", PF_APPLETALK);
+ sock_rb_define_const("AF_APPLETALK", AF_APPLETALK);
+ sock_rb_define_const("PF_APPLETALK", PF_APPLETALK);
#endif
- sock_define_const("MSG_OOB", MSG_OOB);
+ sock_rb_define_const("MSG_OOB", MSG_OOB);
#ifdef MSG_PEEK
- sock_define_const("MSG_PEEK", MSG_PEEK);
+ sock_rb_define_const("MSG_PEEK", MSG_PEEK);
#endif
#ifdef MSG_DONTROUTE
- sock_define_const("MSG_DONTROUTE", MSG_DONTROUTE);
+ sock_rb_define_const("MSG_DONTROUTE", MSG_DONTROUTE);
#endif
- sock_define_const("SOL_SOCKET", SOL_SOCKET);
+ sock_rb_define_const("SOL_SOCKET", SOL_SOCKET);
#ifdef SOL_IP
- sock_define_const("SOL_IP", SOL_IP);
+ sock_rb_define_const("SOL_IP", SOL_IP);
#endif
#ifdef SOL_IPX
- sock_define_const("SOL_IPX", SOL_IPX);
+ sock_rb_define_const("SOL_IPX", SOL_IPX);
#endif
#ifdef SOL_AX25
- sock_define_const("SOL_AX25", SOL_AX25);
+ sock_rb_define_const("SOL_AX25", SOL_AX25);
#endif
#ifdef SOL_ATALK
- sock_define_const("SOL_ATALK", SOL_ATALK);
+ sock_rb_define_const("SOL_ATALK", SOL_ATALK);
#endif
#ifdef SOL_TCP
- sock_define_const("SOL_TCP", SOL_TCP);
+ sock_rb_define_const("SOL_TCP", SOL_TCP);
#endif
#ifdef SOL_UDP
- sock_define_const("SOL_UDP", SOL_UDP);
+ sock_rb_define_const("SOL_UDP", SOL_UDP);
#endif
#ifdef SO_DEBUG
- sock_define_const("SO_DEBUG", SO_DEBUG);
+ sock_rb_define_const("SO_DEBUG", SO_DEBUG);
#endif
- sock_define_const("SO_REUSEADDR", SO_REUSEADDR);
+ sock_rb_define_const("SO_REUSEADDR", SO_REUSEADDR);
#ifdef SO_TYPE
- sock_define_const("SO_TYPE", SO_TYPE);
+ sock_rb_define_const("SO_TYPE", SO_TYPE);
#endif
#ifdef SO_ERROR
- sock_define_const("SO_ERROR", SO_ERROR);
+ sock_rb_define_const("SO_ERROR", SO_ERROR);
#endif
#ifdef SO_DONTROUTE
- sock_define_const("SO_DONTROUTE", SO_DONTROUTE);
+ sock_rb_define_const("SO_DONTROUTE", SO_DONTROUTE);
#endif
#ifdef SO_BROADCAST
- sock_define_const("SO_BROADCAST", SO_BROADCAST);
+ sock_rb_define_const("SO_BROADCAST", SO_BROADCAST);
#endif
#ifdef SO_SNDBUF
- sock_define_const("SO_SNDBUF", SO_SNDBUF);
+ sock_rb_define_const("SO_SNDBUF", SO_SNDBUF);
#endif
#ifdef SO_RCVBUF
- sock_define_const("SO_RCVBUF", SO_RCVBUF);
+ sock_rb_define_const("SO_RCVBUF", SO_RCVBUF);
#endif
#ifdef SO_KEEPALIVE
- sock_define_const("SO_KEEPALIVE", SO_KEEPALIVE);
+ sock_rb_define_const("SO_KEEPALIVE", SO_KEEPALIVE);
#endif
#ifdef SO_OOBINLINE
- sock_define_const("SO_OOBINLINE", SO_OOBINLINE);
+ sock_rb_define_const("SO_OOBINLINE", SO_OOBINLINE);
#endif
#ifdef SO_NO_CHECK
- sock_define_const("SO_NO_CHECK", SO_NO_CHECK);
+ sock_rb_define_const("SO_NO_CHECK", SO_NO_CHECK);
#endif
#ifdef SO_PRIORITY
- sock_define_const("SO_PRIORITY", SO_PRIORITY);
+ sock_rb_define_const("SO_PRIORITY", SO_PRIORITY);
#endif
#ifdef SO_LINGER
- sock_define_const("SO_LINGER", SO_LINGER);
+ sock_rb_define_const("SO_LINGER", SO_LINGER);
#endif
#ifdef SOPRI_INTERACTIVE
- sock_define_const("SOPRI_INTERACTIVE", SOPRI_INTERACTIVE);
+ sock_rb_define_const("SOPRI_INTERACTIVE", SOPRI_INTERACTIVE);
#endif
#ifdef SOPRI_NORMAL
- sock_define_const("SOPRI_NORMAL", SOPRI_NORMAL);
+ sock_rb_define_const("SOPRI_NORMAL", SOPRI_NORMAL);
#endif
#ifdef SOPRI_BACKGROUND
- sock_define_const("SOPRI_BACKGROUND", SOPRI_BACKGROUND);
+ sock_rb_define_const("SOPRI_BACKGROUND", SOPRI_BACKGROUND);
#endif
#ifdef IP_MULTICAST_IF
- sock_define_const("IP_MULTICAST_IF", IP_MULTICAST_IF);
+ sock_rb_define_const("IP_MULTICAST_IF", IP_MULTICAST_IF);
#endif
#ifdef IP_MULTICAST_TTL
- sock_define_const("IP_MULTICAST_TTL", IP_MULTICAST_TTL);
+ sock_rb_define_const("IP_MULTICAST_TTL", IP_MULTICAST_TTL);
#endif
#ifdef IP_MULTICAST_LOOP
- sock_define_const("IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
+ sock_rb_define_const("IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
#endif
#ifdef IP_ADD_MEMBERSHIP
- sock_define_const("IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
+ sock_rb_define_const("IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
#endif
#ifdef IP_DEFAULT_MULTICAST_TTL
- sock_define_const("IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL);
+ sock_rb_define_const("IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL);
#endif
#ifdef IP_DEFAULT_MULTICAST_LOOP
- sock_define_const("IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP);
+ sock_rb_define_const("IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP);
#endif
#ifdef IP_MAX_MEMBERSHIPS
- sock_define_const("IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS);
+ sock_rb_define_const("IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS);
#endif
#ifdef IPX_TYPE
- sock_define_const("IPX_TYPE", IPX_TYPE);
+ sock_rb_define_const("IPX_TYPE", IPX_TYPE);
#endif
#ifdef TCP_NODELAY
- sock_define_const("TCP_NODELAY", TCP_NODELAY);
+ sock_rb_define_const("TCP_NODELAY", TCP_NODELAY);
#endif
#ifdef TCP_MAXSEG
- sock_define_const("TCP_MAXSEG", TCP_MAXSEG);
+ sock_rb_define_const("TCP_MAXSEG", TCP_MAXSEG);
#endif
}
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index 5948c8f..b3ff66e 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -16,10 +16,10 @@
# include <Quickdraw.h>
#endif
-/* for debug */
+/* for rb_debug */
-#define DUMP1(ARG1) if (debug) { fprintf(stderr, "tcltklib: %s\n", ARG1);}
-#define DUMP2(ARG1, ARG2) if (debug) { fprintf(stderr, "tcltklib: ");\
+#define DUMP1(ARG1) if (rb_debug) { fprintf(stderr, "tcltklib: %s\n", ARG1);}
+#define DUMP2(ARG1, ARG2) if (rb_debug) { fprintf(stderr, "tcltklib: ");\
fprintf(stderr, ARG1, ARG2); fprintf(stderr, "\n"); }
/*
#define DUMP1(ARG1)
@@ -56,7 +56,7 @@ void _timer_for_tcl (ClientData clientData)
timer->flag = 0;
CHECK_INTS;
#ifdef THREAD
- if (!thread_critical) thread_schedule();
+ if (!rb_thread_critical) rb_thread_schedule();
#endif
timer->token = Tk_CreateTimerHandler(200, _timer_for_tcl,
@@ -121,7 +121,7 @@ ip_ruby(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
/* ruby command has 1 arg. */
if (argc != 2) {
- ArgError("wrong # of arguments (%d for 1)", argc);
+ rb_raise(rb_eArgError, "wrong # of arguments (%d for 1)", argc);
}
/* get C string from Tcl object */
@@ -133,10 +133,10 @@ ip_ruby(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
/* evaluate the argument string by ruby */
DUMP2("rb_eval_string(%s)", arg);
- old_trapflg = trap_immediate;
- trap_immediate = 0;
+ old_trapflg = rb_trap_immediate;
+ rb_trap_immediate = 0;
res = rb_rescue(rb_eval_string, (VALUE)arg, ip_eval_rescue, (VALUE)&failed);
- trap_immediate = old_trapflg;
+ rb_trap_immediate = old_trapflg;
Tcl_ResetResult(interp);
if (failed) {
@@ -192,11 +192,11 @@ ip_new(VALUE self)
/* from Tcl_AppInit() */
DUMP1("Tcl_Init");
if (Tcl_Init(ptr->ip) == TCL_ERROR) {
- Fail("Tcl_Init");
+ rb_raise(rb_eRuntimeError, "Tcl_Init");
}
DUMP1("Tk_Init");
if (Tk_Init(ptr->ip) == TCL_ERROR) {
- Fail("Tk_Init");
+ rb_raise(rb_eRuntimeError, "Tk_Init");
}
DUMP1("Tcl_StaticPackage(\"Tk\")");
Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init,
@@ -234,12 +234,12 @@ ip_eval(VALUE self, VALUE str)
DUMP2("Tcl_Eval(%s)", buf);
ptr->return_value = Tcl_Eval(ptr->ip, buf);
if (ptr->return_value == TCL_ERROR) {
- Fail(ptr->ip->result);
+ rb_raise(rb_eRuntimeError, ptr->ip->result);
}
DUMP2("(TCL_Eval result) %d", ptr->return_value);
/* pass back the result (as string) */
- return(str_new2(ptr->ip->result));
+ return(rb_str_new2(ptr->ip->result));
}
@@ -271,7 +271,7 @@ ip_toUTF8(VALUE self, VALUE str, VALUE encodename)
Tcl_FreeEncoding(encoding);
Tcl_DStringFree(&dstr);
- return str_new2(buff2);
+ return rb_str_new2(buff2);
#endif
}
@@ -303,7 +303,7 @@ ip_fromUTF8(VALUE self, VALUE str, VALUE encodename)
Tcl_FreeEncoding(encoding);
Tcl_DStringFree(&dstr);
- return str_new2(buff2);
+ return rb_str_new2(buff2);
#endif
}
@@ -330,7 +330,7 @@ ip_invoke(int argc, VALUE *argv, VALUE obj)
/* map from the command name to a C procedure */
if (!Tcl_GetCommandInfo(ptr->ip, cmd, &info)) {
- NameError("invalid command name `%s'", cmd);
+ rb_raise(rb_eNameError, "invalid command name `%s'", cmd);
}
#if TCL_MAJOR_VERSION >= 8
object = info.isNativeObjectProc;
@@ -379,11 +379,11 @@ ip_invoke(int argc, VALUE *argv, VALUE obj)
}
if (ptr->return_value == TCL_ERROR) {
- Fail(ptr->ip->result);
+ rb_raise(rb_eRuntimeError, ptr->ip->result);
}
/* pass back the result (as string) */
- return(str_new2(ptr->ip->result));
+ return(rb_str_new2(ptr->ip->result));
}
/* get return code from Tcl_Eval() */
@@ -413,10 +413,10 @@ void Init_tcltklib()
extern VALUE rb_argv0; /* the argv[0] */
VALUE lib = rb_define_module("TclTkLib");
- VALUE ip = rb_define_class("TclTkIp", cObject);
+ VALUE ip = rb_define_class("TclTkIp", rb_cObject);
- eTkCallbackBreak = rb_define_class("TkCallbackBreak", eStandardError);
- eTkCallbackContinue = rb_define_class("TkCallbackContinue",eStandardError);
+ eTkCallbackBreak = rb_define_class("TkCallbackBreak", rb_eStandardError);
+ eTkCallbackContinue = rb_define_class("TkCallbackContinue",rb_eStandardError);
rb_define_module_function(lib, "mainloop", lib_mainloop, 0);
diff --git a/ext/tkutil/tkutil.c b/ext/tkutil/tkutil.c
index 58a382a..46f3b0f 100644
--- a/ext/tkutil/tkutil.c
+++ b/ext/tkutil/tkutil.c
@@ -22,24 +22,8 @@ tk_eval_cmd(argc, argv)
}
static VALUE
-tk_s_new(argc, argv, class)
- int argc;
- VALUE *argv;
- VALUE class;
-{
- VALUE obj = obj_alloc(class);
-
- rb_funcall2(obj, rb_intern("initialize"), argc, argv);
- if (iterator_p()) rb_yield_0(obj, obj);
- return obj;
-}
-
Init_tkutil()
{
VALUE mTK = rb_define_module("TkUtil");
- VALUE cTK = rb_define_class("TkKernel", cObject);
-
rb_define_singleton_method(mTK, "eval_cmd", tk_eval_cmd, -1);
-
- rb_define_singleton_method(cTK, "new", tk_s_new, -1);
}
diff --git a/file.c b/file.c
index 2d616a6..72dd022 100644
--- a/file.c
+++ b/file.c
@@ -56,29 +56,29 @@ char *strrchr _((char*,char));
extern int utimes();
#endif
-VALUE cFile;
-VALUE mFileTest;
+VALUE rb_cFile;
+VALUE rb_mFileTest;
static VALUE sStat;
VALUE
-file_open(fname, mode)
+rb_file_open(fname, mode)
char *fname, *mode;
{
OpenFile *fptr;
NEWOBJ(port, struct RFile);
- OBJSETUP(port, cFile, T_FILE);
+ OBJSETUP(port, rb_cFile, T_FILE);
MakeOpenFile(port, fptr);
- fptr->mode = io_mode_flags(mode);
+ fptr->mode = rb_io_mode_flags(mode);
fptr->f = rb_fopen(fname, mode);
fptr->path = strdup(fname);
- obj_call_init((VALUE)port);
+ rb_obj_call_init((VALUE)port);
return (VALUE)port;
}
static VALUE
-file_s_open(argc, argv, klass)
+rb_file_s_open(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -94,19 +94,19 @@ file_s_open(argc, argv, klass)
else {
mode = "r";
}
- file = file_open(RSTRING(fname)->ptr, mode);
+ file = rb_file_open(RSTRING(fname)->ptr, mode);
RBASIC(file)->klass = klass;
- obj_call_init(file);
- if (iterator_p()) {
- return rb_ensure(rb_yield, file, io_close, file);
+ rb_obj_call_init(file);
+ if (rb_iterator_p()) {
+ return rb_ensure(rb_yield, file, rb_io_close, file);
}
return file;
}
static VALUE
-file_reopen(argc, argv, file)
+rb_file_reopen(argc, argv, file)
int argc;
VALUE *argv;
VALUE file;
@@ -117,7 +117,7 @@ file_reopen(argc, argv, file)
if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
if (TYPE(fname) == T_FILE) { /* fname must be IO */
- return io_reopen(file, fname);
+ return rb_io_reopen(file, fname);
}
}
@@ -132,7 +132,7 @@ file_reopen(argc, argv, file)
GetOpenFile(file, fptr);
if (fptr->path) free(fptr->path);
fptr->path = strdup(RSTRING(fname)->ptr);
- fptr->mode = io_mode_flags(mode);
+ fptr->mode = rb_io_mode_flags(mode);
if (!fptr->f) {
fptr->f = rb_fopen(RSTRING(fname)->ptr, mode);
if (fptr->f2) {
@@ -178,14 +178,14 @@ apply2files(func, vargs, arg)
}
static VALUE
-file_path(obj)
+rb_file_path(obj)
VALUE obj;
{
OpenFile *fptr;
GetOpenFile(obj, fptr);
if (fptr->path == NULL) return Qnil;
- return str_new2(fptr->path);
+ return rb_str_new2(fptr->path);
}
#ifndef NT
@@ -200,33 +200,33 @@ static VALUE
stat_new(st)
struct stat *st;
{
- if (!st) Bug("stat_new() called with bad value");
- return struct_new(sStat,
- INT2FIX((int)st->st_dev),
- INT2FIX((int)st->st_ino),
- INT2FIX((int)st->st_mode),
- INT2FIX((int)st->st_nlink),
- INT2FIX((int)st->st_uid),
- INT2FIX((int)st->st_gid),
+ if (!st) rb_bug("stat_new() called with bad value");
+ return rb_struct_new(sStat,
+ INT2FIX((int)st->st_dev),
+ INT2FIX((int)st->st_ino),
+ INT2FIX((int)st->st_mode),
+ INT2FIX((int)st->st_nlink),
+ INT2FIX((int)st->st_uid),
+ INT2FIX((int)st->st_gid),
#ifdef HAVE_ST_RDEV
- INT2FIX((int)st->st_rdev),
+ INT2FIX((int)st->st_rdev),
#else
- INT2FIX(0),
+ INT2FIX(0),
#endif
- INT2FIX((int)st->st_size),
+ INT2FIX((int)st->st_size),
#ifdef HAVE_ST_BLKSIZE
- INT2FIX((int)st->st_blksize),
+ INT2FIX((int)st->st_blksize),
#else
- INT2FIX(0),
+ INT2FIX(0),
#endif
#ifdef HAVE_ST_BLOCKS
- INT2FIX((int)st->st_blocks),
+ INT2FIX((int)st->st_blocks),
#else
- INT2FIX(0),
+ INT2FIX(0),
#endif
- time_new(st->st_atime, 0),
- time_new(st->st_mtime, 0),
- time_new(st->st_ctime, 0));
+ rb_time_new(st->st_atime, 0),
+ rb_time_new(st->st_mtime, 0),
+ rb_time_new(st->st_ctime, 0));
}
static int
@@ -245,7 +245,7 @@ rb_stat(file, st)
}
static VALUE
-file_s_stat(obj, fname)
+rb_file_s_stat(obj, fname)
VALUE obj, fname;
{
struct stat st;
@@ -258,7 +258,7 @@ file_s_stat(obj, fname)
}
static VALUE
-io_stat(obj)
+rb_io_stat(obj)
VALUE obj;
{
OpenFile *fptr;
@@ -272,7 +272,7 @@ io_stat(obj)
}
static VALUE
-file_s_lstat(obj, fname)
+rb_file_s_lstat(obj, fname)
VALUE obj, fname;
{
#if !defined(MSDOS) && !defined(NT)
@@ -289,7 +289,7 @@ file_s_lstat(obj, fname)
}
static VALUE
-file_lstat(obj)
+rb_file_lstat(obj)
VALUE obj;
{
#if !defined(MSDOS) && !defined(NT)
@@ -312,7 +312,7 @@ group_member(gid)
{
#if !defined(NT) && !defined(USE_CWGUSI)
if (getgid() == gid || getegid() == gid)
- return TRUE;
+ return Qtrue;
# ifdef HAVE_GETGROUPS
# ifndef NGROUPS
@@ -325,11 +325,11 @@ group_member(gid)
anum = getgroups(NGROUPS, gary);
while (--anum >= 0)
if (gary[anum] == gid)
- return TRUE;
+ return Qtrue;
}
# endif
#endif
- return FALSE;
+ return Qfalse;
}
#ifndef S_IXUGO
@@ -385,9 +385,9 @@ test_d(obj, fname)
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (S_ISDIR(st.st_mode)) return TRUE;
- return FALSE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (S_ISDIR(st.st_mode)) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -401,11 +401,11 @@ test_p(obj, fname)
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (S_ISFIFO(st.st_mode)) return TRUE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (S_ISFIFO(st.st_mode)) return Qtrue;
#endif
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -430,11 +430,11 @@ test_l(obj, fname)
struct stat st;
Check_SafeStr(fname);
- if (lstat(RSTRING(fname)->ptr, &st) < 0) return FALSE;
- if (S_ISLNK(st.st_mode)) return TRUE;
+ if (lstat(RSTRING(fname)->ptr, &st) < 0) return Qfalse;
+ if (S_ISLNK(st.st_mode)) return Qtrue;
#endif
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -458,11 +458,11 @@ test_S(obj, fname)
#ifdef S_ISSOCK
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (S_ISSOCK(st.st_mode)) return TRUE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (S_ISSOCK(st.st_mode)) return Qtrue;
#endif
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -480,11 +480,11 @@ test_b(obj, fname)
#ifdef S_ISBLK
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (S_ISBLK(st.st_mode)) return TRUE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (S_ISBLK(st.st_mode)) return Qtrue;
#endif
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -497,10 +497,10 @@ test_c(obj, fname)
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (S_ISBLK(st.st_mode)) return TRUE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (S_ISBLK(st.st_mode)) return Qtrue;
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -509,8 +509,8 @@ test_e(obj, fname)
{
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- return TRUE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ return Qtrue;
}
static VALUE
@@ -518,8 +518,8 @@ test_r(obj, fname)
VALUE obj, fname;
{
Check_SafeStr(fname);
- if (eaccess(RSTRING(fname)->ptr, R_OK) < 0) return FALSE;
- return TRUE;
+ if (eaccess(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse;
+ return Qtrue;
}
static VALUE
@@ -527,8 +527,8 @@ test_R(obj, fname)
VALUE obj, fname;
{
Check_SafeStr(fname);
- if (access(RSTRING(fname)->ptr, R_OK) < 0) return FALSE;
- return TRUE;
+ if (access(RSTRING(fname)->ptr, R_OK) < 0) return Qfalse;
+ return Qtrue;
}
static VALUE
@@ -536,8 +536,8 @@ test_w(obj, fname)
VALUE obj, fname;
{
Check_SafeStr(fname);
- if (eaccess(RSTRING(fname)->ptr, W_OK) < 0) return FALSE;
- return TRUE;
+ if (eaccess(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse;
+ return Qtrue;
}
static VALUE
@@ -545,8 +545,8 @@ test_W(obj, fname)
VALUE obj, fname;
{
Check_SafeStr(fname);
- if (access(RSTRING(fname)->ptr, W_OK) < 0) return FALSE;
- return TRUE;
+ if (access(RSTRING(fname)->ptr, W_OK) < 0) return Qfalse;
+ return Qtrue;
}
static VALUE
@@ -554,8 +554,8 @@ test_x(obj, fname)
VALUE obj, fname;
{
Check_SafeStr(fname);
- if (eaccess(RSTRING(fname)->ptr, X_OK) < 0) return FALSE;
- return TRUE;
+ if (eaccess(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse;
+ return Qtrue;
}
static VALUE
@@ -563,8 +563,8 @@ test_X(obj, fname)
VALUE obj, fname;
{
Check_SafeStr(fname);
- if (access(RSTRING(fname)->ptr, X_OK) < 0) return FALSE;
- return TRUE;
+ if (access(RSTRING(fname)->ptr, X_OK) < 0) return Qfalse;
+ return Qtrue;
}
#ifndef S_ISREG
@@ -577,9 +577,9 @@ test_f(obj, fname)
{
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (S_ISREG(st.st_mode)) return TRUE;
- return FALSE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (S_ISREG(st.st_mode)) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -588,9 +588,9 @@ test_z(obj, fname)
{
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (st.st_size == 0) return TRUE;
- return FALSE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (st.st_size == 0) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -599,9 +599,9 @@ test_s(obj, fname)
{
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (st.st_size == 0) return FALSE;
- return int2inum(st.st_size);
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (st.st_size == 0) return Qfalse;
+ return rb_int2inum(st.st_size);
}
static VALUE
@@ -610,9 +610,9 @@ test_owned(obj, fname)
{
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (st.st_uid == geteuid()) return TRUE;
- return FALSE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (st.st_uid == geteuid()) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -621,9 +621,9 @@ test_rowned(obj, fname)
{
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (st.st_uid == getuid()) return TRUE;
- return FALSE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (st.st_uid == getuid()) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -633,10 +633,10 @@ test_grpowned(obj, fname)
#ifndef NT
struct stat st;
- if (rb_stat(fname, &st) < 0) return FALSE;
- if (st.st_gid == getegid()) return TRUE;
+ if (rb_stat(fname, &st) < 0) return Qfalse;
+ if (st.st_gid == getegid()) return Qtrue;
#endif
- return FALSE;
+ return Qfalse;
}
#if defined(S_ISUID) || defined(S_ISGID) || defined(S_ISVTX)
@@ -647,9 +647,9 @@ check3rdbyte(file, mode)
{
struct stat st;
- if (stat(file, &st) < 0) return FALSE;
- if (st.st_mode & mode) return TRUE;
- return FALSE;
+ if (stat(file, &st) < 0) return Qfalse;
+ if (st.st_mode & mode) return Qtrue;
+ return Qfalse;
}
#endif
@@ -661,7 +661,7 @@ test_suid(obj, fname)
Check_SafeStr(fname);
return check3rdbyte(RSTRING(fname)->ptr, S_ISUID);
#else
- return FALSE;
+ return Qfalse;
#endif
}
@@ -673,7 +673,7 @@ test_sgid(obj, fname)
Check_SafeStr(fname);
return check3rdbyte(RSTRING(fname)->ptr, S_ISGID);
#else
- return FALSE;
+ return Qfalse;
#endif
}
@@ -684,23 +684,23 @@ test_sticky(obj, fname)
#ifdef S_ISVTX
return check3rdbyte(STR2CSTR(fname), S_ISVTX);
#else
- return FALSE;
+ return Qfalse;
#endif
}
static VALUE
-file_s_size(obj, fname)
+rb_file_s_size(obj, fname)
VALUE obj, fname;
{
struct stat st;
if (rb_stat(fname, &st) < 0)
rb_sys_fail(RSTRING(fname)->ptr);
- return int2inum(st.st_size);
+ return rb_int2inum(st.st_size);
}
static VALUE
-file_s_ftype(obj, fname)
+rb_file_s_ftype(obj, fname)
VALUE obj, fname;
{
struct stat st;
@@ -747,22 +747,22 @@ file_s_ftype(obj, fname)
t = "unknown";
}
- return str_new2(t);
+ return rb_str_new2(t);
}
static VALUE
-file_s_atime(obj, fname)
+rb_file_s_atime(obj, fname)
VALUE obj, fname;
{
struct stat st;
if (rb_stat(fname, &st) < 0)
rb_sys_fail(RSTRING(fname)->ptr);
- return time_new(st.st_atime, 0);
+ return rb_time_new(st.st_atime, 0);
}
static VALUE
-file_atime(obj)
+rb_file_atime(obj)
VALUE obj;
{
OpenFile *fptr;
@@ -772,22 +772,22 @@ file_atime(obj)
if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
- return time_new(st.st_atime, 0);
+ return rb_time_new(st.st_atime, 0);
}
static VALUE
-file_s_mtime(obj, fname)
+rb_file_s_mtime(obj, fname)
VALUE obj, fname;
{
struct stat st;
if (rb_stat(fname, &st) < 0)
rb_sys_fail(RSTRING(fname)->ptr);
- return time_new(st.st_mtime, 0);
+ return rb_time_new(st.st_mtime, 0);
}
static VALUE
-file_mtime(obj)
+rb_file_mtime(obj)
VALUE obj;
{
OpenFile *fptr;
@@ -797,22 +797,22 @@ file_mtime(obj)
if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
- return time_new(st.st_mtime, 0);
+ return rb_time_new(st.st_mtime, 0);
}
static VALUE
-file_s_ctime(obj, fname)
+rb_file_s_ctime(obj, fname)
VALUE obj, fname;
{
struct stat st;
if (rb_stat(fname, &st) < 0)
rb_sys_fail(RSTRING(fname)->ptr);
- return time_new(st.st_ctime, 0);
+ return rb_time_new(st.st_ctime, 0);
}
static VALUE
-file_ctime(obj)
+rb_file_ctime(obj)
VALUE obj;
{
OpenFile *fptr;
@@ -822,7 +822,7 @@ file_ctime(obj)
if (fstat(fileno(fptr->f), &st) == -1) {
rb_sys_fail(fptr->path);
}
- return time_new(st.st_ctime, 0);
+ return rb_time_new(st.st_ctime, 0);
}
static void
@@ -835,7 +835,7 @@ chmod_internal(path, mode)
}
static VALUE
-file_s_chmod(argc, argv)
+rb_file_s_chmod(argc, argv)
int argc;
VALUE *argv;
{
@@ -851,7 +851,7 @@ file_s_chmod(argc, argv)
}
static VALUE
-file_chmod(obj, vmode)
+rb_file_chmod(obj, vmode)
VALUE obj, vmode;
{
OpenFile *fptr;
@@ -886,7 +886,7 @@ chown_internal(path, args)
}
static VALUE
-file_s_chown(argc, argv)
+rb_file_s_chown(argc, argv)
int argc;
VALUE *argv;
{
@@ -913,7 +913,7 @@ file_s_chown(argc, argv)
}
static VALUE
-file_chown(obj, owner, group)
+rb_file_chown(obj, owner, group)
VALUE obj, owner, group;
{
OpenFile *fptr;
@@ -931,7 +931,7 @@ file_chown(obj, owner, group)
return INT2FIX(0);
}
-struct timeval time_timeval();
+struct timeval rb_time_timeval();
#ifdef HAVE_UTIMES
@@ -945,7 +945,7 @@ utime_internal(path, tvp)
}
static VALUE
-file_s_utime(argc, argv)
+rb_file_s_utime(argc, argv)
int argc;
VALUE *argv;
{
@@ -955,8 +955,8 @@ file_s_utime(argc, argv)
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
- tvp[0] = time_timeval(atime);
- tvp[1] = time_timeval(mtime);
+ tvp[0] = rb_time_timeval(atime);
+ tvp[1] = rb_time_timeval(mtime);
n = apply2files(utime_internal, rest, tvp);
return INT2FIX(n);
@@ -992,7 +992,7 @@ utime_internal(path, utp)
}
static VALUE
-file_s_utime(argc, argv)
+rb_file_s_utime(argc, argv)
int argc;
VALUE *argv;
{
@@ -1003,9 +1003,9 @@ file_s_utime(argc, argv)
rb_scan_args(argc, argv, "2*", &atime, &mtime, &rest);
- tv = time_timeval(atime);
+ tv = rb_time_timeval(atime);
utbuf.actime = tv.tv_sec;
- tv = time_timeval(mtime);
+ tv = rb_time_timeval(mtime);
utbuf.modtime = tv.tv_sec;
n = apply2files(utime_internal, rest, &utbuf);
@@ -1015,7 +1015,7 @@ file_s_utime(argc, argv)
#endif
static VALUE
-file_s_link(obj, from, to)
+rb_file_s_link(obj, from, to)
VALUE obj, from, to;
{
#if defined(USE_CWGUSI)
@@ -1031,7 +1031,7 @@ file_s_link(obj, from, to)
}
static VALUE
-file_s_symlink(obj, from, to)
+rb_file_s_symlink(obj, from, to)
VALUE obj, from, to;
{
#if !defined(MSDOS) && !defined(NT)
@@ -1047,7 +1047,7 @@ file_s_symlink(obj, from, to)
}
static VALUE
-file_s_readlink(obj, path)
+rb_file_s_readlink(obj, path)
VALUE obj, path;
{
#if !defined(MSDOS) && !defined(NT)
@@ -1059,7 +1059,7 @@ file_s_readlink(obj, path)
if ((cc = readlink(RSTRING(path)->ptr, buf, MAXPATHLEN)) < 0)
rb_sys_fail(RSTRING(path)->ptr);
- return str_new(buf, cc);
+ return rb_str_new(buf, cc);
#else
rb_notimplement();
#endif
@@ -1074,7 +1074,7 @@ unlink_internal(path)
}
static VALUE
-file_s_unlink(obj, args)
+rb_file_s_unlink(obj, args)
VALUE obj, args;
{
int n;
@@ -1084,7 +1084,7 @@ file_s_unlink(obj, args)
}
static VALUE
-file_s_rename(obj, from, to)
+rb_file_s_rename(obj, from, to)
VALUE obj, from, to;
{
Check_SafeStr(from);
@@ -1097,7 +1097,7 @@ file_s_rename(obj, from, to)
}
static VALUE
-file_s_umask(argc, argv)
+rb_file_s_umask(argc, argv)
int argc;
VALUE *argv;
{
@@ -1114,14 +1114,14 @@ file_s_umask(argc, argv)
omask = umask(NUM2INT(argv[0]));
}
else {
- ArgError("wrong # of argument");
+ rb_raise(rb_eArgError, "wrong # of argument");
}
return INT2FIX(omask);
#endif /* USE_CWGUSI */
}
VALUE
-file_s_expand_path(argc, argv)
+rb_file_s_expand_path(argc, argv)
int argc;
VALUE *argv;
{
@@ -1142,7 +1142,7 @@ file_s_expand_path(argc, argv)
char *dir = getenv("HOME");
if (!dir) {
- Fail("couldn't find HOME environment -- expanding `%s'", s);
+ rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `%s'", s);
}
strcpy(buf, dir);
p = &buf[strlen(buf)];
@@ -1161,7 +1161,7 @@ file_s_expand_path(argc, argv)
pwPtr = getpwnam(buf);
if (!pwPtr) {
endpwent();
- Fail("user %s doesn't exist", buf);
+ rb_raise(rb_eArgError, "user %s doesn't exist", buf);
}
strcpy(buf, pwPtr->pw_dir);
p = &buf[strlen(buf)];
@@ -1171,7 +1171,7 @@ file_s_expand_path(argc, argv)
}
else if (s[0] != '/') {
if (argc == 2) {
- dname = file_s_expand_path(1, &dname);
+ dname = rb_file_s_expand_path(1, &dname);
strcpy(buf, RSTRING(dname)->ptr);
}
else {
@@ -1221,7 +1221,7 @@ file_s_expand_path(argc, argv)
if (p == buf || *p != '/') p++;
*p = '\0';
- return str_taint(str_new2(buf));
+ return rb_str_taint(rb_str_new2(buf));
}
static int
@@ -1248,7 +1248,7 @@ rmext(p, e)
}
static VALUE
-file_s_basename(argc, argv)
+rb_file_s_basename(argc, argv)
int argc;
VALUE *argv;
{
@@ -1264,20 +1264,20 @@ file_s_basename(argc, argv)
if (!p) {
if (!NIL_P(fext)) {
f = rmext(name, ext);
- if (f) return str_new(name, f);
+ if (f) return rb_str_new(name, f);
}
return fname;
}
p++; /* skip last `/' */
if (!NIL_P(fext)) {
f = rmext(p, ext);
- if (f) return str_new(p, f);
+ if (f) return rb_str_new(p, f);
}
- return str_taint(str_new2(p));
+ return rb_str_taint(rb_str_new2(p));
}
static VALUE
-file_s_dirname(obj, fname)
+rb_file_s_dirname(obj, fname)
VALUE obj, fname;
{
char *name, *p;
@@ -1285,31 +1285,31 @@ file_s_dirname(obj, fname)
name = STR2CSTR(fname);
p = strrchr(name, '/');
if (!p) {
- return str_new2(".");
+ return rb_str_new2(".");
}
if (p == name)
p++;
- return str_taint(str_new(name, p - name));
+ return rb_str_taint(rb_str_new(name, p - name));
}
static VALUE
-file_s_split(obj, path)
+rb_file_s_split(obj, path)
VALUE obj, path;
{
- return assoc_new(file_s_dirname(Qnil, path), file_s_basename(1,&path));
+ return rb_assoc_new(rb_file_s_dirname(Qnil, path), rb_file_s_basename(1,&path));
}
static VALUE separator;
static VALUE
-file_s_join(obj, args)
+rb_file_s_join(obj, args)
VALUE obj, args;
{
- return ary_join(args, separator);
+ return rb_ary_join(args, separator);
}
static VALUE
-file_s_truncate(obj, path, len)
+rb_file_s_truncate(obj, path, len)
VALUE obj, path, len;
{
Check_SafeStr(path);
@@ -1345,7 +1345,7 @@ file_s_truncate(obj, path, len)
}
static VALUE
-file_truncate(obj, len)
+rb_file_truncate(obj, len)
VALUE obj, len;
{
OpenFile *fptr;
@@ -1353,7 +1353,7 @@ file_truncate(obj, len)
rb_secure(2);
GetOpenFile(obj, fptr);
if (!(fptr->mode & FMODE_WRITABLE)) {
- Fail("not opened for writing");
+ rb_raise(rb_eIOError, "not opened for writing");
}
#ifdef HAVE_TRUNCATE
if (ftruncate(fileno(fptr->f), NUM2INT(len)) < 0)
@@ -1384,10 +1384,10 @@ file_truncate(obj, len)
#if defined(THREAD) && defined(EWOULDBLOCK)
static int
-thread_flock(fd, op)
+rb_thread_flock(fd, op)
int fd, op;
{
- if (thread_alone() || (op & LOCK_NB)) {
+ if (rb_thread_alone() || (op & LOCK_NB)) {
return flock(fd, op);
}
op |= LOCK_NB;
@@ -1395,7 +1395,7 @@ thread_flock(fd, op)
switch (errno) {
case EINTR: /* can be happen? */
case EWOULDBLOCK:
- thread_schedule(); /* busy wait */
+ rb_thread_schedule(); /* busy wait */
break;
default:
return -1;
@@ -1403,11 +1403,11 @@ thread_flock(fd, op)
}
return 0;
}
-#define flock thread_flock
+#define flock rb_thread_flock
#endif
static VALUE
-file_flock(obj, operation)
+rb_file_flock(obj, operation)
VALUE obj;
VALUE operation;
{
@@ -1422,7 +1422,7 @@ file_flock(obj, operation)
if (flock(fileno(fptr->f), NUM2INT(operation)) < 0) {
#ifdef EWOULDBLOCK
if (errno == EWOULDBLOCK) {
- return FALSE;
+ return Qfalse;
}
#endif
rb_sys_fail(fptr->path);
@@ -1440,7 +1440,7 @@ test_check(n, argc, argv)
int i;
n+=1;
- if (n < argc) ArgError("Wrong # of arguments(%d for %d)", argc, n);
+ if (n < argc) rb_raise(rb_eArgError, "Wrong # of arguments(%d for %d)", argc, n);
for (i=1; i<n; i++) {
switch (TYPE(argv[i])) {
case T_STRING:
@@ -1458,15 +1458,15 @@ test_check(n, argc, argv)
#define CHECK(n) test_check((n), argc, argv)
static VALUE
-f_test(argc, argv)
+rb_f_test(argc, argv)
int argc;
VALUE *argv;
{
int cmd;
- if (argc == 0) ArgError("Wrong # of arguments");
+ if (argc == 0) rb_raise(rb_eArgError, "Wrong # of arguments");
cmd = NUM2CHR(argv[0]);
- if (cmd == 0) return FALSE;
+ if (cmd == 0) return Qfalse;
if (strchr("bcdefgGkloOprRsSuwWxXz", cmd)) {
CHECK(1);
switch (cmd) {
@@ -1549,11 +1549,11 @@ f_test(argc, argv)
switch (cmd) {
case 'A':
- return time_new(st.st_atime, 0);
+ return rb_time_new(st.st_atime, 0);
case 'M':
- return time_new(st.st_mtime, 0);
+ return rb_time_new(st.st_mtime, 0);
case 'C':
- return time_new(st.st_ctime, 0);
+ return rb_time_new(st.st_ctime, 0);
}
}
@@ -1561,136 +1561,136 @@ f_test(argc, argv)
struct stat st1, st2;
CHECK(2);
- if (rb_stat(argv[1], &st1) < 0) return FALSE;
- if (rb_stat(argv[2], &st2) < 0) return FALSE;
+ if (rb_stat(argv[1], &st1) < 0) return Qfalse;
+ if (rb_stat(argv[2], &st2) < 0) return Qfalse;
switch (cmd) {
case '-':
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
- return TRUE;
+ return Qtrue;
break;
case '=':
- if (st1.st_mtime == st2.st_mtime) return TRUE;
+ if (st1.st_mtime == st2.st_mtime) return Qtrue;
break;
case '>':
- if (st1.st_mtime > st2.st_mtime) return TRUE;
+ if (st1.st_mtime > st2.st_mtime) return Qtrue;
break;
case '<':
- if (st1.st_mtime < st2.st_mtime) return TRUE;
+ if (st1.st_mtime < st2.st_mtime) return Qtrue;
break;
}
}
/* unknown command */
- ArgError("unknow command ?%c", cmd);
+ rb_raise(rb_eArgError, "unknow command ?%c", cmd);
return Qnil; /* not reached */
}
void
Init_File()
{
- VALUE mConst;
-
- mFileTest = rb_define_module("FileTest");
-
- rb_define_module_function(mFileTest, "directory?", test_d, 1);
- rb_define_module_function(mFileTest, "exist?", test_e, 1);
- rb_define_module_function(mFileTest, "exists?", test_e, 1); /* temporary */
- rb_define_module_function(mFileTest, "readable?", test_r, 1);
- rb_define_module_function(mFileTest, "readable_real?", test_R, 1);
- rb_define_module_function(mFileTest, "writable?", test_w, 1);
- rb_define_module_function(mFileTest, "writable_real?", test_W, 1);
- rb_define_module_function(mFileTest, "executable?", test_x, 1);
- rb_define_module_function(mFileTest, "executable_real?", test_X, 1);
- rb_define_module_function(mFileTest, "file?", test_f, 1);
- rb_define_module_function(mFileTest, "zero?", test_z, 1);
- rb_define_module_function(mFileTest, "size?", test_s, 1);
- rb_define_module_function(mFileTest, "size", test_s, 1);
- rb_define_module_function(mFileTest, "owned?", test_owned, 1);
- rb_define_module_function(mFileTest, "grpowned?", test_grpowned, 1);
-
- rb_define_module_function(mFileTest, "pipe?", test_p, 1);
- rb_define_module_function(mFileTest, "symlink?", test_l, 1);
- rb_define_module_function(mFileTest, "socket?", test_S, 1);
-
- rb_define_module_function(mFileTest, "blockdev?", test_b, 1);
- rb_define_module_function(mFileTest, "chardev?", test_c, 1);
-
- rb_define_module_function(mFileTest, "setuid?", test_suid, 1);
- rb_define_module_function(mFileTest, "setgid?", test_sgid, 1);
- rb_define_module_function(mFileTest, "sticky?", test_sticky, 1);
-
- cFile = rb_define_class("File", cIO);
- rb_extend_object(cFile, CLASS_OF(mFileTest));
-
- rb_define_singleton_method(cFile, "new", file_s_open, -1);
- rb_define_singleton_method(cFile, "open", file_s_open, -1);
-
- rb_define_singleton_method(cFile, "stat", file_s_stat, 1);
- rb_define_singleton_method(cFile, "lstat", file_s_lstat, 1);
- rb_define_singleton_method(cFile, "ftype", file_s_ftype, 1);
-
- rb_define_singleton_method(cFile, "atime", file_s_atime, 1);
- rb_define_singleton_method(cFile, "mtime", file_s_mtime, 1);
- rb_define_singleton_method(cFile, "ctime", file_s_ctime, 1);
- rb_define_singleton_method(cFile, "size", file_s_size, 1);
-
- rb_define_singleton_method(cFile, "utime", file_s_utime, -1);
- rb_define_singleton_method(cFile, "chmod", file_s_chmod, -1);
- rb_define_singleton_method(cFile, "chown", file_s_chown, -1);
-
- rb_define_singleton_method(cFile, "link", file_s_link, 2);
- rb_define_singleton_method(cFile, "symlink", file_s_symlink, 2);
- rb_define_singleton_method(cFile, "readlink", file_s_readlink, 1);
-
- rb_define_singleton_method(cFile, "unlink", file_s_unlink, -2);
- rb_define_singleton_method(cFile, "delete", file_s_unlink, -2);
- rb_define_singleton_method(cFile, "rename", file_s_rename, 2);
- rb_define_singleton_method(cFile, "umask", file_s_umask, -1);
- rb_define_singleton_method(cFile, "truncate", file_s_truncate, 2);
- rb_define_singleton_method(cFile, "expand_path", file_s_expand_path, -1);
- rb_define_singleton_method(cFile, "basename", file_s_basename, -1);
- rb_define_singleton_method(cFile, "dirname", file_s_dirname, 1);
-
- separator = str_new2("/");
- rb_define_const(cFile, "Separator", separator);
- rb_define_singleton_method(cFile, "split", file_s_split, 1);
- rb_define_singleton_method(cFile, "join", file_s_join, -2);
-
- rb_define_method(cFile, "reopen", file_reopen, -1);
-
- rb_define_method(cIO, "stat", io_stat, 0); /* this is IO's method */
- rb_define_method(cFile, "lstat", file_lstat, 0);
-
- rb_define_method(cFile, "atime", file_atime, 0);
- rb_define_method(cFile, "mtime", file_mtime, 0);
- rb_define_method(cFile, "ctime", file_ctime, 0);
-
- rb_define_method(cFile, "chmod", file_chmod, 1);
- rb_define_method(cFile, "chown", file_chown, 2);
- rb_define_method(cFile, "truncate", file_truncate, 1);
-
- rb_define_method(cFile, "flock", file_flock, 1);
-
- mConst = rb_define_module_under(cFile, "Constants");
- rb_define_const(cFile, "LOCK_SH", INT2FIX(LOCK_SH));
- rb_define_const(cFile, "LOCK_EX", INT2FIX(LOCK_EX));
- rb_define_const(cFile, "LOCK_UN", INT2FIX(LOCK_UN));
- rb_define_const(cFile, "LOCK_NB", INT2FIX(LOCK_NB));
-
- rb_define_const(mConst, "LOCK_SH", INT2FIX(LOCK_SH));
- rb_define_const(mConst, "LOCK_EX", INT2FIX(LOCK_EX));
- rb_define_const(mConst, "LOCK_UN", INT2FIX(LOCK_UN));
- rb_define_const(mConst, "LOCK_NB", INT2FIX(LOCK_NB));
-
- rb_define_method(cFile, "path", file_path, 0);
-
- rb_define_global_function("test", f_test, -1);
-
- sStat = struct_define("Stat", "dev", "ino", "mode",
- "nlink", "uid", "gid", "rdev",
- "size", "blksize", "blocks",
- "atime", "mtime", "ctime", 0);
+ VALUE rb_mConst;
+
+ rb_mFileTest = rb_define_module("FileTest");
+
+ rb_define_module_function(rb_mFileTest, "directory?", test_d, 1);
+ rb_define_module_function(rb_mFileTest, "exist?", test_e, 1);
+ rb_define_module_function(rb_mFileTest, "exists?", test_e, 1); /* temporary */
+ rb_define_module_function(rb_mFileTest, "readable?", test_r, 1);
+ rb_define_module_function(rb_mFileTest, "readable_real?", test_R, 1);
+ rb_define_module_function(rb_mFileTest, "writable?", test_w, 1);
+ rb_define_module_function(rb_mFileTest, "writable_real?", test_W, 1);
+ rb_define_module_function(rb_mFileTest, "executable?", test_x, 1);
+ rb_define_module_function(rb_mFileTest, "executable_real?", test_X, 1);
+ rb_define_module_function(rb_mFileTest, "file?", test_f, 1);
+ rb_define_module_function(rb_mFileTest, "zero?", test_z, 1);
+ rb_define_module_function(rb_mFileTest, "size?", test_s, 1);
+ rb_define_module_function(rb_mFileTest, "size", test_s, 1);
+ rb_define_module_function(rb_mFileTest, "owned?", test_owned, 1);
+ rb_define_module_function(rb_mFileTest, "grpowned?", test_grpowned, 1);
+
+ rb_define_module_function(rb_mFileTest, "pipe?", test_p, 1);
+ rb_define_module_function(rb_mFileTest, "symlink?", test_l, 1);
+ rb_define_module_function(rb_mFileTest, "socket?", test_S, 1);
+
+ rb_define_module_function(rb_mFileTest, "blockdev?", test_b, 1);
+ rb_define_module_function(rb_mFileTest, "chardev?", test_c, 1);
+
+ rb_define_module_function(rb_mFileTest, "setuid?", test_suid, 1);
+ rb_define_module_function(rb_mFileTest, "setgid?", test_sgid, 1);
+ rb_define_module_function(rb_mFileTest, "sticky?", test_sticky, 1);
+
+ 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);
+
+ rb_define_singleton_method(rb_cFile, "atime", rb_file_s_atime, 1);
+ rb_define_singleton_method(rb_cFile, "mtime", rb_file_s_mtime, 1);
+ rb_define_singleton_method(rb_cFile, "ctime", rb_file_s_ctime, 1);
+ rb_define_singleton_method(rb_cFile, "size", rb_file_s_size, 1);
+
+ rb_define_singleton_method(rb_cFile, "utime", rb_file_s_utime, -1);
+ rb_define_singleton_method(rb_cFile, "chmod", rb_file_s_chmod, -1);
+ rb_define_singleton_method(rb_cFile, "chown", rb_file_s_chown, -1);
+
+ rb_define_singleton_method(rb_cFile, "link", rb_file_s_link, 2);
+ rb_define_singleton_method(rb_cFile, "symlink", rb_file_s_symlink, 2);
+ rb_define_singleton_method(rb_cFile, "readlink", rb_file_s_readlink, 1);
+
+ rb_define_singleton_method(rb_cFile, "unlink", rb_file_s_unlink, -2);
+ rb_define_singleton_method(rb_cFile, "delete", rb_file_s_unlink, -2);
+ rb_define_singleton_method(rb_cFile, "rename", rb_file_s_rename, 2);
+ rb_define_singleton_method(rb_cFile, "umask", rb_file_s_umask, -1);
+ rb_define_singleton_method(rb_cFile, "truncate", rb_file_s_truncate, 2);
+ rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1);
+ rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1);
+ rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1);
+
+ separator = rb_str_new2("/");
+ rb_define_const(rb_cFile, "Separator", separator);
+ 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);
+
+ rb_define_method(rb_cFile, "atime", rb_file_atime, 0);
+ rb_define_method(rb_cFile, "mtime", rb_file_mtime, 0);
+ rb_define_method(rb_cFile, "ctime", rb_file_ctime, 0);
+
+ rb_define_method(rb_cFile, "chmod", rb_file_chmod, 1);
+ rb_define_method(rb_cFile, "chown", rb_file_chown, 2);
+ rb_define_method(rb_cFile, "truncate", rb_file_truncate, 1);
+
+ 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_define_method(rb_cFile, "path", rb_file_path, 0);
+
+ rb_define_global_function("test", rb_f_test, -1);
+
+ sStat = rb_struct_define("Stat", "dev", "ino", "mode",
+ "nlink", "uid", "gid", "rdev",
+ "size", "blksize", "blocks",
+ "atime", "mtime", "ctime", 0);
}
diff --git a/gc.c b/gc.c
index 21c719f..ad5969c 100644
--- a/gc.c
+++ b/gc.c
@@ -20,7 +20,7 @@
#include <setjmp.h>
void re_free_registers _((struct re_registers*));
-void io_fptr_finalize _((struct OpenFile*));
+void rb_io_fptr_finalize _((struct OpenFile*));
#ifndef setjmp
#ifdef HAVE__SETJMP
@@ -54,19 +54,19 @@ xmalloc(size)
void *mem;
if (size < 0) {
- ArgError("negative allocation size (or too big)");
+ rb_raise(rb_eArgError, "negative allocation size (or too big)");
}
if (size == 0) size = 1;
malloc_memories += size;
if (malloc_memories > GC_MALLOC_LIMIT && alloc_objects > GC_NEWOBJ_LIMIT) {
- gc_gc();
+ rb_gc();
}
mem = malloc(size);
if (!mem) {
- gc_gc();
+ rb_gc();
mem = malloc(size);
if (!mem)
- Fatal("failed to allocate memory");
+ rb_fatal("failed to allocate memory");
}
return mem;
@@ -92,16 +92,16 @@ xrealloc(ptr, size)
void *mem;
if (size < 0) {
- ArgError("negative re-allocation size");
+ rb_raise(rb_eArgError, "negative re-allocation size");
}
if (!ptr) return xmalloc(size);
malloc_memories += size;
mem = realloc(ptr, size);
if (!mem) {
- gc_gc();
+ rb_gc();
mem = realloc(ptr, size);
if (!mem)
- Fatal("failed to allocate memory(realloc)");
+ rb_fatal("failed to allocate memory(realloc)");
}
return mem;
@@ -140,25 +140,25 @@ Cambridge, MA 02138
extern int rb_in_compile;
static int dont_gc;
-VALUE
-gc_s_enable()
+static VALUE
+gc_enable()
{
int old = dont_gc;
- dont_gc = FALSE;
+ dont_gc = Qfalse;
return old;
}
-VALUE
-gc_s_disable()
+static VALUE
+gc_disable()
{
int old = dont_gc;
- dont_gc = TRUE;
+ dont_gc = Qtrue;
return old;
}
-VALUE mGC;
+VALUE rb_mGC;
static struct gc_list {
VALUE *varptr;
@@ -225,11 +225,11 @@ add_heap()
heaps = (heaps_used>0)?
(RVALUE**)realloc(heaps, heaps_length*sizeof(RVALUE)):
(RVALUE**)malloc(heaps_length*sizeof(RVALUE));
- if (heaps == 0) Fatal("can't alloc memory");
+ if (heaps == 0) rb_fatal("can't alloc memory");
}
p = heaps[heaps_used++] = (RVALUE*)malloc(sizeof(RVALUE)*HEAP_SLOTS);
- if (p == 0) Fatal("can't alloc memory");
+ if (p == 0) rb_fatal("add_heap: can't alloc memory");
pend = p + HEAP_SLOTS;
if (lomem == 0 || lomem > p) lomem = p;
if (himem < pend) himem = pend;
@@ -255,14 +255,14 @@ rb_newobj()
alloc_objects++;
return obj;
}
- if (dont_gc || prohibit_interrupt) add_heap();
- else gc_gc();
+ if (dont_gc || rb_prohibit_interrupt) add_heap();
+ else rb_gc();
goto retry;
}
VALUE
-data_object_alloc(klass, datap, dmark, dfree)
+rb_data_object_alloc(klass, datap, dmark, dfree)
VALUE klass;
void *datap;
void (*dfree)();
@@ -278,7 +278,7 @@ data_object_alloc(klass, datap, dmark, dfree)
}
extern st_table *rb_class_tbl;
-VALUE *gc_stack_start;
+VALUE *rb_gc_stack_start;
static int
looks_pointerp(ptr)
@@ -288,16 +288,16 @@ looks_pointerp(ptr)
register RVALUE *heap_org;
register long i;
- if (p < lomem || p > himem) return FALSE;
+ if (p < lomem || p > himem) return Qfalse;
/* check if p looks like a pointer */
for (i=0; i < heaps_used; i++) {
heap_org = heaps[i];
if (heap_org <= p && p < heap_org + HEAP_SLOTS
&& ((((char*)p)-((char*)heap_org))%sizeof(RVALUE)) == 0)
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static void
@@ -307,14 +307,14 @@ mark_locations_array(x, n)
{
while (n--) {
if (looks_pointerp(*x)) {
- gc_mark(*x);
+ rb_gc_mark(*x);
}
x++;
}
}
void
-gc_mark_locations(start, end)
+rb_gc_mark_locations(start, end)
VALUE *start, *end;
{
VALUE *tmp;
@@ -334,7 +334,7 @@ mark_entry(key, value)
ID key;
VALUE value;
{
- gc_mark(value);
+ rb_gc_mark(value);
return ST_CONTINUE;
}
@@ -351,8 +351,8 @@ mark_hashentry(key, value)
ID key;
VALUE value;
{
- gc_mark(key);
- gc_mark(value);
+ rb_gc_mark(key);
+ rb_gc_mark(value);
return ST_CONTINUE;
}
@@ -365,16 +365,16 @@ mark_hash(tbl)
}
void
-gc_mark_maybe(obj)
+rb_gc_mark_maybe(obj)
void *obj;
{
if (looks_pointerp(obj)) {
- gc_mark(obj);
+ rb_gc_mark(obj);
}
}
void
-gc_mark(ptr)
+rb_gc_mark(ptr)
void *ptr;
{
register RVALUE *obj = RANY(ptr);
@@ -390,7 +390,7 @@ gc_mark(ptr)
switch (obj->as.basic.flags & T_MASK) {
case T_NIL:
case T_FIXNUM:
- Bug("gc_mark() called for broken object");
+ rb_bug("rb_gc_mark() called for broken object");
break;
case T_NODE:
@@ -399,7 +399,7 @@ gc_mark(ptr)
case NODE_FOR:
case NODE_ITER:
case NODE_CREF:
- gc_mark(obj->as.node.u2.node);
+ rb_gc_mark(obj->as.node.u2.node);
/* fall through */
case NODE_BLOCK: /* 1,3 */
case NODE_ARRAY:
@@ -413,7 +413,7 @@ gc_mark(ptr)
#ifdef C_ALLOCA
case NODE_ALLOCA:
#endif
- gc_mark(obj->as.node.u1.node);
+ rb_gc_mark(obj->as.node.u1.node);
/* fall through */
case NODE_SUPER: /* 3 */
case NODE_FCALL:
@@ -425,7 +425,7 @@ gc_mark(ptr)
case NODE_UNTIL:
case NODE_MATCH2:
case NODE_MATCH3:
- gc_mark(obj->as.node.u1.node);
+ rb_gc_mark(obj->as.node.u1.node);
/* fall through */
case NODE_METHOD: /* 2 */
case NODE_NOT:
@@ -447,7 +447,7 @@ gc_mark(ptr)
goto Top;
case NODE_SCOPE: /* 2,3 */
- gc_mark(obj->as.node.u3.node);
+ rb_gc_mark(obj->as.node.u3.node);
obj = RANY(obj->as.node.u2.node);
goto Top;
@@ -471,10 +471,10 @@ gc_mark(ptr)
default:
if (looks_pointerp(obj->as.node.u1.node)) {
- gc_mark(obj->as.node.u1.node);
+ rb_gc_mark(obj->as.node.u1.node);
}
if (looks_pointerp(obj->as.node.u2.node)) {
- gc_mark(obj->as.node.u2.node);
+ rb_gc_mark(obj->as.node.u2.node);
}
if (looks_pointerp(obj->as.node.u3.node)) {
obj = RANY(obj->as.node.u3.node);
@@ -484,17 +484,17 @@ gc_mark(ptr)
return; /* no need to mark class. */
}
- gc_mark(obj->as.basic.klass);
+ rb_gc_mark(obj->as.basic.klass);
switch (obj->as.basic.flags & T_MASK) {
case T_ICLASS:
- gc_mark(obj->as.klass.super);
+ rb_gc_mark(obj->as.klass.super);
mark_tbl(obj->as.klass.iv_tbl);
mark_tbl(obj->as.klass.m_tbl);
break;
case T_CLASS:
case T_MODULE:
- gc_mark(obj->as.klass.super);
+ rb_gc_mark(obj->as.klass.super);
mark_tbl(obj->as.klass.m_tbl);
mark_tbl(obj->as.klass.iv_tbl);
break;
@@ -505,12 +505,13 @@ gc_mark(ptr)
VALUE *ptr = obj->as.array.ptr;
for (i=0; i < len; i++)
- gc_mark(*ptr++);
+ rb_gc_mark(*ptr++);
}
break;
case T_HASH:
mark_hash(obj->as.hash.tbl);
+ rb_gc_mark(obj->as.hash.ifnone);
break;
case T_STRING:
@@ -542,7 +543,7 @@ gc_mark(ptr)
break;
case T_VARMAP:
- gc_mark(obj->as.varmap.val);
+ rb_gc_mark(obj->as.varmap.val);
obj = RANY(obj->as.varmap.next);
goto Top;
break;
@@ -553,7 +554,7 @@ gc_mark(ptr)
VALUE *vars = &obj->as.scope.local_vars[-1];
while (n--) {
- gc_mark_maybe(*vars);
+ rb_gc_mark(*vars);
vars++;
}
}
@@ -565,14 +566,14 @@ gc_mark(ptr)
VALUE *ptr = obj->as.rstruct.ptr;
for (i=0; i < len; i++)
- gc_mark(*ptr++);
+ rb_gc_mark(*ptr++);
}
break;
default:
- Bug("gc_mark(): unknown data type 0x%x(0x%x) %s",
- obj->as.basic.flags & T_MASK, obj,
- looks_pointerp(obj)?"corrupted object":"non object");
+ rb_bug("rb_gc_mark(): unknown data type 0x%x(0x%x) %s",
+ obj->as.basic.flags & T_MASK, obj,
+ looks_pointerp(obj)?"corrupted object":"non object");
}
}
@@ -588,11 +589,12 @@ gc_sweep()
int i;
if (rb_in_compile) {
+ /* sould not reclaim nodes during compilation */
for (i = 0; i < heaps_used; i++) {
p = heaps[i]; pend = p + HEAP_SLOTS;
while (p < pend) {
if (!(p->as.basic.flags&FL_MARK) && BUILTIN_TYPE(p) == T_NODE)
- gc_mark(p);
+ rb_gc_mark(p);
p++;
}
}
@@ -628,7 +630,7 @@ gc_sweep()
}
void
-gc_force_recycle(p)
+rb_gc_force_recycle(p)
VALUE p;
{
RANY(p)->as.free.flag = 0;
@@ -647,11 +649,11 @@ obj_free(obj)
case T_FIXNUM:
case T_TRUE:
case T_FALSE:
- Bug("obj_free() called for broken object");
+ rb_bug("obj_free() called for broken object");
break;
}
- if (need_call_final) {
+ if (need_call_final && FL_TEST(obj, FL_FINALIZE)) {
run_final(obj);
}
switch (RANY(obj)->as.basic.flags & T_MASK) {
@@ -705,7 +707,7 @@ obj_free(obj)
break;
case T_FILE:
if (RANY(obj)->as.file.fptr) {
- io_fptr_finalize(RANY(obj)->as.file.fptr);
+ rb_io_fptr_finalize(RANY(obj)->as.file.fptr);
free(RANY(obj)->as.file.fptr);
}
break;
@@ -742,22 +744,23 @@ obj_free(obj)
break;
default:
- Bug("gc_sweep(): unknown data type %d", RANY(obj)->as.basic.flags & T_MASK);
+ rb_bug("gc_sweep(): unknown data type %d",
+ RANY(obj)->as.basic.flags & T_MASK);
}
}
void
-gc_mark_frame(frame)
+rb_gc_mark_frame(frame)
struct FRAME *frame;
{
int n = frame->argc;
VALUE *tbl = frame->argv;
while (n--) {
- gc_mark_maybe(*tbl);
+ rb_gc_mark_maybe(*tbl);
tbl++;
}
- gc_mark(frame->cbase);
+ rb_gc_mark(frame->cbase);
}
#ifdef __GNUC__
@@ -796,7 +799,7 @@ int rb_setjmp (rb_jmp_buf);
#endif /* __GNUC__ */
void
-gc_gc()
+rb_gc()
{
struct gc_list *list;
struct FRAME *frame;
@@ -812,52 +815,52 @@ gc_gc()
#endif
/* mark frame stack */
- for (frame = the_frame; frame; frame = frame->prev) {
- gc_mark_frame(frame);
+ for (frame = ruby_frame; frame; frame = frame->prev) {
+ rb_gc_mark_frame(frame);
}
- gc_mark(the_scope);
- gc_mark(the_dyna_vars);
+ rb_gc_mark(ruby_scope);
+ rb_gc_mark(ruby_dyna_vars);
FLUSH_REGISTER_WINDOWS;
/* This assumes that all registers are saved into the jmp_buf */
setjmp(save_regs_gc_mark);
mark_locations_array((VALUE*)&save_regs_gc_mark, sizeof(save_regs_gc_mark) / sizeof(VALUE *));
- gc_mark_locations(gc_stack_start, (VALUE*)&stack_end);
+ rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)&stack_end);
#if defined(THINK_C) || defined(__human68k__)
#ifndef __human68k__
mark_locations_array((VALUE*)((char*)save_regs_gc_mark+2),
sizeof(save_regs_gc_mark) / sizeof(VALUE *));
#endif
- gc_mark_locations((VALUE*)((char*)gc_stack_start + 2),
+ rb_gc_mark_locations((VALUE*)((char*)rb_gc_stack_start + 2),
(VALUE*)((char*)&stack_end + 2));
#endif
#ifdef THREAD
- gc_mark_threads();
+ rb_gc_mark_threads();
#endif
/* mark protected global variables */
for (list = Global_List; list; list = list->next) {
- gc_mark(*list->varptr);
+ rb_gc_mark(*list->varptr);
}
- gc_mark_global_tbl();
+ rb_gc_mark_global_tbl();
mark_tbl(rb_class_tbl);
- gc_mark_trap_list();
+ rb_gc_mark_trap_list();
gc_sweep();
dont_gc--;
}
static VALUE
-gc_method()
+gc_start()
{
- gc_gc();
+ rb_gc();
return Qnil;
}
void
-init_stack()
+Init_stack()
{
#ifdef __human68k__
extern void *_SEND;
@@ -865,14 +868,14 @@ init_stack()
#else
VALUE start;
- gc_stack_start = &start;
+ rb_gc_stack_start = &start;
#endif
}
void
-init_heap()
+Init_heap()
{
- init_stack();
+ Init_stack();
add_heap();
}
@@ -929,7 +932,7 @@ os_obj_of(of)
case T_CLASS:
if (FL_TEST(p, FL_SINGLETON)) continue;
default:
- if (obj_is_kind_of((VALUE)p, of)) {
+ if (rb_obj_is_kind_of((VALUE)p, of)) {
rb_yield((VALUE)p);
n++;
}
@@ -962,11 +965,11 @@ static VALUE
add_final(os, proc)
VALUE os, proc;
{
- if (!obj_is_kind_of(proc, cProc)) {
- ArgError("wrong type argument %s (Proc required)",
- rb_class2name(CLASS_OF(proc)));
+ if (!rb_obj_is_kind_of(proc, rb_cProc)) {
+ rb_raise(rb_eArgError, "wrong type argument %s (Proc required)",
+ rb_class2name(CLASS_OF(proc)));
}
- ary_push(finalizers, proc);
+ rb_ary_push(finalizers, proc);
return proc;
}
@@ -974,7 +977,7 @@ static VALUE
rm_final(os, proc)
VALUE os, proc;
{
- ary_delete(finalizers, proc);
+ rb_ary_delete(finalizers, proc);
return proc;
}
@@ -999,16 +1002,14 @@ run_final(obj)
{
int i;
- if (!FL_TEST(obj, FL_FINALIZE)) return;
-
obj = INT2NUM((long)obj); /* make obj into id */
for (i=0; i<RARRAY(finalizers)->len; i++) {
- rb_eval_cmd(RARRAY(finalizers)->ptr[i], ary_new3(1,obj));
+ rb_eval_cmd(RARRAY(finalizers)->ptr[i], rb_ary_new3(1,obj));
}
}
void
-gc_call_finalizer_at_exit()
+rb_gc_call_finalizer_at_exit()
{
RVALUE *p, *pend;
int i;
@@ -1017,7 +1018,8 @@ gc_call_finalizer_at_exit()
for (i = 0; i < heaps_used; i++) {
p = heaps[i]; pend = p + HEAP_SLOTS;
while (p < pend) {
- run_final((VALUE)p);
+ if (FL_TEST(p, FL_FINALIZE))
+ run_final((VALUE)p);
p++;
}
}
@@ -1041,15 +1043,15 @@ id2ref(obj, id)
unsigned long ptr = NUM2UINT(id);
if (FIXNUM_P(ptr)) return (VALUE)ptr;
- if (ptr == TRUE) return TRUE;
- if (ptr == FALSE) return FALSE;
+ if (ptr == Qtrue) return Qtrue;
+ if (ptr == Qfalse) return Qfalse;
if (ptr == Qnil) return Qnil;
if (!looks_pointerp(ptr)) {
- IndexError("0x%x is not the id value", ptr);
+ rb_raise(rb_eIndexError, "0x%x is not the id value", ptr);
}
if (RANY(ptr)->as.free.flag == 0) {
- IndexError("0x%x is recycled object", ptr);
+ rb_raise(rb_eIndexError, "0x%x is recycled object", ptr);
}
return (VALUE)ptr;
}
@@ -1057,23 +1059,23 @@ id2ref(obj, id)
void
Init_GC()
{
- VALUE mObSpace;
-
- mGC = rb_define_module("GC");
- rb_define_singleton_method(mGC, "start", gc_method, 0);
- rb_define_singleton_method(mGC, "enable", gc_s_enable, 0);
- rb_define_singleton_method(mGC, "disable", gc_s_disable, 0);
- rb_define_method(mGC, "garbage_collect", gc_method, 0);
-
- mObSpace = rb_define_module("ObjectSpace");
- rb_define_module_function(mObSpace, "each_object", os_each_obj, -1);
- rb_define_module_function(mObSpace, "garbage_collect", gc_method, 0);
- rb_define_module_function(mObSpace, "add_finalizer", add_final, 1);
- rb_define_module_function(mObSpace, "remove_finalizer", rm_final, 1);
- rb_define_module_function(mObSpace, "finalizers", finals, 0);
- rb_define_module_function(mObSpace, "call_finalizer", call_final, 1);
- rb_define_module_function(mObSpace, "_id2ref", id2ref, 1);
+ VALUE rb_mObSpace;
+
+ rb_mGC = rb_define_module("GC");
+ rb_define_singleton_method(rb_mGC, "start", gc_start, 0);
+ rb_define_singleton_method(rb_mGC, "enable", gc_enable, 0);
+ rb_define_singleton_method(rb_mGC, "disable", gc_disable, 0);
+ rb_define_method(rb_mGC, "garbage_collect", gc_start, 0);
+
+ rb_mObSpace = rb_define_module("ObjectSpace");
+ rb_define_module_function(rb_mObSpace, "each_object", os_each_obj, -1);
+ rb_define_module_function(rb_mObSpace, "garbage_collect", gc_start, 0);
+ rb_define_module_function(rb_mObSpace, "add_finalizer", add_final, 1);
+ rb_define_module_function(rb_mObSpace, "remove_finalizer", rm_final, 1);
+ rb_define_module_function(rb_mObSpace, "finalizers", finals, 0);
+ rb_define_module_function(rb_mObSpace, "call_finalizer", call_final, 1);
+ rb_define_module_function(rb_mObSpace, "_id2ref", id2ref, 1);
rb_global_variable(&finalizers);
- finalizers = ary_new();
+ finalizers = rb_ary_new();
}
diff --git a/hash.c b/hash.c
index 56256ea..a5b8f5f 100644
--- a/hash.c
+++ b/hash.c
@@ -25,17 +25,17 @@ char *strchr _((char*,char));
#define HASH_DELETED FL_USER2
static void
-hash_modify(hash)
+rb_hash_modify(hash)
VALUE hash;
{
rb_secure(5);
if (FL_TEST(hash, HASH_FREEZE)) {
- TypeError("can't modify frozen hash");
+ rb_raise(rb_eTypeError, "can't modify frozen hash");
}
}
VALUE
-hash_freeze(hash)
+rb_hash_freeze(hash)
VALUE hash;
{
FL_SET(hash, HASH_FREEZE);
@@ -43,15 +43,15 @@ hash_freeze(hash)
}
static VALUE
-hash_frozen_p(hash)
+rb_hash_frozen_p(hash)
VALUE hash;
{
if (FL_TEST(hash, HASH_FREEZE))
- return TRUE;
- return FALSE;
+ return Qtrue;
+ return Qfalse;
}
-VALUE cHash;
+VALUE rb_cHash;
static VALUE envtbl;
static ID hash;
@@ -64,14 +64,14 @@ rb_hash(obj)
}
static int
-any_cmp(a, b)
+rb_any_cmp(a, b)
VALUE a, b;
{
if (FIXNUM_P(a)) {
if (FIXNUM_P(b)) return a != b;
}
else if (TYPE(a) == T_STRING) {
- if (TYPE(b) == T_STRING) return str_cmp(a, b);
+ if (TYPE(b) == T_STRING) return rb_str_cmp(a, b);
}
DEFER_INTS;
@@ -81,7 +81,7 @@ any_cmp(a, b)
}
static int
-any_hash(a, mod)
+rb_any_hash(a, mod)
VALUE a;
int mod;
{
@@ -93,7 +93,7 @@ any_hash(a, mod)
break;
case T_STRING:
- hval = str_hash(a);
+ hval = rb_str_hash(a);
break;
default:
@@ -105,24 +105,25 @@ any_hash(a, mod)
ENABLE_INTS;
hval = FIX2LONG(hval);
}
+ if (hval < 0) hval = -hval;
return hval % mod;
}
static struct st_hash_type objhash = {
- any_cmp,
- any_hash,
+ rb_any_cmp,
+ rb_any_hash,
};
-struct hash_foreach_arg {
+struct rb_hash_foreach_arg {
VALUE hash;
enum st_retval (*func)();
char *arg;
};
static int
-hash_foreach_iter(key, value, arg)
+rb_hash_foreach_iter(key, value, arg)
VALUE key, value;
- struct hash_foreach_arg *arg;
+ struct rb_hash_foreach_arg *arg;
{
int status;
st_table *tbl = RHASH(arg->hash)->tbl;
@@ -131,21 +132,21 @@ hash_foreach_iter(key, value, arg)
if (key == Qnil) return ST_CONTINUE;
status = (*arg->func)(key, value, arg->arg);
if (RHASH(arg->hash)->tbl != tbl || RHASH(arg->hash)->tbl->bins != bins){
- IndexError("rehash occurred during iteration");
+ rb_raise(rb_eIndexError, "rehash occurred during iteration");
}
return status;
}
static VALUE
-hash_foreach_call(arg)
- struct hash_foreach_arg *arg;
+rb_hash_foreach_call(arg)
+ struct rb_hash_foreach_arg *arg;
{
- st_foreach(RHASH(arg->hash)->tbl, hash_foreach_iter, arg);
+ st_foreach(RHASH(arg->hash)->tbl, rb_hash_foreach_iter, arg);
return Qnil;
}
static int
-hash_delete_nil(key, value)
+rb_hash_delete_nil(key, value)
VALUE key, value;
{
if (value == Qnil) return ST_DELETE;
@@ -153,14 +154,14 @@ hash_delete_nil(key, value)
}
static VALUE
-hash_foreach_ensure(hash)
+rb_hash_foreach_ensure(hash)
VALUE hash;
{
RHASH(hash)->iter_lev--;
if (RHASH(hash)->iter_lev == 0) {
if (FL_TEST(hash, HASH_DELETED)) {
- st_foreach(RHASH(hash)->tbl, hash_delete_nil, 0);
+ st_foreach(RHASH(hash)->tbl, rb_hash_delete_nil, 0);
FL_UNSET(hash, HASH_DELETED);
}
}
@@ -168,56 +169,58 @@ hash_foreach_ensure(hash)
}
static int
-hash_foreach(hash, func, farg)
+rb_hash_foreach(hash, func, farg)
VALUE hash;
enum st_retval (*func)();
char *farg;
{
- struct hash_foreach_arg arg;
+ struct rb_hash_foreach_arg arg;
RHASH(hash)->iter_lev++;
arg.hash = hash;
arg.func = func;
arg.arg = farg;
- return rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash);
+ return rb_ensure(rb_hash_foreach_call, (VALUE)&arg, rb_hash_foreach_ensure, hash);
}
static VALUE
-hash_s_new(argc, argv, klass)
+rb_hash_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
- VALUE sz;
+ VALUE sz, ifnone;
int size;
NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
hash->iter_lev = 0;
- hash->status = 0;
+ hash->ifnone = Qnil;
hash->tbl = 0; /* avoid GC crashing */
- if (rb_scan_args(argc, argv, "01", &sz) == 0) {
+ rb_scan_args(argc, argv, "02", &ifnone, &sz);
+ if (NIL_P(sz)) {
size = 0;
}
else size = NUM2INT(sz);
+ hash->ifnone = ifnone;
hash->tbl = st_init_table_with_size(&objhash, size);
- obj_call_init((VALUE)hash);
+ rb_obj_call_init((VALUE)hash);
return (VALUE)hash;
}
static VALUE
-hash_new2(klass)
+rb_hash_new2(klass)
VALUE klass;
{
NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
hash->iter_lev = 0;
- hash->status = 0;
+ hash->ifnone = Qnil;
hash->tbl = 0; /* avoid GC crashing */
hash->tbl = st_init_table(&objhash);
@@ -225,13 +228,13 @@ hash_new2(klass)
}
VALUE
-hash_new()
+rb_hash_new()
{
- return hash_new2(cHash);
+ return rb_hash_new2(rb_cHash);
}
static VALUE
-hash_s_create(argc, argv, klass)
+rb_hash_s_create(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -246,36 +249,36 @@ hash_s_create(argc, argv, klass)
OBJSETUP(hash, klass, T_HASH);
hash->iter_lev = 0;
- hash->status = 0;
+ hash->ifnone = Qnil;
hash->tbl = 0; /* avoid GC crashing */
hash->tbl = (st_table*)st_copy(RHASH(argv[0])->tbl);
- obj_call_init((VALUE)hash);
+ rb_obj_call_init((VALUE)hash);
return (VALUE)hash;
}
}
if (argc % 2 != 0) {
- ArgError("odd number args for Hash");
+ rb_raise(rb_eArgError, "odd number args for Hash");
}
- hash = hash_new2(klass);
+ hash = rb_hash_new2(klass);
for (i=0; i<argc; i+=2) {
st_insert(RHASH(hash)->tbl, argv[i], argv[i+1]);
}
- obj_call_init(hash);
+ rb_obj_call_init(hash);
return hash;
}
static VALUE
-hash_clone(hash)
+rb_hash_clone(hash)
VALUE hash;
{
NEWOBJ(hash2, struct RHash);
CLONESETUP(hash2, hash);
hash2->iter_lev = 0;
- hash2->status = 0;
+ hash2->ifnone = RHASH(hash)->ifnone;
hash2->tbl = 0; /* avoid GC crashing */
hash2->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
@@ -283,14 +286,14 @@ hash_clone(hash)
}
static VALUE
-hash_dup(hash)
+rb_hash_dup(hash)
VALUE hash;
{
NEWOBJ(hash2, struct RHash);
OBJSETUP(hash2, CLASS_OF(hash), T_HASH);
hash2->iter_lev = 0;
- hash2->status = 0;
+ hash2->ifnone = RHASH(hash)->ifnone;
hash2->tbl = 0; /* avoid GC crashing */
hash2->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
@@ -305,7 +308,7 @@ to_hash(hash)
}
static int
-hash_rehash_i(key, value, tbl)
+rb_hash_rehash_i(key, value, tbl)
VALUE key, value;
st_table *tbl;
{
@@ -316,13 +319,13 @@ hash_rehash_i(key, value, tbl)
}
static VALUE
-hash_rehash(hash)
+rb_hash_rehash(hash)
VALUE hash;
{
st_table *tbl;
tbl = st_init_table_with_size(&objhash, RHASH(hash)->tbl->num_entries);
- st_foreach(RHASH(hash)->tbl, hash_rehash_i, tbl);
+ st_foreach(RHASH(hash)->tbl, rb_hash_rehash_i, tbl);
st_free_table(RHASH(hash)->tbl);
RHASH(hash)->tbl = tbl;
@@ -330,19 +333,19 @@ hash_rehash(hash)
}
VALUE
-hash_aref(hash, key)
+rb_hash_aref(hash, key)
VALUE hash, key;
{
VALUE val;
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
- return Qnil;
+ return RHASH(hash)->ifnone;
}
return val;
}
static VALUE
-hash_fetch(argc, argv, hash)
+rb_hash_fetch(argc, argv, hash)
int argc;
VALUE *argv;
VALUE hash;
@@ -353,9 +356,9 @@ hash_fetch(argc, argv, hash)
rb_scan_args(argc, argv, "11", &key, &if_none);
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
- if (iterator_p()) {
+ if (rb_iterator_p()) {
if (argc > 1) {
- ArgError("wrong # of arguments", argc);
+ rb_raise(rb_eArgError, "wrong # of arguments", argc);
}
return rb_yield(argv[0]);
}
@@ -365,7 +368,15 @@ hash_fetch(argc, argv, hash)
}
static VALUE
-hash_indexes(argc, argv, hash)
+rb_hash_default(hash, ifnone)
+ VALUE hash;
+{
+ RHASH(hash)->ifnone = ifnone;
+ return hash;
+}
+
+static VALUE
+rb_hash_indexes(argc, argv, hash)
int argc;
VALUE *argv;
VALUE hash;
@@ -373,21 +384,21 @@ hash_indexes(argc, argv, hash)
VALUE indexes;
int i;
- indexes = ary_new2(argc);
+ indexes = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
- RARRAY(indexes)->ptr[i] = hash_aref(hash, argv[i]);
+ RARRAY(indexes)->ptr[i] = rb_hash_aref(hash, argv[i]);
}
RARRAY(indexes)->len = i;
return indexes;
}
static VALUE
-hash_delete(hash, key)
+rb_hash_delete(hash, key)
VALUE hash, key;
{
VALUE val;
- hash_modify(hash);
+ rb_hash_modify(hash);
if (RHASH(hash)->iter_lev > 0 &&
st_delete_safe(RHASH(hash)->tbl, &key, &val, Qnil)) {
FL_SET(hash, HASH_DELETED);
@@ -395,7 +406,7 @@ hash_delete(hash, key)
}
else if (st_delete(RHASH(hash)->tbl, &key, &val))
return val;
- if (iterator_p()) {
+ if (rb_iterator_p()) {
return rb_yield(key);
}
return Qnil;
@@ -421,17 +432,17 @@ shift_i(key, value, var)
}
static VALUE
-hash_shift(hash)
+rb_hash_shift(hash)
VALUE hash;
{
struct shift_var var;
- hash_modify(hash);
+ rb_hash_modify(hash);
var.stop = 0;
st_foreach(RHASH(hash)->tbl, shift_i, &var);
if (var.stop == 0) return Qnil;
- return assoc_new(var.key, var.val);
+ return rb_assoc_new(var.key, var.val);
}
static int
@@ -439,17 +450,17 @@ delete_if_i(key, value)
VALUE key, value;
{
if (key == Qnil) return ST_CONTINUE;
- if (rb_yield(assoc_new(key, value)))
+ if (rb_yield(rb_assoc_new(key, value)))
return ST_DELETE;
return ST_CONTINUE;
}
static VALUE
-hash_delete_if(hash)
+rb_hash_delete_if(hash)
VALUE hash;
{
- hash_modify(hash);
- hash_foreach(hash, delete_if_i, 0);
+ rb_hash_modify(hash);
+ rb_hash_foreach(hash, delete_if_i, 0);
return hash;
}
@@ -462,26 +473,26 @@ clear_i(key, value)
}
static VALUE
-hash_clear(hash)
+rb_hash_clear(hash)
VALUE hash;
{
- hash_modify(hash);
+ rb_hash_modify(hash);
st_foreach(RHASH(hash)->tbl, clear_i);
return hash;
}
VALUE
-hash_aset(hash, key, val)
+rb_hash_aset(hash, key, val)
VALUE hash, key, val;
{
- hash_modify(hash);
+ rb_hash_modify(hash);
if (NIL_P(val)) {
- hash_delete(hash, key);
+ rb_hash_delete(hash, key);
return Qnil;
}
if (TYPE(key) == T_STRING) {
- key = str_dup_frozen(key);
+ key = rb_str_dup_frozen(key);
}
st_insert(RHASH(hash)->tbl, key, val);
return val;
@@ -491,35 +502,35 @@ static int
replace_i(key, val, hash)
VALUE key, val, hash;
{
- hash_aset(hash, key, val);
+ rb_hash_aset(hash, key, val);
return ST_CONTINUE;
}
static VALUE
-hash_replace(hash, hash2)
+rb_hash_replace(hash, hash2)
VALUE hash, hash2;
{
hash2 = to_hash(hash2);
- hash_clear(hash);
+ rb_hash_clear(hash);
st_foreach(RHASH(hash2)->tbl, replace_i, hash);
return hash;
}
static VALUE
-hash_length(hash)
+rb_hash_length(hash)
VALUE hash;
{
return INT2FIX(RHASH(hash)->tbl->num_entries);
}
static VALUE
-hash_empty_p(hash)
+rb_hash_empty_p(hash)
VALUE hash;
{
if (RHASH(hash)->tbl->num_entries == 0)
- return TRUE;
- return FALSE;
+ return Qtrue;
+ return Qfalse;
}
static int
@@ -532,10 +543,10 @@ each_value_i(key, value)
}
static VALUE
-hash_each_value(hash)
+rb_hash_each_value(hash)
VALUE hash;
{
- hash_foreach(hash, each_value_i, 0);
+ rb_hash_foreach(hash, each_value_i, 0);
return hash;
}
@@ -549,10 +560,10 @@ each_key_i(key, value)
}
static VALUE
-hash_each_key(hash)
+rb_hash_each_key(hash)
VALUE hash;
{
- hash_foreach(hash, each_key_i, 0);
+ rb_hash_foreach(hash, each_key_i, 0);
return hash;
}
@@ -561,15 +572,15 @@ each_pair_i(key, value)
VALUE key, value;
{
if (key == Qnil) return ST_CONTINUE;
- rb_yield(assoc_new(key, value));
+ rb_yield(rb_assoc_new(key, value));
return ST_CONTINUE;
}
static VALUE
-hash_each_pair(hash)
+rb_hash_each_pair(hash)
VALUE hash;
{
- hash_foreach(hash, each_pair_i, 0);
+ rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}
@@ -578,22 +589,29 @@ to_a_i(key, value, ary)
VALUE key, value, ary;
{
if (key == Qnil) return ST_CONTINUE;
- ary_push(ary, assoc_new(key, value));
+ rb_ary_push(ary, rb_assoc_new(key, value));
return ST_CONTINUE;
}
static VALUE
-hash_to_a(hash)
+rb_hash_to_a(hash)
VALUE hash;
{
VALUE ary;
- ary = ary_new();
+ ary = rb_ary_new();
st_foreach(RHASH(hash)->tbl, to_a_i, ary);
return ary;
}
+static VALUE
+rb_hash_sort(hash)
+ VALUE hash;
+{
+ return rb_ary_sort_bang(rb_hash_to_a(hash));
+}
+
static int
inspect_i(key, value, str)
VALUE key, value, str;
@@ -602,39 +620,39 @@ inspect_i(key, value, str)
if (key == Qnil) return ST_CONTINUE;
if (RSTRING(str)->len > 1) {
- str_cat(str, ", ", 2);
+ rb_str_cat(str, ", ", 2);
}
str2 = rb_inspect(key);
- str_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
- str_cat(str, "=>", 2);
+ rb_str_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
+ rb_str_cat(str, "=>", 2);
str2 = rb_inspect(value);
- str_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
+ rb_str_cat(str, RSTRING(str2)->ptr, RSTRING(str2)->len);
return ST_CONTINUE;
}
static VALUE
-hash_inspect(hash)
+rb_hash_inspect(hash)
VALUE hash;
{
VALUE str;
- str = str_new2("{");
+ str = rb_str_new2("{");
st_foreach(RHASH(hash)->tbl, inspect_i, str);
- str_cat(str, "}", 1);
+ rb_str_cat(str, "}", 1);
return str;
}
static VALUE
-hash_to_s(hash)
+rb_hash_to_s(hash)
VALUE hash;
{
- return ary_to_s(hash_to_a(hash));
+ return rb_ary_to_s(rb_hash_to_a(hash));
}
static VALUE
-hash_to_hash(hash)
+rb_hash_to_hash(hash)
VALUE hash;
{
return hash;
@@ -645,17 +663,17 @@ keys_i(key, value, ary)
VALUE key, value, ary;
{
if (key == Qnil) return ST_CONTINUE;
- ary_push(ary, key);
+ rb_ary_push(ary, key);
return ST_CONTINUE;
}
static VALUE
-hash_keys(hash)
+rb_hash_keys(hash)
VALUE hash;
{
VALUE ary;
- ary = ary_new();
+ ary = rb_ary_new();
st_foreach(RHASH(hash)->tbl, keys_i, ary);
return ary;
@@ -666,55 +684,55 @@ values_i(key, value, ary)
VALUE key, value, ary;
{
if (key == Qnil) return ST_CONTINUE;
- ary_push(ary, value);
+ rb_ary_push(ary, value);
return ST_CONTINUE;
}
static VALUE
-hash_values(hash)
+rb_hash_values(hash)
VALUE hash;
{
VALUE ary;
- ary = ary_new();
+ ary = rb_ary_new();
st_foreach(RHASH(hash)->tbl, values_i, ary);
return ary;
}
static VALUE
-hash_has_key(hash, key)
+rb_hash_has_key(hash, key)
VALUE hash;
VALUE key;
{
if (st_lookup(RHASH(hash)->tbl, key, 0)) {
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static int
-hash_search_value(key, value, data)
+rb_hash_search_value(key, value, data)
VALUE key, value, *data;
{
if (key == Qnil) return ST_CONTINUE;
if (rb_equal(value, data[1])) {
- data[0] = TRUE;
+ data[0] = Qtrue;
return ST_STOP;
}
return ST_CONTINUE;
}
static VALUE
-hash_has_value(hash, val)
+rb_hash_has_value(hash, val)
VALUE hash;
VALUE val;
{
VALUE data[2];
- data[0] = FALSE;
+ data[0] = Qfalse;
data[1] = val;
- st_foreach(RHASH(hash)->tbl, hash_search_value, data);
+ st_foreach(RHASH(hash)->tbl, rb_hash_search_value, data);
return data[0];
}
@@ -732,69 +750,69 @@ equal_i(key, val1, data)
if (key == Qnil) return ST_CONTINUE;
if (!st_lookup(data->tbl, key, &val2)) {
- data->result = FALSE;
+ data->result = Qfalse;
return ST_STOP;
}
if (!rb_equal(val1, val2)) {
- data->result = FALSE;
+ data->result = Qfalse;
return ST_STOP;
}
return ST_CONTINUE;
}
static VALUE
-hash_equal(hash1, hash2)
+rb_hash_equal(hash1, hash2)
VALUE hash1, hash2;
{
struct equal_data data;
- if (TYPE(hash2) != T_HASH) return FALSE;
+ if (TYPE(hash2) != T_HASH) return Qfalse;
if (RHASH(hash1)->tbl->num_entries != RHASH(hash2)->tbl->num_entries)
- return FALSE;
+ return Qfalse;
data.tbl = RHASH(hash2)->tbl;
- data.result = TRUE;
+ data.result = Qtrue;
st_foreach(RHASH(hash1)->tbl, equal_i, &data);
return data.result;
}
static int
-hash_invert_i(key, value, hash)
+rb_hash_invert_i(key, value, hash)
VALUE key, value;
VALUE hash;
{
if (key == Qnil) return ST_CONTINUE;
- hash_aset(hash, value, key);
+ rb_hash_aset(hash, value, key);
return ST_CONTINUE;
}
static VALUE
-hash_invert(hash)
+rb_hash_invert(hash)
VALUE hash;
{
- VALUE h = hash_new();
+ VALUE h = rb_hash_new();
- st_foreach(RHASH(hash)->tbl, hash_invert_i, h);
+ st_foreach(RHASH(hash)->tbl, rb_hash_invert_i, h);
return h;
}
static int
-hash_update_i(key, value, hash)
+rb_hash_update_i(key, value, hash)
VALUE key, value;
VALUE hash;
{
if (key == Qnil) return ST_CONTINUE;
- hash_aset(hash, key, value);
+ rb_hash_aset(hash, key, value);
return ST_CONTINUE;
}
static VALUE
-hash_update(hash1, hash2)
+rb_hash_update(hash1, hash2)
VALUE hash1, hash2;
{
hash2 = to_hash(hash2);
- st_foreach(RHASH(hash2)->tbl, hash_update_i, hash1);
+ st_foreach(RHASH(hash2)->tbl, rb_hash_update_i, hash1);
return hash1;
}
@@ -827,7 +845,7 @@ env_delete(obj, name)
i++;
}
if (val) {
- return str_new2(val);
+ return rb_str_new2(val);
}
return Qnil;
}
@@ -837,12 +855,12 @@ env_delete_method(obj, name)
VALUE obj, name;
{
VALUE val = env_delete(obj, name);
- if (iterator_p()) rb_yield(name);
+ if (rb_iterator_p()) rb_yield(name);
return val;
}
static VALUE
-f_getenv(obj, name)
+rb_f_getenv(obj, name)
VALUE obj, name;
{
char *nam, *env;
@@ -850,13 +868,13 @@ f_getenv(obj, name)
nam = str2cstr(name, &len);
if (strlen(nam) != len) {
- ArgError("Bad environment variable name");
+ rb_raise(rb_eArgError, "Bad environment variable name");
}
env = getenv(nam);
if (env) {
- if (strcmp(nam, "PATH") == 0 && !env_path_tainted())
- return str_new2(env);
- return str_taint(str_new2(env));
+ if (strcmp(nam, "PATH") == 0 && !rb_env_path_tainted())
+ return rb_str_new2(env);
+ return rb_str_taint(rb_str_new2(env));
}
return Qnil;
}
@@ -913,7 +931,7 @@ path_check(path)
}
int
-env_path_tainted()
+rb_env_path_tainted()
{
if (path_tainted < 0) {
path_check(getenv("PATH"));
@@ -922,11 +940,11 @@ env_path_tainted()
}
static VALUE
-f_setenv(obj, name, value)
+rb_f_setenv(obj, name, value)
VALUE obj, name, value;
{
if (rb_safe_level() >= 4) {
- Raise(eSecurityError, "cannot change environment variable");
+ rb_raise(rb_eSecurityError, "cannot change environment variable");
}
Check_SafeStr(name);
@@ -937,33 +955,33 @@ f_setenv(obj, name, value)
Check_SafeStr(value);
if (strlen(RSTRING(name)->ptr) != RSTRING(name)->len)
- ArgError("Bad environment name");
+ rb_raise(rb_eArgError, "Bad environment name");
if (strlen(RSTRING(value)->ptr) != RSTRING(value)->len)
- ArgError("Bad environment value");
-
+ rb_raise(rb_eArgError, "Bad environment value");
+
setenv(RSTRING(name)->ptr, RSTRING(value)->ptr, 1);
if (strcmp(RSTRING(name)->ptr, "PATH") == 0) {
- if (str_tainted(value)) {
+ if (rb_str_tainted(value)) {
/* already tainted, no check */
path_tainted = 1;
- return TRUE;
+ return Qtrue;
}
path_check(RSTRING(name)->ptr);
}
- return TRUE;
+ return Qtrue;
}
static VALUE
env_keys()
{
char **env;
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
env = environ;
while (*env) {
char *s = strchr(*env, '=');
- ary_push(ary, str_taint(str_new(*env, s-*env)));
+ rb_ary_push(ary, rb_str_taint(rb_str_new(*env, s-*env)));
env++;
}
return ary;
@@ -973,19 +991,19 @@ static VALUE
env_each_key(hash)
VALUE hash;
{
- return ary_each(env_keys());
+ return rb_ary_each(env_keys());
}
static VALUE
env_values()
{
char **env;
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
env = environ;
while (*env) {
char *s = strchr(*env, '=');
- ary_push(ary, str_taint(str_new2(s+1)));
+ rb_ary_push(ary, rb_str_taint(rb_str_new2(s+1)));
env++;
}
return ary;
@@ -995,7 +1013,7 @@ static VALUE
env_each_value(hash)
VALUE hash;
{
- return ary_each(env_values());
+ return rb_ary_each(env_values());
}
static VALUE
@@ -1007,9 +1025,9 @@ env_each(hash)
int len = RARRAY(ary)->len;
while (len--) {
- VALUE val = f_getenv(Qnil, *ptr);
+ VALUE val = rb_f_getenv(Qnil, *ptr);
if (!NIL_P(val)) {
- rb_yield(assoc_new(*ptr, val));
+ rb_yield(rb_assoc_new(*ptr, val));
}
ptr++;
}
@@ -1024,9 +1042,9 @@ env_delete_if()
int len = RARRAY(ary)->len;
while (len--) {
- VALUE val = f_getenv(Qnil, *ptr);
+ VALUE val = rb_f_getenv(Qnil, *ptr);
if (!NIL_P(val)) {
- if (RTEST(rb_yield(assoc_new(*ptr, val)))) {
+ if (RTEST(rb_yield(rb_assoc_new(*ptr, val)))) {
env_delete(Qnil, *ptr);
}
}
@@ -1038,20 +1056,20 @@ env_delete_if()
static VALUE
env_to_s()
{
- return str_new2("ENV");
+ return rb_str_new2("ENV");
}
static VALUE
env_to_a()
{
char **env;
- VALUE ary = ary_new();
+ VALUE ary = rb_ary_new();
env = environ;
while (*env) {
char *s = strchr(*env, '=');
- ary_push(ary, assoc_new(str_taint(str_new(*env, s-*env)),
- str_taint(str_new2(s+1))));
+ rb_ary_push(ary, rb_assoc_new(rb_str_taint(rb_str_new(*env, s-*env)),
+ rb_str_taint(rb_str_new2(s+1))));
env++;
}
return ary;
@@ -1076,17 +1094,17 @@ env_size()
static VALUE
env_empty_p()
{
- if (environ[0] == 0) return TRUE;
- return FALSE;
+ if (environ[0] == 0) return Qtrue;
+ return Qfalse;
}
static VALUE
env_has_key(env, key)
VALUE env, key;
{
- if (TYPE(key) != T_STRING) return FALSE;
- if (getenv(RSTRING(key)->ptr)) return TRUE;
- return FALSE;
+ if (TYPE(key) != T_STRING) return Qfalse;
+ if (getenv(RSTRING(key)->ptr)) return Qtrue;
+ return Qfalse;
}
static VALUE
@@ -1096,16 +1114,16 @@ env_has_value(dmy, value)
char **env;
VALUE ary;
- if (TYPE(value) != T_STRING) return FALSE;
- ary = ary_new();
+ if (TYPE(value) != T_STRING) return Qfalse;
+ ary = rb_ary_new();
env = environ;
while (*env) {
char *s = strchr(*env, '=')+1;
int len = strlen(s);
- if (strncmp(s, RSTRING(value)->ptr, len) == 0) return TRUE;
+ if (strncmp(s, RSTRING(value)->ptr, len) == 0) return Qtrue;
env++;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -1114,7 +1132,7 @@ env_indexes(argc, argv)
VALUE *argv;
{
int i;
- VALUE indexes = ary_new2(argc);
+ VALUE indexes = rb_ary_new2(argc);
for (i=0;i<argc;i++) {
char *v = 0;
@@ -1122,7 +1140,7 @@ env_indexes(argc, argv)
v = getenv(RSTRING(argv[i])->ptr);
}
if (v) {
- RARRAY(indexes)->ptr[i] = str_new2(v);
+ RARRAY(indexes)->ptr[i] = rb_str_new2(v);
}
else {
RARRAY(indexes)->ptr[i] = Qnil;
@@ -1137,15 +1155,15 @@ static VALUE
env_to_hash(obj)
VALUE obj;
{
- VALUE hash = hash_new();
+ VALUE hash = rb_hash_new();
VALUE ary = env_keys();
VALUE *ptr = RARRAY(ary)->ptr;
int len = RARRAY(ary)->len;
while (len--) {
- VALUE val = f_getenv(Qnil, *ptr);
+ VALUE val = rb_f_getenv(Qnil, *ptr);
if (!NIL_P(val)) {
- hash_aset(hash, *ptr, val);
+ rb_hash_aset(hash, *ptr, val);
}
ptr++;
}
@@ -1159,64 +1177,66 @@ Init_Hash()
{
hash = rb_intern("hash");
- cHash = rb_define_class("Hash", cObject);
-
- rb_include_module(cHash, mEnumerable);
-
- rb_define_singleton_method(cHash, "new", hash_s_new, -1);
- rb_define_singleton_method(cHash, "[]", hash_s_create, -1);
-
- rb_define_method(cHash,"clone", hash_clone, 0);
- rb_define_method(cHash,"dup", hash_dup, 0);
- rb_define_method(cHash,"rehash", hash_rehash, 0);
-
- rb_define_method(cHash,"freeze", hash_freeze, 0);
- rb_define_method(cHash,"frozen?",hash_frozen_p, 0);
-
- rb_define_method(cHash,"to_hash", hash_to_hash, 0);
- rb_define_method(cHash,"to_a", hash_to_a, 0);
- rb_define_method(cHash,"to_s", hash_to_s, 0);
- rb_define_method(cHash,"inspect", hash_inspect, 0);
-
- rb_define_method(cHash,"==", hash_equal, 1);
- rb_define_method(cHash,"[]", hash_aref, 1);
- rb_define_method(cHash,"fetch", hash_fetch, -1);
- rb_define_method(cHash,"[]=", hash_aset, 2);
- rb_define_method(cHash,"store", hash_aset, 2);
- rb_define_method(cHash,"indexes", hash_indexes, -1);
- rb_define_method(cHash,"indices", hash_indexes, -1);
- rb_define_method(cHash,"length", hash_length, 0);
- rb_define_alias(cHash, "size", "length");
- rb_define_method(cHash,"empty?", hash_empty_p, 0);
-
- rb_define_method(cHash,"each", hash_each_pair, 0);
- rb_define_method(cHash,"each_value", hash_each_value, 0);
- rb_define_method(cHash,"each_key", hash_each_key, 0);
- rb_define_method(cHash,"each_pair", hash_each_pair, 0);
-
- rb_define_method(cHash,"keys", hash_keys, 0);
- rb_define_method(cHash,"values", hash_values, 0);
-
- rb_define_method(cHash,"shift", hash_shift, 0);
- rb_define_method(cHash,"delete", hash_delete, 1);
- rb_define_method(cHash,"delete_if", hash_delete_if, 0);
- rb_define_method(cHash,"clear", hash_clear, 0);
- rb_define_method(cHash,"invert", hash_invert, 0);
- rb_define_method(cHash,"update", hash_update, 1);
- rb_define_method(cHash,"replace", hash_replace, 1);
-
- rb_define_method(cHash,"include?", hash_has_key, 1);
- rb_define_method(cHash,"has_key?", hash_has_key, 1);
- rb_define_method(cHash,"has_value?", hash_has_value, 1);
- rb_define_method(cHash,"key?", hash_has_key, 1);
- rb_define_method(cHash,"value?", hash_has_value, 1);
+ rb_cHash = rb_define_class("Hash", rb_cObject);
+
+ rb_include_module(rb_cHash, rb_mEnumerable);
+
+ rb_define_singleton_method(rb_cHash, "new", rb_hash_s_new, -1);
+ rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
+
+ rb_define_method(rb_cHash,"clone", rb_hash_clone, 0);
+ rb_define_method(rb_cHash,"dup", rb_hash_dup, 0);
+ rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
+
+ rb_define_method(rb_cHash,"freeze", rb_hash_freeze, 0);
+ rb_define_method(rb_cHash,"frozen?",rb_hash_frozen_p, 0);
+
+ rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
+ rb_define_method(rb_cHash,"to_a", rb_hash_to_a, 0);
+ rb_define_method(rb_cHash,"to_s", rb_hash_to_s, 0);
+ rb_define_method(rb_cHash,"inspect", rb_hash_inspect, 0);
+
+ rb_define_method(rb_cHash,"==", rb_hash_equal, 1);
+ rb_define_method(rb_cHash,"[]", rb_hash_aref, 1);
+ rb_define_method(rb_cHash,"fetch", rb_hash_fetch, -1);
+ rb_define_method(rb_cHash,"[]=", rb_hash_aset, 2);
+ rb_define_method(rb_cHash,"store", rb_hash_aset, 2);
+ rb_define_method(rb_cHash,"default", rb_hash_default, 1);
+ rb_define_method(rb_cHash,"indexes", rb_hash_indexes, -1);
+ rb_define_method(rb_cHash,"indices", rb_hash_indexes, -1);
+ rb_define_method(rb_cHash,"length", rb_hash_length, 0);
+ rb_define_alias(rb_cHash, "size", "length");
+ rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);
+
+ rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
+ rb_define_method(rb_cHash,"each_value", rb_hash_each_value, 0);
+ rb_define_method(rb_cHash,"each_key", rb_hash_each_key, 0);
+ rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0);
+ rb_define_method(rb_cHash,"sort", rb_hash_sort, 0);
+
+ rb_define_method(rb_cHash,"keys", rb_hash_keys, 0);
+ rb_define_method(rb_cHash,"values", rb_hash_values, 0);
+
+ rb_define_method(rb_cHash,"shift", rb_hash_shift, 0);
+ rb_define_method(rb_cHash,"delete", rb_hash_delete, 1);
+ rb_define_method(rb_cHash,"delete_if", rb_hash_delete_if, 0);
+ rb_define_method(rb_cHash,"clear", rb_hash_clear, 0);
+ rb_define_method(rb_cHash,"invert", rb_hash_invert, 0);
+ rb_define_method(rb_cHash,"update", rb_hash_update, 1);
+ rb_define_method(rb_cHash,"replace", rb_hash_replace, 1);
+
+ rb_define_method(rb_cHash,"include?", rb_hash_has_key, 1);
+ rb_define_method(rb_cHash,"has_key?", rb_hash_has_key, 1);
+ rb_define_method(rb_cHash,"has_value?", rb_hash_has_value, 1);
+ rb_define_method(rb_cHash,"key?", rb_hash_has_key, 1);
+ rb_define_method(rb_cHash,"value?", rb_hash_has_value, 1);
#ifndef __MACOS__ /* environment variables nothing on MacOS. */
- envtbl = obj_alloc(cObject);
- rb_extend_object(envtbl, mEnumerable);
+ envtbl = rb_obj_alloc(rb_cObject);
+ rb_extend_object(envtbl, rb_mEnumerable);
- rb_define_singleton_method(envtbl,"[]", f_getenv, 1);
- rb_define_singleton_method(envtbl,"[]=", f_setenv, 2);
+ rb_define_singleton_method(envtbl,"[]", rb_f_getenv, 1);
+ rb_define_singleton_method(envtbl,"[]=", rb_f_setenv, 2);
rb_define_singleton_method(envtbl,"each", env_each, 0);
rb_define_singleton_method(envtbl,"each_pair", env_each, 0);
rb_define_singleton_method(envtbl,"each_key", env_each_key, 0);
@@ -1241,7 +1261,7 @@ Init_Hash()
rb_define_global_const("ENV", envtbl);
#else /* __MACOS__ */
- envtbl = hash_s_new(0, NULL, cHash);
+ envtbl = rb_hash_s_new(0, NULL, rb_cHash);
rb_define_global_const("ENV", envtbl);
#endif /* ifndef __MACOS__ environment variables nothing on MacOS. */
}
diff --git a/intern.h b/intern.h
index c68d5a4..5f6386b 100644
--- a/intern.h
+++ b/intern.h
@@ -3,74 +3,72 @@
*/
/* array.c */
-void memclear _((register VALUE*, register int));
-VALUE assoc_new _((VALUE, VALUE));
-VALUE ary_new _((void));
-VALUE ary_new2 _((int));
-VALUE ary_new3 __((int,...));
-VALUE ary_new4 _((int, VALUE *));
-VALUE ary_freeze _((VALUE));
-VALUE ary_aref _((int, VALUE*, VALUE));
-void ary_store _((VALUE, int, VALUE));
-VALUE ary_push _((VALUE, VALUE));
-VALUE ary_pop _((VALUE));
-VALUE ary_shift _((VALUE));
-VALUE ary_unshift _((VALUE, VALUE));
-VALUE ary_entry _((VALUE, int));
-VALUE ary_each _((VALUE));
-VALUE ary_join _((VALUE, VALUE));
-VALUE ary_to_s _((VALUE));
-VALUE ary_print_on _((VALUE, VALUE));
-VALUE ary_reverse _((VALUE));
-VALUE ary_sort_bang _((VALUE));
-VALUE ary_sort _((VALUE));
-VALUE ary_delete _((VALUE, VALUE));
-VALUE ary_delete_at _((VALUE, VALUE));
-VALUE ary_plus _((VALUE, VALUE));
-VALUE ary_concat _((VALUE, VALUE));
-VALUE ary_assoc _((VALUE, VALUE));
-VALUE ary_rassoc _((VALUE, VALUE));
-VALUE ary_includes _((VALUE, VALUE));
+void rb_mem_clear _((register VALUE*, register int));
+VALUE rb_assoc_new _((VALUE, VALUE));
+VALUE rb_ary_new _((void));
+VALUE rb_ary_new2 _((int));
+VALUE rb_ary_new3 __((int,...));
+VALUE rb_ary_new4 _((int, VALUE *));
+VALUE rb_ary_freeze _((VALUE));
+VALUE rb_ary_aref _((int, VALUE*, VALUE));
+void rb_ary_store _((VALUE, int, VALUE));
+VALUE rb_ary_to_s _((VALUE));
+VALUE rb_ary_push _((VALUE, VALUE));
+VALUE rb_ary_pop _((VALUE));
+VALUE rb_ary_shift _((VALUE));
+VALUE rb_ary_unshift _((VALUE, VALUE));
+VALUE rb_ary_entry _((VALUE, int));
+VALUE rb_ary_each _((VALUE));
+VALUE rb_ary_join _((VALUE, VALUE));
+VALUE rb_ary_print_on _((VALUE, VALUE));
+VALUE rb_ary_reverse _((VALUE));
+VALUE rb_ary_sort _((VALUE));
+VALUE rb_ary_sort_bang _((VALUE));
+VALUE rb_ary_delete _((VALUE, VALUE));
+VALUE rb_ary_delete_at _((VALUE, VALUE));
+VALUE rb_ary_plus _((VALUE, VALUE));
+VALUE rb_ary_concat _((VALUE, VALUE));
+VALUE rb_ary_assoc _((VALUE, VALUE));
+VALUE rb_ary_rassoc _((VALUE, VALUE));
+VALUE rb_ary_includes _((VALUE, VALUE));
/* bignum.c */
-VALUE big_clone _((VALUE));
-void big_2comp _((VALUE));
-VALUE big_norm _((VALUE));
-VALUE uint2big _((unsigned long));
-VALUE int2big _((long));
-VALUE uint2inum _((unsigned long));
-VALUE int2inum _((long));
-VALUE str2inum _((char*, int));
-VALUE big2str _((VALUE, int));
-long big2long _((VALUE));
-#define big2int(x) big2long(x)
-unsigned long big2ulong _((VALUE));
-#define big2uint(x) big2ulong(x)
-VALUE big_to_i _((VALUE));
-VALUE dbl2big _((double));
-double big2dbl _((VALUE));
-VALUE big_to_f _((VALUE));
-VALUE big_plus _((VALUE, VALUE));
-VALUE big_minus _((VALUE, VALUE));
-VALUE big_mul _((VALUE, VALUE));
-VALUE big_pow _((VALUE, VALUE));
-VALUE big_and _((VALUE, VALUE));
-VALUE big_or _((VALUE, VALUE));
-VALUE big_xor _((VALUE, VALUE));
-VALUE big_lshift _((VALUE, VALUE));
-VALUE big_rand _((VALUE));
+VALUE rb_big_clone _((VALUE));
+void rb_big_2comp _((VALUE));
+VALUE rb_big_norm _((VALUE));
+VALUE rb_uint2big _((unsigned long));
+VALUE rb_int2big _((long));
+VALUE rb_uint2inum _((unsigned long));
+VALUE rb_int2inum _((long));
+VALUE rb_str2inum _((char*, int));
+VALUE rb_big2str _((VALUE, int));
+long rb_big2long _((VALUE));
+#define rb_big2int(x) rb_big2long(x)
+unsigned long rb_big2ulong _((VALUE));
+#define rb_big2uint(x) rb_big2ulong(x)
+VALUE rb_dbl2big _((double));
+double rb_big2dbl _((VALUE));
+VALUE rb_big_plus _((VALUE, VALUE));
+VALUE rb_big_minus _((VALUE, VALUE));
+VALUE rb_big_mul _((VALUE, VALUE));
+VALUE rb_big_pow _((VALUE, VALUE));
+VALUE rb_big_and _((VALUE, VALUE));
+VALUE rb_big_or _((VALUE, VALUE));
+VALUE rb_big_xor _((VALUE, VALUE));
+VALUE rb_big_lshift _((VALUE, VALUE));
+VALUE rb_big_rand _((VALUE));
/* class.c */
-VALUE class_new _((VALUE));
-VALUE singleton_class_new _((VALUE));
-VALUE singleton_class_clone _((VALUE));
-void singleton_class_attached _((VALUE,VALUE));
+VALUE rb_class_new _((VALUE));
+VALUE rb_singleton_class_new _((VALUE));
+VALUE rb_singleton_class_clone _((VALUE));
+void rb_singleton_class_attached _((VALUE,VALUE));
VALUE rb_define_class_id _((ID, VALUE));
-VALUE module_new _((void));
+VALUE rb_module_new _((void));
VALUE rb_define_module_id _((ID));
-VALUE mod_included_modules _((VALUE));
-VALUE mod_ancestors _((VALUE));
-VALUE class_instance_methods _((int, VALUE*, VALUE));
-VALUE class_private_instance_methods _((int, VALUE*, VALUE));
-VALUE obj_singleton_methods _((VALUE));
+VALUE rb_mod_included_modules _((VALUE));
+VALUE rb_mod_ancestors _((VALUE));
+VALUE rb_class_instance_methods _((int, VALUE*, VALUE));
+VALUE rb_class_private_instance_methods _((int, VALUE*, VALUE));
+VALUE rb_obj_singleton_methods _((VALUE));
void rb_define_method_id _((VALUE, ID, VALUE (*)(), int));
void rb_undef_method _((VALUE, char*));
void rb_define_protected_method _((VALUE, char*, VALUE (*)(), int));
@@ -79,17 +77,18 @@ void rb_define_singleton_method _((VALUE,char*,VALUE(*)(),int));
void rb_define_private_method _((VALUE,char*,VALUE(*)(),int));
VALUE rb_singleton_class _((VALUE));
/* enum.c */
-VALUE enum_length _((VALUE));
+VALUE rb_enum_length _((VALUE));
/* error.c */
-VALUE exc_new _((VALUE, char*, unsigned int));
-VALUE exc_new2 _((VALUE, char*));
-VALUE exc_new3 _((VALUE, VALUE));
-void TypeError __((char*, ...)) NORETURN;
-void ArgError __((char*, ...)) NORETURN;
-void NameError __((char*, ...)) NORETURN;
-void IndexError __((char*, ...)) NORETURN;
-void LoadError __((char*, ...)) NORETURN;
+extern int ruby_nerrs;
+VALUE rb_exc_new _((VALUE, char*, unsigned int));
+VALUE rb_exc_new2 _((VALUE, char*));
+VALUE rb_exc_new3 _((VALUE, VALUE));
+void rb_loaderror __((char*, ...)) NORETURN;
+void rb_compile_error __((char*, ...));
+void rb_compile_append __((char*, ...));
/* eval.c */
+void rb_exc_raise _((VALUE)) NORETURN;
+void rb_exc_fatal _((VALUE)) NORETURN;
void rb_remove_method _((VALUE, char*));
void rb_disable_super _((VALUE, char*));
void rb_enable_super _((VALUE, char*));
@@ -97,133 +96,129 @@ void rb_clear_cache _((void));
void rb_alias _((VALUE, ID, ID));
void rb_attr _((VALUE,ID,int,int,int));
int rb_method_boundp _((VALUE, ID, int));
-VALUE dyna_var_defined _((ID));
-VALUE dyna_var_ref _((ID));
-VALUE dyna_var_asgn _((ID, VALUE));
-void ruby_init _((void));
-void ruby_options _((int, char**));
-void ruby_run _((void));
+VALUE rb_dvar_defined _((ID));
+VALUE rb_dvar_ref _((ID));
+void rb_dvar_asgn _((ID, VALUE));
+void rb_dvar_push _((ID, VALUE));
VALUE rb_eval_cmd _((VALUE, VALUE));
VALUE rb_trap_eval _((VALUE, int));
int rb_respond_to _((VALUE, ID));
-void rb_raise _((VALUE));
-void rb_fatal _((VALUE));
void rb_interrupt _((void));
-int iterator_p _((void));
-VALUE rb_yield_0 _((VALUE, volatile VALUE));
VALUE rb_apply _((VALUE, ID, VALUE));
VALUE rb_funcall2 _((VALUE, ID, int, VALUE*));
void rb_backtrace _((void));
ID rb_frame_last_func _((void));
-VALUE f_load _((VALUE, VALUE));
+VALUE rb_f_load _((VALUE, VALUE));
void rb_provide _((char*));
-VALUE f_require _((VALUE, VALUE));
-void obj_call_init _((VALUE));
-VALUE class_new_instance _((int, VALUE*, VALUE));
-VALUE f_lambda _((void));
+VALUE rb_f_require _((VALUE, VALUE));
+void rb_obj_call_init _((VALUE));
+VALUE rb_class_new_instance _((int, VALUE*, VALUE));
+VALUE rb_f_lambda _((void));
void rb_set_end_proc _((void (*)(),VALUE));
-void gc_mark_threads _((void));
-void thread_schedule _((void));
-void thread_wait_fd _((int));
-void thread_fd_writable _((int));
-int thread_alone _((void));
-void thread_sleep _((int));
-void thread_sleep_forever _((void));
-VALUE thread_create _((VALUE (*)(), void*));
-void thread_interrupt _((void));
-void thread_trap_eval _((VALUE, int));
-int thread_select();
-void thread_wait_for();
+void rb_gc_mark_threads _((void));
+void rb_thread_schedule _((void));
+void rb_thread_wait_fd _((int));
+void rb_thread_fd_writable _((int));
+int rb_thread_alone _((void));
+void rb_thread_sleep _((int));
+void rb_thread_sleep_forever _((void));
+VALUE rb_thread_create _((VALUE (*)(), void*));
+int rb_thread_scope_shared_p _((void));
+void rb_thread_interrupt _((void));
+void rb_thread_trap_eval _((VALUE, int));
+int rb_thread_select();
+void rb_thread_wait_for();
/* file.c */
-VALUE file_open _((char*, char*));
+VALUE rb_file_open _((char*, char*));
int eaccess _((char*, int));
-VALUE file_s_expand_path _((int, VALUE *));
+VALUE rb_file_s_expand_path _((int, VALUE *));
/* gc.c */
void rb_global_variable _((VALUE*));
-void gc_mark_locations _((VALUE*, VALUE*));
-void gc_mark_maybe();
-void gc_mark();
-void gc_force_recycle();
-void gc_gc _((void));
-void init_stack _((void));
-void init_heap _((void));
+void rb_gc_mark_locations _((VALUE*, VALUE*));
+void rb_gc_mark_maybe();
+void rb_gc_mark();
+void rb_gc_force_recycle();
+void rb_gc _((void));
+void rb_gc_call_finalizer_at_exit _((void));
/* hash.c */
-VALUE hash_freeze _((VALUE));
+VALUE rb_hash_freeze _((VALUE));
VALUE rb_hash _((VALUE));
-VALUE hash_new _((void));
-VALUE hash_aref _((VALUE, VALUE));
-VALUE hash_aset _((VALUE, VALUE, VALUE));
-int env_path_tainted _((void));
+VALUE rb_hash_new _((void));
+VALUE rb_hash_aref _((VALUE, VALUE));
+VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
+int rb_env_path_tainted _((void));
/* io.c */
-void eof_error _((void));
-VALUE io_write _((VALUE, VALUE));
-VALUE io_gets_method _((int, VALUE*, VALUE));
-VALUE io_gets _((VALUE));
-VALUE io_getc _((VALUE));
-VALUE io_ungetc _((VALUE, VALUE));
-VALUE io_close _((VALUE));
-VALUE io_binmode _((VALUE));
-int io_mode_flags _((char*));
-VALUE io_reopen _((VALUE, VALUE));
-VALUE f_gets _((void));
+extern VALUE rb_fs;
+extern VALUE rb_output_fs;
+extern VALUE rb_rs;
+extern VALUE rb_default_rs;
+extern VALUE rb_output_rs;
+VALUE rb_io_write _((VALUE, VALUE));
+VALUE rb_io_gets_method _((int, VALUE*, VALUE));
+VALUE rb_io_gets _((VALUE));
+VALUE rb_io_getc _((VALUE));
+VALUE rb_io_ungetc _((VALUE, VALUE));
+VALUE rb_io_close _((VALUE));
+VALUE rb_io_binmode _((VALUE));
+int rb_io_mode_flags _((char*));
+VALUE rb_io_reopen _((VALUE, VALUE));
+VALUE rb_f_gets _((void));
void rb_str_setter _((VALUE, ID, VALUE*));
/* numeric.c */
-void num_zerodiv _((void));
-VALUE num_coerce_bin _((VALUE, VALUE));
-VALUE float_new _((double));
-VALUE flo_pow _((VALUE, VALUE));
-VALUE num2fix _((VALUE));
-VALUE fix2str _((VALUE, int));
-VALUE fix_to_s _((VALUE));
-VALUE num_upto _((VALUE, VALUE));
-VALUE fix_upto _((VALUE, VALUE));
+void rb_num_zerodiv _((void));
+VALUE rb_num_coerce_bin _((VALUE, VALUE));
+VALUE rb_float_new _((double));
+VALUE rb_num2fix _((VALUE));
+VALUE rb_fix2str _((VALUE, int));
+VALUE rb_fix_upto _((VALUE, VALUE));
/* object.c */
VALUE rb_equal _((VALUE, VALUE));
int rb_eql _((VALUE, VALUE));
-VALUE obj_equal _((VALUE, VALUE));
-VALUE any_to_s _((VALUE));
+VALUE rb_obj_equal _((VALUE, VALUE));
+VALUE rb_any_to_s _((VALUE));
VALUE rb_inspect _((VALUE));
-VALUE obj_is_instance_of _((VALUE, VALUE));
-VALUE obj_is_kind_of _((VALUE, VALUE));
-VALUE obj_alloc _((VALUE));
+VALUE rb_obj_is_instance_of _((VALUE, VALUE));
+VALUE rb_obj_is_kind_of _((VALUE, VALUE));
+VALUE rb_obj_alloc _((VALUE));
VALUE rb_convert_type _((VALUE,int,char*,char*));
VALUE rb_Integer _((VALUE));
VALUE rb_Float _((VALUE));
VALUE rb_String _((VALUE));
VALUE rb_Array _((VALUE));
-double num2dbl _((VALUE));
+double rb_num2dbl _((VALUE));
/* parse.y */
+extern int ruby_sourceline;
+extern char *ruby_sourcefile;
int yyparse _((void));
-void pushback _((int));
-ID id_attrset _((ID));
-void yyappend_print _((void));
-void yywhile_loop _((int, int));
+ID rb_id_attrset _((ID));
+void rb_parser_append_print _((void));
+void rb_parser_while_loop _((int, int));
int rb_is_const_id _((ID));
int rb_is_instance_id _((ID));
-void local_var_append _((ID));
-VALUE backref_get _((void));
-void backref_set _((VALUE));
-VALUE lastline_get _((void));
-void lastline_set _((VALUE));
+VALUE rb_backref_get _((void));
+void rb_backref_set _((VALUE));
+VALUE rb_lastline_get _((void));
+void rb_lastline_set _((VALUE));
/* process.c */
int rb_proc_exec _((char*));
void rb_syswait _((int));
/* range.c */
-VALUE range_new _((VALUE, VALUE));
-VALUE range_beg_end _((VALUE, int*, int*));
+VALUE rb_range_new _((VALUE, VALUE));
+VALUE rb_range_beg_end _((VALUE, int*, int*));
/* re.c */
-VALUE reg_nth_defined _((int, VALUE));
-VALUE reg_nth_match _((int, VALUE));
-VALUE reg_last_match _((VALUE));
-VALUE reg_match_pre _((VALUE));
-VALUE reg_match_post _((VALUE));
-VALUE reg_match_last _((VALUE));
-VALUE reg_new _((char*, int, int));
-VALUE reg_match _((VALUE, VALUE));
-VALUE reg_match2 _((VALUE));
-int reg_options _((VALUE));
+VALUE rb_reg_nth_defined _((int, VALUE));
+VALUE rb_reg_nth_match _((int, VALUE));
+VALUE rb_reg_last_match _((VALUE));
+VALUE rb_reg_match_pre _((VALUE));
+VALUE rb_reg_match_post _((VALUE));
+VALUE rb_reg_match_last _((VALUE));
+VALUE rb_reg_new _((char*, int, int));
+VALUE rb_reg_match _((VALUE, VALUE));
+VALUE rb_reg_match2 _((VALUE));
+int rb_reg_options _((VALUE));
char*rb_get_kcode _((void));
void rb_set_kcode _((char*));
+int rb_ignorecase_p _((void));
/* ruby.c */
void rb_load_file _((char*));
void ruby_script _((char*));
@@ -233,72 +228,75 @@ void ruby_process_options _((int, char**));
void ruby_require_modules _((void));
void ruby_load_script _((void));
/* signal.c */
-VALUE f_kill _((int, VALUE*));
-void gc_mark_trap_list _((void));
+VALUE rb_f_kill _((int, VALUE*));
+void rb_gc_mark_trap_list _((void));
+#ifdef POSIX_SIGNAL
+#define posix_signal ruby_posix_signal
void posix_signal _((int, void (*)()));
+#endif
void rb_trap_exit _((void));
void rb_trap_exec _((void));
/* sprintf.c */
-VALUE f_sprintf _((int, VALUE*));
+VALUE rb_f_sprintf _((int, VALUE*));
/* string.c */
-VALUE str_new _((char*, unsigned int));
-VALUE str_new2 _((char*));
-VALUE str_new3 _((VALUE));
-VALUE str_new4 _((VALUE));
-VALUE obj_as_string _((VALUE));
-VALUE str_to_str _((VALUE));
-VALUE str_dup _((VALUE));
-VALUE str_plus _((VALUE, VALUE));
-VALUE str_times _((VALUE, VALUE));
-VALUE str_substr _((VALUE, int, int));
-void str_modify _((VALUE));
-VALUE str_freeze _((VALUE));
-VALUE str_dup_frozen _((VALUE));
-VALUE str_taint _((VALUE));
-VALUE str_tainted _((VALUE));
-VALUE str_resize _((VALUE, int));
-VALUE str_cat _((VALUE, char*, unsigned int));
-VALUE str_concat _((VALUE, VALUE));
-int str_hash _((VALUE));
-int str_cmp _((VALUE, VALUE));
-VALUE str_upto _((VALUE, VALUE));
-VALUE str_inspect _((VALUE));
-VALUE str_split _((VALUE, char*));
+VALUE rb_str_new _((char*, unsigned int));
+VALUE rb_str_new2 _((char*));
+VALUE rb_str_new3 _((VALUE));
+VALUE rb_str_new4 _((VALUE));
+VALUE rb_obj_as_string _((VALUE));
+VALUE rb_str_to_str _((VALUE));
+VALUE rb_str_dup _((VALUE));
+VALUE rb_str_plus _((VALUE, VALUE));
+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_taint _((VALUE));
+VALUE rb_str_tainted _((VALUE));
+VALUE rb_str_resize _((VALUE, int));
+VALUE rb_str_cat _((VALUE, char*, unsigned int));
+VALUE rb_str_concat _((VALUE, VALUE));
+int rb_str_hash _((VALUE));
+int rb_str_cmp _((VALUE, VALUE));
+VALUE rb_str_upto _((VALUE, VALUE));
+VALUE rb_str_inspect _((VALUE));
+VALUE rb_str_split _((VALUE, char*));
/* struct.c */
-VALUE struct_new __((VALUE, ...));
-VALUE struct_define __((char*, ...));
-VALUE struct_alloc _((VALUE, VALUE));
-VALUE struct_aref _((VALUE, VALUE));
-VALUE struct_aset _((VALUE, VALUE, VALUE));
-VALUE struct_getmember _((VALUE, ID));
+VALUE rb_struct_new __((VALUE, ...));
+VALUE rb_struct_define __((char*, ...));
+VALUE rb_struct_alloc _((VALUE, VALUE));
+VALUE rb_struct_aref _((VALUE, VALUE));
+VALUE rb_struct_aset _((VALUE, VALUE, VALUE));
+VALUE rb_struct_getmember _((VALUE, ID));
/* time.c */
-VALUE time_new _((int, int));
-/* util.c */
-void add_suffix _((VALUE, char*));
-unsigned long scan_oct _((char*, int, int*));
-unsigned long scan_hex _((char*, int, int*));
+VALUE rb_time_new _((int, int));
/* variable.c */
-struct st_table *new_idhash _((void));
-VALUE mod_name _((VALUE));
+VALUE rb_mod_name _((VALUE));
VALUE rb_class_path _((VALUE));
void rb_set_class_path _((VALUE, VALUE, char*));
VALUE rb_path2class _((char*));
void rb_name_class _((VALUE, ID));
void rb_autoload _((char*, char*));
-VALUE f_autoload _((VALUE, VALUE, VALUE));
-void gc_mark_global_tbl _((void));
-VALUE f_trace_var _((int, VALUE*));
-VALUE f_untrace_var _((int, VALUE*));
+VALUE rb_f_autoload _((VALUE, VALUE, VALUE));
+void rb_gc_mark_global_tbl _((void));
+VALUE rb_f_trace_var _((int, VALUE*));
+VALUE rb_f_untrace_var _((int, VALUE*));
VALUE rb_gvar_set2 _((char*, VALUE));
-VALUE f_global_variables _((void));
+VALUE rb_f_global_variables _((void));
void rb_alias_variable _((ID, ID));
VALUE rb_ivar_get _((VALUE, ID));
VALUE rb_ivar_set _((VALUE, ID, VALUE));
VALUE rb_ivar_defined _((VALUE, ID));
-VALUE obj_instance_variables _((VALUE));
-VALUE mod_const_at _((VALUE, VALUE));
-VALUE mod_constants _((VALUE));
-VALUE mod_const_of _((VALUE, VALUE));
+VALUE rb_obj_instance_variables _((VALUE));
+VALUE rb_obj_remove_instance_variable _((VALUE, VALUE));
+VALUE rb_mod_const_at _((VALUE, VALUE));
+VALUE rb_mod_constants _((VALUE));
+VALUE rb_mod_const_of _((VALUE, VALUE));
+VALUE rb_mod_remove_const _((VALUE, VALUE));
int rb_const_defined_at _((VALUE, ID));
int rb_autoload_defined _((ID));
int rb_const_defined _((VALUE, ID));
+/* version.c */
+void ruby_show_version _((void));
+void ruby_show_copyright _((void));
diff --git a/io.c b/io.c
index c86409d..7794c67 100644
--- a/io.c
+++ b/io.c
@@ -61,23 +61,25 @@ struct timeval {
#include <net/socket.h>
#endif
-VALUE cIO;
-VALUE eEOFError;
-VALUE eIOError;
+VALUE rb_cIO;
+VALUE rb_eEOFError;
+VALUE rb_eIOError;
VALUE rb_stdin, rb_stdout, rb_stderr, rb_defout;
-VALUE FS, OFS;
-VALUE RS, ORS;
-VALUE RS_default;
+VALUE rb_fs;
+VALUE rb_output_fs;
+VALUE rb_rs;
+VALUE rb_output_rs;
+VALUE rb_default_rs;
static VALUE argf;
-ID id_write;
+static ID id_write;
-extern char *inplace;
+extern char *ruby_inplace_mode;
-struct timeval time_timeval _((VALUE));
+struct timeval rb_time_timeval _((VALUE));
static VALUE filename, file;
static int gets_lineno;
@@ -90,65 +92,61 @@ static VALUE lineno;
# else
# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
# endif
+#elif defined(FILE_COUNT)
+# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
+#elif defined(__BEOS__)
+# define ReadDataPending(fp) (fp->_state._eof == 0)
+#elif defined(USE_CWGUSI)
+# define ReadDataPending(fp) (fp->state.eof == 0)
#else
-# ifdef FILE_COUNT
-# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
-# else
-# if defined(__BEOS__)
-# define ReadDataPending(fp) (fp->_state._eof == 0)
-# elif defined(USE_CWGUSI)
-# define ReadDataPending(fp) (fp->state.eof == 0)
-# else
/* requires systems own version of the ReadDataPending() */
extern int ReadDataPending();
-# endif
-# define READ_DATA_PENDING(fp) ReadDataPending(fp)
-# endif
+# define READ_DATA_PENDING(fp) ReadDataPending(fp)
#endif
#ifndef THREAD
# define READ_CHECK(fp) 0
#else
# define READ_CHECK(fp) do {\
- if (!READ_DATA_PENDING(fp)) thread_wait_fd(fileno(fp));\
+ if (!READ_DATA_PENDING(fp)) rb_thread_wait_fd(fileno(fp));\
} while(0)
#endif
void
-eof_error()
+rb_eof_error()
{
- Raise(eEOFError, "End of file reached");
+ rb_raise(rb_eEOFError, "End of file reached");
}
void
-io_check_closed(fptr)
+rb_io_check_closed(fptr)
OpenFile *fptr;
{
if (fptr->f == NULL && fptr->f2 == NULL)
- Raise(eIOError, "closed stream");
+ rb_raise(rb_eIOError, "closed stream");
}
void
-io_readable(fptr)
+rb_io_check_readable(fptr)
OpenFile *fptr;
{
if (!(fptr->mode & FMODE_READABLE)) {
- Raise(eIOError, "not opened for reading");
+ rb_raise(rb_eIOError, "not opened for reading");
}
}
void
-io_writable(fptr)
+rb_io_check_writable(fptr)
OpenFile *fptr;
{
if (!(fptr->mode & FMODE_WRITABLE)) {
- Raise(eIOError, "not opened for writing");
+ rb_raise(rb_eIOError, "not opened for writing");
}
}
/* writing functions */
VALUE
-io_write(io, str)
+rb_io_write(io, str)
VALUE io, str;
{
OpenFile *fptr;
@@ -156,7 +154,7 @@ io_write(io, str)
int n;
if (TYPE(str) != T_STRING)
- str = obj_as_string(str);
+ str = rb_obj_as_string(str);
if (RSTRING(str)->len == 0) return INT2FIX(0);
if (BUILTIN_TYPE(io) != T_FILE) {
@@ -166,7 +164,7 @@ io_write(io, str)
rb_secure(4);
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
@@ -195,22 +193,22 @@ io_write(io, str)
}
static VALUE
-io_addstr(io, str)
+rb_io_addstr(io, str)
VALUE io, str;
{
- io_write(io, str);
+ rb_io_write(io, str);
return io;
}
static VALUE
-io_flush(io)
+rb_io_flush(io)
VALUE io;
{
OpenFile *fptr;
FILE *f;
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
if (fflush(f) == EOF) rb_sys_fail(0);
@@ -219,7 +217,7 @@ io_flush(io)
}
static VALUE
-io_tell(io)
+rb_io_tell(io)
VALUE io;
{
OpenFile *fptr;
@@ -229,11 +227,11 @@ io_tell(io)
pos = ftell(fptr->f);
if (ferror(fptr->f) != 0) rb_sys_fail(fptr->path);
- return int2inum(pos);
+ return rb_int2inum(pos);
}
static VALUE
-io_seek(io, offset, ptrname)
+rb_io_seek(io, offset, ptrname)
VALUE io, offset, ptrname;
{
OpenFile *fptr;
@@ -248,7 +246,7 @@ io_seek(io, offset, ptrname)
}
static VALUE
-io_set_pos(io, offset)
+rb_io_set_pos(io, offset)
VALUE io, offset;
{
OpenFile *fptr;
@@ -263,7 +261,7 @@ io_set_pos(io, offset)
}
static VALUE
-io_rewind(io)
+rb_io_rewind(io)
VALUE io;
{
OpenFile *fptr;
@@ -276,19 +274,19 @@ io_rewind(io)
}
static VALUE
-io_eof(io)
+rb_io_eof(io)
VALUE io;
{
OpenFile *fptr;
int ch;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
- if (READ_DATA_PENDING(fptr->f)) return FALSE;
+ if (READ_DATA_PENDING(fptr->f)) return Qfalse;
#if 0
- if (feof(fptr->f)) return TRUE;
- return FALSE;
+ if (feof(fptr->f)) return Qtrue;
+ return Qfalse;
#else
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -297,24 +295,24 @@ io_eof(io)
if (ch != EOF) {
(void)ungetc(ch, fptr->f);
- return FALSE;
+ return Qfalse;
}
- return TRUE;
+ return Qtrue;
#endif
}
static VALUE
-io_sync(io)
+rb_io_sync(io)
VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- return (fptr->mode & FMODE_SYNC) ? TRUE : FALSE;
+ return (fptr->mode & FMODE_SYNC) ? Qtrue : Qfalse;
}
static VALUE
-io_set_sync(io, mode)
+rb_io_set_sync(io, mode)
VALUE io, mode;
{
OpenFile *fptr;
@@ -330,7 +328,7 @@ io_set_sync(io, mode)
}
static VALUE
-io_fileno(io)
+rb_io_fileno(io)
VALUE io;
{
OpenFile *fptr;
@@ -342,7 +340,7 @@ io_fileno(io)
}
static VALUE
-io_to_io(io)
+rb_io_to_io(io)
VALUE io;
{
return io;
@@ -368,7 +366,7 @@ read_all(port)
int n;
GetOpenFile(port, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
#ifdef __BEOS__
if (fstat(fileno(fptr->f), &st) == 0 && S_ISREG(st.st_mode)
@@ -384,7 +382,7 @@ read_all(port)
}
}
}
- str = str_new(0, siz);
+ str = rb_str_new(0, siz);
for (;;) {
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -397,15 +395,15 @@ read_all(port)
bytes += n;
if (bytes < siz) break;
siz += BUFSIZ;
- str_resize(str, siz);
+ rb_str_resize(str, siz);
}
if (bytes == 0) return Qnil;
- if (bytes != siz) str_resize(str, bytes);
- return str_taint(str);
+ if (bytes != siz) rb_str_resize(str, bytes);
+ return rb_str_taint(str);
}
static VALUE
-io_read(argc, argv, io)
+rb_io_read(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -420,9 +418,9 @@ io_read(argc, argv, io)
len = NUM2INT(length);
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
- str = str_new(0, len);
+ str = rb_str_new(0, len);
READ_CHECK(fptr->f);
TRAP_BEG;
@@ -435,11 +433,11 @@ io_read(argc, argv, io)
RSTRING(str)->len = n;
RSTRING(str)->ptr[n] = '\0';
- return str_taint(str);
+ return rb_str_taint(str);
}
VALUE
-io_gets_method(argc, argv, io)
+rb_io_gets_method(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -453,7 +451,7 @@ io_gets_method(argc, argv, io)
VALUE rs;
if (argc == 0) {
- rs = RS;
+ rs = rb_rs;
}
else {
rb_scan_args(argc, argv, "1", &rs);
@@ -472,7 +470,7 @@ io_gets_method(argc, argv, io)
rspara = 1;
}
else if (rslen == 1 && RSTRING(rs)->ptr[0] == '\n') {
- return io_gets(io);
+ return rb_io_gets(io);
}
else {
rsptr = RSTRING(rs)->ptr;
@@ -480,7 +478,7 @@ io_gets_method(argc, argv, io)
}
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
if (rspara) {
@@ -541,9 +539,9 @@ io_gets_method(argc, argv, io)
}
if (append)
- str_cat(str, buf, cnt);
+ rb_str_cat(str, buf, cnt);
else
- str = str_new(buf, cnt);
+ str = rb_str_new(buf, cnt);
if (c != EOF &&
(!rslen ||
@@ -571,15 +569,15 @@ io_gets_method(argc, argv, io)
if (!NIL_P(str)) {
fptr->lineno++;
lineno = INT2FIX(fptr->lineno);
- str_taint(str);
+ rb_str_taint(str);
}
- lastline_set(str);
+ rb_lastline_set(str);
return str;
}
VALUE
-io_gets(io)
+rb_io_gets(io)
VALUE io;
{
OpenFile *fptr;
@@ -592,7 +590,7 @@ io_gets(io)
int append = 0;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
again:
@@ -617,9 +615,9 @@ io_gets(io)
}
if (append)
- str_cat(str, buf, cnt);
+ rb_str_cat(str, buf, cnt);
else
- str = str_new(buf, cnt);
+ str = rb_str_new(buf, cnt);
if (c != EOF && RSTRING(str)->ptr[RSTRING(str)->len-1] != '\n') {
append = 1;
@@ -630,32 +628,32 @@ io_gets(io)
if (!NIL_P(str)) {
fptr->lineno++;
lineno = INT2FIX(fptr->lineno);
- str_taint(str);
+ rb_str_taint(str);
}
- lastline_set(str);
+ rb_lastline_set(str);
return str;
}
static VALUE
-io_lineno(io)
+rb_io_lineno(io)
VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
return INT2NUM(fptr->lineno);
}
static VALUE
-io_set_lineno(io, lineno)
+rb_io_set_lineno(io, lineno)
VALUE io, lineno;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
fptr->lineno = NUM2INT(lineno);
}
@@ -670,50 +668,50 @@ lineno_setter(val, id, var)
}
static VALUE
-io_readline(argc, argv, io)
+rb_io_readline(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
- VALUE line = io_gets_method(argc, argv, io);
+ VALUE line = rb_io_gets_method(argc, argv, io);
if (NIL_P(line)) {
- eof_error();
+ rb_eof_error();
}
return line;
}
static VALUE
-io_readlines(argc, argv, io)
+rb_io_readlines(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
VALUE line, ary;
- ary = ary_new();
- while (!NIL_P(line = io_gets_method(argc, argv, io))) {
- ary_push(ary, line);
+ ary = rb_ary_new();
+ while (!NIL_P(line = rb_io_gets_method(argc, argv, io))) {
+ rb_ary_push(ary, line);
}
return ary;
}
static VALUE
-io_each_line(argc, argv, io)
+rb_io_each_line(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
{
VALUE str;
- while (!NIL_P(str = io_gets_method(argc, argv, io))) {
+ while (!NIL_P(str = rb_io_gets_method(argc, argv, io))) {
rb_yield(str);
}
return Qnil;
}
static VALUE
-io_each_byte(io)
+rb_io_each_byte(io)
VALUE io;
{
OpenFile *fptr;
@@ -721,7 +719,7 @@ io_each_byte(io)
int c;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
for (;;) {
@@ -737,7 +735,7 @@ io_each_byte(io)
}
VALUE
-io_getc(io)
+rb_io_getc(io)
VALUE io;
{
OpenFile *fptr;
@@ -745,7 +743,7 @@ io_getc(io)
int c;
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
f = fptr->f;
READ_CHECK(f);
@@ -761,26 +759,26 @@ io_getc(io)
}
static VALUE
-io_readchar(io)
+rb_io_readchar(io)
VALUE io;
{
- VALUE c = io_getc(io);
+ VALUE c = rb_io_getc(io);
if (NIL_P(c)) {
- eof_error();
+ rb_eof_error();
}
return c;
}
VALUE
-io_ungetc(io, c)
+rb_io_ungetc(io, c)
VALUE io, c;
{
OpenFile *fptr;
Check_Type(c, T_FIXNUM);
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
if (ungetc(FIX2INT(c), fptr->f) == EOF)
rb_sys_fail(fptr->path);
@@ -788,15 +786,15 @@ io_ungetc(io, c)
}
static VALUE
-io_isatty(io)
+rb_io_isatty(io)
VALUE io;
{
OpenFile *fptr;
GetOpenFile(io, fptr);
if (isatty(fileno(fptr->f)) == 0)
- return FALSE;
- return TRUE;
+ return Qfalse;
+ return Qtrue;
}
static void
@@ -816,7 +814,7 @@ fptr_finalize(fptr)
}
static void
-io_fptr_close(fptr)
+rb_io_fptr_close(fptr)
OpenFile *fptr;
{
if (fptr->f == NULL && fptr->f2 == NULL) return;
@@ -831,10 +829,10 @@ io_fptr_close(fptr)
}
void
-io_fptr_finalize(fptr)
+rb_io_fptr_finalize(fptr)
OpenFile *fptr;
{
- io_fptr_close(fptr);
+ rb_io_fptr_close(fptr);
if (fptr->path) {
free(fptr->path);
fptr->path = NULL;
@@ -842,37 +840,30 @@ io_fptr_finalize(fptr)
}
VALUE
-io_close(io)
+rb_io_close(io)
VALUE io;
{
OpenFile *fptr;
+ rb_secure(4);
GetOpenFile(io, fptr);
- io_fptr_close(fptr);
+ rb_io_fptr_close(fptr);
return Qnil;
}
-VALUE
-io_close_method(io)
- VALUE io;
-{
- rb_secure(4);
- return io_close(io);
-}
-
static VALUE
-io_closed(io)
+rb_io_closed(io)
VALUE io;
{
OpenFile *fptr;
fptr = RFILE(io)->fptr;
- return (fptr->f || fptr->f2)?FALSE:TRUE;
+ return (fptr->f || fptr->f2)?Qfalse:Qtrue;
}
static VALUE
-io_syswrite(io, str)
+rb_io_syswrite(io, str)
VALUE io, str;
{
OpenFile *fptr;
@@ -881,14 +872,14 @@ io_syswrite(io, str)
rb_secure(4);
if (TYPE(str) != T_STRING)
- str = obj_as_string(str);
+ str = rb_obj_as_string(str);
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
#ifdef THREAD
- thread_fd_writable(fileno(f));
+ rb_thread_fd_writable(fileno(f));
#endif
n = write(fileno(f), RSTRING(str)->ptr, RSTRING(str)->len);
@@ -898,7 +889,7 @@ io_syswrite(io, str)
}
static VALUE
-io_sysread(io, len)
+rb_io_sysread(io, len)
VALUE io, len;
{
OpenFile *fptr;
@@ -907,27 +898,27 @@ io_sysread(io, len)
ilen = NUM2INT(len);
GetOpenFile(io, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
- str = str_new(0, ilen);
+ str = rb_str_new(0, ilen);
#ifdef THREAD
- thread_wait_fd(fileno(fptr->f));
+ rb_thread_wait_fd(fileno(fptr->f));
#endif
TRAP_BEG;
n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len);
TRAP_END;
if (n == -1) rb_sys_fail(fptr->path);
- if (n == 0) eof_error();
+ if (n == 0) rb_eof_error();
RSTRING(str)->len = n;
RSTRING(str)->ptr[n] = '\0';
- return str_taint(str);
+ return rb_str_taint(str);
}
VALUE
-io_binmode(io)
+rb_io_binmode(io)
VALUE io;
{
#if defined(NT) || defined(DJGPP) || defined(__CYGWIN32__) || defined(__human68k__) || defined(USE_CWGUSI)
@@ -947,9 +938,9 @@ io_binmode(io)
rb_sys_fail(fptr->path);
# else /* USE_CWGUSI */
if (fptr->f)
- fptr->f->mode.binary_io = 1;
+ fptr->f->mode.binrb_ary_io = 1;
if (fptr->f2)
- fptr->f2->mode.binary_io = 1;
+ fptr->f2->mode.binrb_ary_io = 1;
# endif /* USE_CWGUSI */
#endif
@@ -959,7 +950,7 @@ io_binmode(io)
}
int
-io_mode_flags(mode)
+rb_io_mode_flags(mode)
char *mode;
{
int flags = 0;
@@ -975,7 +966,7 @@ io_mode_flags(mode)
flags |= FMODE_WRITABLE;
break;
default:
- ArgError("illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode");
}
if (mode[1] == 'b') {
@@ -1000,7 +991,7 @@ rb_fopen(fname, mode)
f = fopen(fname, mode);
if (f == NULL) {
if (errno == EMFILE || errno == ENFILE) {
- gc_gc();
+ rb_gc();
f = fopen(fname, mode);
}
if (f == NULL) {
@@ -1079,7 +1070,7 @@ pipe_atexit()
while (list) {
tmp = list->next;
- io_fptr_finalize(list->fptr);
+ rb_io_fptr_finalize(list->fptr);
list = tmp;
}
}
@@ -1104,10 +1095,10 @@ pipe_finalize(fptr)
#endif
void
-io_unbuffered(fptr)
+rb_io_unbuffered(fptr)
OpenFile *fptr;
{
- if (fptr->f2 == 0) TypeError("non-writable fptr");
+ if (fptr->f2 == 0) rb_raise(rb_eTypeError, "non-writable fptr");
if (fptr->f != 0) setbuf(fptr->f, NULL);
setbuf(fptr->f2, NULL);
fptr->mode |= FMODE_SYNC;
@@ -1118,7 +1109,7 @@ pipe_open(pname, mode)
char *pname, *mode;
{
#ifndef USE_CWGUSI
- int modef = io_mode_flags(mode);
+ int modef = rb_io_mode_flags(mode);
OpenFile *fptr;
#if defined(NT) || defined(DJGPP) || defined(__human68k__)
@@ -1127,7 +1118,7 @@ pipe_open(pname, mode)
if (f == NULL) rb_sys_fail(pname);
else {
NEWOBJ(port, struct RFile);
- OBJSETUP(port, cIO, T_FILE);
+ OBJSETUP(port, rb_cIO, T_FILE);
MakeOpenFile(port, fptr);
fptr->finalize = pipe_finalize;
fptr->mode = modef;
@@ -1136,9 +1127,9 @@ pipe_open(pname, mode)
if (modef & FMODE_READABLE) fptr->f = f;
if (modef & FMODE_WRITABLE) {
fptr->f2 = f;
- io_unbuffered(fptr);
+ rb_io_unbuffered(fptr);
}
- obj_call_init((VALUE)port);
+ rb_obj_call_init((VALUE)port);
return (VALUE)port;
}
#else
@@ -1175,15 +1166,15 @@ pipe_open(pname, mode)
}
if (doexec) {
- extern char *sourcefile;
- extern int sourceline;
+ extern char *ruby_sourcefile;
+ extern int ruby_sourceline;
int fd;
for (fd = 3; fd < NOFILE; fd++)
close(fd);
rb_proc_exec(pname);
fprintf(stderr, "%s:%d: command not found: %s\n",
- sourcefile, sourceline, pname);
+ ruby_sourcefile, ruby_sourceline, pname);
_exit(127);
}
return Qnil;
@@ -1191,7 +1182,7 @@ pipe_open(pname, mode)
case -1: /* fork failed */
if (errno == EAGAIN) {
#ifdef THREAD
- thread_sleep(1);
+ rb_thread_sleep(1);
#else
sleep(1);
#endif
@@ -1205,7 +1196,7 @@ pipe_open(pname, mode)
if (pid < 0) rb_sys_fail(pname);
else {
NEWOBJ(port, struct RFile);
- OBJSETUP(port, cIO, T_FILE);
+ OBJSETUP(port, rb_cIO, T_FILE);
MakeOpenFile(port, fptr);
fptr->mode = modef;
fptr->mode |= FMODE_SYNC;
@@ -1226,7 +1217,7 @@ pipe_open(pname, mode)
fptr->finalize = pipe_finalize;
pipe_add_fptr(fptr);
#endif
- obj_call_init((VALUE)port);
+ rb_obj_call_init((VALUE)port);
return (VALUE)port;
}
}
@@ -1237,7 +1228,7 @@ pipe_open(pname, mode)
}
static VALUE
-io_s_popen(argc, argv, self)
+rb_io_s_popen(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
@@ -1254,26 +1245,26 @@ io_s_popen(argc, argv, self)
mode = STR2CSTR(pmode);
len = strlen(mode);
if (len == 0 || len > 3)
- ArgError("illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode");
}
Check_SafeStr(pname);
return pipe_open(RSTRING(pname)->ptr, mode);
}
static VALUE
-io_open(fname, mode)
+rb_io_open(fname, mode)
char *fname, *mode;
{
if (fname[0] == '|') {
return pipe_open(fname+1, mode);
}
else {
- return file_open(fname, mode);
+ return rb_file_open(fname, mode);
}
}
static VALUE
-f_open(argc, argv)
+rb_f_open(argc, argv)
int argc;
VALUE *argv;
{
@@ -1292,30 +1283,26 @@ f_open(argc, argv)
mode = STR2CSTR(pmode);
len = strlen(mode);
if (len == 0 || len > 3)
- ArgError("illegal access mode");
+ rb_raise(rb_eArgError, "illegal access mode");
}
- port = io_open(RSTRING(pname)->ptr, mode);
- if (iterator_p()) {
- return rb_ensure(rb_yield, port, io_close, port);
+ port = rb_io_open(RSTRING(pname)->ptr, mode);
+ if (rb_iterator_p()) {
+ return rb_ensure(rb_yield, port, rb_io_close, port);
}
return port;
}
static VALUE
-io_get_io(io)
+rb_io_get_io(io)
VALUE io;
{
return rb_convert_type(io, T_FILE, "IO", "to_io");
}
-#ifndef NT
-extern char *strdup();
-#endif
-
static char*
-io_mode_string(fptr)
+rb_io_mode_string(fptr)
OpenFile *fptr;
{
switch (fptr->mode & FMODE_READWRITE) {
@@ -1330,7 +1317,7 @@ io_mode_string(fptr)
}
VALUE
-io_reopen(io, nfile)
+rb_io_reopen(io, nfile)
VALUE io, nfile;
{
OpenFile *fptr, *orig;
@@ -1338,7 +1325,7 @@ io_reopen(io, nfile)
int fd;
GetOpenFile(io, fptr);
- nfile = io_get_io(nfile);
+ nfile = rb_io_get_io(nfile);
GetOpenFile(nfile, orig);
if (orig->f2) {
@@ -1357,7 +1344,7 @@ io_reopen(io, nfile)
else fptr->path = 0;
fptr->finalize = orig->finalize;
- mode = io_mode_string(fptr);
+ mode = rb_io_mode_string(fptr);
fd = fileno(fptr->f);
if (fileno(fptr->f) < 3) {
/* need to keep stdio */
@@ -1381,7 +1368,7 @@ io_reopen(io, nfile)
}
if (fptr->mode & FMODE_BINMODE) {
- io_binmode(io);
+ rb_io_binmode(io);
}
RBASIC(io)->klass = RBASIC(nfile)->klass;
@@ -1389,7 +1376,7 @@ io_reopen(io, nfile)
}
static VALUE
-io_clone(io)
+rb_io_clone(io)
VALUE io;
{
OpenFile *fptr, *orig;
@@ -1434,25 +1421,25 @@ io_clone(io)
fptr->f = rb_fdopen(fd, "w");
}
if (fptr->mode & FMODE_BINMODE) {
- io_binmode((VALUE)obj);
+ rb_io_binmode((VALUE)obj);
}
return (VALUE)obj;
}
static VALUE
-io_printf(argc, argv, out)
+rb_io_printf(argc, argv, out)
int argc;
VALUE argv[];
VALUE out;
{
- rb_funcall(out, id_write, 1, f_sprintf(argc, argv));
+ rb_funcall(out, id_write, 1, rb_f_sprintf(argc, argv));
return Qnil;
}
static VALUE
-f_printf(argc, argv)
+rb_rb_f_printf(argc, argv)
int argc;
VALUE argv[];
{
@@ -1468,15 +1455,15 @@ f_printf(argc, argv)
argc--;
}
else {
- NameError("output must responds to `write'");
+ rb_raise(rb_eNameError, "output must responds to `write'");
}
- rb_funcall(out, id_write, 1, f_sprintf(argc, argv));
+ rb_funcall(out, id_write, 1, rb_f_sprintf(argc, argv));
return Qnil;
}
static VALUE
-io_print(argc, argv, out)
+rb_io_print(argc, argv, out)
int argc;
VALUE *argv;
VALUE out;
@@ -1487,48 +1474,48 @@ io_print(argc, argv, out)
/* if no argument given, print `$_' */
if (argc == 0) {
argc = 1;
- line = lastline_get();
+ line = rb_lastline_get();
argv = &line;
}
for (i=0; i<argc; i++) {
- if (!NIL_P(OFS) && i>0) {
- io_write(out, OFS);
+ if (!NIL_P(rb_output_fs) && i>0) {
+ rb_io_write(out, rb_output_fs);
}
switch (TYPE(argv[i])) {
case T_NIL:
- io_write(out, str_new2("nil"));
+ rb_io_write(out, rb_str_new2("nil"));
break;
case T_ARRAY:
for (j=0; j<RARRAY(argv[i])->len; j++) {
- if (!NIL_P(OFS) && j>0) {
- io_write(out, OFS);
+ if (!NIL_P(rb_output_fs) && j>0) {
+ rb_io_write(out, rb_output_fs);
}
- io_write(out, RARRAY(argv[i])->ptr[j]);
+ rb_io_write(out, RARRAY(argv[i])->ptr[j]);
}
break;
default:
- io_write(out, argv[i]);
+ rb_io_write(out, argv[i]);
break;
}
}
- if (!NIL_P(ORS)) {
- io_write(out, ORS);
+ if (!NIL_P(rb_output_rs)) {
+ rb_io_write(out, rb_output_rs);
}
return Qnil;
}
static VALUE
-f_print(argc, argv)
+rb_f_print(argc, argv)
int argc;
VALUE *argv;
{
- io_print(argc, argv, rb_defout);
+ rb_io_print(argc, argv, rb_defout);
return Qnil;
}
static VALUE
-io_putc(io, ch)
+rb_io_putc(io, ch)
VALUE io, ch;
{
OpenFile *fptr;
@@ -1537,7 +1524,7 @@ io_putc(io, ch)
rb_secure(4);
GetOpenFile(io, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
@@ -1550,14 +1537,14 @@ io_putc(io, ch)
}
static VALUE
-f_putc(recv, ch)
+rb_f_putc(recv, ch)
VALUE recv, ch;
{
- return io_putc(rb_defout, ch);
+ return rb_io_putc(rb_defout, ch);
}
static VALUE
-io_puts(argc, argv, out)
+rb_io_puts(argc, argv, out)
int argc;
VALUE *argv;
VALUE out;
@@ -1567,27 +1554,27 @@ io_puts(argc, argv, out)
/* if no argument given, print newline. */
if (argc == 0) {
- io_write(out, RS_default);
+ rb_io_write(out, rb_default_rs);
return Qnil;
}
for (i=0; i<argc; i++) {
switch (TYPE(argv[i])) {
case T_NIL:
- line = str_new2("nil");
+ line = rb_str_new2("nil");
break;
case T_ARRAY:
for (j=0; j<RARRAY(argv[i])->len; j++) {
- io_puts(1, &RARRAY(argv[i])->ptr[j], out);
+ rb_io_puts(1, &RARRAY(argv[i])->ptr[j], out);
}
continue;
default:
line = argv[i];
break;
}
- line = obj_as_string(line);
- io_write(out, line);
+ line = rb_obj_as_string(line);
+ rb_io_write(out, line);
if (RSTRING(line)->ptr[RSTRING(line)->len-1] != '\n') {
- io_write(out, RS_default);
+ rb_io_write(out, rb_default_rs);
}
}
@@ -1595,11 +1582,11 @@ io_puts(argc, argv, out)
}
static VALUE
-f_puts(argc, argv)
+rb_f_puts(argc, argv)
int argc;
VALUE *argv;
{
- io_puts(argc, argv, rb_defout);
+ rb_io_puts(argc, argv, rb_defout);
return Qnil;
}
@@ -1607,12 +1594,12 @@ void
rb_p(obj) /* for debug print within C code */
VALUE obj;
{
- io_write(rb_defout, rb_inspect(obj));
- io_write(rb_defout, RS_default);
+ rb_io_write(rb_defout, rb_inspect(obj));
+ rb_io_write(rb_defout, rb_default_rs);
}
static VALUE
-f_p(argc, argv)
+rb_f_p(argc, argv)
int argc;
VALUE *argv;
{
@@ -1625,7 +1612,7 @@ f_p(argc, argv)
}
static VALUE
-obj_display(argc, argv, self)
+rb_obj_display(argc, argv, self)
int argc;
VALUE *argv;
VALUE self;
@@ -1636,28 +1623,28 @@ obj_display(argc, argv, self)
out = rb_defout;
}
- io_write(out, self);
+ rb_io_write(out, self);
return Qnil;
}
static void
-io_defset(val, id)
+rb_io_defset(val, id)
VALUE val;
ID id;
{
if (TYPE(val) == T_STRING) {
- val = io_open(RSTRING(val)->ptr, "w");
+ val = rb_io_open(RSTRING(val)->ptr, "w");
}
if (!rb_respond_to(val, id_write)) {
- TypeError("$< must have write method, %s given",
- rb_class2name(CLASS_OF(val)));
+ rb_raise(rb_eTypeError, "$< must have write method, %s given",
+ rb_class2name(CLASS_OF(val)));
}
rb_defout = val;
}
static void
-io_stdio_set(val, id, var)
+rb_io_stdio_set(val, id, var)
VALUE val;
ID id;
VALUE *var;
@@ -1666,18 +1653,18 @@ io_stdio_set(val, id, var)
int fd;
if (TYPE(val) != T_FILE) {
- TypeError("%s must be IO object", rb_id2name(id));
+ rb_raise(rb_eTypeError, "%s must be IO object", rb_id2name(id));
}
GetOpenFile(*var, fptr);
fd = fileno(fptr->f);
GetOpenFile(val, fptr);
if (fd == 0) {
- io_readable(fptr);
+ rb_io_check_readable(fptr);
}
else {
- io_writable(fptr);
+ rb_io_check_writable(fptr);
}
- io_reopen(*var, val);
+ rb_io_reopen(*var, val);
}
static VALUE
@@ -1693,13 +1680,13 @@ prep_stdio(f, mode, klass)
MakeOpenFile(io, fp);
fp->f = f;
fp->mode = mode;
- obj_call_init((VALUE)io);
+ rb_obj_call_init((VALUE)io);
return (VALUE)io;
}
static VALUE
-io_s_new(argc, argv, klass)
+rb_io_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
@@ -1711,7 +1698,7 @@ io_s_new(argc, argv, klass)
Check_SafeStr(mode);
m = RSTRING(mode)->ptr;
}
- return prep_stdio(rb_fdopen(NUM2INT(fnum), m), io_mode_flags(m), klass);
+ return prep_stdio(rb_fdopen(NUM2INT(fnum), m), rb_io_mode_flags(m), klass);
}
static int
@@ -1736,32 +1723,33 @@ next_argv()
if (next_p == 1) {
next_p = 0;
if (RARRAY(rb_argv)->len > 0) {
- filename = ary_shift(rb_argv);
+ filename = rb_ary_shift(rb_argv);
fn = RSTRING(filename)->ptr;
if (RSTRING(filename)->len == 1 && fn[0] == '-') {
file = rb_stdin;
- if (inplace) {
+ if (ruby_inplace_mode) {
rb_defout = rb_stdout;
}
}
else {
FILE *fr = rb_fopen(fn, "r");
- if (inplace) {
+ if (ruby_inplace_mode) {
struct stat st, st2;
VALUE str;
FILE *fw;
if (TYPE(rb_defout) == T_FILE && rb_defout != rb_stdout) {
- io_close(rb_defout);
+ rb_io_close(rb_defout);
}
fstat(fileno(fr), &st);
- if (*inplace) {
- str = str_new2(fn);
+ if (*ruby_inplace_mode) {
+ str = rb_str_new2(fn);
#if defined(MSDOS) || defined(__CYGWIN32__) || defined(NT)
- add_suffix(str, inplace);
+ add_suffix(str, ruby_inplace_mode);
#else
- str_cat(str, inplace, strlen(inplace));
+ rb_str_cat(str, ruby_inplace_mode,
+ strlen(ruby_inplace_mode));
#endif
#if defined(MSDOS) || defined(__BOW__) || defined(__CYGWIN32__) || defined(NT) || defined(__human68k__)
(void)fclose(fr);
@@ -1770,8 +1758,8 @@ next_argv()
fr = rb_fopen(RSTRING(str)->ptr, "r");
#else
if (rename(fn, RSTRING(str)->ptr) < 0) {
- Warn("Can't rename %s to %s: %s, skipping file",
- fn, RSTRING(str)->ptr, strerror(errno));
+ rb_warn("Can't rename %s to %s: %s, skipping file",
+ fn, RSTRING(str)->ptr, strerror(errno));
fclose(fr);
goto retry;
}
@@ -1780,13 +1768,13 @@ next_argv()
else {
#if !defined(MSDOS) && !defined(__BOW__) && !defined(__CYGWIN32__) && !defined(NT) && !defined(__human68k__)
if (unlink(fn) < 0) {
- Warn("Can't remove %s: %s, skipping file",
- fn, strerror(errno));
+ rb_warn("Can't remove %s: %s, skipping file",
+ fn, strerror(errno));
fclose(fr);
goto retry;
}
#else
- Fatal("Can't do inplace edit without backup");
+ rb_fatal("Can't do inplace edit without backup");
#endif
}
fw = rb_fopen(fn, "w");
@@ -1798,21 +1786,21 @@ next_argv()
fchown(fileno(fw), st.st_uid, st.st_gid);
}
#endif
- rb_defout = prep_stdio(fw, FMODE_WRITABLE, cFile);
+ rb_defout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile);
}
- file = prep_stdio(fr, FMODE_READABLE, cFile);
+ file = prep_stdio(fr, FMODE_READABLE, rb_cFile);
}
}
else {
init_p = 0;
- return FALSE;
+ return Qfalse;
}
}
- return TRUE;
+ return Qtrue;
}
static VALUE
-f_gets_method(argc, argv)
+rb_f_gets_method(argc, argv)
int argc;
VALUE *argv;
{
@@ -1820,9 +1808,9 @@ f_gets_method(argc, argv)
retry:
if (!next_argv()) return Qnil;
- line = io_gets_method(argc, argv, file);
+ line = rb_io_gets_method(argc, argv, file);
if (NIL_P(line) && next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
goto retry;
}
@@ -1833,109 +1821,122 @@ f_gets_method(argc, argv)
}
VALUE
-f_gets()
+rb_f_gets()
{
- return f_gets_method(0,0);
+ VALUE line;
+
+ retry:
+ if (!next_argv()) return Qnil;
+ line = rb_io_gets(file);
+ if (NIL_P(line) && next_p != -1) {
+ rb_io_close(file);
+ next_p = 1;
+ goto retry;
+ }
+ gets_lineno++;
+ lineno = INT2FIX(gets_lineno);
+
+ return line;
}
static VALUE
-f_readline(argc, argv)
+rb_f_readline(argc, argv)
int argc;
VALUE *argv;
{
- VALUE line = f_gets_method(argc, argv);
+ VALUE line = rb_f_gets_method(argc, argv);
if (NIL_P(line)) {
- eof_error();
+ rb_eof_error();
}
return line;
}
static VALUE
-f_tell()
+rb_f_tell()
{
- return io_tell(file);
+ return rb_io_tell(file);
}
static VALUE
-f_seek(self, offset, ptrname)
+rb_f_seek(self, offset, ptrname)
VALUE self, offset, ptrname;
{
if (!next_argv()) {
- ArgError("no stream to seek");
+ rb_raise(rb_eArgError, "no stream to seek");
}
- return io_seek(file, offset, ptrname);
+ return rb_io_seek(file, offset, ptrname);
}
static VALUE
-f_set_pos(self, offset)
+rb_f_set_pos(self, offset)
VALUE self, offset;
{
if (!next_argv()) {
- ArgError("no stream to pos");
+ rb_raise(rb_eArgError, "no stream to pos");
}
- return io_set_pos(file, offset);
+ return rb_io_set_pos(file, offset);
}
static VALUE
-f_rewind()
+rb_f_rewind()
{
- return io_rewind(file);
+ return rb_io_rewind(file);
}
static VALUE
-f_eof()
+rb_f_eof()
{
if (init_p == 0 && !next_argv())
- return TRUE;
- if (io_eof(file)) {
+ return Qtrue;
+ if (rb_io_eof(file)) {
next_p = 1;
- return TRUE;
+ return Qtrue;
}
- return FALSE;
+ return Qfalse;
}
static VALUE
-f_getc()
+rb_f_getc()
{
- return io_getc(rb_stdin);
+ return rb_io_getc(rb_stdin);
}
static VALUE
-f_ungetc(self, c)
+rb_f_ungetc(self, c)
VALUE self, c;
{
if (!next_argv()) {
- ArgError("no stream to ungetc");
+ rb_raise(rb_eArgError, "no stream to ungetc");
}
- return io_ungetc(file, c);
+ return rb_io_ungetc(file, c);
}
static VALUE
-f_readchar()
+rb_f_readchar()
{
- VALUE c = f_getc();
+ VALUE c = rb_f_getc();
if (NIL_P(c)) {
- eof_error();
+ rb_eof_error();
}
return c;
}
static VALUE
-f_readlines(argc, argv)
+rb_f_readlines(argc, argv)
int argc;
VALUE *argv;
{
VALUE line, ary;
- ary = ary_new();
- while (!NIL_P(line = f_gets_method(argc, argv))) {
- ary_push(ary, line);
+ ary = rb_ary_new();
+ while (!NIL_P(line = rb_f_gets_method(argc, argv))) {
+ rb_ary_push(ary, line);
}
return ary;
@@ -1948,13 +1949,13 @@ rb_str_setter(val, id, var)
VALUE *var;
{
if (!NIL_P(val) && TYPE(val) != T_STRING) {
- TypeError("value of %s must be String", rb_id2name(id));
+ rb_raise(rb_eTypeError, "value of %s must be String", rb_id2name(id));
}
*var = val;
}
static VALUE
-f_backquote(obj, str)
+rb_f_backquote(obj, str)
VALUE obj, str;
{
VALUE port, result;
@@ -1963,9 +1964,9 @@ f_backquote(obj, str)
port = pipe_open(RSTRING(str)->ptr, "r");
result = read_all(port);
- io_close(port);
+ rb_io_close(port);
- if (NIL_P(result)) return str_new(0,0);
+ if (NIL_P(result)) return rb_str_new(0,0);
return result;
}
@@ -1977,7 +1978,7 @@ f_backquote(obj, str)
#endif
static VALUE
-f_select(argc, argv, obj)
+rb_f_select(argc, argv, obj)
int argc;
VALUE *argv;
VALUE obj;
@@ -1996,7 +1997,7 @@ f_select(argc, argv, obj)
tp = NULL;
}
else {
- timerec = time_timeval(timeout);
+ timerec = rb_time_timeval(timeout);
tp = &timerec;
}
@@ -2006,7 +2007,7 @@ f_select(argc, argv, obj)
rp = &rset;
FD_ZERO(rp);
for (i=0; i<RARRAY(read)->len; i++) {
- VALUE io = io_get_io(RARRAY(read)->ptr[i]);
+ VALUE io = rb_io_get_io(RARRAY(read)->ptr[i]);
GetOpenFile(io, fptr);
FD_SET(fileno(fptr->f), rp);
@@ -2029,7 +2030,7 @@ f_select(argc, argv, obj)
wp = &wset;
FD_ZERO(wp);
for (i=0; i<RARRAY(write)->len; i++) {
- VALUE io = io_get_io(RARRAY(write)->ptr[i]);
+ VALUE io = rb_io_get_io(RARRAY(write)->ptr[i]);
GetOpenFile(io, fptr);
FD_SET(fileno(fptr->f), wp);
@@ -2048,7 +2049,7 @@ f_select(argc, argv, obj)
ep = &eset;
FD_ZERO(ep);
for (i=0; i<RARRAY(except)->len; i++) {
- VALUE io = io_get_io(RARRAY(except)->ptr[i]);
+ VALUE io = rb_io_get_io(RARRAY(except)->ptr[i]);
GetOpenFile(io, fptr);
FD_SET(fileno(fptr->f), ep);
@@ -2065,7 +2066,7 @@ f_select(argc, argv, obj)
max++;
#ifdef THREAD
- n = thread_select(max, rp, wp, ep, tp);
+ n = rb_thread_select(max, rp, wp, ep, tp);
if (n < 0) {
rb_sys_fail(0);
}
@@ -2084,10 +2085,10 @@ f_select(argc, argv, obj)
#endif
if (!pending && n == 0) return Qnil; /* returns nil on timeout */
- res = ary_new2(3);
- ary_push(res, rp?ary_new():ary_new2(0));
- ary_push(res, wp?ary_new():ary_new2(0));
- ary_push(res, ep?ary_new():ary_new2(0));
+ res = rb_ary_new2(3);
+ rb_ary_push(res, rp?rb_ary_new():rb_ary_new2(0));
+ rb_ary_push(res, wp?rb_ary_new():rb_ary_new2(0));
+ rb_ary_push(res, ep?rb_ary_new():rb_ary_new2(0));
if (interrupt_flag == 0) {
if (rp) {
@@ -2096,7 +2097,7 @@ f_select(argc, argv, obj)
GetOpenFile(RARRAY(read)->ptr[i], fptr);
if (FD_ISSET(fileno(fptr->f), rp)
|| FD_ISSET(fileno(fptr->f), &pset)) {
- ary_push(list, RARRAY(read)->ptr[i]);
+ rb_ary_push(list, RARRAY(read)->ptr[i]);
}
}
}
@@ -2106,10 +2107,10 @@ f_select(argc, argv, obj)
for (i=0; i< RARRAY(write)->len; i++) {
GetOpenFile(RARRAY(write)->ptr[i], fptr);
if (FD_ISSET(fileno(fptr->f), wp)) {
- ary_push(list, RARRAY(write)->ptr[i]);
+ rb_ary_push(list, RARRAY(write)->ptr[i]);
}
else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), wp)) {
- ary_push(list, RARRAY(write)->ptr[i]);
+ rb_ary_push(list, RARRAY(write)->ptr[i]);
}
}
}
@@ -2119,10 +2120,10 @@ f_select(argc, argv, obj)
for (i=0; i< RARRAY(except)->len; i++) {
GetOpenFile(RARRAY(except)->ptr[i], fptr);
if (FD_ISSET(fileno(fptr->f), ep)) {
- ary_push(list, RARRAY(except)->ptr[i]);
+ rb_ary_push(list, RARRAY(except)->ptr[i]);
}
else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), ep)) {
- ary_push(list, RARRAY(except)->ptr[i]);
+ rb_ary_push(list, RARRAY(except)->ptr[i]);
}
}
}
@@ -2132,7 +2133,7 @@ f_select(argc, argv, obj)
}
static VALUE
-io_ctl(io, req, arg, io_p)
+rb_io_ctl(io, req, arg, io_p)
VALUE io, req, arg;
int io_p;
{
@@ -2147,13 +2148,13 @@ io_ctl(io, req, arg, io_p)
rb_secure(2);
GetOpenFile(io, fptr);
- if (NIL_P(arg) || arg == FALSE) {
+ if (NIL_P(arg) || arg == Qfalse) {
narg = 0;
}
else if (FIXNUM_P(arg)) {
narg = FIX2INT(arg);
}
- else if (arg == TRUE) {
+ else if (arg == Qtrue) {
narg = 1;
}
else {
@@ -2169,13 +2170,13 @@ io_ctl(io, req, arg, io_p)
#else
len = 256; /* otherwise guess at what's safe */
#endif
- str_modify(arg);
+ rb_str_modify(arg);
if (len <= RSTRING(arg)->len) {
len = RSTRING(arg)->len;
}
if (RSTRING(arg)->len < len) {
- str_resize(arg, len+1);
+ rb_str_resize(arg, len+1);
}
RSTRING(arg)->ptr[len] = 17; /* a little sanity check here */
narg = (long)RSTRING(arg)->ptr;
@@ -2190,7 +2191,7 @@ io_ctl(io, req, arg, io_p)
# endif
TRAP_END;
#else
- if (!io_p) {
+ if (!rb_io_p) {
rb_notimplement();
}
TRAP_BEG;
@@ -2199,7 +2200,7 @@ io_ctl(io, req, arg, io_p)
#endif
if (retval < 0) rb_sys_fail(fptr->path);
if (TYPE(arg) == T_STRING && RSTRING(arg)->ptr[len] != 17) {
- ArgError("return value overflowed string");
+ rb_raise(rb_eArgError, "return value overflowed string");
}
return INT2NUM(retval);
#else
@@ -2208,7 +2209,7 @@ io_ctl(io, req, arg, io_p)
}
static VALUE
-io_ioctl(argc, argv, io)
+rb_io_ioctl(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2216,11 +2217,11 @@ io_ioctl(argc, argv, io)
VALUE req, arg;
rb_scan_args(argc, argv, "11", &req, &arg);
- return io_ctl(io, req, arg, 1);
+ return rb_io_ctl(io, req, arg, 1);
}
static VALUE
-io_fcntl(argc, argv, io)
+rb_io_fcntl(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2229,14 +2230,14 @@ io_fcntl(argc, argv, io)
VALUE req, arg;
rb_scan_args(argc, argv, "11", &req, &arg);
- return io_ctl(io, req, arg, 0);
+ return rb_io_ctl(io, req, arg, 0);
#else
rb_notimplement();
#endif
}
static VALUE
-f_syscall(argc, argv)
+rb_f_syscall(argc, argv)
int argc;
VALUE *argv;
{
@@ -2257,7 +2258,7 @@ f_syscall(argc, argv)
rb_secure(2);
if (argc == 0)
- ArgError("too few arguments for syscall");
+ rb_raise(rb_eArgError, "too few arguments for syscall");
arg[0] = NUM2INT(argv[0]); argv++;
while (items--) {
if (FIXNUM_P(*argv)) {
@@ -2265,7 +2266,7 @@ f_syscall(argc, argv)
}
else {
Check_Type(*argv, T_STRING);
- str_modify(*argv);
+ rb_str_modify(*argv);
arg[i] = (unsigned long)RSTRING(*argv)->ptr; argv++;
}
i++;
@@ -2333,7 +2334,7 @@ f_syscall(argc, argv)
}
static VALUE
-io_s_pipe()
+rb_io_s_pipe()
{
#ifndef __human68k__
int pipes[2];
@@ -2346,12 +2347,12 @@ io_s_pipe()
#endif
rb_sys_fail(0);
- r = prep_stdio(fdopen(pipes[0], "r"), FMODE_READABLE, cIO);
- w = prep_stdio(fdopen(pipes[1], "w"), FMODE_WRITABLE, cIO);
+ r = prep_stdio(fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO);
+ w = prep_stdio(fdopen(pipes[1], "w"), FMODE_WRITABLE, rb_cIO);
- ary = ary_new2(2);
- ary_push(ary, r);
- ary_push(ary, w);
+ ary = rb_ary_new2(2);
+ rb_ary_push(ary, r);
+ rb_ary_push(ary, w);
return ary;
#else
@@ -2366,19 +2367,19 @@ struct foreach_arg {
};
static VALUE
-io_foreach_line(arg)
+rb_io_foreach_line(arg)
struct foreach_arg *arg;
{
VALUE str;
- while (!NIL_P(str = io_gets_method(arg->argc, &arg->sep, arg->io))) {
+ while (!NIL_P(str = rb_io_gets_method(arg->argc, &arg->sep, arg->io))) {
rb_yield(str);
}
return Qnil;
}
static VALUE
-io_s_foreach(argc, argv, io)
+rb_io_s_foreach(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2390,26 +2391,26 @@ io_s_foreach(argc, argv, io)
Check_SafeStr(fname);
arg.argc = argc - 1;
- arg.io = io_open(RSTRING(fname)->ptr, "r");
- return rb_ensure(io_foreach_line, (VALUE)&arg, io_close, arg.io);
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ return rb_ensure(rb_io_foreach_line, (VALUE)&arg, rb_io_close, arg.io);
}
static VALUE
-io_readline_line(arg)
+rb_io_readline_line(arg)
struct foreach_arg *arg;
{
VALUE line, ary;
- ary = ary_new();
- while (!NIL_P(line = io_gets_method(arg->argc, &arg->sep, arg->io))) {
- ary_push(ary, line);
+ ary = rb_ary_new();
+ while (!NIL_P(line = rb_io_gets_method(arg->argc, &arg->sep, arg->io))) {
+ rb_ary_push(ary, line);
}
return ary;
}
static VALUE
-io_s_readlines(argc, argv, io)
+rb_io_s_readlines(argc, argv, io)
int argc;
VALUE *argv;
VALUE io;
@@ -2421,14 +2422,14 @@ io_s_readlines(argc, argv, io)
Check_SafeStr(fname);
arg.argc = argc - 1;
- arg.io = io_open(RSTRING(fname)->ptr, "r");
- return rb_ensure(io_readline_line, (VALUE)&arg, io_close, arg.io);
+ arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ return rb_ensure(rb_io_readline_line, (VALUE)&arg, rb_io_close, arg.io);
}
static VALUE
arg_fileno()
{
- return io_fileno(file);
+ return rb_io_fileno(file);
}
static VALUE
@@ -2450,15 +2451,15 @@ arg_read(argc, argv)
retry:
if (!next_argv()) return str;
- tmp = io_read(argc, argv, file);
+ tmp = rb_io_read(argc, argv, file);
if (NIL_P(tmp) && next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
goto retry;
}
if (NIL_P(tmp)) return str;
else if (NIL_P(str)) str = tmp;
- else str_cat(str, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
+ else rb_str_cat(str, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
if (argc == 0) {
goto retry;
}
@@ -2478,9 +2479,9 @@ arg_getc()
retry:
if (!next_argv()) return Qnil;
- byte = io_getc(file);
+ byte = rb_io_getc(file);
if (NIL_P(byte) && next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
goto retry;
}
@@ -2491,10 +2492,10 @@ arg_getc()
static VALUE
arg_readchar()
{
- VALUE c = io_getc(file);
+ VALUE c = rb_io_getc(file);
if (NIL_P(c)) {
- eof_error();
+ rb_eof_error();
}
return c;
}
@@ -2506,7 +2507,7 @@ arg_each_line(argc, argv)
{
VALUE str;
- while (RTEST(str = f_gets_method(argc, argv))) {
+ while (RTEST(str = rb_f_gets_method(argc, argv))) {
rb_yield(str);
}
return Qnil;
@@ -2539,7 +2540,7 @@ static VALUE
arg_skip()
{
if (next_p != -1) {
- io_close(file);
+ rb_io_close(file);
next_p = 1;
}
return argf;
@@ -2548,7 +2549,7 @@ arg_skip()
static VALUE
arg_close()
{
- io_close(file);
+ rb_io_close(file);
if (next_p != -1) {
next_p = 1;
}
@@ -2559,14 +2560,14 @@ arg_close()
static VALUE
arg_closed()
{
- return io_closed(file);
+ return rb_io_closed(file);
}
static VALUE
opt_i_get()
{
- if (!inplace) return Qnil;
- return str_new2(inplace);
+ if (!ruby_inplace_mode) return Qnil;
+ return rb_str_new2(ruby_inplace_mode);
}
static void
@@ -2574,140 +2575,140 @@ opt_i_set(val)
VALUE val;
{
if (!RTEST(val)) {
- inplace = 0;
+ ruby_inplace_mode = 0;
return;
}
- inplace = STR2CSTR(val);
+ ruby_inplace_mode = STR2CSTR(val);
}
void
Init_IO()
{
- eIOError = rb_define_class("IOError", eStandardError);
- eEOFError = rb_define_class("EOFError", eIOError);
+ rb_eIOError = rb_define_class("IOError", rb_eStandardError);
+ rb_eEOFError = rb_define_class("EOFError", rb_eIOError);
id_write = rb_intern("write");
- rb_define_global_function("syscall", f_syscall, -1);
-
- rb_define_global_function("open", f_open, -1);
- rb_define_global_function("printf", f_printf, -1);
- rb_define_global_function("print", f_print, -1);
- rb_define_global_function("putc", f_putc, 1);
- rb_define_global_function("puts", f_puts, -1);
- rb_define_global_function("gets", f_gets_method, -1);
- rb_define_global_function("readline", f_readline, -1);
- rb_define_global_function("tell", f_tell, 0);
- rb_define_global_function("seek", f_seek, 2);
- rb_define_global_function("rewind", f_rewind, 0);
- rb_define_global_function("eof", f_eof, 0);
- rb_define_global_function("eof?", f_eof, 0);
- rb_define_global_function("getc", f_getc, 0);
- rb_define_global_function("readchar", f_readchar, 0);
- rb_define_global_function("select", f_select, -1);
- rb_define_global_function("ungetc", f_ungetc, 1);
-
- rb_define_global_function("readlines", f_readlines, -1);
-
- rb_define_global_function("`", f_backquote, 1);
- rb_define_global_function("pipe", io_s_pipe, 0);
-
- rb_define_global_function("p", f_p, -1);
- rb_define_method(mKernel, "display", obj_display, -1);
-
- cIO = rb_define_class("IO", cObject);
- rb_include_module(cIO, mEnumerable);
-
- rb_define_singleton_method(cIO, "new", io_s_new, -1);
- rb_define_singleton_method(cIO, "popen", io_s_popen, -1);
- rb_define_singleton_method(cIO, "foreach", io_s_foreach, -1);
- rb_define_singleton_method(cIO, "readlines", io_s_readlines, -1);
- rb_define_singleton_method(cIO, "select", f_select, -1);
-
- FS = OFS = Qnil;
- rb_define_hooked_variable("$;", &FS, 0, rb_str_setter);
- rb_define_hooked_variable("$-F", &FS, 0, rb_str_setter);
- rb_define_hooked_variable("$,", &OFS, 0, rb_str_setter);
-
- RS = RS_default = str_new2("\n"); ORS = Qnil;
- rb_global_variable(&RS_default);
- str_freeze(RS_default); /* avoid modifying RS_default */
- rb_define_hooked_variable("$/", &RS, 0, rb_str_setter);
- rb_define_hooked_variable("$-0", &RS, 0, rb_str_setter);
- rb_define_hooked_variable("$\\", &ORS, 0, rb_str_setter);
+ rb_define_global_function("syscall", rb_f_syscall, -1);
+
+ rb_define_global_function("open", rb_f_open, -1);
+ rb_define_global_function("printf", rb_rb_f_printf, -1);
+ rb_define_global_function("print", rb_f_print, -1);
+ rb_define_global_function("putc", rb_f_putc, 1);
+ rb_define_global_function("puts", rb_f_puts, -1);
+ rb_define_global_function("gets", rb_f_gets_method, -1);
+ rb_define_global_function("readline", rb_f_readline, -1);
+ rb_define_global_function("tell", rb_f_tell, 0);
+ rb_define_global_function("seek", rb_f_seek, 2);
+ rb_define_global_function("rewind", rb_f_rewind, 0);
+ rb_define_global_function("eof", rb_f_eof, 0);
+ rb_define_global_function("eof?", rb_f_eof, 0);
+ rb_define_global_function("getc", rb_f_getc, 0);
+ rb_define_global_function("readchar", rb_f_readchar, 0);
+ rb_define_global_function("select", rb_f_select, -1);
+ rb_define_global_function("ungetc", rb_f_ungetc, 1);
+
+ rb_define_global_function("readlines", rb_f_readlines, -1);
+
+ rb_define_global_function("`", rb_f_backquote, 1);
+ rb_define_global_function("pipe", rb_io_s_pipe, 0);
+
+ rb_define_global_function("p", rb_f_p, -1);
+ rb_define_method(rb_mKernel, "display", rb_obj_display, -1);
+
+ rb_cIO = rb_define_class("IO", rb_cObject);
+ rb_include_module(rb_cIO, rb_mEnumerable);
+
+ rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
+ rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
+ rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
+ rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1);
+ rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
+
+ rb_fs = rb_output_fs = Qnil;
+ rb_define_hooked_variable("$;", &rb_fs, 0, rb_str_setter);
+ rb_define_hooked_variable("$-F", &rb_fs, 0, rb_str_setter);
+ rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_str_setter);
+
+ rb_rs = rb_default_rs = rb_str_new2("\n"); rb_output_rs = Qnil;
+ rb_global_variable(&rb_default_rs);
+ rb_str_freeze(rb_default_rs); /* avoid modifying RS_default */
+ rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
+ rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
+ rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);
rb_define_hooked_variable("$.", &lineno, 0, lineno_setter);
- rb_define_virtual_variable("$_", lastline_get, lastline_set);
-
- rb_define_method(cIO, "clone", io_clone, 0);
- rb_define_method(cIO, "reopen", io_reopen, 1);
-
- rb_define_method(cIO, "print", io_print, -1);
- rb_define_method(cIO, "putc", io_putc, 1);
- rb_define_method(cIO, "puts", io_puts, -1);
- rb_define_method(cIO, "printf", io_printf, -1);
-
- rb_define_method(cIO, "each", io_each_line, -1);
- rb_define_method(cIO, "each_line", io_each_line, -1);
- rb_define_method(cIO, "each_byte", io_each_byte, 0);
-
- rb_define_method(cIO, "syswrite", io_syswrite, 1);
- rb_define_method(cIO, "sysread", io_sysread, 1);
-
- rb_define_method(cIO, "fileno", io_fileno, 0);
- rb_define_alias(cIO, "to_i", "fileno");
- rb_define_method(cIO, "to_io", io_to_io, 0);
-
- rb_define_method(cIO, "sync", io_sync, 0);
- rb_define_method(cIO, "sync=", io_set_sync, 1);
-
- rb_define_method(cIO, "lineno", io_lineno, 0);
- rb_define_method(cIO, "lineno=", io_set_lineno, 1);
-
- rb_define_method(cIO, "readlines", io_readlines, -1);
-
- rb_define_method(cIO, "read", io_read, -1);
- rb_define_method(cIO, "write", io_write, 1);
- rb_define_method(cIO, "gets", io_gets_method, -1);
- rb_define_method(cIO, "readline", io_readline, -1);
- rb_define_method(cIO, "getc", io_getc, 0);
- rb_define_method(cIO, "readchar", io_readchar, 0);
- rb_define_method(cIO, "ungetc",io_ungetc, 1);
- rb_define_method(cIO, "<<", io_addstr, 1);
- rb_define_method(cIO, "flush", io_flush, 0);
- rb_define_method(cIO, "tell", io_tell, 0);
- rb_define_method(cIO, "seek", io_seek, 2);
- rb_define_method(cIO, "rewind", io_rewind, 0);
- rb_define_method(cIO, "pos", io_tell, 0);
- rb_define_method(cIO, "pos=", io_set_pos, 1);
- rb_define_method(cIO, "eof", io_eof, 0);
- rb_define_method(cIO, "eof?", io_eof, 0);
-
- rb_define_method(cIO, "close", io_close_method, 0);
- rb_define_method(cIO, "closed?", io_closed, 0);
-
- rb_define_method(cIO, "isatty", io_isatty, 0);
- rb_define_method(cIO, "tty?", io_isatty, 0);
- rb_define_method(cIO, "binmode", io_binmode, 0);
-
- rb_define_method(cIO, "ioctl", io_ioctl, -1);
- rb_define_method(cIO, "fcntl", io_fcntl, -1);
-
- rb_stdin = prep_stdio(stdin, FMODE_READABLE, cIO);
- rb_define_hooked_variable("$stdin", &rb_stdin, 0, io_stdio_set);
- rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, cIO);
- rb_define_hooked_variable("$stdout", &rb_stdout, 0, io_stdio_set);
- rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, cIO);
- rb_define_hooked_variable("$stderr", &rb_stderr, 0, io_stdio_set);
+ rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
+
+ rb_define_method(rb_cIO, "clone", rb_io_clone, 0);
+ rb_define_method(rb_cIO, "reopen", rb_io_reopen, 1);
+
+ rb_define_method(rb_cIO, "print", rb_io_print, -1);
+ rb_define_method(rb_cIO, "putc", rb_io_putc, 1);
+ rb_define_method(rb_cIO, "puts", rb_io_puts, -1);
+ rb_define_method(rb_cIO, "printf", rb_io_printf, -1);
+
+ rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
+ rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
+ rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
+
+ rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
+ rb_define_method(rb_cIO, "sysread", rb_io_sysread, 1);
+
+ rb_define_method(rb_cIO, "fileno", rb_io_fileno, 0);
+ rb_define_alias(rb_cIO, "to_i", "fileno");
+ rb_define_method(rb_cIO, "to_io", rb_io_to_io, 0);
+
+ rb_define_method(rb_cIO, "sync", rb_io_sync, 0);
+ rb_define_method(rb_cIO, "sync=", rb_io_set_sync, 1);
+
+ rb_define_method(rb_cIO, "lineno", rb_io_lineno, 0);
+ rb_define_method(rb_cIO, "lineno=", rb_io_set_lineno, 1);
+
+ rb_define_method(rb_cIO, "readlines", rb_io_readlines, -1);
+
+ rb_define_method(rb_cIO, "read", rb_io_read, -1);
+ rb_define_method(rb_cIO, "write", rb_io_write, 1);
+ rb_define_method(rb_cIO, "gets", rb_io_gets_method, -1);
+ rb_define_method(rb_cIO, "readline", rb_io_readline, -1);
+ rb_define_method(rb_cIO, "getc", rb_io_getc, 0);
+ rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0);
+ rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
+ rb_define_method(rb_cIO, "<<", rb_io_addstr, 1);
+ rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
+ rb_define_method(rb_cIO, "tell", rb_io_tell, 0);
+ rb_define_method(rb_cIO, "seek", rb_io_seek, 2);
+ rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
+ rb_define_method(rb_cIO, "pos", rb_io_tell, 0);
+ rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
+ rb_define_method(rb_cIO, "eof", rb_io_eof, 0);
+ rb_define_method(rb_cIO, "eof?", rb_io_eof, 0);
+
+ rb_define_method(rb_cIO, "close", rb_io_close, 0);
+ rb_define_method(rb_cIO, "closed?", rb_io_closed, 0);
+
+ rb_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
+ rb_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
+ rb_define_method(rb_cIO, "binmode", rb_io_binmode, 0);
+
+ rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
+ rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
+
+ rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
+ rb_define_hooked_variable("$stdin", &rb_stdin, 0, rb_io_stdio_set);
+ rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO);
+ rb_define_hooked_variable("$stdout", &rb_stdout, 0, rb_io_stdio_set);
+ rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO);
+ rb_define_hooked_variable("$stderr", &rb_stderr, 0, rb_io_stdio_set);
rb_defout = rb_stdout;
- rb_define_hooked_variable("$>", &rb_defout, 0, io_defset);
+ rb_define_hooked_variable("$>", &rb_defout, 0, rb_io_defset);
rb_define_global_const("STDIN", rb_stdin);
rb_define_global_const("STDOUT", rb_stdout);
rb_define_global_const("STDERR", rb_stderr);
- argf = obj_alloc(cObject);
- rb_extend_object(argf, mEnumerable);
+ argf = rb_obj_alloc(rb_cObject);
+ rb_extend_object(argf, rb_mEnumerable);
rb_define_readonly_variable("$<", &argf);
rb_define_global_const("ARGF", argf);
@@ -2720,20 +2721,20 @@ Init_IO()
rb_define_singleton_method(argf, "each_byte", arg_each_byte, 0);
rb_define_singleton_method(argf, "read", arg_read, -1);
- rb_define_singleton_method(argf, "readlines", f_readlines, -1);
- rb_define_singleton_method(argf, "to_a", f_readlines, -1);
- rb_define_singleton_method(argf, "gets", f_gets_method, -1);
- rb_define_singleton_method(argf, "readline", f_readline, -1);
+ rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
+ rb_define_singleton_method(argf, "to_a", rb_f_readlines, -1);
+ rb_define_singleton_method(argf, "gets", rb_f_gets_method, -1);
+ rb_define_singleton_method(argf, "readline", rb_f_readline, -1);
rb_define_singleton_method(argf, "getc", arg_getc, 0);
rb_define_singleton_method(argf, "readchar", arg_readchar, 0);
- rb_define_singleton_method(argf, "tell", f_tell, 0);
- rb_define_singleton_method(argf, "seek", f_seek, 2);
- rb_define_singleton_method(argf, "rewind", f_rewind, 0);
- rb_define_singleton_method(argf, "pos", f_tell, 0);
- rb_define_singleton_method(argf, "pos=", f_set_pos, 1);
- rb_define_singleton_method(argf, "eof", f_eof, 0);
- rb_define_singleton_method(argf, "eof?", f_eof, 0);
- rb_define_singleton_method(argf, "ungetc", f_ungetc, 1);
+ rb_define_singleton_method(argf, "tell", rb_f_tell, 0);
+ rb_define_singleton_method(argf, "seek", rb_f_seek, 2);
+ rb_define_singleton_method(argf, "rewind", rb_f_rewind, 0);
+ rb_define_singleton_method(argf, "pos", rb_f_tell, 0);
+ rb_define_singleton_method(argf, "pos=", rb_f_set_pos, 1);
+ rb_define_singleton_method(argf, "eof", rb_f_eof, 0);
+ rb_define_singleton_method(argf, "eof?", rb_f_eof, 0);
+ rb_define_singleton_method(argf, "ungetc", rb_f_ungetc, 1);
rb_define_singleton_method(argf, "to_s", arg_filename, 0);
rb_define_singleton_method(argf, "filename", arg_filename, 0);
@@ -2742,7 +2743,7 @@ Init_IO()
rb_define_singleton_method(argf, "close", arg_close, 0);
rb_define_singleton_method(argf, "closed?", arg_closed, 0);
- filename = str_new2("-");
+ filename = rb_str_new2("-");
rb_define_readonly_variable("$FILENAME", &filename);
file = rb_stdin;
rb_global_variable(&file);
diff --git a/lib/debug.rb b/lib/debug.rb
index 90270a3..497d163 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -267,6 +267,6 @@ class DEBUGGER__
CONTEXT = new
end
-set_trace_func proc{|event, file, line, id, binding|
- DEBUGGER__::CONTEXT.trace_func event, file, line, id, binding
+set_trace_func proc{|event, file, line, id, binding, klass|
+ DEBUGGER__::CONTEXT.trace_func event, file, line, id, binding, klass
}
diff --git a/lib/ftools.rb b/lib/ftools.rb
index 59bc81b..fe3264f 100644
--- a/lib/ftools.rb
+++ b/lib/ftools.rb
@@ -30,7 +30,7 @@ class << File
to.binmode
begin
- while TRUE
+ while true
r = from.sysread(fsize)
rsize = r.size
w = 0
@@ -40,9 +40,9 @@ class << File
end
end
rescue EOFError
- ret = TRUE
+ ret = true
rescue
- ret = FALSE
+ ret = false
ensure
to.close
from.close
@@ -50,7 +50,7 @@ class << File
ret
end
- def copy from, to, verbose = FALSE
+ def copy from, to, verbose = false
$stderr.print from, " -> ", catname(from, to), "\n" if verbose
syscopy from, to
end
@@ -59,7 +59,7 @@ class << File
# move file
- def move from, to, verbose = FALSE
+ def move from, to, verbose = false
to = catname(from, to)
$stderr.print from, " -> ", to, "\n" if verbose
@@ -76,10 +76,10 @@ class << File
alias mv move
# compare two files
-# TRUE: identical
-# FALSE: not identical
+# true: identical
+# false: not identical
- def compare from, to, verbose = FALSE
+ def compare from, to, verbose = false
$stderr.print from, " <=> ", to, "\n" if verbose
fsize = size(from)
fsize = 1024 if fsize < 512
@@ -90,7 +90,7 @@ class << File
to = open(to, "r")
to.binmode
- ret = FALSE
+ ret = false
fr = tr = ''
begin
@@ -103,7 +103,7 @@ class << File
end
end
rescue
- ret = FALSE
+ ret = false
ensure
to.close
from.close
@@ -116,7 +116,7 @@ class << File
# unlink files safely
def safe_unlink(*files)
- verbose = if files[-1].is_a? String then FALSE else files.pop end
+ verbose = if files[-1].is_a? String then false else files.pop end
begin
$stderr.print files.join(" "), "\n" if verbose
chmod 0777, *files
@@ -129,7 +129,7 @@ class << File
alias rm_f safe_unlink
def makedirs(*dirs)
- verbose = if dirs[-1].is_a? String then FALSE else dirs.pop end
+ verbose = if dirs[-1].is_a? String then false else dirs.pop end
# mode = if dirs[-1].is_a? Fixnum then dirs.pop else 0755 end
mode = 0755
for dir in dirs
@@ -146,12 +146,12 @@ class << File
alias o_chmod chmod
def chmod(mode, *files)
- verbose = if files[-1].is_a? String then FALSE else files.pop end
+ verbose = if files[-1].is_a? String then false else files.pop end
$stderr.printf "chmod %04o %s\n", mode, files.join(" ") if verbose
o_chmod mode, *files
end
- def install(from, to, mode, verbose)
+ def install(from, to, mode = nil, verbose = false)
to = catname(from, to)
unless FileTest.exist? to and cmp from, to
cp from, to, verbose
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 2de1ebd..bf51ac2 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -22,7 +22,7 @@ class Tempfile < SimpleDelegator
File.unlink(path)
end
if File.exist?(path + '.lock')
- File.rmdir(path + '.lock')
+ Dir.rmdir(path + '.lock')
end
print "done\n" if $DEBUG
}
@@ -51,8 +51,8 @@ class Tempfile < SimpleDelegator
@clean_files = Tempfile.callback(tmpname)
ObjectSpace.define_finalizer(self, @clean_files)
- @tmpname = tmpname
@tmpfile = File.open(tmpname, 'w+')
+ @tmpname = tmpname
super(@tmpfile)
Dir.rmdir(lock)
ensure
diff --git a/lib/tk.rb b/lib/tk.rb
index f44a1fe..7a5d85f 100644
--- a/lib/tk.rb
+++ b/lib/tk.rb
@@ -1548,10 +1548,16 @@ module TkTreatFont
end
end
-class TkObject<TkKernel
+class TkObject
include Tk
include TkTreatFont
+ def TkObject.new(*args, &block)
+ obj = super
+ obj.instance_eval(&block) if block
+ obj
+ end
+
def path
return @path
end
diff --git a/marshal.c b/marshal.c
index 8263e48..815fba5 100644
--- a/marshal.c
+++ b/marshal.c
@@ -64,7 +64,7 @@ w_byte(c, arg)
struct dump_arg *arg;
{
if (arg->fp) putc(c, arg->fp);
- else str_cat(arg->str, &c, 1);
+ else rb_str_cat(arg->str, &c, 1);
}
static void
@@ -78,7 +78,7 @@ w_bytes(s, n, arg)
fwrite(s, 1, n, arg->fp);
}
else {
- str_cat(arg->str, s, n);
+ rb_str_cat(arg->str, s, n);
}
}
@@ -150,7 +150,7 @@ w_symbol(id, arg)
else {
w_byte(TYPE_SYMBOL, arg);
w_bytes(sym, strlen(sym), arg);
- st_insert(arg->symbol, id, arg->symbol->num_entries);
+ st_add_direct(arg->symbol, id, arg->symbol->num_entries);
}
}
@@ -165,7 +165,7 @@ w_unique(s, arg)
static void w_object _((VALUE,struct dump_arg*,int));
static int
-hash_each(key, value, arg)
+rb_hash_each(key, value, arg)
VALUE key, value;
struct dump_call_arg *arg;
{
@@ -175,7 +175,7 @@ hash_each(key, value, arg)
}
static int
-obj_each(id, value, arg)
+rb_obj_each(id, value, arg)
ID id;
VALUE value;
struct dump_call_arg *arg;
@@ -205,15 +205,15 @@ w_object(obj, arg, limit)
struct dump_call_arg c_arg;
if (limit == 0) {
- Fail("exceed depth limit");
+ rb_raise(rb_eRuntimeError, "exceed depth limit");
}
if (obj == Qnil) {
w_byte(TYPE_NIL, arg);
}
- else if (obj == TRUE) {
+ else if (obj == Qtrue) {
w_byte(TYPE_TRUE, arg);
}
- else if (obj == FALSE) {
+ else if (obj == Qfalse) {
w_byte(TYPE_FALSE, arg);
}
else if (FIXNUM_P(obj)) {
@@ -226,7 +226,7 @@ w_object(obj, arg, limit)
w_long(FIX2LONG(obj), arg);
}
else {
- w_object(int2big(FIX2LONG(obj)), arg, limit);
+ w_object(rb_int2big(FIX2LONG(obj)), arg, limit);
return;
}
#endif
@@ -244,7 +244,7 @@ w_object(obj, arg, limit)
return;
}
- st_insert(arg->data, obj, arg->data->num_entries);
+ st_add_direct(arg->data, obj, arg->data->num_entries);
if (rb_respond_to(obj, s_dump)) {
VALUE v;
@@ -252,7 +252,7 @@ w_object(obj, arg, limit)
w_unique(rb_class2name(CLASS_OF(obj)), arg);
v = rb_funcall(obj, s_dump, 1, limit);
if (TYPE(v) != T_STRING) {
- TypeError("_dump_to must return String");
+ rb_raise(rb_eTypeError, "_dump_to must return String");
}
w_bytes(RSTRING(v)->ptr, RSTRING(v)->len, arg);
return;
@@ -290,20 +290,20 @@ w_object(obj, arg, limit)
return;
case T_STRING:
- w_uclass(obj, cString, arg);
+ w_uclass(obj, rb_cString, arg);
w_byte(TYPE_STRING, arg);
w_bytes(RSTRING(obj)->ptr, RSTRING(obj)->len, arg);
return;
case T_REGEXP:
- w_uclass(obj, cRegexp, arg);
+ w_uclass(obj, rb_cRegexp, arg);
w_byte(TYPE_REGEXP, arg);
w_bytes(RREGEXP(obj)->str, RREGEXP(obj)->len, arg);
- w_byte(reg_options(obj), arg);
+ w_byte(rb_reg_options(obj), arg);
return;
case T_ARRAY:
- w_uclass(obj, cArray, arg);
+ w_uclass(obj, rb_cArray, arg);
w_byte(TYPE_ARRAY, arg);
{
int len = RARRAY(obj)->len;
@@ -318,10 +318,10 @@ w_object(obj, arg, limit)
break;
case T_HASH:
- w_uclass(obj, cHash, arg);
+ w_uclass(obj, rb_cHash, arg);
w_byte(TYPE_HASH, arg);
w_long(RHASH(obj)->tbl->num_entries, arg);
- st_foreach(RHASH(obj)->tbl, hash_each, &c_arg);
+ st_foreach(RHASH(obj)->tbl, rb_hash_each, &c_arg);
break;
case T_STRUCT:
@@ -336,7 +336,7 @@ w_object(obj, arg, limit)
w_long(len, arg);
mem = rb_ivar_get(CLASS_OF(obj), rb_intern("__member__"));
if (mem == Qnil) {
- Fatal("non-initialized struct");
+ rb_raise(rb_eTypeError, "non-initialized struct");
}
for (i=0; i<len; i++) {
w_symbol(FIX2LONG(RARRAY(mem)->ptr[i]), arg);
@@ -352,13 +352,13 @@ w_object(obj, arg, limit)
char *path;
if (FL_TEST(klass, FL_SINGLETON)) {
- TypeError("singleton can't be dumped");
+ rb_raise(rb_eTypeError, "singleton can't be dumped");
}
path = rb_class2name(klass);
w_unique(path, arg);
if (ROBJECT(obj)->iv_tbl) {
w_long(ROBJECT(obj)->iv_tbl->num_entries, arg);
- st_foreach(ROBJECT(obj)->iv_tbl, obj_each, &c_arg);
+ st_foreach(ROBJECT(obj)->iv_tbl, rb_obj_each, &c_arg);
}
else {
w_long(0, arg);
@@ -367,7 +367,8 @@ w_object(obj, arg, limit)
break;
default:
- TypeError("can't dump %s", rb_class2name(CLASS_OF(obj)));
+ rb_raise(rb_eTypeError, "can't dump %s",
+ rb_class2name(CLASS_OF(obj)));
break;
}
}
@@ -411,21 +412,21 @@ marshal_dump(argc, argv)
else port = a1;
}
if (port) {
- if (obj_is_kind_of(port, cIO)) {
+ if (rb_obj_is_kind_of(port, rb_cIO)) {
OpenFile *fptr;
- io_binmode(port);
+ rb_io_binmode(port);
GetOpenFile(port, fptr);
- io_writable(fptr);
+ rb_io_check_writable(fptr);
arg.fp = (fptr->f2) ? fptr->f2 : fptr->f;
}
else {
- TypeError("instance of IO needed");
+ rb_raise(rb_eTypeError, "instance of IO needed");
}
}
else {
arg.fp = 0;
- port = str_new(0, 0);
+ port = rb_str_new(0, 0);
arg.str = port;
}
@@ -479,8 +480,8 @@ static void
long_toobig(size)
int size;
{
- TypeError("long too big for this architecture (size %d, given %d)",
- sizeof(long), size);
+ rb_raise(rb_eTypeError, "long too big for this architecture (size %d, given %d)",
+ sizeof(long), size);
}
static long
@@ -554,7 +555,7 @@ r_symbol(arg)
if (st_lookup(arg->symbol, num, &id)) {
return id;
}
- TypeError("bad symbol");
+ rb_raise(rb_eTypeError, "bad symbol");
}
r_bytes(buf, arg);
id = rb_intern(buf);
@@ -578,7 +579,7 @@ r_string(arg)
int len;
r_bytes2(buf, len, arg);
- return str_taint(str_new(buf, len));
+ return rb_str_taint(rb_str_new(buf, len));
}
static VALUE
@@ -602,14 +603,14 @@ r_object(arg)
switch (type) {
case EOF:
- eof_error();
+ rb_eof_error();
return Qnil;
case TYPE_LINK:
if (st_lookup(arg->data, r_long(arg), &v)) {
return v;
}
- ArgError("dump format error (unlinked)");
+ rb_raise(rb_eArgError, "dump format error (unlinked)");
break;
case TYPE_UCLASS:
@@ -617,7 +618,7 @@ r_object(arg)
VALUE c = rb_path2class(r_unique(arg));
v = r_object(arg);
if (rb_special_const_p(v)) {
- ArgError("dump format error (user class)");
+ rb_raise(rb_eArgError, "dump format error (user class)");
}
RBASIC(v)->klass = c;
return v;
@@ -627,10 +628,10 @@ r_object(arg)
return Qnil;
case TYPE_TRUE:
- return TRUE;
+ return Qtrue;
case TYPE_FALSE:
- return FALSE;
+ return Qfalse;
case TYPE_FIXNUM:
{
@@ -646,7 +647,7 @@ r_object(arg)
char *buf;
r_bytes(buf, arg);
- v = float_new(atof(buf));
+ v = rb_float_new(atof(buf));
return r_regist(v, arg);
}
@@ -656,14 +657,14 @@ r_object(arg)
unsigned short *digits;
NEWOBJ(big, struct RBignum);
- OBJSETUP(big, cBignum, T_BIGNUM);
+ OBJSETUP(big, rb_cBignum, T_BIGNUM);
big->sign = (r_byte(arg) == '+');
big->len = len = r_long(arg);
big->digits = digits = ALLOC_N(unsigned short, len);
while (len--) {
*digits++ = r_short(arg);
}
- big = RBIGNUM(big_norm((VALUE)big));
+ big = RBIGNUM(rb_big_norm((VALUE)big));
if (TYPE(big) == T_BIGNUM) {
r_regist((VALUE)big, arg);
}
@@ -681,16 +682,16 @@ r_object(arg)
r_bytes2(buf, len, arg);
options = r_byte(arg);
- return r_regist(reg_new(buf, len, options), arg);
+ return r_regist(rb_reg_new(buf, len, options), arg);
}
case TYPE_ARRAY:
{
volatile int len = r_long(arg);
- v = ary_new2(len);
+ v = rb_ary_new2(len);
r_regist(v, arg);
while (len--) {
- ary_push(v, r_object(arg));
+ rb_ary_push(v, r_object(arg));
}
return v;
}
@@ -699,12 +700,12 @@ r_object(arg)
{
int len = r_long(arg);
- v = hash_new();
+ v = rb_hash_new();
r_regist(v, arg);
while (len--) {
VALUE key = r_object(arg);
VALUE value = r_object(arg);
- hash_aset(v, key, value);
+ rb_hash_aset(v, key, value);
}
return v;
}
@@ -719,26 +720,26 @@ r_object(arg)
klass = rb_path2class(r_unique(arg));
mem = rb_ivar_get(klass, rb_intern("__member__"));
if (mem == Qnil) {
- Fatal("non-initialized struct");
+ rb_raise(rb_eTypeError, "non-initialized struct");
}
len = r_long(arg);
- values = ary_new2(len);
+ values = rb_ary_new2(len);
for (i=0; i<len; i++) {
- ary_push(values, Qnil);
+ rb_ary_push(values, Qnil);
}
- v = struct_alloc(klass, values);
+ v = rb_struct_alloc(klass, values);
r_regist(v, arg);
for (i=0; i<len; i++) {
slot = r_symbol(arg);
if (RARRAY(mem)->ptr[i] != INT2FIX(slot)) {
- TypeError("struct %s not compatible (:%s for :%s)",
- rb_class2name(klass),
- rb_id2name(slot),
- rb_id2name(FIX2INT(RARRAY(mem)->ptr[i])));
+ rb_raise(rb_eTypeError, "struct %s not compatible (:%s for :%s)",
+ rb_class2name(klass),
+ rb_id2name(slot),
+ rb_id2name(FIX2INT(RARRAY(mem)->ptr[i])));
}
- struct_aset(v, INT2FIX(i), r_object(arg));
+ rb_struct_aset(v, INT2FIX(i), r_object(arg));
}
return v;
}
@@ -753,8 +754,8 @@ r_object(arg)
v = rb_funcall(klass, s_load, 1, r_string(arg));
return r_regist(v, arg);
}
- TypeError("class %s needs to have method `_load_from'",
- rb_class2name(klass));
+ rb_raise(rb_eTypeError, "class %s needs to have method `_load_from'",
+ rb_class2name(klass));
}
break;
@@ -765,7 +766,7 @@ r_object(arg)
klass = rb_path2class(r_unique(arg));
len = r_long(arg);
- v = obj_alloc(klass);
+ v = rb_obj_alloc(klass);
r_regist(v, arg);
if (len > 0) {
while (len--) {
@@ -786,7 +787,7 @@ r_object(arg)
}
default:
- ArgError("dump format error(0x%x)", type);
+ rb_raise(rb_eArgError, "dump format error(0x%x)", type);
break;
}
}
@@ -819,10 +820,10 @@ marshal_load(argc, argv)
struct load_arg arg;
rb_scan_args(argc, argv, "11", &port, &proc);
- if (obj_is_kind_of(port, cIO)) {
- io_binmode(port);
+ if (rb_obj_is_kind_of(port, rb_cIO)) {
+ rb_io_binmode(port);
GetOpenFile(port, fptr);
- io_readable(fptr);
+ rb_io_check_readable(fptr);
arg.fp = fptr->f;
}
else if (rb_respond_to(port, rb_intern("to_str"))) {
@@ -833,13 +834,13 @@ marshal_load(argc, argv)
arg.end = arg.ptr + RSTRING(port)->len;
}
else {
- TypeError("instance of IO needed");
+ rb_raise(rb_eTypeError, "instance of IO needed");
}
major = r_byte(&arg);
if (major == MARSHAL_MAJOR) {
if (r_byte(&arg) != MARSHAL_MINOR) {
- Warn("Old marshal file format (can be read)");
+ rb_warn("Old marshal file format (can be read)");
}
arg.symbol = st_init_numtable();
arg.data = st_init_numtable();
@@ -848,7 +849,7 @@ marshal_load(argc, argv)
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
}
else {
- TypeError("Old marshal file format (can't read)");
+ rb_raise(rb_eTypeError, "Old marshal file format (can't read)");
}
return v;
@@ -857,13 +858,13 @@ marshal_load(argc, argv)
void
Init_marshal()
{
- VALUE mMa