use PRId64/32 where available for printing fixnums (issue #479)

This commit is contained in:
Alex Shinn 2018-06-29 22:44:16 +08:00
parent f5a228ee9e
commit 0efa071672
3 changed files with 15 additions and 4 deletions

View file

@ -635,7 +635,7 @@ sexp sexp_load_image (const char* filename, off_t offset, sexp_uint_t heap_free_
goto done;
}
if (offset > 0 && fseek(fp, offset, SEEK_SET) < 0) {
snprintf(gc_heap_err_str, ERR_STR_SIZE, "couldn't seek to image offset: %s -> "PRIoff": %s\n", filename, offset, strerror(errno));
snprintf(gc_heap_err_str, ERR_STR_SIZE, "couldn't seek to image offset: %s -> %"SEXP_PRIdOFF": %s\n", filename, offset, strerror(errno));
goto done;
}

View file

@ -283,9 +283,20 @@ typedef short sexp_int32_t;
#endif
#if defined(__APPLE__) || defined(_WIN64) || (defined(__CYGWIN__) && __SIZEOF_POINTER__ == 8)
#define PRIoff "%lld"
#define SEXP_PRIdOFF "lld"
#else
#define PRIoff "%ld"
#define SEXP_PRIdOFF "ld"
#endif
#if defined(__GNUC__) || defined(_WIN64) || defined(__APPLE__)
#include <stdint.h>
#if SEXP_64_BIT
#define SEXP_PRIdFIXNUM PRId64
#else
#define SEXP_PRIdFIXNUM PRId32
#endif
#else
#define SEXP_PRIdFIXNUM "ld"
#endif
#if SEXP_USE_LONG_PROCEDURE_ARGS

2
sexp.c
View file

@ -2111,7 +2111,7 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
break;
}
} else if (sexp_fixnump(obj)) {
snprintf(numbuf, NUMBUF_LEN, "%ld", (long)sexp_unbox_fixnum(obj));
snprintf(numbuf, NUMBUF_LEN, "%" SEXP_PRIdFIXNUM, (long)sexp_unbox_fixnum(obj));
sexp_write_string(ctx, numbuf, out);
#if SEXP_USE_IMMEDIATE_FLONUMS
} else if (sexp_flonump(obj)) {