Merged changes in the trunk up to revision 52815.

This commit is contained in:
Tamito Kajiyama
2012-12-08 12:35:14 +00:00
179 changed files with 7153 additions and 5305 deletions

View File

@@ -153,13 +153,6 @@ static struct PyMethodDef BPy_BM_methods[] = {
PyDoc_STRVAR(BPy_BM_doc,
"This module provides access to blenders bmesh data structures.\n"
"\n"
"\n"
"Submodules:\n"
"\n"
"* :mod:`bmesh.utils`\n"
"* :mod:`bmesh.types`\n"
"\n"
"\n"
".. include:: include__bmesh.rst\n"
);
static struct PyModuleDef BPy_BM_module_def = {

View File

@@ -268,6 +268,23 @@ void BPY_python_start(int argc, const char **argv)
Py_Initialize();
/* THIS IS BAD: see http://bugs.python.org/issue16129 */
#if 1
/* until python provides a reliable way to set the env var */
PyRun_SimpleString("import sys, io\n"
"sys.__backup_stdio__ = sys.__stdout__, sys.__stderr__\n" /* else we loose the FD's [#32720] */
"sys.__stdout__ = sys.stdout = io.TextIOWrapper(io.open(sys.stdout.fileno(), 'wb', -1), "
"encoding='utf-8', errors='surrogateescape', newline='\\n', line_buffering=True)\n"
"sys.__stderr__ = sys.stderr = io.TextIOWrapper(io.open(sys.stderr.fileno(), 'wb', -1), "
"encoding='utf-8', errors='surrogateescape', newline='\\n', line_buffering=True)\n");
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
}
#endif
/* end the baddness */
// PySys_SetArgv(argc, argv); /* broken in py3, not a huge deal */
/* sigh, why do python guys not have a (char **) version anymore? */
{
@@ -601,7 +618,7 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
}
}
PyC_MainModule_Backup(&main_mod);
PyC_MainModule_Restore(main_mod);
bpy_context_clear(C, &gilstate);

View File

@@ -39,70 +39,80 @@ static const char *traceback_filepath(PyTracebackObject *tb, PyObject **coerce)
return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
}
/* copied from pythonrun.c, 3.2.0 */
/* copied from pythonrun.c, 3.3.0 */
static int
parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
int *lineno, int *offset, const char **text)
{
long hold;
PyObject *v;
_Py_IDENTIFIER(msg);
_Py_IDENTIFIER(filename);
_Py_IDENTIFIER(lineno);
_Py_IDENTIFIER(offset);
_Py_IDENTIFIER(text);
/* old style errors */
if (PyTuple_Check(err))
return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
lineno, offset, text);
*message = NULL;
/* new style errors. `err' is an instance */
if (!(v = PyObject_GetAttrString(err, "msg")))
*message = _PyObject_GetAttrId(err, &PyId_msg);
if (!*message)
goto finally;
*message = v;
if (!(v = PyObject_GetAttrString(err, "filename")))
v = _PyObject_GetAttrId(err, &PyId_filename);
if (!v)
goto finally;
if (v == Py_None)
if (v == Py_None) {
Py_DECREF(v);
*filename = NULL;
else if (!(*filename = _PyUnicode_AsString(v)))
goto finally;
}
else {
*filename = _PyUnicode_AsString(v);
Py_DECREF(v);
if (!*filename)
goto finally;
}
Py_DECREF(v);
if (!(v = PyObject_GetAttrString(err, "lineno")))
v = _PyObject_GetAttrId(err, &PyId_lineno);
if (!v)
goto finally;
hold = PyLong_AsLong(v);
Py_DECREF(v);
v = NULL;
if (hold < 0 && PyErr_Occurred())
goto finally;
*lineno = (int)hold;
if (!(v = PyObject_GetAttrString(err, "offset")))
v = _PyObject_GetAttrId(err, &PyId_offset);
if (!v)
goto finally;
if (v == Py_None) {
*offset = -1;
Py_DECREF(v);
v = NULL;
}
else {
} else {
hold = PyLong_AsLong(v);
Py_DECREF(v);
v = NULL;
if (hold < 0 && PyErr_Occurred())
goto finally;
*offset = (int)hold;
}
if (!(v = PyObject_GetAttrString(err, "text")))
v = _PyObject_GetAttrId(err, &PyId_text);
if (!v)
goto finally;
if (v == Py_None)
if (v == Py_None) {
Py_DECREF(v);
*text = NULL;
else if (!PyUnicode_Check(v) ||
!(*text = _PyUnicode_AsString(v)))
goto finally;
Py_DECREF(v);
}
else {
*text = _PyUnicode_AsString(v);
Py_DECREF(v);
if (!*text)
goto finally;
}
return 1;
finally:
Py_XDECREF(v);
Py_XDECREF(*message);
return 0;
}
/* end copied function! */

View File

@@ -27,16 +27,8 @@
#ifndef __BPY_UTIL_H__
#define __BPY_UTIL_H__
#if PY_VERSION_HEX < 0x03020000
# error "Python 3.2 or greater is required, you'll need to update your python."
#endif
#if PY_VERSION_HEX < 0x03030000
# ifdef _MSC_VER
# pragma message("Python 3.2 will be deprecated soon, upgrade to Python 3.3.")
# else
# warning "Python 3.2 will be deprecated soon, upgrade to Python 3.3."
# endif
# error "Python 3.3 or greater is required, you'll need to update your python."
#endif
struct EnumPropertyItem;

View File

@@ -35,7 +35,10 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#ifndef MATH_STANDALONE
# include "BLI_dynstr.h"
#endif
PyDoc_STRVAR(M_Mathutils_doc,
"This module provides access to matrices, eulers, quaternions and vectors."
@@ -302,7 +305,7 @@ int EXPP_FloatsAreEqual(float af, float bf, int maxDiff)
/*---------------------- EXPP_VectorsAreEqual -------------------------
* Builds on EXPP_FloatsAreEqual to test vectors */
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps)
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps)
{
int x;
for (x = 0; x < size; x++) {
@@ -312,6 +315,7 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps)
return 1;
}
#ifndef MATH_STANDALONE
/* dynstr as python string utility funcions, frees 'ds'! */
PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
{
@@ -324,6 +328,7 @@ PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
PyMem_Free(ds_buf);
return ret;
}
#endif
/* silly function, we dont use arg. just check its compatible with __deepcopy__ */
int mathutils_deepcopy_args_check(PyObject *args)

View File

@@ -74,7 +74,7 @@ void BaseMathObject_dealloc(BaseMathObject * self);
PyMODINIT_FUNC PyInit_mathutils(void);
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps);
#define Py_NEW 1
#define Py_WRAP 2
@@ -120,8 +120,11 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat);
#ifndef MATH_STANDALONE
/* dynstr as python string utility funcions */
PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
#endif
int mathutils_deepcopy_args_check(PyObject *args);
#endif /* __MATHUTILS_H__ */

View File

@@ -31,7 +31,10 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#ifndef MATH_STANDALONE
# include "BLI_dynstr.h"
#endif
#define COLOR_SIZE 3
@@ -131,6 +134,7 @@ static PyObject *Color_repr(ColorObject *self)
return ret;
}
#ifndef MATH_STANDALONE
static PyObject *Color_str(ColorObject *self)
{
DynStr *ds;
@@ -145,6 +149,7 @@ static PyObject *Color_str(ColorObject *self)
return mathutils_dynstr_to_py(ds); /* frees ds */
}
#endif
/* ------------------------tp_richcmpr */
/* returns -1 exception, 0 false, 1 true */
@@ -820,7 +825,11 @@ PyTypeObject color_Type = {
&Color_AsMapping, /* tp_as_mapping */
NULL, /* tp_hash */
NULL, /* tp_call */
#ifndef MATH_STANDALONE
(reprfunc) Color_str, /* tp_str */
#else
NULL, /* tp_str */
#endif
NULL, /* tp_getattro */
NULL, /* tp_setattro */
NULL, /* tp_as_buffer */

View File

@@ -35,7 +35,10 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#ifndef MATH_STANDALONE
# include "BLI_dynstr.h"
#endif
#define EULER_SIZE 3
@@ -323,6 +326,7 @@ static PyObject *Euler_repr(EulerObject *self)
return ret;
}
#ifndef MATH_STANDALONE
static PyObject *Euler_str(EulerObject *self)
{
DynStr *ds;
@@ -337,6 +341,7 @@ static PyObject *Euler_str(EulerObject *self)
return mathutils_dynstr_to_py(ds); /* frees ds */
}
#endif
static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op)
{
@@ -663,7 +668,11 @@ PyTypeObject euler_Type = {
&Euler_AsMapping, /* tp_as_mapping */
NULL, /* tp_hash */
NULL, /* tp_call */
#ifndef MATH_STANDALONE
(reprfunc) Euler_str, /* tp_str */
#else
NULL, /* tp_str */
#endif
NULL, /* tp_getattro */
NULL, /* tp_setattro */
NULL, /* tp_as_buffer */

View File

@@ -35,7 +35,10 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_string.h"
#include "BLI_dynstr.h"
#ifndef MATH_STANDALONE
# include "BLI_dynstr.h"
#endif
typedef enum eMatrixAccess_t {
MAT_ACCESS_ROW,
@@ -1647,6 +1650,7 @@ static PyObject *Matrix_repr(MatrixObject *self)
return NULL;
}
#ifndef MATH_STANDALONE
static PyObject *Matrix_str(MatrixObject *self)
{
DynStr *ds;
@@ -1682,6 +1686,7 @@ static PyObject *Matrix_str(MatrixObject *self)
return mathutils_dynstr_to_py(ds); /* frees ds */
}
#endif
static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
{
@@ -2418,7 +2423,11 @@ PyTypeObject matrix_Type = {
&Matrix_AsMapping, /*tp_as_mapping*/
NULL, /*tp_hash*/
NULL, /*tp_call*/
#ifndef MATH_STANDALONE
(reprfunc) Matrix_str, /*tp_str*/
#else
NULL, /*tp_str*/
#endif
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/

View File

@@ -35,7 +35,10 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#ifndef MATH_STANDALONE
# include "BLI_dynstr.h"
#endif
#define QUAT_SIZE 4
@@ -496,6 +499,7 @@ static PyObject *Quaternion_repr(QuaternionObject *self)
return ret;
}
#ifndef MATH_STANDALONE
static PyObject *Quaternion_str(QuaternionObject *self)
{
DynStr *ds;
@@ -510,6 +514,7 @@ static PyObject *Quaternion_str(QuaternionObject *self)
return mathutils_dynstr_to_py(ds); /* frees ds */
}
#endif
static PyObject *Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
{
@@ -1202,7 +1207,11 @@ PyTypeObject quaternion_Type = {
&Quaternion_AsMapping, /* tp_as_mapping */
NULL, /* tp_hash */
NULL, /* tp_call */
#ifndef MATH_STANDALONE
(reprfunc) Quaternion_str, /* tp_str */
#else
NULL, /* tp_str */
#endif
NULL, /* tp_getattro */
NULL, /* tp_setattro */
NULL, /* tp_as_buffer */

View File

@@ -35,7 +35,10 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#ifndef MATH_STANDALONE
# include "BLI_dynstr.h"
#endif
#define MAX_DIMENSIONS 4
@@ -1231,6 +1234,7 @@ static PyObject *Vector_repr(VectorObject *self)
return ret;
}
#ifndef MATH_STANDALONE
static PyObject *Vector_str(VectorObject *self)
{
int i;
@@ -1252,7 +1256,7 @@ static PyObject *Vector_str(VectorObject *self)
return mathutils_dynstr_to_py(ds); /* frees ds */
}
#endif
/* Sequence Protocol */
/* sequence length len(vector) */
@@ -2816,7 +2820,11 @@ PyTypeObject vector_Type = {
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
#ifndef MATH_STANDALONE
(reprfunc)Vector_str, /* reprfunc tp_str; */
#else
NULL, /* reprfunc tp_str; */
#endif
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */

View File

@@ -973,12 +973,14 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a
float n1n2[3], n2n3[3], n3n1[3];
float potentialVertex[3];
char *planes_used = MEM_callocN(sizeof(char) * len, __func__);
char *planes_used = PyMem_Malloc(sizeof(char) * len);
/* python */
PyObject *py_verts = PyList_New(0);
PyObject *py_plene_index = PyList_New(0);
memset(planes_used, 0, sizeof(char) * len);
for (i = 0; i < len; i++) {
const float *N1 = planes[i];
for (j = i + 1; j < len; j++) {
@@ -1031,7 +1033,7 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a
Py_DECREF(item);
}
}
MEM_freeN(planes_used);
PyMem_Free(planes_used);
{
PyObject *ret = PyTuple_New(2);