From a3f289609685a070bec77addfaf581d00e607e50 Mon Sep 17 00:00:00 2001 From: treectrl Date: Thu, 26 Oct 2006 03:00:32 +0000 Subject: Changed dynamic-option code to use AllocHax_xxx. --- generic/tkTreeCtrl.h | 14 +++-- generic/tkTreeElem.c | 5 +- generic/tkTreeStyle.c | 8 +-- generic/tkTreeUtils.c | 149 ++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 130 insertions(+), 46 deletions(-) diff --git a/generic/tkTreeCtrl.h b/generic/tkTreeCtrl.h index 061fb0e..4353774 100644 --- a/generic/tkTreeCtrl.h +++ b/generic/tkTreeCtrl.h @@ -7,7 +7,7 @@ * Copyright (c) 2002-2003 Christian Krone * Copyright (c) 2003 ActiveState Corporation * - * RCS: @(#) $Id: tkTreeCtrl.h,v 1.57 2006/10/25 03:48:15 treectrl Exp $ + * RCS: @(#) $Id: tkTreeCtrl.h,v 1.58 2006/10/26 03:00:32 treectrl Exp $ */ #include "tkPort.h" @@ -1028,14 +1028,16 @@ struct DynamicOption typedef void (DynamicOptionInitProc)(char *data); -extern DynamicOption *DynamicOption_AllocIfNeeded(DynamicOption **firstPtr, - int id, int size, DynamicOptionInitProc *init); +extern DynamicOption *DynamicOption_AllocIfNeeded(TreeCtrl *tree, + DynamicOption **firstPtr, int id, int size, DynamicOptionInitProc *init); extern char *DynamicOption_FindData(DynamicOption *first, int id); -extern void DynamicOption_Free(DynamicOption *first); - +extern void DynamicOption_Free(TreeCtrl *tree, DynamicOption *first, + Tk_OptionSpec *optionTable); +extern void DynamicOption_Free1(TreeCtrl *tree, DynamicOption **firstPtr, + int id, int size); extern int DynamicCO_Init(Tk_OptionSpec *optionTable, CONST char *optionName, int id, int size, int objOffset, int internalOffset, - Tk_ObjCustomOption *custom,DynamicOptionInitProc *init); + Tk_ObjCustomOption *custom, DynamicOptionInitProc *init); extern Tk_ObjCustomOption pixelsCO; extern Tk_ObjCustomOption stringCO; diff --git a/generic/tkTreeElem.c b/generic/tkTreeElem.c index aa7c133..ccffa78 100644 --- a/generic/tkTreeElem.c +++ b/generic/tkTreeElem.c @@ -5,7 +5,7 @@ * * Copyright (c) 2002-2006 Tim Baker * - * RCS: @(#) $Id: tkTreeElem.c,v 1.45 2006/10/25 03:47:53 treectrl Exp $ + * RCS: @(#) $Id: tkTreeElem.c,v 1.46 2006/10/26 03:00:32 treectrl Exp $ */ #include "tkTreeCtrl.h" @@ -2647,7 +2647,7 @@ if (tree->debug.enable && tree->debug.textLayout) dbwin(" textWidth %d\n", te if (wrap == TEXT_WRAP_WORD) flags |= TK_WHOLE_WORDS; - opt = (DynamicOption *) DynamicOption_AllocIfNeeded(&elem->options, + opt = (DynamicOption *) DynamicOption_AllocIfNeeded(tree, &elem->options, 1007, sizeof(ElementTextLayout2), NULL); etl2 = (ElementTextLayout2 *) opt->data; @@ -2747,6 +2747,7 @@ static void DeleteProcText(ElementArgs *args) etl2 = (ElementTextLayout2 *) DynamicOption_FindData(elem->options, 1007); if (etl2 != NULL && etl2->layout != NULL) TextLayout_Free(etl2->layout); + DynamicOption_Free1(tree, &elem->options, 1007, sizeof(ElementTextLayout2)); #ifdef TEXTVAR TextTraceUnset(tree->interp, elemX); #endif diff --git a/generic/tkTreeStyle.c b/generic/tkTreeStyle.c index d1adc1c..9802715 100644 --- a/generic/tkTreeStyle.c +++ b/generic/tkTreeStyle.c @@ -5,7 +5,7 @@ * * Copyright (c) 2002-2006 Tim Baker * - * RCS: @(#) $Id: tkTreeStyle.c,v 1.54 2006/10/18 03:49:18 treectrl Exp $ + * RCS: @(#) $Id: tkTreeStyle.c,v 1.55 2006/10/26 03:01:17 treectrl Exp $ */ #include "tkTreeCtrl.h" @@ -2436,7 +2436,7 @@ Element_FreeResources( Tk_FreeConfigOptions((char *) elem, typePtr->optionTable, tree->tkwin); - DynamicOption_Free(elem->options); + DynamicOption_Free(tree, elem->options, typePtr->optionSpecs); #ifdef ALLOC_HAX AllocHax_Free(tree->allocData, typePtr->name, (char *) elem, typePtr->size); #else @@ -2858,9 +2858,9 @@ Element_CreateAndConfig( { (*type->deleteProc)(&args); Tk_FreeConfigOptions((char *) elem, - elem->typePtr->optionTable, + type->optionTable, tree->tkwin); - DynamicOption_Free(elem->options); + DynamicOption_Free(tree, elem->options, type->optionSpecs); #ifdef ALLOC_HAX AllocHax_Free(tree->allocData, type->name, (char *) elem, type->size); #else diff --git a/generic/tkTreeUtils.c b/generic/tkTreeUtils.c index 3fb1046..235714b 100644 --- a/generic/tkTreeUtils.c +++ b/generic/tkTreeUtils.c @@ -5,7 +5,7 @@ * * Copyright (c) 2002-2006 Tim Baker * - * RCS: @(#) $Id: tkTreeUtils.c,v 1.44 2006/10/18 22:18:47 treectrl Exp $ + * RCS: @(#) $Id: tkTreeUtils.c,v 1.45 2006/10/26 03:00:32 treectrl Exp $ */ #include "tkTreeCtrl.h" @@ -1809,7 +1809,7 @@ void TextLayout_Draw( * * TreeCtrl_GetPadAmountFromObj -- * - * Parse a pad amount configuration options. + * Parse a pad amount configuration option. * A pad amount (typically the value of an option -XXXpadx or * -XXXpady, where XXX may be a possibly empty string) can * be either a single pixel width, or a list of two pixel widths. @@ -4848,6 +4848,8 @@ PerStateCO_Init( #define DEBUG_DYNAMICxxx +static CONST char *DynamicOptionUid = "DynamicOption"; + /* *---------------------------------------------------------------------- * @@ -4928,6 +4930,7 @@ DynamicOption_FindData( DynamicOption * DynamicOption_AllocIfNeeded( + TreeCtrl *tree, DynamicOption **firstPtr, /* Pointer to the head of linked list. * Will be updated if a new record is * created. */ @@ -4947,7 +4950,12 @@ DynamicOption_AllocIfNeeded( #ifdef DEBUG_DYNAMIC dbwin("DynamicOption_AllocIfNeeded allocated id=%d\n", id); #endif +#ifdef ALLOC_HAX + opt = (DynamicOption *) AllocHax_Alloc(tree->allocData, DynamicOptionUid, + Tk_Offset(DynamicOption, data) + size); +#else opt = (DynamicOption *) ckalloc(Tk_Offset(DynamicOption, data) + size); +#endif opt->id = id; memset(opt->data, '\0', size); if (init != NULL) @@ -4960,37 +4968,6 @@ dbwin("DynamicOption_AllocIfNeeded allocated id=%d\n", id); /* *---------------------------------------------------------------------- * - * DynamicOption_Free -- - * - * Free a linked list of dynamic-option records. This gets called - * after Tk_FreeConfigOptions. - * - * Results: - * None. - * - * Side effects: - * Memory may be freed. - * - *---------------------------------------------------------------------- - */ - -void -DynamicOption_Free( - DynamicOption *first - ) -{ - DynamicOption *opt = first; - - while (opt != NULL) { - DynamicOption *next = opt->next; - ckfree((char *) opt); - opt = next; - } -} - -/* - *---------------------------------------------------------------------- - * * DynamicCO_Set -- * DynamicCO_Get -- * DynamicCO_Restore -- @@ -5061,7 +5038,7 @@ DynamicCO_Set( /* Get the dynamic option record. Create it if needed, and update the * linked list of dynamic options. */ - opt = DynamicOption_AllocIfNeeded(firstPtr, cd->id, cd->size, cd->init); + opt = DynamicOption_AllocIfNeeded(tree, firstPtr, cd->id, cd->size, cd->init); save = (DynamicCOSave *) ckalloc(sizeof(DynamicCOSave)); #ifdef DEBUG_DYNAMIC @@ -5269,6 +5246,110 @@ dbwin("DynamicCO_Init id=%d size=%d objOffset=%d internalOffset=%d custom->name= /* *---------------------------------------------------------------------- * + * DynamicOption_Free -- + * + * Free a linked list of dynamic-option records. This gets called + * after Tk_FreeConfigOptions. + * + * Results: + * None. + * + * Side effects: + * Memory may be freed. + * + *---------------------------------------------------------------------- + */ + +void +DynamicOption_Free( + TreeCtrl *tree, + DynamicOption *first, + Tk_OptionSpec *optionTable + ) +{ + DynamicOption *opt = first; + DynamicCOClientData *cd; + Tk_ObjCustomOption *co; + int i; + + while (opt != NULL) { + DynamicOption *next = opt->next; + + for (i = 0; optionTable[i].type != TK_OPTION_END; i++) { + + if (optionTable[i].type != TK_OPTION_CUSTOM) + continue; + + co = (Tk_ObjCustomOption *) optionTable[i].clientData; + if (co->setProc != DynamicCO_Set) + continue; + + cd = (DynamicCOClientData *) co->clientData; + if (cd->id != opt->id) + continue; + +#ifdef ALLOC_HAX + AllocHax_Free(tree->allocData, DynamicOptionUid, (char *) opt, + Tk_Offset(DynamicOption, data) + cd->size); +#else + ckfree((char *) opt); +#endif + } + + opt = next; + } +} + +/* + *---------------------------------------------------------------------- + * + * DynamicOption_Free1 -- + * + * Free a single dynamic-option record. This is a big hack so that + * dynamic-option records that aren't associated with a Tk_OptionSpec + * array can be used. + * + * Results: + * None. + * + * Side effects: + * Memory may be freed. + * + *---------------------------------------------------------------------- + */ + +void +DynamicOption_Free1( + TreeCtrl *tree, + DynamicOption **firstPtr, + int id, + int size + ) +{ + DynamicOption *opt = *firstPtr, *prev = NULL; + + while (opt != NULL) { + if (opt->id == id) { + if (prev == NULL) + *firstPtr = opt->next; + else + prev->next = opt->next; +#ifdef ALLOC_HAX + AllocHax_Free(tree->allocData, DynamicOptionUid, (char *) opt, + Tk_Offset(DynamicOption, data) + size); +#else + ckfree((char *) opt); +#endif + return; + } + prev = opt; + opt = opt->next; + } +} + +/* + *---------------------------------------------------------------------- + * * StringCO_Set -- * StringCO_Get -- * StringCO_Restore -- -- cgit v0.12