Lists: | pgsql-hackers |
---|
From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-03 19:00:33 |
Message-ID: | 20171003190033.nsizxfnvgwx6frap@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
In my llvm jit work I'd to
#undef PM
/* include some llvm headers */
#define PM 1
because llvm has a number of functions which have an argument named PM.
Now that works, but it's fairly ugly. Perhaps it would be a good idea to
name these defines in a manner that's slightly less likely to conflict?
Alternatively we could use #pragma push_macro() around the includes, but
that'd be a new dependency.
Better ideas?
Greetings,
Andres Freund
From: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-03 20:34:38 |
Message-ID: | dd5a046d-1098-e128-2396-338e62605573@2ndQuadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 10/03/2017 03:00 PM, Andres Freund wrote:
> Hi,
>
> In my llvm jit work I'd to
>
> #undef PM
> /* include some llvm headers */
> #define PM 1
>
> because llvm has a number of functions which have an argument named PM.
> Now that works, but it's fairly ugly. Perhaps it would be a good idea to
> name these defines in a manner that's slightly less likely to conflict?
>
> Alternatively we could use #pragma push_macro() around the includes, but
> that'd be a new dependency.
>
> Better ideas?
>
AFAICT at a quick glance these are only used in a couple of files. Maybe
the defs need to be floated off to a different header with more limited
inclusion?
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-03 20:36:44 |
Message-ID: | 20171003203644.mhe74zwrouwxxfw4@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
On 2017-10-03 16:34:38 -0400, Andrew Dunstan wrote:
> On 10/03/2017 03:00 PM, Andres Freund wrote:
> > Hi,
> >
> > In my llvm jit work I'd to
> >
> > #undef PM
> > /* include some llvm headers */
> > #define PM 1
> >
> > because llvm has a number of functions which have an argument named PM.
> > Now that works, but it's fairly ugly. Perhaps it would be a good idea to
> > name these defines in a manner that's slightly less likely to conflict?
> >
> > Alternatively we could use #pragma push_macro() around the includes, but
> > that'd be a new dependency.
> >
> > Better ideas?
> AFAICT at a quick glance these are only used in a couple of files. Maybe
> the defs need to be floated off to a different header with more limited
> inclusion?
Why not just rename them to PG_PM etc? If we force potential external
users to do some changes, we can use more unique names just as well -
the effort to adapt won't be meaningfully higher... IMNSHO there's not
much excuse for defining macros like PM globally.
- Andres
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de> |
Cc: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-03 20:43:06 |
Message-ID: | 30609.1507063386@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Andres Freund <andres(at)anarazel(dot)de> writes:
> On 2017-10-03 16:34:38 -0400, Andrew Dunstan wrote:
>> AFAICT at a quick glance these are only used in a couple of files. Maybe
>> the defs need to be floated off to a different header with more limited
>> inclusion?
> Why not just rename them to PG_PM etc? If we force potential external
> users to do some changes, we can use more unique names just as well -
> the effort to adapt won't be meaningfully higher... IMNSHO there's not
> much excuse for defining macros like PM globally.
I like the new-header-file idea because it will result in minimal code
churn and thus minimal back-patching hazards.
I do *not* like "PG_PM". For our own purposes that adds no uniqueness
at all. If we're to touch these symbols then I'd go for names like
"DATETIME_PM". Or maybe "DT_PM" ... there's a little bit of precedent
for the DT_ prefix already.
regards, tom lane
From: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-03 22:24:38 |
Message-ID: | bd90cfc0-3b19-64bc-1504-d309f8311a34@2ndQuadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On 10/03/2017 04:43 PM, Tom Lane wrote:
> Andres Freund <andres(at)anarazel(dot)de> writes:
>> On 2017-10-03 16:34:38 -0400, Andrew Dunstan wrote:
>>> AFAICT at a quick glance these are only used in a couple of files. Maybe
>>> the defs need to be floated off to a different header with more limited
>>> inclusion?
>> Why not just rename them to PG_PM etc? If we force potential external
>> users to do some changes, we can use more unique names just as well -
>> the effort to adapt won't be meaningfully higher... IMNSHO there's not
>> much excuse for defining macros like PM globally.
> I like the new-header-file idea because it will result in minimal code
> churn and thus minimal back-patching hazards.
>
> I do *not* like "PG_PM". For our own purposes that adds no uniqueness
> at all. If we're to touch these symbols then I'd go for names like
> "DATETIME_PM". Or maybe "DT_PM" ... there's a little bit of precedent
> for the DT_ prefix already.
>
>
Yeah. If we use a prefix +1 for DT_. If we do that then I think they
should *all* be prefixed, not just the ones we know of conflicts for.
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-04 09:36:56 |
Message-ID: | 20171004093656.odwf7s7ihvacnzbq@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Andrew Dunstan wrote:
> On 10/03/2017 04:43 PM, Tom Lane wrote:
> > I like the new-header-file idea because it will result in minimal code
> > churn and thus minimal back-patching hazards.
> >
> > I do *not* like "PG_PM". For our own purposes that adds no uniqueness
> > at all. If we're to touch these symbols then I'd go for names like
> > "DATETIME_PM". Or maybe "DT_PM" ... there's a little bit of precedent
> > for the DT_ prefix already.
>
> Yeah. If we use a prefix +1 for DT_. If we do that then I think they
> should *all* be prefixed, not just the ones we know of conflicts for.
Maybe it'd be good idea to unify some of that stuff so that ecpg can use
it, too? Having a second copy of the same stuff in
src/interfaces/ecpg/pgtypeslib/dt.h is pretty terrible. Even if not,
let's make sure they don't diverge.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From: | Michael Meskes <meskes(at)postgresql(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-04 09:57:58 |
Message-ID: | 1507111078.2604.107.camel@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> Maybe it'd be good idea to unify some of that stuff so that ecpg can
> use
> it, too? Having a second copy of the same stuff in
> src/interfaces/ecpg/pgtypeslib/dt.h is pretty terrible. Even if not,
> let's make sure they don't diverge.
Please let's unify whatever we can. The fewer manual sync we need, the
better.
Michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Meskes at (Debian|Postgresql) dot Org
Jabber: michael at xmpp dot meskes dot org
VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Michael Meskes <meskes(at)postgresql(dot)org> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-04 14:05:47 |
Message-ID: | 32493.1507125947@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Michael Meskes <meskes(at)postgresql(dot)org> writes:
>> Maybe it'd be good idea to unify some of that stuff so that ecpg can
>> use it, too? Having a second copy of the same stuff in
>> src/interfaces/ecpg/pgtypeslib/dt.h is pretty terrible. Even if not,
>> let's make sure they don't diverge.
> Please let's unify whatever we can. The fewer manual sync we need, the
> better.
Isn't pgtypeslib/*.h exposed to ecpg-using applications?
regards, tom lane
From: | Michael Meskes <meskes(at)postgresql(dot)org> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: datetime.h defines like PM conflict with external libraries |
Date: | 2017-10-04 14:23:20 |
Message-ID: | 1507127000.2604.138.camel@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> Isn't pgtypeslib/*.h exposed to ecpg-using applications?
No, the public interface is is include/*.h, pgtypeslib/*.h is only
internal.
Michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Meskes at (Debian|Postgresql) dot Org
Jabber: michael at xmpp dot meskes dot org
VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL
From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, Michael Meskes <meskes(at)postgresql(dot)org> |
Subject: | Re: [HACKERS] datetime.h defines like PM conflict with external libraries |
Date: | 2018-01-29 21:05:31 |
Message-ID: | 20180129210531.qjbug6marzssc2rl@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
On 2017-10-04 11:36:56 +0200, Alvaro Herrera wrote:
> Andrew Dunstan wrote:
> > On 10/03/2017 04:43 PM, Tom Lane wrote:
> > > I like the new-header-file idea because it will result in minimal code
> > > churn and thus minimal back-patching hazards.
I'm not sure it's that little code churn, and the insulation isn't
great. Based on my WIP patch adding a DT_ prefix it would affect at
least:
contrib/adminpack/adminpack.c | 8 +-
src/backend/parser/gram.y | 52 ++++-----
src/backend/utils/adt/date.c | 50 ++++----
src/backend/utils/adt/datetime.c | 614 +++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------
src/backend/utils/adt/formatting.c | 10 +-
src/backend/utils/adt/json.c | 8 +-
src/backend/utils/adt/nabstime.c | 32 +++---
src/backend/utils/adt/timestamp.c | 196 +++++++++++++++----------------
src/backend/utils/adt/xml.c | 6 +-
src/backend/utils/misc/tzparser.c | 4 +-
src/bin/pg_waldump/compat.c | 6 +-
src/include/utils/datetime.h | 216 +++++++++++++++++------------------
so I'm not quite convinced this that well isolated pieces of code. I
wonder if just moving the defines around won't primarily increase pain.
I have however, for now, worked around the need to deal with this
problem (by moving more stuff .c files that are careful about their
includes). So this is more about historical raisins, I do not have an
urgent need to work on this.
> > > I do *not* like "PG_PM". For our own purposes that adds no uniqueness
> > > at all. If we're to touch these symbols then I'd go for names like
> > > "DATETIME_PM". Or maybe "DT_PM" ... there's a little bit of precedent
> > > for the DT_ prefix already.
> >
> > Yeah. If we use a prefix +1 for DT_. If we do that then I think they
> > should *all* be prefixed, not just the ones we know of conflicts for.
Attached is a WIP patch doing exactly this conversion for
datetime.h. Note that we'd want to do something about ecpg's dt.h if we
were to go for the approach.
While the changes are fairly verbose, they're also mechanical, so I
suspect the issues around backpatching - not that that code changes that
much - wouldn't be too hard to resolve.
> Maybe it'd be good idea to unify some of that stuff so that ecpg can use
> it, too? Having a second copy of the same stuff in
> src/interfaces/ecpg/pgtypeslib/dt.h is pretty terrible. Even if not,
> let's make sure they don't diverge.
I agree that that would be quite an advantage. It's more than just
datetime.h that'd need to be usable by ecpg. Luckily timestamp.h would
probably be easy,
commit a7801b62f21bd051444bd1119cd3745ecc8e14ec
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Date: 2011-09-09 13:23:41 -0400
Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h.
provides the basics. I suspect we'd want to do something very similar
for datetime?
I however wonder if even that would be really going far enough - we'd
still end up with a lot of copied functions:
int DecodeInterval(char **, int *, int, int *, struct tm *, fsec_t *);
int DecodeTime(char *, int *, struct tm *, fsec_t *);
void EncodeDateTime(struct tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str, bool EuroDates);
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str);
int tm2timestamp(struct tm *, fsec_t, int *, timestamp *);
int DecodeUnits(int field, char *lowtoken, int *val);
bool CheckDateTokenTables(void);
void EncodeDateOnly(struct tm *tm, int style, char *str, bool EuroDates);
int GetEpochTime(struct tm *);
int ParseDateTime(char *, char *, char **, int *, int *, char **);
int DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
void j2date(int, int *, int *, int *);
void GetCurrentDateTime(struct tm *);
int date2j(int, int, int);
void TrimTrailingZeros(char *);
void dt2time(double, int *, int *, int *, fsec_t *);
I suspect starting to implement infrastructure to deal with would be a
bit bigger a task than I can chew of right now though. Medium term, it
seems to me, we should start actually move a lot of the adt code into a
library that can be included (or possibly just compiled?) both by
frontend and backend code. Which kinda seems to imply we'd need
compatible elog support for frontend code, which I'd wished for many
times.
Michael, is there any problem including datatype/* headers in ecpg that
are frontend clean? I see no such usage so far, that's why I'm asking.
Greetings,
Andres Freund
Attachment | Content-Type | Size |
---|---|---|
0001-WIP-Deconflict-datetime.h-macro-names.patch | text/x-diff | 84.9 KB |
From: | Michael Meskes <meskes(at)postgresql(dot)org> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [HACKERS] datetime.h defines like PM conflict with external libraries |
Date: | 2018-01-30 08:31:44 |
Message-ID: | 1517301104.2778.66.camel@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> Michael, is there any problem including datatype/* headers in ecpg
> that
> are frontend clean? I see no such usage so far, that's why I'm
> asking.
When the pgtypes library was created we tried to include only the bits
and pieces needed to not create unnecessary hassles, but if it compiles
cleanly I'm fine either way. I'm assuming you're talking about
including the files for compiling ecpg, not as externally visible
header files, right?
michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Meskes at (Debian|Postgresql) dot Org
Jabber: michael at xmpp dot meskes dot org
VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL
From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de> |
Cc: | Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, Michael Meskes <meskes(at)postgresql(dot)org> |
Subject: | Re: [HACKERS] datetime.h defines like PM conflict with external libraries |
Date: | 2018-02-07 04:28:34 |
Message-ID: | 20180207042834.7fshnbh7jdoxc2aj@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Andres Freund wrote:
> Medium term, it
> seems to me, we should start actually move a lot of the adt code into a
> library that can be included (or possibly just compiled?) both by
> frontend and backend code. Which kinda seems to imply we'd need
> compatible elog support for frontend code, which I'd wished for many
> times.
I remember looking into moving this code into src/common/ a couple of
years ago, but the API was not identical in ecpg than backend mostly
because of the use of a few GUC vars, so I didn't finish it. In many
cases it seemed possible to resolve easily (just change hardcoded use of
a GUC in the function with a parameter), but I'm not sure it was the
case everywhere.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services