Re: Example code bug: destination->data

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Example code bug: destination->data
Дата
Msg-id 3868103.1667945245@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Example code bug: destination->data  (PG Doc comments form <noreply@postgresql.org>)
Список pgsql-docs
PG Doc comments form <noreply@postgresql.org> writes:
> 38.10.2. Base Types in C-Language Functions

> In the last example of the section, this line appears:
> memcpy(destination->data, buffer, 40);
> For me, this gave the following error:
> error: ‘text’ {aka ‘struct varlena’} has no member named ‘data’

> After tracking down the struct definition, I got the example working with: 
> destination->vl_dat instead.  I assume this is correct, and that the member
> name changed somewhere along the way.

Hmm.  It's correct by reference to the sample definition of struct
text just above ... but you're right that that has relatively little
to do with the definition we actually use nowadays.

However, referencing vl_dat[] isn't considered good style either
--- AFAICS there are exactly zero direct uses of that name.
The style actually used in the code is to rely on VARDATA() or
VARDATA_ANY(), as in the concat_text() example further down.

Maybe the best fix is to leave the example as it stands but add
a note that this is an oversimplified example?

            regards, tom lane



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

Предыдущее
От: PG Doc comments form
Дата:
Сообщение: Possibly Incorrect Data Return
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Possibly Incorrect Data Return