PyAPI: add PyList_APPEND
This appends while giving ownership to the list, avoiding temp assignment. This matches PyList_SET_ITEM which bypasses refcount's Note, this also reduce code-size, Py_DECREF is a rather heavy macro.
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
#include "bpy_utils_units.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
#include "../generic/python_utildefines.h"
|
||||
|
||||
/* external util modules */
|
||||
#include "../generic/idprop_py_api.h"
|
||||
@@ -89,10 +90,7 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self))
|
||||
|
||||
static bool bpy_blend_paths_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
|
||||
{
|
||||
PyObject *list = (PyObject *)userdata;
|
||||
PyObject *item = PyC_UnicodeFromByte(path_src);
|
||||
PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
PyList_APPEND((PyObject *)userdata, PyC_UnicodeFromByte(path_src));
|
||||
return false; /* never edits the path */
|
||||
}
|
||||
|
||||
|
||||
@@ -2302,8 +2302,7 @@ static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self, Py
|
||||
RNA_property_collection_next(&rna_macro_iter))
|
||||
{
|
||||
item = pyrna_struct_CreatePyObject(&rna_macro_iter.ptr);
|
||||
PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
PyList_APPEND(list, item);
|
||||
|
||||
count++;
|
||||
if (count == stop) {
|
||||
@@ -3427,7 +3426,6 @@ static void pyrna_dir_members_py(PyObject *list, PyObject *self)
|
||||
|
||||
static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr)
|
||||
{
|
||||
PyObject *pystring;
|
||||
const char *idname;
|
||||
|
||||
/* for looping over attrs and funcs */
|
||||
@@ -3443,10 +3441,7 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr)
|
||||
FunctionRNA *func = itemptr.data;
|
||||
if (RNA_function_defined(func)) {
|
||||
idname = RNA_function_identifier(itemptr.data);
|
||||
|
||||
pystring = PyUnicode_FromString(idname);
|
||||
PyList_Append(list, pystring);
|
||||
Py_DECREF(pystring);
|
||||
PyList_APPEND(list, PyUnicode_FromString(idname));
|
||||
}
|
||||
}
|
||||
RNA_PROP_END;
|
||||
@@ -3466,9 +3461,7 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr)
|
||||
nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
|
||||
|
||||
if (nameptr) {
|
||||
pystring = PyUnicode_FromStringAndSize(nameptr, namelen);
|
||||
PyList_Append(list, pystring);
|
||||
Py_DECREF(pystring);
|
||||
PyList_APPEND(list, PyUnicode_FromStringAndSize(nameptr, namelen));
|
||||
|
||||
if (name != nameptr) {
|
||||
MEM_freeN(nameptr);
|
||||
@@ -3483,7 +3476,6 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr)
|
||||
static PyObject *pyrna_struct_dir(BPy_StructRNA *self)
|
||||
{
|
||||
PyObject *ret;
|
||||
PyObject *pystring;
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
@@ -3502,9 +3494,7 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self)
|
||||
LinkData *link;
|
||||
|
||||
for (link = lb.first; link; link = link->next) {
|
||||
pystring = PyUnicode_FromString(link->data);
|
||||
PyList_Append(ret, pystring);
|
||||
Py_DECREF(pystring);
|
||||
PyList_APPEND(ret, PyUnicode_FromString(link->data));
|
||||
}
|
||||
|
||||
BLI_freelistN(&lb);
|
||||
@@ -3584,14 +3574,11 @@ static PyObject *pyrna_struct_getattro(BPy_StructRNA *self, PyObject *pyname)
|
||||
case CTX_DATA_TYPE_COLLECTION:
|
||||
{
|
||||
CollectionPointerLink *link;
|
||||
PyObject *linkptr;
|
||||
|
||||
ret = PyList_New(0);
|
||||
|
||||
for (link = newlb.first; link; link = link->next) {
|
||||
linkptr = pyrna_struct_CreatePyObject(&link->ptr);
|
||||
PyList_Append(ret, linkptr);
|
||||
Py_DECREF(linkptr);
|
||||
PyList_APPEND(ret, pyrna_struct_CreatePyObject(&link->ptr));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -4098,7 +4085,6 @@ PyDoc_STRVAR(pyrna_prop_collection_keys_doc,
|
||||
static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
|
||||
{
|
||||
PyObject *ret = PyList_New(0);
|
||||
PyObject *item;
|
||||
char name[256], *nameptr;
|
||||
int namelen;
|
||||
|
||||
@@ -4107,11 +4093,7 @@ static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
|
||||
nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
|
||||
|
||||
if (nameptr) {
|
||||
/* add to python list */
|
||||
item = PyUnicode_FromStringAndSize(nameptr, namelen);
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
/* done */
|
||||
PyList_APPEND(ret, PyUnicode_FromStringAndSize(nameptr, namelen));
|
||||
|
||||
if (name != nameptr) {
|
||||
MEM_freeN(nameptr);
|
||||
@@ -4157,8 +4139,7 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self)
|
||||
}
|
||||
PyTuple_SET_ITEM(item, 1, pyrna_struct_CreatePyObject(&itemptr));
|
||||
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
PyList_APPEND(ret, item);
|
||||
|
||||
i++;
|
||||
}
|
||||
@@ -4967,14 +4948,11 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
|
||||
{
|
||||
ListBase *lb = (ListBase *)data;
|
||||
CollectionPointerLink *link;
|
||||
PyObject *linkptr;
|
||||
|
||||
ret = PyList_New(0);
|
||||
|
||||
for (link = lb->first; link; link = link->next) {
|
||||
linkptr = pyrna_struct_CreatePyObject(&link->ptr);
|
||||
PyList_Append(ret, linkptr);
|
||||
Py_DECREF(linkptr);
|
||||
PyList_APPEND(ret, pyrna_struct_CreatePyObject(&link->ptr));
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -5138,9 +5116,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
|
||||
#ifdef DEBUG_STRING_FREE
|
||||
if (item) {
|
||||
if (PyUnicode_Check(item)) {
|
||||
item = PyUnicode_FromString(_PyUnicode_AsString(item));
|
||||
PyList_Append(string_free_ls, item);
|
||||
Py_DECREF(item);
|
||||
PyList_APPEND(string_free_ls, PyUnicode_FromString(_PyUnicode_AsString(item)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -6597,7 +6573,6 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self)
|
||||
{
|
||||
PyObject *list;
|
||||
#if 0
|
||||
PyObject *name;
|
||||
PyMethodDef *meth;
|
||||
#endif
|
||||
|
||||
@@ -6605,9 +6580,7 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self)
|
||||
|
||||
#if 0 /* for now only contains __dir__ */
|
||||
for (meth = pyrna_basetype_methods; meth->ml_name; meth++) {
|
||||
name = PyUnicode_FromString(meth->ml_name);
|
||||
PyList_Append(list, name);
|
||||
Py_DECREF(name);
|
||||
PyList_APPEND(list, PyUnicode_FromString(meth->ml_name));
|
||||
}
|
||||
#endif
|
||||
return list;
|
||||
@@ -6618,7 +6591,6 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self)
|
||||
static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self)
|
||||
{
|
||||
PyObject *ret = PyList_New(0);
|
||||
PyObject *item;
|
||||
|
||||
RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop)
|
||||
{
|
||||
@@ -6630,9 +6602,7 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self)
|
||||
}
|
||||
else {
|
||||
/* add to python list */
|
||||
item = PyUnicode_FromString(RNA_struct_identifier(srna));
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
PyList_APPEND(ret, PyUnicode_FromString(RNA_struct_identifier(srna)));
|
||||
}
|
||||
}
|
||||
RNA_PROP_END;
|
||||
|
||||
@@ -53,6 +53,8 @@
|
||||
#include "bpy_util.h"
|
||||
#include "bpy_rna_anim.h"
|
||||
|
||||
#include "../generic/python_utildefines.h"
|
||||
|
||||
/* for keyframes and drivers */
|
||||
static int pyrna_struct_anim_args_parse(
|
||||
PointerRNA *ptr, const char *error_prefix, const char *path,
|
||||
@@ -329,16 +331,13 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
||||
FCurve *fcu;
|
||||
|
||||
PointerRNA tptr;
|
||||
PyObject *item;
|
||||
|
||||
if (index == -1) { /* all, use a list */
|
||||
int i = 0;
|
||||
ret = PyList_New(0);
|
||||
while ((fcu = list_find_fcurve(&adt->drivers, path_full, i++))) {
|
||||
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
|
||||
item = pyrna_struct_CreatePyObject(&tptr);
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
PyList_APPEND(ret, pyrna_struct_CreatePyObject(&tptr));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user