File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -2912,7 +2912,11 @@ _PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op)
2912
2912
#ifdef Py_GIL_DISABLED
2913
2913
op -> ob_tid = (uintptr_t )tstate -> delete_later ;
2914
2914
#else
2915
- * ((PyObject * * )op ) = tstate -> delete_later ;
2915
+ /* Store the pointer in the refcnt field.
2916
+ * As this object may still be tracked by the GC,
2917
+ * it is important that we never store 0 (NULL). */
2918
+ uintptr_t refcnt = (uintptr_t )tstate -> delete_later ;
2919
+ * ((uintptr_t * )op ) = refcnt + 1 ;
2916
2920
#endif
2917
2921
tstate -> delete_later = op ;
2918
2922
}
@@ -2931,7 +2935,8 @@ _PyTrash_thread_destroy_chain(PyThreadState *tstate)
2931
2935
op -> ob_tid = 0 ;
2932
2936
_Py_atomic_store_ssize_relaxed (& op -> ob_ref_shared , _Py_REF_MERGED );
2933
2937
#else
2934
- tstate -> delete_later = * ((PyObject * * )op );
2938
+ uintptr_t refcnt = * ((uintptr_t * )op );
2939
+ tstate -> delete_later = (PyObject * )(refcnt - 1 );
2935
2940
op -> ob_refcnt = 0 ;
2936
2941
#endif
2937
2942
You can’t perform that action at this time.
0 commit comments