pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedExample code bug: destination->data
2+ messages / 2 participants
[nested] [flat]
* Example code bug: destination->data
@ 2022-11-08 00:25 PG Doc comments form <noreply@postgresql.org>
0 siblings, 1 reply; 2+ messages in thread
From: PG Doc comments form @ 2022-11-08 00:25 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org; +Cc: ray.brinzer@gmail.com
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/15/xfunc-c.html
Description:
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.
--
Ray Brinzer
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Example code bug: destination->data
@ 2022-11-08 22:07 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Doc comments form <noreply@postgresql.org>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2022-11-08 22:07 UTC (permalink / raw)
To: ray.brinzer@gmail.com; +Cc: pgsql-docs@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2022-11-08 22:07 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 00:25 Example code bug: destination->data PG Doc comments form <noreply@postgresql.org>
2022-11-08 22:07 ` Re: Example code bug: destination->data Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox