Skip to content

Commit

Permalink
Move table processing of DeclaredClassMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfellows committed Nov 8, 2024
1 parent a4db2b5 commit 4ab16b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
12 changes: 3 additions & 9 deletions generic/tclOO.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,8 @@ InitFoundation(
* Basic method declarations for the core classes.
*/

for (i = 0 ; objMethods[i].name ; i++) {
TclOONewBasicMethod(fPtr->objectCls, &objMethods[i]);
}
for (i = 0 ; clsMethods[i].name ; i++) {
TclOONewBasicMethod(fPtr->classCls, &clsMethods[i]);
}
TclOODefineBasicMethods(fPtr->objectCls, objMethods);
TclOODefineBasicMethods(fPtr->classCls, clsMethods);

/*
* Finish setting up the class of classes by marking the 'new' method as
Expand Down Expand Up @@ -458,9 +454,7 @@ InitFoundation(
Tcl_Object cfgCls = Tcl_NewObjectInstance(interp,
(Tcl_Class) fPtr->classCls, "::oo::configuresupport::configurable",
NULL, TCL_INDEX_NONE, NULL, 0);
for (i = 0 ; cfgMethods[i].name ; i++) {
TclOONewBasicMethod(((Object *) cfgCls)->classPtr, &cfgMethods[i]);
}
TclOODefineBasicMethods(((Object *) cfgCls)->classPtr, cfgMethods);

/*
* Don't have handles to these namespaces, so use Tcl_CreateObjCommand.
Expand Down
2 changes: 1 addition & 1 deletion generic/tclOOInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ MODULE_SCOPE Tcl_Var TclOOLookupObjectVar(Tcl_Interp *interp,
MODULE_SCOPE int TclNRObjectContextInvokeNext(Tcl_Interp *interp,
Tcl_ObjectContext context, Tcl_Size objc,
Tcl_Obj *const *objv, Tcl_Size skip);
MODULE_SCOPE void TclOONewBasicMethod(Class *clsPtr,
MODULE_SCOPE void TclOODefineBasicMethods(Class *clsPtr,
const DeclaredClassMethod *dcm);
MODULE_SCOPE Tcl_Obj * TclOOObjectName(Tcl_Interp *interp, Object *oPtr);
MODULE_SCOPE void TclOOReleaseClassContents(Tcl_Interp *interp,
Expand Down
24 changes: 14 additions & 10 deletions generic/tclOOMethod.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ TclOODelMethodRef(
/*
* ----------------------------------------------------------------------
*
* TclOONewBasicMethod --
* TclOODefineBasicMethods --
*
* Helper that makes it cleaner to create very simple methods during
* basic system initialization. Not suitable for general use.
Expand All @@ -383,17 +383,21 @@ TclOODelMethodRef(
*/

void
TclOONewBasicMethod(
Class *clsPtr, /* Class to attach the method to. */
const DeclaredClassMethod *dcm)
/* Name of the method, whether it is public,
* and the function to implement it. */
TclOODefineBasicMethods(
Class *clsPtr, /* Class to attach the methods to. */
const DeclaredClassMethod *dcmAry)
/* Static table of method definitions. */
{
Tcl_Obj *namePtr = Tcl_NewStringObj(dcm->name, TCL_AUTO_LENGTH);
int i;

TclNewMethod((Tcl_Class) clsPtr, namePtr,
(dcm->isPublic ? PUBLIC_METHOD : 0), &dcm->definition, NULL);
Tcl_BounceRefCount(namePtr);
for (i = 0 ; dcmAry[i].name ; i++) {
Tcl_Obj *namePtr = Tcl_NewStringObj(dcmAry[i].name, TCL_AUTO_LENGTH);

TclNewMethod((Tcl_Class) clsPtr, namePtr,
(dcmAry[i].isPublic ? PUBLIC_METHOD : 0),
&dcmAry[i].definition, NULL);
Tcl_BounceRefCount(namePtr);
}
}

/*
Expand Down

0 comments on commit 4ab16b8

Please sign in to comment.