public inbox for [email protected]  
help / color / mirror / Atom feed
From: Chao Li <[email protected]>
To: Peter Eisentraut <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: get rid of Pointer type, mostly
Date: Mon, 24 Nov 2025 20:03:22 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>



> On Nov 24, 2025, at 18:20, Peter Eisentraut <[email protected]> wrote:
> 
> In a previous thread[0], the question was asked, 'Why do we bother with a "Pointer" type?'.  So I looked into get rid of it.
> 
> There are two stages to this.  One is changing all code that wants to do pointer arithmetic to use char * instead of relying on Pointer being char *.  Then we can change Pointer to be void * and remove a bunch of casts.
> 
> The second is getting rid of uses of Pointer for variables where you might as well use void * directly.  These are actually not that many.
> 
> This gets rid of all uses, except in the GIN code, which is full of Pointer use, and it's part of the documented API.  I'm not touching that, not least because this kind of code
> 
>    Pointer   **extra_data = (Pointer **) PG_GETARG_POINTER(4);
> 
> needs more brain-bending to understand that I'm prepared to spend.  So as far as I'm concerned, the pointer type can continue to exist as a curiosity of the GIN API, but in all other places, it wasn't really doing much of anything anyway.
> 
> 
> [0]: https://www.postgresql.org/message-id/CA%2BhUKG%2BNFKnr%3DK4oybwDvT35dW%3DVAjAAfiuLxp%2B5JeZSOV3nBg%...;

0001 - Removed type cast from memcpy(), which should be safe, as memcpy doesn’t care about types of source and dest pointers referring to, type casting is redundant.

0002 - Changed DatumGetPointer() to DatumGetCString() for %s. Basically, DatumGetPointer() returns a void * pointer and DatumGetCString() returns a char * pointers, but they return the same addresses, thus DatumGetCString() better fits %s.

0003 - Changed type casting from Pointer to char *. Now, Pointer is a typedef of char *, so the replacement is safe. In generic_desc(), Pointer is replaced with const char *, which should be safe also.

0004 - Changed typedef of Pointer from char * to void *. I guess the purpose is to let compiler alter for missed usages of Pointer.

0005/0006 - Removed all usages of Pointer expect in Gin code.

All look good. Only things is that, as Pointer is changed from char * to void *, and Gin code are still using Pointer, so these is a change for Gin code. But I don’t think that would impact runtime, as long as build passes, that should be fine. Build passed on my MacBook M4. If there is a breakage, build farm should be able to catch the error.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









view thread (23+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: get rid of Pointer type, mostly
  In-Reply-To: <[email protected]>

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

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