Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2003 10:13:35 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        ben@timing.com
Cc:        freebsd-arch@FreeBSD.ORG
Subject:   Re: _REENTRANT in math.h & libm oddities.
Message-ID:  <20030123.101335.95024590.imp@bsdimp.com>
In-Reply-To: <15920.6175.737639.566519@piglet.timing.com>
References:  <15920.6175.737639.566519@piglet.timing.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.

:   I think the correct fix for this is to remove the #ifdef _REENTRANT
: from math.h . But perhaps it is there for a reason I am not cognizant
: of. If that is the case, wouldn't we be better served by using
: _THREAD_SAFE in FreeBSD?

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.

:   - add prototypes for gammaf_r & lgammaf_r to math.h

I'd add it as above.

:   - update the lgamma(3) man page to mention gamma_r, lgamma_r, gammaf_r,
:     and lgammaf_r

Safe.

Warner

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?20030123.101335.95024590.imp>