summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-01-10 22:21:26 (GMT)
committersebres <sebres@users.sourceforge.net>2017-01-10 22:21:26 (GMT)
commitdc9796c6e858828861b1339b4734bab19cccca4c (patch)
tree81cb2bbde61282f93461ce283eb461c4afef2e70
parent18be594c8481eee9b98d140af50df7ccb3a3a79e (diff)
downloadtcl-dc9796c6e858828861b1339b4734bab19cccca4c.zip
tcl-dc9796c6e858828861b1339b4734bab19cccca4c.tar.gz
tcl-dc9796c6e858828861b1339b4734bab19cccca4c.tar.bz2
several initialize and finalize facilities
-rw-r--r--generic/tclClock.c16
-rw-r--r--generic/tclClockFmt.c26
-rw-r--r--generic/tclDate.c19
-rw-r--r--generic/tclDate.h14
-rw-r--r--generic/tclGetDate.y19
5 files changed, 49 insertions, 45 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 6bd6336..a4edb82 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -324,6 +324,8 @@ static void
ClockConfigureClear(
ClockClientData *data)
{
+ ClockFrmScnClearCaches();
+
data->LastTZEpoch = 0;
Tcl_UnsetObjRef(data->SystemTimeZone);
Tcl_UnsetObjRef(data->SystemSetupTZData);
@@ -2609,8 +2611,6 @@ ClockScanObjCmd(
ret = TCL_ERROR;
- info->flags = 0;
-
if (opts.baseObj != NULL) {
if (Tcl_GetWideIntFromObj(interp, opts.baseObj, &baseVal) != TCL_OK) {
return TCL_ERROR;
@@ -2621,8 +2621,6 @@ ClockScanObjCmd(
baseVal = (Tcl_WideInt) now.sec;
}
- yydate.tzName = NULL;
-
/* If time zone not specified use system time zone */
if ( opts.timezoneObj == NULL
|| TclGetString(opts.timezoneObj) == NULL
@@ -2630,7 +2628,7 @@ ClockScanObjCmd(
) {
opts.timezoneObj = ClockGetSystemTimeZone(clientData, interp);
if (opts.timezoneObj == NULL) {
- goto done;
+ return TCL_ERROR;
}
}
@@ -2638,8 +2636,12 @@ ClockScanObjCmd(
opts.timezoneObj = ClockSetupTimeZone(clientData, interp, opts.timezoneObj);
if (opts.timezoneObj == NULL) {
- goto done;
+ return TCL_ERROR;
}
+
+ ClockInitDateInfo(info);
+ yydate.tzName = NULL;
+
// Tcl_SetObjRef(yydate.tzName, opts.timezoneObj);
/*
@@ -2679,7 +2681,7 @@ ClockScanObjCmd(
}
ret = ClockFreeScan(clientData, interp, info, objv[1], &opts);
}
-#if 1
+#if 0
else
if (1) {
/* TODO: Tcled Scan proc - */
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index 48b9b69..ad04e4b 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -31,6 +31,8 @@ TCL_DECLARE_MUTEX(ClockFmtMutex); /* Serializes access to common format list. */
static void ClockFmtScnStorageDelete(ClockFmtScnStorage *fss);
+static void ClockFrmScnFinalize(ClientData clientData);
+
/*
* Clock scan and format facilities.
*/
@@ -148,7 +150,7 @@ ClockFmtScnStorage_GC_Out(ClockFmtScnStorage *entry)
*/
static Tcl_HashTable FmtScnHashTable;
-static int initFmtScnHashTable = 0;
+static int initialized = 0;
inline Tcl_HashEntry *
HashEntry4FmtScn(ClockFmtScnStorage *fss) {
@@ -246,16 +248,18 @@ FindOrCreateFmtScnStorage(
Tcl_MutexLock(&ClockFmtMutex);
/* if not yet initialized */
- if (!initFmtScnHashTable) {
+ if (!initialized) {
/* initialize type */
memcpy(&ClockFmtScnStorageHashKeyType, &tclStringHashKeyType, sizeof(tclStringHashKeyType));
ClockFmtScnStorageHashKeyType.allocEntryProc = ClockFmtScnStorageAllocProc;
ClockFmtScnStorageHashKeyType.freeEntryProc = ClockFmtScnStorageFreeProc;
- initFmtScnHashTable = 1;
/* initialize hash table */
Tcl_InitCustomHashTable(&FmtScnHashTable, TCL_CUSTOM_TYPE_KEYS,
&ClockFmtScnStorageHashKeyType);
+
+ initialized = 1;
+ Tcl_CreateExitHandler(ClockFrmScnFinalize, NULL);
}
/* get or create entry (and alocate storage) */
@@ -845,18 +849,30 @@ done:
}
+MODULE_SCOPE void
+ClockFrmScnClearCaches(void)
+{
+ Tcl_MutexLock(&ClockFmtMutex);
+ /* clear caches ... */
+ Tcl_MutexUnlock(&ClockFmtMutex);
+}
+
static void
-Tcl_GetClockFrmScnFinalize()
+ClockFrmScnFinalize(
+ ClientData clientData) /* Not used. */
{
+ Tcl_MutexLock(&ClockFmtMutex);
#if CLOCK_FMT_SCN_STORAGE_GC_SIZE > 0
/* clear GC */
ClockFmtScnStorage_GC.stackPtr = NULL;
ClockFmtScnStorage_GC.stackBound = NULL;
ClockFmtScnStorage_GC.count = 0;
#endif
- if (initFmtScnHashTable) {
+ if (initialized) {
Tcl_DeleteHashTable(&FmtScnHashTable);
+ initialized = 0;
}
+ Tcl_MutexUnlock(&ClockFmtMutex);
Tcl_MutexFinalize(&ClockFmtMutex);
}
/*
diff --git a/generic/tclDate.c b/generic/tclDate.c
index 97d13b4..5bd96d0 100644
--- a/generic/tclDate.c
+++ b/generic/tclDate.c
@@ -2685,24 +2685,11 @@ TclClockFreeScan(
/*
* yyInput = stringToParse;
- * yyYear = baseYear; yyMonth = baseMonth; yyDay = baseDay;
+ *
+ * ClockInitDateInfo(info) should be executed to pre-init info;
*/
- yyHaveDate = 0;
-
- yyHaveTime = 0;
-
- yyHaveZone = 0;
- yyTimezone = 0; yyDSTmode = DSTmaybe;
-
- yyHaveOrdinalMonth = 0;
- yyMonthOrdinalIncr = 0;
-
- yyHaveDay = 0;
- yyDayOrdinal = 0; yyDayNumber = 0;
-
- yyHaveRel = 0;
- yyRelMonth = 0; yyRelDay = 0; yyRelSeconds = 0; yyRelPointer = NULL;
+ yyDSTmode = DSTmaybe;
info->messages = Tcl_NewObj();
info->separatrix = "";
diff --git a/generic/tclDate.h b/generic/tclDate.h
index 9585258..2010178 100644
--- a/generic/tclDate.h
+++ b/generic/tclDate.h
@@ -40,6 +40,9 @@
*/
typedef struct TclDateFields {
+
+ /* Cacheable fields: */
+
Tcl_WideInt seconds; /* Time expressed in seconds from the Posix
* epoch */
Tcl_WideInt localSeconds; /* Local time expressed in nominal seconds
@@ -60,6 +63,8 @@ typedef struct TclDateFields {
time_t minutes; /* Minutes of day (in-between time only calculation) */
time_t secondOfDay; /* Seconds of day (in-between time only calculation) */
+ /* Non cacheable fields: */
+
Tcl_Obj *tzName; /* Name (or corresponding DST-abbreviation) of the
* time zone, if set the refCount is incremented */
} TclDateFields;
@@ -74,10 +79,11 @@ typedef struct TclDateFields {
typedef struct DateInfo {
const char *dateStart;
const char *dateInput;
- int flags;
TclDateFields date;
+ int flags;
+
time_t dateHaveDate;
time_t dateMeridian;
@@ -138,6 +144,10 @@ typedef struct DateInfo {
#define yyInput (info->dateInput)
#define yyDigitCount (info->dateDigitCount)
+inline void
+ClockInitDateInfo(DateInfo *info) {
+ memset(info, 0, sizeof(DateInfo));
+}
/*
* Structure containing the command arguments supplied to [clock format] and [clock scan]
@@ -298,6 +308,8 @@ MODULE_SCOPE int ClockScan(ClientData clientData, Tcl_Interp *interp,
register DateInfo *info,
Tcl_Obj *strObj, ClockFmtScnCmdArgs *opts);
+MODULE_SCOPE void ClockFrmScnClearCaches(void);
+
/*
* Other externals.
*/
diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y
index 54087ca..9e3623f 100644
--- a/generic/tclGetDate.y
+++ b/generic/tclGetDate.y
@@ -896,24 +896,11 @@ TclClockFreeScan(
/*
* yyInput = stringToParse;
- * yyYear = baseYear; yyMonth = baseMonth; yyDay = baseDay;
+ *
+ * ClockInitDateInfo(info) should be executed to pre-init info;
*/
- yyHaveDate = 0;
-
- yyHaveTime = 0;
-
- yyHaveZone = 0;
- yyTimezone = 0; yyDSTmode = DSTmaybe;
-
- yyHaveOrdinalMonth = 0;
- yyMonthOrdinalIncr = 0;
-
- yyHaveDay = 0;
- yyDayOrdinal = 0; yyDayNumber = 0;
-
- yyHaveRel = 0;
- yyRelMonth = 0; yyRelDay = 0; yyRelSeconds = 0; yyRelPointer = NULL;
+ yyDSTmode = DSTmaybe;
info->messages = Tcl_NewObj();
info->separatrix = "";