mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_slice_bang): if there's no corresponding
substring, slice! should return nil without exception. * array.c (rb_ary_insert): type fixed. * string.c (rb_str_split_m): accept separator value nil as well. * string.c (rb_str_become): was leaking memory. * class.c (rb_include_module): should not alter other classes/modules by inclusion. by this fix, local order may not be preserved for some cases. * class.c (include_class_new): module may be T_ICLASS; retrieve original module information. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
da72e5a644
commit
be1d2c5f68
14 changed files with 142 additions and 76 deletions
26
ChangeLog
26
ChangeLog
|
@ -3,10 +3,23 @@ Thu Jul 11 12:59:23 2002 Shugo Maeda <shugo@ruby-lang.org>
|
|||
* lib/resolv.rb: untaint strings read from /etc/hosts and
|
||||
/etc/resolv.conf to prevent SecurityError when $SAFE==1.
|
||||
|
||||
Thu Jul 11 09:00:43 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_slice_bang): if there's no corresponding
|
||||
substring, slice! should return nil without exception.
|
||||
|
||||
Tue Jul 9 20:03:55 2002 Keiju Ishitsuka <keiju@ishitsuka.com>
|
||||
|
||||
* irb 0.9
|
||||
|
||||
Sat Jul 6 07:35:02 2002 Jamie Herre <jfh@gettysgroup.com>
|
||||
|
||||
* array.c (rb_ary_insert): type fixed.
|
||||
|
||||
Fri Jul 5 09:17:00 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_split_m): accept separator value nil as well.
|
||||
|
||||
Fri Jul 5 08:59:15 2002 Michal Rokos <michal@ruby-lang.org>
|
||||
|
||||
* enum.c: Fix bug in enum_sort_by and some code indents
|
||||
|
@ -17,6 +30,10 @@ Fri Jul 5 05:00:40 2002 Wakou Aoyama <wakou@ruby-lang.org>
|
|||
thanks to Sean Chittenden <sean@ruby-lang.org>, Shugo Maeda
|
||||
<shugo@modruby.net>
|
||||
|
||||
Fri Jul 5 00:10:09 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_become): was leaking memory.
|
||||
|
||||
Thu Jul 4 23:43:26 2002 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* parse.y: remove useless function str_extend_p().
|
||||
|
@ -46,6 +63,15 @@ Wed Jul 3 02:32:31 2002 Wakou Aoyama <wakou@ruby-lang.org>
|
|||
|
||||
* lib/cgi.rb (CGI#initialize): improvement for mod_ruby.
|
||||
|
||||
Tue Jul 2 14:53:10 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* class.c (rb_include_module): should not alter other
|
||||
classes/modules by inclusion. by this fix, local order may not
|
||||
be preserved for some cases.
|
||||
|
||||
* class.c (include_class_new): module may be T_ICLASS; retrieve
|
||||
original module information.
|
||||
|
||||
Tue Jul 2 14:13:11 2002 Wakou Aoyama <wakou@ruby-lang.org>
|
||||
|
||||
* lib/cgi.rb (CGI#header): accept any type as value.
|
||||
|
|
2
array.c
2
array.c
|
@ -734,7 +734,7 @@ rb_ary_insert(argc, argv, ary)
|
|||
}
|
||||
pos = NUM2LONG(argv[0]);
|
||||
if (pos == -1) {
|
||||
pos = RSTRING(ary)->len;
|
||||
pos = RARRAY(ary)->len;
|
||||
}
|
||||
else if (pos < 0) {
|
||||
pos++;
|
||||
|
|
19
class.c
19
class.c
|
@ -318,6 +318,9 @@ include_class_new(module, super)
|
|||
NEWOBJ(klass, struct RClass);
|
||||
OBJSETUP(klass, rb_cClass, T_ICLASS);
|
||||
|
||||
if (BUILTIN_TYPE(module) == T_ICLASS) {
|
||||
module = RBASIC(module)->klass;
|
||||
}
|
||||
if (!RCLASS(module)->iv_tbl) {
|
||||
RCLASS(module)->iv_tbl = st_init_numtable();
|
||||
}
|
||||
|
@ -363,19 +366,27 @@ rb_include_module(klass, module)
|
|||
OBJ_INFECT(klass, module);
|
||||
c = klass;
|
||||
while (module) {
|
||||
int superclass_seen = Qfalse;
|
||||
|
||||
if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl)
|
||||
rb_raise(rb_eArgError, "cyclic include detected");
|
||||
/* ignore if the module included already in superclasses */
|
||||
for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) {
|
||||
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
||||
switch (BUILTIN_TYPE(p)) {
|
||||
case T_ICLASS:
|
||||
if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) {
|
||||
c = p; /* move insertion point */
|
||||
if (!superclass_seen) {
|
||||
c = p; /* move insertion point */
|
||||
}
|
||||
goto skip;
|
||||
}
|
||||
break;
|
||||
case T_CLASS:
|
||||
superclass_seen = Qtrue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
|
||||
c = RCLASS(c)->super;
|
||||
c = RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
|
||||
changed = 1;
|
||||
skip:
|
||||
module = RCLASS(module)->super;
|
||||
|
|
|
@ -25,9 +25,13 @@ allclean: distclean
|
|||
|
||||
$(OBJS): ./dlconfig.h
|
||||
|
||||
sym.o: call.func
|
||||
sym.o: dl.h call.func
|
||||
|
||||
dl.o: callback.func cbtable.func
|
||||
dl.o: dl.h callback.func cbtable.func
|
||||
|
||||
ptr.o: dl.h
|
||||
|
||||
handle.o: dl.h
|
||||
|
||||
call.func: $(srcdir)/mkcall.rb ./dlconfig.rb
|
||||
@echo "Generating call.func"
|
||||
|
|
10
ext/dl/dl.h
10
ext/dl/dl.h
|
@ -15,6 +15,16 @@
|
|||
|
||||
#if defined(HAVE_DLFCN_H)
|
||||
# include <dlfcn.h>
|
||||
# /* some stranger systems may not define all of these */
|
||||
#ifndef RTLD_LAZY
|
||||
#define RTLD_LAZY 0
|
||||
#endif
|
||||
#ifndef RTLD_GLOBAL
|
||||
#define RTLD_GLOBAL 0
|
||||
#endif
|
||||
#ifndef RTLD_NOW
|
||||
#define RTLD_NOW 0
|
||||
#endif
|
||||
#else
|
||||
# if defined(HAVE_WINDOWS_H)
|
||||
# include <windows.h>
|
||||
|
|
|
@ -55,7 +55,7 @@ module Net
|
|||
@passive = true
|
||||
return SOCKSsocket.open(host, port)
|
||||
else
|
||||
return TCPsocket.open(host, port)
|
||||
return TCPSocket.open(host, port)
|
||||
end
|
||||
end
|
||||
private :open_socket
|
||||
|
@ -173,7 +173,7 @@ module Net
|
|||
private :sendport
|
||||
|
||||
def makeport
|
||||
sock = TCPserver.open(@sock.addr[3], 0)
|
||||
sock = TCPServer.open(@sock.addr[3], 0)
|
||||
port = sock.addr[1]
|
||||
host = sock.addr[3]
|
||||
resp = sendport(host, port)
|
||||
|
|
|
@ -395,7 +395,7 @@ module Net
|
|||
def connect( otime )
|
||||
D "opening connection to #{@address}..."
|
||||
timeout( otime ) {
|
||||
@socket = TCPsocket.new( @address, @port )
|
||||
@socket = TCPSocket.new( @address, @port )
|
||||
}
|
||||
@rbuf = ''
|
||||
end
|
||||
|
|
|
@ -313,10 +313,10 @@ module Net
|
|||
|
||||
begin
|
||||
if @options["Timeout"] == false
|
||||
@sock = TCPsocket.open(@options["Host"], @options["Port"])
|
||||
@sock = TCPSocket.open(@options["Host"], @options["Port"])
|
||||
else
|
||||
timeout(@options["Timeout"]) do
|
||||
@sock = TCPsocket.open(@options["Host"], @options["Port"])
|
||||
@sock = TCPSocket.open(@options["Host"], @options["Port"])
|
||||
end
|
||||
end
|
||||
rescue TimeoutError
|
||||
|
|
|
@ -44,7 +44,7 @@ module Ping
|
|||
def pingecho(host, timeout=5, service="echo")
|
||||
begin
|
||||
timeout(timeout) do
|
||||
s = TCPsocket.new(host, service)
|
||||
s = TCPSocket.new(host, service)
|
||||
s.close
|
||||
end
|
||||
rescue Errno::ECONNREFUSED
|
||||
|
|
|
@ -42,11 +42,18 @@ class PStore
|
|||
|
||||
def [](name)
|
||||
in_transaction
|
||||
unless @table.key? name
|
||||
raise PStore::Error, format("undefined root name `%s'", name)
|
||||
end
|
||||
@table[name]
|
||||
end
|
||||
def fetch(name, default=PStore::Error)
|
||||
unless @table.key? name
|
||||
if default==PStore::Error
|
||||
raise PStore::Error, format("undefined root name `%s'", name)
|
||||
else
|
||||
default
|
||||
end
|
||||
end
|
||||
self[name]
|
||||
end
|
||||
def []=(name, value)
|
||||
in_transaction
|
||||
@table[name] = value
|
||||
|
|
12
process.c
12
process.c
|
@ -1014,14 +1014,16 @@ proc_getpgrp()
|
|||
static VALUE
|
||||
proc_setpgrp()
|
||||
{
|
||||
#if defined(HAVE_SETPGRP) && defined(SETPGRP_VOID)
|
||||
/* check for posix setpgid() first; this matches the posix */
|
||||
/* getpgrp() above. It appears that configure will set SETPGRP_VOID */
|
||||
/* even though setpgrp(0,0) would be prefered. The posix call avoids */
|
||||
/* this confusion. */
|
||||
#ifdef HAVE_SETPGID
|
||||
if (setpgid(0,0) < 0) rb_sys_fail(0);
|
||||
#elif defined(HAVE_SETPGRP) && defined(SETPGRP_VOID)
|
||||
if (setpgrp() < 0) rb_sys_fail(0);
|
||||
#else
|
||||
# ifdef HAVE_SETPGID
|
||||
if (setpgid(0, 0) < 0) rb_sys_fail(0);
|
||||
# else
|
||||
rb_notimplement();
|
||||
# endif
|
||||
#endif
|
||||
return INT2FIX(0);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ require "socket"
|
|||
host=(if ARGV.length == 2; ARGV.shift; else "localhost"; end)
|
||||
print("Trying ", host, " ...")
|
||||
STDOUT.flush
|
||||
s = TCPsocket.open(host, ARGV.shift)
|
||||
s = TCPSocket.open(host, ARGV.shift)
|
||||
print(" done\n")
|
||||
print("addr: ", s.addr.join(":"), "\n")
|
||||
print("peer: ", s.peeraddr.join(":"), "\n")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# simple webpage fetcher
|
||||
|
||||
# The code demonstrates how a multi-protocol client should be written.
|
||||
# TCPsocket is using getaddrinfo() internally, so there should be no problem.
|
||||
# TCPSocket is using getaddrinfo() internally, so there should be no problem.
|
||||
|
||||
require "socket"
|
||||
|
||||
|
@ -36,7 +36,7 @@ end
|
|||
#STDERR.print "path=<#{path}>\n"
|
||||
|
||||
STDERR.print "conntecting to #{host} port #{port}\n"
|
||||
c = TCPsocket.new(host, port)
|
||||
c = TCPSocket.new(host, port)
|
||||
dest = Socket.getnameinfo(c.getpeername,
|
||||
Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
|
||||
STDERR.print "conntected to #{dest[0]} port #{dest[1]}\n"
|
||||
|
|
110
string.c
110
string.c
|
@ -56,18 +56,22 @@ str_new(klass, ptr, len)
|
|||
const char *ptr;
|
||||
long len;
|
||||
{
|
||||
VALUE str = rb_obj_alloc(klass);
|
||||
VALUE str;
|
||||
|
||||
if (len < 0) {
|
||||
rb_raise(rb_eArgError, "negative string size (or size too big)");
|
||||
}
|
||||
|
||||
str = rb_obj_alloc(klass);
|
||||
RSTRING(str)->len = len;
|
||||
RSTRING(str)->aux.capa = len;
|
||||
RSTRING(str)->ptr = ALLOC_N(char,len+1);
|
||||
if (ptr) {
|
||||
memcpy(RSTRING(str)->ptr, ptr, len);
|
||||
}
|
||||
else {
|
||||
MEMZERO(RSTRING(str)->ptr, char, len);
|
||||
}
|
||||
RSTRING(str)->ptr[len] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
@ -176,8 +180,9 @@ rb_str_buf_new(capa)
|
|||
{
|
||||
VALUE str = rb_obj_alloc(rb_cString);
|
||||
|
||||
if (capa < STR_BUF_MIN_SIZE)
|
||||
if (capa < STR_BUF_MIN_SIZE) {
|
||||
capa = STR_BUF_MIN_SIZE;
|
||||
}
|
||||
RSTRING(str)->ptr = 0;
|
||||
RSTRING(str)->len = 0;
|
||||
RSTRING(str)->aux.capa = capa;
|
||||
|
@ -194,8 +199,8 @@ rb_str_buf_new2(ptr)
|
|||
VALUE str;
|
||||
long len = strlen(ptr);
|
||||
|
||||
str = rb_str_buf_new(len + STR_BUF_MIN_SIZE);
|
||||
rb_str_cat(str, ptr, len);
|
||||
str = rb_str_buf_new(len);
|
||||
rb_str_buf_cat(str, ptr, len);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
@ -212,13 +217,13 @@ rb_str_become(str, str2)
|
|||
VALUE str, str2;
|
||||
{
|
||||
if (str == str2) return;
|
||||
if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
|
||||
if (NIL_P(str2)) {
|
||||
RSTRING(str)->ptr = 0;
|
||||
RSTRING(str)->len = 0;
|
||||
RSTRING(str)->aux.capa = 0;
|
||||
return;
|
||||
}
|
||||
if (FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
|
||||
RSTRING(str)->ptr = RSTRING(str2)->ptr;
|
||||
RSTRING(str)->len = RSTRING(str2)->len;
|
||||
if (FL_TEST(str2, ELTS_SHARED|STR_ASSOC)) {
|
||||
|
@ -800,51 +805,6 @@ rb_str_casecmp(str1, str2)
|
|||
return INT2FIX(-1);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_match(x, y)
|
||||
VALUE x, y;
|
||||
{
|
||||
VALUE reg;
|
||||
long start;
|
||||
|
||||
switch (TYPE(y)) {
|
||||
case T_REGEXP:
|
||||
return rb_reg_match(y, x);
|
||||
|
||||
case T_STRING:
|
||||
reg = rb_reg_regcomp(y);
|
||||
start = rb_reg_search(reg, x, 0, 0);
|
||||
if (start == -1) {
|
||||
return Qnil;
|
||||
}
|
||||
return INT2NUM(start);
|
||||
|
||||
default:
|
||||
return rb_funcall(y, rb_intern("=~"), 1, x);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_match2(str)
|
||||
VALUE str;
|
||||
{
|
||||
StringValue(str);
|
||||
return rb_reg_match2(rb_reg_regcomp(str));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_match_m(str, re)
|
||||
VALUE str, re;
|
||||
{
|
||||
VALUE str2 = rb_check_convert_type(re, T_STRING, "String", "to_str");
|
||||
|
||||
if (!NIL_P(str2)) {
|
||||
StringValue(re);
|
||||
re = rb_reg_regcomp(re);
|
||||
}
|
||||
return rb_funcall(re, rb_intern("match"), 1, str);
|
||||
}
|
||||
|
||||
static long
|
||||
rb_str_index(str, sub, offset)
|
||||
VALUE str, sub;
|
||||
|
@ -1009,6 +969,50 @@ rb_str_rindex(argc, argv, str)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_match(x, y)
|
||||
VALUE x, y;
|
||||
{
|
||||
VALUE reg;
|
||||
long start;
|
||||
|
||||
switch (TYPE(y)) {
|
||||
case T_REGEXP:
|
||||
return rb_reg_match(y, x);
|
||||
|
||||
case T_STRING:
|
||||
start = rb_str_index(reg, x, 0);
|
||||
if (start == -1) {
|
||||
return Qnil;
|
||||
}
|
||||
return INT2NUM(start);
|
||||
|
||||
default:
|
||||
return rb_funcall(y, rb_intern("=~"), 1, x);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_match2(str)
|
||||
VALUE str;
|
||||
{
|
||||
StringValue(str);
|
||||
return rb_reg_match2(rb_reg_regcomp(str));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_match_m(str, re)
|
||||
VALUE str, re;
|
||||
{
|
||||
VALUE str2 = rb_check_convert_type(re, T_STRING, "String", "to_str");
|
||||
|
||||
if (!NIL_P(str2)) {
|
||||
StringValue(re);
|
||||
re = rb_reg_regcomp(re);
|
||||
}
|
||||
return rb_funcall(re, rb_intern("match"), 1, str);
|
||||
}
|
||||
|
||||
static char
|
||||
succ_char(s)
|
||||
char *s;
|
||||
|
@ -1384,7 +1388,9 @@ rb_str_slice_bang(argc, argv, str)
|
|||
}
|
||||
buf[i] = rb_str_new(0,0);
|
||||
result = rb_str_aref_m(argc, buf, str);
|
||||
rb_str_aset_m(argc+1, buf, str);
|
||||
if (!NIL_P(result)) {
|
||||
rb_str_aset_m(argc+1, buf, str);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2456,7 +2462,7 @@ rb_str_split_m(argc, argv, str)
|
|||
i = 1;
|
||||
}
|
||||
|
||||
if (argc == 0) {
|
||||
if (NIL_P(spat)) {
|
||||
if (!NIL_P(rb_fs)) {
|
||||
spat = rb_fs;
|
||||
goto fs_set;
|
||||
|
|
Loading…
Reference in a new issue