summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 08:06:46 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-02 08:06:46 +0000
commit230b8b524da27baaee1ded6bfc8bdef842940400 (patch)
tree5a1dfb3ad743ee6958bb43efc437ac0ed260a8fe
parent55eecb54e79260379480dacb13272b10699ec5a8 (diff)
merges r29446 and r29448 from trunk into ruby_1_9_2.
-- * numeric.c (rb_enc_uint_chr): split from int_chr. * numeric.c (int_chr): use rb_enc_uint_chr. * include/ruby/encoding.h (rb_enc_uint_chr): added. -- * io.c (rb_io_ungetc): use unsigned int for GB18030. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@30038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--include/ruby/encoding.h1
-rw-r--r--io.c11
-rw-r--r--numeric.c27
-rw-r--r--test/ruby/test_io_m17n.rb24
-rw-r--r--version.h2
6 files changed, 60 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 7244badd39..5eae3c70ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Tue Oct 12 15:36:09 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * io.c (rb_io_ungetc): use unsigned int for GB18030.
+
+Tue Oct 12 15:10:31 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * numeric.c (rb_enc_uint_chr): split from int_chr.
+
+ * numeric.c (int_chr): use rb_enc_uint_chr.
+
+ * include/ruby/encoding.h (rb_enc_uint_chr): added.
+
Tue Oct 12 14:04:41 2010 NARUSE, Yui <naruse@ruby-lang.org>
* numeric.c (int_chr): a codepoint of Ruby M17N must be 32bit
diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h
index 88f5e52101..1573b5b200 100644
--- a/include/ruby/encoding.h
+++ b/include/ruby/encoding.h
@@ -98,6 +98,7 @@ long rb_enc_strlen(const char*, const char*, rb_encoding*);
char* rb_enc_nth(const char*, const char*, long, rb_encoding*);
VALUE rb_obj_encoding(VALUE);
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
+VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
diff --git a/io.c b/io.c
index 9ed13a0296..935586e959 100644
--- a/io.c
+++ b/io.c
@@ -3193,12 +3193,13 @@ rb_io_ungetc(VALUE io, VALUE c)
rb_io_check_char_readable(fptr);
if (NIL_P(c)) return Qnil;
if (FIXNUM_P(c)) {
- int cc = FIX2INT(c);
- rb_encoding *enc = io_read_encoding(fptr);
- char buf[16];
-
- c = rb_str_new(buf, rb_enc_mbcput(cc, buf, enc));
+ c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr));
}
+#if SIZEOF_LONG > SIZEOF_INT
+ else if (TYPE(c) == T_BIGNUM) {
+ c = rb_enc_uint_chr(NUM2UINT(c), io_read_encoding(fptr));
+ }
+#endif
else {
SafeStringValue(c);
}
diff --git a/numeric.c b/numeric.c
index 170d970bdc..1bb8d5c75c 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2038,6 +2038,19 @@ int_pred(VALUE num)
return rb_funcall(num, '-', 1, INT2FIX(1));
}
+VALUE
+rb_enc_uint_chr(unsigned int code, rb_encoding *enc)
+{
+ int n;
+ VALUE str;
+ if ((n = rb_enc_codelen(code, enc)) <= 0) {
+ rb_raise(rb_eRangeError, "%d out of char range", code);
+ }
+ str = rb_enc_str_new(0, n, enc);
+ rb_enc_mbcput(code, RSTRING_PTR(str), enc);
+ return str;
+}
+
/*
* call-seq:
* int.chr([encoding]) -> string
@@ -2054,16 +2067,14 @@ static VALUE
int_chr(int argc, VALUE *argv, VALUE num)
{
char c;
- int n;
- uint32_t i = NUM2UINT(num);
+ unsigned int i = NUM2UINT(num);
rb_encoding *enc;
- VALUE str;
switch (argc) {
case 0:
if (i < 0) {
out_of_range:
- rb_raise(rb_eRangeError, "%"PRIdVALUE " out of char range", i);
+ rb_raise(rb_eRangeError, "%d out of char range", i);
}
if (0xff < i) {
enc = rb_default_internal_encoding();
@@ -2086,13 +2097,7 @@ int_chr(int argc, VALUE *argv, VALUE num)
enc = rb_to_encoding(argv[0]);
if (!enc) enc = rb_ascii8bit_encoding();
decode:
-#if SIZEOF_INT < SIZEOF_VALUE
- if (i > UINT_MAX) goto out_of_range;
-#endif
- if (i < 0 || (n = rb_enc_codelen(i, enc)) <= 0) goto out_of_range;
- str = rb_enc_str_new(0, n, enc);
- rb_enc_mbcput(i, RSTRING_PTR(str), enc);
- return str;
+ return rb_enc_uint_chr(i, enc);
}
/*
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 3d3b64c6cc..1cfde82715 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -418,6 +418,30 @@ EOT
}
end
+ def test_ungetc_int
+ with_tmpdir {
+ generate_file('tmp', "A")
+ s = open("tmp", "r:GB18030") {|f|
+ f.ungetc(0x8431A439)
+ f.read
+ }
+ assert_equal(Encoding::GB18030, s.encoding)
+ assert_str_equal(0x8431A439.chr("GB18030")+"A", s)
+ }
+ end
+
+ def test_ungetc_str
+ with_tmpdir {
+ generate_file('tmp', "A")
+ s = open("tmp", "r:GB18030") {|f|
+ f.ungetc(0x8431A439.chr("GB18030"))
+ f.read
+ }
+ assert_equal(Encoding::GB18030, s.encoding)
+ assert_str_equal(0x8431A439.chr("GB18030")+"A", s)
+ }
+ end
+
def test_ungetc_stateful_conversion
with_tmpdir {
src = "before \e$B\x23\x30\x23\x31\e(B after".force_encoding("iso-2022-jp")
diff --git a/version.h b/version.h
index 018c416fce..00be452c33 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.2"
-#define RUBY_PATCHLEVEL 68
+#define RUBY_PATCHLEVEL 69
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 1