PHP 4.0 Bug #5225: Compile problems with reentrant time functions (*_r)

From: Date: Sun, 25 Jun 2000 16:00:20 +0000
Subject: PHP 4.0 Bug #5225: Compile problems with reentrant time functions (*_r)
Groups: php.dev 
Request: Send a blank email to php-dev+get-22272@lists.php.net to get a copy of this message
From: thomas@wolfram.net Operating system: HP-UX 10.20 PHP version: 4.0 Release Candidate 2 PHP Bug Type: Compile Failure Bug description: Compile problems with reentrant time functions (*_r) I compiled PHP 4.0.0 under HP-UX 10.20 (no DCE threads installed if that matters) using gcc 2.8.1 and found and fixed a problem of compiling reentrancy.c under this system. My configure line was: ./configure --prefix=/home/web/php4 \ --with-config-file-path=/home/web/php4 \ --with-apache=../apache_1.3.12 \ --with-mysql \ --enable-track-vars \ --enable-bcmath \ --enable-ftp Compilation of reentrancy.c caused following compiler problem: ==== reentrancy.c: In function `php_localtime_r': reentrancy.c:53: warning: implicit declaration of function `localtime_r' reentrancy.c: In function `php_ctime_r': reentrancy.c:60: warning: implicit declaration of function `ctime_r' reentrancy.c: In function `php_asctime_r': reentrancy.c:67: warning: implicit declaration of function `asctime_r' reentrancy.c: In function `php_gmtime_r': reentrancy.c:74: warning: implicit declaration of function `gmtime_r' reentrancy.c: At top level: reentrancy.c:84: redefinition of `php_localtime_r' reentrancy.c:52: `php_localtime_r' previously defined here reentrancy.c:105: redefinition of `php_ctime_r' reentrancy.c:59: `php_ctime_r' previously defined here reentrancy.c:123: redefinition of `php_asctime_r' reentrancy.c:66: `php_asctime_r' previously defined here reentrancy.c:141: redefinition of `php_gmtime_r' reentrancy.c:73: `php_gmtime_r' previously defined here ==== I found that the problem was caused by a combination of a missing macro definition (-D_REENTRANT) which was not set by the configure script (perhaps because I've no DCE threads installed?) and some wrong lines in php_reentrancy.h. The code in reentrancy.c already tries to workaround the different return types of the reentrant time functions (localtime_r() etc.) with defining special functions just for HP-UX. But because -D_REENTRANT is not set in configure, it doesn't see the existing prototypes of localtime_r() etc. and declares MISSING_*DECL which in turn leads in php_reentrancy.h to the definition of a wrong (i.e. non-HPUX) prototype. Moreover this header file wrongly undefines HAVE_LOCALTIME_R etc. for HP-UX (because this was a attempt to fix the problem?). Anyway, I was able to fix the problem and now have PHP 4.0.0 working by setting CPPFLAGS before running configure this way: CPPFLAGS=-D_REENTRANT ; export CPPFLAGS ./configure --prefix=/home/web/php4 \ --with-config-file-path=/home/web/php4 \ --with-apache=../apache_1.3.12 \ --with-mysql \ --enable-track-vars \ --enable-bcmath \ --enable-ftp and changing php_reentrancy this way (it's the output of diff -c): ==== *** php_reentrancy.h.orig Thu May 18 16:34:21 2000 --- php_reentrancy.h Sun Jun 25 02:40:57 2000 *************** *** 33,54 **** #define HAVE_CTIME 1 ! #ifdef PHP_HPUX_TIME_R ! #undef HAVE_LOCALTIME_R ! #undef HAVE_ASCTIME_R ! #undef HAVE_CTIME_R ! #undef HAVE_GMTIME_R ! #endif #if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME) #define PHP_NEED_REENTRANCY 1 PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm); #else #define php_localtime_r localtime_r #ifdef MISSING_LOCALTIME_R_DECL struct tm *localtime_r(const time_t *const timep, struct tm *p_tm); #endif #endif #if !defined(HAVE_CTIME_R) && defined(HAVE_CTIME) --- 33,58 ---- #define HAVE_CTIME 1 ! //#ifdef PHP_HPUX_TIME_R ! //#undef HAVE_LOCALTIME_R ! //#undef HAVE_ASCTIME_R ! //#undef HAVE_CTIME_R ! //#undef HAVE_GMTIME_R ! //#endif #if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME) #define PHP_NEED_REENTRANCY 1 PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm); #else + #ifdef PHP_HPUX_TIME_R + PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm); + #else #define php_localtime_r localtime_r #ifdef MISSING_LOCALTIME_R_DECL struct tm *localtime_r(const time_t *const timep, struct tm *p_tm); #endif #endif + #endif #if !defined(HAVE_CTIME_R) && defined(HAVE_CTIME) *************** *** 55,65 **** --- 59,73 ---- #define PHP_NEED_REENTRANCY 1 PHPAPI char *php_ctime_r(const time_t *clock, char *buf); #else + #ifdef PHP_HPUX_TIME_R + PHPAPI char *php_ctime_r(const time_t *clock, char *buf); + #else #define php_ctime_r ctime_r #ifdef MISSING_CTIME_R_DECL char *ctime_r(const time_t *clock, char *buf); #endif #endif + #endif #if !defined(HAVE_ASCTIME_R) && defined(HAVE_ASCTIME) *************** *** 66,76 **** --- 74,88 ---- #define PHP_NEED_REENTRANCY 1 PHPAPI char *php_asctime_r(const struct tm *tm, char *buf); #else + #ifdef PHP_HPUX_TIME_R + PHPAPI char *php_asctime_r(const struct tm *tm, char *buf); + #else #define php_asctime_r asctime_r #ifdef MISSING_ASCTIME_R_DECL char *asctime_r(const struct tm *tm, char *buf); #endif #endif + #endif #if !defined(HAVE_GMTIME_R) && defined(HAVE_GMTIME) *************** *** 77,85 **** --- 89,101 ---- #define PHP_NEED_REENTRANCY 1 PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm); #else + #ifdef PHP_HPUX_TIME_R + PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm); + #else #define php_gmtime_r gmtime_r #ifdef MISSING_GMTIME_R_DECL struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm); + #endif #endif #endif ===== I think if configure would set -D_REENTRANT always for HP-UX (whether threads are there or not) and with the above patch for php_reentrancy.h this should work for HP-UX 10.xx regardless whether there are threads or not and always for 11.xx. regards, Thomas Wolfram mailto:thomas@wolfram.net

« previous php.dev (#22272) next »