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
@@ -49,7 +49,8 @@ class CyclesRender(bpy.types.RenderEngine):
|
||||
bl_use_custom_freestyle = True
|
||||
bl_use_alembic_procedural = True
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.session = None
|
||||
|
||||
def __del__(self):
|
||||
|
||||
@@ -1344,7 +1344,8 @@ class HydraRenderEngine(RenderEngine):
|
||||
bl_use_shading_nodes_custom = False
|
||||
bl_delegate_id = 'HdStormRendererPlugin'
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.engine_ptr = None
|
||||
|
||||
def __del__(self):
|
||||
|
||||
@@ -33,7 +33,8 @@ class NODE_OT_connect_to_output(Operator, NodeEditorBase):
|
||||
default=True,
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.shader_output_idname = ""
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -631,7 +631,7 @@ void RNA_collection_clear(PointerRNA *ptr, const char *name);
|
||||
|
||||
#define RNA_STRUCT_BEGIN(sptr, prop) \
|
||||
{ \
|
||||
CollectionPropertyIterator rna_macro_iter; \
|
||||
CollectionPropertyIterator rna_macro_iter{}; \
|
||||
for (RNA_property_collection_begin( \
|
||||
sptr, RNA_struct_iterator_property((sptr)->type), &rna_macro_iter); \
|
||||
rna_macro_iter.valid; \
|
||||
|
||||
@@ -37,12 +37,12 @@ struct bContext;
|
||||
* the properties and validate them. */
|
||||
|
||||
struct PointerRNA {
|
||||
ID *owner_id;
|
||||
StructRNA *type;
|
||||
void *data;
|
||||
ID *owner_id = nullptr;
|
||||
StructRNA *type = nullptr;
|
||||
void *data = nullptr;
|
||||
};
|
||||
|
||||
constexpr PointerRNA PointerRNA_NULL{nullptr, nullptr, nullptr};
|
||||
extern const PointerRNA PointerRNA_NULL;
|
||||
|
||||
struct PropertyPointerRNA {
|
||||
PointerRNA ptr;
|
||||
@@ -451,6 +451,7 @@ struct CollectionPropertyIterator {
|
||||
PointerRNA builtin_parent;
|
||||
PropertyRNA *prop;
|
||||
union {
|
||||
/* Keep biggest object first in the union, for zero-initialization to work properly. */
|
||||
ArrayIterator array;
|
||||
ListBaseIterator listbase;
|
||||
CountIterator count;
|
||||
|
||||
@@ -1619,7 +1619,7 @@ static char *rna_def_property_begin_func(
|
||||
rna_print_data_get(f, dp);
|
||||
}
|
||||
|
||||
fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
|
||||
fprintf(f, "\n *iter = {};\n");
|
||||
fprintf(f, " iter->parent = *ptr;\n");
|
||||
fprintf(f, " iter->prop = &rna_%s_%s;\n", srna->identifier, prop->identifier);
|
||||
|
||||
@@ -3417,17 +3417,28 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
|
||||
|
||||
if (func->c_ret) {
|
||||
dparm = rna_find_parameter_def(func->c_ret);
|
||||
ptrstr = (((dparm->prop->type == PROP_POINTER) &&
|
||||
!(dparm->prop->flag_parameter & PARM_RNAPTR)) ||
|
||||
(dparm->prop->arraydimension)) ?
|
||||
"*" :
|
||||
"";
|
||||
fprintf(f,
|
||||
"\t*((%s%s %s*)_retdata) = %s;\n",
|
||||
rna_type_struct(dparm->prop),
|
||||
rna_parameter_type_name(dparm->prop),
|
||||
ptrstr,
|
||||
func->c_ret->identifier);
|
||||
if ((dparm->prop->type == PROP_POINTER) && (dparm->prop->flag_parameter & PARM_RNAPTR) &&
|
||||
(dparm->prop->flag & PROP_THICK_WRAP))
|
||||
{
|
||||
const char *parameter_type_name = rna_parameter_type_name(dparm->prop);
|
||||
fprintf(f,
|
||||
"\t*reinterpret_cast<%s *>(_retdata) = %s;\n",
|
||||
parameter_type_name,
|
||||
func->c_ret->identifier);
|
||||
}
|
||||
else {
|
||||
ptrstr = (((dparm->prop->type == PROP_POINTER) &&
|
||||
!(dparm->prop->flag_parameter & PARM_RNAPTR)) ||
|
||||
(dparm->prop->arraydimension)) ?
|
||||
"*" :
|
||||
"";
|
||||
fprintf(f,
|
||||
"\t*((%s%s %s*)_retdata) = %s;\n",
|
||||
rna_type_struct(dparm->prop),
|
||||
rna_parameter_type_name(dparm->prop),
|
||||
ptrstr,
|
||||
func->c_ret->identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5188,7 +5199,7 @@ static const char *cpp_classes =
|
||||
" } \\\n"
|
||||
" sname##_##identifier##_end(&iter); \\\n"
|
||||
" if (!found) { \\\n"
|
||||
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
|
||||
" *r_ptr = {}; \\\n"
|
||||
" } \\\n"
|
||||
" return found; \\\n"
|
||||
" } \n"
|
||||
@@ -5198,7 +5209,7 @@ static const char *cpp_classes =
|
||||
" { \\\n"
|
||||
" bool found = sname##_##identifier##_lookup_int(ptr, key, r_ptr); \\\n"
|
||||
" if (!found) { \\\n"
|
||||
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
|
||||
" *r_ptr = {}; \\\n"
|
||||
" } \\\n"
|
||||
" return found; \\\n"
|
||||
" } \n"
|
||||
@@ -5227,7 +5238,7 @@ static const char *cpp_classes =
|
||||
" } \\\n"
|
||||
" sname##_##identifier##_end(&iter); \\\n"
|
||||
" if (!found) { \\\n"
|
||||
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
|
||||
" *r_ptr = {}; \\\n"
|
||||
" } \\\n"
|
||||
" return found; \\\n"
|
||||
" } \n"
|
||||
@@ -5237,7 +5248,7 @@ static const char *cpp_classes =
|
||||
" { \\\n"
|
||||
" bool found = sname##_##identifier##_lookup_string(ptr, key, r_ptr); \\\n"
|
||||
" if (!found) { \\\n"
|
||||
" memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
|
||||
" *r_ptr = {}; \\\n"
|
||||
" } \\\n"
|
||||
" return found; \\\n"
|
||||
" } \n"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <sstream>
|
||||
|
||||
#include <fmt/format.h>
|
||||
@@ -75,6 +76,9 @@ static CLG_LogRef LOG = {"rna.access"};
|
||||
|
||||
/* Init/Exit */
|
||||
|
||||
/* NOTE: Initializing this object here is fine for now, as it should not allocate any memory. */
|
||||
extern const PointerRNA PointerRNA_NULL = {};
|
||||
|
||||
void RNA_init()
|
||||
{
|
||||
StructRNA *srna;
|
||||
@@ -218,7 +222,7 @@ static void rna_pointer_inherit_id(const StructRNA *type,
|
||||
|
||||
PointerRNA RNA_blender_rna_pointer_create()
|
||||
{
|
||||
PointerRNA ptr;
|
||||
PointerRNA ptr = {};
|
||||
ptr.owner_id = nullptr;
|
||||
ptr.type = &RNA_BlenderRNA;
|
||||
ptr.data = &BLENDER_RNA;
|
||||
@@ -6290,6 +6294,10 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms,
|
||||
data_alloc->array_tot = 0;
|
||||
data_alloc->array = nullptr;
|
||||
}
|
||||
else if ((parm->flag_parameter & PARM_RNAPTR) && (parm->flag & PROP_THICK_WRAP)) {
|
||||
BLI_assert(parm->type == PROP_POINTER);
|
||||
new (static_cast<PointerRNA *>(data)) PointerRNA();
|
||||
}
|
||||
|
||||
if (!(parm->flag_parameter & PARM_REQUIRED) && !(parm->flag & PROP_DYNAMIC)) {
|
||||
switch (parm->type) {
|
||||
@@ -6351,23 +6359,28 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms,
|
||||
void RNA_parameter_list_free(ParameterList *parms)
|
||||
{
|
||||
PropertyRNA *parm;
|
||||
int tot;
|
||||
|
||||
parm = static_cast<PropertyRNA *>(parms->func->cont.properties.first);
|
||||
for (tot = 0; parm; parm = parm->next) {
|
||||
void *data = parms->data;
|
||||
for (; parm; parm = parm->next) {
|
||||
if (parm->type == PROP_COLLECTION) {
|
||||
BLI_freelistN((ListBase *)((char *)parms->data + tot));
|
||||
BLI_freelistN(static_cast<ListBase *>(data));
|
||||
}
|
||||
else if ((parm->flag_parameter & PARM_RNAPTR) && (parm->flag & PROP_THICK_WRAP)) {
|
||||
BLI_assert(parm->type == PROP_POINTER);
|
||||
PointerRNA *ptr = static_cast<PointerRNA *>(data);
|
||||
/* #RNA_parameter_list_create ensures that 'thick wrap' PointerRNA parameters are
|
||||
* constructed. */
|
||||
ptr->~PointerRNA();
|
||||
}
|
||||
else if (parm->flag & PROP_DYNAMIC) {
|
||||
/* for dynamic arrays and strings, data is a pointer to an array */
|
||||
ParameterDynAlloc *data_alloc = static_cast<ParameterDynAlloc *>(
|
||||
(void *)(((char *)parms->data) + tot));
|
||||
ParameterDynAlloc *data_alloc = static_cast<ParameterDynAlloc *>(data);
|
||||
if (data_alloc->array) {
|
||||
MEM_freeN(data_alloc->array);
|
||||
}
|
||||
}
|
||||
|
||||
tot += rna_parameter_size_pad(rna_parameter_size(parm));
|
||||
data = static_cast<char *>(data) + rna_parameter_size_pad(rna_parameter_size(parm));
|
||||
}
|
||||
|
||||
MEM_freeN(parms->data);
|
||||
@@ -6507,6 +6520,14 @@ void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *valu
|
||||
data_alloc->array = MEM_mallocN(size, __func__);
|
||||
memcpy(data_alloc->array, value, size);
|
||||
}
|
||||
else if ((parm->flag_parameter & PARM_RNAPTR) && (parm->flag & PROP_THICK_WRAP)) {
|
||||
BLI_assert(parm->type == PROP_POINTER);
|
||||
BLI_assert(iter.size == sizeof(PointerRNA));
|
||||
PointerRNA *ptr = static_cast<PointerRNA *>(iter.data);
|
||||
/* #RNA_parameter_list_create ensures that 'thick wrap' PointerRNA parameters are
|
||||
* constructed. */
|
||||
*ptr = PointerRNA(*static_cast<const PointerRNA *>(value));
|
||||
}
|
||||
else {
|
||||
memcpy(iter.data, value, iter.size);
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ static void bpy_pydriver_namespace_update_depsgraph(Depsgraph *depsgraph)
|
||||
}
|
||||
|
||||
if ((g_pydriver_state_prev.depsgraph == nullptr) ||
|
||||
(depsgraph != g_pydriver_state_prev.depsgraph->ptr.data))
|
||||
(depsgraph != g_pydriver_state_prev.depsgraph->ptr->data))
|
||||
{
|
||||
PyObject *item = bpy_pydriver_depsgraph_as_pyobject(depsgraph);
|
||||
PyDict_SetItem(bpy_pydriver_Dict, bpy_intern_str_depsgraph, item);
|
||||
|
||||
@@ -240,12 +240,12 @@ void BPY_modules_update()
|
||||
|
||||
bContext *BPY_context_get()
|
||||
{
|
||||
return static_cast<bContext *>(bpy_context_module->ptr.data);
|
||||
return static_cast<bContext *>(bpy_context_module->ptr->data);
|
||||
}
|
||||
|
||||
void BPY_context_set(bContext *C)
|
||||
{
|
||||
bpy_context_module->ptr.data = (void *)C;
|
||||
bpy_context_module->ptr->data = (void *)C;
|
||||
}
|
||||
|
||||
#ifdef WITH_FLUID
|
||||
@@ -754,7 +754,7 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
done = true;
|
||||
}
|
||||
else if (BPy_StructRNA_Check(item)) {
|
||||
ptr = &(((BPy_StructRNA *)item)->ptr);
|
||||
ptr = &reinterpret_cast<BPy_StructRNA *>(item)->ptr.value();
|
||||
|
||||
// result->ptr = ((BPy_StructRNA *)item)->ptr;
|
||||
CTX_data_pointer_set_ptr(result, ptr);
|
||||
@@ -776,7 +776,7 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
PyObject *list_item = seq_fast_items[i];
|
||||
|
||||
if (BPy_StructRNA_Check(list_item)) {
|
||||
ptr = &(((BPy_StructRNA *)list_item)->ptr);
|
||||
ptr = &reinterpret_cast<BPy_StructRNA *>(list_item)->ptr.value();
|
||||
CTX_data_list_add_ptr(result, ptr);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -185,7 +185,7 @@ PyDoc_STRVAR(
|
||||
static PyObject *bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
Main *bmain_base = CTX_data_main(BPY_context_get());
|
||||
Main *bmain = static_cast<Main *>(self->ptr.data); /* Typically #G_MAIN */
|
||||
Main *bmain = static_cast<Main *>(self->ptr->data); /* Typically #G_MAIN */
|
||||
BPy_Library *ret;
|
||||
PyC_UnicodeAsBytesAndSize_Data filepath_data = {nullptr};
|
||||
bool is_rel = false, is_link = false, use_assets_only = false;
|
||||
|
||||
@@ -119,7 +119,7 @@ static PyObject *bpy_lib_write(BPy_PropertyRNA *self, PyObject *args, PyObject *
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Main *bmain_src = static_cast<Main *>(self->ptr.data); /* Typically #G_MAIN */
|
||||
Main *bmain_src = static_cast<Main *>(self->ptr->data); /* Typically #G_MAIN */
|
||||
int write_flags = 0;
|
||||
|
||||
if (use_compress) {
|
||||
|
||||
@@ -71,14 +71,14 @@ static int py_msgbus_rna_key_from_py(PyObject *py_sub,
|
||||
if (BPy_PropertyRNA_Check(py_sub)) {
|
||||
BPy_PropertyRNA *data_prop = (BPy_PropertyRNA *)py_sub;
|
||||
PYRNA_PROP_CHECK_INT(data_prop);
|
||||
msg_key_params->ptr = data_prop->ptr;
|
||||
msg_key_params->ptr = *data_prop->ptr;
|
||||
msg_key_params->prop = data_prop->prop;
|
||||
}
|
||||
else if (BPy_StructRNA_Check(py_sub)) {
|
||||
/* NOTE: this isn't typically used since we don't edit structs directly. */
|
||||
BPy_StructRNA *data_srna = (BPy_StructRNA *)py_sub;
|
||||
PYRNA_STRUCT_CHECK_INT(data_srna);
|
||||
msg_key_params->ptr = data_srna->ptr;
|
||||
msg_key_params->ptr = *data_srna->ptr;
|
||||
}
|
||||
/* TODO: property / type, not instance. */
|
||||
else if (PyType_Check(py_sub)) {
|
||||
|
||||
+1122
-597
File diff suppressed because it is too large
Load Diff
@@ -8,6 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
/* --- bpy build options --- */
|
||||
#include "intern/rna_internal_types.hh"
|
||||
#ifdef WITH_PYTHON_SAFETY
|
||||
@@ -103,8 +105,8 @@ extern PyTypeObject pyrna_func_Type;
|
||||
} \
|
||||
(void)0
|
||||
|
||||
#define PYRNA_STRUCT_IS_VALID(pysrna) (LIKELY(((BPy_StructRNA *)(pysrna))->ptr.type != NULL))
|
||||
#define PYRNA_PROP_IS_VALID(pysrna) (LIKELY(((BPy_PropertyRNA *)(pysrna))->ptr.type != NULL))
|
||||
#define PYRNA_STRUCT_IS_VALID(pysrna) (LIKELY(((BPy_StructRNA *)(pysrna))->ptr->type != NULL))
|
||||
#define PYRNA_PROP_IS_VALID(pysrna) (LIKELY(((BPy_PropertyRNA *)(pysrna))->ptr->type != NULL))
|
||||
|
||||
/* 'in_weakreflist' MUST be aligned */
|
||||
|
||||
@@ -113,7 +115,8 @@ struct BPy_DummyPointerRNA {
|
||||
#ifdef USE_WEAKREFS
|
||||
PyObject *in_weakreflist;
|
||||
#endif
|
||||
PointerRNA ptr;
|
||||
|
||||
std::optional<PointerRNA> ptr;
|
||||
};
|
||||
|
||||
struct BPy_StructRNA {
|
||||
@@ -121,7 +124,9 @@ struct BPy_StructRNA {
|
||||
#ifdef USE_WEAKREFS
|
||||
PyObject *in_weakreflist;
|
||||
#endif
|
||||
PointerRNA ptr;
|
||||
|
||||
std::optional<PointerRNA> ptr;
|
||||
|
||||
#ifdef USE_PYRNA_STRUCT_REFERENCE
|
||||
/* generic PyObject we hold a reference to, example use:
|
||||
* hold onto the collection iterator to prevent it from freeing allocated data we may use */
|
||||
@@ -139,18 +144,25 @@ struct BPy_PropertyRNA {
|
||||
#ifdef USE_WEAKREFS
|
||||
PyObject *in_weakreflist;
|
||||
#endif
|
||||
PointerRNA ptr;
|
||||
|
||||
std::optional<PointerRNA> ptr;
|
||||
PropertyRNA *prop;
|
||||
};
|
||||
|
||||
struct BPy_PropertyArrayRNA {
|
||||
PyObject_HEAD /* Required Python macro. */
|
||||
|
||||
/* START Must match #BPy_PropertyRNA. */
|
||||
|
||||
#ifdef USE_WEAKREFS
|
||||
PyObject *in_weakreflist;
|
||||
#endif
|
||||
PointerRNA ptr;
|
||||
|
||||
std::optional<PointerRNA> ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* END Must match #BPy_PropertyRNA. */
|
||||
|
||||
/* Arystan: this is a hack to allow sub-item r/w access like: face.uv[n][m] */
|
||||
/** Array dimension, e.g: 0 for face.uv, 2 for face.uv[n][m], etc. */
|
||||
int arraydim;
|
||||
@@ -165,7 +177,7 @@ struct BPy_PropertyCollectionIterRNA {
|
||||
#endif
|
||||
|
||||
/* collection iterator specific parts */
|
||||
CollectionPropertyIterator iter;
|
||||
std::optional<CollectionPropertyIterator> iter;
|
||||
};
|
||||
|
||||
struct BPy_FunctionRNA {
|
||||
@@ -173,7 +185,8 @@ struct BPy_FunctionRNA {
|
||||
#ifdef USE_WEAKREFS
|
||||
PyObject *in_weakreflist;
|
||||
#endif
|
||||
PointerRNA ptr;
|
||||
|
||||
std::optional<PointerRNA> ptr;
|
||||
FunctionRNA *func;
|
||||
};
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
if (pyrna_struct_keyframe_parse(&self->ptr,
|
||||
if (pyrna_struct_keyframe_parse(&self->ptr.value(),
|
||||
args,
|
||||
kw,
|
||||
"s|$ifsO!s:bpy_struct.keyframe_insert()",
|
||||
@@ -369,13 +369,13 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
|
||||
cfra);
|
||||
|
||||
if (self->ptr.type == &RNA_NlaStrip) {
|
||||
if (self->ptr->type == &RNA_NlaStrip) {
|
||||
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
|
||||
* strips themselves. These are stored separately or else the properties will
|
||||
* not have any effect.
|
||||
*/
|
||||
|
||||
PointerRNA &ptr = self->ptr;
|
||||
PointerRNA &ptr = *self->ptr;
|
||||
PropertyRNA *prop = nullptr;
|
||||
const char *prop_name;
|
||||
|
||||
@@ -402,12 +402,12 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
}
|
||||
}
|
||||
else {
|
||||
BLI_assert(BKE_id_is_in_global_main(self->ptr.owner_id));
|
||||
BLI_assert(BKE_id_is_in_global_main(self->ptr->owner_id));
|
||||
|
||||
const std::optional<blender::StringRefNull> channel_group = group_name ?
|
||||
std::optional(group_name) :
|
||||
std::nullopt;
|
||||
PointerRNA id_pointer = RNA_id_pointer_create(self->ptr.owner_id);
|
||||
PointerRNA id_pointer = RNA_id_pointer_create(self->ptr->owner_id);
|
||||
CombinedKeyingResult combined_result = insert_keyframes(G_MAIN,
|
||||
&id_pointer,
|
||||
channel_group,
|
||||
@@ -476,7 +476,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
if (pyrna_struct_keyframe_parse(&self->ptr,
|
||||
if (pyrna_struct_keyframe_parse(&self->ptr.value(),
|
||||
args,
|
||||
kw,
|
||||
"s|$ifsOs!:bpy_struct.keyframe_delete()",
|
||||
@@ -496,13 +496,13 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
if (self->ptr.type == &RNA_NlaStrip) {
|
||||
if (self->ptr->type == &RNA_NlaStrip) {
|
||||
/* Handle special properties for NLA Strips, whose F-Curves are stored on the
|
||||
* strips themselves. These are stored separately or else the properties will
|
||||
* not have any effect.
|
||||
*/
|
||||
|
||||
PointerRNA ptr = self->ptr;
|
||||
PointerRNA ptr = *self->ptr;
|
||||
PropertyRNA *prop = nullptr;
|
||||
const char *prop_name;
|
||||
|
||||
@@ -557,7 +557,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
rna_path.index = std::nullopt;
|
||||
}
|
||||
result = (blender::animrig::delete_keyframe(
|
||||
G.main, &reports, self->ptr.owner_id, rna_path, cfra) != 0);
|
||||
G.main, &reports, self->ptr->owner_id, rna_path, cfra) != 0);
|
||||
}
|
||||
|
||||
MEM_freeN((void *)path_full);
|
||||
@@ -593,7 +593,7 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
||||
}
|
||||
|
||||
if (pyrna_struct_anim_args_parse(
|
||||
&self->ptr, "bpy_struct.driver_add():", path, &path_full, &index) == -1)
|
||||
&self->ptr.value(), "bpy_struct.driver_add():", path, &path_full, &index) == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -605,7 +605,7 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
result = ANIM_add_driver(&reports,
|
||||
(ID *)self->ptr.owner_id,
|
||||
self->ptr->owner_id,
|
||||
path_full,
|
||||
index,
|
||||
CREATEDRIVER_WITH_FMODIFIER,
|
||||
@@ -616,7 +616,7 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
||||
}
|
||||
|
||||
if (result) {
|
||||
ID *id = self->ptr.owner_id;
|
||||
ID *id = self->ptr->owner_id;
|
||||
AnimData *adt = BKE_animdata_from_id(id);
|
||||
FCurve *fcu;
|
||||
|
||||
@@ -677,7 +677,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
|
||||
}
|
||||
|
||||
if (pyrna_struct_anim_args_parse_no_resolve_fallback(
|
||||
&self->ptr, "bpy_struct.driver_remove():", path, &path_full, &index) == -1)
|
||||
&self->ptr.value(), "bpy_struct.driver_remove():", path, &path_full, &index) == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@@ -687,7 +687,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
result = ANIM_remove_driver(self->ptr.owner_id, path_full, index);
|
||||
result = ANIM_remove_driver(self->ptr->owner_id, path_full, index);
|
||||
|
||||
if (path != path_full) {
|
||||
MEM_freeN((void *)path_full);
|
||||
|
||||
@@ -182,8 +182,8 @@ static PyObject *bpy_rna_data_context_enter(BPy_DataContext *self)
|
||||
|
||||
static PyObject *bpy_rna_data_context_exit(BPy_DataContext *self, PyObject * /*args*/)
|
||||
{
|
||||
BKE_main_free(static_cast<Main *>(self->data_rna->ptr.data));
|
||||
RNA_POINTER_INVALIDATE(&self->data_rna->ptr);
|
||||
BKE_main_free(static_cast<Main *>(self->data_rna->ptr->data));
|
||||
RNA_POINTER_INVALIDATE(&self->data_rna->ptr.value());
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ bool pyrna_driver_is_equal_anim_rna(const PathResolvedRNA *anim_rna, const PyObj
|
||||
{
|
||||
if (BPy_StructRNA_Check(py_anim_rna)) {
|
||||
const PointerRNA *ptr_a = &anim_rna->ptr;
|
||||
const PointerRNA *ptr_b = &(((const BPy_StructRNA *)py_anim_rna)->ptr);
|
||||
const PointerRNA *ptr_b = &reinterpret_cast<const BPy_StructRNA *>(py_anim_rna)->ptr.value();
|
||||
|
||||
if ((ptr_a->owner_id == ptr_b->owner_id) && (ptr_a->type == ptr_b->type) &&
|
||||
(ptr_a->data == ptr_b->data))
|
||||
|
||||
@@ -49,10 +49,10 @@ static int py_rna_gizmo_parse(PyObject *o, void *p)
|
||||
{
|
||||
/* No type checking (this is `self` not a user defined argument). */
|
||||
BLI_assert(BPy_StructRNA_Check(o));
|
||||
BLI_assert(RNA_struct_is_a(((const BPy_StructRNA *)o)->ptr.type, &RNA_Gizmo));
|
||||
BLI_assert(RNA_struct_is_a(((const BPy_StructRNA *)o)->ptr->type, &RNA_Gizmo));
|
||||
|
||||
wmGizmo **gz_p = static_cast<wmGizmo **>(p);
|
||||
*gz_p = static_cast<wmGizmo *>(((const BPy_StructRNA *)o)->ptr.data);
|
||||
*gz_p = static_cast<wmGizmo *>(((const BPy_StructRNA *)o)->ptr->data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ PyDoc_STRVAR(
|
||||
static PyObject *bpy_rna_region_as_string(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
|
||||
Text *text = static_cast<Text *>(pyrna->ptr.data);
|
||||
Text *text = static_cast<Text *>(pyrna->ptr->data);
|
||||
/* Parse the region range. */
|
||||
TextRegion region;
|
||||
|
||||
@@ -128,7 +128,7 @@ PyDoc_STRVAR(
|
||||
static PyObject *bpy_rna_region_from_string(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
|
||||
Text *text = static_cast<Text *>(pyrna->ptr.data);
|
||||
Text *text = static_cast<Text *>(pyrna->ptr->data);
|
||||
|
||||
/* Parse the region range. */
|
||||
const char *buf;
|
||||
|
||||
@@ -28,7 +28,7 @@ PyDoc_STRVAR(
|
||||
static PyObject *bpy_rna_uilayout_introspect(PyObject *self)
|
||||
{
|
||||
BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
|
||||
uiLayout *layout = static_cast<uiLayout *>(pyrna->ptr.data);
|
||||
uiLayout *layout = static_cast<uiLayout *>(pyrna->ptr->data);
|
||||
|
||||
const char *expr = UI_layout_introspect(layout);
|
||||
PyObject *main_mod = PyC_MainModule_Backup();
|
||||
|
||||
Reference in New Issue
Block a user