Skip to content
Browse files

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
  • Loading branch information...
1 parent 8996556 commit 80aaa3ef6c87a4cbb13c92097ee5170a663d4175 @nobu nobu committed May 24, 2012
Showing with 20 additions and 7 deletions.
  1. +7 −0 ChangeLog
  2. +2 −2 error.c
  3. +7 −2 sprintf.c
  4. +4 −3 vsnprintf.c
View
7 ChangeLog
@@ -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
4 error.c
@@ -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
9 sprintf.c
@@ -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
7 vsnprintf.c
@@ -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;

0 comments on commit 80aaa3e

Please sign in to comment.
Something went wrong with that request. Please try again.