From a9af7dc6963f8f45c24de9a41eb207553b9935c9 Mon Sep 17 00:00:00 2001 From: dkf Date: Sat, 23 Aug 2025 07:57:28 +0000 Subject: corrections (createhashentry is different in 9.1) and cleanup (I like command tables) --- generic/tclOO.c | 57 ++++++++++++++++++++++++++++++----------------- 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