From f67bb4e4654a3f225772a25cabc49678687ed5f6 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 15 Aug 2017 21:00:59 -0400 Subject: [PATCH] pep-550: Add a return (#346) * pep-550: Add a return * pep-550: Clarify that ContextItem.get() cache uses a borrowed ref --- pep-0550.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pep-0550.rst b/pep-0550.rst index 431f673fa..a4f89488a 100644 --- a/pep-0550.rst +++ b/pep-0550.rst @@ -222,6 +222,8 @@ follows (in pseudo-code):: if self in local_context: return local_context[self] + return None + def set(self, value): tstate = PyThreadState_Get() @@ -838,13 +840,17 @@ The above two fields allow implementing a fast cache path in value = mapping[self] break - self.last_value = value + self.last_value = value # borrowed ref self.last_tstate_id = tstate.unique_id self.last_ver = tstate.execution_context_ver self.last_deallocs = tstate.interp.context_item_deallocs return value +Note that ``last_value`` is a borrowed reference. The assumption +is that if all counters tests are OK, the object will be alive. +This allows the CI values to be properly GCed. + This is similar to the trick that decimal C implementation uses for caching the current decimal context, and will have the same performance characteristics, but available to all