1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

sprintf.c: inspect by plus

* sprintf.c (ruby__sfvextra): [EXPERIMENTAL] use inspect instead of
  to_s if plus flag is given.
* vsnprintf.c (BSD_vfprintf): pass sign flag.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-05-24 16:15:42 +00:00
parent 8996556b05
commit 80aaa3ef6c
4 changed files with 20 additions and 7 deletions

View file

@ -1,3 +1,10 @@
Fri May 25 01:15:39 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (ruby__sfvextra): [EXPERIMENTAL] use inspect instead of
to_s if plus flag is given.
* vsnprintf.c (BSD_vfprintf): pass sign flag.
Fri May 25 00:37:22 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/rubygems/test_gem_indexer.rb (setup, teardown): save @tempdir

View file

@ -1116,9 +1116,9 @@ nometh_err_args(VALUE self)
void
rb_invalid_str(const char *str, const char *type)
{
VALUE s = rb_str_inspect(rb_str_new2(str));
VALUE s = rb_str_new2(str);
rb_raise(rb_eArgError, "invalid value for %s: %"PRIsVALUE, type, s);
rb_raise(rb_eArgError, "invalid value for %s: %+"PRIsVALUE, type, s);
}
/*

View file

@ -1178,7 +1178,7 @@ ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio)
}
static char *
ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz)
ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int sign)
{
VALUE value, result = (VALUE)fp->_bf._base;
rb_encoding *enc;
@ -1189,7 +1189,12 @@ ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz)
if (RBASIC(result)->klass) {
rb_raise(rb_eRuntimeError, "rb_vsprintf reentered");
}
value = rb_obj_as_string(value);
if (sign == '+') {
value = rb_inspect(value);
}
else {
value = rb_obj_as_string(value);
}
enc = rb_enc_compatible(result, value);
if (enc) {
rb_enc_associate(result, enc);

View file

@ -183,7 +183,7 @@ typedef struct __sFILE {
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
size_t _lbfsize; /* 0 or -_bf._size, for inline putc */
int (*vwrite)(/* struct __sFILE*, struct __suio * */);
char *(*vextra)(/* struct __sFILE*, size_t, void*, long* */);
char *(*vextra)(/* struct __sFILE*, size_t, void*, long*, int */);
} FILE;
@ -811,11 +811,12 @@ reswitch: switch (ch) {
FLUSH();
#if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG
uqval = va_arg(ap, u_quad_t);
cp = (*fp->vextra)(fp, sizeof(uqval), &uqval, &fieldsz);
cp = (*fp->vextra)(fp, sizeof(uqval), &uqval, &fieldsz, sign);
#else
ulval = va_arg(ap, u_long);
cp = (*fp->vextra)(fp, sizeof(ulval), &ulval, &fieldsz);
cp = (*fp->vextra)(fp, sizeof(ulval), &ulval, &fieldsz, sign);
#endif
sign = '\0';
if (!cp) goto error;
if (prec < 0) goto long_len;
size = fieldsz < prec ? (int)fieldsz : prec;