[Xapian-tickets] [Xapian] #665: Avoid C library functions not guaranteed to be thread-safe (was: getenv() not guaranteed to be thread-safe)

Xapian nobody at xapian.org
Fri Dec 19 04:25:47 GMT 2014


#665: Avoid C library functions not guaranteed to be thread-safe
-------------------------+--------------------------
 Reporter:  olly         |             Owner:  olly
     Type:  defect       |            Status:  new
 Priority:  normal       |         Milestone:  1.3.x
Component:  Library API  |           Version:  1.3.2
 Severity:  normal       |        Resolution:
 Keywords:               |        Blocked By:
 Blocking:               |  Operating System:  All
-------------------------+--------------------------

Comment (by olly):

 I think we should broaden this to cover any library functions which aren't
 necessarily thread-safe.

 According to the Linux man pages, there are potential issues with
 {{{atoi()}}} (and related functions like {{{atol()}}}, {{{strtoul()}}},
 etc which we don't currently use in the library code):

 > These functions can be safely used in multithreaded applications, as
 long as setlocale(3) is not called to change the locale during their
 execution.

 I can't see anything in POSIX about this potential issue, so not sure if
 Linux is failing to conform here.  It's not likely to bite in practice,
 but perhaps we should aim to avoid these functions in the library code.

 We use {{{inet_ntoa()}}} (which isn't thread-safe as it has a static
 return buffer) in one place, to report where the connection is from in
 net/tcpserver.cc.  That'll change when IPv6 support is added.

 I'm thinking we should see if we can compile a list of library functions
 to avoid, and blacklist them somehow (perhaps a header which does
 {{{#define inet_ntoa DO_NOT_USE_inet_ntoa}}} which gets included in all
 library code sources).

--
Ticket URL: <http://trac.xapian.org/ticket/665#comment:1>
Xapian <http://xapian.org/>
Xapian



More information about the Xapian-tickets mailing list