Thread: predefined macros for various BSD-based systems?

predefined macros for various BSD-based systems?

From
Tom Lane
Date:
The recently added contrib/pg_upgrade code contains this bit:
   /*    * scandir() is originally from BSD 4.3, which had the third argument as    * non-const. Linux and other C
librarieshave updated it to use a const.    *
http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2005-12/msg00214.html   *    * Here we try to guess which
libc'sneed const, and which don't. The net    * goal here is to try to suppress a compiler warning due to a prototype
* mismatch of const usage. Ideally we would do this via autoconf, but    * autoconf doesn't have a suitable builtin
testand it seems overkill    * to add one just to avoid a warning.    */
 
#elif defined(freebsd) || defined(bsdi) || defined(__darwin__) || defined(openbsd)   /* no const */   return
scandir(dirname,namelist, (int (*) (struct dirent *)) selector, NULL);
 
#else   /* use const */   return scandir(dirname, namelist, selector, NULL);

This drew my attention a couple days ago because it was picking the
wrong alternative on OS X, which was because the as-committed coding
was "defined(darwin)", which is not how that symbol is spelled.  I fixed
that, but I am now thinking that the other three checks are equally
tin-eared.  In particular, I see that buildfarm members ermine (FreeBSD)
and spoonbill (OpenBSD) are reporting warnings here, which proves that
those two platforms don't predefine "freebsd" or "openbsd" respectively.
Does anyone know if they define "__freebsd__" or "__freebsd" etc?

I'm not even too sure what "bsdi" is, but I'm suspicious of that branch
too.  A search of our code finds

contrib/pg_upgrade/file.c: 248: #elif defined(freebsd) || defined(bsdi) || defined(__darwin__) || defined(openbsd)
src/backend/utils/misc/ps_status.c: 67: #elif (defined(BSD) || defined(__bsdi__) || defined(__hurd__)) &&
!defined(__darwin__)
src/include/port.h: 355: #if defined(bsdi) || defined(netbsd)
src/port/fseeko.c: 20: #if defined(__bsdi__) || defined(__NetBSD__)
src/port/fseeko.c: 24: #ifdef bsdi
src/port/fseeko.c: 47: #ifdef bsdi
src/port/fseeko.c: 55: #ifdef bsdi
src/port/fseeko.c: 66: #ifdef bsdi
src/port/fseeko.c: 76: #ifdef bsdi
src/port/fseeko.c: 87: #ifdef bsdi

which leaves one with not a lot of warm fuzzies that we know how to
spell the symbol for either bsdi or netbsd.  (Oh, and shouldn't
this pg_upgrade check be looking for netbsd too?)

In the "darwin" case we aren't really making any assumptions,
because we actually define __darwin__ in port/darwin.h.

I suppose that at least some of the *BSD herd really do predefine some
of the symbols being attributed to them here, but I would like to see
something authoritative about which and what.
        regards, tom lane


Re: predefined macros for various BSD-based systems?

From
Robert Haas
Date:
On Sat, May 15, 2010 at 12:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I'm not even too sure what "bsdi" is, but I'm suspicious of that branch
> too.  A search of our code finds

It's a commercial distribution of BSD.  I remember it being pretty
nice when I used it 10+ years ago, but it sounds like it's dead now.
Too bad.

http://en.wikipedia.org/wiki/Berkeley_Software_Design

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


Re: predefined macros for various BSD-based systems?

From
Tom Lane
Date:
Robert Haas <robertmhaas@gmail.com> writes:
> On Sat, May 15, 2010 at 12:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I'm not even too sure what "bsdi" is, but I'm suspicious of that branch
>> too. �A search of our code finds

> It's a commercial distribution of BSD.  I remember it being pretty
> nice when I used it 10+ years ago, but it sounds like it's dead now.

Um ... so do you remember which symbol they predefined?  It's pretty
lame that we can't even spell it consistently in one source file.
(Or, if BSDI is so dead that no one remembers, shouldn't we rip out
those #if branches?)
        regards, tom lane


Re: predefined macros for various BSD-based systems?

From
Robert Haas
Date:
On Sat, May 15, 2010 at 12:37 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> On Sat, May 15, 2010 at 12:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> I'm not even too sure what "bsdi" is, but I'm suspicious of that branch
>>> too.  A search of our code finds
>
>> It's a commercial distribution of BSD.  I remember it being pretty
>> nice when I used it 10+ years ago, but it sounds like it's dead now.
>
> Um ... so do you remember which symbol they predefined?  It's pretty
> lame that we can't even spell it consistently in one source file.
> (Or, if BSDI is so dead that no one remembers, shouldn't we rip out
> those #if branches?)

No clue.  I agree.  (Yes.)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company


Re: predefined macros for various BSD-based systems?

From
Peter Eisentraut
Date:
On lör, 2010-05-15 at 00:15 -0400, Tom Lane wrote:
> I suppose that at least some of the *BSD herd really do predefine some
> of the symbols being attributed to them here, but I would like to see
> something authoritative about which and what.

http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/porting-versions.html



Re: predefined macros for various BSD-based systems?

From
Peter Eisentraut
Date:
On lör, 2010-05-15 at 00:23 -0400, Robert Haas wrote:
> It's a commercial distribution of BSD.  I remember it being pretty
> nice when I used it 10+ years ago, but it sounds like it's dead now.

BSDI is the company that produced BSD/OS, which was Bruce's main
development environment at some point, which is why it has left
excruciating traces all over the PostgreSQL source.



Re: predefined macros for various BSD-based systems?

From
Giles Lean
Date:
Tom Lane <tgl@sss.pgh.pa.us> wrote:

> I suppose that at least some of the *BSD herd really do predefine some
> of the symbols being attributed to them here, but I would like to see
> something authoritative about which and what.

Documentation follows, but first the summary:

FreeBSD: __FreeBSD__
NetBSD:  __NetBSD__
OpenBSD: __OpenBSD__

I believe those #defines also tell you what the release is.
I didn't look into their encoding schemes just now, but can if
you want.

(OS X aka Darwin is harder: they seem to like __APPLE__, but
to determine the OS version the best I can see is
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__, which is quite
horrid.)

Re BSDi, I have no idea really but based on Google searching
I'd bet on __bsdi__.

Per Wikipedia BSDi was discontinued in 2003 and support ended
in 2004.  I submit that anyone still using it is not likely to
be updating their PostgreSQL installation, so +1 from me for
dropping support for it unless a volunteer using it comes
forward.

FYI (and you may know this, but I didn't learn until recently)
GCC will tell you quite easily what #defines are predefined,
and all those platforms use gcc:
 $ cc -E -dM - < /dev/null | grep FreeBSD   #define __FreeBSD_cc_version 700003 #define __VERSION__ "4.2.1 20070719
[FreeBSD]"#define __FreeBSD__ 7
 

But you wanted something authoritative, so here's what I found:

FreeBSD
=======
 http://www.freebsd.org/doc/en/books/porters-handbook/porting-versions.html
 "__FreeBSD__ is defined in all versions of FreeBSD."

NetBSD
======

From the NetBSD-1.1 release notes (November, 1995):
 "* implement new cpp predefine strategy    define __NetBSD__, ..."

This is still the current behaviour, although the current
release is 5.0.2 from February 2010.

OpenBSD
=======
 http://www.openbsd.org/porting.html
 "Generic Porting Hints
   * __OpenBSD__ should be used sparingly, if at all. Constructs that     look like
    #if defined(__NetBSD__) || defined(__FreeBSD__)
     are often inappropriate. Don't add blindly __OpenBSD__ to     it. Instead, try to figure out what's going on, and
whatactual     feature is needed."
 

Regards,

Giles


Re: predefined macros for various BSD-based systems?

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> On l?r, 2010-05-15 at 00:23 -0400, Robert Haas wrote:
> > It's a commercial distribution of BSD.  I remember it being pretty
> > nice when I used it 10+ years ago, but it sounds like it's dead now.
> 
> BSDI is the company that produced BSD/OS, which was Bruce's main
> development environment at some point, which is why it has left
> excruciating traces all over the PostgreSQL source.

Uh, I still run BSDi.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com


Re: predefined macros for various BSD-based systems?

From
Andrew Dunstan
Date:

Bruce Momjian wrote:
> Peter Eisentraut wrote:
>   
>> On l?r, 2010-05-15 at 00:23 -0400, Robert Haas wrote:
>>     
>>> It's a commercial distribution of BSD.  I remember it being pretty
>>> nice when I used it 10+ years ago, but it sounds like it's dead now.
>>>       
>> BSDI is the company that produced BSD/OS, which was Bruce's main
>> development environment at some point, which is why it has left
>> excruciating traces all over the PostgreSQL source.
>>     
>
> Uh, I still run BSDi.
>
>   

That's more or less the OS equivalent of writing with a quill. :-)

cheers

andrew


Re: predefined macros for various BSD-based systems?

From
Bruce Momjian
Date:
Tom Lane wrote:
> I'm not even too sure what "bsdi" is, but I'm suspicious of that branch
> too.  A search of our code finds
> 
> contrib/pg_upgrade/file.c: 248: #elif defined(freebsd) || defined(bsdi) || defined(__darwin__) || defined(openbsd)
> src/backend/utils/misc/ps_status.c: 67: #elif (defined(BSD) || defined(__bsdi__) || defined(__hurd__)) &&
!defined(__darwin__)
> src/include/port.h: 355: #if defined(bsdi) || defined(netbsd)
> src/port/fseeko.c: 20: #if defined(__bsdi__) || defined(__NetBSD__)
> src/port/fseeko.c: 24: #ifdef bsdi
> src/port/fseeko.c: 47: #ifdef bsdi
> src/port/fseeko.c: 55: #ifdef bsdi
> src/port/fseeko.c: 66: #ifdef bsdi
> src/port/fseeko.c: 76: #ifdef bsdi
> src/port/fseeko.c: 87: #ifdef bsdi
> 
> which leaves one with not a lot of warm fuzzies that we know how to
> spell the symbol for either bsdi or netbsd.  (Oh, and shouldn't
> this pg_upgrade check be looking for netbsd too?)

BSDi defines "bsdi" and "__bsdi__", but our code was clearly
inconsistent.  I have changed all references to __bsdi__.

FYI, src/tools/ccsym will show you your predefined symbols.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com


Re: predefined macros for various BSD-based systems?

From
Bruce Momjian
Date:
Giles Lean wrote:
> 
> Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> > I suppose that at least some of the *BSD herd really do predefine some
> > of the symbols being attributed to them here, but I would like to see
> > something authoritative about which and what.
> 
> Documentation follows, but first the summary:
> 
> FreeBSD: __FreeBSD__
> NetBSD:  __NetBSD__
> OpenBSD: __OpenBSD__

Great.  I have updated pg_upgrade to use those defines.

--  Bruce Momjian  <bruce@momjian.us>        http://momjian.us EnterpriseDB
http://enterprisedb.com