diff --git a/ChangeLog b/ChangeLog index a5b1620d7b..4f9b309137 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Nov 4 12:51:31 2014 Nobuyoshi Nakada + + * 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 * object.c: fix document of Kernel#String by @suzukaze diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 2b175fd89e..18183f787c 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 85adc216f3..d370b8d8de 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 f8b5a8970b..36f6f25465 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);