[Bf-blender-cvs] [90efa34] master: Python API: utility function for filling a tuple with a single value.

Campbell Barton noreply at git.blender.org
Mon Jan 6 10:45:23 CET 2014


Commit: 90efa345c2b512c7dbc615b6210127070ff8b03f
Author: Campbell Barton
Date:   Mon Jan 6 16:46:00 2014 +1100
https://developer.blender.org/rB90efa345c2b512c7dbc615b6210127070ff8b03f

Python API: utility function for filling a tuple with a single value.

===================================================================

M	source/blender/python/generic/py_capi_utils.c
M	source/blender/python/generic/py_capi_utils.h

===================================================================

diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 8e90d48..a37933d 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -162,6 +162,20 @@ PyObject *PyC_FromArray(const void *array, int length, const PyTypeObject *type,
 	return tuple;
 }
 
+/**
+ * Caller needs to ensure tuple is uninitialized.
+ * Handy for filling a typle with None for eg.
+ */
+void PyC_Tuple_Fill(PyObject *tuple, PyObject *value)
+{
+	unsigned int tot = PyTuple_GET_SIZE(tuple);
+	unsigned int i;
+
+	for (i = 0; i < tot; i++) {
+		PyTuple_SET_ITEM(tuple, i, value);
+		Py_INCREF(value);
+	}
+}
 
 /* for debugging */
 void PyC_ObSpit(const char *name, PyObject *var)
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index c6792dd..27dd1bb 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -41,6 +41,7 @@ int				PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length,
                             const PyTypeObject *type, const bool is_double, const char *error_prefix);
 PyObject *      PyC_FromArray(const void *array, int length, const PyTypeObject *type,
                               const bool is_double, const char *error_prefix);
+void            PyC_Tuple_Fill(PyObject *tuple, PyObject *value);
 
 /* follow http://www.python.org/dev/peps/pep-0383/ */
 PyObject *      PyC_UnicodeFromByte(const char *str);




More information about the Bf-blender-cvs mailing list