pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedinappropriate use of NameGetDatum macro
3+ messages / 2 participants
[nested] [flat]
* inappropriate use of NameGetDatum macro
@ 2016-09-12 19:39 Mark Dilger <hornschnorter@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Mark Dilger @ 2016-09-12 19:39 UTC (permalink / raw)
To: pgsql-hackers
Friends,
there are several places in the code where variables defined as
(char *) or as (const char *) are passed to the NameGetDatum()
macro. I believe it would be better form to use CStringGetDatum()
in these locations. I am aware that these two macros are internally
the same.
src/backend/commands/proclang.c, line 466.
src/backend/commands/dbcommands.c, lines 1263, 1489, 1606, 1746.
Am I overlooking some reason why the code is correct as is? If not,
I am attaching a patch that applies cleanly for me against master,
compiles, and passes the regression tests.
Thanks,
Mark Dilger
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments:
NameGetDatum.patch.1 (application/octet-stream, 2.1K) download
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: inappropriate use of NameGetDatum macro
@ 2016-09-12 19:55 Tom Lane <tgl@sss.pgh.pa.us>
parent: Mark Dilger <hornschnorter@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2016-09-12 19:55 UTC (permalink / raw)
To: Mark Dilger <hornschnorter@gmail.com>; +Cc: pgsql-hackers
Mark Dilger <hornschnorter@gmail.com> writes:
> there are several places in the code where variables defined as
> (char *) or as (const char *) are passed to the NameGetDatum()
> macro. I believe it would be better form to use CStringGetDatum()
> in these locations. I am aware that these two macros are internally
> the same.
Hm, I agree, this feels wrong. I suppose you could argue that the
called functions are expecting Name pointers not CString pointers,
but that type cheat is happening anyway. It would be better form
to explicitly pass a CString datum if that's what we're passing.
I'm tempted to propose that we redefine NameGetDatum as
#define NameGetDatum(X) CStringGetDatum(NameStr(*(X)))
which should do the same thing at runtime, but would result in a
compile error if what's passed isn't declared as Name (or NameData*).
This would be asymmetrical with the way DatumGetName looks, though.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: inappropriate use of NameGetDatum macro
@ 2016-09-13 21:18 Tom Lane <tgl@sss.pgh.pa.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2016-09-13 21:18 UTC (permalink / raw)
To: Mark Dilger <hornschnorter@gmail.com>; +Cc: pgsql-hackers
I wrote:
> Mark Dilger <hornschnorter@gmail.com> writes:
>> there are several places in the code where variables defined as
>> (char *) or as (const char *) are passed to the NameGetDatum()
>> macro. I believe it would be better form to use CStringGetDatum()
>> in these locations. I am aware that these two macros are internally
>> the same.
> I'm tempted to propose that we redefine NameGetDatum as
> #define NameGetDatum(X) CStringGetDatum(NameStr(*(X)))
Pushed with that change.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2016-09-13 21:18 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-12 19:39 inappropriate use of NameGetDatum macro Mark Dilger <hornschnorter@gmail.com>
2016-09-12 19:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-13 21:18 ` 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