From 1c4c352fe9104950891533992dfbc449e75350aa Mon Sep 17 00:00:00 2001
From: pooryorick <com.digitalsmarties@pooryorick.com>
Date: Sat, 3 Apr 2021 12:17:40 +0000
Subject: New test for OO cleanup:  routine for object gets deleted before
 namespace deletion is complete.

---
 tests/oo.test | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/tests/oo.test b/tests/oo.test
index 168baee..404c6a4 100644
--- a/tests/oo.test
+++ b/tests/oo.test
@@ -1734,6 +1734,7 @@ test oo-11.6.3 {
 } -result 0 -cleanup {
 }
 
+
 test oo-11.6.4 {
     OO: cleanup ReleaseClassContents() where class is mixed into one of its
     instances
@@ -1754,6 +1755,37 @@ test oo-11.6.4 {
     rename obj1 {}
 }
 
+
+test oo-11.7 {
+    When an object is deleted its namespace is deleted, and all objects it is
+    mixed into are also deleted.  If the object has been renamed into the
+    namespace of one of the objects it has been mixed into, the routine for the
+    object might get entirely deleted before the namespace of the object is
+    entirely deleted, in which case the C routine the performs the namespace
+    either must either understand that the handle on the routine for the object
+    might now be gone, or it must be guaranteed that the handle does not
+    disappear until that routine is finished.
+} -setup {
+} -body {
+    oo::define oo::class {
+	export createWithNamespace
+    }
+    oo::class create class1
+
+    oo::object create obj1
+    oo::objdefine obj1 {
+	mixin ::class1
+    }
+    set obj1ns [info object namespace obj1]
+    set class1ns [info object namespace class1]
+    rename class1 ${obj1ns}::class1
+    # No segmentation fault
+    namespace delete $class1ns
+} -cleanup {
+    rename obj {}
+} -result done
+
+
 test oo-12.1 {OO: filters} {
     oo::class create Aclass
     Aclass create Aobject
@@ -1777,6 +1809,8 @@ test oo-12.1 {OO: filters} {
     Aclass destroy
     return $result
 } {{calling ::Aobject->logFilter 1 2 3 4 5} 1 2 3 4 5 result=12345 12345}
+
+
 test oo-12.2 {OO: filters} -setup {
     oo::class create Aclass
     Aclass create Aobject
@@ -4376,12 +4410,13 @@ test oo-35.6 {
 } -body {
     rename obj2 {}
     rename obj1 {}
-    # doesn't crash
+    # No segmentation fault
     return done
 } -cleanup {
     rename obj {}
 } -result done
 
+
 test oo-36.1 {TIP #470: introspection within oo::define} {
     oo::define oo::object self
 } ::oo::object
-- 
cgit v0.12