Skip to content

Commit 1297436

Browse files
committed
Fix [24d7f1a6] - crash on proc definition in namespace being deleted
1 parent 5dad98f commit 1297436

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

generic/tclBasic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,7 @@ TclCreateObjCommandInNs(
24142414
Tcl_DeleteCommandFromToken(interp, (Tcl_Command) cmdPtr);
24152415
nsPtr = (Namespace *) TclEnsureNamespace(interp,
24162416
(Tcl_Namespace *) cmdPtr->nsPtr);
2417+
/* Note nsPtr may or may not be same as cmdPtr->nsPtr */
24172418
TclNsDecrRefCount(cmdPtr->nsPtr);
24182419

24192420
if (cmdPtr->flags & CMD_REDEF_IN_PROGRESS) {

generic/tclNamesp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,14 @@ TclEnsureNamespace(
23902390
if (!(nsPtr->flags & NS_DYING)) {
23912391
return namespacePtr;
23922392
}
2393+
/*
2394+
* If a new namespace with the same name has been created already,
2395+
* return that. Otherwise, create a new one. Bug 24d7f1a695.
2396+
*/
2397+
Tcl_Namespace *nsPtr2 = Tcl_FindNamespace(interp, nsPtr->fullName, NULL, 0);
2398+
if (nsPtr2 != NULL) {
2399+
return nsPtr2;
2400+
}
23932401
return Tcl_CreateNamespace(interp, nsPtr->fullName, NULL, NULL);
23942402
}
23952403

tests/basic.test

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,18 @@ test basic-15.2 {Tcl_CreateObjCommand, Bug 0e4d88b650} -setup {
240240
namespace delete n
241241
rename deleter {}
242242
}
243-
243+
test basic-15.3 {Tcl_CreateObjCommand, Bug 24d7f1a695} -body {
244+
namespace eval ns {
245+
proc p {} {}; proc q {} {};
246+
namespace delete [namespace current];
247+
proc p {} {}; proc q {} {}
248+
}
249+
# APN - current behavior is that namespace continues to exist
250+
# as it is recreated by the proc calls after the ns delete.
251+
# I am not sure this is consistent with proc ns::foo raising
252+
# an error if ns does not exist. But whatever ...
253+
namespace exists ns
254+
} -result 1
244255

245256
test basic-16.1 {TclInvokeStringCommand} {emptyTest} {
246257
} {}

0 commit comments

Comments
 (0)