summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2023-01-26 11:05:17 -0600
committerJason Madden <jamadden@gmail.com>2023-01-26 11:05:17 -0600
commitb6a5888c395c9e9e8be76193593313357b2b414d (patch)
treeaa1833e8f0398fec090f9804776dc3465eb8d08c
parent1b58d874d0fc8772d8d5b66ad712651ca444f9bb (diff)
downloadgreenlet-b6a5888c395c9e9e8be76193593313357b2b414d.tar.gz
Remove assertions in the set_tracefunc() method.
The assertions were actually incorrect if the same tracer object was set twice. Removing the assertions is ok here because the reference handling is pretty thoroughly debugged and tested now.
-rw-r--r--CHANGES.rst5
-rw-r--r--src/greenlet/greenlet_thread_state.hpp4
-rw-r--r--src/greenlet/tests/test_tracing.py9
3 files changed, 13 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 8a15aac..9f31503 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,7 +5,10 @@
2.0.2 (unreleased)
==================
-- Nothing changed yet.
+- Fix calling ``greenlet.settrace()`` with the same tracer object that
+ was currently active. See `issue 332
+ <https://github.com/python-greenlet/greenlet/issues/332>`_.
+
2.0.1 (2022-11-07)
diff --git a/src/greenlet/greenlet_thread_state.hpp b/src/greenlet/greenlet_thread_state.hpp
index 15111c5..b740874 100644
--- a/src/greenlet/greenlet_thread_state.hpp
+++ b/src/greenlet/greenlet_thread_state.hpp
@@ -307,11 +307,7 @@ public:
this->tracefunc.CLEAR();
}
else {
-#ifndef NDEBUG
- Py_ssize_t old_refs = Py_REFCNT(tracefunc);
-#endif
this->tracefunc = tracefunc;
- assert(this->tracefunc.REFCNT() == old_refs + 1);
}
}
diff --git a/src/greenlet/tests/test_tracing.py b/src/greenlet/tests/test_tracing.py
index 843e3cf..de84dbc 100644
--- a/src/greenlet/tests/test_tracing.py
+++ b/src/greenlet/tests/test_tracing.py
@@ -66,6 +66,15 @@ class TestGreenletTracing(TestCase):
('switch', (main, g)),
])
+ def test_set_same_tracer_twice(self):
+ # https://github.com/python-greenlet/greenlet/issues/332
+ # Our logic in asserting that the tracefunction should
+ # gain a reference was incorrect if the same tracefunction was set
+ # twice.
+ tracer = GreenletTracer()
+ with tracer:
+ greenlet.settrace(tracer)
+
class PythonTracer(object):
oldtrace = None