diff options
Diffstat (limited to 'generic/tclTestProcBodyObj.c')
| -rw-r--r-- | generic/tclTestProcBodyObj.c | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/generic/tclTestProcBodyObj.c b/generic/tclTestProcBodyObj.c index 4d32c5a..644179b 100644 --- a/generic/tclTestProcBodyObj.c +++ b/generic/tclTestProcBodyObj.c @@ -11,9 +11,6 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#ifndef USE_TCL_STUBS -# define USE_TCL_STUBS -#endif #include "tclInt.h" /* @@ -34,8 +31,9 @@ static const char procCommand[] = "proc"; * procs */ -typedef struct CmdTable { - const char *cmdName; /* command name */ +typedef struct CmdTable +{ + const char *cmdName; /* command name */ Tcl_ObjCmdProc *proc; /* command proc */ int exportIt; /* if 1, export the command */ } CmdTable; @@ -45,22 +43,24 @@ typedef struct CmdTable { */ static int ProcBodyTestProcObjCmd(ClientData dummy, - Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); + Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); static int ProcBodyTestInitInternal(Tcl_Interp *interp, int isSafe); static int RegisterCommand(Tcl_Interp* interp, const char *namespace, const CmdTable *cmdTablePtr); +int Procbodytest_Init(Tcl_Interp * interp); +int Procbodytest_SafeInit(Tcl_Interp * interp); /* * List of commands to create when the package is loaded; must go after the * declarations of the enable command procedure. */ -static const CmdTable commands[] = { +static CONST CmdTable commands[] = { { procCommand, ProcBodyTestProcObjCmd, 1 }, { 0, 0, 0 } }; -static const CmdTable safeCommands[] = { +static CONST CmdTable safeCommands[] = { { procCommand, ProcBodyTestProcObjCmd, 1 }, { 0, 0, 0 } }; @@ -70,13 +70,13 @@ static const CmdTable safeCommands[] = { * * Procbodytest_Init -- * - * This function initializes the "procbodytest" package. + * This function initializes the "procbodytest" package. * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ @@ -84,7 +84,7 @@ static const CmdTable safeCommands[] = { int Procbodytest_Init( Tcl_Interp *interp) /* the Tcl interpreter for which the package - * is initialized */ + * is initialized */ { return ProcBodyTestInitInternal(interp, 0); } @@ -94,13 +94,13 @@ Procbodytest_Init( * * Procbodytest_SafeInit -- * - * This function initializes the "procbodytest" package. + * This function initializes the "procbodytest" package. * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ @@ -108,7 +108,7 @@ Procbodytest_Init( int Procbodytest_SafeInit( Tcl_Interp *interp) /* the Tcl interpreter for which the package - * is initialized */ + * is initialized */ { return ProcBodyTestInitInternal(interp, 1); } @@ -118,38 +118,36 @@ Procbodytest_SafeInit( * * RegisterCommand -- * - * This function registers a command in the context of the given - * namespace. + * This function registers a command in the context of the given namespace. * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ -static int -RegisterCommand( - Tcl_Interp* interp, /* the Tcl interpreter for which the operation +static int RegisterCommand(interp, namespace, cmdTablePtr) + Tcl_Interp* interp; /* the Tcl interpreter for which the operation * is performed */ - const char *namespace, /* the namespace in which the command is + const char *namespace; /* the namespace in which the command is * registered */ - const CmdTable *cmdTablePtr)/* the command to register */ + const CmdTable *cmdTablePtr;/* the command to register */ { char buf[128]; if (cmdTablePtr->exportIt) { - sprintf(buf, "namespace eval %s { namespace export %s }", - namespace, cmdTablePtr->cmdName); - if (Tcl_EvalEx(interp, buf, -1, 0) != TCL_OK) { - return TCL_ERROR; - } + sprintf(buf, "namespace eval %s { namespace export %s }", + namespace, cmdTablePtr->cmdName); + if (Tcl_Eval(interp, buf) != TCL_OK) + return TCL_ERROR; } sprintf(buf, "%s::%s", namespace, cmdTablePtr->cmdName); Tcl_CreateObjCommand(interp, buf, cmdTablePtr->proc, 0, 0); + return TCL_OK; } @@ -173,16 +171,16 @@ RegisterCommand( static int ProcBodyTestInitInternal( Tcl_Interp *interp, /* the Tcl interpreter for which the package - * is initialized */ + * is initialized */ int isSafe) /* 1 if this is a safe interpreter */ { - const CmdTable *cmdTablePtr; + CONST CmdTable *cmdTablePtr; cmdTablePtr = (isSafe) ? &safeCommands[0] : &commands[0]; for ( ; cmdTablePtr->cmdName ; cmdTablePtr++) { - if (RegisterCommand(interp, packageName, cmdTablePtr) != TCL_OK) { - return TCL_ERROR; - } + if (RegisterCommand(interp, packageName, cmdTablePtr) != TCL_OK) { + return TCL_ERROR; + } } return Tcl_PkgProvide(interp, packageName, packageVersion); @@ -228,7 +226,7 @@ ProcBodyTestProcObjCmd( int objc, /* argument count */ Tcl_Obj *const objv[]) /* arguments */ { - const char *fullName; + char *fullName; Tcl_Command procCmd; Command *cmdPtr; Proc *procPtr = NULL; @@ -245,23 +243,23 @@ ProcBodyTestProcObjCmd( * Find the Command pointer to this procedure */ - fullName = Tcl_GetString(objv[3]); + fullName = Tcl_GetStringFromObj(objv[3], NULL); procCmd = Tcl_FindCommand(interp, fullName, NULL, TCL_LEAVE_ERR_MSG); if (procCmd == NULL) { - return TCL_ERROR; + return TCL_ERROR; } cmdPtr = (Command *) procCmd; /* * check that this is a procedure and not a builtin command: - * If a procedure, cmdPtr->objClientData is TclIsProc(cmdPtr). + * If a procedure, cmdPtr->objProc is TclObjInterpProc. */ - if (cmdPtr->objClientData != TclIsProc(cmdPtr)) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + if (cmdPtr->objProc != TclGetObjInterpProc()) { + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "command \"", fullName, "\" is not a Tcl procedure", NULL); - return TCL_ERROR; + return TCL_ERROR; } /* @@ -270,9 +268,10 @@ ProcBodyTestProcObjCmd( procPtr = (Proc *) cmdPtr->objClientData; if (procPtr == NULL) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "procedure \"", - fullName, "\" does not have a Proc struct!", NULL); - return TCL_ERROR; + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + "procedure \"", fullName, + "\" does not have a Proc struct!", NULL); + return TCL_ERROR; } /* @@ -281,10 +280,10 @@ ProcBodyTestProcObjCmd( bodyObjPtr = TclNewProcBodyObj(procPtr); if (bodyObjPtr == NULL) { - Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), + Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "failed to create a procbody object for procedure \"", - fullName, "\"", NULL); - return TCL_ERROR; + fullName, "\"", NULL); + return TCL_ERROR; } Tcl_IncrRefCount(bodyObjPtr); @@ -294,7 +293,7 @@ ProcBodyTestProcObjCmd( myobjv[3] = bodyObjPtr; myobjv[4] = NULL; - result = Tcl_ProcObjCmd(NULL, interp, objc, myobjv); + result = Tcl_ProcObjCmd((ClientData) NULL, interp, objc, myobjv); Tcl_DecrRefCount(bodyObjPtr); return result; |
