Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/nanobind/stl/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct pyfunc_wrapper {
}

~pyfunc_wrapper() {
if (f) {
if (f && is_alive()) {
gil_scoped_acquire acq;
Py_DECREF(f);
}
Expand Down
4 changes: 2 additions & 2 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ python_error::python_error() {
}

python_error::~python_error() {
if (m_value) {
if (m_value && detail::is_alive()) {
gil_scoped_acquire acq;
/* With GIL held */ {
// Clear error status in case the following executes Python code
Expand Down Expand Up @@ -73,7 +73,7 @@ python_error::python_error() {
}

python_error::~python_error() {
if (m_type) {
if (m_type && detail::is_alive()) {
gil_scoped_acquire acq;
/* With GIL held */ {
// Clear error status in case the following executes Python code
Expand Down
6 changes: 5 additions & 1 deletion src/nb_ndarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ static PyObject *dlpack_from_buffer_protocol(PyObject *o, bool ro) {
}

mt->deleter = [](managed_dltensor *mt2) {
if(! is_alive())
return;
gil_scoped_acquire guard;
Py_buffer *buf = (Py_buffer *) mt2->manager_ctx;
PyBuffer_Release(buf);
Expand Down Expand Up @@ -617,7 +619,7 @@ void ndarray_dec_ref(ndarray_handle *th) noexcept {

if (rc_value == 0) {
check(false, "ndarray_dec_ref(): reference count became negative!");
} else if (rc_value == 1) {
} else if (rc_value == 1 && is_alive()) {
gil_scoped_acquire guard;

Py_XDECREF(th->owner);
Expand Down Expand Up @@ -662,6 +664,8 @@ ndarray_handle *ndarray_create(void *value, size_t ndim, const size_t *shape_in,
scoped_pymalloc<int64_t> shape(ndim), strides(ndim);

auto deleter = [](managed_dltensor *mt) {
if (! is_alive())
return;
gil_scoped_acquire guard;
ndarray_handle *th = (ndarray_handle *) mt->manager_ctx;
ndarray_dec_ref(th);
Expand Down