Text <-> C string

Поиск
Список
Период
Сортировка
От Brendan Jurd
Тема Text <-> C string
Дата
Msg-id 37ed240d0709211143v6c55bbebx2f1ffbe354208d8c@mail.gmail.com
обсуждение исходный текст
Ответы Re: Text <-> C string  (Gregory Stark <stark@enterprisedb.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: HOT is applied
Следующее
От: Tom Lane
Дата:
Сообщение: Re: HOT is applied