Skip to content

Commit

Permalink
[37108037b9]: Apply patch 0005 for CHERI
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Aug 26, 2022
1 parent 7a3d388 commit b26ef50
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions generic/tclTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ DLLEXPORT int Tcltest_SafeInit(Tcl_Interp *interp);
static Tcl_DString delString;
static Tcl_Interp *delInterp;

/*
* One of the following structures exists for each command created by the
* "testcmdtoken" command.
*/

typedef struct TestCommandTokenRef {
int id; /* Identifier for this reference. */
Tcl_Command token; /* Tcl's token for the command. */
struct TestCommandTokenRef *nextPtr;
/* Next in list of references. */
} TestCommandTokenRef;

static TestCommandTokenRef *firstCommandTokenRef = NULL;
static int nextCommandTokenRefId = 1;

/*
* One of the following structures exists for each asynchronous handler
* created by the "testasync" command".
Expand Down Expand Up @@ -1196,34 +1211,52 @@ TestcmdtokenCmd(
int argc, /* Number of arguments. */
const char **argv) /* Argument strings. */
{
Tcl_Command token;
int *l;
TestCommandTokenRef *refPtr;
char buf[30];
int id;

if (argc != 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" option arg\"", NULL);
return TCL_ERROR;
}
if (strcmp(argv[1], "create") == 0) {
token = Tcl_CreateCommand(interp, argv[2], CmdProc1,
refPtr = (TestCommandTokenRef *)Tcl_Alloc(sizeof(TestCommandTokenRef));
refPtr->token = Tcl_CreateCommand(interp, argv[2], CmdProc1,
(void *) "original", NULL);
sprintf(buf, "%p", (void *)token);
refPtr->id = nextCommandTokenRefId;
nextCommandTokenRefId++;
refPtr->nextPtr = firstCommandTokenRef;
firstCommandTokenRef = refPtr;
sprintf(buf, "%d", refPtr->id);
Tcl_AppendResult(interp, buf, NULL);
} else if (strcmp(argv[1], "name") == 0) {
Tcl_Obj *objPtr;

if (sscanf(argv[2], "%p", &l) != 1) {
if (sscanf(argv[2], "%d", &id) != 1) {
Tcl_AppendResult(interp, "bad command token \"", argv[2],
"\"", NULL);
return TCL_ERROR;
}

for (refPtr = firstCommandTokenRef; refPtr != NULL;
refPtr = refPtr->nextPtr) {
if (refPtr->id == id) {
break;
}
}

if (refPtr == NULL) {
Tcl_AppendResult(interp, "bad command token \"", argv[2],
"\"", NULL);
return TCL_ERROR;
}

objPtr = Tcl_NewObj();
Tcl_GetCommandFullName(interp, (Tcl_Command) l, objPtr);
Tcl_GetCommandFullName(interp, refPtr->token, objPtr);

Tcl_AppendElement(interp,
Tcl_GetCommandName(interp, (Tcl_Command) l));
Tcl_GetCommandName(interp, refPtr->token));
Tcl_AppendElement(interp, Tcl_GetString(objPtr));
Tcl_DecrRefCount(objPtr);
} else {
Expand Down

0 comments on commit b26ef50

Please sign in to comment.