Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2003 16:06:40 -0500 (EST)
From:      Daniel Eischen <eischen@pcnet1.pcnet.com>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        ben@timing.com, freebsd-arch@FreeBSD.ORG
Subject:   Re: _REENTRANT in math.h & libm oddities.
Message-ID:  <Pine.GSO.4.10.10301231601440.12720-100000@pcnet1.pcnet.com>
In-Reply-To: <20030123.101335.95024590.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 23 Jan 2003, M. Warner Losh wrote:
> In message: <15920.6175.737639.566519@piglet.timing.com>
>             Ben Mesander <ben@timing.com> writes:
> :   Recently while working on some threading issues I noticed an oddity
> : in /usr/include/math.h : the definitions of two functions, gamma_r and
> : lgamma_r, are protected with #ifdef _REENTRANT .  I suspect this is a
> : historical artifact, as the FreeBSD manpage for gcc indicates that
> : -D_THREAD_SAFE is the proper way to indicate that you are compiling
> : threaded code on FreeBSD.
> 
> The #ifdef in math.h is way historical:
> 
> 1.1          (jkh      19-Aug-94): #ifdef _REENTRANT
> 1.12         (obrien   21-Mar-02): double       gamma_r(double, int *);
> 1.12         (obrien   21-Mar-02): double       lgamma_r(double, int *);
> 1.1          (jkh      19-Aug-94): #endif /* _REENTRANT */
> 
> Since Sun donated this stuff to BSD back in 1993, I suspect that it
> comes from Solaris' -D_REENTRANT stuff that was/is done for threaded
> programs.

The gcc manpage is wrong.  It should state _REENTRANT instead of
_THREAD_SAFE.  POSIX specifies that _REENTRANT be defined to get
these functions.  I know that we always provide implementations
of most of these _r functions so it might not make sense to
#ifdef them in the header files, but I don't know that always
making them visible would be against the spec or cause namespace
pollution.

> I can see no harm in just removing the ifdef.  However, a quick survey
> of the header files shows that a number of the _r functions have ifdef
> protection for namespace pollution.  One of the standard's wonks will
> have to tell us for sure which standard(s) these comply to.  The
> functions generally don't have an ifdef _THREAD_SAFE around them.
> 
> :  Also note that there are reentrant API's available for gammaf &
> lgamma: : gammaf_r and lgammaf_r, but there are no prototypes for
> these in : math.h. Additionally, there is no mention of the four
> functions : gamma_r, lgamma_r, gammaf_r, and lgammaf_r on the
> lgamma(3) man page.
> 
> This is likely also an issue.
> :   Is it worthwhile to work up a patch to:
> :   - remove _REENTRANT from math.h (and replace with _THREAD_SAFE if
> :     people think that is appropriate)
> 
> I'd remove it completely, unless the standard's wonks think some name
> space pollution avoiding typedef is necessary.

I'd tend to leave them in.  We're not violating the spec by
leaving them in, but may be by removing them.

-- 
Dan Eischen


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10301231601440.12720-100000>