Skip to content

Commit 7c57012

Browse files
Rewrite smart pointers that encapsulate Python references.
First, Rewrite non-null pointer types to use asserts rather than an absolute assumption that the pointer type is not null. Second, add move assignment operators to avoid unneeded incref/decrefs when assigning between these smart pointer classes. Third, allow implicit conversions to happen between all four of these classes. Conversions from pointers that may be null to pointers that count null as an uninitialized state now raise an exception if a null value is encountered, and all other constructors are marked as noexcept. Fourth, add a method to release an owned reference from a given pointer. This replaces the old release method and eliminates various segfaults that were due to over-agressive calls to decref.
1 parent ec82518 commit 7c57012

6 files changed

Lines changed: 190 additions & 109 deletions

File tree

dynd/include/callables/assign_to_pyobject_callable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ namespace nd {
294294
const dynd::string &rawname = src0_tp.extended<dynd::ndt::struct_type>()->get_field_name(i);
295295
pydynd::py_ref name =
296296
capture_if_not_null(PyUnicode_DecodeUTF8(rawname.begin(), rawname.end() - rawname.begin(), NULL));
297-
PyTuple_SET_ITEM(self_ck->m_field_names.get(), i, name.get());
297+
PyTuple_SET_ITEM(self_ck->m_field_names.get(), i, name.release());
298298
}
299299
self_ck->m_copy_el_offsets.resize(field_count);
300300

dynd/include/kernels/assign_to_pyobject_kernel.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ struct assign_to_pyobject_kernel<ndt::tuple_type>
431431
if (PyErr_Occurred()) {
432432
throw std::exception();
433433
}
434-
*dst_obj = tup.get();
434+
*dst_obj = tup.release();
435435
}
436436
};
437437

@@ -470,7 +470,7 @@ struct assign_to_pyobject_kernel<ndt::struct_type>
470470
if (PyErr_Occurred()) {
471471
throw std::exception();
472472
}
473-
*dst_obj = dct.get();
473+
*dst_obj = dct.release();
474474
}
475475
};
476476

@@ -496,7 +496,7 @@ struct assign_to_pyobject_kernel<ndt::fixed_dim_type>
496496
if (PyErr_Occurred()) {
497497
throw std::exception();
498498
}
499-
*dst_obj = lst.get();
499+
*dst_obj = lst.release();
500500
}
501501
};
502502

@@ -524,6 +524,6 @@ struct assign_to_pyobject_kernel<ndt::var_dim_type>
524524
if (PyErr_Occurred()) {
525525
throw std::exception();
526526
}
527-
*dst_obj = lst.get();
527+
*dst_obj = lst.release();
528528
}
529529
};

0 commit comments

Comments
 (0)