summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog23
-rw-r--r--bignum.c10
-rw-r--r--configure.in5
-rw-r--r--io.c39
-rw-r--r--lib/mkmf.rb3
-rw-r--r--pack.c25
6 files changed, 75 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index a92e703..784c5f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Sat Dec 27 00:44:00 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (next_argv): warn always for stdin on inplace edit mode.
+
+ * io.c (read_all): need to check string value.
+
+ * io.c (argf_read): allow ARGF.read(nil). [ruby-dev:22433]
+
+Fri Dec 26 23:02:09 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * io.c (rb_f_backquote): need not to check nil result.
+ [ruby-core:02078]
+
+ * io.c (rb_io_getline): should return nil when read_all gives
+ empty string, even when nil rs is specified. [ruby-core:02077]
+
Fri Dec 26 18:50:59 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in: check if getcontext and setcontext are available.
@@ -8,6 +24,13 @@ Fri Dec 26 16:40:53 2003 Tanaka Akira <akr@m17n.org>
* lib/pathname.rb (PathnameTest#test_plus): add 2 assertions.
+Fri Dec 26 09:26:58 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * pack.c (pack_pack): add sign check for 'i', and 'l'.
+ [ruby-dev:22427]
+
+ * bignum.c (rb_quad_pack): add range check for 'quad int'.
+
Thu Dec 25 22:39:59 2003 NAKAMURA Usaku <usa@ruby-lang.org>
* string.c (rb_str_update): don't return any value.
diff --git a/bignum.c b/bignum.c
index 5089bff..6155ec7 100644
--- a/bignum.c
+++ b/bignum.c
@@ -203,6 +203,8 @@ rb_quad_pack(buf, val)
long len = RBIGNUM(val)->len;
BDIGIT *ds;
+ if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
+ rb_raise(rb_eRangeError, "bignum too big to convert into `quad int'");
ds = BDIGITS(val);
q = 0;
while (len--) {
@@ -272,7 +274,9 @@ rb_quad_pack(buf, val)
val = rb_int2big(FIX2LONG(val));
}
len = RBIGNUM(val)->len * SIZEOF_BDIGITS;
- if (len > QUAD_SIZE) len = QUAD_SIZE;
+ if (len > QUAD_SIZE) {
+ rb_raise(rb_eRangeError, "bignum too big to convert into `quad int'");
+ }
memcpy(buf, (char*)BDIGITS(val), len);
if (!RBIGNUM(val)->sign) {
len = QUAD_SIZE;
@@ -759,10 +763,10 @@ long
rb_big2long(x)
VALUE x;
{
- unsigned long num = big2ulong(x, "int");
+ unsigned long num = big2ulong(x, "long");
if ((long)num < 0 && (RBIGNUM(x)->sign || (long)num != LONG_MIN)) {
- rb_raise(rb_eRangeError, "bignum too big to convert into `int'");
+ rb_raise(rb_eRangeError, "bignum too big to convert into `long'");
}
if (!RBIGNUM(x)->sign) return -(long)num;
return num;
diff --git a/configure.in b/configure.in
index 9226dc9..e49b8d3 100644
--- a/configure.in
+++ b/configure.in
@@ -709,7 +709,10 @@ if test "$enable_pthread" = "yes"; then
fi
AC_CHECK_FUNC(nanosleep)
if test "$ac_cv_func_nanosleep" = "no"; then
- AC_CHECK_LIB(rt, nanosleep, AC_DEFINE(HAVE_NANOSLEEP))
+ AC_CHECK_LIB(rt, nanosleep)
+ if test "$ac_cv_lib_rt_nanosleep" = "yes"; then
+ AC_DEFINE(HAVE_NANOSLEEP)
+ fi
fi
fi
if test $ac_cv_header_ucontext_h = yes; then
diff --git a/io.c b/io.c
index 8f9c9d5..9a49a23 100644
--- a/io.c
+++ b/io.c
@@ -786,6 +786,7 @@ read_all(fptr, siz, str)
str = rb_tainted_str_new(0, siz);
}
else {
+ StringValue(str);
rb_str_resize(str, siz);
}
for (;;) {
@@ -1027,6 +1028,7 @@ rb_io_getline(rs, fptr)
rb_io_check_readable(fptr);
if (NIL_P(rs)) {
str = read_all(fptr, 0, Qnil);
+ if (RSTRING(str)->len == 0) return Qnil;
}
else if (rs == rb_default_rs) {
return rb_io_getline_fast(fptr, '\n');
@@ -1346,8 +1348,8 @@ fptr_finalize(fptr, noraise)
if (fptr->f2) {
f2 = fileno(fptr->f2);
while ((n2 = fclose(fptr->f2)) < 0) {
+ e = errno;
if (!rb_io_wait_writable(f2)) {
- e = errno;
break;
}
if (!fptr->f2) break;
@@ -2990,23 +2992,22 @@ next_argv()
}
else {
next_p = -1;
- current_file = rb_stdin;
- filename = rb_str_new2("-");
}
init_p = 1;
gets_lineno = 0;
}
- retry:
if (next_p == 1) {
next_p = 0;
+ retry:
if (RARRAY(rb_argv)->len > 0) {
filename = rb_ary_shift(rb_argv);
fn = StringValuePtr(filename);
if (strlen(fn) == 1 && fn[0] == '-') {
current_file = rb_stdin;
if (ruby_inplace_mode) {
- rb_warn("Can't do inplace edit for stdio");
+ rb_warn("Can't do inplace edit for stdio; skipping");
+ goto retry;
}
}
else {
@@ -3077,12 +3078,17 @@ next_argv()
}
else {
init_p = 0;
- if (ruby_inplace_mode) {
- rb_stdout = orig_stdout;
- }
return Qfalse;
}
}
+ else if (next_p == -1) {
+ current_file = rb_stdin;
+ filename = rb_str_new2("-");
+ if (ruby_inplace_mode) {
+ rb_warn("Can't do inplace edit for stdio");
+ rb_stdout = orig_stdout;
+ }
+ }
return Qtrue;
}
@@ -3222,10 +3228,8 @@ rb_f_backquote(obj, str)
GetOpenFile(port, fptr);
result = read_all(fptr, remain_size(fptr), Qnil);
-
rb_io_close(port);
- if (NIL_P(result)) return rb_str_new(0,0);
return result;
}
@@ -3828,11 +3832,22 @@ argf_read(argc, argv)
VALUE tmp, str;
long len = 0;
- if (argc == 1) len = NUM2LONG(argv[0]);
+ if (argc == 1 && !NIL_P(argv[0]))
+ len = NUM2LONG(argv[0]);
str = Qnil;
retry:
- if (!next_argv()) return str;
+ if (!next_argv()) {
+ if (NIL_P(str)) {
+ VALUE length;
+
+ rb_scan_args(argc, argv, "02", &length, &str);
+ if (NIL_P(str)) return rb_str_new(0,0);
+ StringValue(str);
+ rb_str_resize(str,0);
+ }
+ return str;
+ }
if (TYPE(current_file) != T_FILE) {
tmp = argf_forward();
}
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 359a741..27e534b 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -217,7 +217,6 @@ def link_command(ldflags, opt="", libpath=$LIBPATH)
'CFLAGS' => "#$CFLAGS",
'ARCH_FLAG' => "#$ARCH_FLAG",
'LDFLAGS' => "#$LDFLAGS #{ldflags}",
- 'DLDFLAGS' => "#$DLDFLAGS",
'LIBPATH' => libpathflag(libpath),
'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS")
@@ -1013,7 +1012,7 @@ COMPILE_C = config_string('COMPILE_C') || '$(CC) $(CFLAGS) $(CPPFLAGS) -c $<'
COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<'
TRY_LINK = config_string('TRY_LINK') ||
"$(CC) #{OUTFLAG}conftest $(INCFLAGS) -I$(hdrdir) $(CPPFLAGS) " \
- "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(DLDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
+ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
LINK_SO = config_string('LINK_SO') ||
if CONFIG["DLEXT"] == $OBJEXT
"ld $(DLDFLAGS) -r -o $(DLLIB) $(OBJS)\n"
diff --git a/pack.c b/pack.c
index e4a301c..4763c81 100644
--- a/pack.c
+++ b/pack.c
@@ -377,15 +377,15 @@ num2u32(x)
#endif
#if SIZEOF_LONG == SIZE32 || SIZEOF_INT == SIZE32
-# define EXTEND32(x) ((I32)(x))
+# define EXTEND32(x)
#else
/* invariant in modulo 1<<31 */
-# define EXTEND32(x) (I32)(((1<<31)-1-(x))^~(~0<<31))
+# define EXTEND32(x) do {if (!natint) {(x) = (I32)(((1<<31)-1-(x))^~(~0<<31))}} while(0)
#endif
#if SIZEOF_SHORT == SIZE16
-# define EXTEND16(x) (short)(x)
+# define EXTEND16(x)
#else
-# define EXTEND16(x) (short)(((1<<15)-1-(x))^~(~0<<15))
+# define EXTEND16(x) do { if (!natint) {(x) = (short)(((1<<15)-1-(x))^~(~0<<15))}} while(0)
#endif
#ifdef HAVE_LONG_LONG
@@ -725,9 +725,12 @@ pack_pack(ary, fmt)
from = NEXTFROM;
if (NIL_P(from)) i = 0;
- else {
+ else if (type == 'i') {
i = NATINT_I32(from);
}
+ else {
+ i = NATINT_U32(from);
+ }
rb_str_buf_cat(res, OFF32(&i), NATINT_LEN(int,4));
}
break;
@@ -739,6 +742,9 @@ pack_pack(ary, fmt)
from = NEXTFROM;
if (NIL_P(from)) l = 0;
+ else if (type == 'l') {
+ l = NATINT_I32(from);
+ }
else {
l = NATINT_U32(from);
}
@@ -1558,9 +1564,7 @@ pack_unpack(str, fmt)
while (len-- > 0) {
short tmp = 0;
memcpy(OFF16(&tmp), s, NATINT_LEN(short,2));
-#if SIZEOF_SHORT != SIZE16
- if (!natint) tmp = EXTEND16(tmp);
-#endif
+ EXTEND16(tmp);
s += NATINT_LEN(short,2);
rb_ary_push(ary, INT2FIX(tmp));
}
@@ -1605,15 +1609,12 @@ pack_unpack(str, fmt)
while (len-- > 0) {
long tmp = 0;
memcpy(OFF32(&tmp), s, NATINT_LEN(long,4));
-#if SIZEOF_LONG != SIZE32
- if (!natint) tmp = EXTEND32(tmp);
-#endif
+ EXTEND32(tmp);
s += NATINT_LEN(long,4);
rb_ary_push(ary, LONG2NUM(tmp));
}
PACK_ITEM_ADJUST();
break;
-
case 'L':
PACK_LENGTH_ADJUST(unsigned long,4);
while (len-- > 0) {