Re: Example code bug: destination->data - Mailing list pgsql-docs

From Tom Lane
Subject Re: Example code bug: destination->data
Date
Msg-id 3868103.1667945245@sss.pgh.pa.us
Whole thread Raw
In response to Example code bug: destination->data  (PG Doc comments form <noreply@postgresql.org>)
List 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 by date:

Previous
From: PG Doc comments form
Date:
Subject: Possibly Incorrect Data Return
Next
From: Tom Lane
Date:
Subject: Re: Possibly Incorrect Data Return