Maybe we can remove the type cast in typecache.c

Started by qinghao huangabout 3 years ago2 messageshackers
Jump to latest
#1qinghao huang
wfnuser@hotmail.com

Hi hackers,
When I was reading postgres code, I found there is a wierd type cast. I'm pondering if it is necessary.

```
/* Allocate a new typmod number. This will be wasted if we error out. */
typmod = (int)
pg_atomic_fetch_add_u32(&CurrentSession->shared_typmod_registry->next_typmod,
1);

```
typmod has u32 type, but we cast it to int first.

And I also have some confusion about why `NextRecordTypmod` and `TupleDescData.tdtypmod` has type of int32, but `SharedTypmodTableEntry.typmod` has type of uint32.

Best regard,
Qinghao Huang

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: qinghao huang (#1)
Re: Maybe we can remove the type cast in typecache.c

qinghao huang <wfnuser@hotmail.com> writes:

When I was reading postgres code, I found there is a wierd type cast. I'm pondering if it is necessary.

```
/* Allocate a new typmod number. This will be wasted if we error out. */
typmod = (int)
pg_atomic_fetch_add_u32(&CurrentSession->shared_typmod_registry->next_typmod,
1);

```
typmod has u32 type, but we cast it to int first.

typmods really ought to be int32, not uint32, so IMO none of this is
exactly right. But it's also true that it makes no real difference.
Postgres pretty much assumes that "int" is 32 bits.

regards, tom lane