diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2011-03-25 13:13:26 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2011-03-25 13:13:26 (GMT) |
commit | 7f62526237f1fbba269a64a7a4c8a369d7b5e388 (patch) | |
tree | 323ee7cfdff0af50f665695cebcc07727c1ce14c | |
parent | 8296df7cb7e4d3398fda3276bb2fc5336a8220ab (diff) | |
download | tcl-7f62526237f1fbba269a64a7a4c8a369d7b5e388.zip tcl-7f62526237f1fbba269a64a7a4c8a369d7b5e388.tar.gz tcl-7f62526237f1fbba269a64a7a4c8a369d7b5e388.tar.bz2 |
Remove Tclp(Local|Gm)time_unix forwarders, the same can be done directly
Some void -> VOID transitions
-rw-r--r-- | generic/tclInt.decls | 10 | ||||
-rw-r--r-- | generic/tclIntDecls.h | 8 | ||||
-rw-r--r-- | generic/tclIntPlatDecls.h | 15 | ||||
-rw-r--r-- | generic/tclStubInit.c | 8 | ||||
-rw-r--r-- | unix/tclUnixTime.c | 281 |
5 files changed, 158 insertions, 164 deletions
diff --git a/generic/tclInt.decls b/generic/tclInt.decls index c48cd0d..4fb88c6 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -640,7 +640,7 @@ declare 162 generic { # correct type when calling this procedure. declare 163 generic { - void * TclGetInstructionTable (void) + VOID *TclGetInstructionTable(void) } # ALERT: The argument of 'TclExpandCodeArray' is actually a @@ -648,7 +648,7 @@ declare 163 generic { # "tclInt.h". It is described in "tclCompile.h". declare 164 generic { - void TclExpandCodeArray (void *envPtr) + void TclExpandCodeArray(VOID *envPtr) } # These functions are vfs aware, but are generally only useful internally. @@ -790,13 +790,13 @@ declare 16 mac { int TclMacOSErrorToPosixError(int error) } declare 17 mac { - void TclMacRemoveTimer(void *timerToken) + void TclMacRemoveTimer(VOID *timerToken) } declare 18 mac { - void * TclMacStartTimer(long ms) + VOID *TclMacStartTimer(long ms) } declare 19 mac { - int TclMacTimerExpired(void *timerToken) + int TclMacTimerExpired(VOID *timerToken) } declare 20 mac { int TclMacRegisterResourceFork(short fileRef, Tcl_Obj *tokenPtr, diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index 453532c..1d831ed 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -465,9 +465,9 @@ EXTERN int TclChannelTransform _ANSI_ARGS_((Tcl_Interp * interp, EXTERN void TclChannelEventScriptInvoker _ANSI_ARGS_(( ClientData clientData, int flags)); /* 163 */ -EXTERN void * TclGetInstructionTable _ANSI_ARGS_((void)); +EXTERN VOID * TclGetInstructionTable _ANSI_ARGS_((void)); /* 164 */ -EXTERN void TclExpandCodeArray _ANSI_ARGS_((void * envPtr)); +EXTERN void TclExpandCodeArray _ANSI_ARGS_((VOID * envPtr)); /* 165 */ EXTERN void TclpSetInitialEncodings _ANSI_ARGS_((void)); /* 166 */ @@ -722,8 +722,8 @@ typedef struct TclIntStubs { void *reserved160; int (*tclChannelTransform) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Channel chan, Tcl_Obj * cmdObjPtr)); /* 161 */ void (*tclChannelEventScriptInvoker) _ANSI_ARGS_((ClientData clientData, int flags)); /* 162 */ - void * (*tclGetInstructionTable) _ANSI_ARGS_((void)); /* 163 */ - void (*tclExpandCodeArray) _ANSI_ARGS_((void * envPtr)); /* 164 */ + VOID * (*tclGetInstructionTable) _ANSI_ARGS_((void)); /* 163 */ + void (*tclExpandCodeArray) _ANSI_ARGS_((VOID * envPtr)); /* 164 */ void (*tclpSetInitialEncodings) _ANSI_ARGS_((void)); /* 165 */ int (*tclListObjSetElement) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Obj * listPtr, int index, Tcl_Obj * valuePtr)); /* 166 */ void (*tclSetStartupScriptPath) _ANSI_ARGS_((Tcl_Obj * pathPtr)); /* 167 */ diff --git a/generic/tclIntPlatDecls.h b/generic/tclIntPlatDecls.h index 3af099d..35bacf1 100644 --- a/generic/tclIntPlatDecls.h +++ b/generic/tclIntPlatDecls.h @@ -189,11 +189,11 @@ EXTERN OSErr TclMacInstallExitToShellPatch _ANSI_ARGS_(( /* 16 */ EXTERN int TclMacOSErrorToPosixError _ANSI_ARGS_((int error)); /* 17 */ -EXTERN void TclMacRemoveTimer _ANSI_ARGS_((void * timerToken)); +EXTERN void TclMacRemoveTimer _ANSI_ARGS_((VOID * timerToken)); /* 18 */ -EXTERN void * TclMacStartTimer _ANSI_ARGS_((long ms)); +EXTERN VOID * TclMacStartTimer _ANSI_ARGS_((long ms)); /* 19 */ -EXTERN int TclMacTimerExpired _ANSI_ARGS_((void * timerToken)); +EXTERN int TclMacTimerExpired _ANSI_ARGS_((VOID * timerToken)); /* 20 */ EXTERN int TclMacRegisterResourceFork _ANSI_ARGS_(( short fileRef, Tcl_Obj * tokenPtr, @@ -285,9 +285,9 @@ typedef struct TclIntPlatStubs { void (*tclMacInitExitToShell) _ANSI_ARGS_((int usePatch)); /* 14 */ OSErr (*tclMacInstallExitToShellPatch) _ANSI_ARGS_((ExitToShellProcPtr newProc)); /* 15 */ int (*tclMacOSErrorToPosixError) _ANSI_ARGS_((int error)); /* 16 */ - void (*tclMacRemoveTimer) _ANSI_ARGS_((void * timerToken)); /* 17 */ - void * (*tclMacStartTimer) _ANSI_ARGS_((long ms)); /* 18 */ - int (*tclMacTimerExpired) _ANSI_ARGS_((void * timerToken)); /* 19 */ + void (*tclMacRemoveTimer) _ANSI_ARGS_((VOID * timerToken)); /* 17 */ + VOID * (*tclMacStartTimer) _ANSI_ARGS_((long ms)); /* 18 */ + int (*tclMacTimerExpired) _ANSI_ARGS_((VOID * timerToken)); /* 19 */ int (*tclMacRegisterResourceFork) _ANSI_ARGS_((short fileRef, Tcl_Obj * tokenPtr, int insert)); /* 20 */ short (*tclMacUnRegisterResourceFork) _ANSI_ARGS_((char * tokenPtr, Tcl_Obj * resultPtr)); /* 21 */ int (*tclMacCreateEnv) _ANSI_ARGS_((void)); /* 22 */ @@ -589,4 +589,7 @@ extern TclIntPlatStubs *tclIntPlatStubsPtr; /* !END!: Do not edit above this line. */ +#undef TclpLocaltime_unix +#undef TclpGmtime_unix + #endif /* _TCLINTPLATDECLS */ diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 9d5a401..a81f3e8 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -29,10 +29,10 @@ #undef Tcl_NewStringObj #undef Tcl_DumpActiveMemory #undef Tcl_ValidateAllMemory -#if TCL_PRESERVE_BINARY_COMPATABILITY -# undef Tcl_FindHashEntry -# undef Tcl_CreateHashEntry -#endif +#undef Tcl_FindHashEntry +#undef Tcl_CreateHashEntry +#define TclpLocaltime_unix TclpLocaltime +#define TclpGmtime_unix TclpGmtime /* * Keep a record of the original Notifier procedures, created in the diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c index 68fc779..707dfbc 100644 --- a/unix/tclUnixTime.c +++ b/unix/tclUnixTime.c @@ -1,25 +1,25 @@ -/* +/* * tclUnixTime.c -- * - * Contains Unix specific versions of Tcl functions that - * obtain time values from the operating system. + * Contains Unix specific versions of Tcl functions that obtain time + * values from the operating system. * * Copyright (c) 1995 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #include "tclPort.h" #include <locale.h> #define TM_YEAR_BASE 1900 -#define IsLeapYear(x) ((x % 4 == 0) && (x % 100 != 0 || x % 400 == 0)) +#define IsLeapYear(x) (((x)%4 == 0) && ((x)%100 != 0 || (x)%400 == 0)) /* - * TclpGetDate is coded to return a pointer to a 'struct tm'. For - * thread safety, this structure must be in thread-specific data. - * The 'tmKey' variable is the key to this buffer. + * TclpGetDate is coded to return a pointer to a 'struct tm'. For thread + * safety, this structure must be in thread-specific data. The 'tmKey' + * variable is the key to this buffer. */ static Tcl_ThreadDataKey tmKey; @@ -29,29 +29,30 @@ typedef struct ThreadSpecificData { } ThreadSpecificData; /* - * If we fall back on the thread-unsafe versions of gmtime and localtime, - * use this mutex to try to protect them. + * If we fall back on the thread-unsafe versions of gmtime and localtime, use + * this mutex to try to protect them. */ TCL_DECLARE_MUTEX(tmMutex) -static char* lastTZ = NULL; /* Holds the last setting of the - * TZ environment variable, or an - * empty string if the variable was - * not set. */ +static char *lastTZ = NULL; /* Holds the last setting of the TZ + * environment variable, or an empty string if + * the variable was not set. */ -/* Static functions declared in this file */ +/* + * Static functions declared in this file. + */ static void SetTZIfNecessary _ANSI_ARGS_((void)); static void CleanupMemory _ANSI_ARGS_((ClientData)); /* - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- * * TclpGetSeconds -- * - * This procedure returns the number of seconds from the epoch. On - * most Unix systems the epoch is Midnight Jan 1, 1970 GMT. + * This procedure returns the number of seconds from the epoch. On most + * Unix systems the epoch is Midnight Jan 1, 1970 GMT. * * Results: * Number of seconds from the epoch. @@ -59,7 +60,7 @@ static void CleanupMemory _ANSI_ARGS_((ClientData)); * Side effects: * None. * - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- */ unsigned long @@ -69,13 +70,13 @@ TclpGetSeconds() } /* - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- * * TclpGetClicks -- * * This procedure returns a value that represents the highest resolution - * clock available on the system. There are no garantees on what the - * resolution will be. In Tcl we will call this value a "click". The + * clock available on the system. There are no garantees on what the + * resolution will be. In Tcl we will call this value a "click". The * start time is also system dependant. * * Results: @@ -84,13 +85,14 @@ TclpGetSeconds() * Side effects: * None. * - *----------------------------------------------------------------------------- + *---------------------------------------------------------------------- */ unsigned long TclpGetClicks() { unsigned long now; + #ifdef NO_GETTOD struct tms dummy; #else @@ -112,13 +114,12 @@ TclpGetClicks() * * TclpGetTimeZone -- * - * Determines the current timezone. The method varies wildly - * between different platform implementations, so its hidden in - * this function. + * Determines the current timezone. The method varies wildly between + * different platform implementations, so its hidden in this function. * * Results: - * The return value is the local time zone, measured in - * minutes away from GMT (-ve for east, +ve for west). + * The return value is the local time zone, measured in minutes away from + * GMT (-ve for east, +ve for west). * * Side effects: * None. @@ -127,102 +128,101 @@ TclpGetClicks() */ int -TclpGetTimeZone (currentTime) - Tcl_WideInt currentTime; +TclpGetTimeZone(currentTime) + Tcl_WideInt currentTime; { + int timeZone; + /* - * We prefer first to use the time zone in "struct tm" if the - * structure contains such a member. Following that, we try - * to locate the external 'timezone' variable and use its value. - * If both of those methods fail, we attempt to convert a known - * time to local time and use the difference from UTC as the local - * time zone. In all cases, we need to undo any Daylight Saving Time - * adjustment. + * We prefer first to use the time zone in "struct tm" if the structure + * contains such a member. Following that, we try to locate the external + * 'timezone' variable and use its value. If both of those methods fail, + * we attempt to convert a known time to local time and use the difference + * from UTC as the local time zone. In all cases, we need to undo any + * Daylight Saving Time adjustment. */ - -#if defined(HAVE_TM_TZADJ) -# define TCL_GOT_TIMEZONE - /* Struct tm contains tm_tzadj - that value may be used. */ +#if defined(HAVE_TM_TZADJ) +#define TCL_GOT_TIMEZONE + /* + * Struct tm contains tm_tzadj - that value may be used. + */ - time_t curTime = (time_t) currentTime; - struct tm *timeDataPtr = TclpLocaltime((TclpTime_t) &curTime); - int timeZone; + time_t curTime = (time_t) currentTime; + struct tm *timeDataPtr = TclpLocaltime((TclpTime_t) &curTime); - timeZone = timeDataPtr->tm_tzadj / 60; + timeZone = timeDataPtr->tm_tzadj / 60; if (timeDataPtr->tm_isdst) { - timeZone += 60; + timeZone += 60; } - - return timeZone; - #endif #if defined(HAVE_TM_GMTOFF) && !defined (TCL_GOT_TIMEZONE) -# define TCL_GOT_TIMEZONE - - /* Struct tm contains tm_gmtoff - that value may be used. */ +#define TCL_GOT_TIMEZONE + /* + * Struct tm contains tm_gmtoff - that value may be used. + */ - time_t curTime = (time_t) currentTime; + time_t curTime = (time_t) currentTime; struct tm *timeDataPtr = TclpLocaltime((TclpTime_t) &curTime); - int timeZone; timeZone = -(timeDataPtr->tm_gmtoff / 60); if (timeDataPtr->tm_isdst) { - timeZone += 60; + timeZone += 60; } - - return timeZone; - #endif #if defined(HAVE_TIMEZONE_VAR) && !defined(TCL_GOT_TIMEZONE) && !defined(USE_DELTA_FOR_TZ) -# define TCL_GOT_TIMEZONE - - int timeZone; - - /* The 'timezone' external var is present and may be used. */ +#define TCL_GOT_TIMEZONE + /* + * The 'timezone' external var is present and may be used. + */ SetTZIfNecessary(); /* - * Note: this is not a typo in "timezone" below! See tzset - * documentation for details. + * Note: this is not a typo in "timezone" below! See tzset documentation + * for details. */ timeZone = timezone / 60; - return timeZone; - #endif -#if !defined(TCL_GOT_TIMEZONE) -#define TCL_GOT_TIMEZONE 1 +#if !defined(TCL_GOT_TIMEZONE) +#define TCL_GOT_TIMEZONE /* * Fallback - determine time zone with a known reference time. */ - int timeZone; time_t tt; struct tm *stm; - tt = 849268800L; /* 1996-11-29 12:00:00 GMT */ - stm = TclpLocaltime((TclpTime_t) &tt); /* eg 1996-11-29 6:00:00 CST6CDT */ - /* The calculation below assumes a max of +12 or -12 hours from GMT */ + + tt = 849268800L; /* 1996-11-29 12:00:00 GMT */ + stm = TclpLocaltime((TclpTime_t) &tt); /* eg 1996-11-29 6:00:00 CST6CDT */ + + /* + * The calculation below assumes a max of +12 or -12 hours from GMT. + */ + timeZone = (12 - stm->tm_hour)*60 + (0 - stm->tm_min); - if ( stm -> tm_isdst ) { - timeZone += 60; + if (stm->tm_isdst) { + timeZone += 60; } - return timeZone; /* eg +360 for CST6CDT */ + + /* + * Now have offset for our known reference time, eg +360 for CST6CDT. + */ #endif #ifndef TCL_GOT_TIMEZONE /* - * Cause compile error, we don't know how to get timezone. + * Cause fatal compile error, we don't know how to get timezone. */ -#error autoconf did not figure out how to determine the timezone. - +#error autoconf did not figure out how to determine the timezone. #endif + return timeZone; } /* @@ -230,8 +230,8 @@ TclpGetTimeZone (currentTime) * * Tcl_GetTime -- * - * Gets the current system time in seconds and microseconds - * since the beginning of the epoch: 00:00 UCT, January 1, 1970. + * Gets the current system time in seconds and microseconds since the + * beginning of the epoch: 00:00 UCT, January 1, 1970. * * Results: * Returns the current time in timePtr. @@ -258,9 +258,9 @@ Tcl_GetTime(timePtr) * * TclpGetDate -- * - * This function converts between seconds and struct tm. If - * useGMT is true, then the returned date will be in Greenwich - * Mean Time (GMT). Otherwise, it will be in the local time zone. + * This function converts between seconds and struct tm. If useGMT is + * true, then the returned date will be in Greenwich Mean Time (GMT). + * Otherwise, it will be in the local time zone. * * Results: * Returns a static tm structure. @@ -339,7 +339,7 @@ TclpStrftime(s, maxsize, format, t, useGMT) */ struct tm * -TclpGmtime( tt ) +TclpGmtime(tt) TclpTime_t_CONST tt; { CONST time_t *timePtr = (CONST time_t *) tt; @@ -350,26 +350,17 @@ TclpGmtime( tt ) * Get a thread-local buffer to hold the returned time. */ - ThreadSpecificData *tsdPtr = TCL_TSD_INIT( &tmKey ); + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&tmKey); #ifdef HAVE_GMTIME_R - gmtime_r(timePtr, &( tsdPtr->gmtime_buf )); + gmtime_r(timePtr, &(tsdPtr->gmtime_buf)); #else - Tcl_MutexLock( &tmMutex ); - memcpy( (VOID *) &( tsdPtr->gmtime_buf ), - (VOID *) gmtime( timePtr ), - sizeof( struct tm ) ); - Tcl_MutexUnlock( &tmMutex ); -#endif - return &( tsdPtr->gmtime_buf ); -} -/* - * Forwarder for obsolete item in Stubs - */ -struct tm* -TclpGmtime_unix( timePtr ) - TclpTime_t_CONST timePtr; -{ - return TclpGmtime( timePtr ); + Tcl_MutexLock(&tmMutex); + memcpy((VOID *) &(tsdPtr->gmtime_buf), + (VOID *) gmtime(timePtr), + sizeof(struct tm)); + Tcl_MutexUnlock(&tmMutex); +#endif + return &(tsdPtr->gmtime_buf); } /* @@ -390,7 +381,7 @@ TclpGmtime_unix( timePtr ) */ struct tm * -TclpLocaltime( tt ) +TclpLocaltime(tt) TclpTime_t_CONST tt; { CONST time_t *timePtr = (CONST time_t *) tt; @@ -400,77 +391,68 @@ TclpLocaltime( tt ) * Get a thread-local buffer to hold the returned time. */ - ThreadSpecificData *tsdPtr = TCL_TSD_INIT( &tmKey ); + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&tmKey); SetTZIfNecessary(); #ifdef HAVE_LOCALTIME_R - localtime_r( timePtr, &( tsdPtr->localtime_buf ) ); + localtime_r(timePtr, &(tsdPtr->localtime_buf)); #else - Tcl_MutexLock( &tmMutex ); - memcpy( (VOID *) &( tsdPtr -> localtime_buf ), - (VOID *) localtime( timePtr ), - sizeof( struct tm ) ); - Tcl_MutexUnlock( &tmMutex ); -#endif - return &( tsdPtr->localtime_buf ); -} -/* - * Forwarder for obsolete item in Stubs - */ -struct tm* -TclpLocaltime_unix( timePtr ) - TclpTime_t_CONST timePtr; -{ - return TclpLocaltime( timePtr ); + Tcl_MutexLock(&tmMutex); + memcpy((VOID *) &(tsdPtr -> localtime_buf), + (VOID *) localtime(timePtr), + sizeof(struct tm)); + Tcl_MutexUnlock(&tmMutex); +#endif + return &(tsdPtr->localtime_buf); } - + /* *---------------------------------------------------------------------- * * SetTZIfNecessary -- * - * Determines whether a call to 'tzset' is needed prior to the - * next call to 'localtime' or examination of the 'timezone' variable. + * Determines whether a call to 'tzset' is needed prior to the next call + * to 'localtime' or examination of the 'timezone' variable. * * Results: * None. * * Side effects: - * If 'tzset' has never been called in the current process, or if - * the value of the environment variable TZ has changed since the - * last call to 'tzset', then 'tzset' is called again. + * If 'tzset' has never been called in the current process, or if the + * value of the environment variable TZ has changed since the last call + * to 'tzset', then 'tzset' is called again. * *---------------------------------------------------------------------- */ static void -SetTZIfNecessary() { +SetTZIfNecessary() +{ + CONST char *newTZ = getenv("TZ"); - CONST char* newTZ = getenv( "TZ" ); Tcl_MutexLock(&tmMutex); - if ( newTZ == NULL ) { + if (newTZ == NULL) { newTZ = ""; } - if ( lastTZ == NULL || strcmp( lastTZ, newTZ ) ) { - tzset(); - if ( lastTZ == NULL ) { - Tcl_CreateExitHandler( CleanupMemory, (ClientData) NULL ); + if (lastTZ == NULL || strcmp(lastTZ, newTZ)) { + tzset(); + if (lastTZ == NULL) { + Tcl_CreateExitHandler(CleanupMemory, (ClientData) NULL); } else { - Tcl_Free( lastTZ ); + Tcl_Free(lastTZ); } - lastTZ = ckalloc( strlen( newTZ ) + 1 ); - strcpy( lastTZ, newTZ ); + lastTZ = ckalloc(strlen(newTZ) + 1); + strcpy(lastTZ, newTZ); } Tcl_MutexUnlock(&tmMutex); - } - + /* *---------------------------------------------------------------------- * * CleanupMemory -- * - * Releases the private copy of the TZ environment variable - * upon exit from Tcl. + * Releases the private copy of the TZ environment variable upon exit + * from Tcl. * * Results: * None. @@ -482,7 +464,16 @@ SetTZIfNecessary() { */ static void -CleanupMemory( ClientData ignored ) +CleanupMemory(ignored) + ClientData ignored; { - ckfree( lastTZ ); + ckfree(lastTZ); } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |