PyAPI: replace PyC_FromArray with typed functions
This was meant to be generic but introduced possible type errors and unnecessary complication. Replace with typed PyC_Tuple_PackArray_* functions. Also add PyC_Tuple_Pack_* macro which replaces some uses of Py_BuildValue, with the advantage of not having to parse a string.
This commit is contained in:
@@ -157,8 +157,7 @@ static PyObject *make_app_info(void)
|
||||
#define SetObjItem(obj) \
|
||||
PyStructSequence_SET_ITEM(app_info, pos++, obj)
|
||||
|
||||
SetObjItem(Py_BuildValue("(iii)",
|
||||
BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
|
||||
SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)",
|
||||
BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
|
||||
|
||||
|
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "bpy_app_alembic.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_ALEMBIC
|
||||
# include "ABC_alembic.h"
|
||||
#endif
|
||||
@@ -79,11 +81,11 @@ static PyObject *make_alembic_info(void)
|
||||
const int patch = curversion - ((curversion / 100 ) * 100);
|
||||
|
||||
SetObjItem(PyBool_FromLong(1));
|
||||
SetObjItem(Py_BuildValue("(iii)", major, minor, patch));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(major, minor, patch));
|
||||
SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", major, minor, patch));
|
||||
#else
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
SetObjItem(Py_BuildValue("(iii)", 0, 0, 0));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
|
||||
SetStrItem("Unknown");
|
||||
#endif
|
||||
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "bpy_app_ffmpeg.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_FFMPEG
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavdevice/avdevice.h>
|
||||
@@ -91,8 +93,7 @@ static PyObject *make_ffmpeg_info(void)
|
||||
#ifdef WITH_FFMPEG
|
||||
# define FFMPEG_LIB_VERSION(lib) { \
|
||||
curversion = lib ## _version(); \
|
||||
SetObjItem(Py_BuildValue("(iii)", \
|
||||
curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
|
||||
SetObjItem(PyC_Tuple_Pack_I32(curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
|
||||
SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", \
|
||||
curversion >> 16, (curversion >> 8) % 256, curversion % 256)); \
|
||||
} (void)0
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "bpy_app_ocio.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_OCIO
|
||||
# include "ocio_capi.h"
|
||||
#endif
|
||||
@@ -74,13 +76,12 @@ static PyObject *make_ocio_info(void)
|
||||
#ifdef WITH_OCIO
|
||||
curversion = OCIO_getVersionHex();
|
||||
SetObjItem(PyBool_FromLong(1));
|
||||
SetObjItem(Py_BuildValue("(iii)",
|
||||
curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
|
||||
SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d",
|
||||
curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
|
||||
#else
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
SetObjItem(Py_BuildValue("(iii)", 0, 0, 0));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
|
||||
SetStrItem("Unknown");
|
||||
#endif
|
||||
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "bpy_app_oiio.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_OPENIMAGEIO
|
||||
# include "openimageio_api.h"
|
||||
#endif
|
||||
@@ -74,13 +76,12 @@ static PyObject *make_oiio_info(void)
|
||||
#ifdef WITH_OPENIMAGEIO
|
||||
curversion = OIIO_getVersionHex();
|
||||
SetObjItem(PyBool_FromLong(1));
|
||||
SetObjItem(Py_BuildValue("(iii)",
|
||||
curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d",
|
||||
curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
#else
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
SetObjItem(Py_BuildValue("(iii)", 0, 0, 0));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
|
||||
SetStrItem("Unknown");
|
||||
#endif
|
||||
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "bpy_app_opensubdiv.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_OPENSUBDIV
|
||||
# include "opensubdiv_capi.h"
|
||||
#endif
|
||||
@@ -70,13 +72,12 @@ static PyObject *make_opensubdiv_info(void)
|
||||
#ifdef WITH_OPENSUBDIV
|
||||
int curversion = openSubdiv_getVersionHex();
|
||||
SetObjItem(PyBool_FromLong(1));
|
||||
SetObjItem(Py_BuildValue("(iii)",
|
||||
curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d",
|
||||
curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
||||
#else
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
SetObjItem(Py_BuildValue("(iii)", 0, 0, 0));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
|
||||
SetStrItem("Unknown");
|
||||
#endif
|
||||
|
||||
|
@@ -34,6 +34,8 @@
|
||||
|
||||
#include "bpy_app_openvdb.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_OPENVDB
|
||||
# include "openvdb_capi.h"
|
||||
#endif
|
||||
@@ -79,13 +81,12 @@ static PyObject *make_openvdb_info(void)
|
||||
#ifdef WITH_OPENVDB
|
||||
curversion = OpenVDB_getVersionHex();
|
||||
SetObjItem(PyBool_FromLong(1));
|
||||
SetObjItem(Py_BuildValue("(iii)",
|
||||
curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
|
||||
SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d",
|
||||
curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
|
||||
#else
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
SetObjItem(Py_BuildValue("(iii)", 0, 0, 0));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
|
||||
SetStrItem("Unknown");
|
||||
#endif
|
||||
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include "bpy_app_sdl.h"
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#ifdef WITH_SDL
|
||||
/* SDL force defines __SSE__ and __SSE2__ flags, which generates warnings
|
||||
* because we pass those defines via command line as well. For until there's
|
||||
@@ -103,7 +105,7 @@ static PyObject *make_sdl_info(void)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
SetObjItem(Py_BuildValue("(iii)", version.major, version.minor, version.patch));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(version.major, version.minor, version.patch));
|
||||
if (sdl_available) {
|
||||
SetObjItem(PyUnicode_FromFormat("%d.%d.%d", version.major, version.minor, version.patch));
|
||||
}
|
||||
@@ -114,7 +116,7 @@ static PyObject *make_sdl_info(void)
|
||||
|
||||
#else // WITH_SDL=OFF
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
SetObjItem(Py_BuildValue("(iii)", 0, 0, 0));
|
||||
SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0));
|
||||
SetStrItem("Unknown");
|
||||
SetObjItem(PyBool_FromLong(0));
|
||||
#endif
|
||||
|
@@ -530,12 +530,8 @@ static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr, struct Propert
|
||||
self = pyrna_struct_as_instance(ptr);
|
||||
PyTuple_SET_ITEM(args, 0, self);
|
||||
|
||||
py_values = PyC_FromArray(values, len, &PyBool_Type, false, "BoolVectorProperty set");
|
||||
if (!py_values) {
|
||||
printf_func_error(py_func);
|
||||
}
|
||||
else
|
||||
PyTuple_SET_ITEM(args, 1, py_values);
|
||||
py_values = PyC_Tuple_PackArray_I32FromBool(values, len);
|
||||
PyTuple_SET_ITEM(args, 1, py_values);
|
||||
|
||||
ret = PyObject_CallObject(py_func, args);
|
||||
|
||||
@@ -764,12 +760,8 @@ static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA
|
||||
self = pyrna_struct_as_instance(ptr);
|
||||
PyTuple_SET_ITEM(args, 0, self);
|
||||
|
||||
py_values = PyC_FromArray(values, len, &PyLong_Type, false, "IntVectorProperty set");
|
||||
if (!py_values) {
|
||||
printf_func_error(py_func);
|
||||
}
|
||||
else
|
||||
PyTuple_SET_ITEM(args, 1, py_values);
|
||||
py_values = PyC_Tuple_PackArray_I32(values, len);
|
||||
PyTuple_SET_ITEM(args, 1, py_values);
|
||||
|
||||
ret = PyObject_CallObject(py_func, args);
|
||||
|
||||
@@ -998,12 +990,8 @@ static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr, struct PropertyR
|
||||
self = pyrna_struct_as_instance(ptr);
|
||||
PyTuple_SET_ITEM(args, 0, self);
|
||||
|
||||
py_values = PyC_FromArray(values, len, &PyFloat_Type, false, "FloatVectorProperty set");
|
||||
if (!py_values) {
|
||||
printf_func_error(py_func);
|
||||
}
|
||||
else
|
||||
PyTuple_SET_ITEM(args, 1, py_values);
|
||||
py_values = PyC_Tuple_PackArray_F32(values, len);
|
||||
PyTuple_SET_ITEM(args, 1, py_values);
|
||||
|
||||
ret = PyObject_CallObject(py_func, args);
|
||||
|
||||
|
Reference in New Issue
Block a user