Re: More CppAsString2() in psql's describe.c - Mailing list pgsql-hackers

From Daniel Gustafsson
Subject Re: More CppAsString2() in psql's describe.c
Date
Msg-id B8C14F27-99B0-44BC-8380-2DA8AF671126@yesql.se
Whole thread Raw
In response to Re: More CppAsString2() in psql's describe.c  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
> On 2 Dec 2024, at 08:52, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> But isn't there a way to improve the macro so this'd lead to an error?

That sounds like a pretty decent improvement in general.  I experimented with
quick hack using a typeof check on the passed symbol which catches symbolname
typos. It might be totally unfit for purpose but it was an interesting hack.

#define CppAsString2(x) ((__builtin_types_compatible_p(__typeof__(x),char *) ?: CppAsString(x)))

It does require changing the any uses of the macro in string generation from
f("pre" CppAsString2(SYM) "post"); into f_v("pre%spost", CppAsString2(SYM));
however, and using it as part of another macro (TABLESPACE_VERSION_DIRECTORY)
doesn't work.

--
Daniel Gustafsson




pgsql-hackers by date:

Previous
From: Ilia Evdokimov
Date:
Subject: Re: Vacuum statistics
Next
From: Nazir Bilal Yavuz
Date:
Subject: Re: Using read stream in autoprewarm