* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@1761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-10-02 04:31:23 +00:00
Родитель 34a31235c9
Коммит 75eee0bafd
17 изменённых файлов: 254 добавлений и 150 удалений

Просмотреть файл

@ -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.

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

69
array.c
Просмотреть файл

@ -178,6 +178,22 @@ rb_ary_s_new(argc, argv, klass)
return ary;
}
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;
@ -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;
}

Просмотреть файл

@ -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'
;;

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;
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -83,7 +83,6 @@ class DEBUGGER__
@stop_next = 0
end
@last_file = nil
@last = [nil, nil]
@file = nil
@line = nil
@no_step = nil
@ -701,14 +700,9 @@ EOHELP
# 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'

Просмотреть файл

@ -14,7 +14,7 @@ class Mail
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

Просмотреть файл

@ -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:

Просмотреть файл

@ -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)
@ -397,13 +390,6 @@ true_to_s(obj)
return rb_str_new2("true");
}
static VALUE
true_type(obj)
VALUE obj;
{
return rb_cTrueClass;
}
static VALUE
true_and(obj, obj2)
VALUE obj, obj2;
@ -432,13 +418,6 @@ false_to_s(obj)
return rb_str_new2("false");
}
static VALUE
false_type(obj)
VALUE obj;
{
return rb_cFalseClass;
}
static VALUE
false_and(obj, obj2)
VALUE obj, obj2;
@ -484,13 +463,6 @@ rb_obj_alloc(klass)
return (VALUE)obj;
}
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);

Просмотреть файл

@ -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);

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

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) {

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;
@ -51,6 +52,14 @@ rb_str_new(ptr, len)
return (VALUE)str;
}
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,7 +376,7 @@ 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");
}
@ -368,16 +384,14 @@ rb_str_times(str, times)
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;
@ -1056,6 +1070,17 @@ rb_str_upto_m(beg, end)
return rb_str_upto(beg, end, 0);
}
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;
@ -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) {

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;

Просмотреть файл

@ -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