diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2025-08-23 07:57:28 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2025-08-23 07:57:28 (GMT) |
| commit | a9af7dc6963f8f45c24de9a41eb207553b9935c9 (patch) | |
| tree | c9f16c89845f638b7e1a3a8d8ae13e6719cea6ac | |
| parent | 14b58a3e203bd9d593055a6a131e747e815b4e2d (diff) | |
| download | tcl-a9af7dc6963f8f45c24de9a41eb207553b9935c9.zip tcl-a9af7dc6963f8f45c24de9a41eb207553b9935c9.tar.gz tcl-a9af7dc6963f8f45c24de9a41eb207553b9935c9.tar.bz2 | |
corrections (createhashentry is different in 9.1) and cleanup (I like command tables)
| -rw-r--r-- | generic/tclOO.c | 57 | ||||
| -rw-r--r-- | generic/tclOODefineCmds.c | 9 |
2 files changed, 41 insertions, 25 deletions
diff --git a/generic/tclOO.c b/generic/tclOO.c index ba770f4..0da8b7f 100644 --- a/generic/tclOO.c +++ b/generic/tclOO.c @@ -17,10 +17,36 @@ #include "tclOOInt.h" /* + * Commands in oo and oo::Helpers. + */ + +static const struct StdCommands { + const char *name; + Tcl_ObjCmdProc *objProc; + Tcl_ObjCmdProc *nreProc; + CompileProc *compileProc; +} ooCmds[] = { + {"define", TclOODefineObjCmd, NULL, NULL}, + {"objdefine", TclOOObjDefObjCmd, NULL, NULL}, + {"copy", TclOOCopyObjectCmd, NULL, NULL}, + {"DelegateName", TclOODelegateNameObjCmd, NULL, NULL}, + {NULL, NULL, NULL, NULL} +}, helpCmds[] = { + {"callback", TclOOCallbackObjCmd, NULL, NULL}, + {"mymethod", TclOOCallbackObjCmd, NULL, NULL}, + {"classvariable", TclOOClassVariableObjCmd, NULL, NULL}, + {"link", TclOOLinkObjCmd, NULL, NULL}, + {"next", NULL, TclOONextObjCmd, TclCompileObjectNextCmd}, + {"nextto", NULL, TclOONextToObjCmd, TclCompileObjectNextToCmd}, + {"self", TclOOSelfObjCmd, NULL, TclCompileObjectSelfCmd}, + {NULL, NULL, NULL, NULL} +}; + +/* * Commands in oo::define and oo::objdefine. */ -static const struct { +static const struct DefineCommands { const char *name; Tcl_ObjCmdProc *objProc; int flag; @@ -437,25 +463,16 @@ InitFoundation( * ensemble. */ - CreateCmdInNS(interp, fPtr->helpersNs, "callback", - TclOOCallbackObjCmd, NULL, NULL, 0); - CreateCmdInNS(interp, fPtr->helpersNs, "mymethod", - TclOOCallbackObjCmd, NULL, NULL, 0); - CreateCmdInNS(interp, fPtr->helpersNs, "classvariable", - TclOOClassVariableObjCmd, NULL, NULL, 0); - CreateCmdInNS(interp, fPtr->helpersNs, "link", - TclOOLinkObjCmd, NULL, NULL, 0); - CreateCmdInNS(interp, fPtr->helpersNs, "next", - NULL, TclOONextObjCmd, TclCompileObjectNextCmd); - CreateCmdInNS(interp, fPtr->helpersNs, "nextto", - NULL, TclOONextToObjCmd, TclCompileObjectNextToCmd); - CreateCmdInNS(interp, fPtr->helpersNs, "self", - TclOOSelfObjCmd, NULL, TclCompileObjectSelfCmd); - - CreateCmdInNS(interp, fPtr->ooNs, "define", TclOODefineObjCmd, NULL, NULL); - CreateCmdInNS(interp, fPtr->ooNs, "objdefine", TclOOObjDefObjCmd, NULL, NULL); - CreateCmdInNS(interp, fPtr->ooNs, "copy", TclOOCopyObjectCmd, NULL, NULL); - CreateCmdInNS(interp, fPtr->ooNs, "DelegateName", TclOODelegateNameObjCmd, NULL, NULL, 0); + for (i = 0 ; helpCmds[i].name ; i++) { + CreateCmdInNS(interp, fPtr->helpersNs, helpCmds[i].name, + helpCmds[i].objProc, helpCmds[i].nreProc, + helpCmds[i].compileProc); + } + for (i = 0 ; ooCmds[i].name ; i++) { + CreateCmdInNS(interp, fPtr->ooNs, ooCmds[i].name, + ooCmds[i].objProc, ooCmds[i].nreProc, + ooCmds[i].compileProc); + } TclOOInitInfo(interp); diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index 6da3a33..8d99b07 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -2735,7 +2735,7 @@ Slot_AppendNew( Tcl_Obj *const *objv) { Object *oPtr = (Object *) Tcl_ObjectContextObject(context); - int skip = Tcl_ObjectContextSkippedArgs(context), code; + int skip = Tcl_ObjectContextSkippedArgs(context), code, isNew; Tcl_Obj *resolved, *list, **listv; Tcl_Size listc, i; Tcl_HashTable unique; @@ -2767,7 +2767,7 @@ Slot_AppendNew( } Tcl_InitObjHashTable(&unique); for (i=0 ; i<listc; i++) { - Tcl_CreateHashEntry(&unique, listv[i], NULL); + Tcl_CreateHashEntry(&unique, listv[i], &isNew); } /* Append the new items if they're not already there */ @@ -2779,7 +2779,6 @@ Slot_AppendNew( } TclListObjGetElements(NULL, resolved, &listc, &listv); for (i=0 ; i<listc; i++) { - int isNew; Tcl_CreateHashEntry(&unique, listv[i], &isNew); if (isNew) { Tcl_ListObjAppendElement(interp, list, listv[i]); @@ -2890,7 +2889,7 @@ Slot_Remove( Tcl_Obj *const *objv) { Object *oPtr = (Object *) Tcl_ObjectContextObject(context); - int skip = Tcl_ObjectContextSkippedArgs(context), code; + int skip = Tcl_ObjectContextSkippedArgs(context), code, isNew; Tcl_Size listc, i; Tcl_Obj *resolved, *oldList, *newList, **listv; Tcl_HashTable removeSet; @@ -2918,7 +2917,7 @@ Slot_Remove( TclListObjGetElements(NULL, resolved, &listc, &listv); Tcl_InitObjHashTable(&removeSet); for (i=0 ; i<listc; i++) { - Tcl_CreateHashEntry(&removeSet, listv[i], NULL); + Tcl_CreateHashEntry(&removeSet, listv[i], &isNew); } Tcl_DecrRefCount(resolved); |
