From 61e2cc66b9aa6f9aa0cb06dd99a5cdb118999c58 Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 22 Aug 2025 17:36:48 +0000 Subject: Move a bit of internal machinery (backport) --- generic/tclOO.c | 1 + generic/tclOOBasic.c | 37 ++++++++++++++++++++++++++++++++++++- generic/tclOOInt.h | 1 + generic/tclOOScript.h | 3 --- tools/tclOOScript.tcl | 14 -------------- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/generic/tclOO.c b/generic/tclOO.c index d9144fd..ced2cb1 100644 --- a/generic/tclOO.c +++ b/generic/tclOO.c @@ -454,6 +454,7 @@ InitFoundation( 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); TclOOInitInfo(interp); diff --git a/generic/tclOOBasic.c b/generic/tclOOBasic.c index 342fa9e..4d34a9c 100644 --- a/generic/tclOOBasic.c +++ b/generic/tclOOBasic.c @@ -1519,7 +1519,8 @@ TclOOClassVariableObjCmd( } // Create the new variable and link it to otherPtr. - if (TclPtrObjMakeUpvarIdx(interp, otherPtr, objv[i], 0, -1) != TCL_OK) { + if (TclPtrObjMakeUpvarIdx(interp, otherPtr, objv[i], 0, + TCL_INDEX_NONE) != TCL_OK) { return TCL_ERROR; } } @@ -1528,6 +1529,40 @@ TclOOClassVariableObjCmd( } /* + * ---------------------------------------------------------------------- + * + * TclOODelegateNameObjCmd -- + * + * Implementation of the [oo::DelegateName] command, which is a utility + * that gets the name of the class delegate for a class. It's trivial, + * but makes working with them much easier as delegate names are + * intentionally hard to create by accident. + * + * Not part of TclOO public API. No public documentation. + * + * ---------------------------------------------------------------------- + */ +int +TclOODelegateNameObjCmd( + TCL_UNUSED(void *), + Tcl_Interp *interp, + int objc, + Tcl_Obj *const *objv) +{ + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "class"); + return TCL_ERROR; + } + Class *clsPtr = TclOOGetClassFromObj(interp, objv[1]); + if (clsPtr == NULL) { + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s:: oo ::delegate", + clsPtr->thisPtr->namespacePtr->fullName)); + return TCL_OK; +} + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h index abb26b8..d5dc36c 100644 --- a/generic/tclOOInt.h +++ b/generic/tclOOInt.h @@ -521,6 +521,7 @@ MODULE_SCOPE Tcl_ObjCmdProc TclOOUnknownDefinition; MODULE_SCOPE Tcl_ObjCmdProc TclOOCallbackObjCmd; MODULE_SCOPE Tcl_ObjCmdProc TclOOClassVariableObjCmd; MODULE_SCOPE Tcl_ObjCmdProc TclOOCopyObjectCmd; +MODULE_SCOPE Tcl_ObjCmdProc TclOODelegateNameObjCmd; MODULE_SCOPE Tcl_ObjCmdProc TclOONextObjCmd; MODULE_SCOPE Tcl_ObjCmdProc TclOONextToObjCmd; MODULE_SCOPE Tcl_ObjCmdProc TclOOSelfObjCmd; diff --git a/generic/tclOOScript.h b/generic/tclOOScript.h index dcc44c0..643e536 100644 --- a/generic/tclOOScript.h +++ b/generic/tclOOScript.h @@ -52,9 +52,6 @@ static const char *tclOOSetupScript = "\t\t\trename $cmd {}\n" "\t\t}\n" "\t}\n" -"\tproc DelegateName {class} {\n" -"\t\tstring cat [info object namespace $class] {:: oo ::delegate}\n" -"\t}\n" "\tproc MixinClassDelegates {class} {\n" "\t\tif {![info object isa class $class]} {\n" "\t\t\treturn\n" diff --git a/tools/tclOOScript.tcl b/tools/tclOOScript.tcl index 3f34c56..2cf40e1 100644 --- a/tools/tclOOScript.tcl +++ b/tools/tclOOScript.tcl @@ -65,20 +65,6 @@ # ---------------------------------------------------------------------- # - # DelegateName -- - # - # Utility that gets the name of the class delegate for a class. It's - # trivial, but makes working with them much easier as delegate names are - # intentionally hard to create by accident. - # - # ---------------------------------------------------------------------- - - proc DelegateName {class} { - string cat [info object namespace $class] {:: oo ::delegate} - } - - # ---------------------------------------------------------------------- - # # MixinClassDelegates -- # # Support code called *after* [oo::define] inside the constructor of a -- cgit v0.12