pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Geier <geidav.pg@gmail.com>
To: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Add explicit casts in four places to simplehash.h
Date: Thu, 3 Nov 2022 12:34:41 +0100
Message-ID: <aa5d88a3-71f4-3455-11cf-82de0372c941@gmail.com> (raw)

Hi hackers,

While working on an extension, I found that simplehash.h is missing 
explicit casts in four places. Without these casts, compiling code 
including simplehash.h yields warnings if the code is compiled with 
-Wc++-compat.

PostgreSQL seems to mostly prefer omitting the explicit casts, however 
there are many places where an explicit cast is actually used. Among 
many others, see e.g.

bool.c:
     state = (BoolAggState *) MemoryContextAlloc(agg_context, 
sizeof(BoolAggState));

domains.c:
    my_extra = (DomainIOData *) MemoryContextAlloc(mcxt, 
sizeof(DomainIOData));

What about, while not being strictly necessary for PostgreSQL itself, 
also adding such casts to simplehash.h so that it can be used in code 
where -Wc++-compat is enabled?

Attached is a small patch that adds the aforementioned casts.
Thanks for your consideration!

--
David Geier
(ServiceNow)

Attachments:

0001-Add-explicit-casts-to-simplehash.h.patch (text/x-patch, 1.8K) download From d2665b4065227ffa6efd37ee912e4add082869cb Mon Sep 17 00:00:00 2001 From: David Geier <geidav.pg@gmail.com> Date: Thu, 3 Nov 2022 12:28:08 +0100 Subject: [PATCH] Add explicit casts to simplehash.h Without these casts compilation yields warnings when compiling the code with -Wc++-compat. --- src/include/lib/simplehash.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/lib/simplehash.h b/src/include/lib/simplehash.h index 329687c1a5..cdfae537a1 100644 --- a/src/include/lib/simplehash.h +++ b/src/include/lib/simplehash.h @@ -438,7 +438,7 @@ SH_CREATE(MemoryContext ctx, uint32 nelements, void *private_data) #ifdef SH_RAW_ALLOCATOR tb = SH_RAW_ALLOCATOR(sizeof(SH_TYPE)); #else - tb = MemoryContextAllocZero(ctx, sizeof(SH_TYPE)); + tb = (SH_TYPE *) MemoryContextAllocZero(ctx, sizeof(SH_TYPE)); tb->ctx = ctx; #endif tb->private_data = private_data; @@ -448,7 +448,7 @@ SH_CREATE(MemoryContext ctx, uint32 nelements, void *private_data) SH_COMPUTE_PARAMETERS(tb, size); - tb->data = SH_ALLOCATE(tb, sizeof(SH_ELEMENT_TYPE) * tb->size); + tb->data = (SH_ELEMENT_TYPE *) SH_ALLOCATE(tb, sizeof(SH_ELEMENT_TYPE) * tb->size); return tb; } @@ -493,7 +493,7 @@ SH_GROW(SH_TYPE * tb, uint64 newsize) /* compute parameters for new table */ SH_COMPUTE_PARAMETERS(tb, newsize); - tb->data = SH_ALLOCATE(tb, sizeof(SH_ELEMENT_TYPE) * tb->size); + tb->data = (SH_ELEMENT_TYPE *) SH_ALLOCATE(tb, sizeof(SH_ELEMENT_TYPE) * tb->size); newdata = tb->data; @@ -1059,7 +1059,7 @@ SH_STAT(SH_TYPE * tb) double fillfactor; uint32 i; - uint32 *collisions = palloc0(tb->size * sizeof(uint32)); + uint32 *collisions = (uint32 *) palloc0(tb->size * sizeof(uint32)); uint32 total_collisions = 0; uint32 max_collisions = 0; double avg_collisions; -- 2.34.1

view thread (4+ messages)  latest in thread

Message-ID: <aa5d88a3-71f4-3455-11cf-82de0372c941@gmail.com>
Permalink:  ../aa5d88a3-71f4-3455-11cf-82de0372c941@gmail.com/
Also on:    postgresql.org/message-id/aa5d88a3-71f4-3455-11cf-82de0372c941@gmail.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: geidav.pg@gmail.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Add explicit casts in four places to simplehash.h
  In-Reply-To: <aa5d88a3-71f4-3455-11cf-82de0372c941@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox