Skip to content

Commit 462ac33

Browse files
committed
Merge pull request #11701 from JuliaLang/yyc/hex-address
Fix string formatting
2 parents d94bb62 + 2ac0be7 commit 462ac33

File tree

8 files changed

+52
-33
lines changed

8 files changed

+52
-33
lines changed

src/builtins.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sys/types.h>
1515
#include <errno.h>
1616
#include <fcntl.h>
17+
#include <inttypes.h>
1718
#if defined(_OS_WINDOWS_)
1819
#include <malloc.h>
1920
#else
@@ -1335,34 +1336,35 @@ size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, int depth)
13351336
n += jl_printf(out, "#<intrinsic function %d>", *(uint32_t*)jl_data_ptr(v));
13361337
}
13371338
else if (jl_is_int64(v)) {
1338-
n += jl_printf(out, "%lld", jl_unbox_int64(v));
1339+
n += jl_printf(out, "%" PRId64, jl_unbox_int64(v));
13391340
}
13401341
else if (jl_is_int32(v)) {
1341-
n += jl_printf(out, "%d", jl_unbox_int32(v));
1342+
n += jl_printf(out, "%" PRId32, jl_unbox_int32(v));
13421343
}
13431344
else if (jl_typeis(v,jl_int16_type)) {
1344-
n += jl_printf(out, "%hd", jl_unbox_int16(v));
1345+
n += jl_printf(out, "%" PRId16, jl_unbox_int16(v));
13451346
}
13461347
else if (jl_typeis(v,jl_int8_type)) {
1347-
n += jl_printf(out, "%hhd", jl_unbox_int8(v));
1348+
n += jl_printf(out, "%" PRId8, jl_unbox_int8(v));
13481349
}
13491350
else if (jl_is_uint64(v)) {
1350-
n += jl_printf(out, "0x%016llx", jl_unbox_uint64(v));
1351+
n += jl_printf(out, "0x%016" PRIx64, jl_unbox_uint64(v));
13511352
}
13521353
else if (jl_is_uint32(v)) {
1353-
n += jl_printf(out, "0x%08x", jl_unbox_uint32(v));
1354+
n += jl_printf(out, "0x%08" PRIx32, jl_unbox_uint32(v));
13541355
}
13551356
else if (jl_typeis(v,jl_uint16_type)) {
1356-
n += jl_printf(out, "0x%04hx", jl_unbox_uint16(v));
1357+
n += jl_printf(out, "0x%04" PRIx16, jl_unbox_uint16(v));
13571358
}
13581359
else if (jl_typeis(v,jl_uint8_type)) {
1359-
n += jl_printf(out, "0x%02hhx", jl_unbox_uint8(v));
1360+
n += jl_printf(out, "0x%02" PRIx8, jl_unbox_uint8(v));
13601361
}
13611362
else if (jl_is_cpointer(v)) {
13621363
#ifdef _P64
1363-
n += jl_printf(out, "0x%016llx", jl_unbox_voidpointer(v));
1364+
n += jl_printf(out, "0x%016" PRIx64,
1365+
(int64_t)jl_unbox_voidpointer(v));
13641366
#else
1365-
n += jl_printf(out, "0x%08x", jl_unbox_voidpointer(v));
1367+
n += jl_printf(out, "0x%08" PRIx32, (int32_t)jl_unbox_voidpointer(v));
13661368
#endif
13671369
}
13681370
else if (jl_is_float32(v)) {
@@ -1409,7 +1411,8 @@ size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, int depth)
14091411
n += jl_printf(out, ":%s", ((jl_sym_t*)v)->name);
14101412
}
14111413
else if (jl_is_gensym(v)) {
1412-
n += jl_printf(out, "GenSym(%d)", ((jl_gensym_t*)v)->id);
1414+
n += jl_printf(out, "GenSym(%" PRIuPTR ")",
1415+
(uintptr_t)((jl_gensym_t*)v)->id);
14131416
}
14141417
else if (jl_is_symbolnode(v)) {
14151418
n += jl_printf(out, "%s::", jl_symbolnode_sym(v)->name);
@@ -1420,10 +1423,10 @@ size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, int depth)
14201423
n += jl_printf(out, ".%s", jl_globalref_name(v)->name);
14211424
}
14221425
else if (jl_is_labelnode(v)) {
1423-
n += jl_printf(out, "%d:", jl_labelnode_label(v));
1426+
n += jl_printf(out, "%" PRIuPTR ":", jl_labelnode_label(v));
14241427
}
14251428
else if (jl_is_gotonode(v)) {
1426-
n += jl_printf(out, "goto %d", jl_gotonode_label(v));
1429+
n += jl_printf(out, "goto %" PRIuPTR, jl_gotonode_label(v));
14271430
}
14281431
else if (jl_is_quotenode(v)) {
14291432
jl_value_t *qv = jl_fieldref(v,0);
@@ -1442,7 +1445,7 @@ size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, int depth)
14421445
n += jl_printf(out, ")");
14431446
}
14441447
else if (jl_is_linenode(v)) {
1445-
n += jl_printf(out, "# line %d", jl_linenode_line(v));
1448+
n += jl_printf(out, "# line %" PRIuPTR, jl_linenode_line(v));
14461449
}
14471450
else if (jl_is_expr(v)) {
14481451
jl_expr_t *e = (jl_expr_t*)v;
@@ -1508,14 +1511,14 @@ size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, int depth)
15081511
char *data = (char*)jl_data_ptr(v);
15091512
n += jl_printf(out, "0x");
15101513
for(int i=nb-1; i >= 0; --i)
1511-
n += jl_printf(out, "%02hhx", data[i]);
1514+
n += jl_printf(out, "%02" PRIx8, data[i]);
15121515
}
15131516
else {
15141517
jl_value_t *fldval=NULL;
15151518
JL_GC_PUSH1(&fldval);
15161519
for (size_t i = 0; i < tlen; i++) {
15171520
if (!istuple) {
1518-
n += jl_printf(out, ((jl_sym_t*)jl_svecref(t->name->names, i))->name);
1521+
n += jl_printf(out, "%s", ((jl_sym_t*)jl_svecref(t->name->names, i))->name);
15191522
//jl_fielddesc_t f = t->fields[i];
15201523
n += jl_printf(out, "=");
15211524
}

src/codegen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5812,7 +5812,8 @@ extern "C" void jl_init_codegen(void)
58125812
jl_ExecutionEngine = eb.create(jl_TargetMachine);
58135813
//jl_printf(JL_STDERR,"%s\n",jl_ExecutionEngine->getDataLayout()->getStringRepresentation().c_str());
58145814
if (!jl_ExecutionEngine) {
5815-
jl_printf(JL_STDERR, "Critical error initializing llvm: ", ErrorStr.c_str());
5815+
jl_printf(JL_STDERR, "Critical error initializing llvm: %s\n",
5816+
ErrorStr.c_str());
58165817
exit(1);
58175818
}
58185819
#ifdef LLVM35

src/debuginfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
130130
#endif
131131
static int warned = 0;
132132
if (!warned) {
133-
jl_printf(JL_STDERR, "WARNING: failed to insert module info for backtrace: %d\n", GetLastError());
133+
jl_printf(JL_STDERR, "WARNING: failed to insert module info for backtrace: %lu\n", GetLastError());
134134
warned = 1;
135135
}
136136
}
@@ -143,7 +143,7 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
143143
name[len-1] = 0;
144144
if (!SymAddSymbol(GetCurrentProcess(), (ULONG64)Section, name,
145145
(DWORD64)Code, (DWORD)Size, 0)) {
146-
jl_printf(JL_STDERR, "WARNING: failed to insert function name %s into debug info: %d\n", name, GetLastError());
146+
jl_printf(JL_STDERR, "WARNING: failed to insert function name %s into debug info: %lu\n", name, GetLastError());
147147
}
148148
}
149149
jl_in_stackwalk = 0;
@@ -152,7 +152,7 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam
152152
if (!RtlAddFunctionTable(tbl, 1, (DWORD64)Section)) {
153153
static int warned = 0;
154154
if (!warned) {
155-
jl_printf(JL_STDERR, "WARNING: failed to insert function stack unwind info: %d\n", GetLastError());
155+
jl_printf(JL_STDERR, "WARNING: failed to insert function stack unwind info: %lu\n", GetLastError());
156156
warned = 1;
157157
}
158158
}

src/disasm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, size_t slide,
324324
OwningPtr<MCDisassembler> DisAsm(TheTarget->createMCDisassembler(*STI));
325325
#endif
326326
if (!DisAsm) {
327-
jl_printf(JL_STDERR, "error: no disassembler for target", TripleName.c_str(), "\n");
327+
jl_printf(JL_STDERR, "error: no disassembler for target %s\n",
328+
TripleName.c_str());
328329
return;
329330
}
330331

src/gc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <strings.h>
1919
#endif
2020
#include <assert.h>
21+
#include <inttypes.h>
2122
#include "julia.h"
2223
#include "julia_internal.h"
2324
#ifndef _OS_WINDOWS_
@@ -496,8 +497,8 @@ static void add_lostval_parent(jl_value_t* parent)
496497
#define verify_val(v) do { \
497498
if (lostval == (jl_value_t*)(v) && (v) != 0) { \
498499
jl_printf(JL_STDOUT, \
499-
"Found lostval 0x%lx at %s:%d oftype: ", \
500-
(uintptr_t)(lostval), __FILE__, __LINE__); \
500+
"Found lostval %p at %s:%d oftype: ", \
501+
(void*)(lostval), __FILE__, __LINE__); \
501502
jl_static_show(JL_STDOUT, jl_typeof(v)); \
502503
jl_printf(JL_STDOUT, "\n"); \
503504
} \
@@ -506,9 +507,9 @@ static void add_lostval_parent(jl_value_t* parent)
506507

507508
#define verify_parent(ty, obj, slot, args...) do { \
508509
if (*(jl_value_t**)(slot) == lostval && (obj) != lostval) { \
509-
jl_printf(JL_STDOUT, "Found parent %s 0x%lx at %s:%d\n", \
510-
ty, (uintptr_t)(obj), __FILE__, __LINE__); \
511-
jl_printf(JL_STDOUT, "\tloc 0x%lx : ", (uintptr_t)(slot)); \
510+
jl_printf(JL_STDOUT, "Found parent %s %p at %s:%d\n", \
511+
(void*)(ty), (void*)(obj), __FILE__, __LINE__); \
512+
jl_printf(JL_STDOUT, "\tloc %p : ", (void*)(slot)); \
512513
jl_printf(JL_STDOUT, args); \
513514
jl_printf(JL_STDOUT, "\n"); \
514515
jl_printf(JL_STDOUT, "\ttype: "); \
@@ -1432,7 +1433,8 @@ static void grow_mark_stack(void)
14321433
size_t offset = mark_stack - mark_stack_base;
14331434
mark_stack_base = (jl_value_t**)realloc(mark_stack_base, newsz*sizeof(void*));
14341435
if (mark_stack_base == NULL) {
1435-
jl_printf(JL_STDERR, "Could'nt grow mark stack to : %d\n", newsz);
1436+
jl_printf(JL_STDERR, "Couldn't grow mark stack to : %" PRIuPTR "\n",
1437+
(uintptr_t)newsz);
14361438
exit(1);
14371439
}
14381440
mark_stack = mark_stack_base + offset;

src/gf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ void print_func_loc(JL_STREAM *s, jl_lambda_info_t *li)
17641764
long lno = li->line;
17651765
if (lno > 0) {
17661766
char *fname = ((jl_sym_t*)li->file)->name;
1767-
jl_printf(s, " at %s:%d", fname, lno);
1767+
jl_printf(s, " at %s:%ld", fname, lno);
17681768
}
17691769
}
17701770

src/julia.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,19 @@ typedef struct {
14901490
uv_file file;
14911491
} jl_uv_file_t;
14921492

1493-
DLLEXPORT int jl_printf(uv_stream_t *s, const char *format, ...);
1494-
DLLEXPORT int jl_vprintf(uv_stream_t *s, const char *format, va_list args);
1495-
DLLEXPORT void jl_safe_printf(const char *str, ...);
1493+
#ifdef __GNUC__
1494+
#define _JL_FORMAT_ATTR(type, str, arg) \
1495+
__attribute__((format(type, str, arg)))
1496+
#else
1497+
#define _JL_FORMAT_ATTR(type, str, arg)
1498+
#endif
1499+
1500+
DLLEXPORT int jl_printf(uv_stream_t *s, const char *format, ...)
1501+
_JL_FORMAT_ATTR(printf, 2, 3);
1502+
DLLEXPORT int jl_vprintf(uv_stream_t *s, const char *format, va_list args)
1503+
_JL_FORMAT_ATTR(printf, 2, 0);
1504+
DLLEXPORT void jl_safe_printf(const char *str, ...)
1505+
_JL_FORMAT_ATTR(printf, 1, 2);
14961506

14971507
extern DLLEXPORT JL_STREAM *JL_STDIN;
14981508
extern DLLEXPORT JL_STREAM *JL_STDOUT;

src/task.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <assert.h>
1212
#include <signal.h>
1313
#include <errno.h>
14+
#include <inttypes.h>
1415
#include "julia.h"
1516
#include "julia_internal.h"
1617

@@ -754,11 +755,12 @@ DLLEXPORT void gdblookup(ptrint_t ip)
754755
frame_info_from_ip(&func_name, &line_num, &file_name, ip, 0);
755756
if (func_name != NULL) {
756757
if (line_num == ip)
757-
jl_safe_printf("unknown function (ip: %d)\n", line_num);
758+
jl_safe_printf("unknown function (ip: %p)\n", (void*)ip);
758759
else if (line_num == -1)
759760
jl_safe_printf("%s at %s (unknown line)\n", func_name, file_name);
760761
else
761-
jl_safe_printf("%s at %s:%d\n", func_name, file_name, line_num);
762+
jl_safe_printf("%s at %s:%" PRIuPTR "\n", func_name, file_name,
763+
(uintptr_t)line_num);
762764
}
763765
}
764766

0 commit comments

Comments
 (0)