Text <-> C string - Mailing list pgsql-hackers

From Brendan Jurd
Subject Text <-> C string
Date
Msg-id 37ed240d0709211143v6c55bbebx2f1ffbe354208d8c@mail.gmail.com
Whole thread Raw
Responses Re: Text <-> C string
List pgsql-hackers
Hi hackers,

I've noticed that there is a lot of code, particularly in src/backend,
that goes through the motions of making a text datum into a cstring to
perform some work on it, and likewise for making a cstring into a text
datum.

Is there not a nice macro somewhere to handle this consistently?  And
if not, shouldn't there be?

I noticed a comment for StrNCpy() in src/include/c.h that seems related:

/* BTW: when you need to copy a non-null-terminated string (like a
text datum) and add a null, do not do it with StrNCpy [snip] Do it
honestly with "memcpy(dst,src,len); dst[len] = '\0'; instead."

Okay, I can see why using StrNCpy is a bad idea, but why not "Do it
honestly with TEXT_CSTRING(src, dst)", or similar?

Surely having the exact same four lines of code written out in dozens
of places is a Bad Thing, but perhaps there is some reasoning behind
this that I am missing?

Thanks for your time,
BJ


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: HOT is applied
Next
From: Tom Lane
Date:
Subject: Re: HOT is applied