yarv-diff:101
From: ko1 atdot.net
Date: 23 Sep 2005 11:41:37 -0000
Subject: [yarv-diff:101] r257 - in trunk: . lib missing rb win32
Author: ko1
Date: 2005-09-23 20:41:35 +0900 (Fri, 23 Sep 2005)
New Revision: 257
Added:
trunk/eval_error.h
trunk/eval_intern.h
trunk/eval_jump.c
trunk/eval_jump.h
trunk/eval_method.h
trunk/eval_proc.c
trunk/eval_safe.h
trunk/eval_thread.c
Modified:
trunk/ChangeLog
trunk/array.c
trunk/bignum.c
trunk/class.c
trunk/common.mk
trunk/compar.c
trunk/compile.c
trunk/defines.h
trunk/dir.c
trunk/dln.c
trunk/dln.h
trunk/dmyext.c
trunk/enum.c
trunk/enumerator.c
trunk/env.h
trunk/error.c
trunk/eval.c
trunk/file.c
trunk/gc.c
trunk/hash.c
trunk/inits.c
trunk/intern.h
trunk/io.c
trunk/lex.c
trunk/lib/fileutils.rb
trunk/main.c
trunk/marshal.c
trunk/math.c
trunk/missing.h
trunk/missing/strchr.c
trunk/missing/vsnprintf.c
trunk/node.h
trunk/numeric.c
trunk/object.c
trunk/pack.c
trunk/parse.y
trunk/prec.c
trunk/process.c
trunk/random.c
trunk/range.c
trunk/rb/ir.rb
trunk/re.c
trunk/re.h
trunk/regcomp.c
trunk/regenc.c
trunk/regerror.c
trunk/regexec.c
trunk/regparse.c
trunk/regparse.h
trunk/ruby.c
trunk/ruby.h
trunk/rubyio.h
trunk/rubysig.h
trunk/signal.c
trunk/sprintf.c
trunk/st.c
trunk/st.h
trunk/string.c
trunk/struct.c
trunk/test.rb
trunk/time.c
trunk/util.c
trunk/util.h
trunk/variable.c
trunk/version.h
trunk/vm_opts.h
trunk/win32/win32.c
trunk/win32/win32.h
trunk/yarvcore.c
trunk/yarvcore.h
Log:
* eval_*.[ch] : split eval.c to some files
* *.[ch] : import ruby 1.9.0 (2004-09-23)
* parse.y : remove dependency to ruby_dyna_vars and ruby_scope
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/ChangeLog 2005-09-23 11:41:35 UTC (rev 257)
@@ -4,6 +4,15 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-09-23(Fri) 20:39:14 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * eval_*.[ch] : split eval.c to some files
+
+ * *.[ch] : import ruby 1.9.0 (2004-09-23)
+
+ * parse.y : remove dependency to ruby_dyna_vars and ruby_scope
+
+
2005-09-15(Thu) 16:51:06 +0900 Koichi Sasada <ko1 atdot.net>
* compile.c, yarvcore.h : fix "for" scope
Modified: trunk/array.c
===================================================================
--- trunk/array.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/array.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -3,7 +3,7 @@
array.c -
$Author: matz $
- $Date: 2005/08/10 01:39:24 $
+ $Date: 2005/09/12 15:23:54 $
created at: Fri Aug 6 09:46:12 JST 1993
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -23,11 +23,8 @@
#define ARY_DEFAULT_SIZE 16
-
void
-rb_mem_clear(mem, size)
- register VALUE *mem;
- register long size;
+rb_mem_clear(register VALUE *mem, register long size)
{
while (size--) {
*mem++ = Qnil;
@@ -35,10 +32,7 @@
}
static inline void
-memfill(mem, size, val)
- register VALUE *mem;
- register long size;
- register VALUE val;
+memfill(register VALUE *mem, register long size, register VALUE val)
{
while (size--) {
*mem++ = val;
@@ -48,8 +42,7 @@
#define ARY_TMPLOCK FL_USER1
static inline void
-rb_ary_modify_check(ary)
- VALUE ary;
+rb_ary_modify_check(VALUE ary)
{
if (OBJ_FROZEN(ary)) rb_error_frozen("array");
if (FL_TEST(ary, ARY_TMPLOCK))
@@ -59,8 +52,7 @@
}
static void
-rb_ary_modify(ary)
- VALUE ary;
+rb_ary_modify(VALUE ary)
{
VALUE *ptr;
@@ -75,8 +67,7 @@
}
VALUE
-rb_ary_freeze(ary)
- VALUE ary;
+rb_ary_freeze(VALUE ary)
{
return rb_obj_freeze(ary);
}
@@ -90,18 +81,15 @@
*/
static VALUE
-rb_ary_frozen_p(ary)
- VALUE ary;
+rb_ary_frozen_p(VALUE ary)
{
if (OBJ_FROZEN(ary)) return Qtrue;
if (FL_TEST(ary, ARY_TMPLOCK)) return Qtrue;
return Qfalse;
}
-static VALUE ary_alloc(VALUE);
static VALUE
-ary_alloc(klass)
- VALUE klass;
+ary_alloc(VALUE klass)
{
NEWOBJ(ary, struct RArray);
OBJSETUP(ary, klass, T_ARRAY);
@@ -114,9 +102,7 @@
}
static VALUE
-ary_new(klass, len)
- VALUE klass;
- long len;
+ary_new(VALUE klass, long len)
{
VALUE ary;
@@ -136,35 +122,22 @@
}
VALUE
-rb_ary_new2(len)
- long len;
+rb_ary_new2(long len)
{
return ary_new(rb_cArray, len);
}
VALUE
-rb_ary_new()
+rb_ary_new(void)
{
return rb_ary_new2(ARY_DEFAULT_SIZE);
}
-#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
-#define va_init_list(a,b) va_start(a,b)
-#else
-#include <varargs.h>
-#define va_init_list(a,b) va_start(a)
-#endif
VALUE
-#ifdef HAVE_STDARG_PROTOTYPES
rb_ary_new3(long n, ...)
-#else
-rb_ary_new3(n, va_alist)
- long n;
- va_dcl
-#endif
{
va_list ar;
VALUE ary;
@@ -172,7 +145,7 @@
ary = rb_ary_new2(n);
- va_init_list(ar, n);
+ va_start(ar, n);
for (i=0; i<n; i++) {
RARRAY(ary)->ptr[i] = va_arg(ar, VALUE);
}
@@ -183,9 +156,7 @@
}
VALUE
-rb_ary_new4(n, elts)
- long n;
- const VALUE *elts;
+rb_ary_new4(long n, const VALUE *elts)
{
VALUE ary;
@@ -199,20 +170,14 @@
}
VALUE
-#ifdef HAVE_STDARG_PROTOTYPES
rb_values_new(long n, ...)
-#else
-rb_values_new(n, va_alist)
- long n;
- va_dcl
-#endif
{
va_list ar;
VALUE val;
long i;
val = ary_new(rb_cValues, n);
- va_init_list(ar, n);
+ va_start(ar, n);
for (i=0; i<n; i++) {
RARRAY(val)->ptr[i] = va_arg(ar, VALUE);
}
@@ -223,9 +188,7 @@
}
VALUE
-rb_values_new2(n, elts)
- long n;
- const VALUE *elts;
+rb_values_new2(long n, const VALUE *elts)
{
VALUE val;
@@ -239,8 +202,7 @@
}
static VALUE
-ary_make_shared(ary)
- VALUE ary;
+ary_make_shared(VALUE ary)
{
if (!FL_TEST(ary, ELTS_SHARED)) {
NEWOBJ(shared, struct RArray);
@@ -260,8 +222,7 @@
}
static VALUE
-ary_shared_array(klass, ary)
- VALUE klass, ary;
+ary_shared_array(VALUE klass, VALUE ary)
{
VALUE val = ary_alloc(klass);
@@ -274,48 +235,42 @@
}
VALUE
-rb_values_from_ary(ary)
- VALUE ary;
+rb_values_from_ary(VALUE ary)
{
return ary_shared_array(rb_cValues, ary);
}
VALUE
-rb_ary_from_values(val)
- VALUE val;
+rb_ary_from_values(VALUE val)
{
return ary_shared_array(rb_cArray, val);
}
VALUE
-rb_assoc_new(car, cdr)
- VALUE car, cdr;
+rb_assoc_new(VALUE car, VALUE cdr)
{
return rb_values_new(2, car, cdr);
}
static VALUE
-to_ary(ary)
- VALUE ary;
+to_ary(VALUE ary)
{
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
static VALUE
-to_a(ary)
- VALUE ary;
+to_a(VALUE ary)
{
return rb_convert_type(ary, T_ARRAY, "Array", "to_a");
}
VALUE
-rb_check_array_type(ary)
- VALUE ary;
+rb_check_array_type(VALUE ary)
{
return rb_check_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
-static VALUE rb_ary_replace _((VALUE, VALUE));
+static VALUE rb_ary_replace(VALUE, VALUE);
/*
* call-seq:
@@ -356,10 +311,7 @@
*/
static VALUE
-rb_ary_initialize(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
{
long len;
VALUE size, val;
@@ -421,10 +373,7 @@
*/
static VALUE
-rb_ary_s_create(argc, argv, klass)
- int argc;
- VALUE *argv;
- VALUE klass;
+rb_ary_s_create(int argc, VALUE *argv, VALUE klass)
{
VALUE ary = ary_alloc(klass);
@@ -438,10 +387,7 @@
}
void
-rb_ary_store(ary, idx, val)
- VALUE ary;
- long idx;
- VALUE val;
+rb_ary_store(VALUE ary, long idx, VALUE val)
{
if (idx < 0) {
idx += RARRAY(ary)->len;
@@ -477,10 +423,7 @@
}
static VALUE
-ary_shared_first(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+ary_shared_first(int argc, VALUE *argv, VALUE ary)
{
VALUE nv, result;
long n;
@@ -499,10 +442,7 @@
}
static VALUE
-ary_shared_last(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+ary_shared_last(int argc, VALUE *argv, VALUE ary)
{
VALUE result = ary_shared_first(argc, argv, ary);
@@ -524,9 +464,7 @@
*/
VALUE
-rb_ary_push(ary, item)
- VALUE ary;
- VALUE item;
+rb_ary_push(VALUE ary, VALUE item)
{
rb_ary_store(ary, RARRAY(ary)->len, item);
return ary;
@@ -546,10 +484,7 @@
*/
static VALUE
-rb_ary_push_m(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_push_m(int argc, VALUE *argv, VALUE ary)
{
while (argc--) {
rb_ary_push(ary, *argv++);
@@ -558,8 +493,7 @@
}
VALUE
-rb_ary_pop(ary)
- VALUE ary;
+rb_ary_pop(VALUE ary)
{
rb_ary_modify_check(ary);
if (RARRAY(ary)->len == 0) return Qnil;
@@ -586,10 +520,7 @@
*/
static VALUE
-rb_ary_pop_m(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_pop_m(int argc, VALUE *argv, VALUE ary)
{
VALUE result;
@@ -605,8 +536,7 @@
}
VALUE
-rb_ary_shift(ary)
- VALUE ary;
+rb_ary_shift(VALUE ary)
{
VALUE top;
@@ -638,10 +568,7 @@
*/
static VALUE
-rb_ary_shift_m(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
{
VALUE result;
long n;
@@ -661,8 +588,7 @@
}
VALUE
-rb_ary_unshift(ary, item)
- VALUE ary, item;
+rb_ary_unshift(VALUE ary, VALUE item)
{
rb_ary_modify(ary);
if (RARRAY(ary)->len == RARRAY(ary)->aux.capa) {
@@ -696,10 +622,7 @@
*/
static VALUE
-rb_ary_unshift_m(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_unshift_m(int argc, VALUE *argv, VALUE ary)
{
long len = RARRAY(ary)->len;
@@ -717,9 +640,7 @@
/* faster version - use this if you don't need to treat negative offset */
static inline VALUE
-rb_ary_elt(ary, offset)
- VALUE ary;
- long offset;
+rb_ary_elt(VALUE ary, long offset)
{
if (RARRAY(ary)->len == 0) return Qnil;
if (offset < 0 || RARRAY(ary)->len <= offset) {
@@ -729,9 +650,7 @@
}
VALUE
-rb_ary_entry(ary, offset)
- VALUE ary;
- long offset;
+rb_ary_entry(VALUE ary, long offset)
{
if (offset < 0) {
offset += RARRAY(ary)->len;
@@ -740,9 +659,7 @@
}
static VALUE
-rb_ary_subseq(ary, beg, len)
- VALUE ary;
- long beg, len;
+rb_ary_subseq(VALUE ary, long beg, long len)
{
VALUE klass, ary2, shared;
VALUE *ptr;
@@ -802,10 +719,7 @@
*/
VALUE
-rb_ary_aref(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_aref(int argc, VALUE *argv, VALUE ary)
{
VALUE arg;
long beg, len;
@@ -854,8 +768,7 @@
*/
static VALUE
-rb_ary_at(ary, pos)
- VALUE ary, pos;
+rb_ary_at(VALUE ary, VALUE pos)
{
return rb_ary_entry(ary, NUM2LONG(pos));
}
@@ -874,10 +787,7 @@
*/
static VALUE
-rb_ary_first(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_first(int argc, VALUE *argv, VALUE ary)
{
if (argc == 0) {
if (RARRAY(ary)->len == 0) return Qnil;
@@ -902,10 +812,7 @@
*/
static VALUE
-rb_ary_last(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_last(int argc, VALUE *argv, VALUE ary)
{
if (argc == 0) {
if (RARRAY(ary)->len == 0) return Qnil;
@@ -937,10 +844,7 @@
*/
static VALUE
-rb_ary_fetch(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_fetch(int argc, VALUE *argv, VALUE ary)
{
VALUE pos, ifnone;
long block_given;
@@ -983,15 +887,13 @@
*/
static VALUE
-rb_ary_index(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_index(int argc, VALUE *argv, VALUE ary)
{
VALUE val;
long i;
if (rb_scan_args(argc, argv, "01", &val) == 0) {
+ RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY(ary)->len; i++) {
if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
return LONG2NUM(i);
@@ -1023,16 +925,14 @@
*/
static VALUE
-rb_ary_rindex(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
{
VALUE val;
long i = RARRAY(ary)->len;
if (rb_scan_args(argc, argv, "01", &val) == 0) {
while (i--) {
+ RETURN_ENUMERATOR(ary, 0, 0);
if (RTEST(rb_yield(RARRAY(ary)->ptr[i])))
return LONG2NUM(i);
if (i > RARRAY(ary)->len) {
@@ -1053,8 +953,7 @@
}
VALUE
-rb_ary_to_ary(obj)
- VALUE obj;
+rb_ary_to_ary(VALUE obj)
{
if (TYPE(obj) == T_ARRAY) {
return obj;
@@ -1066,10 +965,7 @@
}
static void
-rb_ary_splice(ary, beg, len, rpl)
- VALUE ary;
- long beg, len;
- VALUE rpl;
+rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
{
long rlen;
@@ -1159,10 +1055,7 @@
*/
static VALUE
-rb_ary_aset(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_aset(int argc, VALUE *argv, VALUE ary)
{
long offset, beg, len;
@@ -1202,10 +1095,7 @@
*/
static VALUE
-rb_ary_insert(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_insert(int argc, VALUE *argv, VALUE ary)
{
long pos;
@@ -1241,11 +1131,11 @@
*/
VALUE
-rb_ary_each(ary)
- VALUE ary;
+rb_ary_each(VALUE ary)
{
long i;
+ RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY(ary)->len; i++) {
rb_yield(RARRAY(ary)->ptr[i]);
}
@@ -1268,11 +1158,11 @@
*/
static VALUE
-rb_ary_each_index(ary)
- VALUE ary;
+rb_ary_each_index(VALUE ary)
{
long i;
+ RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY(ary)->len; i++) {
rb_yield(LONG2NUM(i));
}
@@ -1295,11 +1185,11 @@
*/
static VALUE
-rb_ary_reverse_each(ary)
- VALUE ary;
+rb_ary_reverse_each(VALUE ary)
{
long len = RARRAY(ary)->len;
+ RETURN_ENUMERATOR(ary, 0, 0);
while (len--) {
rb_yield(RARRAY(ary)->ptr[len]);
if (RARRAY(ary)->len < len) {
@@ -1319,8 +1209,7 @@
*/
static VALUE
-rb_ary_length(ary)
- VALUE ary;
+rb_ary_length(VALUE ary)
{
return LONG2NUM(RARRAY(ary)->len);
}
@@ -1335,8 +1224,7 @@
*/
static VALUE
-rb_ary_empty_p(ary)
- VALUE ary;
+rb_ary_empty_p(VALUE ary)
{
if (RARRAY(ary)->len == 0)
return Qtrue;
@@ -1344,8 +1232,7 @@
}
VALUE
-rb_ary_dup(ary)
- VALUE ary;
+rb_ary_dup(VALUE ary)
{
VALUE dup = rb_ary_new2(RARRAY(ary)->len);
@@ -1358,10 +1245,7 @@
extern VALUE rb_output_fs;
static VALUE
-recursive_join(ary, arg, recur)
- VALUE ary;
- VALUE *arg;
- int recur;
+recursive_join(VALUE ary, VALUE *arg, int recur)
{
if (recur) {
return rb_str_new2("[...]");
@@ -1370,8 +1254,7 @@
}
VALUE
-rb_ary_join(ary, sep)
- VALUE ary, sep;
+rb_ary_join(VALUE ary, VALUE sep)
{
long len = 1, i;
int taint = Qfalse;
@@ -1428,10 +1311,7 @@
*/
static VALUE
-rb_ary_join_m(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
{
VALUE sep;
@@ -1452,8 +1332,7 @@
*/
VALUE
-rb_ary_to_s(ary)
- VALUE ary;
+rb_ary_to_s(VALUE ary)
{
if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
@@ -1461,10 +1340,7 @@
}
static VALUE
-inspect_ary(ary, dummy, recur)
- VALUE ary;
- VALUE dummy;
- int recur;
+inspect_ary(VALUE ary, VALUE dummy, int recur)
{
int tainted = OBJ_TAINTED(ary);
long i;
@@ -1491,8 +1367,7 @@
*/
static VALUE
-rb_ary_inspect(ary)
- VALUE ary;
+rb_ary_inspect(VALUE ary)
{
if (RARRAY(ary)->len == 0) return rb_str_new2("[]");
return rb_exec_recursive(inspect_ary, ary, 0);
@@ -1507,8 +1382,7 @@
*/
static VALUE
-rb_ary_to_a(ary)
- VALUE ary;
+rb_ary_to_a(VALUE ary)
{
if (rb_obj_class(ary) != rb_cArray) {
VALUE dup = rb_ary_new2(RARRAY(ary)->len);
@@ -1526,15 +1400,13 @@
*/
static VALUE
-rb_ary_to_ary_m(ary)
- VALUE ary;
+rb_ary_to_ary_m(VALUE ary)
{
return ary;
}
VALUE
-rb_ary_reverse(ary)
- VALUE ary;
+rb_ary_reverse(VALUE ary)
{
VALUE *p1, *p2;
VALUE tmp;
@@ -1565,8 +1437,7 @@
*/
static VALUE
-rb_ary_reverse_bang(ary)
- VALUE ary;
+rb_ary_reverse_bang(VALUE ary)
{
return rb_ary_reverse(ary);
}
@@ -1582,8 +1453,7 @@
*/
static VALUE
-rb_ary_reverse_m(ary)
- VALUE ary;
+rb_ary_reverse_m(VALUE ary)
{
return rb_ary_reverse(rb_ary_dup(ary));
}
@@ -1595,8 +1465,7 @@
};
static void
-ary_sort_check(data)
- struct ary_sort_data *data;
+ary_sort_check(struct ary_sort_data *data)
{
if (RARRAY(data->ary)->ptr != data->ptr || RARRAY(data->ary)->len != data->len) {
rb_raise(rb_eRuntimeError, "array modified during sort");
@@ -1604,9 +1473,7 @@
}
static int
-sort_1(a, b, data)
- VALUE *a, *b;
- struct ary_sort_data *data;
+sort_1(VALUE *a, VALUE *b, struct ary_sort_data *data)
{
VALUE retval = rb_yield_values(2, *a, *b);
int n;
@@ -1617,9 +1484,7 @@
}
static int
-sort_2(ap, bp, data)
- VALUE *ap, *bp;
- struct ary_sort_data *data;
+sort_2(VALUE *ap, VALUE *bp, struct ary_sort_data *data)
{
VALUE retval;
VALUE a = *ap, b = *bp;
@@ -1642,8 +1507,7 @@
}
static VALUE
-sort_internal(ary)
- VALUE ary;
+sort_internal(VALUE ary)
{
struct ary_sort_data data;
@@ -1655,8 +1519,7 @@
}
static VALUE
-sort_unlock(ary)
- VALUE ary;
+sort_unlock(VALUE ary)
{
FL_UNSET(ary, ARY_TMPLOCK);
return ary;
@@ -1679,8 +1542,7 @@
*/
VALUE
-rb_ary_sort_bang(ary)
- VALUE ary;
+rb_ary_sort_bang(VALUE ary)
{
rb_ary_modify(ary);
if (RARRAY(ary)->len > 1) {
@@ -1707,8 +1569,7 @@
*/
VALUE
-rb_ary_sort(ary)
- VALUE ary;
+rb_ary_sort(VALUE ary)
{
ary = rb_ary_dup(ary);
rb_ary_sort_bang(ary);
@@ -1730,16 +1591,12 @@
*/
static VALUE
-rb_ary_collect(ary)
- VALUE ary;
+rb_ary_collect(VALUE ary)
{
long i;
VALUE collect;
- if (!rb_block_given_p()) {
- return rb_ary_new4(RARRAY(ary)->len, RARRAY(ary)->ptr);
- }
-
+ RETURN_ENUMERATOR(ary, 0, 0);
collect = rb_ary_new2(RARRAY(ary)->len);
for (i = 0; i < RARRAY(ary)->len; i++) {
rb_ary_push(collect, rb_yield(RARRAY(ary)->ptr[i]));
@@ -1762,11 +1619,11 @@
*/
static VALUE
-rb_ary_collect_bang(ary)
- VALUE ary;
+rb_ary_collect_bang(VALUE ary)
{
long i;
+ RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i = 0; i < RARRAY(ary)->len; i++) {
rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
@@ -1775,12 +1632,7 @@
}
VALUE
-rb_get_values_at(obj, olen, argc, argv, func)
- VALUE obj;
- long olen;
- int argc;
- VALUE *argv;
- VALUE (*func) _((VALUE,long));
+rb_get_values_at(VALUE obj, long olen, int argc, VALUE *argv, VALUE (*func) (VALUE, long))
{
VALUE result = rb_ary_new2(argc);
long beg, len, i, j;
@@ -1824,10 +1676,7 @@
*/
static VALUE
-rb_ary_values_at(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_values_at(int argc, VALUE *argv, VALUE ary)
{
return rb_get_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry);
}
@@ -1845,12 +1694,12 @@
*/
static VALUE
-rb_ary_select(ary)
- VALUE ary;
+rb_ary_select(VALUE ary)
{
VALUE result;
long i;
+ RETURN_ENUMERATOR(ary, 0, 0);
result = rb_ary_new2(RARRAY(ary)->len);
for (i = 0; i < RARRAY(ary)->len; i++) {
if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
@@ -1878,9 +1727,7 @@
*/
VALUE
-rb_ary_delete(ary, item)
- VALUE ary;
- VALUE item;
+rb_ary_delete(VALUE ary, VALUE item)
{
long i1, i2;
@@ -1914,9 +1761,7 @@
}
VALUE
-rb_ary_delete_at(ary, pos)
- VALUE ary;
- long pos;
+rb_ary_delete_at(VALUE ary, long pos)
{
long i, len = RARRAY(ary)->len;
VALUE del;
@@ -1952,8 +1797,7 @@
*/
static VALUE
-rb_ary_delete_at_m(ary, pos)
- VALUE ary, pos;
+rb_ary_delete_at_m(VALUE ary, VALUE pos)
{
return rb_ary_delete_at(ary, NUM2LONG(pos));
}
@@ -1984,10 +1828,7 @@
*/
static VALUE
-rb_ary_slice_bang(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
{
VALUE arg1, arg2;
long pos, len;
@@ -2022,11 +1863,11 @@
*/
static VALUE
-rb_ary_reject_bang(ary)
- VALUE ary;
+rb_ary_reject_bang(VALUE ary)
{
long i1, i2;
+ RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
VALUE v = RARRAY(ary)->ptr[i1];
@@ -2052,9 +1893,9 @@
*/
static VALUE
-rb_ary_reject(ary)
- VALUE ary;
+rb_ary_reject(VALUE ary)
{
+ RETURN_ENUMERATOR(ary, 0, 0);
ary = rb_ary_dup(ary);
rb_ary_reject_bang(ary);
return ary;
@@ -2072,8 +1913,7 @@
*/
static VALUE
-rb_ary_delete_if(ary)
- VALUE ary;
+rb_ary_delete_if(VALUE ary)
{
rb_ary_reject_bang(ary);
return ary;
@@ -2102,10 +1942,7 @@
*/
static VALUE
-rb_ary_zip(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_zip(int argc, VALUE *argv, VALUE ary)
{
int i, j;
long len;
@@ -2152,8 +1989,7 @@
*/
static VALUE
-rb_ary_transpose(ary)
- VALUE ary;
+rb_ary_transpose(VALUE ary)
{
long elen = -1, alen, i, j;
VALUE tmp, result = 0;
@@ -2193,8 +2029,7 @@
*/
static VALUE
-rb_ary_replace(copy, orig)
- VALUE copy, orig;
+rb_ary_replace(VALUE copy, VALUE orig)
{
VALUE shared;
@@ -2223,8 +2058,7 @@
*/
VALUE
-rb_ary_clear(ary)
- VALUE ary;
+rb_ary_clear(VALUE ary)
{
rb_ary_modify(ary);
RARRAY(ary)->len = 0;
@@ -2260,10 +2094,7 @@
*/
static VALUE
-rb_ary_fill(argc, argv, ary)
- int argc;
- VALUE *argv;
- VALUE ary;
+rb_ary_fill(int argc, VALUE *argv, VALUE ary)
{
VALUE item, arg1, arg2;
long beg, end, len;
@@ -2341,8 +2172,7 @@
*/
VALUE
-rb_ary_plus(x, y)
- VALUE x, y;
+rb_ary_plus(VALUE x, VALUE y)
{
VALUE z;
long len;
@@ -2367,8 +2197,7 @@
VALUE
-rb_ary_concat(x, y)
- VALUE x, y;
+rb_ary_concat(VALUE x, VALUE y)
{
y = to_ary(y);
if (RARRAY(y)->len > 0) {
@@ -2394,8 +2223,7 @@
*/
static VALUE
-rb_ary_times(ary, times)
- VALUE ary, times;
+rb_ary_times(VALUE ary, VALUE times)
{
VALUE ary2, tmp;
long i, len;
@@ -2447,8 +2275,7 @@
*/
VALUE
-rb_ary_assoc(ary, key)
- VALUE ary, key;
+rb_ary_assoc(VALUE ary, VALUE key)
{
long i;
VALUE v;
@@ -2478,8 +2305,7 @@
*/
VALUE
-rb_ary_rassoc(ary, value)
- VALUE ary, value;
+rb_ary_rassoc(VALUE ary, VALUE value)
{
long i;
VALUE v;
@@ -2509,8 +2335,7 @@
*/
static VALUE
-rb_ary_equal(ary1, ary2)
- VALUE ary1, ary2;
+rb_ary_equal(VALUE ary1, VALUE ary2)
{
long i;
@@ -2538,8 +2363,7 @@
*/
static VALUE
-rb_ary_eql(ary1, ary2)
- VALUE ary1, ary2;
+rb_ary_eql(VALUE ary1, VALUE ary2)
{
long i;
@@ -2554,9 +2378,7 @@
}
static VALUE
-recursive_hash(ary, dummy, recur)
- VALUE ary, dummy;
- int recur;
+recursive_hash(VALUE ary, VALUE dummy, int recur)
{
long i, h;
VALUE n;
@@ -2582,8 +2404,7 @@
*/
static VALUE
-rb_ary_hash(ary)
- VALUE ary;
+rb_ary_hash(VALUE ary)
{
return rb_exec_recursive(recursive_hash, ary, 0);
}
@@ -2602,9 +2423,7 @@
*/
VALUE
-rb_ary_includes(ary, item)
- VALUE ary;
- VALUE item;
+rb_ary_includes(VALUE ary, VALUE item)
{
long i;
@@ -2638,8 +2457,7 @@
*/
VALUE
-rb_ary_cmp(ary1, ary2)
- VALUE ary1, ary2;
+rb_ary_cmp(VALUE ary1, VALUE ary2)
{
long i, len;
@@ -2661,8 +2479,7 @@
}
static VALUE
-ary_make_hash(ary1, ary2)
- VALUE ary1, ary2;
+ary_make_hash(VALUE ary1, VALUE ary2)
{
VALUE hash = rb_hash_new();
long i;
@@ -2691,8 +2508,7 @@
*/
static VALUE
-rb_ary_diff(ary1, ary2)
- VALUE ary1, ary2;
+rb_ary_diff(VALUE ary1, VALUE ary2)
{
VALUE ary3, hash;
long i;
@@ -2719,8 +2535,7 @@
static VALUE
-rb_ary_and(ary1, ary2)
- VALUE ary1, ary2;
+rb_ary_and(VALUE ary1, VALUE ary2)
{
VALUE hash, ary3, v, vv;
long i;
@@ -2752,8 +2567,7 @@
*/
static VALUE
-rb_ary_or(ary1, ary2)
- VALUE ary1, ary2;
+rb_ary_or(VALUE ary1, VALUE ary2)
{
VALUE hash, ary3;
VALUE v, vv;
@@ -2793,8 +2607,7 @@
*/
static VALUE
-rb_ary_uniq_bang(ary)
- VALUE ary;
+rb_ary_uniq_bang(VALUE ary)
{
VALUE hash, v, vv;
long i, j;
@@ -2826,8 +2639,7 @@
*/
static VALUE
-rb_ary_uniq(ary)
- VALUE ary;
+rb_ary_uniq(VALUE ary)
{
ary = rb_ary_dup(ary);
rb_ary_uniq_bang(ary);
@@ -2846,8 +2658,7 @@
*/
static VALUE
-rb_ary_compact_bang(ary)
- VALUE ary;
+rb_ary_compact_bang(VALUE ary)
{
VALUE *p, *t, *end;
@@ -2879,8 +2690,7 @@
*/
static VALUE
-rb_ary_compact(ary)
- VALUE ary;
+rb_ary_compact(VALUE ary)
{
ary = rb_ary_dup(ary);
rb_ary_compact_bang(ary);
@@ -2903,8 +2713,7 @@
*/
static VALUE
-rb_ary_nitems(ary)
- VALUE ary;
+rb_ary_nitems(VALUE ary)
{
long n = 0;
@@ -2929,10 +2738,7 @@
}
static long
-flatten(ary, idx, ary2, memo)
- VALUE ary;
- long idx;
- VALUE ary2, memo;
+flatten(VALUE ary, long idx, VALUE ary2, VALUE memo)
{
VALUE id;
long i = idx;
@@ -2974,8 +2780,7 @@
*/
static VALUE
-rb_ary_flatten_bang(ary)
- VALUE ary;
+rb_ary_flatten_bang(VALUE ary)
{
long i = 0;
int mod = 0;
@@ -3014,8 +2819,7 @@
*/
static VALUE
-rb_ary_flatten(ary)
- VALUE ary;
+rb_ary_flatten(VALUE ary)
{
ary = rb_ary_dup(ary);
rb_ary_flatten_bang(ary);
@@ -3031,7 +2835,7 @@
*/
void
-Init_Array()
+Init_Array(void)
{
rb_cArray = rb_define_class("Array", rb_cObject);
rb_include_module(rb_cArray, rb_mEnumerable);
Modified: trunk/bignum.c
===================================================================
--- trunk/bignum.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/bignum.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
bignum.c -
- $Author: matz $
- $Date: 2005/08/12 08:13:28 $
+ $Author: ocean $
+ $Date: 2005/09/14 06:32:29 $
created at: Fri Jun 10 00:48:55 JST 1994
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -39,14 +39,11 @@
#define BIGZEROP(x) (RBIGNUM(x)->len == 0 || (RBIGNUM(x)->len == 1 && BDIGITS(x)[0] == 0))
static VALUE
-bignew_1(klass, len, sign)
- VALUE klass;
- long len;
- char sign;
+bignew_1(VALUE klass, long len, int sign)
{
NEWOBJ(big, struct RBignum);
OBJSETUP(big, klass, T_BIGNUM);
- big->sign = sign;
+ big->sign = (char)sign;
big->len = len;
big->digits = ALLOC_N(BDIGIT, len);
@@ -56,8 +53,7 @@
#define bignew(len,sign) bignew_1(rb_cBignum,len,sign)
VALUE
-rb_big_clone(x)
- VALUE x;
+rb_big_clone(VALUE x)
{
VALUE z = bignew_1(CLASS_OF(x), RBIGNUM(x)->len, RBIGNUM(x)->sign);
@@ -88,15 +84,13 @@
}
void
-rb_big_2comp(x) /* get 2's complement */
- VALUE x;
+rb_big_2comp(VALUE x) /* get 2's complement */
{
get2comp(x);
}
static VALUE
-bignorm(x)
- VALUE x;
+bignorm(VALUE x)
{
if (!FIXNUM_P(x)) {
long len = RBIGNUM(x)->len;
@@ -122,15 +116,13 @@
}
VALUE
-rb_big_norm(x)
- VALUE x;
+rb_big_norm(VALUE x)
{
return bignorm(x);
}
VALUE
-rb_uint2big(n)
- unsigned long n;
+rb_uint2big(unsigned long n)
{
BDIGIT_DBL num = n;
long i = 0;
@@ -151,8 +143,7 @@
}
VALUE
-rb_int2big(n)
- long n;
+rb_int2big(long n)
{
long neg = 0;
VALUE big;
@@ -169,16 +160,14 @@
}
VALUE
-rb_uint2inum(n)
- unsigned long n;
+rb_uint2inum(unsigned long n)
{
if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_uint2big(n);
}
VALUE
-rb_int2inum(n)
- long n;
+rb_int2inum(long n)
{
if (FIXABLE(n)) return LONG2FIX(n);
return rb_int2big(n);
@@ -187,9 +176,7 @@
#ifdef HAVE_LONG_LONG
void
-rb_quad_pack(buf, val)
- char *buf;
- VALUE val;
+rb_quad_pack(char *buf, VALUE val)
{
LONG_LONG q;
@@ -216,9 +203,7 @@
}
VALUE
-rb_quad_unpack(buf, sign)
- const char *buf;
- int sign;
+rb_quad_unpack(const char *buf, int sign)
{
unsigned LONG_LONG q;
long neg = 0;
@@ -313,10 +298,7 @@
#endif
VALUE
-rb_cstr_to_inum(str, base, badcheck)
- const char *str;
- int base;
- int badcheck;
+rb_cstr_to_inum(const char *str, int base, int badcheck)
{
const char *s = str;
char *end;
@@ -508,10 +490,7 @@
}
VALUE
-rb_str_to_inum(str, base, badcheck)
- VALUE str;
- int base;
- int badcheck;
+rb_str_to_inum(VALUE str, int base, int badcheck)
{
char *s;
long len;
@@ -539,8 +518,7 @@
#if HAVE_LONG_LONG
VALUE
-rb_ull2big(n)
- unsigned LONG_LONG n;
+rb_ull2big(unsigned LONG_LONG n)
{
BDIGIT_DBL num = n;
long i = 0;
@@ -561,8 +539,7 @@
}
VALUE
-rb_ll2big(n)
- LONG_LONG n;
+rb_ll2big(LONG_LONG n)
{
long neg = 0;
VALUE big;
@@ -579,16 +556,14 @@
}
VALUE
-rb_ull2inum(n)
- unsigned LONG_LONG n;
+rb_ull2inum(unsigned LONG_LONG n)
{
if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_ull2big(n);
}
VALUE
-rb_ll2inum(n)
- LONG_LONG n;
+rb_ll2inum(LONG_LONG n)
{
if (FIXABLE(n)) return LONG2FIX(n);
return rb_ll2big(n);
@@ -597,26 +572,20 @@
#endif /* HAVE_LONG_LONG */
VALUE
-rb_cstr2inum(str, base)
- const char *str;
- int base;
+rb_cstr2inum(const char *str, int base)
{
return rb_cstr_to_inum(str, base, base==0);
}
VALUE
-rb_str2inum(str, base)
- VALUE str;
- int base;
+rb_str2inum(VALUE str, int base)
{
return rb_str_to_inum(str, base, base==0);
}
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
VALUE
-rb_big2str(x, base)
- VALUE x;
- int base;
+rb_big2str(VALUE x, int base)
{
volatile VALUE t;
BDIGIT *ds;
@@ -712,10 +681,7 @@
*/
static VALUE
-rb_big_to_s(argc, argv, x)
- int argc;
- VALUE *argv;
- VALUE x;
+rb_big_to_s(int argc, VALUE *argv, VALUE x)
{
VALUE b;
int base;
@@ -727,10 +693,7 @@
}
static unsigned long
-big2ulong(x, type, check)
- VALUE x;
- char *type;
- int check;
+big2ulong(VALUE x, char *type, int check)
{
long len = RBIGNUM(x)->len;
BDIGIT_DBL num;
@@ -751,8 +714,7 @@
}
unsigned long
-rb_big2ulong_pack(x)
- VALUE x;
+rb_big2ulong_pack(VALUE x)
{
unsigned long num = big2ulong(x, "unsigned long", Qfalse);
if (!RBIGNUM(x)->sign) {
@@ -762,8 +724,7 @@
}
unsigned long
-rb_big2ulong(x)
- VALUE x;
+rb_big2ulong(VALUE x)
{
unsigned long num = big2ulong(x, "unsigned long", Qtrue);
@@ -777,8 +738,7 @@
}
long
-rb_big2long(x)
- VALUE x;
+rb_big2long(VALUE x)
{
unsigned long num = big2ulong(x, "long", Qtrue);
@@ -792,9 +752,7 @@
#if HAVE_LONG_LONG
static unsigned LONG_LONG
-big2ull(x, type)
- VALUE x;
- char *type;
+big2ull(VALUE x, char *type)
{
long len = RBIGNUM(x)->len;
BDIGIT_DBL num;
@@ -812,8 +770,7 @@
}
unsigned LONG_LONG
-rb_big2ull(x)
- VALUE x;
+rb_big2ull(VALUE x)
{
unsigned LONG_LONG num = big2ull(x, "unsigned long long");
@@ -822,8 +779,7 @@
}
LONG_LONG
-rb_big2ll(x)
- VALUE x;
+rb_big2ll(VALUE x)
{
unsigned LONG_LONG num = big2ull(x, "long long");
@@ -838,8 +794,7 @@
#endif /* HAVE_LONG_LONG */
static VALUE
-dbl2big(d)
- double d;
+dbl2big(double d)
{
long i = 0;
BDIGIT c;
@@ -871,15 +826,13 @@
}
VALUE
-rb_dbl2big(d)
- double d;
+rb_dbl2big(double d)
{
return bignorm(dbl2big(d));
}
double
-rb_big2dbl(x)
- VALUE x;
+rb_big2dbl(VALUE x)
{
double d = 0.0;
long i = RBIGNUM(x)->len;
@@ -906,8 +859,7 @@
*/
static VALUE
-rb_big_to_f(x)
- VALUE x;
+rb_big_to_f(VALUE x)
{
return rb_float_new(rb_big2dbl(x));
}
@@ -923,8 +875,7 @@
*/
VALUE
-rb_big_cmp(x, y)
- VALUE x, y;
+rb_big_cmp(VALUE x, VALUE y)
{
long xlen = RBIGNUM(x)->len;
@@ -969,8 +920,7 @@
*/
VALUE
-rb_big_eq(x, y)
- VALUE x, y;
+rb_big_eq(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -1008,8 +958,7 @@
*/
static VALUE
-rb_big_eql(x, y)
- VALUE x, y;
+rb_big_eql(VALUE x, VALUE y)
{
if (TYPE(y) != T_BIGNUM) return Qfalse;
if (RBIGNUM(x)->sign != RBIGNUM(y)->sign) return Qfalse;
@@ -1026,8 +975,7 @@
*/
static VALUE
-rb_big_uminus(x)
- VALUE x;
+rb_big_uminus(VALUE x)
{
VALUE z = rb_big_clone(x);
@@ -1036,8 +984,6 @@
return bignorm(z);
}
-static VALUE bigadd _((VALUE,VALUE,char));
-
/*
* call-seq:
* ~big => integer
@@ -1051,8 +997,7 @@
*/
static VALUE
-rb_big_neg(x)
- VALUE x;
+rb_big_neg(VALUE x)
{
VALUE z = rb_big_clone(x);
BDIGIT *ds;
@@ -1071,8 +1016,7 @@
}
static VALUE
-bigsub(x, y)
- VALUE x, y;
+bigsub(VALUE x, VALUE y)
{
VALUE z = 0;
BDIGIT *zds;
@@ -1118,9 +1062,7 @@
}
static VALUE
-bigadd(x, y, sign)
- VALUE x, y;
- char sign;
+bigadd(VALUE x, VALUE y, int sign)
{
VALUE z;
BDIGIT_DBL num;
@@ -1170,8 +1112,7 @@
*/
VALUE
-rb_big_plus(x, y)
- VALUE x, y;
+rb_big_plus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -1196,8 +1137,7 @@
*/
VALUE
-rb_big_minus(x, y)
- VALUE x, y;
+rb_big_minus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -1215,8 +1155,7 @@
}
static VALUE
-rb_big_mul0(x, y)
- VALUE x, y;
+rb_big_mul0(VALUE x, VALUE y)
{
long i, j;
BDIGIT_DBL n = 0;
@@ -1267,16 +1206,13 @@
*/
VALUE
-rb_big_mul(x, y)
- VALUE x, y;
+rb_big_mul(VALUE x, VALUE y)
{
return bignorm(rb_big_mul0(x, y));
}
static void
-bigdivrem(x, y, divp, modp)
- VALUE x, y;
- VALUE *divp, *modp;
+bigdivrem(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
{
long nx = RBIGNUM(x)->len, ny = RBIGNUM(y)->len;
long i, j;
@@ -1404,9 +1340,7 @@
}
static void
-bigdivmod(x, y, divp, modp)
- VALUE x, y;
- VALUE *divp, *modp;
+bigdivmod(VALUE x, VALUE y, VALUE *divp, VALUE *modp)
{
VALUE mod;
@@ -1430,8 +1364,7 @@
*/
VALUE
-rb_big_div(x, y)
- VALUE x, y;
+rb_big_div(VALUE x, VALUE y)
{
VALUE z;
@@ -1464,8 +1397,7 @@
*/
VALUE
-rb_big_modulo(x, y)
- VALUE x, y;
+rb_big_modulo(VALUE x, VALUE y)
{
VALUE z;
@@ -1495,8 +1427,7 @@
* -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
*/
static VALUE
-rb_big_remainder(x, y)
- VALUE x, y;
+rb_big_remainder(VALUE x, VALUE y)
{
VALUE z;
@@ -1524,8 +1455,7 @@
*
*/
VALUE
-rb_big_divmod(x, y)
- VALUE x, y;
+rb_big_divmod(VALUE x, VALUE y)
{
VALUE div, mod;
@@ -1558,8 +1488,7 @@
*/
static VALUE
-rb_big_quo(x, y)
- VALUE x, y;
+rb_big_quo(VALUE x, VALUE y)
{
double dx = rb_big2dbl(x);
double dy;
@@ -1597,8 +1526,7 @@
*/
VALUE
-rb_big_pow(x, y)
- VALUE x, y;
+rb_big_pow(VALUE x, VALUE y)
{
double d;
long yy;
@@ -1647,8 +1575,7 @@
*/
VALUE
-rb_big_and(xx, yy)
- VALUE xx, yy;
+rb_big_and(VALUE xx, VALUE yy)
{
volatile VALUE x, y, z;
BDIGIT *ds1, *ds2, *zds;
@@ -1703,8 +1630,7 @@
*/
VALUE
-rb_big_or(xx, yy)
- VALUE xx, yy;
+rb_big_or(VALUE xx, VALUE yy)
{
volatile VALUE x, y, z;
BDIGIT *ds1, *ds2, *zds;
@@ -1761,8 +1687,7 @@
*/
VALUE
-rb_big_xor(xx, yy)
- VALUE xx, yy;
+rb_big_xor(VALUE xx, VALUE yy)
{
volatile VALUE x, y;
VALUE z;
@@ -1814,7 +1739,7 @@
return bignorm(z);
}
-static VALUE rb_big_rshift _((VALUE,VALUE));
+static VALUE rb_big_rshift(VALUE,VALUE);
/*
* call-seq:
@@ -1824,8 +1749,7 @@
*/
VALUE
-rb_big_lshift(x, y)
- VALUE x, y;
+rb_big_lshift(VALUE x, VALUE y)
{
BDIGIT *xds, *zds;
int shift = NUM2INT(y);
@@ -1860,8 +1784,7 @@
*/
static VALUE
-rb_big_rshift(x, y)
- VALUE x, y;
+rb_big_rshift(VALUE x, VALUE y)
{
BDIGIT *xds, *zds;
int shift = NUM2INT(y);
@@ -1921,8 +1844,7 @@
*/
static VALUE
-rb_big_aref(x, y)
- VALUE x, y;
+rb_big_aref(VALUE x, VALUE y)
{
BDIGIT *xds;
int shift;
@@ -1960,8 +1882,7 @@
*/
static VALUE
-rb_big_hash(x)
- VALUE x;
+rb_big_hash(VALUE x)
{
long i, len, key;
BDIGIT *digits;
@@ -1978,8 +1899,7 @@
*/
static VALUE
-rb_big_coerce(x, y)
- VALUE x, y;
+rb_big_coerce(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
@@ -2005,8 +1925,7 @@
*/
static VALUE
-rb_big_abs(x)
- VALUE x;
+rb_big_abs(VALUE x)
{
if (!RBIGNUM(x)->sign) {
x = rb_big_clone(x);
@@ -2016,9 +1935,7 @@
}
VALUE
-rb_big_rand(max, rand_buf)
- VALUE max;
- double *rand_buf;
+rb_big_rand(VALUE max, double *rand_buf)
{
VALUE v;
long len = RBIGNUM(max)->len;
@@ -2049,8 +1966,7 @@
*/
static VALUE
-rb_big_size(big)
- VALUE big;
+rb_big_size(VALUE big)
{
return LONG2FIX(RBIGNUM(big)->len*SIZEOF_BDIGITS);
}
@@ -2074,7 +1990,7 @@
*/
void
-Init_Bignum()
+Init_Bignum(void)
{
rb_cBignum = rb_define_class("Bignum", rb_cInteger);
Modified: trunk/class.c
===================================================================
--- trunk/class.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/class.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
class.c -
- $Author: nobu $
- $Date: 2005/05/16 13:28:54 $
+ $Author: ocean $
+ $Date: 2005/09/12 10:44:19 $
created at: Tue Aug 10 15:05:44 JST 1993
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -19,8 +19,7 @@
extern st_table *rb_class_tbl;
VALUE
-rb_class_boot(super)
- VALUE super;
+rb_class_boot(VALUE super)
{
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_CLASS);
@@ -35,8 +34,7 @@
}
void
-rb_check_inheritable(super)
- VALUE super;
+rb_check_inheritable(VALUE super)
{
if (TYPE(super) != T_CLASS) {
rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
@@ -48,8 +46,7 @@
}
VALUE
-rb_class_new(super)
- VALUE super;
+rb_class_new(VALUE super)
{
Check_Type(super, T_CLASS);
rb_check_inheritable(super);
@@ -60,10 +57,7 @@
}
static int
-clone_method(mid, body, tbl)
- ID mid;
- NODE *body;
- st_table *tbl;
+clone_method(ID mid, NODE *body, st_table *tbl)
{
st_insert(tbl, mid, (st_data_t)NEW_METHOD(body->nd_body, body->nd_noex));
return ST_CONTINUE;
@@ -71,8 +65,7 @@
/* :nodoc: */
VALUE
-rb_mod_init_copy(clone, orig)
- VALUE clone, orig;
+rb_mod_init_copy(VALUE clone, VALUE orig)
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
@@ -99,8 +92,7 @@
/* :nodoc: */
VALUE
-rb_class_init_copy(clone, orig)
- VALUE clone, orig;
+rb_class_init_copy(VALUE clone, VALUE orig)
{
if (RCLASS(clone)->super != 0) {
rb_raise(rb_eTypeError, "already initialized class");
@@ -112,8 +104,7 @@
}
VALUE
-rb_singleton_class_clone(obj)
- VALUE obj;
+rb_singleton_class_clone(VALUE obj)
{
VALUE klass = RBASIC(obj)->klass;
@@ -147,8 +138,7 @@
}
void
-rb_singleton_class_attached(klass, obj)
- VALUE klass, obj;
+rb_singleton_class_attached(VALUE klass, VALUE obj)
{
if (FL_TEST(klass, FL_SINGLETON)) {
if (!RCLASS(klass)->iv_tbl) {
@@ -159,8 +149,7 @@
}
VALUE
-rb_make_metaclass(obj, super)
- VALUE obj, super;
+rb_make_metaclass(VALUE obj, VALUE super)
{
if (BUILTIN_TYPE(obj) == T_CLASS && FL_TEST(obj, FL_SINGLETON)) {
return RBASIC(obj)->klass = rb_cClass;
@@ -183,9 +172,7 @@
}
VALUE
-rb_define_class_id(id, super)
- ID id;
- VALUE super;
+rb_define_class_id(ID id, VALUE super)
{
VALUE klass;
@@ -197,17 +184,14 @@
}
VALUE
-rb_class_inherited(super, klass)
- VALUE super, klass;
+rb_class_inherited(VALUE super, VALUE klass)
{
if (!super) super = rb_cObject;
return rb_funcall(super, rb_intern("inherited"), 1, klass);
}
VALUE
-rb_define_class(name, super)
- const char *name;
- VALUE super;
+rb_define_class(const char *name, VALUE super)
{
VALUE klass;
ID id;
@@ -236,10 +220,7 @@
}
VALUE
-rb_define_class_under(outer, name, super)
- VALUE outer;
- const char *name;
- VALUE super;
+rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
VALUE klass;
ID id;
@@ -268,7 +249,7 @@
}
VALUE
-rb_module_new()
+rb_module_new(void)
{
NEWOBJ(mdl, struct RClass);
OBJSETUP(mdl, rb_cModule, T_MODULE);
@@ -282,8 +263,7 @@
}
VALUE
-rb_define_module_id(id)
- ID id;
+rb_define_module_id(ID id)
{
VALUE mdl;
@@ -294,8 +274,7 @@
}
VALUE
-rb_define_module(name)
- const char *name;
+rb_define_module(const char *name)
{
VALUE module;
ID id;
@@ -315,9 +294,7 @@
}
VALUE
-rb_define_module_under(outer, name)
- VALUE outer;
- const char *name;
+rb_define_module_under(VALUE outer, const char *name)
{
VALUE module;
ID id;
@@ -338,8 +315,7 @@
}
static VALUE
-include_class_new(module, super)
- VALUE module, super;
+include_class_new(VALUE module, VALUE super)
{
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_ICLASS);
@@ -366,8 +342,7 @@
}
void
-rb_include_module(klass, module)
- VALUE klass, module;
+rb_include_module(VALUE klass, VALUE module)
{
VALUE p, c;
int changed = 0;
@@ -407,7 +382,8 @@
break;
}
}
- c = RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
+ RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
+ c = RCLASS(c)->super;
changed = 1;
skip:
module = RCLASS(module)->super;
@@ -433,8 +409,7 @@
*/
VALUE
-rb_mod_included_modules(mod)
- VALUE mod;
+rb_mod_included_modules(VALUE mod)
{
VALUE ary = rb_ary_new();
VALUE p;
@@ -467,9 +442,7 @@
*/
VALUE
-rb_mod_include_p(mod, mod2)
- VALUE mod;
- VALUE mod2;
+rb_mod_include_p(VALUE mod, VALUE mod2)
{
VALUE p;
@@ -499,8 +472,7 @@
*/
VALUE
-rb_mod_ancestors(mod)
- VALUE mod;
+rb_mod_ancestors(VALUE mod)
{
VALUE p, ary = rb_ary_new();
@@ -521,11 +493,7 @@
#define VISI_CHECK(x,f) (VISI(x) == (f))
static int
-ins_methods_push(name, type, ary, visi)
- ID name;
- long type;
- VALUE ary;
- long visi;
+ins_methods_push(ID name, long type, VALUE ary, long visi)
{
if (type == -1) return ST_CONTINUE;
switch (visi) {
@@ -545,46 +513,31 @@
}
static int
-ins_methods_i(name, type, ary)
- ID name;
- long type;
- VALUE ary;
+ins_methods_i(ID name, long type, VALUE ary)
{
return ins_methods_push(name, type, ary, -1); /* everything but private */
}
static int
-ins_methods_prot_i(name, type, ary)
- ID name;
- long type;
- VALUE ary;
+ins_methods_prot_i(ID name, long type, VALUE ary)
{
return ins_methods_push(name, type, ary, NOEX_PROTECTED);
}
static int
-ins_methods_priv_i(name, type, ary)
- ID name;
- long type;
- VALUE ary;
+ins_methods_priv_i(ID name, long type, VALUE ary)
{
return ins_methods_push(name, type, ary, NOEX_PRIVATE);
}
static int
-ins_methods_pub_i(name, type, ary)
- ID name;
- long type;
- VALUE ary;
+ins_methods_pub_i(ID name, long type, VALUE ary)
{
return ins_methods_push(name, type, ary, NOEX_PUBLIC);
}
static int
-method_entry(key, body, list)
- ID key;
- NODE *body;
- st_table *list;
+method_entry(ID key, NODE *body, st_table *list)
{
long type;
@@ -598,11 +551,7 @@
}
static VALUE
-class_instance_method_list(argc, argv, mod, func)
- int argc;
- VALUE *argv;
- VALUE mod;
- int (*func) _((ID, long, VALUE));
+class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
{
VALUE ary;
int recur;
@@ -659,10 +608,7 @@
*/
VALUE
-rb_class_instance_methods(argc, argv, mod)
- int argc;
- VALUE *argv;
- VALUE mod;
+rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
{
return class_instance_method_list(argc, argv, mod, ins_methods_i);
}
@@ -677,10 +623,7 @@
*/
VALUE
-rb_class_protected_instance_methods(argc, argv, mod)
- int argc;
- VALUE *argv;
- VALUE mod;
+rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
{
return class_instance_method_list(argc, argv, mod, ins_methods_prot_i);
}
@@ -703,10 +646,7 @@
*/
VALUE
-rb_class_private_instance_methods(argc, argv, mod)
- int argc;
- VALUE *argv;
- VALUE mod;
+rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
{
return class_instance_method_list(argc, argv, mod, ins_methods_priv_i);
}
@@ -721,10 +661,7 @@
*/
VALUE
-rb_class_public_instance_methods(argc, argv, mod)
- int argc;
- VALUE *argv;
- VALUE mod;
+rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
{
return class_instance_method_list(argc, argv, mod, ins_methods_pub_i);
}
@@ -762,10 +699,7 @@
*/
VALUE
-rb_obj_singleton_methods(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
{
VALUE recur, ary, klass;
st_table *list;
@@ -794,49 +728,31 @@
}
void
-rb_define_method_id(klass, name, func, argc)
- VALUE klass;
- ID name;
- VALUE (*func)();
- int argc;
+rb_define_method_id(VALUE klass, ID name, VALUE (*func) (/* ??? */), int argc)
{
rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC);
}
void
-rb_define_method(klass, name, func, argc)
- VALUE klass;
- const char *name;
- VALUE (*func)();
- int argc;
+rb_define_method(VALUE klass, const char *name, VALUE (*func) (/* ??? */), int argc)
{
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PUBLIC);
}
void
-rb_define_protected_method(klass, name, func, argc)
- VALUE klass;
- const char *name;
- VALUE (*func)();
- int argc;
+rb_define_protected_method(VALUE klass, const char *name, VALUE (*func) (/* ??? */), int argc)
{
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PROTECTED);
}
void
-rb_define_private_method(klass, name, func, argc)
- VALUE klass;
- const char *name;
- VALUE (*func)();
- int argc;
+rb_define_private_method(VALUE klass, const char *name, VALUE (*func) (/* ??? */), int argc)
{
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
}
void
-rb_undef_method(klass, name)
- VALUE klass;
- const char *name;
+rb_undef_method(VALUE klass, const char *name)
{
rb_add_method(klass, rb_intern(name), 0, NOEX_UNDEF);
}
@@ -848,8 +764,7 @@
} while (0)
VALUE
-rb_singleton_class(obj)
- VALUE obj;
+rb_singleton_class(VALUE obj)
{
VALUE klass;
@@ -884,77 +799,47 @@
}
void
-rb_define_singleton_method(obj, name, func, argc)
- VALUE obj;
- const char *name;
- VALUE (*func)();
- int argc;
+rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func) (/* ??? */), int argc)
{
rb_define_method(rb_singleton_class(obj), name, func, argc);
}
void
-rb_define_module_function(module, name, func, argc)
- VALUE module;
- const char *name;
- VALUE (*func)();
- int argc;
+rb_define_module_function(VALUE module, const char *name, VALUE (*func) (/* ??? */), int argc)
{
rb_define_private_method(module, name, func, argc);
rb_define_singleton_method(module, name, func, argc);
}
void
-rb_define_global_function(name, func, argc)
- const char *name;
- VALUE (*func)();
- int argc;
+rb_define_global_function(const char *name, VALUE (*func) (/* ??? */), int argc)
{
rb_define_module_function(rb_mKernel, name, func, argc);
}
void
-rb_define_alias(klass, name1, name2)
- VALUE klass;
- const char *name1, *name2;
+rb_define_alias(VALUE klass, const char *name1, const char *name2)
{
rb_alias(klass, rb_intern(name1), rb_intern(name2));
}
void
-rb_define_attr(klass, name, read, write)
- VALUE klass;
- const char *name;
- int read, write;
+rb_define_attr(VALUE klass, const char *name, int read, int write)
{
rb_attr(klass, rb_intern(name), read, write, Qfalse);
}
-#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
-#define va_init_list(a,b) va_start(a,b)
-#else
-#include <varargs.h>
-#define va_init_list(a,b) va_start(a)
-#endif
int
-#ifdef HAVE_STDARG_PROTOTYPES
rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
-#else
-rb_scan_args(argc, argv, fmt, va_alist)
- int argc;
- const VALUE *argv;
- const char *fmt;
- va_dcl
-#endif
{
int n, i = 0;
const char *p = fmt;
VALUE *var;
va_list vargs;
- va_init_list(vargs, fmt);
+ va_start(vargs, fmt);
if (*p == '*') goto rest_arg;
Modified: trunk/common.mk
===================================================================
--- trunk/common.mk 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/common.mk 2005-09-23 11:41:35 UTC (rev 257)
@@ -24,6 +24,8 @@
error.$(OBJEXT) \
euc_jp.$(OBJEXT) \
eval.$(OBJEXT) \
+ eval_proc.$(OBJEXT) \
+ eval_thread.$(OBJEXT) \
file.$(OBJEXT) \
gc.$(OBJEXT) \
hash.$(OBJEXT) \
@@ -248,10 +250,23 @@
{$(VPATH)}env.h {$(VPATH)}st.h
euc_jp.$(OBJEXT): {$(VPATH)}euc_jp.c {$(VPATH)}regenc.h \
{$(VPATH)}oniguruma.h
-eval.$(OBJEXT): {$(VPATH)}eval.c {$(VPATH)}ruby.h config.h \
+
+eval.$(OBJEXT): {$(VPATH)}eval.c {$(VPATH)}eval_intern.h \
+ {$(VPATH)}eval_method.h {$(VPATH)}eval_safe.h {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}node.h {$(VPATH)}env.h {$(VPATH)}util.h \
{$(VPATH)}rubysig.h {$(VPATH)}st.h {$(VPATH)}dln.h {$(VPATH)}yarv.h
+eval_thread.$(OBJEXT): {$(VPATH)}eval_thread.c {$(VPATH)}eval_intern.h \
+ {$(VPATH)}ruby.h config.h \
+ {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
+ {$(VPATH)}node.h {$(VPATH)}env.h {$(VPATH)}util.h \
+ {$(VPATH)}rubysig.h {$(VPATH)}st.h {$(VPATH)}dln.h {$(VPATH)}yarv.h
+eval_proc.$(OBJEXT): {$(VPATH)}eval_proc.c {$(VPATH)}eval_intern.h \
+ {$(VPATH)}ruby.h config.h \
+ {$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
+ {$(VPATH)}node.h {$(VPATH)}env.h {$(VPATH)}util.h \
+ {$(VPATH)}rubysig.h {$(VPATH)}st.h {$(VPATH)}dln.h {$(VPATH)}yarv.h
+
file.$(OBJEXT): {$(VPATH)}file.c {$(VPATH)}ruby.h config.h \
{$(VPATH)}defines.h {$(VPATH)}intern.h {$(VPATH)}missing.h \
{$(VPATH)}rubyio.h {$(VPATH)}rubysig.h {$(VPATH)}util.h \
@@ -421,6 +436,10 @@
aotc:
$(RUBY) -I$(srcdir) -I. $(srcdir)/rb/aotcompile.rb $(INSNS2VMOPT)
+# for GCC
+vm.asm:
+ $(CC) $(CFLAGS) $(CPPFLAGS) -S $(srcdir)/vm.c
+
run.gdb:
echo run > run.gdb
Modified: trunk/compar.c
===================================================================
--- trunk/compar.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/compar.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
compar.c -
- $Author: michal $
- $Date: 2004/06/22 06:30:41 $
+ $Author: matz $
+ $Date: 2005/09/12 15:23:54 $
created at: Thu Aug 26 14:39:48 JST 1993
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -17,8 +17,7 @@
static ID cmp;
int
-rb_cmpint(val, a, b)
- VALUE val, a, b;
+rb_cmpint(VALUE val, VALUE a, VALUE b)
{
if (NIL_P(val)) {
rb_cmperr(a, b);
@@ -34,8 +33,7 @@
}
void
-rb_cmperr(x, y)
- VALUE x, y;
+rb_cmperr(VALUE x, VALUE y)
{
const char *classname;
@@ -51,8 +49,7 @@
}
static VALUE
-cmp_eq(a)
- VALUE *a;
+cmp_eq(VALUE *a)
{
VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
@@ -62,7 +59,7 @@
}
static VALUE
-cmp_failed()
+cmp_failed(void)
{
return Qnil;
}
@@ -77,8 +74,7 @@
*/
static VALUE
-cmp_equal(x, y)
- VALUE x, y;
+cmp_equal(VALUE x, VALUE y)
{
VALUE a[2];
@@ -97,8 +93,7 @@
*/
static VALUE
-cmp_gt(x, y)
- VALUE x, y;
+cmp_gt(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
@@ -115,8 +110,7 @@
*/
static VALUE
-cmp_ge(x, y)
- VALUE x, y;
+cmp_ge(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
@@ -133,8 +127,7 @@
*/
static VALUE
-cmp_lt(x, y)
- VALUE x, y;
+cmp_lt(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
@@ -142,7 +135,6 @@
return Qfalse;
}
-
/*
* call-seq:
* obj <= other => true or false
@@ -152,8 +144,7 @@
*/
static VALUE
-cmp_le(x, y)
- VALUE x, y;
+cmp_le(VALUE x, VALUE y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
@@ -177,8 +168,7 @@
*/
static VALUE
-cmp_between(x, min, max)
- VALUE x, min, max;
+cmp_between(VALUE x, VALUE min, VALUE max)
{
if (RTEST(cmp_lt(x, min))) return Qfalse;
if (RTEST(cmp_gt(x, max))) return Qfalse;
@@ -223,7 +213,7 @@
*/
void
-Init_Comparable()
+Init_Comparable(void)
{
rb_mComparable = rb_define_module("Comparable");
rb_define_method(rb_mComparable, "==", cmp_equal, 1);
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/compile.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -206,7 +206,7 @@
ADD_LABEL(list_anchor, iseqobj->compile_data->end_label);
}
else if(iseqobj->type == ISEQ_TYPE_TOP){
- set_localtbl(iseqobj, ruby_scope->local_tbl);
+ set_localtbl(iseqobj, GET_THREAD()->top_local_tbl);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
COMPILE(list_anchor, "top level node", node);
}
Modified: trunk/defines.h
===================================================================
--- trunk/defines.h 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/defines.h 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
defines.h -
- $Author: akr $
- $Date: 2005/07/02 08:11:24 $
+ $Author: ocean $
+ $Date: 2005/09/14 06:32:30 $
created at: Wed May 18 00:21:44 JST 1994
************************************************/
@@ -46,10 +46,10 @@
#define xrealloc ruby_xrealloc
#define xfree ruby_xfree
-void *xmalloc _((long));
-void *xcalloc _((long,long));
-void *xrealloc _((void*,long));
-void xfree _((void*));
+void *xmalloc(long);
+void *xcalloc(long,long);
+void *xrealloc(void*,long);
+void xfree(void*);
#if SIZEOF_LONG_LONG > 0
# define LONG_LONG long long
Modified: trunk/dir.c
===================================================================
--- trunk/dir.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/dir.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
dir.c -
- $Author: matz $
- $Date: 2005/07/27 07:27:19 $
+ $Author: nobu $
+ $Date: 2005/09/16 13:46:03 $
created at: Wed Jan 5 09:51:01 JST 1994
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -56,7 +56,7 @@
#endif
#ifndef HAVE_STRING_H
-char *strchr _((char*,char));
+char *strchr(char*,char);
#endif
#include <ctype.h>
@@ -105,10 +105,7 @@
# define Inc(p) ((p) = Next(p))
# define Compare(p1, p2) (CompareImpl(p1, p2, nocase))
static int
-CompareImpl(p1, p2, nocase)
- const char *p1;
- const char *p2;
- int nocase;
+CompareImpl(const char *p1, const char *p2, int nocase)
{
const int len1 = Next(p1) - p1;
const int len2 = Next(p2) - p2;
@@ -165,10 +162,10 @@
#endif /* environment */
static char *
-bracket(p, s, flags)
- const char *p; /* pattern (next to '[') */
- const char *s; /* string */
- int flags;
+bracket(
+ const char *p, /* pattern (next to '[') */
+ const char *s, /* string */
+ int flags)
{
const int nocase = flags & FNM_CASEFOLD;
const int escape = !(flags & FNM_NOESCAPE);
@@ -215,10 +212,10 @@
#define RETURN(val) return *pcur = p, *scur = s, (val);
static int
-fnmatch_helper(pcur, scur, flags)
- const char **pcur; /* pattern */
- const char **scur; /* string */
- int flags;
+fnmatch_helper(
+ const char **pcur, /* pattern */
+ const char **scur, /* string */
+ int flags)
{
const int period = !(flags & FNM_DOTMATCH);
const int pathname = flags & FNM_PATHNAME;
@@ -292,10 +289,10 @@
}
static int
-fnmatch(p, s, flags)
- const char *p; /* pattern */
- const char *s; /* string */
- int flags;
+fnmatch(
+ const char *p, /* pattern */
+ const char *s, /* string */
+ int flags)
{
const int period = !(flags & FNM_DOTMATCH);
const int pathname = flags & FNM_PATHNAME;
@@ -345,8 +342,7 @@
};
static void
-free_dir(dir)
- struct dir_data *dir;
+free_dir(struct dir_data *dir)
{
if (dir) {
if (dir->dir) closedir(dir->dir);
@@ -355,12 +351,10 @@
free(dir);
}
-static VALUE dir_close _((VALUE));
+static VALUE dir_close(VALUE);
-static VALUE dir_s_alloc _((VALUE));
static VALUE
-dir_s_alloc(klass)
- VALUE klass;
+dir_s_alloc(VALUE klass)
{
struct dir_data *dirp;
VALUE obj = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dirp);
@@ -378,8 +372,7 @@
* Returns a new directory object for the named directory.
*/
static VALUE
-dir_initialize(dir, dirname)
- VALUE dir, dirname;
+dir_initialize(VALUE dir, VALUE dirname)
{
struct dir_data *dp;
@@ -416,8 +409,7 @@
* block.
*/
static VALUE
-dir_s_open(klass, dirname)
- VALUE klass, dirname;
+dir_s_open(VALUE klass, VALUE dirname)
{
struct dir_data *dp;
VALUE dir = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dp);
@@ -431,7 +423,7 @@
}
static void
-dir_closed()
+dir_closed(void)
{
rb_raise(rb_eIOError, "closed directory");
}
@@ -448,8 +440,7 @@
* Return a string describing this Dir object.
*/
static VALUE
-dir_inspect(dir)
- VALUE dir;
+dir_inspect(VALUE dir)
{
struct dir_data *dirp;
@@ -474,8 +465,7 @@
* d.path #=> ".."
*/
static VALUE
-dir_path(dir)
- VALUE dir;
+dir_path(VALUE dir)
{
struct dir_data *dirp;
@@ -497,8 +487,7 @@
* d.read #=> "config.h"
*/
static VALUE
-dir_read(dir)
- VALUE dir;
+dir_read(VALUE dir)
{
struct dir_data *dirp;
struct dirent *dp;
@@ -536,12 +525,12 @@
* Got main.rb
*/
static VALUE
-dir_each(dir)
- VALUE dir;
+dir_each(VALUE dir)
{
struct dir_data *dirp;
struct dirent *dp;
+ RETURN_ENUMERATOR(dir, 0, 0);
GetDIR(dir, dirp);
rewinddir(dirp->dir);
for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
@@ -565,8 +554,7 @@
* d.tell #=> 12
*/
static VALUE
-dir_tell(dir)
- VALUE dir;
+dir_tell(VALUE dir)
{
#ifdef HAVE_TELLDIR
struct dir_data *dirp;
@@ -595,8 +583,7 @@
* d.read #=> ".."
*/
static VALUE
-dir_seek(dir, pos)
- VALUE dir, pos;
+dir_seek(VALUE dir, VALUE pos)
{
struct dir_data *dirp;
off_t p = NUM2OFFT(pos);
@@ -625,8 +612,7 @@
* d.read #=> ".."
*/
static VALUE
-dir_set_pos(dir, pos)
- VALUE dir, pos;
+dir_set_pos(VALUE dir, VALUE pos)
{
dir_seek(dir, pos);
return pos;
@@ -644,8 +630,7 @@
* d.read #=> "."
*/
static VALUE
-dir_rewind(dir)
- VALUE dir;
+dir_rewind(VALUE dir)
{
struct dir_data *dirp;
@@ -665,8 +650,7 @@
* d.close #=> nil
*/
static VALUE
-dir_close(dir)
- VALUE dir;
+dir_close(VALUE dir)
{
struct dir_data *dirp;
@@ -678,8 +662,7 @@
}
static void
-dir_chdir(path)
- VALUE path;
+dir_chdir(VALUE path)
{
if (chdir(RSTRING(path)->ptr) < 0)
rb_sys_fail(RSTRING(path)->ptr);
@@ -694,8 +677,7 @@
};
static VALUE
-chdir_yield(args)
- struct chdir_data *args;
+chdir_yield(struct chdir_data *args)
{
dir_chdir(args->new_path);
args->done = Qtrue;
@@ -706,8 +688,7 @@
}
static VALUE
-chdir_restore(args)
- struct chdir_data *args;
+chdir_restore(struct chdir_data *args)
{
if (args->done) {
chdir_blocking--;
@@ -758,10 +739,7 @@
* /var/spool/mail
*/
static VALUE
-dir_s_chdir(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+dir_s_chdir(int argc, VALUE *argv, VALUE obj)
{
VALUE path = Qnil;
@@ -809,8 +787,7 @@
* Dir.getwd #=> "/tmp"
*/
static VALUE
-dir_s_getwd(dir)
- VALUE dir;
+dir_s_getwd(VALUE dir)
{
char *path;
VALUE cwd;
@@ -823,10 +800,8 @@
return cwd;
}
-static void check_dirname _((volatile VALUE *));
static void
-check_dirname(dir)
- volatile VALUE *dir;
+check_dirname(volatile VALUE *dir)
{
char *path, *pend;
@@ -848,8 +823,7 @@
* information.
*/
static VALUE
-dir_s_chroot(dir, path)
- VALUE dir, path;
+dir_s_chroot(VALUE dir, VALUE path)
{
#if defined(HAVE_CHROOT) && !defined(__CHECKER__)
check_dirname(&path);
@@ -878,10 +852,7 @@
*
*/
static VALUE
-dir_s_mkdir(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
{
VALUE path, vmode;
int mode;
@@ -910,8 +881,7 @@
* <code>SystemCallError</code> if the directory isn't empty.
*/
static VALUE
-dir_s_rmdir(obj, dir)
- VALUE obj, dir;
+dir_s_rmdir(VALUE obj, VALUE dir)
{
check_dirname(&dir);
if (rmdir(RSTRING(dir)->ptr) < 0)
@@ -920,47 +890,45 @@
return INT2FIX(0);
}
+#define GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1))
+#define sys_warning(val) \
+ ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)(VALUE))rb_sys_warning, (VALUE)(val), 0))
+
/* System call with warning */
static int
-do_stat(path, pst)
- const char *path;
- struct stat *pst;
+do_stat(const char *path, struct stat *pst, int flags)
+
{
int ret = stat(path, pst);
if (ret < 0 && errno != ENOENT)
- rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)path, 0);
+ sys_warning(path);
return ret;
}
static int
-do_lstat(path, pst)
- const char *path;
- struct stat *pst;
+do_lstat(const char *path, struct stat *pst, int flags)
{
int ret = lstat(path, pst);
if (ret < 0 && errno != ENOENT)
- rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)path, 0);
+ sys_warning(path);
return ret;
}
static DIR *
-do_opendir(path)
- const char *path;
+do_opendir(const char *path, int flags)
{
DIR *dirp = opendir(path);
if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
- rb_protect((VALUE (*)_((VALUE)))rb_sys_warning, (VALUE)path, 0);
+ sys_warning(path);
return dirp;
}
/* Return nonzero if S has any special globbing chars in it. */
static int
-has_magic(s, flags)
- const char *s;
- int flags;
+has_magic(const char *s, int flags)
{
const int escape = !(flags & FNM_NOESCAPE);
@@ -988,9 +956,7 @@
/* Find separator in globbing pattern. */
static char *
-find_dirsep(s, flags)
- const char *s;
- int flags;
+find_dirsep(const char *s, int flags)
{
const int escape = !(flags & FNM_NOESCAPE);
@@ -1026,8 +992,7 @@
/* Remove escaping baskclashes */
static void
-remove_backslashes(p)
- char *p;
+remove_backslashes(char *p)
{
char *t = p;
char *s = p;
@@ -1059,9 +1024,7 @@
};
static struct glob_pattern *
-glob_make_pattern(p, flags)
- const char *p;
- int flags;
+glob_make_pattern(const char *p, int flags)
{
struct glob_pattern *list, *tmp, **tail = &list;
int dirsep = 0; /* pattern is terminated with '/' */
@@ -1105,8 +1068,7 @@
}
static void
-glob_free_pattern(list)
- struct glob_pattern *list;
+glob_free_pattern(struct glob_pattern *list)
{
while (list) {
struct glob_pattern *tmp = list;
@@ -1118,10 +1080,7 @@
}
static char *
-join_path(path, dirsep, name)
- const char *path;
- int dirsep;
- const char *name;
+join_path(const char *path, int dirsep, const char *name)
{
long len = strlen(path);
char *buf = ALLOC_N(char, len+strlen(name)+(dirsep?1:0)+1);
@@ -1150,51 +1109,33 @@
#endif
struct glob_args {
- void (*func) _((const char *, VALUE));
- const char *c;
- VALUE v;
+ void (*func)(const char *, VALUE);
+ const char *path;
+ VALUE value;
};
-static VALUE glob_func_caller _((VALUE));
-
static VALUE
-glob_func_caller(val)
- VALUE val;
+glob_func_caller(VALUE val)
{
struct glob_args *args = (struct glob_args *)val;
- (*args->func)(args->c, args->v);
+ (*args->func)(args->path, args->value);
return Qnil;
}
-static int
-glob_call_func(func, path, arg)
- void (*func) _((const char *, VALUE));
- const char *path;
- VALUE arg;
-{
- int status;
- struct glob_args args;
+#define glob_call_func(func, path, arg) (*func)(path, arg)
- args.func = func;
- args.c = path;
- args.v = arg;
-
- rb_protect(glob_func_caller, (VALUE)&args, &status);
- return status;
-}
-
static int
-glob_helper(path, dirsep, exist, isdir, beg, end, flags, func, arg)
- const char *path;
- int dirsep; /* '/' should be placed before appending child entry's name to 'path'. */
- enum answer exist; /* Does 'path' indicate an existing entry? */
- enum answer isdir; /* Does 'path' indicate a directory or a symlink to a directory? */
- struct glob_pattern **beg;
- struct glob_pattern **end;
- int flags;
- void (*func) _((const char *, VALUE));
- VALUE arg;
+glob_helper(
+ const char *path,
+ int dirsep, /* '/' should be placed before appending child entry's name to 'path'. */
+ enum answer exist, /* Does 'path' indicate an existing entry? */
+ enum answer isdir, /* Does 'path' indicate a directory or a symlink to a directory? */
+ struct glob_pattern **beg,
+ struct glob_pattern **end,
+ int flags,
+ ruby_glob_func *func,
+ VALUE arg)
{
struct stat st;
int status = 0;
@@ -1228,7 +1169,7 @@
if (*path) {
if (match_all && exist == UNKNOWN) {
- if (do_lstat(path, &st) == 0) {
+ if (do_lstat(path, &st, flags) == 0) {
exist = YES;
isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
}
@@ -1238,7 +1179,7 @@
}
}
if (match_dir && isdir == UNKNOWN) {
- if (do_stat(path, &st) == 0) {
+ if (do_stat(path, &st, flags) == 0) {
exist = YES;
isdir = S_ISDIR(st.st_mode) ? YES : NO;
}
@@ -1263,7 +1204,7 @@
if (magical || recursive) {
struct dirent *dp;
- DIR *dirp = do_opendir(*path ? path : ".");
+ DIR *dirp = do_opendir(*path ? path : ".", flags);
if (dirp == NULL) return 0;
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
@@ -1273,7 +1214,7 @@
if (recursive && strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0
&& fnmatch("*", dp->d_name, flags) == 0) {
#ifndef _WIN32
- if (do_lstat(buf, &st) == 0)
+ if (do_lstat(buf, &st, flags) == 0)
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
else
new_isdir = NO;
@@ -1345,11 +1286,7 @@
}
static int
-rb_glob2(path, flags, func, arg)
- const char *path;
- int flags;
- void (*func) _((const char *, VALUE));
- VALUE arg;
+ruby_glob0(const char *path, int flags, ruby_glob_func *func, VALUE arg)
{
struct glob_pattern *list;
const char *root, *start;
@@ -1357,10 +1294,6 @@
int n;
int status;
- if (flags & FNM_CASEFOLD) {
- rb_warn("Dir.glob() ignores File::FNM_CASEFOLD");
- }
-
start = root = path;
#if defined DOSISH
flags |= FNM_CASEFOLD;
@@ -1384,54 +1317,53 @@
return status;
}
-struct rb_glob_args {
- void (*func) _((const char*, VALUE));
- VALUE arg;
-};
-
-static VALUE
-rb_glob_caller(path, a)
- const char *path;
- VALUE a;
+int
+ruby_glob(const char *path, int flags, ruby_glob_func *func, VALUE arg)
{
- struct rb_glob_args *args = (struct rb_glob_args *)a;
- (*args->func)(path, args->arg);
- return Qnil;
+ return ruby_glob0(path, flags & ~GLOB_VERBOSE, func, arg);
}
-void
-rb_glob(path, func, arg)
- const char *path;
- void (*func) _((const char*, VALUE));
- VALUE arg;
+static int
+rb_glob_caller(const char *path, VALUE a)
{
- struct rb_glob_args args;
int status;
+ struct glob_args *args = (struct glob_args *)a;
+ args->path = path;
+ rb_protect(glob_func_caller, a, &status);
+ return status;
+}
+
+static int
+rb_glob2(const char *path, int flags, void (*func)(const char *, VALUE), VALUE arg)
+{
+ struct glob_args args;
+
args.func = func;
- args.arg = arg;
- status = rb_glob2(path, 0, rb_glob_caller, &args);
+ args.value = arg;
+ if (flags & FNM_CASEFOLD) {
+ rb_warn("Dir.glob() ignores File::FNM_CASEFOLD");
+ }
+
+ return ruby_glob0(path, flags | GLOB_VERBOSE, rb_glob_caller, (VALUE)&args);
+}
+
+void
+rb_glob(const char *path, void (*func)(const char *, VALUE), VALUE arg)
+{
+ int status = rb_glob2(path, 0, func, arg);
if (status) rb_jump_tag(status);
}
static void
-push_pattern(path, ary)
- const char *path;
- VALUE ary;
+push_pattern(const char *path, VALUE ary)
{
rb_ary_push(ary, rb_tainted_str_new2(path));
}
-static int
-push_glob(VALUE ary, const char *str, long offset, int flags);
-
-static int
-push_glob(ary, str, offset, flags)
- VALUE ary;
- const char *str;
- long offset;
- int flags;
+int
+ruby_brace_expand(const char *str, int flags, ruby_glob_func *func, VALUE arg)
{
const int escape = !(flags & FNM_NOESCAPE);
const char *p = str;
@@ -1454,11 +1386,9 @@
}
if (lbrace && rbrace) {
- volatile VALUE buffer = rb_str_new(0, strlen(s));
- char *buf;
+ char *buf = ALLOC_N(char, strlen(s) + 1);
long shift;
- buf = RSTRING(buffer)->ptr;
memcpy(buf, s, lbrace-s);
shift = (lbrace-s);
p = lbrace;
@@ -1475,22 +1405,62 @@
}
memcpy(buf+shift, t, p-t);
strcpy(buf+shift+(p-t), rbrace+1);
- status = push_glob(ary, buf, offset, flags);
+ status = ruby_brace_expand(buf, flags, func, arg);
if (status) break;
}
+ free(buf);
}
else if (!lbrace && !rbrace) {
- status = rb_glob2(s, flags, push_pattern, ary);
+ status = (*func)(s, arg);
}
return status;
}
-static VALUE
-rb_push_glob(str, flags) /* '\0' is delimiter */
- VALUE str;
+struct brace_args {
+ ruby_glob_func *func;
+ VALUE value;
int flags;
+};
+
+static int
+glob_brace(const char *path, VALUE val)
{
+ struct brace_args *arg = (struct brace_args *)val;
+
+ return ruby_glob0(path, arg->flags, arg->func, arg->value);
+}
+
+static int
+ruby_brace_glob0(const char *str, int flags, ruby_glob_func *func, VALUE arg)
+{
+ struct brace_args args;
+
+ args.func = func;
+ args.value = arg;
+ args.flags = flags;
+ return ruby_brace_expand(str, flags, glob_brace, (VALUE)&args);
+}
+
+int
+ruby_brace_glob(const char *str, int flags, ruby_glob_func *func, VALUE arg)
+{
+ return ruby_brace_glob0(str, flags & ~GLOB_VERBOSE, func, arg);
+}
+
+static int
+push_glob(VALUE ary, const char *str, int flags)
+{
+ struct glob_args args;
+
+ args.func = push_pattern;
+ args.value = ary;
+ return ruby_brace_glob0(str, flags | GLOB_VERBOSE, rb_glob_caller, (VALUE)&args);
+}
+
+static VALUE
+rb_push_glob(VALUE str, int flags) /* '\0' is delimiter */
+{
long offset = 0;
VALUE ary;
@@ -1499,9 +1469,10 @@
ary = rb_ary_new();
while (offset < RSTRING(str)->len) {
- int status = push_glob(ary, RSTRING(str)->ptr, offset, flags);
+ int status = push_glob(ary, RSTRING(str)->ptr + offset, flags);
char *p, *pend;
if (status) rb_jump_tag(status);
+ if (offset >= RSTRING(str)->len) break;
p = RSTRING(str)->ptr + offset;
p += strlen(p) + 1;
pend = RSTRING(str)->ptr + RSTRING(str)->len;
@@ -1510,39 +1481,57 @@
offset = p - RSTRING(str)->ptr;
}
- if (rb_block_given_p()) {
- rb_ary_each(ary);
- return Qnil;
+ return ary;
+}
+
+static VALUE
+dir_globs(long argc, VALUE *argv, int flags)
+{
+ VALUE ary = rb_ary_new();
+ long i;
+
+ for (i = 0; i < argc; ++i) {
+ int status;
+ VALUE str = argv[i];
+ FilePathValue(str);
+ status = push_glob(ary, RSTRING(str)->ptr, flags);
+ if (status) rb_jump_tag(status);
}
+
return ary;
}
/*
* call-seq:
- * Dir[ string ] => array
+ * Dir[ array ] => array
+ * Dir[ string [, string ...] ] => array
*
* Equivalent to calling
- * <em>dir</em>.<code>glob(</code><i>string,</i><code>0)</code>.
+ * <code>Dir.glob(</code><i>array,</i><code>0)</code> and
+ * <code>Dir.glob([</code><i>string,...</i><code>],0)</code>.
*
*/
static VALUE
-dir_s_aref(obj, str)
- VALUE obj, str;
+dir_s_aref(int argc, VALUE *argv, VALUE obj)
{
- return rb_push_glob(str, 0);
+ if (argc == 1) {
+ return rb_push_glob(argv[0], 0);
+ }
+ return dir_globs(argc, argv, 0);
}
/*
* call-seq:
- * Dir.glob( string, [flags] ) => array
- * Dir.glob( string, [flags] ) {| filename | block } => nil
+ * Dir.glob( pattern, [flags] ) => array
+ * Dir.glob( pattern, [flags] ) {| filename | block } => nil
*
- * Returns the filenames found by expanding the pattern given in
- * <i>string</i>, either as an <i>array</i> or as parameters to the
- * block. Note that this pattern is not a regexp (it's closer to a
- * shell glob). See <code>File::fnmatch</code> for the meaning of
- * the <i>flags</i> parameter. Note that case sensitivity
- * depends on your system (so <code>File::FNM_CASEFOLD</code> is ignored)
+ * Returns the filenames found by expanding <i>pattern</i> which is
+ * an +Array+ of the patterns or the pattern +String+, either as an
+ * <i>array</i> or as parameters to the block. Note that this pattern
+ * is not a regexp (it's closer to a shell glob). See
+ * <code>File::fnmatch</code> for the meaning of the <i>flags</i>
+ * parameter. Note that case sensitivity depends on your system (so
+ * <code>File::FNM_CASEFOLD</code> is ignored)
*
* <code>*</code>:: Matches any file. Can be restricted by
* other values in the glob. <code>*</code>
@@ -1592,12 +1581,9 @@
* Dir.glob(librbfiles) #=> ["lib/song.rb"]
*/
static VALUE
-dir_s_glob(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+dir_s_glob(int argc, VALUE *argv, VALUE obj)
{
- VALUE str, rflags;
+ VALUE str, rflags, ary;
int flags;
if (rb_scan_args(argc, argv, "11", &str, &rflags) == 2)
@@ -1605,12 +1591,24 @@
else
flags = 0;
- return rb_push_glob(str, flags);
+ ary = rb_check_array_type(str);
+ if (NIL_P(ary)) {
+ ary = rb_push_glob(str, flags);
+ }
+ else {
+ volatile VALUE v = ary;
+ ary = dir_globs(RARRAY(ary)->len, RARRAY(ary)->ptr, flags);
+ }
+
+ if (rb_block_given_p()) {
+ rb_ary_each(ary);
+ return Qnil;
+ }
+ return ary;
}
static VALUE
-dir_open_dir(path)
- VALUE path;
+dir_open_dir(VALUE path)
{
VALUE dir = rb_funcall(rb_cDir, rb_intern("open"), 1, path);
@@ -1641,8 +1639,7 @@
*
*/
static VALUE
-dir_foreach(io, dirname)
- VALUE io, dirname;
+dir_foreach(VALUE io, VALUE dirname)
{
VALUE dir;
@@ -1663,8 +1660,7 @@
*
*/
static VALUE
-dir_entries(io, dirname)
- VALUE io, dirname;
+dir_entries(VALUE io, VALUE dirname)
{
VALUE dir;
@@ -1752,10 +1748,7 @@
* File.fnmatch('** IGNORE /foo', 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
*/
static VALUE
-file_s_fnmatch(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+file_s_fnmatch(int argc, VALUE *argv, VALUE obj)
{
VALUE pattern, path;
VALUE rflags;
@@ -1787,7 +1780,7 @@
* (<code>.</code>).
*/
void
-Init_Dir()
+Init_Dir(void)
{
rb_cDir = rb_define_class("Dir", rb_cObject);
@@ -1820,7 +1813,7 @@
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_aref, 1);
+ rb_define_singleton_method(rb_cDir,"[]", dir_s_aref, -1);
rb_define_singleton_method(rb_cFile,"fnmatch", file_s_fnmatch, -1);
rb_define_singleton_method(rb_cFile,"fnmatch?", file_s_fnmatch, -1);
Modified: trunk/dln.c
===================================================================
--- trunk/dln.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/dln.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
dln.c -
- $Author: matz $
- $Date: 2005/07/19 08:31:04 $
+ $Author: ocean $
+ $Date: 2005/09/12 11:03:24 $
created at: Tue Jan 18 17:05:06 JST 1994
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -89,7 +89,7 @@
# include <image.h>
#endif
-int eaccess();
+int eaccess(const char *, int);
#ifndef NO_DLN_LOAD
@@ -107,9 +107,7 @@
#endif
static int
-init_funcname_len(buf, file)
- char **buf;
- const char *file;
+init_funcname_len(char **buf, const char *file)
{
char *p;
const char *slash;
@@ -1161,7 +1159,7 @@
#endif
static const char *
-dln_strerror()
+dln_strerror(void)
{
#ifdef USE_DLN_A_OUT
char *strerror();
@@ -1262,8 +1260,7 @@
#endif /* NO_DLN_LOAD */
void*
-dln_load(file)
- const char *file;
+dln_load(const char *file)
{
#ifdef NO_DLN_LOAD
rb_raise(rb_eLoadError, "this executable file can't load extension libraries");
@@ -1606,12 +1603,10 @@
return 0; /* dummy return */
}
-static char *dln_find_1();
+static char *dln_find_1(const char *fname, const char *path, int exe_flag);
char *
-dln_find_exe(fname, path)
- const char *fname;
- const char *path;
+dln_find_exe(const char *fname, const char *path)
{
if (!path) {
path = getenv(PATH_ENV);
@@ -1628,9 +1623,7 @@
}
char *
-dln_find_file(fname, path)
- const char *fname;
- const char *path;
+dln_find_file(const char *fname, const char *path)
{
#ifndef __MACOS__
if (!path) path = ".";
@@ -1672,34 +1665,33 @@
static char fbuf[MAXPATHLEN];
static char *
-dln_find_1(fname, path, exe_flag)
- char *fname;
- char *path;
- int exe_flag; /* non 0 if looking for executable. */
+dln_find_1(const char *fname, const char *path, int exe_flag /* non 0 if looking for executable. */)
{
- register char *dp;
- register char *ep;
+ register const char *dp;
+ register const char *ep;
register char *bp;
struct stat st;
#ifdef __MACOS__
const char* mac_fullpath;
#endif
- if (!fname) return fname;
- if (fname[0] == '/') return fname;
- if (strncmp("./", fname, 2) == 0 || strncmp("../", fname, 3) == 0)
- return fname;
- if (exe_flag && strchr(fname, '/')) return fname;
+#define RETURN_IF(expr) if (expr) return (char *)fname;
+
+ RETURN_IF(!fname);
+ RETURN_IF(fname[0] == '/');
+ RETURN_IF(strncmp("./", fname, 2) == 0 || strncmp("../", fname, 3) == 0);
+ RETURN_IF(exe_flag && strchr(fname, '/'));
#ifdef DOSISH
- if (fname[0] == '\\') return fname;
+ RETURN_IF(fname[0] == '\\');
# ifdef DOSISH_DRIVE_LETTER
- if (strlen(fname) > 2 && fname[1] == ':') return fname;
+ RETURN_IF(strlen(fname) > 2 && fname[1] == ':');
# endif
- if (strncmp(".\\", fname, 2) == 0 || strncmp("..\\", fname, 3) == 0)
- return fname;
- if (exe_flag && strchr(fname, '\\')) return fname;
+ RETURN_IF(strncmp(".\\", fname, 2) == 0 || strncmp("..\\", fname, 3) == 0);
+ RETURN_IF(exe_flag && strchr(fname, '\\'));
#endif
+#undef RETURN_IF
+
for (dp = path;; dp = ++ep) {
register int l;
int i;
Modified: trunk/dln.h
===================================================================
--- trunk/dln.h 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/dln.h 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
dln.h -
- $Author: michal $
- $Date: 2003/01/16 07:34:01 $
+ $Author: ocean $
+ $Date: 2005/09/14 06:32:30 $
created at: Wed Jan 19 16:53:09 JST 1994
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -29,12 +29,12 @@
# define _(args) ()
#endif
-char *dln_find_exe _((const char*,const char*));
-char *dln_find_file _((const char*,const char*));
+char *dln_find_exe(const char*,const char*);
+char *dln_find_file(const char*,const char*);
#ifdef USE_DLN_A_OUT
extern char *dln_argv0;
#endif
-void *dln_load _((const char*));
+void *dln_load(const char*);
#endif
Modified: trunk/dmyext.c
===================================================================
--- trunk/dmyext.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/dmyext.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -1,4 +1,4 @@
void
-Init_ext()
+Init_ext(void)
{
}
Modified: trunk/enum.c
===================================================================
--- trunk/enum.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/enum.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
enum.c -
- $Author: nobu $
- $Date: 2005/07/14 16:18:44 $
+ $Author: ocean $
+ $Date: 2005/09/12 10:44:19 $
created at: Fri Oct 1 15:15:19 JST 1993
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -17,25 +17,14 @@
VALUE rb_mEnumerable;
static ID id_each, id_eqq, id_cmp;
-static VALUE
-enumeratorize(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
-{
- return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()), argc, argv);
-}
-
VALUE
-rb_each(obj)
- VALUE obj;
+rb_each(VALUE obj)
{
return rb_funcall(obj, id_each, 0, 0);
}
static VALUE
-grep_i(i, arg)
- VALUE i, *arg;
+grep_i(VALUE i, VALUE *arg)
{
if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
rb_ary_push(arg[1], i);
@@ -44,8 +33,7 @@
}
static VALUE
-grep_iter_i(i, arg)
- VALUE i, *arg;
+grep_iter_i(VALUE i, VALUE *arg)
{
if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
rb_ary_push(arg[1], rb_yield(i));
@@ -72,8 +60,7 @@
*/
static VALUE
-enum_grep(obj, pat)
- VALUE obj, pat;
+enum_grep(VALUE obj, VALUE pat)
{
VALUE ary = rb_ary_new();
VALUE arg[2];
@@ -87,11 +74,64 @@
}
static VALUE
-find_i(i, memo)
- VALUE i;
- VALUE *memo;
+count_i(VALUE i, VALUE *arg)
{
+ if (rb_equal(i, arg[0])) {
+ arg[1]++;
+ }
+ return Qnil;
+}
+
+static VALUE
+count_iter_i(VALUE i, long *n)
+{
if (RTEST(rb_yield(i))) {
+ (*n)++;
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * enum.count(item) => int
+ * enum.count {| obj | block } => int
+ *
+ * Returns the number of items in <i>enum</i> for which equals to <i>item</i>.
+ * If a block is given, counts the number of elements yielding a true value.
+ *
+ * ary = [1, 2, 4, 2]
+ * ary.count(2) # => 2
+ * ary.count{|x|x%2==0} # => 3
+ *
+ */
+
+static VALUE
+enum_count(int argc, VALUE *argv, VALUE obj)
+{
+ if (argc == 1) {
+ VALUE item, args[2];
+
+ if (rb_block_given_p()) {
+ rb_warn("given block not used");
+ }
+ rb_scan_args(argc, argv, "1", &item);
+ args[0] = item;
+ args[1] = 0;
+ rb_iterate(rb_each, obj, count_i, (VALUE)&args);
+ return INT2NUM(args[1]);
+ }
+ else {
+ long n = 0;
+
+ rb_iterate(rb_each, obj, count_iter_i, (VALUE)&n);
+ return INT2NUM(n);
+ }
+}
+
+static VALUE
+find_i(VALUE i, VALUE *memo)
+{
+ if (RTEST(rb_yield(i))) {
*memo = i;
rb_iter_break();
}
@@ -114,17 +154,13 @@
*/
static VALUE
-enum_find(argc, argv, obj)
- int argc;
- VALUE* argv;
- VALUE obj;
+enum_find(int argc, VALUE *argv, VALUE obj)
{
VALUE memo = Qundef;
VALUE if_none;
rb_scan_args(argc, argv, "01", &if_none);
- if (!rb_block_given_p())
- return enumeratorize(argc, argv, obj);
+ RETURN_ENUMERATOR(obj, argc, argv);
rb_iterate(rb_each, obj, find_i, (VALUE)&memo);
if (memo != Qundef) {
return memo;
@@ -136,8 +172,7 @@
}
static VALUE
-find_all_i(i, ary)
- VALUE i, ary;
+find_all_i(VALUE i, VALUE ary)
{
if (RTEST(rb_yield(i))) {
rb_ary_push(ary, i);
@@ -159,12 +194,11 @@
*/
static VALUE
-enum_find_all(obj)
- VALUE obj;
+enum_find_all(VALUE obj)
{
VALUE ary;
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_iterate(rb_each, obj, find_all_i, ary);
@@ -173,8 +207,7 @@
}
static VALUE
-reject_i(i, ary)
- VALUE i, ary;
+reject_i(VALUE i, VALUE ary)
{
if (!RTEST(rb_yield(i))) {
rb_ary_push(ary, i);
@@ -194,12 +227,11 @@
*/
static VALUE
-enum_reject(obj)
- VALUE obj;
+enum_reject(VALUE obj)
{
VALUE ary;
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_iterate(rb_each, obj, reject_i, ary);
@@ -208,8 +240,7 @@
}
static VALUE
-collect_i(i, ary)
- VALUE i, ary;
+collect_i(VALUE i, VALUE ary)
{
rb_ary_push(ary, rb_yield(i));
@@ -217,8 +248,7 @@
}
static VALUE
-collect_all(i, ary)
- VALUE i, ary;
+collect_all(VALUE i, VALUE ary)
{
rb_ary_push(ary, i);
@@ -239,12 +269,11 @@
*/
static VALUE
-enum_collect(obj)
- VALUE obj;
+enum_collect(VALUE obj)
{
VALUE ary;
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_iterate(rb_each, obj, collect_i, ary);
@@ -263,8 +292,7 @@
* { 'a'=>1, 'b'=>2, 'c'=>3 }.to_a #=> [["a", 1], ["b", 2], ["c", 3]]
*/
static VALUE
-enum_to_a(obj)
- VALUE obj;
+enum_to_a(VALUE obj)
{
VALUE ary = rb_ary_new();
@@ -274,9 +302,7 @@
}
static VALUE
-inject_i(i, memo)
- VALUE i;
- VALUE *memo;
+inject_i(VALUE i, VALUE *memo)
{
if (*memo == Qundef) {
*memo = i;
@@ -319,9 +345,7 @@
*/
static VALUE
-enum_inject(argc, argv, obj)
- int argc;
- VALUE *argv, obj;
+enum_inject(int argc, VALUE *argv, VALUE obj)
{
VALUE memo = Qundef;
@@ -333,8 +357,7 @@
}
static VALUE
-partition_i(i, ary)
- VALUE i, *ary;
+partition_i(VALUE i, VALUE *ary)
{
if (RTEST(rb_yield(i))) {
rb_ary_push(ary[0], i);
@@ -358,12 +381,11 @@
*/
static VALUE
-enum_partition(obj)
- VALUE obj;
+enum_partition(VALUE obj)
{
VALUE ary[2];
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
ary[0] = rb_ary_new();
ary[1] = rb_ary_new();
@@ -390,15 +412,13 @@
*/
static VALUE
-enum_sort(obj)
- VALUE obj;
+enum_sort(VALUE obj)
{
return rb_ary_sort(enum_to_a(obj));
}
static VALUE
-sort_by_i(i, ary)
- VALUE i, ary;
+sort_by_i(VALUE i, VALUE ary)
{
VALUE v;
NODE *memo;
@@ -413,8 +433,7 @@
}
static int
-sort_by_cmp(aa, bb)
- NODE **aa, **bb;
+sort_by_cmp(NODE **aa, NODE **bb)
{
VALUE a = aa[0]->u1.value;
VALUE b = bb[0]->u1.value;
@@ -492,13 +511,12 @@
*/
static VALUE
-enum_sort_by(obj)
- VALUE obj;
+enum_sort_by(VALUE obj)
{
VALUE ary;
long i;
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
if (TYPE(obj) == T_ARRAY) {
ary = rb_ary_new2(RARRAY(obj)->len);
@@ -522,9 +540,7 @@
}
static VALUE
-all_iter_i(i, memo)
- VALUE i;
- VALUE *memo;
+all_iter_i(VALUE i, VALUE *memo)
{
if (!RTEST(rb_yield(i))) {
*memo = Qfalse;
@@ -534,9 +550,7 @@
}
static VALUE
-all_i(i, memo)
- VALUE i;
- VALUE *memo;
+all_i(VALUE i, VALUE *memo)
{
if (!RTEST(i)) {
*memo = Qfalse;
@@ -563,8 +577,7 @@
*/
static VALUE
-enum_all(obj)
- VALUE obj;
+enum_all(VALUE obj)
{
VALUE result = Qtrue;
@@ -573,9 +586,7 @@
}
static VALUE
-any_iter_i(i, memo)
- VALUE i;
- VALUE *memo;
+any_iter_i(VALUE i, VALUE *memo)
{
if (RTEST(rb_yield(i))) {
*memo = Qtrue;
@@ -585,9 +596,7 @@
}
static VALUE
-any_i(i, memo)
- VALUE i;
- VALUE *memo;
+any_i(VALUE i, VALUE *memo)
{
if (RTEST(i)) {
*memo = Qtrue;
@@ -615,8 +624,7 @@
*/
static VALUE
-enum_any(obj)
- VALUE obj;
+enum_any(VALUE obj)
{
VALUE result = Qfalse;
@@ -625,9 +633,7 @@
}
static VALUE
-min_i(i, memo)
- VALUE i;
- VALUE *memo;
+min_i(VALUE i, VALUE *memo)
{
VALUE cmp;
@@ -644,9 +650,7 @@
}
static VALUE
-min_ii(i, memo)
- VALUE i;
- VALUE *memo;
+min_ii(VALUE i, VALUE *memo)
{
VALUE cmp;
@@ -678,8 +682,7 @@
*/
static VALUE
-enum_min(obj)
- VALUE obj;
+enum_min(VALUE obj)
{
VALUE result = Qundef;
@@ -689,9 +692,7 @@
}
static VALUE
-max_i(i, memo)
- VALUE i;
- VALUE *memo;
+max_i(VALUE i, VALUE *memo)
{
VALUE cmp;
@@ -708,9 +709,7 @@
}
static VALUE
-max_ii(i, memo)
- VALUE i;
- VALUE *memo;
+max_ii(VALUE i, VALUE *memo)
{
VALUE cmp;
@@ -741,8 +740,7 @@
*/
static VALUE
-enum_max(obj)
- VALUE obj;
+enum_max(VALUE obj)
{
VALUE result = Qundef;
@@ -752,9 +750,7 @@
}
static VALUE
-min_by_i(i, memo)
- VALUE i;
- VALUE *memo;
+min_by_i(VALUE i, VALUE *memo)
{
VALUE v;
@@ -782,12 +778,11 @@
*/
static VALUE
-enum_min_by(obj)
- VALUE obj;
+enum_min_by(VALUE obj)
{
VALUE memo[2];
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
memo[0] = Qundef;
memo[1] = Qnil;
@@ -796,9 +791,7 @@
}
static VALUE
-max_by_i(i, memo)
- VALUE i;
- VALUE *memo;
+max_by_i(VALUE i, VALUE *memo)
{
VALUE v;
@@ -826,12 +819,11 @@
*/
static VALUE
-enum_max_by(obj)
- VALUE obj;
+enum_max_by(VALUE obj)
{
VALUE memo[2];
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
memo[0] = Qundef;
memo[1] = Qnil;
@@ -840,9 +832,7 @@
}
static VALUE
-member_i(item, memo)
- VALUE item;
- VALUE *memo;
+member_i(VALUE item, VALUE *memo)
{
if (rb_equal(item, memo[0])) {
memo[1] = Qtrue;
@@ -865,8 +855,7 @@
*/
static VALUE
-enum_member(obj, val)
- VALUE obj, val;
+enum_member(VALUE obj, VALUE val)
{
VALUE memo[2];
@@ -877,9 +866,7 @@
}
static VALUE
-each_with_index_i(val, memo)
- VALUE val;
- VALUE *memo;
+each_with_index_i(VALUE val, VALUE *memo)
{
rb_yield_values(2, val, INT2FIX(*memo));
++*memo;
@@ -902,21 +889,18 @@
*/
static VALUE
-enum_each_with_index(obj)
- VALUE obj;
+enum_each_with_index(VALUE obj)
{
VALUE memo = 0;
- if (!rb_block_given_p()) return enumeratorize(0, 0, obj);
+ RETURN_ENUMERATOR(obj, 0, 0);
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&memo);
return obj;
}
static VALUE
-zip_i(val, memo)
- VALUE val;
- VALUE *memo;
+zip_i(VALUE val, VALUE *memo)
{
VALUE result = memo[0];
VALUE args = memo[1];
@@ -962,10 +946,7 @@
*/
static VALUE
-enum_zip(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+enum_zip(int argc, VALUE *argv, VALUE obj)
{
int i;
VALUE result;
@@ -995,7 +976,7 @@
*/
void
-Init_Enumerable()
+Init_Enumerable(void)
{
rb_mEnumerable = rb_define_module("Enumerable");
@@ -1005,6 +986,7 @@
rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
rb_define_method(rb_mEnumerable,"sort_by", enum_sort_by, 0);
rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
+ rb_define_method(rb_mEnumerable,"count", enum_count, -1);
rb_define_method(rb_mEnumerable,"find", enum_find, -1);
rb_define_method(rb_mEnumerable,"detect", enum_find, -1);
rb_define_method(rb_mEnumerable,"find_all", enum_find_all, 0);
Modified: trunk/enumerator.c
===================================================================
--- trunk/enumerator.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/enumerator.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,13 +2,13 @@
enumerator.c - provides Enumerator class
- $Author: nobu $
+ $Author: ocean $
Copyright (C) 2001-2003 Akinori MUSHA
$Idaemons: /home/cvs/rb/enumerator/enumerator.c,v 1.1.1.1 2001/07/15 10:12:48 knu Exp $
$RoughId: enumerator.c,v 1.6 2003/07/27 11:03:24 nobu Exp $
- $Id: enumerator.c,v 1.4 2005/08/04 15:09:03 nobu Exp $
+ $Id: enumerator.c,v 1.7 2005/09/14 08:30:15 ocean Exp $
************************************************/
@@ -24,8 +24,7 @@
static VALUE sym_each, sym_each_with_index, sym_each_slice, sym_each_cons;
static VALUE
-proc_call(proc, args)
- VALUE proc, args;
+proc_call(VALUE proc, VALUE args)
{
if (TYPE(args) != T_ARRAY) {
args = rb_values_new(1, args);
@@ -34,8 +33,7 @@
}
static VALUE
-method_call(method, args)
- VALUE method, args;
+method_call(VALUE method, VALUE args)
{
int argc = 0;
VALUE *argv = 0;
@@ -50,13 +48,11 @@
VALUE method;
VALUE proc;
VALUE args;
- VALUE (*iter)_((VALUE, struct enumerator *));
+ VALUE (*iter)(VALUE, struct enumerator *);
};
-static void enumerator_mark _((void *));
static void
-enumerator_mark(p)
- void *p;
+enumerator_mark(void *p)
{
struct enumerator *ptr = p;
rb_gc_mark(ptr->method);
@@ -65,8 +61,7 @@
}
static struct enumerator *
-enumerator_ptr(obj)
- VALUE obj;
+enumerator_ptr(VALUE obj)
{
struct enumerator *ptr;
@@ -82,11 +77,8 @@
return ptr;
}
-static VALUE enumerator_iter_i _((VALUE, struct enumerator *));
static VALUE
-enumerator_iter_i(i, e)
- VALUE i;
- struct enumerator *e;
+enumerator_iter_i(VALUE i, struct enumerator *e)
{
return rb_yield(proc_call(e->proc, i));
}
@@ -110,10 +102,7 @@
*
*/
static VALUE
-obj_to_enum(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
VALUE meth = sym_each;
@@ -132,16 +121,13 @@
*
*/
static VALUE
-enumerator_enum_with_index(obj)
- VALUE obj;
+enumerator_enum_with_index(VALUE obj)
{
return rb_enumeratorize(obj, sym_each_with_index, 0, 0);
}
static VALUE
-each_slice_i(val, memo)
- VALUE val;
- VALUE *memo;
+each_slice_i(VALUE val, VALUE *memo)
{
VALUE ary = memo[0];
long size = (long)memo[1];
@@ -172,8 +158,7 @@
*
*/
static VALUE
-enum_each_slice(obj, n)
- VALUE obj, n;
+enum_each_slice(VALUE obj, VALUE n)
{
long size = NUM2LONG(n);
VALUE args[2], ary;
@@ -199,16 +184,13 @@
*
*/
static VALUE
-enumerator_enum_slice(obj, n)
- VALUE obj, n;
+enumerator_enum_slice(VALUE obj, VALUE n)
{
return rb_enumeratorize(obj, sym_each_slice, 1, &n);
}
static VALUE
-each_cons_i(val, memo)
- VALUE val;
- VALUE *memo;
+each_cons_i(VALUE val, VALUE *memo)
{
VALUE ary = memo[0];
long size = (long)memo[1];
@@ -244,8 +226,7 @@
*
*/
static VALUE
-enum_each_cons(obj, n)
- VALUE obj, n;
+enum_each_cons(VALUE obj, VALUE n)
{
long size = NUM2LONG(n);
VALUE args[2];
@@ -267,16 +248,13 @@
*
*/
static VALUE
-enumerator_enum_cons(obj, n)
- VALUE obj, n;
+enumerator_enum_cons(VALUE obj, VALUE n)
{
return rb_enumeratorize(obj, sym_each_cons, 1, &n);
}
-static VALUE enumerator_allocate _((VALUE));
static VALUE
-enumerator_allocate(klass)
- VALUE klass;
+enumerator_allocate(VALUE klass)
{
struct enumerator *ptr;
return Data_Make_Struct(rb_cEnumerator, struct enumerator,
@@ -284,10 +262,7 @@
}
VALUE
-enumerator_init(enum_obj, obj, meth, argc, argv)
- VALUE enum_obj, obj, meth;
- int argc;
- VALUE *argv;
+enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, VALUE *argv)
{
struct enumerator *ptr = enumerator_ptr(enum_obj);
@@ -297,7 +272,7 @@
ptr->iter = enumerator_iter_i;
}
else {
- ptr->iter = (VALUE (*) _((VALUE, struct enumerator *)))rb_yield;
+ ptr->iter = (VALUE (*)(VALUE, struct enumerator *))rb_yield;
}
if (argc) ptr->args = rb_ary_new4(argc, argv);
@@ -320,10 +295,7 @@
*
*/
static VALUE
-enumerator_initialize(argc, argv, obj)
- int argc;
- VALUE *argv;
- VALUE obj;
+enumerator_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE recv, meth = sym_each;
@@ -338,18 +310,13 @@
}
VALUE
-rb_enumeratorize(obj, meth, argc, argv)
- VALUE obj, meth;
- int argc;
- VALUE *argv;
+rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
{
return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
}
-static VALUE enumerator_iter _((VALUE));
static VALUE
-enumerator_iter(memo)
- VALUE memo;
+enumerator_iter(VALUE memo)
{
struct enumerator *e = (struct enumerator *)memo;
@@ -365,8 +332,7 @@
*
*/
static VALUE
-enumerator_each(obj)
- VALUE obj;
+enumerator_each(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
@@ -374,8 +340,7 @@
}
static VALUE
-enumerator_with_index_i(val, memo)
- VALUE val, *memo;
+enumerator_with_index_i(VALUE val, VALUE *memo)
{
val = rb_yield_values(2, val, INT2FIX(*memo));
++*memo;
@@ -391,8 +356,7 @@
*
*/
static VALUE
-enumerator_with_index(obj)
- VALUE obj;
+enumerator_with_index(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE memo = 0;
@@ -402,7 +366,7 @@
}
void
-Init_Enumerator()
+Init_Enumerator(void)
{
rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -1);
rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -1);
Modified: trunk/env.h
===================================================================
--- trunk/env.h 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/env.h 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
env.h -
- $Author: matz $
- $Date: 2005/03/04 06:47:44 $
+ $Author: ocean $
+ $Date: 2005/09/14 06:32:30 $
created at: Mon Jul 11 11:53:03 JST 1994
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -27,9 +27,10 @@
unsigned long uniq;
} *ruby_frame;
-void rb_gc_mark_frame _((struct FRAME *));
+void rb_gc_mark_frame(struct FRAME *);
#define FRAME_DMETH 1
+#define FRAME_FUNC 2
RUBY_EXTERN struct SCOPE {
struct RBasic super;
Modified: trunk/error.c
===================================================================
--- trunk/error.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/error.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -2,8 +2,8 @@
error.c -
- $Author: matz $
- $Date: 2005/07/27 07:27:18 $
+ $Author: ocean $
+ $Date: 2005/09/14 06:32:30 $
created at: Mon Aug 9 16:11:34 JST 1993
Copyright (C) 1993-2003 Yukihiro Matsumoto
@@ -11,17 +11,10 @@
**********************************************************************/
#include "ruby.h"
-#include "env.h"
#include "st.h"
#include <stdio.h>
-#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
-#define va_init_list(a,b) va_start(a,b)
-#else
-#include <varargs.h>
-#define va_init_list(a,b) va_start(a)
-#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -30,13 +23,12 @@
#endif
extern const char ruby_version[], ruby_release_date[], ruby_platform[];
+extern ruby_in_eval;
int ruby_nerrs;
static int
-err_position(buf, len)
- char *buf;
- long len;
+err_position(char *buf, long len)
{
ruby_set_current_source();
if (!ruby_sourcefile) {
@@ -51,11 +43,7 @@
}
static void
-err_snprintf(buf, len, fmt, args)
- char *buf;
- long len;
- const char *fmt;
- va_list args;
+err_snprintf(char *buf, long len, const char *fmt, va_list args)
{
long n;
@@ -65,11 +53,9 @@
}
}
-static void err_append _((const char*));
+static void err_append(const char*);
static void
-err_print(fmt, args)
- const char *fmt;
- va_list args;
+err_print(const char *fmt, va_list args)
{
char buf[BUFSIZ];
@@ -78,44 +64,30 @@
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_compile_error(const char *fmt, ...)
-#else
-rb_compile_error(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
va_list args;
- va_init_list(args, fmt);
+ va_start(args, fmt);
err_print(fmt, args);
va_end(args);
ruby_nerrs++;
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_compile_error_append(const char *fmt, ...)
-#else
-rb_compile_error_append(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
va_list args;
char buf[BUFSIZ];
- va_init_list(args, fmt);
+ va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
err_append(buf);
}
static void
-warn_print(fmt, args)
- const char *fmt;
- va_list args;
+warn_print(const char *fmt, va_list args)
{
char buf[BUFSIZ];
int len;
@@ -127,13 +99,7 @@
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_warn(const char *fmt, ...)
-#else
-rb_warn(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
char buf[BUFSIZ];
va_list args;
@@ -142,20 +108,14 @@
snprintf(buf, BUFSIZ, "warning: %s", fmt);
- va_init_list(args, fmt);
+ va_start(args, fmt);
warn_print(buf, args);
va_end(args);
}
/* rb_warning() reports only in verbose mode */
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_warning(const char *fmt, ...)
-#else
-rb_warning(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
char buf[BUFSIZ];
va_list args;
@@ -164,7 +124,7 @@
snprintf(buf, BUFSIZ, "warning: %s", fmt);
- va_init_list(args, fmt);
+ va_start(args, fmt);
warn_print(buf, args);
va_end(args);
}
@@ -178,8 +138,7 @@
*/
static VALUE
-rb_warn_m(self, mesg)
- VALUE self, mesg;
+rb_warn_m(VALUE self, VALUE mesg)
{
if (!NIL_P(ruby_verbose)) {
rb_io_write(rb_stderr, mesg);
@@ -189,13 +148,7 @@
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_bug(const char *fmt, ...)
-#else
-rb_bug(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
char buf[BUFSIZ];
va_list args;
@@ -205,7 +158,7 @@
if (fwrite(buf, 1, len, out) == len ||
fwrite(buf, 1, len, (out = stdout)) == len) {
fputs("[BUG] ", out);
- va_init_list(args, fmt);
+ va_start(args, fmt);
vfprintf(out, fmt, args);
va_end(args);
fprintf(out, "\nruby %s (%s) [%s]\n\n",
@@ -245,9 +198,7 @@
};
void
-rb_check_type(x, t)
- VALUE x;
- int t;
+rb_check_type(VALUE x, int t)
{
struct types *type = builtin_types;
@@ -315,25 +266,19 @@
static VALUE eNOERROR;
VALUE
-rb_exc_new(etype, ptr, len)
- VALUE etype;
- const char *ptr;
- long len;
+rb_exc_new(VALUE etype, const char *ptr, long len)
{
return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
}
VALUE
-rb_exc_new2(etype, s)
- VALUE etype;
- const char *s;
+rb_exc_new2(VALUE etype, const char *s)
{
return rb_exc_new(etype, s, strlen(s));
}
VALUE
-rb_exc_new3(etype, str)
- VALUE etype, str;
+rb_exc_new3(VALUE etype, VALUE str)
{
StringValue(str);
return rb_funcall(etype, rb_intern("new"), 1, str);
@@ -348,10 +293,7 @@
*/
static VALUE
-exc_initialize(argc, argv, exc)
- int argc;
- VALUE *argv;
- VALUE exc;
+exc_initialize(int argc, VALUE *argv, VALUE exc)
{
VALUE arg;
@@ -376,10 +318,7 @@
*/
static VALUE
-exc_exception(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+exc_exception(int argc, VALUE *argv, VALUE self)
{
VALUE exc;
@@ -400,8 +339,7 @@
*/
static VALUE
-exc_to_s(exc)
- VALUE exc;
+exc_to_s(VALUE exc)
{
VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
@@ -421,8 +359,7 @@
*/
static VALUE
-exc_message(exc)
- VALUE exc;
+exc_message(VALUE exc)
{
return rb_funcall(exc, rb_intern("to_s"), 0, 0);
}
@@ -435,8 +372,7 @@
*/
static VALUE
-exc_inspect(exc)
- VALUE exc;
+exc_inspect(VALUE exc)
{
VALUE str, klass;
@@ -486,8 +422,7 @@
*/
static VALUE
-exc_backtrace(exc)
- VALUE exc;
+exc_backtrace(VALUE exc)
{
ID bt = rb_intern("bt");
@@ -496,8 +431,7 @@
}
static VALUE
-check_backtrace(bt)
- VALUE bt;
+check_backtrace(VALUE bt)
{
long i;
static char *err = "backtrace must be Array of String";
@@ -529,9 +463,7 @@
*/
static VALUE
-exc_set_backtrace(exc, bt)
- VALUE exc;
- VALUE bt;
+exc_set_backtrace(VALUE exc, VALUE bt)
{
return rb_iv_set(exc, "bt", check_backtrace(bt));
}
@@ -546,9 +478,7 @@
*/
static VALUE
-exc_equal(exc, obj)
- VALUE exc;
- VALUE obj;
+exc_equal(VALUE exc, VALUE obj)
{
ID id_mesg = rb_intern("mesg");
@@ -570,10 +500,7 @@
*/
static VALUE
-exit_initialize(argc, argv, exc)
- int argc;
- VALUE *argv;
- VALUE exc;
+exit_initialize(int argc, VALUE *argv, VALUE exc)
{
VALUE status = INT2FIX(EXIT_SUCCESS);
if (argc > 0 && FIXNUM_P(argv[0])) {
@@ -594,8 +521,7 @@
*/
static VALUE
-exit_status(exc)
- VALUE exc;
+exit_status(VALUE exc)
{
return rb_attr_get(exc, rb_intern("status"));
}
@@ -609,8 +535,7 @@
*/
static VALUE
-exit_success_p(exc)
- VALUE exc;
+exit_success_p(VALUE exc)
{
VALUE status = rb_attr_get(exc, rb_intern("status"));
if (NIL_P(status)) return Qtrue;
@@ -619,20 +544,13 @@
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_name_error(ID id, const char *fmt, ...)
-#else
-rb_name_error(id, fmt, va_alist)
- ID id;
- const char *fmt;
- va_dcl
-#endif
{
VALUE exc, argv[2];
va_list args;
char buf[BUFSIZ];
- va_init_list(args, fmt);
+ va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
@@ -652,10 +570,7 @@
*/
static VALUE
-name_err_initialize(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+name_err_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE name;
@@ -673,8 +588,7 @@
*/
static VALUE
-name_err_name(self)
- VALUE self;
+name_err_name(VALUE self)
{
return rb_attr_get(self, rb_intern("name"));
}
@@ -687,8 +601,7 @@
*/
static VALUE
-name_err_to_s(exc)
- VALUE exc;
+name_err_to_s(VALUE exc)
{
VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
VALUE str = mesg;
@@ -713,10 +626,7 @@
*/
static VALUE
-nometh_err_initialize(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+nometh_err_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE args = (argc > 2) ? argv[--argc] : Qnil;
name_err_initialize(argc, argv, self);
@@ -726,16 +636,14 @@
/* :nodoc: */
static void
-name_err_mesg_mark(ptr)
- VALUE *ptr;
+name_err_mesg_mark(VALUE *ptr)
{
rb_gc_mark_locations(ptr, ptr+3);
}
/* :nodoc: */
static VALUE
-name_err_mesg_new(obj, mesg, recv, method)
- VALUE obj, mesg, recv, method;
+name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
{
VALUE *ptr = ALLOC_N(VALUE, 3);
@@ -747,8 +655,7 @@
/* :nodoc: */
static VALUE
-name_err_mesg_equal(obj1, obj2)
- VALUE obj1, obj2;
+name_err_mesg_equal(VALUE obj1, VALUE obj2)
{
VALUE *ptr1, *ptr2;
int i;
@@ -768,8 +675,7 @@
/* :nodoc: */
static VALUE
-name_err_mesg_to_str(obj)
- VALUE obj;
+name_err_mesg_to_str(VALUE obj)
{
VALUE *ptr, mesg;
Data_Get_Struct(obj, VALUE, ptr);
@@ -815,8 +721,7 @@
/* :nodoc: */
static VALUE
-name_err_mesg_load(klass, str)
- VALUE klass, str;
+name_err_mesg_load(VALUE klass, VALUE str)
{
return str;
}
@@ -830,15 +735,13 @@
*/
static VALUE
-nometh_err_args(self)
- VALUE self;
+nometh_err_args(VALUE self)
{
return rb_attr_get(self, rb_intern("args"));
}
void
-rb_invalid_str(str, type)
- const char *str, *type;
+rb_invalid_str(const char *str, const char *type)
{
VALUE s = rb_str_inspect(rb_str_new2(str));
@@ -879,9 +782,7 @@
static st_table *syserr_tbl;
static VALUE
-set_syserr(n, name)
- int n;
- const char *name;
+set_syserr(int n, const char *name)
{
VALUE error;
@@ -897,8 +798,7 @@
}
static VALUE
-get_syserr(n)
- int n;
+get_syserr(int n)
{
VALUE error;
@@ -923,10 +823,7 @@
*/
static VALUE
-syserr_initialize(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+syserr_initialize(int argc, VALUE *argv, VALUE self)
{
#if !defined(_WIN32) && !defined(__VMS)
char *strerror();
@@ -977,8 +874,7 @@
*/
static VALUE
-syserr_errno(self)
- VALUE self;
+syserr_errno(VALUE self)
{
return rb_attr_get(self, rb_intern("errno"));
}
@@ -992,8 +888,7 @@
*/
static VALUE
-syserr_eqq(self, exc)
- VALUE self, exc;
+syserr_eqq(VALUE self, VALUE exc)
{
VALUE num, e;
@@ -1022,8 +917,7 @@
* Returns default SystemCallError class.
*/
static VALUE
-errno_missing(self, id)
- VALUE self, id;
+errno_missing(VALUE self, VALUE id)
{
return eNOERROR;
}
@@ -1039,7 +933,7 @@
*/
void
-Init_Exception()
+Init_Exception(void)
{
rb_eException = rb_define_class("Exception", rb_cObject);
rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1);
@@ -1103,63 +997,44 @@
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_raise(VALUE exc, const char *fmt, ...)
-#else
-rb_raise(exc, fmt, va_alist)
- VALUE exc;
- const char *fmt;
- va_dcl
-#endif
{
va_list args;
char buf[BUFSIZ];
- va_init_list(args,fmt);
+ va_start(args,fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
rb_exc_raise(rb_exc_new2(exc, buf));
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_loaderror(const char *fmt, ...)
-#else
-rb_loaderror(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
va_list args;
char buf[BUFSIZ];
- va_init_list(args, fmt);
+ va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
rb_exc_raise(rb_exc_new2(rb_eLoadError, buf));
}
void
-rb_notimplement()
+rb_notimplement(void)
{
rb_raise(rb_eNotImpError,
"The %s() function is unimplemented on this machine",
- rb_id2name(ruby_frame->callee));
+ rb_id2name(rb_frame_callee()));
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_fatal(const char *fmt, ...)
-#else
-rb_fatal(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
va_list args;
char buf[BUFSIZ];
- va_init_list(args, fmt);
+ va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
@@ -1168,8 +1043,7 @@
}
void
-rb_sys_fail(mesg)
- const char *mesg;
+rb_sys_fail(const char *mesg)
{
int n = errno;
VALUE arg;
@@ -1184,13 +1058,7 @@
}
void
-#ifdef HAVE_STDARG_PROTOTYPES
rb_sys_warning(const char *fmt, ...)
-#else
-rb_sys_warning(fmt, va_alist)
- const char *fmt;
- va_dcl
-#endif
{
char buf[BUFSIZ];
va_list args;
@@ -1203,35 +1071,32 @@
snprintf(buf, BUFSIZ, "warning: %s", fmt);
snprintf(buf+strlen(buf), BUFSIZ-strlen(buf), ": %s", strerror(errno_save));
- va_init_list(args, fmt);
+ va_start(args, fmt);
warn_print(buf, args);
va_end(args);
errno = errno_save;
}
void
-rb_load_fail(path)
- const char *path;
+rb_load_fail(const char *path)
{
rb_loaderror("%s -- %s", strerror(errno), path);
}
void
-rb_error_frozen(what)
- const char *what;
+rb_error_frozen(const char *what)
{
rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
}
void
-rb_check_frozen(obj)
- VALUE obj;
+rb_check_frozen(VALUE obj)
{
if (OBJ_FROZEN(obj)) rb_error_frozen(rb_obj_classname(obj));
}
void
-Init_syserr()
+Init_syserr(void)
{
#ifdef EPERM
set_syserr(EPERM, "EPERM");
@@ -1603,8 +1468,7 @@
}
static void
-err_append(s)
- const char *s;
+err_append(const char *s)
{
extern VALUE ruby_errinfo;
Modified: trunk/eval.c
===================================================================
--- trunk/eval.c 2005-09-15 07:55:24 UTC (rev 256)
+++ trunk/eval.c 2005-09-23 11:41:35 UTC (rev 257)
@@ -12,203 +12,22 @@
**********************************************************************/
-#include "ruby.h"
-#include "node.h"
-#include "env.h"
-#include "util.h"
-#include "rubysig.h"
-#include "yarv.h"
+#include "eval_intern.h"
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifndef EXIT_SUCCESS
-#define EXIT_SUCCESS 0
-#endif
-#ifndef EXIT_FAILURE
-#define EXIT_FAILURE 1
-#endif
+struct SCOPE *ruby_scope = 0; /* for gc.c */
-#include <stdio.h>
-#if defined(HAVE_GETCONTEXT) && defined(HAVE_SETCONTEXT)
-#include <ucontext.h>
-#define USE_CONTEXT
-#endif
-#include <setjmp.h>
+struct tag *ruby_prot_tag;
+VALUE rb_cProc;
+VALUE rb_cBinding;
-#include "st.h"
-#include "dln.h"
+VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE));
+VALUE rb_f_binding _((VALUE));
+void bm_mark _((void *));
-#ifdef __APPLE__
-#include <crt_externs.h>
-#endif
-
-/* Make alloca work the best possible way. */
-#ifdef __GNUC__
-# ifndef atarist
-# ifndef alloca
-# define alloca __builtin_alloca
-# endif
-# endif /* atarist */
-#else
-# ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-# else
-# ifdef _AIX
- #pragma alloca
-# else
-# ifndef alloca /* predefined by HP cc +Olibcalls */
-void *alloca ();
-# endif
-# endif /* AIX */
-# endif /* HAVE_ALLOCA_H */
-#endif /* __GNUC__ */
-
-#ifdef HAVE_STDARG_PROTOTYPES
-#include <stdarg.h>
-#define va_init_list(a,b) va_start(a,b)
-#else
-#include <varargs.h>
-#define va_init_list(a,b) va_start(a)
-#endif
-
-#ifndef HAVE_STRING_H
-char *strrchr _((const char*,const char));
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef __BEOS__
-#include <net/socket.h>
-#endif
-
-#ifdef __MACOS__
-#include "macruby_private.h"
-#endif
-
-#ifdef __VMS
-#include "vmsruby_private.h"
-#endif
-
-#ifdef USE_CONTEXT
-typedef struct {
- ucontext_t context;
- volatile int status;
-} rb_jmpbuf_t[1];
-
-NORETURN(static void rb_jump_context(rb_jmpbuf_t, int));
-static inline void
-rb_jump_context(env, val)
- rb_jmpbuf_t env;
- int val;
-{
- env->status = val;
- setcontext(&env->context);
- abort(); /* ensure noreturn */
-}
-/*
- * FUNCTION_CALL_MAY_RETURN_TWICE is a magic for getcontext, gcc,
- * IA64 register stack and SPARC register window combination problem.
- *
- * Assume following code sequence.
- *
- * 1. set a register in the register stack/window such as r32/l0.
- * 2. call getcontext.
- * 3. use the register.
- * 4. update the register for other use.
- * 5. call setcontext indirectly (or directly).
- *
- * This code should be run as 1->2->3->4->5->3->4.
- * But after second getcontext return (second 3),
- * the register is broken (updated).
- * It's because getcontext/setcontext doesn't preserve the content of the
- * register stack/window.
- *
- * setjmp also doesn't preserve the content of the register stack/window.
- * But it has not the problem because gcc knows setjmp may return twice.
- * gcc detects setjmp and generates setjmp safe code.
- *
- * So setjmp call before getcontext call makes the code somewhat safe.
- * It fix the problem on IA64.
- * It is not required that setjmp is called at run time, since the problem is
- * register usage.
- *
- * Since the magic setjmp is not enough for SPARC,
- * inline asm is used to prohibit registers in register windows.
- */
-#if defined (__GNUC__) && (defined(sparc) || defined(__sparc__))
-#define FUNCTION_CALL_MAY_RETURN_TWICE \
- ({ __asm__ volatile ("" : : : \
- "%o0", "%o1", "%o2", "%o3", "%o4", "%o5", "%o7", \
- "%l0", "%l1", "%l2", "%l3", "%l4", "%l5", "%l6", "%l7", \
- "%i0", "%i1", "%i2", "%i3", "%i4", "%i5", "%i7"); })
-#else
-static jmp_buf function_call_may_return_twice_jmp_buf;
-int function_call_may_return_twice_false = 0;
-#define FUNCTION_CALL_MAY_RETURN_TWICE \
- (function_call_may_return_twice_false ? \
- setjmp(function_call_may_return_twice_jmp_buf) : \
- 0)
-#endif
-#define ruby_longjmp(env, val) rb_jump_context(env, val)
-#define ruby_setjmp(j) ((j)->status = 0, \
- FUNCTION_CALL_MAY_RETURN_TWICE, \
- getcontext(&(j)->context), \
- (j)->status)
-#else
-typedef jmp_buf rb_jmpbuf_t;
-#if !defined(setjmp) && defined(HAVE__SETJMP)
-#define ruby_setjmp(env) _setjmp(env)
-#define ruby_longjmp(env,val) _longjmp(env,val)
-#else
-#define ruby_setjmp(env) setjmp(env)
-#define ruby_longjmp(env,val) longjmp(env,val)
-#endif
-#endif
-
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-
-#if defined(__VMS)
-#pragma nostandard
-#endif
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-
-/*
- Solaris sys/select.h switches select to select_large_fdset to support larger
- file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
- But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
- So following definition is required to use select_large_fdset.
-*/
-#ifdef HAVE_SELECT_LARGE_FDSET
-#define select(n, r, w, e, t) select_large_fdset(n, r, w, e, t)
-#endif
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-
-#include <sys/stat.h>
-
-VALUE rb_cProc;
-static VALUE rb_cBinding;
-static VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE));
static VALUE proc_lambda _((void));
-static VALUE rb_f_binding _((VALUE));
-static void rb_f_END _((void));
static VALUE rb_f_block_given_p _((void));
-static VALUE rb_cMethod;
-static VALUE rb_cUnboundMethod;
static VALUE umethod_bind _((VALUE, VALUE));
static VALUE rb_mod_define_method _((int, VALUE*, VALUE));
-NORETURN(static void rb_raise_jump _((VALUE)));
-static VALUE rb_make_exception _((int argc, VALUE *argv));
static int scope_vmode;
#define SCOPE_PUBLIC 0
@@ -220,706 +39,27 @@
#define SCOPE_TEST(f) (scope_vmode&(f))
NODE* ruby_current_node;
-int ruby_safe_level = 0;
-/* safe-level:
- 0 - strings from streams/environment/ARGV are tainted (default)
- 1 - no dangerous operation by tainted value
- 2 - process/file operations prohibited
- 3 - all generated objects are tainted
- 4 - no global (non-tainted) variable modification/no direct output
-*/
-static VALUE safe_getter _((void));
-static void safe_setter _((VALUE val));
-
-void
-rb_secure(level)
- int level;
-{
- if (level <= ruby_safe_level) {
- if (ruby_frame->callee) {
- rb_raise(rb_eSecurityError, "Insecure operation `%s' at level %d",
- rb_id2name(ruby_frame->callee), ruby_safe_level);
- }
- else {
- rb_raise(rb_eSecurityError, "Insecure operation at level %d", ruby_safe_level);
- }
- }
-}
-
-void
-rb_secure_update(obj)
- VALUE obj;
-{
- if (!OBJ_TAINTED(obj)) rb_secure(4);
-}
-
-void
-rb_check_safe_obj(x)
- VALUE x;
-{
- if (ruby_safe_level > 0 && OBJ_TAINTED(x)){
- if (ruby_frame->callee) {
- rb_raise(rb_eSecurityError, "Insecure operation - %s",
- rb_id2name(ruby_frame->callee));
- }
- else {
- rb_raise(rb_eSecurityError, "Insecure operation: -r");
- }
- }
- rb_secure(4);
-}
-
-void
-rb_check_safe_str(x)
- VALUE x;
-{
- rb_check_safe_obj(x);
- if (TYPE(x)!= T_STRING) {
- rb_raise(rb_eTypeError, "wrong argument type %s (expected String)",
- rb_obj_classname(x));
- }
-}
-
-NORETURN(static void print_undef _((VALUE, ID)));
-static void
-print_undef(klass, id)
- VALUE klass;
- ID id;
-{
- rb_name_error(id, "undefined method `%s' for %s `%s'",
- rb_id2name(id),
- (TYPE(klass) == T_MODULE) ? "module" : "class",
- rb_class2name(klass));
-}
-
static ID removed, singleton_removed, undefined, singleton_undefined;
-
-#define CACHE_SIZE 0x800
-#define CACHE_MASK 0x7ff
-#define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
-
-struct cache_entry { /* method hash table. */
- ID mid; /* method's id */
- ID mid0; /* method's original id */
- VALUE klass; /* receiver's class */
- VALUE origin; /* where method defined */
- NODE *method;
- int noex;
-};
-
-static struct cache_entry cache[CACHE_SIZE];
-static int ruby_running = 0;
-
-void
-rb_clear_cache()
-{
- struct cache_entry *ent, *end;
-
- if (!ruby_running) return;
- ent = cache; end = ent + CACHE_SIZE;
- while (ent < end) {
- ent->mid = 0;
- ent++;
- }
-}
-
-static void
-rb_clear_cache_for_undef(klass, id)
- VALUE klass;
- ID id;
-{
- struct cache_entry *ent, *end;
-
- if (!ruby_running) return;
- ent = cache; end = ent + CACHE_SIZE;
- while (ent < end) {
- if (ent->origin == klass && ent->mid == id) {
- ent->mid = 0;
- }
- ent++;
- }
-}
-
-static void
-rb_clear_cache_by_id(id)
- ID id;
-{
- struct cache_entry *ent, *end;
-
- if (!ruby_running) return;
- ent = cache; end = ent + CACHE_SIZE;
- while (ent < end) {
- if (ent->mid == id) {
- ent->mid = 0;
- }
- ent++;
- }
-}
-
-void
-rb_clear_cache_by_class(klass)
- VALUE klass;
-{
- struct cache_entry *ent, *end;
-
- if (!ruby_running) return;
- ent = cache; end = ent + CACHE_SIZE;
- while (ent < end) {
- if (ent->klass == klass || ent->origin == klass) {
- ent->mid = 0;
- }
- ent++;
- }
-}
-
static ID init, eqq, each, aref, aset, match, missing;
static ID added, singleton_added;
static ID __id__, __send__, respond_to;
-void
-rb_add_method(klass, mid, node, noex)
- VALUE klass;
- ID mid;
- NODE *node;
- int noex;
-{
- NODE *body;
-
- if (NIL_P(klass)) klass = rb_cObject;
- if (ruby_safe_level >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) {
- rb_raise(rb_eSecurityError, "Insecure: can't define method");
- }
- if (!FL_TEST(klass, FL_SINGLETON) &&
- node && nd_type(node) != NODE_ZSUPER &&
- (mid == rb_intern("initialize" )|| mid == rb_intern("initialize_copy"))) {
- noex = NOEX_PRIVATE | noex;
- }
- else if (FL_TEST(klass, FL_SINGLETON) && node && nd_type(node) == NODE_CFUNC &&
- mid == rb_intern("allocate")) {
- rb_warn("defining %s.allocate is deprecated; use rb_define_alloc_func()",
- rb_class2name(rb_iv_get(klass, "__attached__")));
- mid = ID_ALLOCATOR;
- }
- if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
- rb_clear_cache_by_id(mid);
- body = NEW_METHOD(node, noex);
- st_insert(RCLASS(klass)->m_tbl, mid, (st_data_t)body);
- if (node && mid != ID_ALLOCATOR && ruby_running) {
- if (FL_TEST(klass, FL_SINGLETON)) {
- rb_funcall(rb_iv_get(klass, "__attached__"), singleton_added, 1, ID2SYM(mid));
- }
- else {
- rb_funcall(klass, added, 1, ID2SYM(mid));
- }
- }
-}
-
-void
-rb_define_alloc_func(klass, func)
- VALUE klass;
- VALUE (*func) _((VALUE));
-{
- Check_Type(klass, T_CLASS);
- rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0), NOEX_PRIVATE);
-}
-
-void
-rb_undef_alloc_func(klass)
- VALUE klass;
-{
- Check_Type(klass, T_CLASS);
- rb_add_method(CLASS_OF(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
-}
-
-static NODE*
-search_method(klass, id, origin)
- VALUE klass, *origin;
- ID id;
-{
- NODE *body;
-
- if (!klass) return 0;
- while (!st_lookup(RCLASS(klass)->m_tbl, id, (st_data_t *)&body)) {
- klass = RCLASS(klass)->super;
- if (!klass) return 0;
- }
-
- if (origin) *origin = klass;
- return body;
-}
-
-static NODE*
-rb_get_method_body(klassp, idp, noexp)
- VALUE *klassp;
- ID *idp;
- int *noexp;
-{
- ID id = *idp;
- VALUE klass = *klassp;
- VALUE origin;
- NODE * volatile body;
- struct cache_entry *ent;
-
- if ((body = search_method(klass, id, &origin)) == 0 || !body->nd_body) {
- /* store empty info in cache */
- ent = cache + EXPR1(klass, id);
- ent->klass = klass;
- ent->origin = klass;
- ent->mid = ent->mid0 = id;
- ent->noex = 0;
- ent->method = 0;
-
- return 0;
- }
-
- if (ruby_running) {
- /* store in cache */
- ent = cache + EXPR1(klass, id);
- ent->klass = klass;
- ent->noex = body->nd_noex;
- if (noexp) *noexp = body->nd_noex;
- body = body->nd_body;
- if (nd_type(body) == NODE_FBODY) {
- ent->mid = id;
- *klassp = body->nd_orig;
- ent->origin = body->nd_orig;
- *idp = ent->mid0 = body->nd_mid;
- body = ent->method = body->nd_head;
- }
- else {
- *klassp = origin;
- ent->origin = origin;
- ent->mid = ent->mid0 = id;
- ent->method = body;
- }
- }
- else {
- if (noexp) *noexp = body->nd_noex;
- body = body->nd_body;
- if (nd_type(body) == NODE_FBODY) {
- *klassp = body->nd_orig;
- *idp = body->nd_mid;
- body = body->nd_head;
- }
- else {
- *klassp = origin;
- }
- }
-
- return body;
-}
-
-NODE*
-rb_method_node(klass, id)
- VALUE klass;
- ID id;
-{
- int noex;
- struct cache_entry *ent;
-
- ent = cache + EXPR1(klass, id);
- if (ent->mid == id && ent->klass == klass && ent->method){
- return ent->method;
- }
-
- return rb_get_method_body(&klass, &id, &noex);
-}
-
-static void
-remove_method(klass, mid)
- VALUE klass;
- ID mid;
-{
- NODE *body;
-
- if (klass == rb_cObject) {
- rb_secure(4);
- }
- if (ruby_safe_level >= 4 && !OBJ_TAINTED(klass)) {
- rb_raise(rb_eSecurityError, "Insecure: can't remove method");
- }
- if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
- if (mid == __id__ || mid == __send__ || mid == init) {
- rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
- }
- if (!st_delete(RCLASS(klass)->m_tbl, &mid, (st_data_t *)&body) ||
- !body->nd_body) {
- rb_name_error(mid, "method `%s' not defined in %s",
- rb_id2name(mid), rb_class2name(klass));
- }
- rb_clear_cache_for_undef(klass, mid);
- if (FL_TEST(klass, FL_SINGLETON)) {
- rb_funcall(rb_iv_get(klass, "__attached__"), singleton_removed, 1, ID2SYM(mid));
- }
- else {
- rb_funcall(klass, removed, 1, ID2SYM(mid));
- }
-}
-
-void
-rb_remove_method(klass, name)
- VALUE klass;
- const char *name;
-{
- remove_method(klass, rb_intern(name));
-}
-
-/*
- * call-seq:
- * remove_method(symbol) => self
- *
- * Removes the method identified by _symbol_ from the current
- * class. For an example, see <code>Module.undef_method</code>.
- */
-
-static VALUE
-rb_mod_remove_method(argc, argv, mod)
- int argc;
- VALUE *argv;
- VALUE mod;
-{
- int i;
-
- for (i=0; i<argc; i++) {
- remove_method(mod, rb_to_id(argv[i]));
- }
- return mod;
-}
-
-#undef rb_disable_super
-#undef rb_enable_super
-
-void
-rb_disable_super(klass, name)
- VALUE klass;
- const char *name;
-{
- /* obsolete - no use */
-}
-
-void
-rb_enable_super(klass, name)
- VALUE klass;
- const char *name;
-{
- rb_warning("rb_enable_super() is obsolete");
-}
-
-static void
-rb_export_method(klass, name, noex)
- VALUE klass;
- ID name;
- ID noex;
-{
- NODE *body;
- VALUE origin;
-
- if (klass == rb_cObject) {
- rb_secure(4);
- }
- body = search_method(klass, name, &origin);
- if (!body && TYPE(klass) == T_MODULE) {
- body = search_method(rb_cObject, name, &origin);
- }
- if (!body || !body->nd_body) {
- print_undef(klass, name);
- }
- if (body->nd_noex != noex) {
- if (klass == origin) {
- body->nd_noex = noex;
- }
- else {
- rb_add_method(klass, name, NEW_ZSUPER(), noex);
- }
- }
-}
-
-int
-rb_method_boundp(klass, id, ex)
- VALUE klass;
- ID id;
- int ex;
-{
- struct cache_entry *ent;
- int noex;
-
- /* is it in the method cache? */
- ent = cache + EXPR1(klass, id);
- if (ent->mid == id && ent->klass == klass) {
- if (ex && (ent->noex & NOEX_PRIVATE))
- return Qfalse;
- if (!ent->method) return Qfalse;
- return Qtrue;
- }
- if (rb_get_method_body(&klass, &id, &noex)) {
- if (ex && (noex & NOEX_PRIVATE))
- return Qfalse;
- return Qtrue;
- }
- return Qfalse;
-}
-
-void
-rb_attr(klass, id, read, write, ex)
- VALUE klass;
- ID id;
- int read, write, ex;
-{
- const char *name;
- char *buf;
- ID attriv;
- int noex;
- size_t len;
-
- if (!ex) noex = NOEX_PUBLIC;
- else {
- if (SCOPE_TEST(SCOPE_PRIVATE)) {
- noex = NOEX_PRIVATE;
- rb_warning((scope_vmode == SCOPE_MODFUNC) ?
- "attribute accessor as module_function" :
- "private attribute?");
- }
- else if (SCOPE_TEST(SCOPE_PROTECTED)) {
- noex = NOEX_PROTECTED;
- }
- else {
- noex = NOEX_PUBLIC;
- }
- }
-
- if (!rb_is_local_id(id) && !rb_is_const_id(id)) {
- rb_name_error(id, "invalid attribute name `%s'", rb_id2name(id));
- }
- name = rb_id2name(id);
- if (!name) {
- rb_raise(rb_eArgError, "argument needs to be symbol or string");
- }
- len = strlen(name)+2;
- buf = ALLOCA_N(char,len);
- snprintf(buf, l