Re: PostgreSQL libraries - PThread Support, but not use...

Поиск
Список
Период
Сортировка
От Lee Kindness
Тема Re: PostgreSQL libraries - PThread Support, but not use...
Дата
Msg-id 15898.64618.778433.660836@kelvin.csl.co.uk
обсуждение исходный текст
Ответ на Re: PostgreSQL libraries - PThread Support, but not use...  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
Bruce Momjian writes:> Lee Kindness wrote:> > Right, so a reasonable angle for me to take is to go through the libpq> >
sourcelooking 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
confusedby the *_r functions.  Are they for all> functions?  BSD/OS doesn't have them, but all our libc functions are>
threadsafeexcept 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 fgetgrentfgetpwent fgetspent getaliasbyname getaliasent getdate
getgrentgetgrgidgetgrnam gethostbyaddr gethostbyname gethostbyname2gethostent getlogin getnetbyaddr getnetbyname
getnetentgetnetgrentgetprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuidgetservbyname getservbyport
getserventgetspent getspnam getutentgetutid getutline gmtime hcreate hdestroy hsearch initstate jrand48lcong48
localtimelrand48 mrand48 nrand48 ptsname qecvt qfcvt randrandom readdir readdir64 seed48 setkey setstate sgetspent
srand48srandomstrerror 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.


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: contrib/noupdate does not work and never has worked
Следующее
От: Greg Copeland
Дата:
Сообщение: Re: [Npgsql-general] Get function OID and function