Re: pstrdup(TextDatumGetCString(foo)) ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chapman Flack <chap(at)anastigmatix(dot)net>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pstrdup(TextDatumGetCString(foo)) ?
Date: 2016-03-10 04:07:24
Message-ID: 4779.1457582844@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chapman Flack <chap(at)anastigmatix(dot)net> writes:
> I am encountering, here and there, an idiom like
> pstrdup(TextDatumGetCString(foo))

> or a pre-8.4 version,

> pstrdup(DatumGetCString(DirectFunctionCall1(textout, foo)))

> It's leading me to question my sanity because it appears to me
> that both text_to_cstring (underlying TextDatumGetCString) and
> textout already return a string palloc'd in the current context,
> and that pstrdup (without any change of context) can't be accomplishing
> anything. I'm probably missing something crucial, but what?

No, you're right: pstrdup in that context is a useless waste of cycles and
memory.

A quick grep in the current PG sources shows me only two occurrences of
the former, both in the same function and both doubtless introduced by
the same misinformed author. I find no occurrences of the latter.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tsunakawa, Takayuki 2016-03-10 04:48:17 Re: [HACKERS] How can we expand PostgreSQL ecosystem?
Previous Message Chapman Flack 2016-03-10 03:46:10 pstrdup(TextDatumGetCString(foo)) ?