diff --git a/ChangeLog b/ChangeLog index c5af756c20..221a28828e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sat Jul 12 22:17:26 2008 Nobuyoshi Nakada + + * configure.in (sizeof ptrdiff_t): check for size of ptrdiff_t. + + * include/ruby/ruby.h (PRI?PTRDIFF, PRI?SIZE): printf conversion + specifiers for ptrdiff_t and size_t/ssize_t. + + * insns.def (leave), marshal.c (long_toobig), transcode.c + (str_transcode), vm_dump.c (control_frame_dump, stack_dump_each), + (debug_print_register, debug_print_pre): t and z length modifiers + are C99. + Sat Jul 12 16:02:31 2008 Nobuyoshi Nakada * lib/xmlrpc/client.rb (XMLRPC::Client#do_rpc): requires diff --git a/configure.in b/configure.in index 942a790963..5e3047d5c2 100644 --- a/configure.in +++ b/configure.in @@ -628,6 +628,7 @@ AC_CHECK_SIZEOF(rlim_t, 0, [ dnl Checks for typedefs, structures, and compiler characteristics. AC_TYPE_SIZE_T AC_CHECK_SIZEOF(size_t, 0) +AC_CHECK_SIZEOF(ptrdiff_t, $ac_cv_sizeof_size_t) AC_STRUCT_ST_BLKSIZE AC_STRUCT_ST_BLOCKS AC_STRUCT_ST_RDEV diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 89c7f602ed..67c22af9ad 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -87,28 +87,51 @@ typedef unsigned long VALUE; typedef unsigned long ID; # define SIGNED_VALUE long # define SIZEOF_VALUE SIZEOF_LONG -# define PRIdVALUE "ld" -# define PRIiVALUE "li" -# define PRIoVALUE "lo" -# define PRIuVALUE "lu" -# define PRIxVALUE "lx" -# define PRIXVALUE "lX" +# define PRI_VALUE_PREFIX "l" #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP typedef unsigned LONG_LONG VALUE; typedef unsigned LONG_LONG ID; # define SIGNED_VALUE LONG_LONG # define LONG_LONG_VALUE 1 # define SIZEOF_VALUE SIZEOF_LONG_LONG -# define PRIdVALUE "lld" -# define PRIiVALUE "lli" -# define PRIoVALUE "llo" -# define PRIuVALUE "llu" -# define PRIxVALUE "llx" -# define PRIXVALUE "llX" +# define PRI_VALUE_PREFIX "ll" #else # error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<---- #endif +#define PRIdVALUE PRI_VALUE_PREFIX"d" +#define PRIiVALUE PRI_VALUE_PREFIX"i" +#define PRIoVALUE PRI_VALUE_PREFIX"o" +#define PRIuVALUE PRI_VALUE_PREFIX"u" +#define PRIxVALUE PRI_VALUE_PREFIX"x" +#define PRIXVALUE PRI_VALUE_PREFIX"X" +#if SIZEOF_PTRDIFF_T == SIZEOF_INT +# define PRI_PTDIFF_PREFIX +#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG +# define PRI_PTDIFF_PREFIX "l" +#elif SIZEOF_PTRDIFF_T == SIZEOF_LONG +# define PRI_PTDIFF_PREFIX "ll" +#endif +#define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d" +#define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i" +#define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o" +#define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u" +#define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x" +#define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X" + +#if SIZEOF_SIZE_T == SIZEOF_INT +# define PRI_PTDIFF_PREFIX +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define PRI_PTDIFF_PREFIX "l" +#elif SIZEOF_SIZE_T == SIZEOF_LONG +# define PRI_PTDIFF_PREFIX "ll" +#endif +#define PRIdSIZE PRI_SIZE_PREFIX"d" +#define PRIiSIZE PRI_SIZE_PREFIX"i" +#define PRIoSIZE PRI_SIZE_PREFIX"o" +#define PRIuSIZE PRI_SIZE_PREFIX"u" +#define PRIxSIZE PRI_SIZE_PREFIX"x" +#define PRIXSIZE PRI_SIZE_PREFIX"X" #ifdef __STDC__ # include diff --git a/insns.def b/insns.def index 62490f248f..a695630ea6 100644 --- a/insns.def +++ b/insns.def @@ -1058,7 +1058,7 @@ leave { if (OPT_CHECKED_RUN) { if (reg_cfp->sp != reg_cfp->bp) { - rb_bug("Stack consistency error (sp: %td, bp: %td)", + rb_bug("Stack consistency error (sp: %"PRIdPTRDIFF", bp: %"PRIdPTRDIFF")", VM_SP_CNT(th, reg_cfp->sp), VM_SP_CNT(th, reg_cfp->bp)); } } diff --git a/marshal.c b/marshal.c index f2d01809ca..ec0041dd01 100644 --- a/marshal.c +++ b/marshal.c @@ -941,8 +941,8 @@ r_byte(struct load_arg *arg) static void long_toobig(int size) { - rb_raise(rb_eTypeError, "long too big for this architecture (size %zd, given %d)", - sizeof(long), size); + rb_raise(rb_eTypeError, "long too big for this architecture (size " + STRINGIZE(SIZEOF_LONG)", given %d)", size); } #undef SIGN_EXTEND_CHAR diff --git a/transcode.c b/transcode.c index 02c82c5c3b..d3e59a815b 100644 --- a/transcode.c +++ b/transcode.c @@ -326,7 +326,7 @@ str_transcode(int argc, VALUE *argv, VALUE *self) my_transcoding.ruby_string_dest = dest; (*my_transcoder->preprocessor)(&fromp, &bp, (sp+slen), (bp+blen), &my_transcoding); if (fromp != sp+slen) { - rb_raise(rb_eArgError, "not fully converted, %td bytes left", sp+slen-fromp); + rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); } buf = (unsigned char *)RSTRING_PTR(dest); *bp = '\0'; @@ -343,7 +343,7 @@ str_transcode(int argc, VALUE *argv, VALUE *self) transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), my_transcoder, &my_transcoding, options); if (fromp != sp+slen) { - rb_raise(rb_eArgError, "not fully converted, %td bytes left", sp+slen-fromp); + rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); } buf = (unsigned char *)RSTRING_PTR(dest); *bp = '\0'; @@ -358,7 +358,7 @@ str_transcode(int argc, VALUE *argv, VALUE *self) my_transcoding.ruby_string_dest = dest; (*my_transcoder->postprocessor)(&fromp, &bp, (sp+slen), (bp+blen), &my_transcoding); if (fromp != sp+slen) { - rb_raise(rb_eArgError, "not fully converted, %td bytes left", sp+slen-fromp); + rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp); } buf = (unsigned char *)RSTRING_PTR(dest); *bp = '\0'; diff --git a/vm_dump.c b/vm_dump.c index e1da979d04..c88396d36f 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -115,17 +115,17 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp) line = -1; } - fprintf(stderr, "c:%04td ", - (rb_control_frame_t *)(th->stack + th->stack_size) - cfp); + fprintf(stderr, "c:%04"PRIdPTRDIFF" ", + ((rb_control_frame_t *)(th->stack + th->stack_size) - cfp)); if (pc == -1) { fprintf(stderr, "p:---- "); } else { fprintf(stderr, "p:%04d ", pc); } - fprintf(stderr, "s:%04td b:%04d ", cfp->sp - th->stack, bp); - fprintf(stderr, lfp_in_heap == ' ' ? "l:%06td " : "l:%06tx ", lfp % 10000); - fprintf(stderr, dfp_in_heap == ' ' ? "d:%06td " : "d:%06tx ", dfp % 10000); + fprintf(stderr, "s:%04"PRIdPTRDIFF" b:%04d ", (cfp->sp - th->stack), bp); + fprintf(stderr, lfp_in_heap == ' ' ? "l:%06"PRIdPTRDIFF" " : "l:%06"PRIxPTRDIFF" ", lfp % 10000); + fprintf(stderr, dfp_in_heap == ' ' ? "d:%06"PRIdPTRDIFF" " : "d:%06"PRIxPTRDIFF" ", dfp % 10000); fprintf(stderr, "%-6s ", magic); if (line) { fprintf(stderr, "%s", posbuf); @@ -308,8 +308,8 @@ stack_dump_each(rb_thread_t *th, rb_control_frame_t *cfp) else { rstr = rb_inspect(*ptr); } - fprintf(stderr, " stack %2d: %8s (%td)\n", i, StringValueCStr(rstr), - ptr - th->stack); + fprintf(stderr, " stack %2d: %8s (%"PRIdPTRDIFF")\n", i, StringValueCStr(rstr), + (ptr - th->stack)); } } else if (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_FINISH) { @@ -345,8 +345,8 @@ debug_print_register(rb_thread_t *th) dfp = -1; cfpi = ((rb_control_frame_t *)(th->stack + th->stack_size)) - cfp; - fprintf(stderr, " [PC] %04d, [SP] %04td, [LFP] %04d, [DFP] %04d, [CFP] %04d\n", - pc, cfp->sp - th->stack, lfp, dfp, cfpi); + fprintf(stderr, " [PC] %04d, [SP] %04"PRIdPTRDIFF", [LFP] %04d, [DFP] %04d, [CFP] %04d\n", + pc, (cfp->sp - th->stack), lfp, dfp, cfpi); } void @@ -366,7 +366,7 @@ debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp) VALUE *seq = iseq->iseq; int pc = cfp->pc - iseq->iseq_encoded; - printf("%3td ", VM_CFP_CNT(th, cfp)); + printf("%3"PRIdPTRDIFF" ", VM_CFP_CNT(th, cfp)); ruby_iseq_disasm_insn(0, seq, pc, iseq, 0); }