use inttypes.h and PTIdPTR

This commit is contained in:
Matthew Flatt 2010-12-12 08:23:50 -07:00
parent 953dd78d76
commit f9fb041598
6 changed files with 27 additions and 23 deletions

View File

@ -29,7 +29,7 @@
#undef HAVE_UINTPTR_T
#ifdef HAVE_INTPTR_T
# include <stdint.h>
# include <inttypes.h>
#endif
#ifndef HAVE_INTPTR_T
typedef long intptr_t;

View File

@ -308,7 +308,7 @@ Scheme_Env *scheme_engine_instance_init() {
os_platform_init();
#ifdef TIME_STARTUP_PROCESS
printf("#if 0\nengine_instance_init @ %" PRINTF_INTPTR_SIZE_PREFIX "d\n", scheme_get_process_milliseconds());
printf("#if 0\nengine_instance_init @ %" PRIdPTR "\n", scheme_get_process_milliseconds());
#endif
scheme_starting_up = 1;
@ -464,7 +464,7 @@ static Scheme_Env *place_instance_init(void *stack_base, int initial_main_os_thr
Scheme_Env *env;
#ifdef TIME_STARTUP_PROCESS
printf("place_init @ %" PRINTF_INTPTR_SIZE_PREFIX "d\n", scheme_get_process_milliseconds());
printf("place_init @ %" PRIdPTR "\n", scheme_get_process_milliseconds());
#endif
scheme_set_current_os_thread_stack_base(stack_base);
@ -480,7 +480,7 @@ static Scheme_Env *place_instance_init(void *stack_base, int initial_main_os_thr
init_toplevel_local_offsets_hashtable_caches();
#ifdef TIME_STARTUP_PROCESS
printf("pre-process @ %" PRINTF_INTPTR_SIZE_PREFIX "d\n", scheme_get_process_milliseconds());
printf("pre-process @ %" PRIdPTR "\n", scheme_get_process_milliseconds());
#endif
scheme_make_thread(stack_base);
@ -499,7 +499,7 @@ static Scheme_Env *place_instance_init(void *stack_base, int initial_main_os_thr
scheme_init_module_resolver();
#ifdef TIME_STARTUP_PROCESS
printf("process @ %" PRINTF_INTPTR_SIZE_PREFIX "d\n", scheme_get_process_milliseconds());
printf("process @ %" PRIdPTR "\n", scheme_get_process_milliseconds());
#endif
/* error handling and buffers */
@ -564,7 +564,7 @@ static Scheme_Env *place_instance_init(void *stack_base, int initial_main_os_thr
--scheme_current_thread->suspend_break; /* created with breaks suspended */
#ifdef TIME_STARTUP_PROCESS
printf("done @ %" PRINTF_INTPTR_SIZE_PREFIX "d\n#endif\n", scheme_get_process_milliseconds());
printf("done @ %" PRIdPTR "\n#endif\n", scheme_get_process_milliseconds());
#endif
return env;
@ -611,10 +611,10 @@ static void make_kernel_env(void)
builtin_ref_counter = 0;
#ifdef TIME_STARTUP_PROCESS
printf("init @ %" PRINTF_INTPTR_SIZE_PREFIX "d\n", scheme_get_process_milliseconds());
printf("init @ %" PRIdPTR "\n", scheme_get_process_milliseconds());
# define MZTIMEIT(n, f) (MARK_START_TIME(), f, DONE_TIME(n))
# define MARK_START_TIME() startt = scheme_get_process_milliseconds()
# define DONE_TIME(n) (printf(#n ": %" PRINTF_INTPTR_SIZE_PREFIX "d\n", (intptr_t)(scheme_get_process_milliseconds() - startt)))
# define DONE_TIME(n) (printf(#n ": %" PRIdPTR "\n", (intptr_t)(scheme_get_process_milliseconds() - startt)))
#else
# define MZTIMEIT(n, f) f
# define MARK_START_TIME() /**/

View File

@ -349,9 +349,9 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list
j++;
d = ints[ip++];
if (as_hex)
sprintf(buf, "%" PRINTF_INTPTR_SIZE_PREFIX "x", d);
sprintf(buf, "%" PRIxPTR, d);
else
sprintf(buf, "%" PRINTF_INTPTR_SIZE_PREFIX "d", d);
sprintf(buf, "%" PRIdPTR, d);
t = buf;
tlen = strlen(t);
}
@ -370,7 +370,7 @@ static intptr_t sch_vsprintf(char *s, intptr_t maxlen, const char *msg, va_list
intptr_t d;
d = ints[ip++];
if (d >= 0) {
sprintf(buf, "%" PRINTF_INTPTR_SIZE_PREFIX "d:", d);
sprintf(buf, "%" PRIdPTR ":", d);
t = buf;
tlen = strlen(t);
} else {
@ -1944,7 +1944,7 @@ void scheme_unbound_global(Scheme_Bucket *b)
errmsg = "reference to an identifier before its definition: %S%_%s";
if (((Scheme_Bucket_With_Home *)b)->home->phase) {
sprintf(phase_buf, " phase: %" PRINTF_INTPTR_SIZE_PREFIX "d", ((Scheme_Bucket_With_Home *)b)->home->phase);
sprintf(phase_buf, " phase: %" PRIdPTR "", ((Scheme_Bucket_With_Home *)b)->home->phase);
phase = phase_buf;
} else
phase = "";

View File

@ -1881,10 +1881,10 @@ Scheme_Object *scheme_source_to_name(Scheme_Object *code)
}
if (cstx->srcloc->line >= 0) {
sprintf(buf, "%s%s%" PRINTF_INTPTR_SIZE_PREFIX "d:%" PRINTF_INTPTR_SIZE_PREFIX "d",
sprintf(buf, "%s%s%" PRIdPTR ":%" PRIdPTR,
src, (src[0] ? ":" : ""), cstx->srcloc->line, cstx->srcloc->col - 1);
} else {
sprintf(buf, "%s%s%" PRINTF_INTPTR_SIZE_PREFIX "d",
sprintf(buf, "%s%s%" PRIdPTR,
src, (src[0] ? "::" : ""), cstx->srcloc->pos);
}

View File

@ -1698,7 +1698,7 @@ static void cannot_print(PrintParams *pp, int notdisplay,
static void printaddress(PrintParams *pp, Scheme_Object *o)
{
char buf[40];
sprintf(buf, ":%" PRINTF_INTPTR_SIZE_PREFIX "x", (intptr_t)o);
sprintf(buf, ":%" PRIxPTR, (intptr_t)o);
print_this_string(pp, buf, 0, -1);
}
# define PRINTADDRESS(pp, obj) printaddress(pp, obj)
@ -1838,12 +1838,12 @@ print(Scheme_Object *obj, int notdisplay, int compact, Scheme_Hash_Table *ht,
} else {
if (val > 0) {
always_scheme(pp, 1);
sprintf(quick_buffer, "#%" PRINTF_INTPTR_SIZE_PREFIX "d=", (val - 3) >> 1);
sprintf(quick_buffer, "#%" PRIdPTR "=", (val - 3) >> 1);
print_utf8_string(pp, quick_buffer, 0, -1);
scheme_hash_set(ht, obj, (Scheme_Object *)(-val));
} else {
always_scheme(pp, 0);
sprintf(quick_buffer, "#%" PRINTF_INTPTR_SIZE_PREFIX "d#", ((-val) - 3) >> 1);
sprintf(quick_buffer, "#%" PRIdPTR "#", ((-val) - 3) >> 1);
print_utf8_string(pp, quick_buffer, 0, -1);
return 0;
}
@ -2041,7 +2041,7 @@ print(Scheme_Object *obj, int notdisplay, int compact, Scheme_Hash_Table *ht,
}
}
} else {
sprintf(quick_buffer, "%" PRINTF_INTPTR_SIZE_PREFIX "d", SCHEME_INT_VAL(obj));
sprintf(quick_buffer, "%" PRIdPTR "", SCHEME_INT_VAL(obj));
print_utf8_string(pp, quick_buffer, 0, -1);
}
}
@ -2574,7 +2574,7 @@ print(Scheme_Object *obj, int notdisplay, int compact, Scheme_Hash_Table *ht,
print_utf8_string(pp, ":", 0, 1);
}
sprintf(s, "%" PRINTF_INTPTR_SIZE_PREFIX "d", ((Scheme_Env *)obj)->phase);
sprintf(s, "%" PRIdPTR "", ((Scheme_Env *)obj)->phase);
print_utf8_string(pp, s, 0, -1);
print_utf8_string(pp, ">", 0, 1);
}
@ -2703,10 +2703,10 @@ print(Scheme_Object *obj, int notdisplay, int compact, Scheme_Hash_Table *ht,
}
if (stx->srcloc->line >= 0)
sprintf(quick_buffer,
"%" PRINTF_INTPTR_SIZE_PREFIX "d:%" PRINTF_INTPTR_SIZE_PREFIX "d",
"%" PRIdPTR ":%" PRIdPTR "",
stx->srcloc->line, stx->srcloc->col-1);
else
sprintf(quick_buffer, ":%" PRINTF_INTPTR_SIZE_PREFIX "d",
sprintf(quick_buffer, ":%" PRIdPTR "",
stx->srcloc->pos);
print_utf8_string(pp, quick_buffer, 0, -1);
} else
@ -3016,7 +3016,7 @@ print(Scheme_Object *obj, int notdisplay, int compact, Scheme_Hash_Table *ht,
#if NO_COMPACT
if (t < _scheme_last_type_) {
sprintf (quick_buffer,
"%" PRINTF_INTPTR_SIZE_PREFIX "d",
"%" PRIdPTR,
(intptr_t)SCHEME_TYPE(obj));
print_this_string(pp, quick_buffer, 0, -1);
} else

View File

@ -2023,8 +2023,12 @@ Scheme_Object *scheme_load_delayed_code(int pos, struct Scheme_Load_Delay *ld);
intptr_t scheme_get_print_width(void);
#ifndef PRINTF_INTPTR_SIZE_PREFIX
#ifndef PTIdPTR
# ifndef PRINTF_INTPTR_SIZE_PREFIX
# define PRINTF_INTPTR_SIZE_PREFIX "l"
# endif
# define PTIdPTR PRINTF_INTPTR_SIZE_PREFIX "d"
# define PTIxPTR PRINTF_INTPTR_SIZE_PREFIX "x"
#endif
/*========================================================================*/