Skip to content

Commit

Permalink
deprecate Tcl_CreateTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Nov 8, 2024
1 parent 3743065 commit 060ce9e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion generic/tcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,10 @@ typedef void (Tcl_CloseProc) (void *data);
typedef void (Tcl_CmdDeleteProc) (void *clientData);
typedef int (Tcl_CmdProc) (void *clientData, Tcl_Interp *interp,
int argc, const char *argv[]);
#ifndef TCL_NO_DEPRECATED
typedef void (Tcl_CmdTraceProc) (void *clientData, Tcl_Interp *interp,
int level, char *command, Tcl_CmdProc *proc,
void *cmdClientData, int argc, const char *argv[]);
#ifndef TCL_NO_DEPRECATED
typedef int (Tcl_CmdObjTraceProc) (void *clientData, Tcl_Interp *interp,
int level, const char *command, Tcl_Command commandInfo, int objc,
struct Tcl_Obj *const *objv);
Expand Down
3 changes: 3 additions & 0 deletions generic/tclDecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#ifdef TCL_NO_DEPRECATED
# define Tcl_ObjCmdProc void
# define Tcl_CmdTraceProc void
# define Tcl_CmdObjTraceProc void
#endif /* TCL_NO_DEPRECATED */

Expand Down Expand Up @@ -3913,6 +3914,7 @@ extern const TclStubs *tclStubsPtr;

#ifdef TCL_NO_DEPRECATED
# undef Tcl_ObjCmdProc
# undef Tcl_CmdTraceProc
# undef Tcl_CmdObjTraceProc
#endif /* TCL_NO_DEPRECATED */

Expand Down Expand Up @@ -4149,6 +4151,7 @@ extern const TclStubs *tclStubsPtr;
#undef TclUtfPrev
#ifdef TCL_NO_DEPRECATED
# undef Tcl_CreateObjCommand
# undef Tcl_CreateTrace
# undef Tcl_CreateObjTrace
# undef Tcl_NRCallObjProc
# undef Tcl_NRCreateCommand
Expand Down
1 change: 1 addition & 0 deletions generic/tclStubInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

#ifdef TCL_NO_DEPRECATED
# define Tcl_CreateObjCommand 0
# define Tcl_CreateTrace 0
# define Tcl_CreateObjTrace 0
# define Tcl_NRCallObjProc 0
# define Tcl_NRCreateCommand 0
Expand Down
57 changes: 25 additions & 32 deletions generic/tclTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,8 @@ static void CmdDelProc1(void *clientData);
static void CmdDelProc2(void *clientData);
static Tcl_CmdProc CmdProc1;
static Tcl_CmdProc CmdProc2;
static void CmdTraceDeleteProc(
void *clientData, Tcl_Interp *interp,
int level, char *command, Tcl_CmdProc *cmdProc,
void *cmdClientData, int argc,
const char **argv);
static void CmdTraceProc(void *clientData,
Tcl_Interp *interp, int level, char *command,
Tcl_CmdProc *cmdProc, void *cmdClientData,
int argc, const char **argv);
static Tcl_CmdObjTraceProc2 CmdTraceDeleteProc;
static Tcl_CmdObjTraceProc2 CmdTraceProc;
static Tcl_ObjCmdProc2 CreatedCommandProc;
static Tcl_ObjCmdProc2 CreatedCommandProc2;
static void DelCallbackProc(void *clientData,
Expand Down Expand Up @@ -1356,7 +1349,7 @@ TestcmdtraceCmd(

if (strcmp(Tcl_GetString(objv[1]), "tracetest") == 0) {
Tcl_DStringInit(&buffer);
cmdTrace = Tcl_CreateTrace(interp, 50000, CmdTraceProc, &buffer);
cmdTrace = Tcl_CreateObjTrace2(interp, 50000, 0, CmdTraceProc, &buffer, NULL);
result = Tcl_EvalEx(interp, Tcl_GetString(objv[2]), TCL_INDEX_NONE, 0);
if (result == TCL_OK) {
Tcl_ResetResult(interp);
Expand All @@ -1372,13 +1365,13 @@ TestcmdtraceCmd(
* TclNRExecuteByteCode.
*/

cmdTrace = Tcl_CreateTrace(interp, 50000, CmdTraceDeleteProc, NULL);
cmdTrace = Tcl_CreateObjTrace2(interp, 50000, 0, CmdTraceDeleteProc, NULL, NULL);
Tcl_EvalEx(interp, Tcl_GetString(objv[2]), TCL_INDEX_NONE, 0);
} else if (strcmp(Tcl_GetString(objv[1]), "leveltest") == 0) {
Interp *iPtr = (Interp *) interp;
Tcl_DStringInit(&buffer);
cmdTrace = Tcl_CreateTrace(interp, iPtr->numLevels + 4, CmdTraceProc,
&buffer);
cmdTrace = Tcl_CreateObjTrace2(interp, iPtr->numLevels + 4, 0, CmdTraceProc,
&buffer, NULL);
result = Tcl_EvalEx(interp, Tcl_GetString(objv[2]), TCL_INDEX_NONE, 0);
if (result == TCL_OK) {
Tcl_ResetResult(interp);
Expand Down Expand Up @@ -1409,8 +1402,8 @@ TestcmdtraceCmd(
Tcl_Trace t1, t2;

Tcl_DStringInit(&buffer);
t1 = Tcl_CreateTrace(interp, 1, CmdTraceProc, &buffer);
t2 = Tcl_CreateTrace(interp, 50000, CmdTraceProc, &buffer);
t1 = Tcl_CreateObjTrace2(interp, 1, 0, CmdTraceProc, &buffer, NULL);
t2 = Tcl_CreateObjTrace2(interp, 50000, 0, CmdTraceProc, &buffer, NULL);
result = Tcl_EvalEx(interp, Tcl_GetString(objv[2]), TCL_INDEX_NONE, 0);
if (result == TCL_OK) {
Tcl_ResetResult(interp);
Expand All @@ -1427,42 +1420,41 @@ TestcmdtraceCmd(
return TCL_OK;
}

static void
static int
CmdTraceProc(
void *clientData, /* Pointer to buffer in which the
* command and arguments are appended.
* Accumulates test result. */
TCL_UNUSED(Tcl_Interp *),
TCL_UNUSED(int) /*level*/,
char *command, /* The command being traced (after
TCL_UNUSED(Tcl_Size) /*level*/,
const char *command, /* The command being traced (after
* substitutions). */
TCL_UNUSED(Tcl_CmdProc *) /*cmdProc*/,
TCL_UNUSED(void *),
int argc, /* Number of arguments. */
const char **argv) /* Argument strings. */
TCL_UNUSED(Tcl_Command) /*cmdProc*/,
Tcl_Size objc, /* Number of arguments. */
Tcl_Obj *const *objv) /* Arguments. */
{
Tcl_DString *bufPtr = (Tcl_DString *) clientData;
int i;
Tcl_Size i;

Tcl_DStringAppendElement(bufPtr, command);

Tcl_DStringStartSublist(bufPtr);
for (i = 0; i < argc; i++) {
Tcl_DStringAppendElement(bufPtr, argv[i]);
for (i = 0; i < objc; i++) {
Tcl_DStringAppendElement(bufPtr, Tcl_GetString(objv[i]));
}
Tcl_DStringEndSublist(bufPtr);
return TCL_OK;
}

static void
static int
CmdTraceDeleteProc(
TCL_UNUSED(void *),
Tcl_Interp *interp, /* Current interpreter. */
TCL_UNUSED(int) /*level*/,
TCL_UNUSED(char *) /*command*/,
TCL_UNUSED(Tcl_CmdProc *),
TCL_UNUSED(void *),
TCL_UNUSED(int) /*argc*/,
TCL_UNUSED(const char **) /*argv*/)
TCL_UNUSED(Tcl_Size) /*level*/,
TCL_UNUSED(const char *) /*command*/,
TCL_UNUSED(Tcl_Command),
TCL_UNUSED(Tcl_Size) /*objc*/,
TCL_UNUSED(Tcl_Obj *const *) /*objv*/)
{
/*
* Remove ourselves to test whether calling Tcl_DeleteTrace within a trace
Expand All @@ -1471,6 +1463,7 @@ CmdTraceDeleteProc(
*/

Tcl_DeleteTrace(interp, cmdTrace);
return TCL_OK;
}

static int
Expand Down
6 changes: 6 additions & 0 deletions generic/tclTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ static void TraceCommandProc(void *clientData,
Tcl_Interp *interp, const char *oldName,
const char *newName, int flags);
static Tcl_CmdObjTraceProc2 TraceExecutionProc;
#ifndef TCL_NO_DEPRECATED
static int StringTraceProc(void *clientData,
Tcl_Interp *interp, Tcl_Size level,
const char *command, Tcl_Command commandInfo,
Tcl_Size objc, Tcl_Obj *const objv[]);
static void StringTraceDeleteProc(void *clientData);
#endif /* TCL_NO_DEPRECATED */
static void DisposeTraceResult(int flags, char *result);
static int TraceVarEx(Tcl_Interp *interp, const char *part1,
const char *part2, VarTrace *tracePtr);
Expand All @@ -145,10 +147,12 @@ static int TraceVarEx(Tcl_Interp *interp, const char *part1,
* trace procs
*/

#ifndef TCL_NO_DEPRECATED
typedef struct {
void *clientData; /* Client data from Tcl_CreateTrace */
Tcl_CmdTraceProc *proc; /* Trace function from Tcl_CreateTrace */
} StringTraceData;
#endif /* TCL_NO_DEPRECATED */

/*
* Convenience macros for iterating over the list of traces. Note that each of
Expand Down Expand Up @@ -2123,6 +2127,7 @@ Tcl_CreateObjTrace2(
*----------------------------------------------------------------------
*/

#ifndef TCL_NO_DEPRECATED
Tcl_Trace
Tcl_CreateTrace(
Tcl_Interp *interp, /* Interpreter in which to create trace. */
Expand Down Expand Up @@ -2218,6 +2223,7 @@ StringTraceDeleteProc(
{
Tcl_Free(clientData);
}
#endif /* TCL_NO_DEPRECATED */

/*
*----------------------------------------------------------------------
Expand Down

0 comments on commit 060ce9e

Please sign in to comment.