summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog26
-rw-r--r--array.c2
-rw-r--r--class.c19
-rw-r--r--ext/dl/depend8
-rw-r--r--ext/dl/dl.h10
-rw-r--r--lib/net/ftp.rb4
-rw-r--r--lib/net/protocol.rb2
-rw-r--r--lib/net/telnet.rb4
-rw-r--r--lib/ping.rb2
-rw-r--r--lib/pstore.rb11
-rw-r--r--process.c12
-rw-r--r--sample/clnt.rb2
-rw-r--r--sample/dualstack-fetch.rb4
-rw-r--r--string.c110
14 files changed, 141 insertions, 75 deletions
diff --git a/ChangeLog b/ChangeLog
index be94f252aa..d5022d3258 100644
--- a/ChangeLog
+++ b/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.
diff --git a/array.c b/array.c
index 90acbce6e2..b505775626 100644
--- a/array.c
+++ b/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++;
diff --git a/class.c b/class.c
index 962a9abefc..6fb7b51519 100644
--- a/class.c
+++ b/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;
diff --git a/ext/dl/depend b/ext/dl/depend
index 7f1c2ecb15..3d62fe3421 100644
--- a/ext/dl/depend
+++ b/ext/dl/depend
@@ -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"
diff --git a/ext/dl/dl.h b/ext/dl/dl.h
index 9554ea91ba..19ec859f6a 100644
--- a/ext/dl/dl.h
+++ b/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>
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 1d8cbba554..75e087a20c 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -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)
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 0398e512e1..df38725cb9 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -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
diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb
index 91c4faedbe..62a8246d11 100644
--- a/lib/net/telnet.rb
+++ b/lib/net/telnet.rb
@@ -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
diff --git a/lib/ping.rb b/lib/ping.rb
index d698dd0c52..d90551e671 100644
--- a/lib/ping.rb
+++ b/lib/ping.rb
@@ -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
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 23b2d878a3..dfec76e470 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -42,10 +42,17 @@ class PStore
def [](name)
in_transaction
+ @table[name]
+ end
+ def fetch(name, default=PStore::Error)
unless @table.key? name
- raise PStore::Error, format("undefined root name `%s'", name)
+ if default==PStore::Error
+ raise PStore::Error, format("undefined root name `%s'", name)
+ else
+ default
+ end
end
- @table[name]
+ self[name]
end
def []=(name, value)
in_transaction
diff --git a/process.c b/process.c
index 329c5ff1d6..b4f462bf7b 100644
--- a/process.c
+++ b/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);
}
diff --git a/sample/clnt.rb b/sample/clnt.rb
index 7998379aa2..4f96ca4089 100644
--- a/sample/clnt.rb
+++ b/sample/clnt.rb
@@ -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")
diff --git a/sample/dualstack-fetch.rb b/sample/dualstack-fetch.rb
index ab8d0914f2..1897a3d8e9 100644
--- a/sample/dualstack-fetch.rb
+++ b/sample/dualstack-fetch.rb
@@ -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"
diff --git a/string.c b/string.c
index 9894423f80..9aeb7ef800 100644
--- a/string.c
+++ b/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;