PyAPI: Fix for instancing (Blender owns a reference)

Also set newly created values to the instance pointer.
This commit is contained in:
Campbell Barton 2017-07-26 23:05:00 +10:00
parent 80befca6e5
commit 40a45e393e
1 changed files with 16 additions and 11 deletions

View File

@ -6657,18 +6657,17 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr)
if (ptr->data == NULL && ptr->type == NULL) { /* Operator RNA has NULL data */
Py_RETURN_NONE;
}
else {
/* New in 2.8x, since not many types support instancing
* we may want to use a flag to avoid looping over all classes. - campbell */
{
void **instance = RNA_struct_instance(ptr);
if (instance && *instance) {
pyrna = *instance;
Py_INCREF(pyrna);
return (PyObject *)pyrna;
}
}
/* New in 2.8x, since not many types support instancing
* we may want to use a flag to avoid looping over all classes. - campbell */
void **instance = RNA_struct_instance(ptr);
if (instance && *instance) {
pyrna = *instance;
Py_INCREF(pyrna);
return (PyObject *)pyrna;
}
{
PyTypeObject *tp = (PyTypeObject *)pyrna_struct_Subtype(ptr);
if (tp) {
@ -6689,6 +6688,12 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr)
return NULL;
}
/* Blender's instance owns a reference (to avoid Python freeing it). */
if (instance) {
*instance = pyrna;
Py_INCREF(pyrna);
}
pyrna->ptr = *ptr;
#ifdef PYRNA_FREE_SUPPORT
pyrna->freeptr = false;