From 5497daf3aa2ae6ec9d5097f25c40627f8c801de8 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 16 Feb 2024 11:37:50 -0600 Subject: Replace calls to pg_qsort() with the qsort() macro. Calls to this function might give the impression that pg_qsort() is somehow different than qsort(), when in fact there is a qsort() macro in port.h that expands all in-tree uses to pg_qsort(). Reviewed-by: Mats Kindahl Discussion: https://postgr.es/m/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com --- src/backend/access/brin/brin_minmax_multi.c | 2 +- src/backend/optimizer/plan/analyzejoins.c | 4 ++-- src/backend/storage/buffer/bufmgr.c | 4 ++-- src/backend/utils/cache/syscache.c | 10 +++++----- src/include/port.h | 4 ++++ 5 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c index 3ffaad3e42d..2c29aa3d4ef 100644 --- a/src/backend/access/brin/brin_minmax_multi.c +++ b/src/backend/access/brin/brin_minmax_multi.c @@ -1369,7 +1369,7 @@ build_distances(FmgrInfo *distanceFn, Oid colloid, * Sort the distances in descending order, so that the longest gaps are at * the front. */ - pg_qsort(distances, ndistances, sizeof(DistanceValue), compare_distances); + qsort(distances, ndistances, sizeof(DistanceValue), compare_distances); return distances; } diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c index 7dcb74572ad..e494acd51a6 100644 --- a/src/backend/optimizer/plan/analyzejoins.c +++ b/src/backend/optimizer/plan/analyzejoins.c @@ -2307,8 +2307,8 @@ remove_self_joins_recurse(PlannerInfo *root, List *joinlist, Relids toRemove) j++; } - pg_qsort(candidates, numRels, sizeof(SelfJoinCandidate), - self_join_candidates_cmp); + qsort(candidates, numRels, sizeof(SelfJoinCandidate), + self_join_candidates_cmp); /* * Iteratively form a group of relation indexes with the same oid and diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index eb1ec3b86df..07575ef3129 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -3915,7 +3915,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators) /* sort the list of rlocators if necessary */ if (use_bsearch) - pg_qsort(locators, n, sizeof(RelFileLocator), rlocator_comparator); + qsort(locators, n, sizeof(RelFileLocator), rlocator_comparator); for (i = 0; i < NBuffers; i++) { @@ -4269,7 +4269,7 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels) /* sort the list of SMgrRelations if necessary */ if (use_bsearch) - pg_qsort(srels, nrels, sizeof(SMgrSortArray), rlocator_comparator); + qsort(srels, nrels, sizeof(SMgrSortArray), rlocator_comparator); for (i = 0; i < NBuffers; i++) { diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index 162855b1587..662f9308647 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -146,14 +146,14 @@ InitCatalogCache(void) Assert(SysCacheSupportingRelOidSize <= lengthof(SysCacheSupportingRelOid)); /* Sort and de-dup OID arrays, so we can use binary search. */ - pg_qsort(SysCacheRelationOid, SysCacheRelationOidSize, - sizeof(Oid), oid_compare); + qsort(SysCacheRelationOid, SysCacheRelationOidSize, + sizeof(Oid), oid_compare); SysCacheRelationOidSize = qunique(SysCacheRelationOid, SysCacheRelationOidSize, sizeof(Oid), oid_compare); - pg_qsort(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize, - sizeof(Oid), oid_compare); + qsort(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize, + sizeof(Oid), oid_compare); SysCacheSupportingRelOidSize = qunique(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize, sizeof(Oid), oid_compare); @@ -668,7 +668,7 @@ RelationSupportsSysCache(Oid relid) /* - * OID comparator for pg_qsort + * OID comparator for qsort */ static int oid_compare(const void *a, const void *b) diff --git a/src/include/port.h b/src/include/port.h index 263cf791a39..ae115d2d970 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -438,6 +438,10 @@ extern bool pg_get_user_name(uid_t user_id, char *buffer, size_t buflen); extern bool pg_get_user_home_dir(uid_t user_id, char *buffer, size_t buflen); #endif +/* + * Callers should use the qsort() macro defined below instead of calling + * pg_qsort() directly. + */ extern void pg_qsort(void *base, size_t nel, size_t elsize, int (*cmp) (const void *, const void *)); extern int pg_qsort_strcmp(const void *a, const void *b); -- cgit v1.2.3