Re: Remove some useless casts to (void *)

2023-02-06 Thread Peter Eisentraut

On 03.02.23 00:59, Corey Huinker wrote:
On Thu, Feb 2, 2023 at 5:22 PM Peter Eisentraut 
> wrote:


I have found that in some corners of the code some calls to standard C
functions are decorated with casts to (void *) for no reason, and this
code pattern then gets copied around.  I have gone through and cleaned
this up a bit, in the attached patches.

The involved functions are: repalloc, memcpy, memset, memmove, memcmp,
qsort, bsearch

Also hash_search(), for which there was a historical reason (the
argument used to be char *), but not anymore.


+1


committed


All code is example code.


I like that one!





Re: Remove some useless casts to (void *)

2023-02-02 Thread Corey Huinker
On Thu, Feb 2, 2023 at 5:22 PM Peter Eisentraut <
peter.eisentr...@enterprisedb.com> wrote:

> I have found that in some corners of the code some calls to standard C
> functions are decorated with casts to (void *) for no reason, and this
> code pattern then gets copied around.  I have gone through and cleaned
> this up a bit, in the attached patches.
>
> The involved functions are: repalloc, memcpy, memset, memmove, memcmp,
> qsort, bsearch
>
> Also hash_search(), for which there was a historical reason (the
> argument used to be char *), but not anymore.


+1

All code is example code.

Applies.
Passes make check world.


Remove some useless casts to (void *)

2023-02-02 Thread Peter Eisentraut
I have found that in some corners of the code some calls to standard C 
functions are decorated with casts to (void *) for no reason, and this 
code pattern then gets copied around.  I have gone through and cleaned 
this up a bit, in the attached patches.


The involved functions are: repalloc, memcpy, memset, memmove, memcmp, 
qsort, bsearch


Also hash_search(), for which there was a historical reason (the 
argument used to be char *), but not anymore.From b4f050d23761187e05576cfbe8277b593d9c19fb Mon Sep 17 00:00:00 2001
From: Peter Eisentraut 
Date: Thu, 2 Feb 2023 23:02:34 +0100
Subject: [PATCH 1/8] Remove useless casts to (void *) (hash_search)

Some of these appear to be leftovers from when hash_search took a char
* argument (changed in 5999e78fc45dcb91784b64b6e9ae43f4e4f68ca2).
---
 contrib/postgres_fdw/shippable.c  |  6 +--
 src/backend/access/gist/gistbuild.c   |  4 +-
 src/backend/access/gist/gistbuildbuffers.c|  2 +-
 src/backend/access/transam/xlogutils.c|  6 +--
 src/backend/catalog/storage.c |  4 +-
 src/backend/optimizer/util/predtest.c |  2 +-
 src/backend/parser/parse_oper.c   |  6 +--
 src/backend/replication/logical/relation.c|  6 +--
 .../replication/logical/reorderbuffer.c   | 16 +++---
 src/backend/replication/pgoutput/pgoutput.c   |  2 +-
 src/backend/storage/buffer/buf_table.c|  6 +--
 src/backend/storage/buffer/bufmgr.c   |  8 +--
 src/backend/storage/buffer/localbuf.c | 12 ++---
 src/backend/storage/lmgr/lock.c   | 50 +--
 src/backend/storage/smgr/smgr.c   |  6 +--
 src/backend/storage/sync/sync.c   |  4 +-
 src/backend/tsearch/ts_typanalyze.c   |  4 +-
 src/backend/utils/adt/array_typanalyze.c  |  4 +-
 src/backend/utils/adt/ri_triggers.c   |  8 +--
 src/backend/utils/cache/attoptcache.c |  6 +--
 src/backend/utils/cache/relcache.c| 12 ++---
 src/backend/utils/cache/relfilenumbermap.c|  6 +--
 src/backend/utils/cache/spccache.c|  6 +--
 src/backend/utils/cache/ts_cache.c| 12 ++---
 src/backend/utils/cache/typcache.c|  8 +--
 src/backend/utils/time/combocid.c |  2 +-
 src/pl/plpgsql/src/pl_comp.c  |  6 +--
 src/pl/plpgsql/src/pl_exec.c  |  2 +-
 28 files changed, 108 insertions(+), 108 deletions(-)

diff --git a/contrib/postgres_fdw/shippable.c b/contrib/postgres_fdw/shippable.c
index 1b47a30dbf..a500b90390 100644
--- a/contrib/postgres_fdw/shippable.c
+++ b/contrib/postgres_fdw/shippable.c
@@ -77,7 +77,7 @@ InvalidateShippableCacheCallback(Datum arg, int cacheid, 
uint32 hashvalue)
while ((entry = (ShippableCacheEntry *) hash_seq_search()) != 
NULL)
{
if (hash_search(ShippableCacheHash,
-   (void *) >key,
+   >key,
HASH_REMOVE,
NULL) == NULL)
elog(ERROR, "hash table corrupted");
@@ -184,7 +184,7 @@ is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo 
*fpinfo)
/* See if we already cached the result. */
entry = (ShippableCacheEntry *)
hash_search(ShippableCacheHash,
-   (void *) ,
+   ,
HASH_FIND,
NULL);
 
@@ -200,7 +200,7 @@ is_shippable(Oid objectId, Oid classId, PgFdwRelationInfo 
*fpinfo)
 */
entry = (ShippableCacheEntry *)
hash_search(ShippableCacheHash,
-   (void *) ,
+   ,
HASH_ENTER,
NULL);
 
diff --git a/src/backend/access/gist/gistbuild.c 
b/src/backend/access/gist/gistbuild.c
index d21a308d41..7a6d93bb87 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -1587,7 +1587,7 @@ gistMemorizeParent(GISTBuildState *buildstate, 
BlockNumber child, BlockNumber pa
boolfound;
 
entry = (ParentMapEntry *) hash_search(buildstate->parentMap,
-   
   (const void *) ,
+   
   ,

   HASH_ENTER,

   );
entry->parentblkno = parent;
@@ -1625,7 +1625,7 @@ gistGetParent(GISTBuildState *buildstate, BlockNumber 
child)
 
/* Find node buffer in hash