1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-26 09:41:40 +03:00

Avoid casting void * function arguments

In many cases, the cast would silently drop a const qualifier.  To
fix, drop the unnecessary cast and let the compiler check the types
and qualifiers.  Add const to read-only local variables, preserving
the const qualifiers from the function signatures.

Co-authored-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Co-authored-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/aUQHy/MmWq7c97wK%40ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
Peter Eisentraut
2026-01-12 16:12:56 +01:00
parent 707f905399
commit c3c240537f
16 changed files with 58 additions and 58 deletions

View File

@@ -857,8 +857,8 @@ brin_range_deserialize(int maxvalues, SerializedRanges *serialized)
static int
compare_expanded_ranges(const void *a, const void *b, void *arg)
{
ExpandedRange *ra = (ExpandedRange *) a;
ExpandedRange *rb = (ExpandedRange *) b;
const ExpandedRange *ra = a;
const ExpandedRange *rb = b;
Datum r;
compare_context *cxt = (compare_context *) arg;
@@ -895,8 +895,8 @@ compare_expanded_ranges(const void *a, const void *b, void *arg)
static int
compare_values(const void *a, const void *b, void *arg)
{
Datum *da = (Datum *) a;
Datum *db = (Datum *) b;
const Datum *da = a;
const Datum *db = b;
Datum r;
compare_context *cxt = (compare_context *) arg;
@@ -1304,8 +1304,8 @@ merge_overlapping_ranges(FmgrInfo *cmp, Oid colloid,
static int
compare_distances(const void *a, const void *b)
{
DistanceValue *da = (DistanceValue *) a;
DistanceValue *db = (DistanceValue *) b;
const DistanceValue *da = a;
const DistanceValue *db = b;
if (da->value < db->value)
return 1;

View File

@@ -103,7 +103,7 @@ static HTAB *missing_cache = NULL;
static uint32
missing_hash(const void *key, Size keysize)
{
const missing_cache_key *entry = (missing_cache_key *) key;
const missing_cache_key *entry = key;
return hash_bytes((const unsigned char *) DatumGetPointer(entry->value), entry->len);
}
@@ -111,8 +111,8 @@ missing_hash(const void *key, Size keysize)
static int
missing_match(const void *key1, const void *key2, Size keysize)
{
const missing_cache_key *entry1 = (missing_cache_key *) key1;
const missing_cache_key *entry2 = (missing_cache_key *) key2;
const missing_cache_key *entry1 = key1;
const missing_cache_key *entry2 = key2;
if (entry1->len != entry2->len)
return entry1->len > entry2->len ? 1 : -1;

View File

@@ -2021,8 +2021,8 @@ heap_log_freeze_eq(xlhp_freeze_plan *plan, HeapTupleFreeze *frz)
static int
heap_log_freeze_cmp(const void *arg1, const void *arg2)
{
HeapTupleFreeze *frz1 = (HeapTupleFreeze *) arg1;
HeapTupleFreeze *frz2 = (HeapTupleFreeze *) arg2;
const HeapTupleFreeze *frz1 = arg1;
const HeapTupleFreeze *frz2 = arg2;
if (frz1->xmax < frz2->xmax)
return -1;

View File

@@ -1462,8 +1462,8 @@ _bt_delitems_update(BTVacuumPosting *updatable, int nupdatable,
static int
_bt_delitems_cmp(const void *a, const void *b)
{
TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
const TM_IndexDelete *indexdelete1 = a;
const TM_IndexDelete *indexdelete2 = b;
Assert(indexdelete1->id != indexdelete2->id);

View File

@@ -1792,8 +1792,8 @@ _bt_unmark_keys(IndexScanDesc scan, int *keyDataMap)
static int
_bt_reorder_array_cmp(const void *a, const void *b)
{
BTArrayKeyInfo *arraya = (BTArrayKeyInfo *) a;
BTArrayKeyInfo *arrayb = (BTArrayKeyInfo *) b;
const BTArrayKeyInfo *arraya = a;
const BTArrayKeyInfo *arrayb = b;
return pg_cmp_s32(arraya->scan_key, arrayb->scan_key);
}

View File

@@ -594,8 +594,8 @@ _bt_deltasortsplits(FindSplitData *state, double fillfactormult,
static int
_bt_splitcmp(const void *arg1, const void *arg2)
{
SplitPoint *split1 = (SplitPoint *) arg1;
SplitPoint *split2 = (SplitPoint *) arg2;
const SplitPoint *split1 = arg1;
const SplitPoint *split2 = arg2;
return pg_cmp_s16(split1->curdelta, split2->curdelta);
}

View File

@@ -84,8 +84,8 @@ typedef struct SortedPoint
static int
x_cmp(const void *a, const void *b)
{
SortedPoint *pa = (SortedPoint *) a;
SortedPoint *pb = (SortedPoint *) b;
const SortedPoint *pa = a;
const SortedPoint *pb = b;
if (pa->p->x == pb->p->x)
return 0;
@@ -95,8 +95,8 @@ x_cmp(const void *a, const void *b)
static int
y_cmp(const void *a, const void *b)
{
SortedPoint *pa = (SortedPoint *) a;
SortedPoint *pb = (SortedPoint *) b;
const SortedPoint *pa = a;
const SortedPoint *pb = b;
if (pa->p->y == pb->p->y)
return 0;

View File

@@ -862,8 +862,8 @@ int
multi_sort_compare(const void *a, const void *b, void *arg)
{
MultiSortSupport mss = (MultiSortSupport) arg;
SortItem *ia = (SortItem *) a;
SortItem *ib = (SortItem *) b;
const SortItem *ia = a;
const SortItem *ib = b;
int i;
for (i = 0; i < mss->ndims; i++)

View File

@@ -402,8 +402,8 @@ count_distinct_groups(int numrows, SortItem *items, MultiSortSupport mss)
static int
compare_sort_item_count(const void *a, const void *b, void *arg)
{
SortItem *ia = (SortItem *) a;
SortItem *ib = (SortItem *) b;
const SortItem *ia = a;
const SortItem *ib = b;
if (ia->count == ib->count)
return 0;
@@ -465,8 +465,8 @@ static int
sort_item_compare(const void *a, const void *b, void *arg)
{
SortSupport ssup = (SortSupport) arg;
SortItem *ia = (SortItem *) a;
SortItem *ib = (SortItem *) b;
const SortItem *ia = a;
const SortItem *ib = b;
return ApplySortComparator(ia->values[0], ia->isnull[0],
ib->values[0], ib->isnull[0],

View File

@@ -210,8 +210,8 @@ cmpspellaffix(const void *s1, const void *s2)
static int
cmpcmdflag(const void *f1, const void *f2)
{
CompoundAffixFlag *fv1 = (CompoundAffixFlag *) f1,
*fv2 = (CompoundAffixFlag *) f2;
const CompoundAffixFlag *fv1 = f1;
const CompoundAffixFlag *fv2 = f2;
Assert(fv1->flagMode == fv2->flagMode);

View File

@@ -1729,9 +1729,9 @@ get_gist_range_class(RangeType *range)
static int
single_bound_cmp(const void *a, const void *b, void *arg)
{
SingleBoundSortItem *i1 = (SingleBoundSortItem *) a;
SingleBoundSortItem *i2 = (SingleBoundSortItem *) b;
TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
const SingleBoundSortItem *i1 = a;
const SingleBoundSortItem *i2 = b;
TypeCacheEntry *typcache = arg;
return range_cmp_bounds(typcache, &i1->bound, &i2->bound);
}
@@ -1742,9 +1742,9 @@ single_bound_cmp(const void *a, const void *b, void *arg)
static int
interval_cmp_lower(const void *a, const void *b, void *arg)
{
NonEmptyRange *i1 = (NonEmptyRange *) a;
NonEmptyRange *i2 = (NonEmptyRange *) b;
TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
const NonEmptyRange *i1 = a;
const NonEmptyRange *i2 = b;
TypeCacheEntry *typcache = arg;
return range_cmp_bounds(typcache, &i1->lower, &i2->lower);
}
@@ -1755,9 +1755,9 @@ interval_cmp_lower(const void *a, const void *b, void *arg)
static int
interval_cmp_upper(const void *a, const void *b, void *arg)
{
NonEmptyRange *i1 = (NonEmptyRange *) a;
NonEmptyRange *i2 = (NonEmptyRange *) b;
TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
const NonEmptyRange *i1 = a;
const NonEmptyRange *i2 = b;
TypeCacheEntry *typcache = arg;
return range_cmp_bounds(typcache, &i1->upper, &i2->upper);
}

View File

@@ -185,9 +185,9 @@ spg_range_quad_choose(PG_FUNCTION_ARGS)
static int
bound_cmp(const void *a, const void *b, void *arg)
{
RangeBound *ba = (RangeBound *) a;
RangeBound *bb = (RangeBound *) b;
TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
const RangeBound *ba = a;
const RangeBound *bb = b;
TypeCacheEntry *typcache = arg;
return range_cmp_bounds(typcache, ba, bb);
}

View File

@@ -111,9 +111,9 @@ float8_qsort_cmp(const void *a1, const void *a2, void *arg)
static int
range_bound_qsort_cmp(const void *a1, const void *a2, void *arg)
{
RangeBound *b1 = (RangeBound *) a1;
RangeBound *b2 = (RangeBound *) a2;
TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
const RangeBound *b1 = a1;
const RangeBound *b2 = a2;
TypeCacheEntry *typcache = arg;
return range_cmp_bounds(typcache, b1, b2);
}

View File

@@ -235,8 +235,8 @@ shared_record_table_compare(const void *a, const void *b, size_t size,
void *arg)
{
dsa_area *area = (dsa_area *) arg;
SharedRecordTableKey *k1 = (SharedRecordTableKey *) a;
SharedRecordTableKey *k2 = (SharedRecordTableKey *) b;
const SharedRecordTableKey *k1 = a;
const SharedRecordTableKey *k2 = b;
TupleDesc t1;
TupleDesc t2;
@@ -259,8 +259,8 @@ shared_record_table_compare(const void *a, const void *b, size_t size,
static uint32
shared_record_table_hash(const void *a, size_t size, void *arg)
{
dsa_area *area = (dsa_area *) arg;
SharedRecordTableKey *k = (SharedRecordTableKey *) a;
dsa_area *area = arg;
const SharedRecordTableKey *k = a;
TupleDesc t;
if (k->shared)
@@ -2013,7 +2013,7 @@ lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
static uint32
record_type_typmod_hash(const void *data, size_t size)
{
RecordCacheEntry *entry = (RecordCacheEntry *) data;
const RecordCacheEntry *entry = data;
return hashRowType(entry->tupdesc);
}
@@ -2024,8 +2024,8 @@ record_type_typmod_hash(const void *data, size_t size)
static int
record_type_typmod_compare(const void *a, const void *b, size_t size)
{
RecordCacheEntry *left = (RecordCacheEntry *) a;
RecordCacheEntry *right = (RecordCacheEntry *) b;
const RecordCacheEntry *left = a;
const RecordCacheEntry *right = b;
return equalRowTypes(left->tupdesc, right->tupdesc) ? 0 : 1;
}

View File

@@ -11102,7 +11102,7 @@ fetchAttributeStats(Archive *fout)
static char *
dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te)
{
const RelStatsInfo *rsinfo = (RelStatsInfo *) userArg;
const RelStatsInfo *rsinfo = userArg;
static PGresult *res;
static int rownum;
PQExpBuffer query;

View File

@@ -189,7 +189,7 @@ injection_init_shmem(void)
* otherwise.
*/
static bool
injection_point_allowed(InjectionPointCondition *condition)
injection_point_allowed(const InjectionPointCondition *condition)
{
bool result = true;
@@ -232,8 +232,8 @@ injection_points_cleanup(int code, Datum arg)
void
injection_error(const char *name, const void *private_data, void *arg)
{
InjectionPointCondition *condition = (InjectionPointCondition *) private_data;
char *argstr = (char *) arg;
const InjectionPointCondition *condition = private_data;
char *argstr = arg;
if (!injection_point_allowed(condition))
return;
@@ -248,8 +248,8 @@ injection_error(const char *name, const void *private_data, void *arg)
void
injection_notice(const char *name, const void *private_data, void *arg)
{
InjectionPointCondition *condition = (InjectionPointCondition *) private_data;
char *argstr = (char *) arg;
const InjectionPointCondition *condition = private_data;
char *argstr = arg;
if (!injection_point_allowed(condition))
return;
@@ -268,7 +268,7 @@ injection_wait(const char *name, const void *private_data, void *arg)
uint32 old_wait_counts = 0;
int index = -1;
uint32 injection_wait_event = 0;
InjectionPointCondition *condition = (InjectionPointCondition *) private_data;
const InjectionPointCondition *condition = private_data;
if (inj_state == NULL)
injection_init_shmem();