Skip to content

Commit 563a421

Browse files
authored
fix: Use PyWeakref_GetRef instead of PyWeakref_GET_OBJECT for Python 3.15
1 parent 534ef71 commit 563a421

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎python/pyarrow/src/arrow/python/extension_type.cc‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "arrow/python/extension_type.h"
2323
#include "arrow/python/helpers.h"
2424
#include "arrow/python/pyarrow.h"
25+
#include "arrow/python/vendored/pythoncapi_compat.h"
2526
#include "arrow/util/checked_cast.h"
2627
#include "arrow/util/logging.h"
2728

@@ -164,15 +165,18 @@ PyObject* PyExtensionType::GetInstance() const {
164165
return nullptr;
165166
}
166167
ARROW_DCHECK(PyWeakref_CheckRef(type_instance_.obj()));
167-
PyObject* inst = PyWeakref_GET_OBJECT(type_instance_.obj());
168-
if (inst != Py_None) {
169-
// Cached instance still alive
170-
Py_INCREF(inst);
168+
PyObject* inst = NULL;
169+
int result = PyWeakref_GetRef(type_instance_.obj(), &inst);
170+
if (result == 1) {
171+
// Alive: inst is a new strong reference
171172
return inst;
172-
} else {
173-
// Must reconstruct from serialized form
173+
} else if (result == 0) {
174+
// Weakref is dead, must reconstruct from serialized form
174175
// XXX cache again?
175176
return DeserializeExtInstance(type_class_.obj(), storage_type_, serialized_);
177+
} else {
178+
// -1 = exception
179+
return nullptr;
176180
}
177181
}
178182

0 commit comments

Comments
 (0)