summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog28
-rw-r--r--array.c2
-rw-r--r--eval.c8
-rw-r--r--file.c4
-rw-r--r--hash.c6
-rw-r--r--intern.h2
-rw-r--r--io.c14
-rw-r--r--lib/irb/ruby-lex.rb3
-rw-r--r--misc/ruby-mode.el1
-rw-r--r--numeric.c4
-rw-r--r--object.c12
-rw-r--r--pack.c39
-rw-r--r--process.c53
-rw-r--r--re.c8
-rw-r--r--sprintf.c62
-rw-r--r--string.c2
-rw-r--r--struct.c4
-rw-r--r--time.c6
18 files changed, 136 insertions, 122 deletions
diff --git a/ChangeLog b/ChangeLog
index 95c6c89..f957e36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,34 @@ Tue Dec 10 12:01:15 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (mnew): original class of method defined in module should
be the module not intermediate class. [ruby-dev:19040]
+Tue Dec 10 01:16:52 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * sprintf.c (rb_f_sprintf): preceding ".." for negative numbers
+ still left; removed.
+
+ * sprintf.c (rb_f_sprintf): should not prepend '0' if width > prec
+ for example "%5.3d".
+
+Sat Dec 7 18:14:23 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * process.c (Init_process): add Process.exit and Process.abort
+
+ * pack.c (utf8_to_uv): raise ArgumentError for malformed/redundant
+ UTF-8 sequences.
+
+Fri Dec 6 03:46:00 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * process.c (last_status_set): add pid attribute to Process::Status.
+
+Wed Dec 4 17:31:42 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * pack.c (uv_to_utf8): limit maximum length of the encoded string
+ to 6 bytes, even when the platform supports 8 bytes long integers.
+
+ * pack.c (utf8_to_uv): do not decode sequences longer than 6 bytes.
+
+ * object.c (copy_object): use "copy_object" method, not "become".
+
Wed Dec 4 16:37:11 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (copy_object): copy finalizers as well if any.
diff --git a/array.c b/array.c
index 7b3dc52..e6c605d 100644
--- a/array.c
+++ b/array.c
@@ -1902,7 +1902,7 @@ Init_Array()
rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
- rb_define_method(rb_cArray, "become", rb_ary_replace, 1);
+ rb_define_method(rb_cArray, "copy_object", rb_ary_replace, 1);
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
diff --git a/eval.c b/eval.c
index 1daf12e..b5d8f14 100644
--- a/eval.c
+++ b/eval.c
@@ -3588,11 +3588,10 @@ rb_exit(status)
exit(status);
}
-static VALUE
-rb_f_exit(argc, argv, obj)
+VALUE
+rb_f_exit(argc, argv)
int argc;
VALUE *argv;
- VALUE obj;
{
VALUE status;
int istatus;
@@ -3608,7 +3607,7 @@ rb_f_exit(argc, argv, obj)
return Qnil; /* not reached */
}
-static VALUE
+VALUE
rb_f_abort(argc, argv)
int argc;
VALUE *argv;
@@ -9458,6 +9457,7 @@ Init_Thread()
rb_define_method(rb_cThread, "run", rb_thread_run, 0);
rb_define_method(rb_cThread, "wakeup", rb_thread_wakeup, 0);
rb_define_method(rb_cThread, "kill", rb_thread_kill, 0);
+ rb_define_method(rb_cThread, "terminate", rb_thread_kill, 0);
rb_define_method(rb_cThread, "exit", rb_thread_kill, 0);
rb_define_method(rb_cThread, "value", rb_thread_value, 0);
rb_define_method(rb_cThread, "status", rb_thread_status, 0);
diff --git a/file.c b/file.c
index ebfdcc5..ea3b260 100644
--- a/file.c
+++ b/file.c
@@ -2030,7 +2030,7 @@ rb_stat_init(obj, fname)
}
static VALUE
-rb_stat_become(copy, orig)
+rb_stat_copy_object(copy, orig)
VALUE copy, orig;
{
struct stat *nst;
@@ -2680,7 +2680,7 @@ Init_File()
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
rb_define_singleton_method(rb_cStat, "allocate", rb_stat_s_alloc, 0);
rb_define_method(rb_cStat, "initialize", rb_stat_init, 1);
- rb_define_method(rb_cStat, "become", rb_stat_become, 1);
+ rb_define_method(rb_cStat, "copy_object", rb_stat_copy_object, 1);
rb_include_module(rb_cStat, rb_mComparable);
diff --git a/hash.c b/hash.c
index 8a9f8f2..89d7b16 100644
--- a/hash.c
+++ b/hash.c
@@ -576,7 +576,7 @@ replace_i(key, val, hash)
}
static VALUE
-rb_hash_become(hash, hash2)
+rb_hash_replace(hash, hash2)
VALUE hash, hash2;
{
hash2 = to_hash(hash2);
@@ -1599,7 +1599,7 @@ Init_Hash()
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
- rb_define_method(rb_cHash,"become", rb_hash_become, 1);
+ rb_define_method(rb_cHash,"copy_object", rb_hash_replace, 1);
rb_define_method(rb_cHash,"rehash", rb_hash_rehash, 0);
rb_define_method(rb_cHash,"to_hash", rb_hash_to_hash, 0);
@@ -1640,7 +1640,7 @@ Init_Hash()
rb_define_method(rb_cHash,"clear", rb_hash_clear, 0);
rb_define_method(rb_cHash,"invert", rb_hash_invert, 0);
rb_define_method(rb_cHash,"update", rb_hash_update, 1);
- rb_define_method(rb_cHash,"replace", rb_hash_become, 1);
+ rb_define_method(rb_cHash,"replace", rb_hash_replace, 1);
rb_define_method(rb_cHash,"include?", rb_hash_has_key, 1);
rb_define_method(rb_cHash,"member?", rb_hash_has_key, 1);
diff --git a/intern.h b/intern.h
index f7838d6..07b5b5e 100644
--- a/intern.h
+++ b/intern.h
@@ -138,6 +138,8 @@ EXTERN struct RNode *ruby_current_node;
void ruby_set_current_source _((void));
NORETURN(void rb_exc_raise _((VALUE)));
NORETURN(void rb_exc_fatal _((VALUE)));
+VALUE rb_f_exit _((int,VALUE*));
+VALUE rb_f_abort _((int,VALUE*));
void rb_remove_method _((VALUE, const char*));
void rb_disable_super _((VALUE, const char*));
void rb_enable_super _((VALUE, const char*));
diff --git a/io.c b/io.c
index 5eecc94..b34c988 100644
--- a/io.c
+++ b/io.c
@@ -2376,17 +2376,17 @@ rb_io_reopen(argc, argv, file)
}
static VALUE
-rb_io_become(clone, io)
- VALUE clone, io;
+rb_io_copy_object(dest, io)
+ VALUE dest, io;
{
OpenFile *fptr, *orig;
int fd;
char *mode;
io = rb_io_get_io(io);
- if (clone == io) return clone;
+ if (dest == io) return dest;
GetOpenFile(io, orig);
- MakeOpenFile(clone, fptr);
+ MakeOpenFile(dest, fptr);
if (orig->f2) {
io_fflush(orig->f2, orig);
@@ -2422,10 +2422,10 @@ rb_io_become(clone, io)
fptr->f2 = rb_fdopen(fd, "w");
}
if (fptr->mode & FMODE_BINMODE) {
- rb_io_binmode(clone);
+ rb_io_binmode(dest);
}
- return clone;
+ return dest;
}
VALUE
@@ -3906,7 +3906,7 @@ Init_IO()
rb_define_hooked_variable("$.", &lineno, 0, lineno_setter);
rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
- rb_define_method(rb_cIO, "become", rb_io_become, 1);
+ rb_define_method(rb_cIO, "copy_object", rb_io_copy_object, 1);
rb_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
rb_define_method(rb_cIO, "print", rb_io_print, -1);
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 1bf47c1..26b0b3b 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -790,7 +790,8 @@ class RubyLex
valid = false unless peek_match?(/^\s*(<<|\w)/)
when "def"
- valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)?=|\&\&|\|\|)/)
+ valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)=|\&\&|\|\|)/)
+# valid = false if peek_match?(/^\s*(([+-\/*&\|^]|<<|>>|\|\||\&\&)?=|\&\&|\|\|)/)
when "do"
valid = false if peek_match?(/^\s*([+-\/*]?=|\*|<|>|\&)/)
when *ENINDENT_CLAUSE
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 408b123..304c481 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -201,6 +201,7 @@ Also ignores spaces after parenthesis when 'space.")
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t))
+;;;###autoload
(defun ruby-mode ()
"Major mode for editing ruby scripts.
\\[ruby-indent-command] properly indents subexpressions of multi-line
diff --git a/numeric.c b/numeric.c
index 9bf9539..c1e0645 100644
--- a/numeric.c
+++ b/numeric.c
@@ -88,7 +88,7 @@ rb_num_coerce_bin(x, y)
}
static VALUE
-num_become(x, y)
+num_copy_object(x, y)
VALUE x, y;
{
/* Numerics are immutable values, which should not be copied */
@@ -1650,7 +1650,7 @@ Init_Numeric()
rb_include_module(rb_cNumeric, rb_mComparable);
rb_define_method(rb_cNumeric, "coerce", num_coerce, 1);
- rb_define_method(rb_cNumeric, "become", num_become, 1);
+ rb_define_method(rb_cNumeric, "copy_object", num_copy_object, 1);
rb_define_method(rb_cNumeric, "+@", num_uplus, 0);
rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
diff --git a/object.c b/object.c
index 06c748a..7eed51b 100644
--- a/object.c
+++ b/object.c
@@ -33,7 +33,7 @@ VALUE rb_cSymbol;
static ID eq, eql;
static ID inspect;
-static ID become;
+static ID copy_obj;
static ID alloc;
VALUE
@@ -115,7 +115,7 @@ copy_object(dest, obj)
}
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
- rb_funcall(dest, become, 1, obj);
+ rb_funcall(dest, copy_obj, 1, obj);
if (FL_TEST(obj, FL_EXIVAR)) {
rb_copy_generic_ivar(dest, obj);
}
@@ -167,13 +167,13 @@ rb_obj_dup(obj)
}
VALUE
-rb_obj_become(obj, orig)
+rb_obj_copy_object(obj, orig)
VALUE obj, orig;
{
if (obj == orig) return obj;
rb_check_frozen(obj);
if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
- rb_raise(rb_eTypeError, "become should take same class object");
+ rb_raise(rb_eTypeError, "copy_object should take same class object");
}
return obj;
}
@@ -1333,7 +1333,7 @@ Init_Object()
rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
- rb_define_method(rb_mKernel, "become", rb_obj_become, 1);
+ rb_define_method(rb_mKernel, "copy_object", rb_obj_copy_object, 1);
rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
@@ -1470,5 +1470,5 @@ Init_Object()
eq = rb_intern("==");
eql = rb_intern("eql?");
inspect = rb_intern("inspect");
- become = rb_intern("become");
+ copy_obj = rb_intern("copy_object");
}
diff --git a/pack.c b/pack.c
index 74ef708..ef540c6 100644
--- a/pack.c
+++ b/pack.c
@@ -1833,21 +1833,7 @@ uv_to_utf8(buf, uv)
buf[5] = (uv&0x3f)|0x80;
return 6;
}
-#if SIZEOF_LONG > 4
- if (uv <= 0xfffffffff) {
-#endif
- buf[0] = 0xfe;
- buf[1] = ((uv>>30)&0x3f)|0x80;
- buf[2] = ((uv>>24)&0x3f)|0x80;
- buf[3] = ((uv>>18)&0x3f)|0x80;
- buf[4] = ((uv>>12)&0x3f)|0x80;
- buf[5] = ((uv>>6)&0x3f)|0x80;
- buf[6] = (uv&0x3f)|0x80;
- return 7;
-#if SIZEOF_LONG > 4
- }
rb_raise(rb_eArgError, "uv_to_utf8(); too big value");
-#endif
}
static const long utf8_limits[] = {
@@ -1866,7 +1852,7 @@ utf8_to_uv(p, lenp)
long *lenp;
{
int c = *p++ & 0xff;
- unsigned long uv = c;
+ unsigned LONG_LONG uv = c;
long n;
if (!(uv & 0x80)) {
@@ -1874,9 +1860,8 @@ utf8_to_uv(p, lenp)
return uv;
}
if (!(uv & 0x40)) {
- rb_warning("malformed UTF-8 character");
*lenp = 1;
- return uv;
+ rb_raise(rb_eArgError, "malformed UTF-8 character");
}
if (!(uv & 0x20)) { n = 2; uv &= 0x1f; }
@@ -1884,21 +1869,21 @@ utf8_to_uv(p, lenp)
else if (!(uv & 0x08)) { n = 4; uv &= 0x07; }
else if (!(uv & 0x04)) { n = 5; uv &= 0x03; }
else if (!(uv & 0x02)) { n = 6; uv &= 0x01; }
- else if (!(uv & 0x01)) { n = 7; uv = 0; }
- else { n = 13; uv = 0; }
+ else {
+ *lenp = 1;
+ rb_raise(rb_eArgError, "malformed UTF-8 character");
+ }
if (n > *lenp) {
- rb_warning("malformed UTF-8 character (expected %d bytes, given %d bytes)",
- n, *lenp);
- return 0xfffd;
+ rb_raise(rb_eArgError, "malformed UTF-8 character (expected %d bytes, given %d bytes)",
+ n, *lenp);
}
*lenp = n--;
if (n != 0) {
while (n--) {
c = *p++ & 0xff;
if ((c & 0xc0) != 0x80) {
- rb_warning("malformed UTF-8 character");
*lenp -= n + 1;
- return 0xfffd;
+ rb_raise(rb_eArgError, "malformed UTF-8 character");
}
else {
c &= 0x3f;
@@ -1907,10 +1892,8 @@ utf8_to_uv(p, lenp)
}
}
n = *lenp - 1;
- if (n < 6) {
- if (uv < utf8_limits[n] || utf8_limits[n+1] <= uv) {
- rb_warning("redundant UTF-8 sequence");
- }
+ if (uv < utf8_limits[n]) {
+ rb_raise(rb_eArgError, "redundant UTF-8 sequence");
}
return uv;
}
diff --git a/process.c b/process.c
index a0ab34e..31b6926 100644
--- a/process.c
+++ b/process.c
@@ -85,11 +85,12 @@ static VALUE rb_cProcStatus;
VALUE rb_last_status = Qnil;
static void
-last_status_set(status)
- int status;
+last_status_set(status, pid)
+ int status, pid;
{
rb_last_status = rb_obj_alloc(rb_cProcStatus);
rb_iv_set(rb_last_status, "status", INT2FIX(status));
+ rb_iv_set(rb_last_status, "pid", INT2FIX(pid));
}
static VALUE
@@ -107,6 +108,13 @@ pst_to_s(st)
}
static VALUE
+pst_pid(st)
+ VALUE st;
+{
+ return rb_iv_get(st, "pid");
+}
+
+static VALUE
pst_equal(st1, st2)
VALUE st1, st2;
{
@@ -258,7 +266,7 @@ rb_waitpid(pid, st, flags)
}
#else /* NO_WAITPID */
if (pid_tbl && st_lookup(pid_tbl, pid, st)) {
- last_status_set(*st);
+ last_status_set(*st, pid);
st_delete(pid_tbl, &pid, NULL);
return pid;
}
@@ -287,7 +295,9 @@ rb_waitpid(pid, st, flags)
if (!rb_thread_alone()) rb_thread_schedule();
}
#endif
- last_status_set(*st);
+ if (result > 0) {
+ last_status_set(*st, result);
+ }
return result;
}
@@ -298,24 +308,24 @@ struct wait_data {
};
static int
-wait_each(key, value, data)
- int key, value;
+wait_each(pid, status, data)
+ int pid, status;
struct wait_data *data;
{
if (data->status != -1) return ST_STOP;
- data->pid = key;
- data->status = value;
+ data->pid = pid;
+ data->status = status;
return ST_DELETE;
}
static int
-waitall_each(key, value, data)
- int key, value;
- VALUE data;
+waitall_each(pid, status, ary)
+ int pid, status;
+ VALUE ary;
{
- last_status_set(value);
- rb_ary_push(data, rb_assoc_new(INT2NUM(key), rb_last_status));
+ last_status_set(status, pid);
+ rb_ary_push(ary, rb_assoc_new(INT2NUM(pid), rb_last_status));
return ST_DELETE;
}
#endif
@@ -342,8 +352,7 @@ proc_wait(argc, argv)
if ((pid = rb_waitpid(pid, &status, flags)) < 0)
rb_sys_fail(0);
if (pid == 0) {
- rb_last_status = Qnil;
- return Qnil;
+ return rb_last_status = Qnil;
}
return INT2FIX(pid);
}
@@ -381,7 +390,7 @@ proc_waitall()
}
rb_sys_fail(0);
}
- last_status_set(status);
+ last_status_set(status, pid);
rb_ary_push(result, rb_assoc_new(INT2NUM(pid), rb_last_status));
}
#else
@@ -817,7 +826,7 @@ rb_f_system(argc, argv)
SafeStringValue(cmd);
status = do_spawn(RSTRING(cmd)->ptr);
- last_status_set(status);
+ last_status_set(status, 0);
if (status == 0) return Qtrue;
return Qfalse;
@@ -840,7 +849,7 @@ rb_f_system(argc, argv)
SafeStringValue(cmd);
status = system(RSTRING(cmd)->ptr);
- last_status_set((status & 0xff) << 8);
+ last_status_set((status & 0xff) << 8, 0);
if (status == 0) return Qtrue;
return Qfalse;
@@ -870,7 +879,7 @@ rb_f_system(argc, argv)
else {
status = proc_spawn_n(argc, argv, prog);
}
- last_status_set(status == -1 ? 127 : status);
+ last_status_set(status == -1 ? 127 : status, 0);
return status == 0 ? Qtrue : Qfalse;
#elif defined(__VMS)
VALUE cmd;
@@ -891,7 +900,7 @@ rb_f_system(argc, argv)
SafeStringValue(cmd);
status = system(RSTRING(cmd)->ptr);
- last_status_set((status & 0xff) << 8);
+ last_status_set((status & 0xff) << 8, 0);
if (status == 0) return Qtrue;
return Qfalse;
@@ -1301,6 +1310,8 @@ Init_process()
rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0);
rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1);
+ rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1);
+ rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1);
rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1);
rb_define_module_function(rb_mProcess, "wait", proc_wait, -1);
@@ -1320,6 +1331,8 @@ Init_process()
rb_define_method(rb_cProcStatus, "to_s", pst_to_s, 0);
rb_define_method(rb_cProcStatus, "inspect", pst_to_s, 0);
+ rb_define_method(rb_cProcStatus, "pid", pst_pid, 0);
+
rb_define_method(rb_cProcStatus, "stopped?", pst_wifstopped, 0);
rb_define_method(rb_cProcStatus, "stopsig", pst_wstopsig, 0);
rb_define_method(rb_cProcStatus, "signaled?", pst_wifsignaled, 0);
diff --git a/re.c b/re.c
index 0e4cd56..9972ba0 100644
--- a/re.c
+++ b/re.c
@@ -527,7 +527,7 @@ match_alloc(klass)
}
static VALUE
-match_become(obj, orig)
+match_copy_object(obj, orig)
VALUE obj, orig;
{
if (obj == orig) return obj;
@@ -1309,7 +1309,7 @@ rb_reg_options(re)
}
static VALUE
-rb_reg_become(copy, re)
+rb_reg_copy_object(copy, re)
VALUE copy, re;
{
if (copy == re) return copy;
@@ -1562,7 +1562,7 @@ Init_Regexp()
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
- rb_define_method(rb_cRegexp, "become", rb_reg_become, 1);
+ rb_define_method(rb_cRegexp, "copy_object", rb_reg_copy_object, 1);
rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
rb_define_method(rb_cRegexp, "===", rb_reg_match, 1);
@@ -1586,7 +1586,7 @@ Init_Regexp()
rb_define_singleton_method(rb_cMatch, "allocate", match_alloc, 0);
rb_undef_method(CLASS_OF(rb_cMatch), "new");
- rb_define_method(rb_cMatch, "become", match_become, 1);
+ rb_define_method(rb_cMatch, "copy_object", match_copy_object, 1);
rb_define_method(rb_cMatch, "size", match_size, 0);
rb_define_method(rb_cMatch, "length", match_size, 0);
rb_define_method(rb_cMatch, "offset", match_offset, 1);
diff --git a/sprintf.c b/sprintf.c
index f5e9542..1013d66 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -436,16 +436,14 @@ rb_f_sprintf(argc, argv)
if (s[0] == '-') {
s++;
sc = '-';
- width--;
}
else if (flags & FPLUS) {
sc = '+';
- width--;
}
else if (flags & FSPACE) {
sc = ' ';
- width--;
}
+ width--;
goto format_integer;
}
if (!RBIGNUM(val)->sign) {
@@ -492,11 +490,17 @@ rb_f_sprintf(argc, argv)
pp++;
}
}
- if (prec < len) prec = len;
- width -= prec;
- if (!(flags&(FZERO|FMINUS)) && v >= 0) {
+ if ((flags&(FZERO|FPREC)) == FZERO) {
+ prec = width;
+ width = 0;
+ }
+ else {
+ if (prec < len) prec = len;
+ width -= prec;
+ }
+ if (!(flags&FMINUS)) {
CHECK(width);
- while (width-->0) {
+ while (width-- > 0) {
buf[blen++] = ' ';
}
}
@@ -504,36 +508,9 @@ rb_f_sprintf(argc, argv)
if (prefix) {
int plen = strlen(prefix);
PUSH(prefix, plen);
- if (pos) pos += plen;
- }
- if (!(flags & FMINUS)) {
- char c = ' ';
-
- if (v < 0) {
- c = '.';
- if ((flags & FPREC) && prec > len) {
- pos = blen;
- }
- else {
- pos = blen + 2;
- }
- }
- else if (flags & FZERO) c = '0';
- CHECK(width);
- while (width-->0) {
- buf[blen++] = c;
- }
}
CHECK(prec - len);
- while (len < prec--) {
- buf[blen++] = v < 0 ? '.' : '0';
- }
- PUSH(s, len);
- CHECK(width);
- while (width-->0) {
- buf[blen++] = ' ';
- }
- if (pos >= 0 && buf[pos] == '.') {
+ if (v < 0) {
char c = '.';
switch (base) {
@@ -546,11 +523,20 @@ rb_f_sprintf(argc, argv)
case 2:
c = '1'; break;
}
- s = &buf[pos];
- while (*s && *s == '.') {
- *s++ = c;
+ while (len < prec--) {
+ buf[blen++] = c;
}
}
+ else {
+ while (len < prec--) {
+ buf[blen++] = '0';
+ }
+ }
+ PUSH(s, len);
+ CHECK(width);
+ while (width-- > 0) {
+ buf[blen++] = ' ';
+ }
}
break;
diff --git a/string.c b/string.c
index e5aa6e2..754db30 100644
--- a/string.c
+++ b/string.c
@@ -3154,7 +3154,7 @@ Init_String()
rb_include_module(rb_cString, rb_mEnumerable);
rb_define_singleton_method(rb_cString, "allocate", rb_str_s_alloc, 0);
rb_define_method(rb_cString, "initialize", rb_str_init, -1);
- rb_define_method(rb_cString, "become", rb_str_replace, 1);
+ rb_define_method(rb_cString, "copy_object", rb_str_replace, 1);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
rb_define_method(rb_cString, "==", rb_str_equal, 1);
rb_define_method(rb_cString, "===", rb_str_equal, 1);
diff --git a/struct.c b/struct.c
index 57e9e11..e8ae73a 100644
--- a/struct.c
+++ b/struct.c
@@ -421,7 +421,7 @@ rb_struct_to_a(s)
}
static VALUE
-rb_struct_become(copy, s)
+rb_struct_copy_object(copy, s)
VALUE copy, s;
{
if (copy == s) return copy;
@@ -592,7 +592,7 @@ Init_Struct()
rb_define_singleton_method(rb_cStruct, "new", rb_struct_s_def, -1);
rb_define_method(rb_cStruct, "initialize", rb_struct_initialize, -2);
- rb_define_method(rb_cStruct, "become", rb_struct_become, 1);
+ rb_define_method(rb_cStruct, "copy_object", rb_struct_copy_object, 1);
rb_define_method(rb_cStruct, "==", rb_struct_equal, 1);
diff --git a/time.c b/time.c
index adb92c7..cb3b3d7 100644
--- a/time.c
+++ b/time.c
@@ -781,7 +781,7 @@ time_modify(time)
}
static VALUE
-time_become(copy, time)
+time_copy_object(copy, time)
VALUE copy, time;
{
struct time_object *tobj, *tcopy;
@@ -803,7 +803,7 @@ time_dup(time)
VALUE time;
{
VALUE dup = time_s_alloc(rb_cTime);
- time_become(dup, time);
+ time_copy_object(dup, time);
return dup;
}
@@ -1411,7 +1411,7 @@ Init_Time()
rb_define_method(rb_cTime, "<=>", time_cmp, 1);
rb_define_method(rb_cTime, "eql?", time_eql, 1);
rb_define_method(rb_cTime, "hash", time_hash, 0);
- rb_define_method(rb_cTime, "become", time_become, 1);
+ rb_define_method(rb_cTime, "copy_object", time_copy_object, 1);
rb_define_method(rb_cTime, "localtime", time_localtime, 0);
rb_define_method(rb_cTime, "gmtime", time_gmtime, 0);