Skip to content
Browse files

* ext/socket/socket.c (unix_addr): getsockname(2) may result len = 0.

* ext/socket/socket.c (unix_peeraddr): getpeername(2) may result
  len = 0.

* string.c (rb_str_subpat_set): support function for new argument
  pattern String#[re,offset] = val. [new]

* eval.c (POP_BLOCK): rb_gc_force_recycle() was called too much.
  Should not be called if SCOPE_DONT_RECYCLE is set.

* string.c (rb_str_aref_m): new argument pattern
  String#[re,offset]. [new]

* string.c (rb_str_substr): should return an instance of
  receiver's class.

* string.c (rb_str_succ): ditto.

* array.c (rb_ary_subseq): ditto.

* array.c (rb_ary_initialize): Array.new([1,2,3]) => [1,2,3]. [new]

* string.c (rb_str_reverse): should return an instance of
  receiver's class.

* string.c (rb_str_times): ditto.

* array.c (rb_ary_times): ditto

* string.c (str_gsub): ditto.

* string.c (rb_str_ljust): ditto.

* string.c (rb_str_rjust): ditto.

* string.c (rb_str_center): ditto.

* eval.c (eval): retrieves file, line information from binding.

* eval.c (intersect_fds): counts intersecting fds.

* eval.c (rb_thread_schedule): only fds requested by
  each thread count as select_value.


git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent e488f19 commit 1baa36bc201ed2c715891df2858f3c14790953e9 matz committed Oct 2, 2001
Showing with 254 additions and 150 deletions.
  1. +62 −1 ChangeLog
  2. +2 −0 ToDo
  3. +41 −28 array.c
  4. +2 −2 configure.in
  5. +22 −18 eval.c
  6. +5 −5 ext/socket/getnameinfo.c
  7. +4 −0 ext/socket/socket.c
  8. +3 −9 lib/debug.rb
  9. +1 −1 lib/mailread.rb
  10. +4 −4 numeric.c
  11. +2 −34 object.c
  12. +1 −1 parse.y
  13. +11 −3 re.c
  14. +4 −2 ruby.c
  15. +87 −39 string.c
  16. +1 −1 time.c
  17. +2 −2 version.h
View
63 ChangeLog
@@ -2,6 +2,28 @@ Tue Oct 2 08:04:52 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* marshal.c (r_object): TYPE_UCLASS check should be inversed.
+Mon Oct 1 19:18:54 2001 Tanaka Akira <akr@m17n.org>
+
+ * ext/socket/socket.c (unix_addr): getsockname(2) may result len = 0.
+
+ * ext/socket/socket.c (unix_peeraddr): getpeername(2) may result
+ len = 0.
+
+Mon Oct 1 09:59:07 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_subpat_set): support function for new argument
+ pattern String#[re,offset] = val. [new]
+
+Sat Sep 29 02:30:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (POP_BLOCK): rb_gc_force_recycle() was called too much.
+ Should not be called if SCOPE_DONT_RECYCLE is set.
+
+Wed Sep 26 22:21:52 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_aref_m): new argument pattern
+ String#[re,offset]. [new]
+
Wed Sep 26 19:02:39 2001 Guy Decoux <ts@moulon.inra.fr>
* parse.y: allow 'primary[] = arg'
@@ -11,6 +33,38 @@ Tue Sep 25 10:46:42 2001 Usaku Nakamura <usa@ruby-lang.org>
* win32/win32.c (isInternalCmd): check return value of NtMakeCmdVector
(Tietew <tietew@tietew.net>'s patch).
+Mon Sep 24 00:55:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_substr): should return an instance of
+ receiver's class.
+
+ * string.c (rb_str_succ): ditto.
+
+ * array.c (rb_ary_subseq): ditto.
+
+ * array.c (rb_ary_initialize): Array.new([1,2,3]) => [1,2,3]. [new]
+
+Sat Sep 22 22:16:08 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_reverse): should return an instance of
+ receiver's class.
+
+ * string.c (rb_str_times): ditto.
+
+ * array.c (rb_ary_times): ditto
+
+ * string.c (str_gsub): ditto.
+
+ * string.c (rb_str_ljust): ditto.
+
+ * string.c (rb_str_rjust): ditto.
+
+ * string.c (rb_str_center): ditto.
+
+Sat Sep 22 12:13:39 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (eval): retrieves file, line information from binding.
+
Thu Sep 20 21:25:00 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* eval.c (MATCH_DATA): access via rb_svar().
@@ -52,7 +106,7 @@ Thu Sep 20 15:20:00 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
Tue Sep 18 11:44:26 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
- * string.c (rb_str_init): String.new() => ""
+ * string.c (rb_str_init): String.new() => "" [new]
Tue Sep 11 20:53:56 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
@@ -250,6 +304,13 @@ Wed Aug 22 23:20:03 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* hash.c (rb_hash_equal): check identiry equality first.
+Wed Aug 22 19:58:59 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * eval.c (intersect_fds): counts intersecting fds.
+
+ * eval.c (rb_thread_schedule): only fds requested by
+ each thread count as select_value.
+
Tue Aug 21 22:28:09 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* file.c (group_member): should check real gid only.
View
2 ToDo
@@ -29,6 +29,7 @@ Language Spec.
* resumable Exception via Exception#resume.
* method combination, e.g. before, after, around, etc.
* .. or something like defadvice in Emacs.
+* Class#allocate - basicNew
Hacking Interpreter
@@ -105,6 +106,7 @@ Ruby Libraries
Tools
* freeze or undump to bundle everything
+* bundle using zlib
Misc
View
69 array.c
@@ -179,6 +179,22 @@ rb_ary_s_new(argc, argv, klass)
}
static VALUE
+to_ary(ary)
+ VALUE ary;
+{
+ return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
+}
+
+static VALUE
+to_ary_failed(failed)
+ int *failed;
+{
+ *failed = Qtrue;
+}
+
+static VALUE rb_ary_replace _((VALUE, VALUE));
+
+static VALUE
rb_ary_initialize(argc, argv, ary)
int argc;
VALUE *argv;
@@ -187,11 +203,17 @@ rb_ary_initialize(argc, argv, ary)
long len;
VALUE size, val;
+ rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
+ RARRAY(ary)->len = 0;
+ return ary;
+ }
+
+ if (argc == 1 && !FIXNUM_P(size) && rb_respond_to(size, rb_intern("to_ary"))) {
+ rb_ary_replace(ary, rb_convert_type(size, T_ARRAY, "Array", "to_ary"));
return ary;
}
- rb_ary_modify(ary);
len = NUM2LONG(size);
if (len < 0) {
rb_raise(rb_eArgError, "negative array size");
@@ -409,6 +431,7 @@ rb_ary_subseq(ary, beg, len)
ary2 = rb_ary_new2(len);
MEMCPY(RARRAY(ary2)->ptr, RARRAY(ary)->ptr+beg, VALUE, len);
RARRAY(ary2)->len = len;
+ RBASIC(ary2)->klass = rb_obj_class(ary);
return ary2;
}
@@ -544,6 +567,20 @@ rb_ary_indexes(argc, argv, ary)
return new_ary;
}
+VALUE
+rb_ary_to_ary(obj)
+ VALUE obj;
+{
+ if (NIL_P(obj)) return rb_ary_new2(0);
+ if (TYPE(obj) == T_ARRAY) {
+ return obj;
+ }
+ if (rb_respond_to(obj, rb_intern("to_ary"))) {
+ return rb_convert_type(obj, T_ARRAY, "Array", "to_ary");
+ }
+ return rb_ary_new3(1, obj);
+}
+
static void
rb_ary_update(ary, beg, len, rpl)
VALUE ary;
@@ -552,12 +589,7 @@ rb_ary_update(ary, beg, len, rpl)
{
long rlen;
- if (NIL_P(rpl)) {
- rpl = rb_ary_new2(0);
- }
- else if (TYPE(rpl) != T_ARRAY) {
- rpl = rb_ary_new3(1, rpl);
- }
+ rpl = rb_ary_to_ary(rpl);
rlen = RARRAY(rpl)->len;
if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len);
@@ -739,27 +771,6 @@ rb_ary_dup(ary)
return dup;
}
-static VALUE
-to_ary(ary)
- VALUE ary;
-{
- return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
-}
-
-VALUE
-rb_ary_to_ary(obj)
- VALUE obj;
-{
- if (NIL_P(obj)) return rb_ary_new2(0);
- if (TYPE(obj) == T_ARRAY) {
- return obj;
- }
- if (rb_respond_to(obj, rb_intern("to_ary"))) {
- return rb_convert_type(obj, T_ARRAY, "Array", "to_ary");
- }
- return rb_ary_new3(1, obj);
-}
-
extern VALUE rb_output_fs;
static VALUE
@@ -1342,6 +1353,8 @@ rb_ary_times(ary, times)
for (i=0; i<len; i+=RARRAY(ary)->len) {
MEMCPY(RARRAY(ary2)->ptr+i, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
}
+ OBJ_INFECT(ary2, ary);
+ RBASIC(ary2)->klass = rb_obj_class(ary);
return ary2;
}
View
4 configure.in
@@ -635,7 +635,7 @@ if test "$with_dln_a_out" != yes; then
LDFLAGS=""
DLDFLAGS="$ARCH_FLAG"
rb_cv_dlopen=yes ;;
- darwin*) LDSHARED='cc -dynamic -bundle -undefined suppress'
+ darwin*) LDSHARED='cc -dynamic -bundle -undefined suppress -flat_namespace'
LDFLAGS=""
DLDFLAGS="$ARCH_FLAG"
rb_cv_dlopen=yes ;;
@@ -921,7 +921,7 @@ if test "$enable_shared" = 'yes'; then
;;
darwin*)
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib'
- LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress'
+ LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress -flat_namespace'
LIBRUBY_DLDFLAGS='-install_name lib$(RUBY_INSTALL_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
LIBRUBY_ALIASES='lib$(RUBY_INSTALL_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_INSTALL_NAME).dylib'
;;
View
40 eval.c
@@ -585,15 +585,11 @@ new_blktag()
_block.wrapper = ruby_wrapper; \
ruby_block = &_block;
-#define POP_BLOCK_TAG(tag) do { \
- if ((tag)->flags & BLOCK_DYNAMIC) \
- (tag)->flags |= BLOCK_ORPHAN; \
- else \
- rb_gc_force_recycle((VALUE)tag); \
-} while (0)
-
#define POP_BLOCK() \
- POP_BLOCK_TAG(_block.tag); \
+ if (_block.tag->flags & (BLOCK_DYNAMIC)) \
+ _block.tag->flags |= BLOCK_ORPHAN; \
+ else if (!(_block.scope->flags & SCOPE_DONT_RECYCLE)) \
+ rb_gc_force_recycle((VALUE)_block.tag); \
ruby_block = _block.prev; \
}
@@ -4631,7 +4627,8 @@ rb_call(klass, recv, mid, argc, argv, scope)
struct cache_entry *ent;
if (!klass) {
- rb_raise(rb_eNotImpError, "method call on terminated object");
+ rb_raise(rb_eNotImpError, "method `%s' called on terminated object (0x%x)",
+ rb_id2name(mid), recv);
}
/* is it in the method cache? */
ent = cache + EXPR1(klass, mid);
@@ -4909,10 +4906,6 @@ eval(self, src, scope, file, line)
volatile int iter = ruby_frame->iter;
int state;
- if (file == 0) {
- file = ruby_sourcefile;
- line = ruby_sourceline;
- }
if (!NIL_P(scope)) {
if (!rb_obj_is_block(scope)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
@@ -4936,6 +4929,11 @@ eval(self, src, scope, file, line)
ruby_cref = (NODE*)ruby_frame->cbase;
old_wrapper = ruby_wrapper;
ruby_wrapper = data->wrapper;
+ if ((file == 0 || (line == 1 && strcmp(file, "(eval)") == 0)) &&
+ data->body && data->body->nd_file) {
+ file = data->body->nd_file;
+ line = nd_line(data->body);
+ }
self = data->self;
ruby_frame->iter = data->iter;
@@ -4945,6 +4943,10 @@ eval(self, src, scope, file, line)
ruby_frame->iter = ruby_frame->prev->iter;
}
}
+ if (file == 0) {
+ file = ruby_sourcefile;
+ line = ruby_sourceline;
+ }
PUSH_CLASS();
ruby_class = ruby_cbase;
@@ -7520,24 +7522,26 @@ match_fds(dst, src, max)
return Qfalse;
}
-static void
+static int
intersect_fds(src, dst, max)
fd_set *src, *dst;
int max;
{
- int i;
+ int i, n = 0;
for (i=0; i<=max; i++) {
if (FD_ISSET(i, dst)) {
if (FD_ISSET(i, src)) {
/* Wake up only one thread per fd. */
FD_CLR(i, src);
+ ++n;
}
else {
FD_CLR(i, dst);
}
}
}
+ return n;
}
static int
@@ -7693,9 +7697,9 @@ rb_thread_schedule()
/* Wake up only one thread per fd. */
th->status = THREAD_RUNNABLE;
th->wait_for = 0;
- intersect_fds(&readfds, &th->readfds, max);
- intersect_fds(&writefds, &th->writefds, max);
- intersect_fds(&exceptfds, &th->exceptfds, max);
+ n = intersect_fds(&readfds, &th->readfds, max) +
+ intersect_fds(&writefds, &th->writefds, max) +
+ intersect_fds(&exceptfds, &th->exceptfds, max);
th->select_value = n;
found = 1;
}
View
10 ext/socket/getnameinfo.c
@@ -180,14 +180,14 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
/* what we should do? */
} else if (flags & NI_NUMERICSERV) {
snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
- if (strlen(numserv) > servlen)
+ if (strlen(numserv) + 1 > servlen)
return ENI_MEMORY;
strcpy(serv, numserv);
} else {
#if defined(HAVE_GETSERVBYPORT)
sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp");
if (sp) {
- if (strlen(sp->s_name) > servlen)
+ if (strlen(sp->s_name) + 1 > servlen)
return ENI_MEMORY;
strcpy(serv, sp->s_name);
} else
@@ -199,11 +199,11 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
switch (sa->sa_family) {
case AF_INET:
- v4a = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
+ v4a = ntohl(((struct sockaddr_in *)sa)->sin_addr.s_addr);
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
flags |= NI_NUMERICHOST;
v4a >>= IN_CLASSA_NSHIFT;
- if (v4a == 0 || v4a == IN_LOOPBACKNET)
+ if (v4a == 0)
flags |= NI_NUMERICHOST;
break;
#ifdef INET6
@@ -236,7 +236,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
p = strchr(hp->h_name, '.');
if (p) *p = '\0';
}
- if (strlen(hp->h_name) > hostlen) {
+ if (strlen(hp->h_name) + 1 > hostlen) {
#ifdef INET6
freehostent(hp);
#endif
View
4 ext/socket/socket.c
@@ -1434,6 +1434,8 @@ unix_addr(sock)
if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
+ if (len == 0)
+ addr.sun_path[0] = '\0';
return unixaddr(&addr);
}
@@ -1449,6 +1451,8 @@ unix_peeraddr(sock)
if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail("getsockname(2)");
+ if (len == 0)
+ addr.sun_path[0] = '\0';
return unixaddr(&addr);
}
#endif
View
12 lib/debug.rb
@@ -83,7 +83,6 @@ def initialize
@stop_next = 0
end
@last_file = nil
- @last = [nil, nil]
@file = nil
@line = nil
@no_step = nil
@@ -701,14 +700,9 @@ def trace_func(event, file, line, id, binding, klass)
# nothing to do. skipped.
end
if @stop_next == 0 or check_break_points(file, line, binding, id)
- if [file, line] == @last
- @stop_next = 1
- else
- @no_step = nil
- suspend_all
- debug_command(file, line, id, binding)
- @last = [file, line]
- end
+ @no_step = nil
+ suspend_all
+ debug_command(file, line, id, binding)
end
when 'call'
View
2 lib/mailread.rb
@@ -14,7 +14,7 @@ def initialize(f)
next if /^From /=~line # skip From-line
break if /^$/=~line # end of header
- if /^(\S+):\s*(.*)/=~line
+ if /^(\S+?):\s*(.*)/=~line
(attr = $1).capitalize!
@header[attr] = $2
elsif attr
View
8 numeric.c
@@ -765,7 +765,7 @@ rb_num2long(val)
VALUE val;
{
if (NIL_P(val)) {
- rb_raise(rb_eTypeError, "no implicit conversion from nil");
+ rb_raise(rb_eTypeError, "no implicit conversion to integer from nil");
}
if (FIXNUM_P(val)) return FIX2LONG(val);
@@ -782,19 +782,19 @@ rb_num2long(val)
sprintf(buf, "%-.10g", RFLOAT(val)->value);
if (s = strchr(buf, ' ')) *s = '\0';
- rb_raise(rb_eRangeError, "float %s out of rang of integer", buf);
+ rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
}
case T_BIGNUM:
return rb_big2long(val);
case T_STRING:
- rb_raise(rb_eTypeError, "no implicit conversion from string");
+ rb_raise(rb_eTypeError, "no implicit conversion to integer from string");
return Qnil; /* not reached */
case T_TRUE:
case T_FALSE:
- rb_raise(rb_eTypeError, "no implicit conversion from boolean");
+ rb_raise(rb_eTypeError, "no implicit conversion to integer from boolean");
return Qnil; /* not reached */
default:
View
36 object.c
@@ -354,13 +354,6 @@ nil_inspect(obj)
return rb_str_new2("nil");
}
-static VALUE
-nil_type(obj)
- VALUE obj;
-{
- return rb_cNilClass;
-}
-
#ifdef NIL_PLUS
static VALUE
nil_plus(x, y)
@@ -398,13 +391,6 @@ true_to_s(obj)
}
static VALUE
-true_type(obj)
- VALUE obj;
-{
- return rb_cTrueClass;
-}
-
-static VALUE
true_and(obj, obj2)
VALUE obj, obj2;
{
@@ -433,13 +419,6 @@ false_to_s(obj)
}
static VALUE
-false_type(obj)
- VALUE obj;
-{
- return rb_cFalseClass;
-}
-
-static VALUE
false_and(obj, obj2)
VALUE obj, obj2;
{
@@ -485,13 +464,6 @@ rb_obj_alloc(klass)
}
static VALUE
-sym_type(sym)
- VALUE sym;
-{
- return rb_cSymbol;
-}
-
-static VALUE
sym_to_i(sym)
VALUE sym;
{
@@ -1011,11 +983,11 @@ rb_num2dbl(val)
return RFLOAT(val)->value;
case T_STRING:
- rb_raise(rb_eTypeError, "no implicit conversion from String");
+ rb_raise(rb_eTypeError, "no implicit conversion to float from string");
break;
case T_NIL:
- rb_raise(rb_eTypeError, "no implicit conversion from nil");
+ rb_raise(rb_eTypeError, "no implicit conversion to float from nil");
break;
default:
@@ -1197,7 +1169,6 @@ Init_Object()
rb_define_global_function("Array", rb_f_array, 1);
rb_cNilClass = rb_define_class("NilClass", rb_cObject);
- rb_define_method(rb_cNilClass, "type", nil_type, 0);
rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
@@ -1214,7 +1185,6 @@ Init_Object()
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0);
- rb_define_method(rb_cSymbol, "type", sym_type, 0);
rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0);
rb_define_method(rb_cSymbol, "to_int", sym_to_i, 0);
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
@@ -1271,7 +1241,6 @@ Init_Object()
rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
rb_define_method(rb_cTrueClass, "to_s", true_to_s, 0);
- rb_define_method(rb_cTrueClass, "type", true_type, 0);
rb_define_method(rb_cTrueClass, "&", true_and, 1);
rb_define_method(rb_cTrueClass, "|", true_or, 1);
rb_define_method(rb_cTrueClass, "^", true_xor, 1);
@@ -1280,7 +1249,6 @@ Init_Object()
rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0);
- rb_define_method(rb_cFalseClass, "type", false_type, 0);
rb_define_method(rb_cFalseClass, "&", false_and, 1);
rb_define_method(rb_cFalseClass, "|", false_or, 1);
rb_define_method(rb_cFalseClass, "^", false_xor, 1);
View
2 parse.y
@@ -715,7 +715,7 @@ arg : lhs '=' arg
}
| primary '[' aref_args ']' tOP_ASGN arg
{
- NODE *args = NEW_LIST($6);
+ NODE *tmp, *args = NEW_LIST($6);
$3 = list_append($3, NEW_NIL());
list_concat(args, $3);
View
14 re.c
@@ -703,19 +703,27 @@ VALUE
rb_reg_match_pre(match)
VALUE match;
{
+ VALUE str;
+
if (NIL_P(match)) return Qnil;
if (RMATCH(match)->BEG(0) == -1) return Qnil;
- return rb_str_new(RSTRING(RMATCH(match)->str)->ptr, RMATCH(match)->BEG(0));
+ str = rb_str_new(RSTRING(RMATCH(match)->str)->ptr, RMATCH(match)->BEG(0));
+ if (OBJ_TAINTED(match)) OBJ_TAINT(str);
+ return str;
}
VALUE
rb_reg_match_post(match)
VALUE match;
{
+ VALUE str;
+
if (NIL_P(match)) return Qnil;
if (RMATCH(match)->BEG(0) == -1) return Qnil;
- return rb_str_new(RSTRING(RMATCH(match)->str)->ptr+RMATCH(match)->END(0),
- RSTRING(RMATCH(match)->str)->len-RMATCH(match)->END(0));
+ str = rb_str_new(RSTRING(RMATCH(match)->str)->ptr+RMATCH(match)->END(0),
+ RSTRING(RMATCH(match)->str)->len-RMATCH(match)->END(0));
+ if (OBJ_TAINTED(match)) OBJ_TAINT(str);
+ return str;
}
VALUE
View
6 ruby.c
@@ -600,8 +600,10 @@ proc_options(argc, argv)
s++;
if (strcmp("copyright", s) == 0)
copyright = 1;
- else if (strcmp("debug", s) == 0)
- ruby_debug = 1;
+ else if (strcmp("debug", s) == 0) {
+ ruby_debug = Qtrue;
+ ruby_verbose = Qtrue;
+ }
else if (strcmp("version", s) == 0)
version = 1;
else if (strcmp("verbose", s) == 0) {
View
126 string.c
@@ -33,12 +33,13 @@ VALUE rb_cString;
VALUE rb_fs;
VALUE
-rb_str_new(ptr, len)
+rb_str_new0(klass, ptr, len)
+ VALUE klass;
const char *ptr;
long len;
{
NEWOBJ(str, struct RString);
- OBJSETUP(str, rb_cString, T_STRING);
+ OBJSETUP(str, klass, T_STRING);
str->ptr = 0;
str->len = len;
@@ -52,6 +53,14 @@ rb_str_new(ptr, len)
}
VALUE
+rb_str_new(ptr, len)
+ const char *ptr;
+ long len;
+{
+ return rb_str_new0(rb_cString, ptr, len);
+}
+
+VALUE
rb_str_new2(ptr)
const char *ptr;
{
@@ -129,6 +138,15 @@ rb_str_new4(orig)
}
}
+VALUE
+rb_str_new5(obj, ptr, len)
+ VALUE obj;
+ const char *ptr;
+ long len;
+{
+ return rb_str_new0(rb_obj_class(obj), ptr, len);
+}
+
#define STR_BUF_MIN_SIZE 128
VALUE
@@ -276,7 +294,6 @@ rb_str_dup(str)
return str2;
}
-
static VALUE
rb_str_clone(str)
VALUE str;
@@ -295,8 +312,7 @@ rb_str_s_new(argc, argv, klass)
VALUE *argv;
VALUE klass;
{
- VALUE str = rb_str_new(0, 0);
- OBJSETUP(str, klass, T_STRING);
+ VALUE str = rb_str_new0(klass, 0, 0);
rb_obj_call_init(str, argc, argv);
return str;
@@ -360,24 +376,22 @@ rb_str_times(str, times)
long i, len;
len = NUM2LONG(times);
- if (len == 0) return rb_str_new(0,0);
+ if (len == 0) return rb_str_new5(str,0,0);
if (len < 0) {
rb_raise(rb_eArgError, "negative argument");
}
if (LONG_MAX/len < RSTRING(str)->len) {
rb_raise(rb_eArgError, "argument too big");
}
- str2 = rb_str_new(0, RSTRING(str)->len*len);
+ str2 = rb_str_new5(str,0, RSTRING(str)->len*len);
for (i=0; i<len; i++) {
memcpy(RSTRING(str2)->ptr+(i*RSTRING(str)->len),
RSTRING(str)->ptr, RSTRING(str)->len);
}
RSTRING(str2)->ptr[RSTRING(str2)->len] = '\0';
- if (OBJ_TAINTED(str)) {
- OBJ_TAINT(str2);
- }
+ OBJ_INFECT(str2, str);
return str2;
}
@@ -420,10 +434,10 @@ rb_str_substr(str, beg, len)
if (len < 0) {
len = 0;
}
- if (len == 0) return rb_str_new(0,0);
+ if (len == 0) return rb_str_new5(str,0,0);
- str2 = rb_str_new(RSTRING(str)->ptr+beg, len);
- if (OBJ_TAINTED(str)) OBJ_TAINT(str2);
+ str2 = rb_str_new5(str,RSTRING(str)->ptr+beg, len);
+ OBJ_INFECT(str2, str);
return str2;
}
@@ -984,7 +998,7 @@ rb_str_succ(orig)
int c = -1;
int n = 0;
- str = rb_str_new(RSTRING(orig)->ptr, RSTRING(orig)->len);
+ str = rb_str_new5(orig,RSTRING(orig)->ptr, RSTRING(orig)->len);
OBJ_INFECT(str, orig);
if (RSTRING(str)->len == 0) return str;
@@ -1057,6 +1071,17 @@ rb_str_upto_m(beg, end)
}
static VALUE
+rb_str_subpat(str, re, offset)
+ VALUE str, re;
+ int offset;
+{
+ if (rb_reg_search(re, str, 0, 0) >= 0) {
+ return rb_reg_nth_match(offset, rb_backref_get());
+ }
+ return Qnil;
+}
+
+static VALUE
rb_str_aref(str, indx)
VALUE str;
VALUE indx;
@@ -1077,9 +1102,7 @@ rb_str_aref(str, indx)
return INT2FIX(RSTRING(str)->ptr[idx] & 0xff);
case T_REGEXP:
- if (rb_reg_search(indx, str, 0, 0) >= 0)
- return rb_reg_last_match(rb_backref_get());
- return Qnil;
+ return rb_str_subpat(str, indx, 0);
case T_STRING:
if (rb_str_index(str, indx, 0) != -1) return indx;
@@ -1111,6 +1134,9 @@ rb_str_aref_m(argc, argv, str)
VALUE str;
{
if (argc == 2) {
+ if (TYPE(argv[0]) == T_REGEXP) {
+ return rb_str_subpat(str, argv[0], NUM2INT(argv[1]));
+ }
return rb_str_substr(str, NUM2INT(argv[0]), NUM2INT(argv[1]));
}
if (argc != 1) {
@@ -1162,7 +1188,31 @@ rb_str_update(str, beg, len, val)
OBJ_INFECT(str, val);
}
-static VALUE rb_str_sub_bang _((int, VALUE*, VALUE));
+static void
+rb_str_subpat_set(str, re, offset, val)
+ VALUE str, re;
+ int offset;
+ VALUE val;
+{
+ VALUE match;
+ int start, end, len;
+
+ if (rb_reg_search(re, str, 0, 0) < 0) {
+ rb_raise(rb_eIndexError, "regexp not matched");
+ }
+ match = rb_backref_get();
+ if (offset >= RMATCH(match)->regs->num_regs) {
+ rb_raise(rb_eIndexError, "index %d out of regexp", offset);
+ }
+
+ start = RMATCH(match)->BEG(offset);
+ if (start == -1) {
+ rb_raise(rb_eIndexError, "regexp group %d not matched", offset);
+ }
+ end = RMATCH(match)->END(offset);
+ len = end - start;
+ rb_str_update(str, start, len, val);
+}
static VALUE
rb_str_aset(str, indx, val)
@@ -1194,12 +1244,7 @@ rb_str_aset(str, indx, val)
return val;
case T_REGEXP:
- {
- VALUE args[2];
- args[0] = indx;
- args[1] = val;
- rb_str_sub_bang(2, args, str);
- }
+ rb_str_subpat_set(str, indx, 0, val);
return val;
case T_STRING:
@@ -1231,11 +1276,12 @@ rb_str_aset_m(argc, argv, str)
{
rb_str_modify(str);
if (argc == 3) {
- long beg, len;
-
- beg = NUM2INT(argv[0]);
- len = NUM2INT(argv[1]);
- rb_str_update(str, beg, len, argv[2]);
+ if (TYPE(argv[0]) == T_REGEXP) {
+ rb_str_subpat_set(str, argv[0], NUM2INT(argv[1]), argv[2]);
+ }
+ else {
+ rb_str_update(str, NUM2INT(argv[0]), NUM2INT(argv[1]), argv[2]);
+ }
return argv[2];
}
if (argc != 2) {
@@ -1479,6 +1525,7 @@ str_gsub(argc, argv, str, bang)
NEWOBJ(dup, struct RString);
OBJSETUP(dup, rb_cString, T_STRING);
OBJ_INFECT(dup, str);
+ RBASIC(dup)->klass = rb_obj_class(str);
str = (VALUE)dup;
dup->orig = 0;
}
@@ -1529,7 +1576,7 @@ rb_str_replace(str, str2)
memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
}
- if (OBJ_TAINTED(str2)) OBJ_TAINT(str);
+ OBJ_INFECT(str2, str);
return str;
}
@@ -1616,13 +1663,14 @@ rb_str_reverse(str)
if (RSTRING(str)->len <= 1) return rb_str_dup(str);
- obj = rb_str_new(0, RSTRING(str)->len);
+ obj = rb_str_new5(str, 0, RSTRING(str)->len);
s = RSTRING(str)->ptr; e = s + RSTRING(str)->len - 1;
p = RSTRING(obj)->ptr;
while (e >= s) {
*p++ = *e--;
}
+ OBJ_INFECT(obj, str);
return obj;
}
@@ -1771,7 +1819,7 @@ rb_str_dump(str)
}
}
- result = rb_str_new(0, len);
+ result = rb_str_new5(str, 0, len);
p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len;
q = RSTRING(result)->ptr; qend = q + len;
@@ -2432,7 +2480,7 @@ rb_str_split_m(argc, argv, str)
for (idx=1; idx < regs->num_regs; idx++) {
if (BEG(idx) == -1) continue;
if (BEG(idx) == END(idx))
- tmp = rb_str_new(0, 0);
+ tmp = rb_str_new5(str, 0, 0);
else
tmp = rb_str_substr(str, BEG(idx), END(idx)-BEG(idx));
rb_ary_push(result, tmp);
@@ -2442,7 +2490,7 @@ rb_str_split_m(argc, argv, str)
}
if (!NIL_P(limit) || RSTRING(str)->len > beg || lim < 0) {
if (RSTRING(str)->len == beg)
- tmp = rb_str_new(0, 0);
+ tmp = rb_str_new5(str, 0, 0);
else
tmp = rb_str_substr(str, beg, RSTRING(str)->len-beg);
rb_ary_push(result, tmp);
@@ -2515,7 +2563,7 @@ rb_str_each_line(argc, argv, str)
if (p[-1] == newline &&
(rslen <= 1 ||
rb_memcmp(RSTRING(rs)->ptr, p-rslen, rslen) == 0)) {
- line = rb_str_new(s, p - s);
+ line = rb_str_new5(str, s, p - s);
rb_yield(line);
if (RSTRING(str)->ptr != ptr || RSTRING(str)->len != len)
rb_raise(rb_eArgError, "string modified");
@@ -2525,7 +2573,7 @@ rb_str_each_line(argc, argv, str)
if (s != pend) {
if (p > pend) p = pend;
- line = rb_str_new(s, p - s);
+ line = rb_str_new5(str, s, p - s);
OBJ_INFECT(line, str);
rb_yield(line);
}
@@ -2932,7 +2980,7 @@ rb_str_ljust(str, w)
char *p, *pend;
if (width < 0 || RSTRING(str)->len >= width) return str;
- res = rb_str_new(0, width);
+ res = rb_str_new5(str, 0, width);
memcpy(RSTRING(res)->ptr, RSTRING(str)->ptr, RSTRING(str)->len);
p = RSTRING(res)->ptr + RSTRING(str)->len; pend = RSTRING(res)->ptr + width;
while (p < pend) {
@@ -2952,7 +3000,7 @@ rb_str_rjust(str, w)
char *p, *pend;
if (width < 0 || RSTRING(str)->len >= width) return str;
- res = rb_str_new(0, width);
+ res = rb_str_new5(str, 0, width);
p = RSTRING(res)->ptr; pend = p + width - RSTRING(str)->len;
while (p < pend) {
*p++ = ' ';
@@ -2973,7 +3021,7 @@ rb_str_center(str, w)
long n;
if (width < 0 || RSTRING(str)->len >= width) return str;
- res = rb_str_new(0, width);
+ res = rb_str_new5(str, 0, width);
n = (width - RSTRING(str)->len)/2;
p = RSTRING(res)->ptr; pend = p + n;
while (p < pend) {
View
2 time.c
@@ -865,7 +865,7 @@ time_minus(time1, time2)
sec--;
usec += 1000000;
}
- time2 = rb_time_new(sec, usec);
+ time2 = time_new_internal(rb_obj_class(time1), sec, usec);
if (tobj->gmt) {
GetTimeval(time2, tobj);
tobj->gmt = 1;
View
4 version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.1"
-#define RUBY_RELEASE_DATE "2001-09-20"
+#define RUBY_RELEASE_DATE "2001-10-02"
#define RUBY_VERSION_CODE 171
-#define RUBY_RELEASE_CODE 20010920
+#define RUBY_RELEASE_CODE 20011002

0 comments on commit 1baa36b

Please sign in to comment.
Something went wrong with that request. Please try again.