summaryrefslogtreecommitdiffstats
path: root/generic/tclClockFmt.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-09 16:19:58 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-06-09 16:19:58 (GMT)
commit5abc5a13387207ec3a15e9ca49d13d48ed96b75a (patch)
tree3a842a0dfaecf0a3e860eb484f09b47110eab577 /generic/tclClockFmt.c
parent27de590700d5ed4c4fcb9e1e54245126a4ed14e3 (diff)
downloadtcl-5abc5a13387207ec3a15e9ca49d13d48ed96b75a.zip
tcl-5abc5a13387207ec3a15e9ca49d13d48ed96b75a.tar.gz
tcl-5abc5a13387207ec3a15e9ca49d13d48ed96b75a.tar.bz2
(cherry-pick) Put ClockFmtScnStorageHashKeyType (and some more) in read-only memory
Diffstat (limited to 'generic/tclClockFmt.c')
-rw-r--r--generic/tclClockFmt.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/generic/tclClockFmt.c b/generic/tclClockFmt.c
index faf0d87..c9b30bf 100644
--- a/generic/tclClockFmt.c
+++ b/generic/tclClockFmt.c
@@ -22,20 +22,28 @@ static void ClockFmtObj_DupInternalRep(Tcl_Obj *srcPtr, Tcl_Obj *copyPtr);
static void ClockFmtObj_FreeInternalRep(Tcl_Obj *objPtr);
static int ClockFmtObj_SetFromAny(Tcl_Interp *, Tcl_Obj *objPtr);
static void ClockFmtObj_UpdateString(Tcl_Obj *objPtr);
+static Tcl_HashEntry * ClockFmtScnStorageAllocProc(Tcl_HashTable *, void *keyPtr);
+static void ClockFmtScnStorageFreeProc(Tcl_HashEntry *hPtr);
+static void ClockFmtScnStorageDelete(ClockFmtScnStorage *fss);
TCL_DECLARE_MUTEX(ClockFmtMutex); /* Serializes access to common format list. */
-static void ClockFmtScnStorageDelete(ClockFmtScnStorage *fss);
-
#ifndef TCL_CLOCK_FULL_COMPAT
#define TCL_CLOCK_FULL_COMPAT 1
#endif
/*
- * Derivation of tclStringHashKeyType with another allocEntryProc
+ * Derivation of tclStringHashKeyType with extra memory management trickery.
*/
-static Tcl_HashKeyType ClockFmtScnStorageHashKeyType;
+static const Tcl_HashKeyType ClockFmtScnStorageHashKeyType = {
+ TCL_HASH_KEY_TYPE_VERSION, /* version */
+ 0, /* flags */
+ TclHashStringKey, /* hashKeyProc */
+ TclCompareStringKeys, /* compareKeysProc */
+ ClockFmtScnStorageAllocProc, /* allocEntryProc */
+ ClockFmtScnStorageFreeProc /* freeEntryProc */
+};
#define IntFieldAt(info, offset) \
((int *) (((char *) (info)) + (offset)))
@@ -543,7 +551,7 @@ FmtScn4HashEntry(
static Tcl_HashEntry *
ClockFmtScnStorageAllocProc(
- TCL_UNUSED(Tcl_HashTable *), /* Hash table. */
+ TCL_UNUSED(Tcl_HashTable *),/* Hash table. */
void *keyPtr) /* Key to store in the hash table entry. */
{
ClockFmtScnStorage *fss;
@@ -757,7 +765,7 @@ ClockFmtObj_UpdateString(
* Returns tcl object with key or format object if not localizable.
*
* Side effects:
- * Converts given format object to ClockFmtObjType on demand for caching
+ * Converts given format object to ClockFmtObjType on demand for caching
* the key inside its internal representation.
*
*----------------------------------------------------------------------
@@ -803,7 +811,7 @@ ClockFrmObjGetLocFmtKey(
* Returns scan/format storage pointer to ClockFmtScnStorage.
*
* Side effects:
- * Converts given format object to ClockFmtObjType on demand for caching
+ * Converts given format object to ClockFmtObjType on demand for caching
* the format storage reference inside its internal representation.
* Increments objRefCount of the ClockFmtScnStorage reference.
*
@@ -824,11 +832,6 @@ FindOrCreateFmtScnStorage(
/* if not yet initialized */
if (!initialized) {
- /* initialize type */
- memcpy(&ClockFmtScnStorageHashKeyType, &tclStringHashKeyType, sizeof(tclStringHashKeyType));
- ClockFmtScnStorageHashKeyType.allocEntryProc = ClockFmtScnStorageAllocProc;
- ClockFmtScnStorageHashKeyType.freeEntryProc = ClockFmtScnStorageFreeProc;
-
/* initialize hash table */
Tcl_InitCustomHashTable(&FmtScnHashTable, TCL_CUSTOM_TYPE_KEYS,
&ClockFmtScnStorageHashKeyType);
@@ -1240,9 +1243,13 @@ ObjListSearch(
/* currently unused */
static int
-LocaleListSearch(ClockFmtScnCmdArgs *opts,
- DateInfo *info, int mcKey, int *val,
- int minLen, int maxLen)
+LocaleListSearch(
+ ClockFmtScnCmdArgs *opts,
+ DateInfo *info,
+ int mcKey,
+ int *val,
+ int minLen,
+ int maxLen)
{
Tcl_Obj **lstv;
Tcl_Size lstc;
@@ -1415,7 +1422,7 @@ ClockMCGetMultiListIdxTree(
* Results:
* TCL_OK - match found and the index stored in *val,
* TCL_RETURN - not matched or ambigous,
- * TCL_ERROR - in error case.
+ * TCL_ERROR - in error case.
*
* Side effects:
* Input points to end of the found token in string.
@@ -1769,7 +1776,7 @@ ClockScnToken_JDN_Proc(
}
s = p;
while (p < end && isdigit(UCHAR(*p))) {
- fractJDDiv *= 10;
+ fractJDDiv *= 10;
p++;
}
if (Clock_str2int(&fractJD, s, p, 1) != TCL_OK) {
@@ -2648,7 +2655,7 @@ ClockScan(
}
if (flags & (CLF_ISO8601WEEK | CLF_ISO8601YEAR)) {
if ((flags & (CLF_ISO8601YEAR | CLF_YEAR)) == CLF_YEAR) {
- /* for calculations expected iso year */
+ /* for calculations expected iso year */
info->date.iso8601Year = yyYear;
} else if (info->date.iso8601Year < 100) {
if (!(flags & CLF_ISO8601CENTURY)) {
@@ -2661,7 +2668,7 @@ ClockScan(
}
}
if ((flags & (CLF_ISO8601YEAR | CLF_YEAR)) == CLF_ISO8601YEAR) {
- /* for calculations expected year (e. g. CLF_ISO8601WEEK not set) */
+ /* for calculations expected year (e. g. CLF_ISO8601WEEK not set) */
yyYear = info->date.iso8601Year;
}
}
@@ -2861,7 +2868,7 @@ ClockFmtToken_JDN_Proc(
fractJD = dateFmt->date.secondOfDay
- (int)tok->map->offs; /* 0 for calendar or 43200 for astro JD */
if (fractJD < 0) {
- intJD--;
+ intJD--;
fractJD += SECONDS_PER_DAY;
}
if (fractJD && intJD < 0) { /* avoid jump over 0, by negative JD's */