From 4ded52b623ebd1b3de12db82f8b54cc156c1fd28 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 7 Apr 2004 02:51:05 +0000 Subject: * file.c (rb_get_path): get path string via "to_path" method if path object is not a string. [Ruby2] * gc.c (rb_gc_call_finalizer_at_exit): do not free threads in the exit finalizers. * io.c (rb_io_reopen): should use rb_io_check_io(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index dfdce5eff5..0ed7590cd4 100644 --- a/array.c +++ b/array.c @@ -16,11 +16,13 @@ #include "util.h" #include "st.h" -VALUE rb_cArray; +VALUE rb_cArray, rb_cValues; + static ID id_cmp; #define ARY_DEFAULT_SIZE 16 + void rb_mem_clear(mem, size) register VALUE *mem; @@ -193,17 +195,50 @@ rb_ary_new4(n, elts) } VALUE -rb_assoc_new(car, cdr) - VALUE car, cdr; +#ifdef HAVE_STDARG_PROTOTYPES +rb_values_new(long n, ...) +#else +rb_values_new(n, va_alist) + long n; + va_dcl +#endif { - VALUE ary; + va_list ar; + VALUE val; + long i; - ary = rb_ary_new2(2); - RARRAY(ary)->ptr[0] = car; - RARRAY(ary)->ptr[1] = cdr; - RARRAY(ary)->len = 2; + val = ary_new(rb_cValues, n); + va_init_list(ar, n); + for (i=0; iptr[i] = va_arg(ar, VALUE); + } + va_end(ar); + RARRAY(val)->len = n; - return ary; + return val; +} + +VALUE +rb_values_new2(n, elts) + long n; + const VALUE *elts; +{ + VALUE val; + + val = ary_new(rb_cValues, n); + if (n > 0 && elts) { + MEMCPY(RARRAY(val)->ptr, elts, VALUE, n); + } + RARRAY(val)->len = n; + + return val; +} + +VALUE +rb_assoc_new(car, cdr) + VALUE car, cdr; +{ + return rb_values_new(2, car, cdr); } static VALUE @@ -905,7 +940,6 @@ rb_ary_indexes(argc, argv, ary) VALUE new_ary; long i; - rb_warn("Array#%s is deprecated; use Array#values_at", rb_id2name(rb_frame_last_func())); new_ary = rb_ary_new2(argc); for (i=0; ilen, argc, argv, rb_ary_entry); + return rb_get_values_at(ary, RARRAY(ary)->len, argc, argv, rb_ary_entry); } /* @@ -3016,4 +3050,6 @@ Init_Array() id_cmp = rb_intern("<=>"); inspect_key = rb_intern("__inspect_key__"); + + rb_cValues = rb_define_class("Values", rb_cArray); } -- cgit v1.2.3