Author: wyoung
Date: Tue Feb 20 12:57:30 2007
New Revision: 1421

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1421&view=rev
Log:
More tweaks to the thread-safe localtime() replacement code in the
datetime module.  If not VS2005 with the native RTL, explicitly
testing for localtime_r() in autoconf stage now instead of doing a
bunch of compile-time tests for platforms we know don't have it.
localtime_r() should only be on platforms that use autoconf, and it's
easier to test if it exists than to test for all the cases where we
know it is _not_ there.

Added:
    trunk/config/localtime_r.m4
Modified:
    trunk/configure.ac
    trunk/lib/datetime.cpp

Added: trunk/config/localtime_r.m4
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/config/localtime_r.m4?rev=1421&view=auto
==============================================================================
--- trunk/config/localtime_r.m4 (added)
+++ trunk/config/localtime_r.m4 Tue Feb 20 12:57:30 2007
@@ -1,0 +1,30 @@
+dnl @synopsis AX_C_LOCALTIME_R
+dnl 
+dnl This macro determines whether the C runtime library contains
+dnl localtime_r(), a thread-safe replacement for localtime().
+dnl
+dnl @version 1.0, 2007/02/20
+dnl @author Warren Young <[EMAIL PROTECTED]>
+AC_DEFUN([AX_C_LOCALTIME_R],
+[
+       AC_MSG_CHECKING([for localtime_r()])
+
+       AC_TRY_RUN([
+               #include <time.h>
+               int main(void)
+               {
+                       time_t tt;
+                       struct tm stm;
+                       localtime_r(&tt, &stm);
+                       return 0;
+               }
+       ], [localtime_r_found=yes], [localtime_r_found=no], 
[localtime_r_found=no])
+
+       AC_MSG_RESULT([$localtime_r_found])
+       if test x"$localtime_r_found" = xyes
+       then
+               AC_DEFINE(HAVE_LOCALTIME_R, 1,
+                       [Define if you have the localtime_r() facility])
+       fi
+]) dnl AX_C_LOCALTIME_R
+

Modified: trunk/configure.ac
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/configure.ac?rev=1421&r1=1420&r2=1421&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Tue Feb 20 12:57:30 2007
@@ -63,6 +63,7 @@
 MYSQL_API_LOCATION
 MYSQL_SHUTDOWN_ARG
 MYSQL_WITH_SSL
+AX_C_LOCALTIME_R
 AC_CHECK_LIB(intl, main)
 
 

Modified: trunk/lib/datetime.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.cpp?rev=1421&r1=1420&r2=1421&view=diff
==============================================================================
--- trunk/lib/datetime.cpp (original)
+++ trunk/lib/datetime.cpp Tue Feb 20 12:57:30 2007
@@ -191,10 +191,17 @@
 {
        struct tm tm;
 #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(_STLP_VERSION)
+       // Use thread-safe localtime() replacement included with VS2005 and
+       // up, but only when using native RTL, not STLport.
        localtime_s(&tm, &t);
-#elif !defined(__MINGW32_VERSION) && !defined(_STLP_VERSION)
+#elif defined(HAVE_LOCALTIME_R)
+       // Detected POSIX thread-safe localtime() replacement.
        localtime_r(&t, &tm);
 #else
+       // No explicitly thread-safe localtime() replacement found.  This
+       // may still be thread-safe, as some C libraries take special steps
+       // within localtime() to get thread safety.  For example, thread-
+       // local storage (TLS) in some Windows compilers.
        memcpy(&tm, localtime(&t), sizeof(tm));
 #endif
 


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to