mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* backport r33021 from trunk.
* sprintf.c (rb_str_format): add RB_GC_GUARD to prevent temporary strings from GC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@33029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
df0cb1c4d1
commit
bdd342d85a
2 changed files with 13 additions and 2 deletions
|
@ -14,6 +14,13 @@ Tue Aug 23 15:11:48 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* test/zlib/test_zlib.rb (test_corrupted_header): Test it.
|
* test/zlib/test_zlib.rb (test_corrupted_header): Test it.
|
||||||
|
|
||||||
|
Mon Aug 22 23:43:33 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
|
||||||
|
|
||||||
|
* backport r33021 from trunk.
|
||||||
|
|
||||||
|
* sprintf.c (rb_str_format): add RB_GC_GUARD to prevent temporary
|
||||||
|
strings from GC.
|
||||||
|
|
||||||
Sun Aug 21 17:58:38 2011 Kazuki Tsujimoto <kazuki@callcc.net>
|
Sun Aug 21 17:58:38 2011 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||||
|
|
||||||
* backport r33019 from trunk.
|
* backport r33019 from trunk.
|
||||||
|
|
|
@ -641,6 +641,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
rb_raise(rb_eArgError, "%%c requires a character");
|
rb_raise(rb_eArgError, "%%c requires a character");
|
||||||
}
|
}
|
||||||
c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
|
c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
|
||||||
|
RB_GC_GUARD(tmp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c = NUM2INT(val);
|
c = NUM2INT(val);
|
||||||
|
@ -711,6 +712,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
}
|
}
|
||||||
CHECK(len);
|
CHECK(len);
|
||||||
memcpy(&buf[blen], RSTRING_PTR(str), len);
|
memcpy(&buf[blen], RSTRING_PTR(str), len);
|
||||||
|
RB_GC_GUARD(str);
|
||||||
blen += len;
|
blen += len;
|
||||||
if (flags&FMINUS) {
|
if (flags&FMINUS) {
|
||||||
CHECK(width);
|
CHECK(width);
|
||||||
|
@ -723,6 +725,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PUSH(RSTRING_PTR(str), len);
|
PUSH(RSTRING_PTR(str), len);
|
||||||
|
RB_GC_GUARD(str);
|
||||||
rb_enc_associate(result, enc);
|
rb_enc_associate(result, enc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -736,7 +739,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
case 'B':
|
case 'B':
|
||||||
case 'u':
|
case 'u':
|
||||||
{
|
{
|
||||||
volatile VALUE tmp1;
|
|
||||||
volatile VALUE val = GETARG();
|
volatile VALUE val = GETARG();
|
||||||
char fbuf[32], nbuf[64], *s;
|
char fbuf[32], nbuf[64], *s;
|
||||||
const char *prefix = 0;
|
const char *prefix = 0;
|
||||||
|
@ -887,7 +889,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
val = rb_big_clone(val);
|
val = rb_big_clone(val);
|
||||||
rb_big_2comp(val);
|
rb_big_2comp(val);
|
||||||
}
|
}
|
||||||
tmp1 = tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val));
|
tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val));
|
||||||
s = RSTRING_PTR(tmp);
|
s = RSTRING_PTR(tmp);
|
||||||
if (*s == '-') {
|
if (*s == '-') {
|
||||||
dots = 1;
|
dots = 1;
|
||||||
|
@ -981,6 +983,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PUSH(s, len);
|
PUSH(s, len);
|
||||||
|
RB_GC_GUARD(tmp);
|
||||||
CHECK(width);
|
CHECK(width);
|
||||||
while (width-- > 0) {
|
while (width-- > 0) {
|
||||||
buf[blen++] = ' ';
|
buf[blen++] = ' ';
|
||||||
|
@ -1065,6 +1068,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
sprint_exit:
|
sprint_exit:
|
||||||
|
RB_GC_GUARD(fmt);
|
||||||
/* XXX - We cannot validate the number of arguments if (digit)$ style used.
|
/* XXX - We cannot validate the number of arguments if (digit)$ style used.
|
||||||
*/
|
*/
|
||||||
if (posarg >= 0 && nextarg < argc) {
|
if (posarg >= 0 && nextarg < argc) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue