RNA: Make the PointerRNA struct non-trivial.
For now, PointerRNA is made non-trivial by giving explicit default
values to its members.
Besides of BPY python binding code, the change is relatively trivial.
The main change (besides the creation/deletion part) is the replacement
of `memset` by zero-initialized assignment (using `{}`).
makesrna required changes are quite small too.
The big piece of this PR is the refactor of the BPY RNA code.
It essentially brings back allocation and deletion of the BPy_StructRNA,
BPy_Pointer etc. python objects into 'cannonical process', using `__new__`,
and `__init__` callbacks (and there matching CAPI functions).
Existing code was doing very low-level manipulations to create these
data, which is not really easy to understand, and AFAICT incompatible
with handling C++ data that needs to be constructed and destructed.
Unfortunately, similar change in destruction code (using `__del__` and
matching `tp_finalize` CAPI callback) is not possible, because of technical
low-level implementation details in CPython (see [1] for details).
`std::optional` pointer management is used to encapsulate PointerRNA
data. This allows to keep control on _when_ actual RNA creation is done,
and to have a safe destruction in `tp_dealloc` callbacks.
Note that a critical change in Blender's Python API will be that classes
inherinting from `bpy_struct` etc. will now have to properly call the
base class `__new__` and/or `__init__`if they define them.
Implements #122431.
[1] https://discuss.python.org/t/cpython-usage-of-tp-finalize-in-c-defined-static-types-with-no-custom-tp-dealloc/64100
This commit is contained in:
committed by
Bastien Montagne
parent
1b130f651a
commit
1dbe94c8ac
@@ -218,11 +218,11 @@ static PyObject *Freestyle_evaluateColorRamp(PyObject * /*self*/, PyObject *args
|
||||
if (!PyArg_ParseTuple(args, "O!f", &pyrna_struct_Type, &py_srna, &in)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_ColorRamp)) {
|
||||
if (!RNA_struct_is_a(py_srna->ptr->type, &RNA_ColorRamp)) {
|
||||
PyErr_SetString(PyExc_TypeError, "1st argument is not a ColorRamp object");
|
||||
return nullptr;
|
||||
}
|
||||
coba = (ColorBand *)py_srna->ptr.data;
|
||||
coba = (ColorBand *)py_srna->ptr->data;
|
||||
if (!BKE_colorband_evaluate(coba, in, out)) {
|
||||
PyErr_SetString(PyExc_ValueError, "failed to evaluate the color ramp");
|
||||
return nullptr;
|
||||
@@ -258,7 +258,7 @@ static PyObject *Freestyle_evaluateCurveMappingF(PyObject * /*self*/, PyObject *
|
||||
if (!PyArg_ParseTuple(args, "O!if", &pyrna_struct_Type, &py_srna, &cur, &value)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!RNA_struct_is_a(py_srna->ptr.type, &RNA_CurveMapping)) {
|
||||
if (!RNA_struct_is_a(py_srna->ptr->type, &RNA_CurveMapping)) {
|
||||
PyErr_SetString(PyExc_TypeError, "1st argument is not a CurveMapping object");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -266,7 +266,7 @@ static PyObject *Freestyle_evaluateCurveMappingF(PyObject * /*self*/, PyObject *
|
||||
PyErr_SetString(PyExc_ValueError, "2nd argument is out of range");
|
||||
return nullptr;
|
||||
}
|
||||
cumap = (CurveMapping *)py_srna->ptr.data;
|
||||
cumap = (CurveMapping *)py_srna->ptr->data;
|
||||
BKE_curvemapping_init(cumap);
|
||||
/* disable extrapolation if enabled */
|
||||
if (cumap->flag & CUMA_EXTEND_EXTRAPOLATE) {
|
||||
|
||||
Reference in New Issue
Block a user