Re: Example code bug: destination->data

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ray(dot)brinzer(at)gmail(dot)com
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Example code bug: destination->data
Date: 2022-11-08 22:07:25
Message-ID: 3868103.1667945245@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

PG Doc comments form <noreply(at)postgresql(dot)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

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2022-11-08 22:22:24 Re: Possibly Incorrect Data Return
Previous Message PG Doc comments form 2022-11-08 21:31:15 Possibly Incorrect Data Return