From: | Lee Kindness <lkindness(at)csl(dot)co(dot)uk> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Lee Kindness <lkindness(at)csl(dot)co(dot)uk>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: PostgreSQL libraries - PThread Support, but not use... |
Date: | 2003-01-07 16:12:26 |
Message-ID: | 15898.64618.778433.660836@kelvin.csl.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
Bruce Momjian writes:
> Lee Kindness wrote:
> > Right, so a reasonable angle for me to take is to go through the libpq
> > source looking for potential problem areas and use of "known bad"
> > functions. I can add autoconf checks for the replacement *_r()
> > functions, and use these in place of the traditional ones where
> > available.
> I am a little confused by the *_r functions. Are they for all
> functions? BSD/OS doesn't have them, but all our libc functions are
> threadsafe except for things like strtok, where they recommend strsep,
> and gethostbyname, where they would suggest getaddrinfo, I guess.
Some functions in the C library (and other common system libraries)
are defined in such a way to make their implementation
non-reentrant. Normally this is due to return values being supplied in
a static buffer which is overwritten by the subsequent call, or the
calls relying on static data between calls. A list such functions
would include:
asctime crypt ctime drand48 ecvt encrypt erand48 fcvt fgetgrent
fgetpwent fgetspent getaliasbyname getaliasent getdate getgrent
getgrgid getgrnam gethostbyaddr gethostbyname gethostbyname2
gethostent getlogin getnetbyaddr getnetbyname getnetent getnetgrent
getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid
getservbyname getservbyport getservent getspent getspnam getutent
getutid getutline gmtime hcreate hdestroy hsearch initstate jrand48
lcong48 localtime lrand48 mrand48 nrand48 ptsname qecvt qfcvt rand
random readdir readdir64 seed48 setkey setstate sgetspent srand48
srandom strerror strtok tmpnam ttyname
to one degree or another. The important ones to watch for are: ctime,
localtime, asctime, gmtime, readdir, strtok and tmpnam. Now these
functions are often augmented by a _r partner which fixes their API to
allow their implementations to be reentrant.
After a quick grep libpq could be using crypt, gethostbyname, random,
strerror, encrypt, getpwuid, rand and strtok. As you rightly note, ins
ome cases the correct fix is to use alternative functions and not the
_r versions - this avoids lots of ifdefs!
L.
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2003-01-07 16:17:01 | Re: IPv6 patch |
Previous Message | Greg Copeland | 2003-01-07 16:12:14 | Re: [Npgsql-general] Get function OID and function |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2003-01-07 16:32:51 | Re: Refuse SSL patch |
Previous Message | Jon Jensen | 2003-01-07 16:04:45 | Re: Refuse SSL patch |