Attachment "tkConfig.c.patch" to
ticket [2492179f]
added by
nijtmans
2009-12-11 22:19:05.
*** generic/tkConfig.c 2009-12-11 16:13:18.520064000 +0100
--- generic/tkConfig.c 2009-12-11 16:10:57.331398200 +0100
***************
*** 102,107 ****
--- 102,109 ----
* chain. */
int numOptions; /* The number of items in the options array
* below. */
+ int refCount2; /* Reference counter for controlling the freeing
+ * of the memory occupied by this OptionTable */
Option options[1]; /* Information about the individual options in
* the table. This must be the last field in
* the structure: the actual size of the array
***************
*** 127,132 ****
--- 129,135 ----
static Option * GetOptionFromObj(Tcl_Interp *interp,
Tcl_Obj *objPtr, OptionTable *tablePtr);
static int ObjectIsEmpty(Tcl_Obj *objPtr);
+ static void FreeOptionInternalRep(Tcl_Obj *objPtr);
static int SetOptionFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
/*
***************
*** 138,144 ****
const Tcl_ObjType tkOptionObjType = {
"option", /* name */
! NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
NULL, /* updateStringProc */
SetOptionFromAny /* setFromAnyProc */
--- 141,147 ----
const Tcl_ObjType tkOptionObjType = {
"option", /* name */
! FreeOptionInternalRep, /* freeIntRepProc */
NULL, /* dupIntRepProc */
NULL, /* updateStringProc */
SetOptionFromAny /* setFromAnyProc */
***************
*** 222,227 ****
--- 225,231 ----
tablePtr = (OptionTable *) (ckalloc(sizeof(OptionTable)
+ (numOptions * sizeof(Option))));
tablePtr->refCount = 1;
+ tablePtr->refCount2 = 1;
tablePtr->hashEntryPtr = hashEntryPtr;
tablePtr->nextPtr = NULL;
tablePtr->numOptions = numOptions;
***************
*** 357,363 ****
}
}
Tcl_DeleteHashEntry(tablePtr->hashEntryPtr);
! ckfree((char *) tablePtr);
}
/*
--- 361,370 ----
}
}
Tcl_DeleteHashEntry(tablePtr->hashEntryPtr);
! tablePtr->refCount2--;
! if (tablePtr->refCount2 <= 0) {
! ckfree((char *) tablePtr);
! }
}
/*
***************
*** 1153,1158 ****
--- 1160,1166 ----
objPtr->internalRep.twoPtrValue.ptr1 = (void *) tablePtr;
objPtr->internalRep.twoPtrValue.ptr2 = (void *) bestPtr;
objPtr->typePtr = &tkOptionObjType;
+ tablePtr->refCount2++;
return bestPtr;
error:
***************
*** 1229,1234 ****
--- 1237,1277 ----
NULL);
return TCL_ERROR;
}
+
+ /*
+ *----------------------------------------------------------------------
+ *
+ * FreeOptionInternalRep --
+ *
+ * Part of the option Tcl object type implementation. Frees the storage
+ * associated with a option object's internal representation unless it
+ * is still in use.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * The option object's internal rep is marked invalid and its memory
+ * gets freed unless it is still in use somewhere. In that case the
+ * cleanup is delayed until the last reference goes away.
+ *
+ *----------------------------------------------------------------------
+ */
+
+ static void
+ FreeOptionInternalRep(
+ register Tcl_Obj *objPtr) /* Object whose internal rep to free. */
+ {
+ register OptionTable *tablePtr = (OptionTable *) objPtr->internalRep.twoPtrValue.ptr1;
+
+ tablePtr->refCount2--;
+ if (tablePtr->refCount2 <= 0) {
+ ckfree((char *)tablePtr);
+ }
+ objPtr->typePtr = NULL;
+ objPtr->internalRep.twoPtrValue.ptr1 = NULL;
+ objPtr->internalRep.twoPtrValue.ptr2 = NULL;
+ }
/*
*--------------------------------------------------------------