From 31056536d6c5d29bd07df8c3bcae9dde8342d497 Mon Sep 17 00:00:00 2001 From: joye Date: Fri, 18 Apr 2014 19:06:17 +0000 Subject: *** empty log message *** --- src/bltGrElem.C | 16 +++++++++++++++- src/bltGrElem.h | 2 ++ src/bltGrElemBar.C | 6 ++++-- src/bltGrElemLine.C | 6 ++++-- src/bltGrElemOption.C | 1 + src/bltGrPenOp.C | 39 ++++++++++++--------------------------- src/bltGrPenOp.h | 2 -- src/bltGrPenOption.C | 8 ++++++-- src/bltGraph.C | 1 - 9 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/bltGrElem.C b/src/bltGrElem.C index c7ae0e6..cd249df 100644 --- a/src/bltGrElem.C +++ b/src/bltGrElem.C @@ -125,6 +125,15 @@ PenStyle** Element::StyleMap() return dataToStyle; } +void Element::freePen(Pen* penPtr) +{ + if (penPtr != NULL) { + penPtr->refCount_--; + if (penPtr->refCount_ == 0) + delete penPtr; + } +} + void Blt_FreeStylePalette(Blt_Chain stylePalette) { // Skip the first slot. It contains the built-in "normal" pen of the element @@ -134,7 +143,12 @@ void Blt_FreeStylePalette(Blt_Chain stylePalette) for (link = Blt_Chain_NextLink(link); link != NULL; link = next) { next = Blt_Chain_NextLink(link); PenStyle *stylePtr = (PenStyle*)Blt_Chain_GetValue(link); - Blt_FreePen(stylePtr->penPtr); + Pen* penPtr = stylePtr->penPtr; + if (penPtr) { + penPtr->refCount_--; + if (penPtr->refCount_ == 0) + delete penPtr; + } Blt_Chain_DeleteLink(stylePalette, link); } } diff --git a/src/bltGrElem.h b/src/bltGrElem.h index 744bc79..f73f662 100644 --- a/src/bltGrElem.h +++ b/src/bltGrElem.h @@ -159,6 +159,8 @@ class Element { virtual const char* className() =0; virtual const char* typeName() =0; + void freePen(Pen*); + Tk_OptionTable optionTable() {return optionTable_;} void* ops() {return ops_;} }; diff --git a/src/bltGrElemBar.C b/src/bltGrElemBar.C index d4cc617..e4d3d48 100644 --- a/src/bltGrElemBar.C +++ b/src/bltGrElemBar.C @@ -219,9 +219,11 @@ BarElement::~BarElement() BarElementOptions* ops = (BarElementOptions*)ops_; if (ops->activePenPtr) - Blt_FreePen((Pen*)ops->activePenPtr); + freePen((Pen*)ops->activePenPtr); + if (ops->normalPenPtr) - Blt_FreePen((Pen*)ops->normalPenPtr); + freePen((Pen*)ops->normalPenPtr); + if (ops->builtinPenPtr) delete builtinPenPtr; diff --git a/src/bltGrElemLine.C b/src/bltGrElemLine.C index 649cae4..4554edc 100644 --- a/src/bltGrElemLine.C +++ b/src/bltGrElemLine.C @@ -288,9 +288,11 @@ LineElement::~LineElement() LineElementOptions* ops = (LineElementOptions*)ops_; if (ops->activePenPtr) - Blt_FreePen((Pen *)ops->activePenPtr); + freePen((Pen *)ops->activePenPtr); + if (ops->normalPenPtr) - Blt_FreePen((Pen *)ops->normalPenPtr); + freePen((Pen *)ops->normalPenPtr); + if (ops->builtinPenPtr) delete builtinPenPtr; diff --git a/src/bltGrElemOption.C b/src/bltGrElemOption.C index d4f0d7f..fd166fc 100644 --- a/src/bltGrElemOption.C +++ b/src/bltGrElemOption.C @@ -369,6 +369,7 @@ static int GetPenStyleFromObj(Tcl_Interp* interp, Graph* graphPtr, SETWEIGHT(stylePtr->weight, min, max); } + penPtr->refCount_++; stylePtr->penPtr = penPtr; return TCL_OK; } diff --git a/src/bltGrPenOp.C b/src/bltGrPenOp.C index b749652..1b2885a 100644 --- a/src/bltGrPenOp.C +++ b/src/bltGrPenOp.C @@ -145,7 +145,6 @@ static int DeleteOp(Tcl_Interp* interp, Graph* graphPtr, if (graphPtr->getPen(objv[3], &penPtr) != TCL_OK) return TCL_ERROR; - penPtr->flags |= DELETE_PENDING; if (penPtr->refCount_ == 0) delete penPtr; @@ -158,27 +157,24 @@ static int NamesOp(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); if (objc == 3) { Tcl_HashSearch iter; - for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->penTable_, &iter); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { + for (Tcl_HashEntry *hPtr=Tcl_FirstHashEntry(&graphPtr->penTable_, &iter); + hPtr; hPtr=Tcl_NextHashEntry(&iter)) { Pen* penPtr = (Pen*)Tcl_GetHashValue(hPtr); - if ((penPtr->flags & DELETE_PENDING) == 0) - Tcl_ListObjAppendElement(interp, listObjPtr, - Tcl_NewStringObj(penPtr->name_, -1)); + Tcl_ListObjAppendElement(interp, listObjPtr, + Tcl_NewStringObj(penPtr->name_, -1)); } } else { Tcl_HashSearch iter; - for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->penTable_, &iter); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&iter)) { + for (Tcl_HashEntry *hPtr=Tcl_FirstHashEntry(&graphPtr->penTable_, &iter); + hPtr; hPtr=Tcl_NextHashEntry(&iter)) { Pen* penPtr = (Pen*)Tcl_GetHashValue(hPtr); - if ((penPtr->flags & DELETE_PENDING) == 0) { - for (int ii=3; iiname_, pattern)) { - Tcl_ListObjAppendElement(interp, listObjPtr, - Tcl_NewStringObj(penPtr->name_, -1)); - break; - } + for (int ii=3; iiname_, pattern)) { + Tcl_ListObjAppendElement(interp, listObjPtr, + Tcl_NewStringObj(penPtr->name_, -1)); + break; } } } @@ -221,14 +217,3 @@ int Blt_PenOp(Graph* graphPtr, Tcl_Interp* interp, return (*proc)(interp, graphPtr, objc, objv); } - -// Support - -void Blt_FreePen(Pen* penPtr) -{ - if (penPtr != NULL) { - penPtr->refCount_--; - if ((penPtr->refCount_ == 0) && (penPtr->flags & DELETE_PENDING)) - delete penPtr; - } -} diff --git a/src/bltGrPenOp.h b/src/bltGrPenOp.h index 7cf7377..0c7de55 100644 --- a/src/bltGrPenOp.h +++ b/src/bltGrPenOp.h @@ -34,6 +34,4 @@ extern int PenObjConfigure(Tcl_Interp* interp, Graph* graphPtr, Pen* penPtr, int objc, Tcl_Obj* const objv[]); extern int Blt_PenOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]); - -extern void Blt_FreePen(Pen* penPtr); #endif diff --git a/src/bltGrPenOption.C b/src/bltGrPenOption.C index bb13665..da5aee4 100644 --- a/src/bltGrPenOption.C +++ b/src/bltGrPenOption.C @@ -66,6 +66,7 @@ static int PenSetProc(ClientData clientData, Tcl_Interp* interp, if (graphPtr->getPen(*objPtr, &penPtr) != TCL_OK) return TCL_ERROR; + penPtr->refCount_++; *penPtrPtr = penPtr; return TCL_OK; @@ -84,8 +85,11 @@ static Tcl_Obj* PenGetProc(ClientData clientData, Tk_Window tkwin, static void PenFreeProc(ClientData clientData, Tk_Window tkwin, char *ptr) { Pen* penPtr = *(Pen**)ptr; - if (penPtr) - Blt_FreePen(penPtr); + if (penPtr) { + penPtr->refCount_--; + if (penPtr->refCount_ == 0) + delete penPtr; + } } diff --git a/src/bltGraph.C b/src/bltGraph.C index 46c2450..d1c0f0e 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -905,7 +905,6 @@ int Graph::getPen(Tcl_Obj* objPtr, Pen** penPtrPtr) } *penPtrPtr = (Pen*)Tcl_GetHashValue(hPtr); - (*penPtrPtr)->refCount_++; return TCL_OK; } -- cgit v0.12