> 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%40mail.gmail.com<0001-Remove-useless-casts-to-Pointer.patch><0002-Use-better-DatumGet-function.patch><0003-Don-t-rely-on-pointer-arithmetic-with-Pointer-type.patch><0004-Change-Pointer-to-void.patch><0005-Remove-no-longer-needed-casts-to-Pointer.patch><0006-Remove-some-uses-of-the-Pointer-type.patch>

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/






Reply via email to