Re: Syntax for partitioning

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Syntax for partitioning
Дата
Msg-id 15531.1258697946@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Syntax for partitioning  (Nikhil Sontakke <nikhil.sontakke@enterprisedb.com>)
Список pgsql-hackers
Nikhil Sontakke <nikhil.sontakke@enterprisedb.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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Stefan Kaltenbrunner
Дата:
Сообщение: Re: Summary and Plan for Hot Standby
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Summary and Plan for Hot Standby