Re: [PATCHES] time_t timezone - Mailing list pgsql-cygwin
From | Reini Urban |
---|---|
Subject | Re: [PATCHES] time_t timezone |
Date | |
Msg-id | 413551B4.1040905@x-ray.at Whole thread Raw |
Responses |
Re: [PATCHES] time_t timezone
|
List | pgsql-cygwin |
Now I've found time to test beta2 and came up with the attached better patch: Added configure time_t timezone check for the SUSV definition. Not only cygwin, all newlib installations without struct tm timezone. Casted to (int) timezone. (configure should really be re-created by autoconf. I patched it just for completeness in the forthcoming cygwin package.) Bruce Momjian schrieb: > OK, patch attached and applied that casts _timezone to (int) on Cygwin. > --------------------------------------------------------------------------- > > Reini Urban wrote: >>Bruce Momjian schrieb: >> >>>Should I apply this change? >>> >>> #define TIMEZONE_GLOBAL ((int)_timezone) >> >>yes, please. >>I have no time yet, to come up with the better patch. It's already monday. >> >> >>>--------------------------------------------------------------------------- >>> >>>Reini Urban wrote: >>> >>> >>>>Bruce Momjian schrieb: >>>> >>>> >>>>>Your patch highlighted several bugs in our code. First, I wasn't >>>>>testing for CYGWIN in the backend pgport_palloc code. Second, I added >>>>>an #undef to prevent compiler warnings. Third I added your Cygwin >>>>>includes with an #ifdef. These will appear in beta2. >>>>> >>>>>On the timezone issue, I see this in dt.h: >>>>> >>>>> /* Global variable holding time zone information. */ >>>>> #if !defined(__CYGWIN__) && !defined(WIN32) >>>>> #define TIMEZONE_GLOBAL timezone >>>>> #else >>>>> #define TIMEZONE_GLOBAL _timezone >>>>> #define tzname _tzname /* should be in time.h? */ >>>>> #endif >>>>> >>>>>so are you saying your _timezone is time_t and not an int? Sometimes it >>>>>is just a short because it is only minutes west of GMT, not an actually >>>>>seconds since 1970 or anything. Making it time_t actually sounds like >>>>>overkill, but we can work around that in dt.h if indeed that is how your >>>>>OS defines it. The easiest fix would probably be to add the cast to int >>>>>right in dt.h and only for Cygwin: >>>>> >>>>> #define TIMEZONE_GLOBAL ((int)_timezone) >>>>> >>>>>Does that work for you? >>>> >>>>yes, that's better. >>>> >>>>FYI /usr/include/time.h: >>>>/* defines for the opengroup specifications Derived from Issue 1 of the >>>>SVID. */ >>>>extern __IMPORT time_t _timezone; >>>>... >>>> >>>>BTW: I see that CYGWIN also has a struct timezone in sys/time.h, but >>>>configure didn't check for that. >>>>I'll come with better patches after beta2. >>>> >>>> >>>> >>>> >>>>>--------------------------------------------------------------------------- >>>>> >>>>>Reini Urban wrote: >>>>> >>>>> >>>>> >>>>>>Attached patches are required for cygwin: >>>>>> >>>>>>2004-08-24 21:23:53 rurban@x-ray.at >>>>>> * (postmaster/syslogger.c) struct timeval is >>>>>> declared in sys/time.h, not in time.h >>>>>> >>>>>>2004-08-24 20:20:54 rurban: >>>>>> * (port/dirmod.c) cygwin needs different header locations, >>>>>> and unlink is a macro. There are no pgport_palloc >>>>>> versions yet >>>>>> >>>>>> >>>>>>timezone/pgtz.c: >>>>>>Pending is a patch against postgresql-8.0.0beta1/config/c-library.m4: >>>>>>PGAC_VAR_INT_TIMEZONE >>>>>> >>>>>>In the meantime I've hacked it with a cast from time_t to (int) in >>>>>>timezone/pgtz.c: get_timezone_offset >>>>>> >>>>>>but timezone really is of time_t, not int. I don't know what you are >>>>>>trying to do here. >>>>>> >>>>>> >>>>>>There's on remaining issue for the cygwin build: >>>>>>../../src/port/libpgport.a(dirmod.o)(.text+0x5ee):dirmod.c: undefined >>>>>>reference to `__imp__CurrentMemoryContext' >>>>>>../../src/port/libpgport.a(dirmod.o)(.text+0x64b):dirmod.c: undefined >>>>>>reference to `__imp__CurrentMemoryContext' >>>>>> >>>>>>which explains the pgport_palloc problem. >>>>>>-- >>>>>>Reini Urban >>>>>>http://xarch.tu-graz.ac.at/home/rurban/ >>>>>> >>>>> >>>>> >>>>>>2004-08-24 20:20:54 rurban: >>>>>> * cygwin needs different header locations, and unlink is a macro >>>>>> * There are no pgport_palloc versions yet >>>>>> >>>>>>--- postgresql-8.0.0beta1/src/port/dirmod.c.orig 2004-08-08 07:44:36.000000000 +0100 >>>>>>+++ postgresql-8.0.0beta1/src/port/dirmod.c 2004-08-24 19:20:56.557435000 +0100 >>>>>>@@ -33,16 +33,28 @@ >>>>>> >>>>>> >>>>>>#include "miscadmin.h" >>>>>>+ >>>>>>+#ifdef __CYGWIN__ >>>>>>+#include <windows.h> >>>>>>+#include <w32api/winioctl.h> >>>>>>+#else >>>>>>#include <winioctl.h> >>>>>>+#undef unlink >>>>>>+#endif >>>>>> >>>>>>#undef rename >>>>>>-#undef unlink >>>>>> >>>>>>+/* 2004-08-24 20:20:54 rurban: There are no pgport_palloc versions yet */ >>>>>>+#if 0 >>>>>>#ifndef FRONTEND >>>>>>+#undef palloc >>>>>>+#undef pstrdup >>>>>>+#undef pfree >>>>>>#define palloc(sz) pgport_palloc(sz) >>>>>>#define pstrdup(str) pgport_pstrdup(str) >>>>>>#define pfree(pointer) pgport_pfree(pointer) >>>>>>#endif >>>>>>+#endif >>>>>> >>>>>> >>>>>>/* >>>>> >>>>> >>>>>>2004-08-24 21:23:53 rurban@x-ray.at >>>>>> * struct timeval is declared in sys/time.h, not in time.h >>>>>> >>>>>>--- postgresql-8.0.0beta1/src/backend/postmaster/syslogger.c.orig 2004-08-06 20:17:31.000000000 +0100 >>>>>>+++ postgresql-8.0.0beta1/src/backend/postmaster/syslogger.c 2004-08-24 20:21:26.057851800 +0100 >>>>>>@@ -28,6 +28,7 @@ >>>>>>#include <signal.h> >>>>>>#include <time.h> >>>>>>#include <unistd.h> >>>>>>+#include <sys/time.h> >>>>>>#include <sys/stat.h> >>>>>> >>>>>>#include "libpq/pqsignal.h" >>>>> >>>>> >>>>>>--- postgresql-8.0.0beta1/src/timezone/pgtz.c.orig 2004-07-31 20:12:15.000000000 +0100 >>>>>>+++ postgresql-8.0.0beta1/src/timezone/pgtz.c 2004-08-24 19:56:30.686367800 +0100 >>>>>>@@ -97,9 +97,9 @@ >>>>>> return tm->tm_gmtoff; >>>>>>#elif defined(HAVE_INT_TIMEZONE) >>>>>>#ifdef HAVE_UNDERSCORE_TIMEZONE >>>>>>- return -_timezone; >>>>>>+ return -(int)_timezone; >>>>>>#else >>>>>>- return -timezone; >>>>>>+ return -(int)timezone; >>>>>>#endif >>>>>>#else >>>>>>#error No way to determine TZ? Can this happen? >>>>> >>>>> >>>>>>---------------------------(end of broadcast)--------------------------- >>>>>>TIP 9: the planner will ignore your desire to choose an index scan if your >>>>>> joining column's datatypes do not match >>>>> >>>>> >>>>> >>>>>------------------------------------------------------------------------ >>>>> >>>>>Index: src/backend/utils/mmgr/mcxt.c >>>>>=================================================================== >>>>>RCS file: /cvsroot/pgsql-server/src/backend/utils/mmgr/mcxt.c,v >>>>>retrieving revision 1.47 >>>>>diff -c -c -r1.47 mcxt.c >>>>>*** src/backend/utils/mmgr/mcxt.c 8 Aug 2004 06:44:32 -0000 1.47 >>>>>--- src/backend/utils/mmgr/mcxt.c 29 Aug 2004 02:50:25 -0000 >>>>>*************** >>>>>*** 631,637 **** >>>>> } >>>>> >>>>> >>>>>! #ifdef WIN32 >>>>> /* >>>>> * Memory support routines for libpgport on Win32 >>>>> * >>>>>--- 631,637 ---- >>>>> } >>>>> >>>>> >>>>>! #if defined(WIN32) || defined(__CYGWIN__) >>>>> /* >>>>> * Memory support routines for libpgport on Win32 >>>>> * >>>>>*************** >>>>>*** 649,654 **** >>>>>--- 649,655 ---- >>>>> return palloc(sz); >>>>> } >>>>> >>>>>+ >>>>> char * >>>>> pgport_pstrdup(const char *str) >>>>> { >>>>>Index: src/port/dirmod.c >>>>>=================================================================== >>>>>RCS file: /cvsroot/pgsql-server/src/port/dirmod.c,v >>>>>retrieving revision 1.19 >>>>>diff -c -c -r1.19 dirmod.c >>>>>*** src/port/dirmod.c 29 Aug 2004 01:44:02 -0000 1.19 >>>>>--- src/port/dirmod.c 29 Aug 2004 02:50:28 -0000 >>>>>*************** >>>>>*** 31,48 **** >>>>> >>>>> #if defined(WIN32) || defined(__CYGWIN__) >>>>> >>>>>- >>>>> #include "miscadmin.h" >>>>>- #include <winioctl.h> >>>>> >>>>> #undef rename >>>>> #undef unlink >>>>> >>>>> #ifndef FRONTEND >>>>> /* >>>>> * Call non-macro versions of palloc, can't reference CurrentMemoryContext >>>>> * because of DLLIMPORT. >>>>> */ >>>>> #define palloc(sz) pgport_palloc(sz) >>>>> #define pstrdup(str) pgport_pstrdup(str) >>>>> #define pfree(pointer) pgport_pfree(pointer) >>>>>--- 31,57 ---- >>>>> >>>>> #if defined(WIN32) || defined(__CYGWIN__) >>>>> >>>>> #include "miscadmin.h" >>>>> >>>>> #undef rename >>>>> #undef unlink >>>>> >>>>>+ #ifdef __WIN32__ >>>>>+ #include <winioctl.h> >>>>>+ #else >>>>>+ /* __CYGWIN__ */ >>>>>+ #include <windows.h> >>>>>+ #include <w32api/winioctl.h> >>>>>+ #endif >>>>>+ >>>>> #ifndef FRONTEND >>>>> /* >>>>> * Call non-macro versions of palloc, can't reference CurrentMemoryContext >>>>> * because of DLLIMPORT. >>>>> */ >>>>>+ #undef palloc >>>>>+ #undef pstrdup >>>>>+ #undef pfree >>>>> #define palloc(sz) pgport_palloc(sz) >>>>> #define pstrdup(str) pgport_pstrdup(str) >>>>> #define pfree(pointer) pgport_pfree(pointer) >>>> >>>> >>>>-- >>>>Reini Urban >>>>http://xarch.tu-graz.ac.at/home/rurban/ >>>> >>>>---------------------------(end of broadcast)--------------------------- >>>>TIP 4: Don't 'kill -9' the postmaster >>>> >>> >>> >> >>-- >>Reini Urban >>http://xarch.tu-graz.ac.at/home/rurban/ >> >>---------------------------(end of broadcast)--------------------------- >>TIP 8: explain analyze is your friend >> > > > > ------------------------------------------------------------------------ > > Index: src/interfaces/ecpg/pgtypeslib/dt.h > =================================================================== > RCS file: /cvsroot/pgsql-server/src/interfaces/ecpg/pgtypeslib/dt.h,v > retrieving revision 1.17 > diff -c -c -r1.17 dt.h > *** src/interfaces/ecpg/pgtypeslib/dt.h 19 Jan 2004 19:04:40 -0000 1.17 > --- src/interfaces/ecpg/pgtypeslib/dt.h 1 Sep 2004 04:00:49 -0000 > *************** > *** 220,226 **** > --- 220,230 ---- > #if !defined(__CYGWIN__) && !defined(WIN32) > #define TIMEZONE_GLOBAL timezone > #else > + #if defined(WIN32) > #define TIMEZONE_GLOBAL _timezone > + #else > + #define TIMEZONE_GLOBAL ((int)_timezone) /* time_t on Cywgin */ > + #endif > #define tzname _tzname /* should be in time.h? */ > #endif > -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban/ --- config/c-library.m4.orig 2004-06-07 23:39:44.000000000 +0100 +++ config/c-library.m4 2004-09-01 01:52:49.685665700 +0100 @@ -17,7 +17,22 @@ AC_DEFINE(HAVE_INT_TIMEZONE,, [Define to 1 if you have the global variable 'int timezone'.]) fi])# PGAC_VAR_INT_TIMEZONE +# PGAC_VAR_TIME_T_TIMEZONE +# --------------------- +# Check if the global variable `time_t timezone' exists. If so, define +# HAVE_TIME_T_TIMEZONE. +AC_DEFUN([PGAC_VAR_TIME_T_TIMEZONE], +[AC_CACHE_CHECK(for time_t timezone, pgac_cv_var_time_t_timezone, +[AC_TRY_LINK([#include <time.h> +int res;], + [res = (int) timezone / 60;], + [pgac_cv_var_time_t_timezone=yes], + [pgac_cv_var_time_t_timezone=no])]) +if test x"$pgac_cv_var_time_t_timezone" = xyes ; then + AC_DEFINE(HAVE_TIME_T_TIMEZONE,, [Define to 1 if you have the global variable 'time_t timezone'.]) +fi])# PGAC_VAR_TIME_T_TIMEZONE + # PGAC_STRUCT_TIMEZONE # ------------------ --- src/timezone/pgtz.c.orig 2004-08-30 03:54:42.000000000 +0100 +++ src/timezone/pgtz.c 2004-09-01 01:55:46.011533700 +0100 @@ -96,14 +96,20 @@ #if defined(HAVE_STRUCT_TM_TM_ZONE) return tm->tm_gmtoff; #elif defined(HAVE_INT_TIMEZONE) -#ifdef HAVE_UNDERSCORE_TIMEZONE +# ifdef HAVE_UNDERSCORE_TIMEZONE return -_timezone; -#else +# else return -timezone; -#endif +# endif +#elif defined(HAVE_TIME_T_TIMEZONE) +# ifdef HAVE_UNDERSCORE_TIMEZONE + return -(int) _timezone; +# else + return -(int) timezone; +# endif #else -#error No way to determine TZ? Can this happen? +# error No way to determine TZ? Can this happen? #endif } --- configure.in.orig 2004-08-31 05:08:33.000000000 +0100 +++ configure.in 2004-09-01 01:54:24.450077700 +0100 @@ -804,7 +804,8 @@ ## PGAC_VAR_INT_TIMEZONE +PGAC_VAR_TIME_T_TIMEZONE AC_FUNC_ACCEPT_ARGTYPES PGAC_FUNC_GETTIMEOFDAY_1ARG --- configure.orig 2004-08-31 05:08:32.000000000 +0100 +++ configure 2004-09-01 02:00:16.758068100 +0100 @@ -12905,7 +12905,69 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for time_t timezone" >&5 +echo $ECHO_N "checking for time_t timezone... $ECHO_C" >&6 +if test "${pgac_cv_var_time_t_timezone+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <time.h> +int res; +int +main () +{ +res = (int)timezone / 60; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + pgac_cv_var_time_t_timezone=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +pgac_cv_var_time_t_timezone=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $pgac_cv_var_time_t_timezone" >&5 +echo "${ECHO_T}$pgac_cv_var_time_t_timezone" >&6 +if test x"$pgac_cv_var_time_t_timezone" = xyes ; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_TIME_T_TIMEZONE +_ACEOF + +fi echo "$as_me:$LINENO: checking types of arguments for accept()" >&5 echo $ECHO_N "checking types of arguments for accept()... $ECHO_C" >&6 if test "${ac_cv_func_accept_return+set}" = set; then --- src/include/pg_config.h.orig 2004-09-01 01:24:36.472964100 +0100 +++ src/include/pg_config.h 2004-09-01 02:10:22.562813700 +0100 @@ -177,7 +177,10 @@ /* Define to 1 if you have the global variable 'int timezone'. */ /* #undef HAVE_INT_TIMEZONE */ +/* Define to 1 if you have the global variable 'time_t timezone'. */ +#define HAVE_TIME_T_TIMEZONE 1 + /* Define to 1 if you have support for IPv6. */ /* #undef HAVE_IPV6 */ --- src/include/pg_config.h.in.orig 2004-07-14 18:55:10.000000000 +0100 +++ src/include/pg_config.h.in 2004-09-01 02:11:49.389827300 +0100 @@ -176,7 +176,10 @@ /* Define to 1 if you have the global variable 'int timezone'. */ #undef HAVE_INT_TIMEZONE +/* Define to 1 if you have the global variable 'time_t timezone'. */ +#undef HAVE_TIME_T_TIMEZONE + /* Define to 1 if you have support for IPv6. */ #undef HAVE_IPV6
pgsql-cygwin by date: