Skip to content

Commit 03ea96b

Browse files
authored
AVRO-3960: [C] Fix st ANYARGS warning (#2798)
This removes the following warning: avro/lang/c/src/st.c:240:13: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype] hash_val = do_hash(key, table); Signed-off-by: Sahil Kang <[email protected]> Signed-off-by: Sahil Kang <[email protected]>
1 parent 8866b81 commit 03ea96b

File tree

8 files changed

+45
-47
lines changed

8 files changed

+45
-47
lines changed

lang/c/src/datum.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static void avro_datum_free(avro_datum_t datum)
10951095
record = avro_datum_to_record(datum);
10961096
avro_schema_decref(record->schema);
10971097
st_foreach(record->fields_byname,
1098-
HASH_FUNCTION_CAST char_datum_free_foreach, 0);
1098+
(hash_function_foreach) char_datum_free_foreach, 0);
10991099
st_free_table(record->field_order);
11001100
st_free_table(record->fields_byname);
11011101
avro_freet(struct avro_record_datum_t, record);
@@ -1123,7 +1123,7 @@ static void avro_datum_free(avro_datum_t datum)
11231123
struct avro_map_datum_t *map;
11241124
map = avro_datum_to_map(datum);
11251125
avro_schema_decref(map->schema);
1126-
st_foreach(map->map, HASH_FUNCTION_CAST char_datum_free_foreach,
1126+
st_foreach(map->map, (hash_function_foreach) char_datum_free_foreach,
11271127
0);
11281128
st_free_table(map->map);
11291129
st_free_table(map->indices_by_key);
@@ -1135,7 +1135,7 @@ static void avro_datum_free(avro_datum_t datum)
11351135
struct avro_array_datum_t *array;
11361136
array = avro_datum_to_array(datum);
11371137
avro_schema_decref(array->schema);
1138-
st_foreach(array->els, HASH_FUNCTION_CAST array_free_foreach, 0);
1138+
st_foreach(array->els, (hash_function_foreach) array_free_foreach, 0);
11391139
st_free_table(array->els);
11401140
avro_freet(struct avro_array_datum_t, array);
11411141
}
@@ -1183,7 +1183,7 @@ avro_datum_reset(avro_datum_t datum)
11831183
{
11841184
struct avro_array_datum_t *array;
11851185
array = avro_datum_to_array(datum);
1186-
st_foreach(array->els, HASH_FUNCTION_CAST array_free_foreach, 0);
1186+
st_foreach(array->els, (hash_function_foreach) array_free_foreach, 0);
11871187
st_free_table(array->els);
11881188

11891189
rval = avro_init_array(array);
@@ -1198,7 +1198,7 @@ avro_datum_reset(avro_datum_t datum)
11981198
{
11991199
struct avro_map_datum_t *map;
12001200
map = avro_datum_to_map(datum);
1201-
st_foreach(map->map, HASH_FUNCTION_CAST char_datum_free_foreach, 0);
1201+
st_foreach(map->map, (hash_function_foreach) char_datum_free_foreach, 0);
12021202
st_free_table(map->map);
12031203
st_free_table(map->indices_by_key);
12041204
st_free_table(map->keys_by_index);
@@ -1217,7 +1217,7 @@ avro_datum_reset(avro_datum_t datum)
12171217
record = avro_datum_to_record(datum);
12181218
rval = 0;
12191219
st_foreach(record->fields_byname,
1220-
HASH_FUNCTION_CAST datum_reset_foreach, (st_data_t) &rval);
1220+
(hash_function_foreach) datum_reset_foreach, (st_data_t) &rval);
12211221
return rval;
12221222
}
12231223

lang/c/src/datum_equal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int map_equal(struct avro_map_datum_t *a, struct avro_map_datum_t *b)
7878
if (a->map->num_entries != b->map->num_entries) {
7979
return 0;
8080
}
81-
st_foreach(a->map, HASH_FUNCTION_CAST st_equal_foreach, (st_data_t) & args);
81+
st_foreach(a->map, (hash_function_foreach) st_equal_foreach, (st_data_t) & args);
8282
return args.rval;
8383
}
8484

@@ -93,7 +93,7 @@ static int record_equal(struct avro_record_datum_t *a,
9393
if (a->fields_byname->num_entries != b->fields_byname->num_entries) {
9494
return 0;
9595
}
96-
st_foreach(a->fields_byname, HASH_FUNCTION_CAST st_equal_foreach, (st_data_t) & args);
96+
st_foreach(a->fields_byname, (hash_function_foreach) st_equal_foreach, (st_data_t) & args);
9797
return args.rval;
9898
}
9999

lang/c/src/datum_size.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ size_map(avro_writer_t writer, const avro_encoding_t * enc,
126126
if (datum->map->num_entries) {
127127
size_accum(rval, size,
128128
enc->size_long(writer, datum->map->num_entries));
129-
st_foreach(datum->map, HASH_FUNCTION_CAST size_map_foreach, (st_data_t) & args);
129+
st_foreach(datum->map, (hash_function_foreach) size_map_foreach, (st_data_t) & args);
130130
size += args.size;
131131
}
132132
if (!args.rval) {

lang/c/src/datum_validate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ avro_schema_datum_validate(avro_schema_t expected_schema, avro_datum_t datum)
123123
{ avro_schema_to_map(expected_schema)->values, 1
124124
};
125125
st_foreach(avro_datum_to_map(datum)->map,
126-
HASH_FUNCTION_CAST schema_map_validate_foreach,
126+
(hash_function_foreach) schema_map_validate_foreach,
127127
(st_data_t) & vst);
128128
return vst.rval;
129129
}

lang/c/src/memoize.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ avro_memoize_key_hash(avro_memoize_key_t *a)
5252

5353

5454
static struct st_hash_type avro_memoize_hash_type = {
55-
HASH_FUNCTION_CAST avro_memoize_key_cmp,
56-
HASH_FUNCTION_CAST avro_memoize_key_hash
55+
(hash_function_compare) avro_memoize_key_cmp,
56+
(hash_function_hash) avro_memoize_key_hash
5757
};
5858

5959

@@ -78,7 +78,7 @@ avro_memoize_free_key(avro_memoize_key_t *key, void *result, void *dummy)
7878
void
7979
avro_memoize_done(avro_memoize_t *mem)
8080
{
81-
st_foreach((st_table *) mem->cache, HASH_FUNCTION_CAST avro_memoize_free_key, 0);
81+
st_foreach((st_table *) mem->cache, (hash_function_foreach) avro_memoize_free_key, 0);
8282
st_free_table((st_table *) mem->cache);
8383
memset(mem, 0, sizeof(avro_memoize_t));
8484
}

lang/c/src/schema.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void avro_schema_free(avro_schema_t schema)
137137
if (record->space) {
138138
avro_str_free(record->space);
139139
}
140-
st_foreach(record->fields, HASH_FUNCTION_CAST record_free_foreach,
140+
st_foreach(record->fields, (hash_function_foreach) record_free_foreach,
141141
0);
142142
st_free_table(record->fields_byname);
143143
st_free_table(record->fields);
@@ -152,7 +152,7 @@ static void avro_schema_free(avro_schema_t schema)
152152
if (enump->space) {
153153
avro_str_free(enump->space);
154154
}
155-
st_foreach(enump->symbols, HASH_FUNCTION_CAST enum_free_foreach,
155+
st_foreach(enump->symbols, (hash_function_foreach) enum_free_foreach,
156156
0);
157157
st_free_table(enump->symbols);
158158
st_free_table(enump->symbols_byname);
@@ -189,7 +189,7 @@ static void avro_schema_free(avro_schema_t schema)
189189
case AVRO_UNION:{
190190
struct avro_union_schema_t *unionp;
191191
unionp = avro_schema_to_union(schema);
192-
st_foreach(unionp->branches, HASH_FUNCTION_CAST union_free_foreach,
192+
st_foreach(unionp->branches, (hash_function_foreach) union_free_foreach,
193193
0);
194194
st_free_table(unionp->branches);
195195
st_free_table(unionp->branches_byname);
@@ -1239,7 +1239,7 @@ avro_schema_from_json_root(json_t *root, avro_schema_t *schema)
12391239
/* json_dumpf(root, stderr, 0); */
12401240
rval = avro_schema_from_json_t(root, schema, named_schemas, NULL);
12411241
json_decref(root);
1242-
st_foreach(named_schemas, HASH_FUNCTION_CAST named_schema_free_foreach, 0);
1242+
st_foreach(named_schemas, (hash_function_foreach) named_schema_free_foreach, 0);
12431243
st_free_table(named_schemas);
12441244
return rval;
12451245
}
@@ -1455,7 +1455,7 @@ avro_schema_t avro_schema_copy(avro_schema_t schema)
14551455
}
14561456

14571457
new_schema = avro_schema_copy_root(schema, named_schemas);
1458-
st_foreach(named_schemas, HASH_FUNCTION_CAST named_schema_free_foreach, 0);
1458+
st_foreach(named_schemas, (hash_function_foreach) named_schema_free_foreach, 0);
14591459
st_free_table(named_schemas);
14601460
return new_schema;
14611461
}

lang/c/src/st.c

+18-16
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ struct st_table_entry {
3939
static int numcmp(long, long);
4040
static int numhash(long);
4141
static struct st_hash_type type_numhash = {
42-
HASH_FUNCTION_CAST numcmp,
43-
HASH_FUNCTION_CAST numhash
42+
(hash_function_compare) numcmp,
43+
(hash_function_hash) numhash
4444
};
4545

4646
/*
4747
* extern int strcmp(const char *, const char *);
4848
*/
4949
static int strhash(const char *);
5050
static struct st_hash_type type_strhash = {
51-
HASH_FUNCTION_CAST strcmp,
52-
HASH_FUNCTION_CAST strhash
51+
(hash_function_compare) strcmp,
52+
(hash_function_hash) strhash
5353
};
5454

5555
static void rehash(st_table *);
@@ -212,7 +212,7 @@ void st_free_table(st_table *table)
212212
}
213213

214214
#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
215-
((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
215+
((ptr) != 0 && (ptr->hash != (hash_val) || !EQUAL((table), (void*) (key), (void*) (ptr)->key)))
216216

217217
#ifdef HASH_LOG
218218
#define COLLISION collision++
@@ -237,7 +237,7 @@ int st_lookup(st_table *table, register st_data_t key, st_data_t *value)
237237
unsigned int hash_val, bin_pos;
238238
register st_table_entry *ptr;
239239

240-
hash_val = do_hash(key, table);
240+
hash_val = do_hash((void*) key, table);
241241
FIND_ENTRY(table, ptr, hash_val, bin_pos);
242242

243243
if (ptr == 0) {
@@ -272,7 +272,7 @@ int st_insert(register st_table *table, register st_data_t key, st_data_t value)
272272
unsigned int hash_val, bin_pos;
273273
register st_table_entry *ptr;
274274

275-
hash_val = do_hash(key, table);
275+
hash_val = do_hash((void*) key, table);
276276
FIND_ENTRY(table, ptr, hash_val, bin_pos);
277277

278278
if (ptr == 0) {
@@ -288,7 +288,7 @@ void st_add_direct(st_table *table,st_data_t key,st_data_t value)
288288
{
289289
unsigned int hash_val, bin_pos;
290290

291-
hash_val = do_hash(key, table);
291+
hash_val = do_hash((void*) key, table);
292292
bin_pos = hash_val % table->num_bins;
293293
ADD_DIRECT(table, key, value, hash_val, bin_pos);
294294
}
@@ -363,7 +363,7 @@ int st_delete(register st_table *table,register st_data_t *key,st_data_t *value)
363363
st_table_entry *tmp;
364364
register st_table_entry *ptr;
365365

366-
hash_val = do_hash_bin(*key, table);
366+
hash_val = do_hash_bin((void*) *key, table);
367367
ptr = table->bins[hash_val];
368368

369369
if (ptr == 0) {
@@ -372,7 +372,7 @@ int st_delete(register st_table *table,register st_data_t *key,st_data_t *value)
372372
return 0;
373373
}
374374

375-
if (EQUAL(table, *key, ptr->key)) {
375+
if (EQUAL(table, (void*) *key, (void*) ptr->key)) {
376376
table->bins[hash_val] = ptr->next;
377377
table->num_entries--;
378378
if (value != 0)
@@ -383,7 +383,7 @@ int st_delete(register st_table *table,register st_data_t *key,st_data_t *value)
383383
}
384384

385385
for (; ptr->next != 0; ptr = ptr->next) {
386-
if (EQUAL(table, ptr->next->key, *key)) {
386+
if (EQUAL(table, (void*) ptr->next->key, (void*) *key)) {
387387
tmp = ptr->next;
388388
ptr->next = ptr->next->next;
389389
table->num_entries--;
@@ -403,7 +403,7 @@ int st_delete_safe(register st_table *table,register st_data_t *key,st_data_t *v
403403
unsigned int hash_val;
404404
register st_table_entry *ptr;
405405

406-
hash_val = do_hash_bin(*key, table);
406+
hash_val = do_hash_bin((void*) *key, table);
407407
ptr = table->bins[hash_val];
408408

409409
if (ptr == 0) {
@@ -413,7 +413,7 @@ int st_delete_safe(register st_table *table,register st_data_t *key,st_data_t *v
413413
}
414414

415415
for (; ptr != 0; ptr = ptr->next) {
416-
if ((ptr->key != never) && EQUAL(table, ptr->key, *key)) {
416+
if ((ptr->key != never) && EQUAL(table, (void*) ptr->key, (void*) *key)) {
417417
table->num_entries--;
418418
*key = ptr->key;
419419
if (value != 0)
@@ -439,11 +439,11 @@ void st_cleanup_safe(st_table *table,st_data_t never)
439439
{
440440
int num_entries = table->num_entries;
441441

442-
st_foreach(table, HASH_FUNCTION_CAST delete_never, never);
442+
st_foreach(table, (hash_function_foreach) delete_never, never);
443443
table->num_entries = num_entries;
444444
}
445445

446-
int st_foreach(st_table *table,int (*func) (ANYARGS),st_data_t arg)
446+
int st_foreach(st_table *table,int (*func) (void*, void*, void*),st_data_t arg)
447447
{
448448
st_table_entry *ptr, *last, *tmp;
449449
enum st_retval retval;
@@ -452,7 +452,9 @@ int st_foreach(st_table *table,int (*func) (ANYARGS),st_data_t arg)
452452
for (i = 0; i < table->num_bins; i++) {
453453
last = 0;
454454
for (ptr = table->bins[i]; ptr != 0;) {
455-
retval = (enum st_retval) (*func) (ptr->key, ptr->record, arg);
455+
retval = (enum st_retval) (*func) ((void*) ptr->key,
456+
(void*) ptr->record,
457+
(void*) arg);
456458
switch (retval) {
457459
case ST_CHECK: /* check if hash is modified during
458460
* iteration */

lang/c/src/st.h

+9-13
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,22 @@ extern "C" {
2020

2121
#pragma GCC visibility push(hidden)
2222

23-
#ifndef ANYARGS
24-
#ifdef __cplusplus
25-
#define ANYARGS ...
26-
#else
27-
#define ANYARGS
28-
#endif
29-
#endif
30-
3123
#ifdef _WIN32
32-
#define HASH_FUNCTION_CAST (int (__cdecl *)(ANYARGS))
24+
typedef int (__cdecl *hash_function_compare)(void*, void*);
25+
typedef int (__cdecl *hash_function_hash)(void*);
26+
typedef int (__cdecl *hash_function_foreach)(void*, void*, void*);
3327
#else
34-
#define HASH_FUNCTION_CAST
28+
typedef int (*hash_function_compare)(void*, void*);
29+
typedef int (*hash_function_hash)(void*);
30+
typedef int (*hash_function_foreach)(void*, void*, void*);
3531
#endif
3632

3733
typedef uintptr_t st_data_t;
3834
typedef struct st_table st_table;
3935

4036
struct st_hash_type {
41-
int (*compare) (ANYARGS);
42-
int (*hash) (ANYARGS);
37+
hash_function_compare compare;
38+
hash_function_hash hash;
4339
};
4440

4541
struct st_table {
@@ -67,7 +63,7 @@ int st_delete _((st_table *, st_data_t *, st_data_t *));
6763
int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t));
6864
int st_insert _((st_table *, st_data_t, st_data_t));
6965
int st_lookup _((st_table *, st_data_t, st_data_t *));
70-
int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t));
66+
int st_foreach _((st_table *, hash_function_foreach, st_data_t));
7167
void st_add_direct _((st_table *, st_data_t, st_data_t));
7268
void st_free_table _((st_table *));
7369
void st_cleanup_safe _((st_table *, st_data_t));

0 commit comments

Comments
 (0)