summaryrefslogtreecommitdiffstats
path: root/generic/tkCursor.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2009-11-21 17:24:42 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2009-11-21 17:24:42 (GMT)
commit3e32b5193302ae1a6fe572b1abfb23236d62eceb (patch)
tree2f3caa27961649ffb0b7e55228284889014f5c1c /generic/tkCursor.c
parentd610ac08ec4c694f1fd4be42eafce064c3f9d40a (diff)
downloadtk-3e32b5193302ae1a6fe572b1abfb23236d62eceb.zip
tk-3e32b5193302ae1a6fe572b1abfb23236d62eceb.tar.gz
tk-3e32b5193302ae1a6fe572b1abfb23236d62eceb.tar.bz2
[Tcl Bug 2857044]: Corrections following audit of Tcl_ObjType freeing
practises; the typePtr field is now cleared when an object ceases to be of the type. Also remove some anachronistic techniques (pointless casts, mixed assignments and tests, etc.)
Diffstat (limited to 'generic/tkCursor.c')
-rw-r--r--generic/tkCursor.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/generic/tkCursor.c b/generic/tkCursor.c
index f5a4ca4..5ca7b07 100644
--- a/generic/tkCursor.c
+++ b/generic/tkCursor.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkCursor.c,v 1.22 2009/01/09 07:03:31 nijtmans Exp $
+ * RCS: @(#) $Id: tkCursor.c,v 1.23 2009/11/21 17:24:42 dkf Exp $
*/
#include "tkInt.h"
@@ -42,6 +42,7 @@ static void CursorInit(TkDisplay *dispPtr);
static void DupCursorObjProc(Tcl_Obj *srcObjPtr,
Tcl_Obj *dupObjPtr);
static void FreeCursor(TkCursor *cursorPtr);
+static void FreeCursorObj(Tcl_Obj *objPtr);
static void FreeCursorObjProc(Tcl_Obj *objPtr);
static TkCursor * TkcGetCursor(Tcl_Interp *interp, Tk_Window tkwin,
const char *name);
@@ -115,7 +116,7 @@ Tk_AllocCursorFromObj(
* longer in use. Clear the reference.
*/
- FreeCursorObjProc(objPtr);
+ FreeCursorObj(objPtr);
cursorPtr = NULL;
} else if (Tk_Display(tkwin) == cursorPtr->display) {
cursorPtr->resourceRefCount++;
@@ -132,7 +133,7 @@ Tk_AllocCursorFromObj(
if (cursorPtr != NULL) {
TkCursor *firstCursorPtr = Tcl_GetHashValue(cursorPtr->hashPtr);
- FreeCursorObjProc(objPtr);
+ FreeCursorObj(objPtr);
for (cursorPtr = firstCursorPtr; cursorPtr != NULL;
cursorPtr = cursorPtr->nextPtr) {
if (Tk_Display(tkwin) == cursorPtr->display) {
@@ -240,7 +241,7 @@ TkcGetCursor(
}
nameHashPtr = Tcl_CreateHashEntry(&dispPtr->cursorNameTable,
- string, &isNew);
+ string, &isNew);
if (!isNew) {
existingCursorPtr = Tcl_GetHashValue(nameHashPtr);
for (cursorPtr = existingCursorPtr; cursorPtr != NULL;
@@ -274,7 +275,7 @@ TkcGetCursor(
cursorPtr->hashPtr = nameHashPtr;
cursorPtr->nextPtr = existingCursorPtr;
cursorPtr->idHashPtr = Tcl_CreateHashEntry(&dispPtr->cursorIdTable,
- (char *) cursorPtr->cursor, &isNew);
+ (char *) cursorPtr->cursor, &isNew);
if (!isNew) {
Tcl_Panic("cursor already registered in Tk_GetCursor");
}
@@ -340,7 +341,7 @@ Tk_GetCursorFromData(
dataKey.bg = bg;
dataKey.display = Tk_Display(tkwin);
dataHashPtr = Tcl_CreateHashEntry(&dispPtr->cursorDataTable,
- (char *) &dataKey, &isNew);
+ (char *) &dataKey, &isNew);
if (!isNew) {
cursorPtr = Tcl_GetHashValue(dataHashPtr);
cursorPtr->resourceRefCount++;
@@ -373,7 +374,7 @@ Tk_GetCursorFromData(
cursorPtr->hashPtr = dataHashPtr;
cursorPtr->objRefCount = 0;
cursorPtr->idHashPtr = Tcl_CreateHashEntry(&dispPtr->cursorIdTable,
- (char *) cursorPtr->cursor, &isNew);
+ (char *) cursorPtr->cursor, &isNew);
cursorPtr->nextPtr = NULL;
if (!isNew) {
@@ -550,13 +551,13 @@ Tk_FreeCursorFromObj(
Tcl_Obj *objPtr) /* The Tcl_Obj * to be freed. */
{
FreeCursor(GetCursorFromObj(tkwin, objPtr));
- FreeCursorObjProc(objPtr);
+ FreeCursorObj(objPtr);
}
/*
*---------------------------------------------------------------------------
*
- * FreeCursorFromObjProc --
+ * FreeCursorObjProc, FreeCursorObj --
*
* This proc is called to release an object reference to a cursor.
* Called when the object's internal rep is released or when the cached
@@ -576,6 +577,14 @@ static void
FreeCursorObjProc(
Tcl_Obj *objPtr) /* The object we are releasing. */
{
+ FreeCursorObj(objPtr);
+ objPtr->typePtr = NULL;
+}
+
+static void
+FreeCursorObj(
+ Tcl_Obj *objPtr) /* The object we are releasing. */
+{
TkCursor *cursorPtr = objPtr->internalRep.twoPtrValue.ptr1;
if (cursorPtr != NULL) {
@@ -714,7 +723,7 @@ GetCursorFromObj(
for (cursorPtr = Tcl_GetHashValue(hashPtr);
cursorPtr != NULL; cursorPtr = cursorPtr->nextPtr) {
if (Tk_Display(tkwin) == cursorPtr->display) {
- FreeCursorObjProc(objPtr);
+ FreeCursorObj(objPtr);
objPtr->internalRep.twoPtrValue.ptr1 = cursorPtr;
cursorPtr->objRefCount++;
return cursorPtr;