summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-04 03:51:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-04 03:51:33 +0000
commita9f3eb75de7c4041b273cc782585e1b7b20a6fa4 (patch)
treebc3e0feff04abf0f51714a7300755890986e5e78
parent95e83cb3f940cc1a8ab7681ad01f67aba77554a0 (diff)
ruby.h: add mark to PRIsVALUE
* include/ruby/ruby.h (PRIsVALUE), vsnprintf.c (BSD_vfprintf): add RUBY_PRI_VALUE_MARK to reduce danger of accidental conflict with plain "%i". binary incompatible with extension libraries using PRIsVALUE and built for 2.1 and earlier. [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--include/ruby/ruby.h5
-rw-r--r--sprintf.c3
-rw-r--r--vsnprintf.c16
4 files changed, 28 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index a5b1620..4f9b309 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Nov 4 12:51:31 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/ruby.h (PRIsVALUE), vsnprintf.c (BSD_vfprintf): add
+ RUBY_PRI_VALUE_MARK to reduce danger of accidental conflict with
+ plain "%i". binary incompatible with extension libraries using
+ PRIsVALUE and built for 2.1 and earlier. [EXPERIMENTAL]
+
Tue Nov 4 12:33:44 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* object.c: fix document of Kernel#String by @suzukaze
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 2b175fd..18183f7 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -123,20 +123,21 @@ typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1];
#define PRI_64_PREFIX PRI_LL_PREFIX
#endif
+#define RUBY_PRI_VALUE_MARK "\v"
#if defined PRIdPTR && !defined PRI_VALUE_PREFIX
#define PRIdVALUE PRIdPTR
#define PRIoVALUE PRIoPTR
#define PRIuVALUE PRIuPTR
#define PRIxVALUE PRIxPTR
#define PRIXVALUE PRIXPTR
-#define PRIsVALUE PRIiPTR
+#define PRIsVALUE PRIiPTR""RUBY_PRI_VALUE_MARK
#else
#define PRIdVALUE PRI_VALUE_PREFIX"d"
#define PRIoVALUE PRI_VALUE_PREFIX"o"
#define PRIuVALUE PRI_VALUE_PREFIX"u"
#define PRIxVALUE PRI_VALUE_PREFIX"x"
#define PRIXVALUE PRI_VALUE_PREFIX"X"
-#define PRIsVALUE PRI_VALUE_PREFIX"i"
+#define PRIsVALUE PRI_VALUE_PREFIX"i"RUBY_PRI_VALUE_MARK
#endif
#ifndef PRI_VALUE_PREFIX
# define PRI_VALUE_PREFIX ""
diff --git a/sprintf.c b/sprintf.c
index 85adc21..d370b8d 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1253,6 +1253,9 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
#define FLOATING_POINT 1
#define BSD__dtoa ruby_dtoa
#define BSD__hdtoa ruby_hdtoa
+#ifdef RUBY_PRI_VALUE_MARK
+# define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK
+#endif
#include "vsnprintf.c"
typedef struct {
diff --git a/vsnprintf.c b/vsnprintf.c
index f8b5a89..36f6f25 100644
--- a/vsnprintf.c
+++ b/vsnprintf.c
@@ -806,7 +806,21 @@ reswitch: switch (ch) {
#else
# define INTPTR_FLAG 0
#endif
- if (fp->vextra && (flags & INTPTR_MASK) == INTPTR_FLAG) {
+#ifdef PRI_EXTRA_MARK
+# define PRI_EXTRA_MARK_LEN (sizeof(PRI_EXTRA_MARK)-1)
+# define IS_PRI_EXTRA_MARK(s) \
+ (PRI_EXTRA_MARK_LEN < 1 || \
+ (*(s) == PRI_EXTRA_MARK[0] && \
+ (PRI_EXTRA_MARK_LEN == 1 || \
+ strncmp((s)+1, PRI_EXTRA_MARK+1, \
+ PRI_EXTRA_MARK_LEN-1) == 0)))
+#else
+# define PRI_EXTRA_MARK_LEN 0
+# define IS_PRI_EXTRA_MARK(s) 1
+#endif
+ if (fp->vextra && (flags & INTPTR_MASK) == INTPTR_FLAG &&
+ IS_PRI_EXTRA_MARK(fmt)) {
+ fmt += PRI_EXTRA_MARK_LEN;
FLUSH();
#if defined _HAVE_SANE_QUAD_ && SIZEOF_VOIDP == SIZEOF_LONG_LONG
uqval = va_arg(ap, u_quad_t);