Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-01-06 09:39:47 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-01-06 11:09:53 +0300
commitbf0c8e116db49379900020b5a20ba15d91b3fb9a (patch)
treec65b43084bde562dc2a08b5d88cb128f09028b6b /source
parent9fd569a654ded46901c7f20c5fe080972cbb10d2 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c6
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_select.c6
-rw-r--r--source/blender/python/generic/python_utildefines.h8
-rw-r--r--source/blender/python/intern/bpy.c6
-rw-r--r--source/blender/python/intern/bpy_rna.c52
-rw-r--r--source/blender/python/intern/bpy_rna_anim.c7
-rw-r--r--source/blender/python/mathutils/mathutils_geometry.c9
7 files changed, 30 insertions, 64 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index d3f4bfcacda..1da5599ea29 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -44,6 +44,7 @@
#include "../mathutils/mathutils.h"
#include "../generic/py_capi_utils.h"
+#include "../generic/python_utildefines.h"
#include "bmesh_py_types.h" /* own include */
#include "bmesh_py_types_select.h"
@@ -2796,7 +2797,6 @@ static PyObject *bpy_bmelemseq_subscript_slice(BPy_BMElemSeq *self, Py_ssize_t s
bool ok;
PyObject *list;
- PyObject *item;
BMHeader *ele;
BPY_BM_CHECK_OBJ(self);
@@ -2821,9 +2821,7 @@ static PyObject *bpy_bmelemseq_subscript_slice(BPy_BMElemSeq *self, Py_ssize_t s
/* add items until stop */
while ((ele = BM_iter_step(&iter))) {
- item = BPy_BMElem_CreatePyObject(self->bm, ele);
- PyList_Append(list, item);
- Py_DECREF(item);
+ PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, ele));
count++;
if (count == stop) {
diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c
index 6dd0ec5be0b..7b792e9f08e 100644
--- a/source/blender/python/bmesh/bmesh_py_types_select.c
+++ b/source/blender/python/bmesh/bmesh_py_types_select.c
@@ -44,6 +44,7 @@
#include "bmesh_py_types_select.h"
#include "../generic/py_capi_utils.h"
+#include "../generic/python_utildefines.h"
PyDoc_STRVAR(bpy_bmeditselseq_active_doc,
"The last selected element or None (read-only).\n\n:type: :class:`BMVert`, :class:`BMEdge` or :class:`BMFace`"
@@ -193,7 +194,6 @@ static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, Py_ssi
bool ok;
PyObject *list;
- PyObject *item;
BMEditSelection *ese;
BPY_BM_CHECK_OBJ(self);
@@ -218,9 +218,7 @@ static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, Py_ssi
/* add items until stop */
while ((ese = ese->next)) {
- item = BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head);
- PyList_Append(list, item);
- Py_DECREF(item);
+ PyList_APPEND(list, BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head));
count++;
if (count == stop) {
diff --git a/source/blender/python/generic/python_utildefines.h b/source/blender/python/generic/python_utildefines.h
index 555ad4819eb..f7d3e7a8b4a 100644
--- a/source/blender/python/generic/python_utildefines.h
+++ b/source/blender/python/generic/python_utildefines.h
@@ -44,6 +44,14 @@ extern "C" {
* use sparingly to avoid comma operator or temp var assignment */
BLI_INLINE PyObject *Py_INCREF_RET(PyObject *op) { Py_INCREF(op); return op; }
+/* append & transfer ownership to the list, avoids inline Py_DECREF all over (which is quite a large macro) */
+BLI_INLINE int PyList_APPEND(PyObject *op, PyObject *v)
+{
+ int ret = PyList_Append(op, v);
+ Py_DecRef(v);
+ return ret;
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index dbeccfdb8e6..ec3c017a7ed 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -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 */
}
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 74006c48dee..592150239be 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -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;
diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c
index ed51ba5bd1f..ced7d6a5c1c 100644
--- a/source/blender/python/intern/bpy_rna_anim.c
+++ b/source/blender/python/intern/bpy_rna_anim.c
@@ -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 {
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c
index 261234e6aae..da46af8a847 100644
--- a/source/blender/python/mathutils/mathutils_geometry.c
+++ b/source/blender/python/mathutils/mathutils_geometry.c
@@ -1061,10 +1061,7 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a
if (l == len) { /* ok */
/* python */
- PyObject *item = Vector_CreatePyObject(potentialVertex, 3, NULL);
- PyList_Append(py_verts, item);
- Py_DECREF(item);
-
+ PyList_APPEND(py_verts, Vector_CreatePyObject(potentialVertex, 3, NULL));
planes_used[i] = planes_used[j] = planes_used[k] = true;
}
}
@@ -1080,9 +1077,7 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a
/* now make a list of used planes */
for (i = 0; i < len; i++) {
if (planes_used[i]) {
- PyObject *item = PyLong_FromLong(i);
- PyList_Append(py_plane_index, item);
- Py_DECREF(item);
+ PyList_APPEND(py_plane_index, PyLong_FromLong(i));
}
}
PyMem_Free(planes_used);