File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
graalpython/com.oracle.graal.python.cext/src Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1- /* Copyright (c) 2024, Oracle and/or its affiliates.
1+ /* Copyright (c) 2024, 2025, Oracle and/or its affiliates.
22 * Copyright (C) 1996-2024 Python Software Foundation
33 *
44 * Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -498,7 +498,20 @@ push_native_references_to_managed(PyObject *op, GraalPyGC_Cycle *cycle)
498498
499499 // avoid costly upcalls
500500 if (cycle -> n > 0 ) {
501- GraalPyTruffleObject_ReplicateNativeReferences (op , cycle -> head , cycle -> n );
501+ int dead = 0 ;
502+ // Some managed handles can be already collected if the GC is already cleaning the cycle
503+ for (n = cycle -> head ; n != NULL ; n = n -> next ) {
504+ if (points_to_py_handle_space (n -> item )) {
505+ GraalPyObject * obj = (GraalPyObject * )pointer_to_stub (n -> item );
506+ if (obj -> handle_table_index == 0 ) {
507+ dead = 1 ;
508+ break ;
509+ }
510+ }
511+ }
512+ if (!dead ) {
513+ GraalPyTruffleObject_ReplicateNativeReferences (op , cycle -> head , cycle -> n );
514+ }
502515 }
503516
504517 // destroy list
You can’t perform that action at this time.
0 commit comments