Skip to content

Commit f760dad

Browse files
authored
Merge pull request #22005 from JuliaLang/yyc/pedantic
Fix all pedantic warnings in C
2 parents aa011a7 + d756106 commit f760dad

17 files changed

+60
-54
lines changed

src/dlload.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ static void *jl_load_dynamic_library_(const char *modname, unsigned flags, int t
134134
if (modname == NULL) {
135135
#ifdef _OS_WINDOWS_
136136
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
137-
(LPCWSTR)(&jl_load_dynamic_library),
137+
(LPCWSTR)(uintptr_t)(&jl_load_dynamic_library),
138138
(HMODULE*)&handle)) {
139139
jl_error("could not load base module");
140140
}
141141
#else
142142
Dl_info info;
143-
if (!dladdr(&jl_load_dynamic_library, &info) || !info.dli_fname)
143+
if (!dladdr((void*)(uintptr_t)&jl_load_dynamic_library, &info) || !info.dli_fname)
144144
jl_error("could not load base module");
145145
handle = dlopen(info.dli_fname, RTLD_NOW);
146146
#endif

src/dump.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void jl_load_sysimg_so(void)
240240
size_t tls_getter_idx = *(size_t*)jl_dlsym(jl_sysimg_handle,
241241
"jl_ptls_states_getter_idx");
242242
*sysimg_gvars[tls_getter_idx - 1] =
243-
(jl_value_t*)jl_get_ptls_states_getter();
243+
(jl_value_t*)(uintptr_t)jl_get_ptls_states_getter();
244244
size_t tls_offset_idx = *(size_t*)jl_dlsym(jl_sysimg_handle,
245245
"jl_tls_offset_idx");
246246
*sysimg_gvars[tls_offset_idx - 1] =
@@ -445,12 +445,12 @@ static void jl_update_all_fptrs(void)
445445
assert(li->def && li->jlcall_api && li->jlcall_api != 2);
446446
int32_t cfunc = delayed_fptrs[i].cfunc - 1;
447447
if (cfunc >= 0) {
448-
jl_fptr_to_llvm((jl_fptr_t)fvars[cfunc], li, 1);
448+
jl_fptr_to_llvm((jl_fptr_t)(uintptr_t)fvars[cfunc], li, 1);
449449
linfos[cfunc] = li;
450450
}
451451
int32_t func = delayed_fptrs[i].func - 1;
452452
if (func >= 0) {
453-
jl_fptr_to_llvm((jl_fptr_t)fvars[func], li, 0);
453+
jl_fptr_to_llvm((jl_fptr_t)(uintptr_t)fvars[func], li, 0);
454454
linfos[func] = li;
455455
}
456456
}
@@ -2141,7 +2141,7 @@ static jl_value_t *jl_deserialize_value_(jl_serializer_state *s, jl_value_t *vta
21412141
}
21422142
}
21432143

2144-
typedef struct _linkedlist_t {
2144+
JL_EXTENSION typedef struct _linkedlist_t {
21452145
struct _linkedlist_t *next;
21462146
union {
21472147
struct {
@@ -3429,7 +3429,7 @@ void jl_init_serializer(void)
34293429

34303430
i=2;
34313431
while (id_to_fptrs[i] != NULL) {
3432-
ptrhash_put(&fptr_to_id, (void*)id_to_fptrs[i], (void*)i);
3432+
ptrhash_put(&fptr_to_id, (void*)(uintptr_t)id_to_fptrs[i], (void*)i);
34333433
i += 1;
34343434
}
34353435

src/flisp/cvalues.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ value_t cbuiltin(fl_context_t *fl_ctx, const char *name, builtin_t f)
780780
cv->type = fl_ctx->builtintype;
781781
cv->data = &cv->_space[0];
782782
cv->len = sizeof(value_t);
783-
*(void**)cv->data = (void*)f;
783+
*(void**)cv->data = (void*)(uintptr_t)f;
784784

785785
value_t sym = symbol(fl_ctx, name);
786786
((symbol_t*)ptr(sym))->dlcache = cv;

src/flisp/flisp.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ static uint32_t process_keys(fl_context_t *fl_ctx, value_t kwtable,
10201020
- allocate vararg array
10211021
- push closed env, set up new environment
10221022
*/
1023-
static value_t apply_cl(fl_context_t *fl_ctx, uint32_t nargs)
1023+
JL_EXTENSION static value_t apply_cl(fl_context_t *fl_ctx, uint32_t nargs)
10241024
{
10251025
VM_LABELS;
10261026
VM_APPLY_LABELS;
@@ -1173,7 +1173,7 @@ static value_t apply_cl(fl_context_t *fl_ctx, uint32_t nargs)
11731173
}
11741174
else if (iscbuiltin(fl_ctx, fl_apply_func)) {
11751175
s = fl_ctx->SP;
1176-
fl_apply_v = ((builtin_t)(((void**)ptr(fl_apply_func))[3]))(fl_ctx, &fl_ctx->Stack[fl_ctx->SP-n], n);
1176+
fl_apply_v = ((builtin_t)(uintptr_t)(((void**)ptr(fl_apply_func))[3]))(fl_ctx, &fl_ctx->Stack[fl_ctx->SP-n], n);
11771177
fl_ctx->SP = s-n;
11781178
fl_ctx->Stack[fl_ctx->SP-1] = fl_apply_v;
11791179
NEXT_OP;
@@ -1223,7 +1223,7 @@ static value_t apply_cl(fl_context_t *fl_ctx, uint32_t nargs)
12231223
}
12241224
else if (iscbuiltin(fl_ctx, fl_apply_func)) {
12251225
s = fl_ctx->SP;
1226-
fl_apply_v = ((builtin_t)(((void**)ptr(fl_apply_func))[3]))(fl_ctx, &fl_ctx->Stack[fl_ctx->SP-n], n);
1226+
fl_apply_v = ((builtin_t)(uintptr_t)(((void**)ptr(fl_apply_func))[3]))(fl_ctx, &fl_ctx->Stack[fl_ctx->SP-n], n);
12271227
fl_ctx->SP = s-n;
12281228
fl_ctx->Stack[fl_ctx->SP-1] = fl_apply_v;
12291229
NEXT_OP;

src/flisp/flisp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ typedef struct _fltype_t {
248248
cvinitfunc_t init;
249249
} fltype_t;
250250

251-
typedef struct {
251+
JL_EXTENSION typedef struct {
252252
fltype_t *type;
253253
void *data;
254254
size_t len; // length of *data in bytes

src/flisp/print.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -642,18 +642,18 @@ static void cvalue_printdata(fl_context_t *fl_ctx, ios_t *f, void *data,
642642
if (init == 0) {
643643
#if defined(RTLD_SELF)
644644
jl_static_print = (size_t (*)(ios_t*, void*))
645-
dlsym(RTLD_SELF, "jl_static_show");
645+
(uintptr_t)dlsym(RTLD_SELF, "jl_static_show");
646646
#elif defined(RTLD_DEFAULT)
647647
jl_static_print = (size_t (*)(ios_t*, void*))
648-
dlsym(RTLD_DEFAULT, "jl_static_show");
648+
(uintptr_t)dlsym(RTLD_DEFAULT, "jl_static_show");
649649
#elif defined(_OS_WINDOWS_)
650650
HMODULE handle;
651651
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
652652
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
653653
(LPCWSTR)(&cvalue_printdata),
654654
&handle)) {
655655
jl_static_print = (size_t (*)(ios_t*, void*))
656-
GetProcAddress(handle, "jl_static_show");
656+
(uintptr_t)GetProcAddress(handle, "jl_static_show");
657657
}
658658
#endif
659659
init = 1;
@@ -748,8 +748,7 @@ static void cvalue_print(fl_context_t *fl_ctx, ios_t *f, value_t v)
748748
void *fptr = *(void**)data;
749749
label = (value_t)ptrhash_get(&fl_ctx->reverse_dlsym_lookup_table, cv);
750750
if (label == (value_t)HT_NOTFOUND) {
751-
fl_ctx->HPOS += ios_printf(f, "#<builtin @0x%08zx>",
752-
(size_t)(builtin_t)fptr);
751+
fl_ctx->HPOS += ios_printf(f, "#<builtin @0x%08zx>", (size_t)fptr);
753752
}
754753
else {
755754
if (fl_ctx->print_princ) {

src/gc-debug.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
12611261
break;
12621262
}
12631263
jl_safe_printf("%p: Root object: %p :: %p (bits: %d)\n of type ",
1264-
data, data->obj, (void*)data->tag, (int)data->bits);
1264+
(void*)data, (void*)data->obj, (void*)data->tag, (int)data->bits);
12651265
jl_((void*)data->tag);
12661266
isroot = 1;
12671267
}
@@ -1272,7 +1272,7 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
12721272
break;
12731273
}
12741274
jl_safe_printf("%p: Queued root: %p :: %p (bits: %d)\n of type ",
1275-
data, data->obj, (void*)data->tag, (int)data->bits);
1275+
(void*)data, (void*)data->obj, (void*)data->tag, (int)data->bits);
12761276
jl_((void*)data->tag);
12771277
isroot = 1;
12781278
}
@@ -1282,7 +1282,8 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
12821282
jl_safe_printf("Mark stack unwind overflow -- ABORTING !!!\n");
12831283
break;
12841284
}
1285-
jl_safe_printf("%p: Finalizer list from %p to %p\n", data, data->begin, data->end);
1285+
jl_safe_printf("%p: Finalizer list from %p to %p\n",
1286+
(void*)data, (void*)data->begin, (void*)data->end);
12861287
isroot = 1;
12871288
}
12881289
else if (pc == gc_mark_label_addrs[GC_MARK_L_objarray]) {
@@ -1292,8 +1293,8 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
12921293
break;
12931294
}
12941295
jl_safe_printf("%p: %s Array in object %p :: %p -- [%p, %p)\n of type ",
1295-
data, prefix, data->parent, ((void**)data->parent)[-1],
1296-
data->begin, data->end);
1296+
(void*)data, prefix, (void*)data->parent, ((void**)data->parent)[-1],
1297+
(void*)data->begin, (void*)data->end);
12971298
jl_(jl_typeof(data->parent));
12981299
}
12991300
else if (pc == gc_mark_label_addrs[GC_MARK_L_obj8]) {
@@ -1305,7 +1306,7 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
13051306
jl_datatype_t *vt = (jl_datatype_t*)jl_typeof(data->parent);
13061307
jl_fielddesc8_t *desc = (jl_fielddesc8_t*)jl_dt_layout_fields(vt->layout);
13071308
jl_safe_printf("%p: %s Object (8bit) %p :: %p -- [%d, %d)\n of type ",
1308-
data, prefix, data->parent, ((void**)data->parent)[-1],
1309+
(void*)data, prefix, (void*)data->parent, ((void**)data->parent)[-1],
13091310
(int)(data->begin - desc), (int)(data->end - desc));
13101311
jl_(jl_typeof(data->parent));
13111312
}
@@ -1318,7 +1319,7 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
13181319
jl_datatype_t *vt = (jl_datatype_t*)jl_typeof(data->parent);
13191320
jl_fielddesc16_t *desc = (jl_fielddesc16_t*)jl_dt_layout_fields(vt->layout);
13201321
jl_safe_printf("%p: %s Object (16bit) %p :: %p -- [%d, %d)\n of type ",
1321-
data, prefix, data->parent, ((void**)data->parent)[-1],
1322+
(void*)data, prefix, (void*)data->parent, ((void**)data->parent)[-1],
13221323
(int)(data->begin - desc), (int)(data->end - desc));
13231324
jl_(jl_typeof(data->parent));
13241325
}
@@ -1331,7 +1332,7 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
13311332
jl_datatype_t *vt = (jl_datatype_t*)jl_typeof(data->parent);
13321333
jl_fielddesc32_t *desc = (jl_fielddesc32_t*)jl_dt_layout_fields(vt->layout);
13331334
jl_safe_printf("%p: %s Object (32bit) %p :: %p -- [%d, %d)\n of type ",
1334-
data, prefix, data->parent, ((void**)data->parent)[-1],
1335+
(void*)data, prefix, (void*)data->parent, ((void**)data->parent)[-1],
13351336
(int)(data->begin - desc), (int)(data->end - desc));
13361337
jl_(jl_typeof(data->parent));
13371338
}
@@ -1342,7 +1343,8 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
13421343
break;
13431344
}
13441345
jl_safe_printf("%p: %s Stack frame %p -- %d of %d (%s)\n",
1345-
data, prefix, data->s, (int)data->i, (int)data->nroots >> 1,
1346+
(void*)data, prefix, (void*)data->s, (int)data->i,
1347+
(int)data->nroots >> 1,
13461348
(data->nroots & 1) ? "indirect" : "direct");
13471349
}
13481350
else if (pc == gc_mark_label_addrs[GC_MARK_L_module_binding]) {
@@ -1353,7 +1355,8 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, gc_mark_sp_t sp, int pc_offset
13531355
break;
13541356
}
13551357
jl_safe_printf("%p: %s Module (bindings) %p (bits %d) -- [%p, %p)\n",
1356-
data, prefix, data->parent, (int)data->bits, data->begin, data->end);
1358+
(void*)data, prefix, (void*)data->parent, (int)data->bits,
1359+
(void*)data->begin, (void*)data->end);
13571360
}
13581361
else {
13591362
jl_safe_printf("Unknown pc %p --- ABORTING !!!\n", pc);

src/gc.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void finalize_object(arraylist_t *list, jl_value_t *o,
140140
void *f = items[i + 1];
141141
move = 1;
142142
if (gc_ptr_tag(v, 1)) {
143-
((void (*)(void*))f)(o);
143+
((void (*)(void*))(uintptr_t)f)(o);
144144
}
145145
else {
146146
arraylist_push(copied_list, o);
@@ -260,7 +260,7 @@ static void schedule_all_finalizers(arraylist_t *flist)
260260
schedule_finalization(v, f);
261261
}
262262
else {
263-
((void (*)(void*))f)(gc_ptr_clear_tag(v, 1));
263+
((void (*)(void*))(uintptr_t)f)(gc_ptr_clear_tag(v, 1));
264264
}
265265
}
266266
flist->len = 0;
@@ -1683,7 +1683,7 @@ STATIC_INLINE int gc_mark_scan_obj32(jl_ptls_t ptls, gc_mark_sp_t *sp, gc_mark_o
16831683
// Additional optimizations are done for some of the common cases by skipping
16841684
// the unnecessary data stack pointer increment and the load from the stack
16851685
// (i.e. store to load forwaring). See `objary_loaded`, `obj8_loaded` and `obj16_loaded`.
1686-
NOINLINE void gc_mark_loop(jl_ptls_t ptls, gc_mark_sp_t sp)
1686+
JL_EXTENSION NOINLINE void gc_mark_loop(jl_ptls_t ptls, gc_mark_sp_t sp)
16871687
{
16881688
if (__unlikely(ptls == NULL)) {
16891689
gc_mark_label_addrs[GC_MARK_L_marked_obj] = gc_mark_laddr(marked_obj);
@@ -2234,7 +2234,7 @@ static void sweep_finalizer_list(arraylist_t *list)
22342234
if (isfreed) {
22352235
// schedule finalizer or execute right away if it is not julia code
22362236
if (is_cptr) {
2237-
((void (*)(void*))fin)(jl_data_ptr(v));
2237+
((void (*)(void*))(uintptr_t)fin)(jl_data_ptr(v));
22382238
continue;
22392239
}
22402240
schedule_finalization(v, fin);

src/gc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ typedef union {
211211

212212
// layout for big (>2k) objects
213213

214-
typedef struct _bigval_t {
214+
JL_EXTENSION typedef struct _bigval_t {
215215
struct _bigval_t *next;
216216
struct _bigval_t **prev; // pointer to the next field of the prev entry
217217
union {

src/jl_uv.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,13 @@ JL_DLLEXPORT int jl_fs_close(int handle)
405405
}
406406

407407
JL_DLLEXPORT int jl_uv_write(uv_stream_t *stream, const char *data, size_t n,
408-
uv_write_t *uvw, void *writecb)
408+
uv_write_t *uvw, uv_write_cb writecb)
409409
{
410410
uv_buf_t buf[1];
411411
buf[0].base = (char*)data;
412412
buf[0].len = n;
413413
JL_SIGATOMIC_BEGIN();
414-
int err = uv_write(uvw,stream,buf,1,(uv_write_cb)writecb);
414+
int err = uv_write(uvw, stream, buf, 1, writecb);
415415
JL_SIGATOMIC_END();
416416
return err;
417417
}
@@ -941,15 +941,15 @@ void jl_work_notifier(uv_work_t *req, int status)
941941
free(baton);
942942
}
943943

944-
JL_DLLEXPORT int jl_queue_work(void *work_func, void *work_args, void *work_retval,
945-
void *notify_func, int notify_idx)
944+
JL_DLLEXPORT int jl_queue_work(work_cb_t work_func, void *work_args, void *work_retval,
945+
notify_cb_t notify_func, int notify_idx)
946946
{
947947
struct work_baton *baton = (struct work_baton*) malloc(sizeof(struct work_baton));
948948
baton->req.data = (void*) baton;
949-
baton->work_func = (work_cb_t)work_func;
949+
baton->work_func = work_func;
950950
baton->work_args = work_args;
951951
baton->work_retval = work_retval;
952-
baton->notify_func = (notify_cb_t)notify_func;
952+
baton->notify_func = notify_func;
953953
baton->notify_idx = notify_idx;
954954

955955
uv_queue_work(jl_io_loop, &baton->req, jl_work_wrapper, jl_work_notifier);

src/jltypes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ JL_DLLEXPORT jl_value_t *jl_tupletype_fill(size_t n, jl_value_t *v)
826826
return p;
827827
}
828828

829-
typedef struct _jl_typestack_t {
829+
JL_EXTENSION typedef struct _jl_typestack_t {
830830
union {
831831
jl_value_t *ua;
832832
jl_datatype_t *tt;

src/julia.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct _jl_taggedvalue_bits {
7474
uintptr_t gc:2;
7575
};
7676

77-
struct _jl_taggedvalue_t {
77+
JL_EXTENSION struct _jl_taggedvalue_t {
7878
union {
7979
uintptr_t header;
8080
jl_taggedvalue_t *next;
@@ -140,7 +140,7 @@ typedef struct {
140140
uint16_t isaligned:1; // data allocated with memalign
141141
} jl_array_flags_t;
142142

143-
typedef struct {
143+
JL_EXTENSION typedef struct {
144144
JL_DATA_TYPE
145145
void *data;
146146
#ifdef STORE_ARRAY_LEN
@@ -190,7 +190,7 @@ typedef jl_value_t *(*jl_fptr_t)(jl_value_t*, jl_value_t**, uint32_t);
190190
typedef jl_value_t *(*jl_fptr_sparam_t)(jl_svec_t*, jl_value_t*, jl_value_t**, uint32_t);
191191
typedef jl_value_t *(*jl_fptr_linfo_t)(struct _jl_method_instance_t*, jl_value_t**, uint32_t, jl_svec_t*);
192192

193-
typedef struct {
193+
JL_EXTENSION typedef struct {
194194
union {
195195
jl_fptr_t fptr;
196196
jl_fptr_t fptr1;

src/rtutils.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
504504
{
505505
size_t n = 0;
506506
if ((uintptr_t)vt < 4096U) {
507-
n += jl_printf(out, "<?#%p::%p>", v, vt);
507+
n += jl_printf(out, "<?#%p::%p>", (void*)v, (void*)vt);
508508
}
509509
else if ((uintptr_t)v < 4096U) {
510-
n += jl_printf(out, "<?#%p::", v);
510+
n += jl_printf(out, "<?#%p::", (void*)v);
511511
n += jl_static_show_x(out, (jl_value_t*)vt, depth);
512512
n += jl_printf(out, ">");
513513
}
@@ -876,7 +876,7 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
876876
n += jl_printf(out, ")");
877877
}
878878
else {
879-
n += jl_printf(out, "<?#%p::", v);
879+
n += jl_printf(out, "<?#%p::", (void*)v);
880880
n += jl_static_show_x(out, (jl_value_t*)vt, depth);
881881
n += jl_printf(out, ">");
882882
}

src/support/dtypes.h

+2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ STATIC_INLINE unsigned int next_power_of_two(unsigned int val)
166166
#ifdef __GNUC__
167167
#define __unlikely(x) __builtin_expect(!!(x), 0)
168168
#define __likely(x) __builtin_expect(!!(x), 1)
169+
#define JL_EXTENSION __extension__
169170
#else
170171
#define __unlikely(x) (x)
171172
#define __likely(x) (x)
173+
#define JL_EXTENSION
172174
#endif
173175

174176
#define DBL_MAXINT 9007199254740992LL

src/support/htable.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int HTNAME##_remove(htable_t *h, void *key) \
189189
\
190190
void HTNAME##_adjoin(htable_t *h, void *key, void *val) \
191191
{ \
192-
return HTNAME##_adjoin_r(h, key, val, NULL); \
192+
HTNAME##_adjoin_r(h, key, val, NULL); \
193193
}
194194

195195
#define HTIMPL_R(HTNAME, HFUNC, EQFUNC) _HTIMPL_EX(HTNAME, HFUNC, EQFUNC, )

0 commit comments

Comments
 (0)