Merge branch 'master' into blender2.8
This commit is contained in:
@@ -127,54 +127,52 @@ int PyC_AsArray(
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Typed Tuple Packing
|
||||
*
|
||||
* \note See #PyC_Tuple_Pack_* macros that take multiple arguments.
|
||||
*
|
||||
* \{ */
|
||||
|
||||
/* array utility function */
|
||||
PyObject *PyC_FromArray(const void *array, int length, const PyTypeObject *type,
|
||||
const bool is_double, const char *error_prefix)
|
||||
PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len)
|
||||
{
|
||||
PyObject *tuple;
|
||||
int i;
|
||||
|
||||
tuple = PyTuple_New(length);
|
||||
|
||||
/* for each type */
|
||||
if (type == &PyFloat_Type) {
|
||||
if (is_double) {
|
||||
const double *array_double = array;
|
||||
for (i = 0; i < length; ++i) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array_double[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
const float *array_float = array;
|
||||
for (i = 0; i < length; ++i) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array_float[i]));
|
||||
}
|
||||
}
|
||||
PyObject *tuple = PyTuple_New(len);
|
||||
for (uint i = 0; i < len; i++) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyFloat_FromDouble(array[i]));
|
||||
}
|
||||
else if (type == &PyLong_Type) {
|
||||
/* could use is_double for 'long int' but no use now */
|
||||
const int *array_int = array;
|
||||
for (i = 0; i < length; ++i) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(array_int[i]));
|
||||
}
|
||||
}
|
||||
else if (type == &PyBool_Type) {
|
||||
const int *array_bool = array;
|
||||
for (i = 0; i < length; ++i) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array_bool[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Py_DECREF(tuple);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%s: internal error %s is invalid",
|
||||
error_prefix, type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tuple;
|
||||
}
|
||||
|
||||
PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len)
|
||||
{
|
||||
PyObject *tuple = PyTuple_New(len);
|
||||
for (uint i = 0; i < len; i++) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(array[i]));
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len)
|
||||
{
|
||||
PyObject *tuple = PyTuple_New(len);
|
||||
for (uint i = 0; i < len; i++) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array[i]));
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len)
|
||||
{
|
||||
PyObject *tuple = PyTuple_New(len);
|
||||
for (uint i = 0; i < len; i++) {
|
||||
PyTuple_SET_ITEM(tuple, i, PyBool_FromLong(array[i]));
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/**
|
||||
* Caller needs to ensure tuple is uninitialized.
|
||||
* Handy for filling a tuple with None for eg.
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#ifndef __PY_CAPI_UTILS_H__
|
||||
#define __PY_CAPI_UTILS_H__
|
||||
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
void PyC_ObSpit(const char *name, PyObject *var);
|
||||
void PyC_LineSpit(void);
|
||||
void PyC_StackSpit(void);
|
||||
@@ -43,8 +45,21 @@ int PyC_AsArray_FAST(
|
||||
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);
|
||||
|
||||
PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len);
|
||||
PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len);
|
||||
PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len);
|
||||
PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len);
|
||||
|
||||
#define PyC_Tuple_Pack_F32(...) \
|
||||
PyC_Tuple_PackArray_F32(((const float []){__VA_ARGS__}), (sizeof((const float []){__VA_ARGS__}) / sizeof(float)))
|
||||
#define PyC_Tuple_Pack_I32(...) \
|
||||
PyC_Tuple_PackArray_I32(((const int []){__VA_ARGS__}), (sizeof((const int []){__VA_ARGS__}) / sizeof(int)))
|
||||
#define PyC_Tuple_Pack_I32FromBool(...) \
|
||||
PyC_Tuple_PackArray_I32FromBool(((const int []){__VA_ARGS__}), (sizeof((const int []){__VA_ARGS__}) / sizeof(int)))
|
||||
#define PyC_Tuple_Pack_Bool(...) \
|
||||
PyC_Tuple_PackArray_Bool(((const bool []){__VA_ARGS__}), (sizeof((const bool []){__VA_ARGS__}) / sizeof(bool)))
|
||||
|
||||
void PyC_Tuple_Fill(PyObject *tuple, PyObject *value);
|
||||
void PyC_List_Fill(PyObject *list, PyObject *value);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -121,8 +121,7 @@ static void py_rna_manipulator_handler_set_cb(
|
||||
py_value = PyFloat_FromDouble(*value);
|
||||
}
|
||||
else {
|
||||
py_value = PyC_FromArray((void *)value, mpr_prop->type->array_length, &PyFloat_Type, false,
|
||||
"Manipulator set callback: ");
|
||||
py_value = PyC_Tuple_PackArray_F32(value, mpr_prop->type->array_length);
|
||||
}
|
||||
if (py_value == NULL) {
|
||||
goto fail;
|
||||
|
||||
@@ -1279,7 +1279,7 @@ static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject
|
||||
index = 0;
|
||||
dl_face = dl->index;
|
||||
while (index < dl->parts) {
|
||||
PyList_SET_ITEM(tri_list, index, Py_BuildValue("iii", dl_face[0], dl_face[1], dl_face[2]));
|
||||
PyList_SET_ITEM(tri_list, index, PyC_Tuple_Pack_I32(dl_face[0], dl_face[1], dl_face[2]));
|
||||
dl_face += 3;
|
||||
index++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user