Skip to content

Commit fd20aa0

Browse files
cosmo0920edsiper
authored andcommitted
st: regparse: Handle C23 strict checking for function signatures
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 2c8aa36 commit fd20aa0

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

lib/onigmo/regparse.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,10 @@ onig_print_names(FILE* fp, regex_t* reg)
501501
# endif /* ONIG_DEBUG */
502502

503503
static int
504-
i_free_name_entry(UChar* key, NameEntry* e, void* arg ARG_UNUSED)
504+
i_free_name_entry(st_data_t vkey, st_data_t ve, st_data_t arg_data ARG_UNUSED, int existing ARG_UNUSED)
505505
{
506+
NameEntry* e = (NameEntry*)ve;
507+
UChar* key = (UChar*)vkey;
506508
xfree(e->name);
507509
if (IS_NOT_NULL(e->back_refs)) xfree(e->back_refs);
508510
xfree(key);
@@ -558,8 +560,12 @@ typedef struct {
558560
} INamesArg;
559561

560562
static int
561-
i_names(UChar* key ARG_UNUSED, NameEntry* e, INamesArg* arg)
563+
i_names(st_data_t key_data ARG_UNUSED, st_data_t value_data, st_data_t arg_data, int existing ARG_UNUSED)
562564
{
565+
/* Cast back to original types */
566+
NameEntry* e = (NameEntry*)value_data;
567+
INamesArg* arg = (INamesArg*)arg_data;
568+
563569
int r = (*(arg->func))(e->name,
564570
e->name + e->name_len,
565571
e->back_num,
@@ -585,16 +591,18 @@ onig_foreach_name(regex_t* reg,
585591
narg.reg = reg;
586592
narg.arg = arg;
587593
narg.enc = reg->enc; /* should be pattern encoding. */
588-
onig_st_foreach(t, i_names, (HashDataType )&narg);
594+
onig_st_foreach(t, i_names, (st_data_t)&narg);
589595
}
590596
return narg.ret;
591597
}
592598

593599
static int
594-
i_renumber_name(UChar* key ARG_UNUSED, NameEntry* e, GroupNumRemap* map)
600+
i_renumber_name(st_data_t key_data ARG_UNUSED, st_data_t ve, st_data_t vmap, int existing ARG_UNUSED)
595601
{
596602
int i;
597603

604+
NameEntry* e = (NameEntry*)ve;
605+
GroupNumRemap* map = (GroupNumRemap*)vmap;
598606
if (e->back_num > 1) {
599607
for (i = 0; i < e->back_num; i++) {
600608
e->back_refs[i] = map[e->back_refs[i]].new_val;
@@ -613,7 +621,7 @@ onig_renumber_name_table(regex_t* reg, GroupNumRemap* map)
613621
NameTable* t = (NameTable* )reg->name_table;
614622

615623
if (IS_NOT_NULL(t)) {
616-
onig_st_foreach(t, i_renumber_name, (HashDataType )map);
624+
onig_st_foreach(t, i_renumber_name, (st_data_t)map);
617625
}
618626
return 0;
619627
}

lib/onigmo/st.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ st_update(st_table *tab, st_data_t key,
16001600
different for ST_CHECK and when the current element is removed
16011601
during traversing. */
16021602
static inline int
1603-
st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg,
1603+
st_general_foreach(st_table *tab, st_foreach_callback_func *func, st_update_callback_func *replace, st_data_t arg,
16041604
int check_p)
16051605
{
16061606
st_index_t bin;
@@ -1712,22 +1712,22 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func
17121712

17131713
#ifdef RUBY
17141714
int
1715-
st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg)
1715+
st_foreach_with_replace(st_table *tab, st_foreach_callback_func *func, st_update_callback_func *replace, st_data_t arg)
17161716
{
17171717
return st_general_foreach(tab, func, replace, arg, TRUE);
17181718
}
17191719
#endif /* RUBY */
17201720

17211721
int
1722-
st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg)
1722+
st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg)
17231723
{
17241724
return st_general_foreach(tab, func, NULL, arg, FALSE);
17251725
}
17261726

17271727
#ifdef RUBY
17281728
/* See comments for function st_delete_safe. */
17291729
int
1730-
st_foreach_check(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
1730+
st_foreach_check(st_table *tab, st_foreach_callback_func *func, st_data_t arg,
17311731
st_data_t never ATTRIBUTE_UNUSED)
17321732
{
17331733
return st_general_foreach(tab, func, NULL, arg, TRUE);

lib/onigmo/st.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index
6666
#define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
6767

6868
struct st_hash_type {
69-
int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
70-
st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
69+
int (*compare)(st_data_t, st_data_t); /* st_compare_func* */
70+
st_index_t (*hash)(st_data_t); /* st_hash_func* */
7171
};
7272

7373
#define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT)
@@ -124,9 +124,10 @@ typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t
124124
/* *key may be altered, but must equal to the old key, i.e., the
125125
* results of hash() are same and compare() returns 0, otherwise the
126126
* behavior is undefined */
127+
typedef int st_foreach_callback_func(st_data_t key, st_data_t value, st_data_t arg, int existing);
127128
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
128-
int st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg);
129-
int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
129+
int st_foreach_with_replace(st_table *tab, st_foreach_callback_func *func, st_update_callback_func *replace, st_data_t arg);
130+
int st_foreach(st_table *, st_foreach_callback_func *func, st_data_t);
130131
int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t);
131132
st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size);
132133
st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);

0 commit comments

Comments
 (0)