Re: Syntax for partitioning

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nikhil Sontakke <nikhil(dot)sontakke(at)enterprisedb(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Syntax for partitioning
Date: 2009-11-20 06:19:06
Message-ID: 15531.1258697946@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Nikhil Sontakke <nikhil(dot)sontakke(at)enterprisedb(dot)com> writes:
>>> partinfo = (PartitionInfo *) malloc(ntups * sizeof(PartitionInfo));
>>
>> 1) Please stop casting the results of palloc and malloc. We are not
>> writing C++ here.

> I thought it was/is a good C programming practice to typecast (void *)
> always to the returning structure type!!

Yes. The above is good style because it ensures that the variable
you're assigning the pointer to is the right type to match the sizeof
computation. In C++ you'd use operator new instead and still have that
type-check without the cast, but indeed we are not writing C++ here.

The *real* bug in the quoted code is that it's using malloc. There are
a few places in PG where it's appropriate to use malloc not palloc, but
pretty darn few.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2009-11-20 06:25:59 Re: Summary and Plan for Hot Standby
Previous Message Tom Lane 2009-11-20 06:12:38 Re: Why do OLD and NEW have special internal names?