freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: Sam Denton <denton AT wantec.com>
- To: 'TDS Development Group' <freetds AT franklin.oit.unc.edu>
- Subject: Re: Patches
- Date: Thu, 27 Jun 2002 12:14:21 -0500
Since the *_r funcs pretty much require _REENTRANT to be #defined, I'd key
everything off of that. Plus, I don't see a problem with using the
lowercase versions of the names for the macros, since that avoids the
problem of someone later using a non-safe function without realizing it.
Here's my suggestion (and James, you had a semi-colon problem that I've also
fixed):
#ifdef _REENTRANT
/*
* Requires "THREAD_SAFE_BUFFER" appear
* among caller's automatic variables
*/
# define THREAD_SAFE_BUFFER struct tm tsb_tm /* et. al. */
# define localtime(x) localtime_r(x, &tsb_tm)
#else
/*
* Appearance of "THREAD_SAFE_BUFFER"
* among caller's automatic variables
* has no effect.
*/
# define THREAD_SAFE_BUFFER 0
#endif
Finally, here's a little Perl script that looks for all of the
non-thread-safe functions (at least the ones that I know of!):
#!/usr/bin/perl
# Scans a file for the names of non-thread-safe functions.
# Use it with something like this to scan a project:
# find . -name \*.c -print | xargs unsafe.pl
# The following all have an associated _r version in Solaris.
@unsafe = qw( getauclassent getauclassnam getauevent getauevnam
getauevnum asctime ctime fgetgrent fgetpwent fgetspent getgrent
getgrgid getgrnam getlogin getpwent getpwnam getpwuid getspent getspnam
gmtime localtime rand readdir strtok ttyname gamma lgamma gethostbyaddr
gethostbyname gethostent getnetbyaddr getnetbyname getnetent
getnetgrent getprotobyname getprotobynumber getprotoent getrpcbyname
getrpcbynumber getrpcent getservbyname getservbyport getservent
nis_sperror ctermid tmpnam );
$pat = join("|", map { "\\b$_\\b" } @unsafe);
while (<>) {
print "$ARGV\t$.\t$_" if /$pat/o;
} continue {
close ARGV if eof; # Not eof()!
}
__END__
Sam Denton, WAN Technologies, Inc.
(314) 428-0888 / (800) 926-7771 Main Office
-----Original Message-----
From: Lowden, James K [mailto:LowdenJK AT bernstein.com]
Sent: Thursday, June 27, 2002 11:06 AM
To: TDS Development Group
Subject: [freetds] Re: Patches
> From: Brian Bruns [mailto:camber AT ais.org]
> Sent: June 26, 2002 10:07 PM
>
> This gets into a sticky situation, older unices will not have the _r
> versions of the calls, so we should be checking via autoconf
> for their
> existence and using only then. So, something like
>
> #if HAVE_LOCALTIME_R
> tm = localtime_r(&t, &res);
> #else
> tm = localtime(&t);
> #endif
>
> and in configure.in adding:
>
> AC_CHECK_FUNCS(localtime_r)
>
> Otherwise, I'm all for this one going in.
Brian,
Rather than sprinkling #if pixie dust over src/tds/*.c, could we localize it
in a header file, say, tds.h.in? At the risk of reinventing the wheel:
#if HAVE_LOCALTIME_R
/*
* Requires "THREAD_SAFE_BUFFER" appear
* among caller's automatic variables
*/
#define THREAD_SAFE_BUFFER struct tm tsb_tm; /* et. al. */
#define LOCALTIME(x) localtime_r(x, &tsb_tm)
#else
/*
* Appearance of "THREAD_SAFE_BUFFER"
* among caller's automatic variables
* has no effect.
*/
#define THREAD_SAFE_BUFFER 0
#define LOCALTIME(x) localtime(x)
#endif
That way, a function that wants localtime need only say LOCALTIME instead.
If the function does not declare a THREAD_SAFE_BUFFER, it won't compile.
(Personally, I would call the macro "Localtime" instead of "LOCALTIME", but
I fear that might offend some sensibilities.)
Also, do you think there needs to be a way to force nonthreadedness for
broken thread implementations?
Stan, thanks for the patch. Even if the patch has to be patched, the fact
that you got it to work makes it a useful reference.
OT. Isn't there a notion unix thread theory of associating heap-allocated
storage with a thread? I'm surprised localtime can't be made thread-safe
without changing its signature.
Regards,
--jkl
---
You are currently subscribed to freetds as: [denton AT wantec.com]
To unsubscribe, forward this message to
$subst('Email.Unsub')
-
Patches,
Stan Liberman, 06/26/2002
- <Possible follow-up(s)>
- Re: Patches, Brian Bruns, 06/26/2002
- Re: Patches, ZIGLIO Frediano, 06/27/2002
- Re: Patches, Stan Liberman, 06/27/2002
- Re: Patches, Stan Liberman, 06/27/2002
- Re: Patches, Lowden, James K, 06/27/2002
- Re: Patches, Sam Denton, 06/27/2002
- Re: Patches, Lowden, James K, 06/27/2002
- Re: Patches, Brian Bruns, 06/27/2002
Archive powered by MHonArc 2.6.24.