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
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/BPY_extern.h14
-rw-r--r--source/blender/python/generic/CMakeLists.txt5
-rw-r--r--source/blender/python/generic/bgl.c24
-rw-r--r--source/blender/python/generic/bgl.h2
-rw-r--r--source/blender/python/generic/bpy_internal_import.c10
-rw-r--r--source/blender/python/generic/mathutils_Color.c278
-rw-r--r--source/blender/python/generic/mathutils_Euler.c2
-rw-r--r--source/blender/python/generic/mathutils_Matrix.c2
-rw-r--r--source/blender/python/generic/mathutils_Vector.c29
-rw-r--r--source/blender/python/generic/mathutils_geometry.c4
-rw-r--r--source/blender/python/intern/CMakeLists.txt5
-rw-r--r--source/blender/python/intern/bpy.c12
-rw-r--r--source/blender/python/intern/bpy.h2
-rw-r--r--source/blender/python/intern/bpy_app.h2
-rw-r--r--source/blender/python/intern/bpy_driver.c2
-rw-r--r--source/blender/python/intern/bpy_library.c2
-rw-r--r--source/blender/python/intern/bpy_props.c103
-rw-r--r--source/blender/python/intern/bpy_props.h2
-rw-r--r--source/blender/python/intern/bpy_rna.c9
-rw-r--r--source/blender/python/intern/bpy_rna.h16
20 files changed, 417 insertions, 108 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index e8796a6f8dd..ae5253d07a0 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -67,14 +67,14 @@ int BPY_is_pyconstraint(struct Text *text);
// void BPY_free_pyconstraint_links(struct Text *text);
//
void BPY_python_start(int argc, const char **argv);
-void BPY_python_end( void );
-// void init_syspath( int first_time );
-// void syspath_append( char *dir );
-// void BPY_rebuild_syspath( void );
-// int BPY_path_update( void );
+void BPY_python_end(void);
+// void init_syspath(int first_time);
+// void syspath_append(char *dir);
+// void BPY_rebuild_syspath(void);
+// int BPY_path_update(void);
//
-// int BPY_Err_getLinenumber( void );
-// const char *BPY_Err_getFilename( void );
+// int BPY_Err_getLinenumber(void);
+// const char *BPY_Err_getFilename(void);
/* 2.5 UI Scripts */
int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports);
diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt
index 5e4eae4f809..0889c77f9ad 100644
--- a/source/blender/python/generic/CMakeLists.txt
+++ b/source/blender/python/generic/CMakeLists.txt
@@ -25,6 +25,9 @@ set(INC
../../blenkernel
../../blenloader
../../../../intern/guardedalloc
+)
+
+set(INC_SYS
${GLEW_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
)
@@ -60,4 +63,4 @@ set(SRC
)
-blender_add_lib(bf_python_ext "${SRC}" "${INC}")
+blender_add_lib(bf_python_ext "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 4eb6d78bd7b..b5a693c397c 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -62,16 +62,16 @@ square buffer. Passing [16, 16, 32] will create a 3 dimensional\n\
buffer which is twice as deep as it is wide or high."
);
-static PyObject *Method_Buffer( PyObject * self, PyObject *args );
+static PyObject *Method_Buffer(PyObject *self, PyObject *args);
/* Buffer sequence methods */
-static int Buffer_len( PyObject * self );
-static PyObject *Buffer_item( PyObject * self, int i );
-static PyObject *Buffer_slice( PyObject * self, int begin, int end );
-static int Buffer_ass_item( PyObject * self, int i, PyObject * v );
-static int Buffer_ass_slice( PyObject * self, int begin, int end,
- PyObject * seq );
+static int Buffer_len(PyObject *self);
+static PyObject *Buffer_item(PyObject *self, int i);
+static PyObject *Buffer_slice(PyObject *self, int begin, int end);
+static int Buffer_ass_item(PyObject *self, int i, PyObject *v);
+static int Buffer_ass_slice(PyObject *self, int begin, int end,
+ PyObject *seq);
static PySequenceMethods Buffer_SeqMethods = {
( lenfunc ) Buffer_len, /*sq_length */
@@ -86,11 +86,11 @@ static PySequenceMethods Buffer_SeqMethods = {
(ssizeargfunc) NULL, /* sq_inplace_repeat */
};
-static void Buffer_dealloc( PyObject * self );
-static PyObject *Buffer_tolist( PyObject * self );
-static PyObject *Buffer_dimensions( PyObject * self );
-static PyObject *Buffer_getattr( PyObject * self, char *name );
-static PyObject *Buffer_repr( PyObject * self );
+static void Buffer_dealloc(PyObject *self);
+static PyObject *Buffer_tolist(PyObject *self);
+static PyObject *Buffer_dimensions(PyObject *self);
+static PyObject *Buffer_getattr(PyObject *self, char *name);
+static PyObject *Buffer_repr(PyObject *self);
PyTypeObject BGL_bufferType = {
PyVarObject_HEAD_INIT(NULL, 0)
diff --git a/source/blender/python/generic/bgl.h b/source/blender/python/generic/bgl.h
index a870e82d4fd..81b570c8505 100644
--- a/source/blender/python/generic/bgl.h
+++ b/source/blender/python/generic/bgl.h
@@ -55,7 +55,7 @@ int BGL_typeSize( int type );
/*@ For Python access to OpenGL functions requiring a pointer. */
typedef struct _Buffer {
PyObject_VAR_HEAD
- PyObject * parent;
+ PyObject *parent;
int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */
int ndimensions;
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index 96fe13bf6fc..f0158fe72c3 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -34,9 +34,6 @@
#include <Python.h>
#include <stddef.h>
-#include "compile.h" /* for the PyCodeObject */
-#include "eval.h" /* for PyEval_EvalCode */
-
#include "bpy_internal_import.h"
#include "MEM_guardedalloc.h"
@@ -51,7 +48,6 @@
/* UNUSED */
#include "BKE_text.h" /* txt_to_buf */
#include "BKE_main.h"
-#include "BKE_global.h" /* grr, only for G.main->name */
static Main *bpy_import_main= NULL;
@@ -97,7 +93,7 @@ void bpy_import_main_set(struct Main *maggie)
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
{
- BLI_snprintf(fn, fn_len, "%s%c%s", text->id.lib ? text->id.lib->filepath : G.main->name, SEP, text->id.name+2);
+ BLI_snprintf(fn, fn_len, "%s%c%s", text->id.lib ? text->id.lib->filepath : bpy_import_main->name, SEP, text->id.name+2);
}
PyObject *bpy_text_import(Text *text)
@@ -221,7 +217,7 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
}
-static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject * kw)
+static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
PyObject *exception, *err, *tb;
char *name;
@@ -274,7 +270,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
* our reload() module, to handle reloading in-memory scripts
*/
-static PyObject *blender_reload(PyObject *UNUSED(self), PyObject * module)
+static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
{
PyObject *exception, *err, *tb;
PyObject *newmodule= NULL;
diff --git a/source/blender/python/generic/mathutils_Color.c b/source/blender/python/generic/mathutils_Color.c
index 09e3493cd09..c59cb501d86 100644
--- a/source/blender/python/generic/mathutils_Color.c
+++ b/source/blender/python/generic/mathutils_Color.c
@@ -186,7 +186,7 @@ static PyObject *Color_item(ColorObject * self, int i)
}
//----------------------------object[]-------------------------
//sequence accessor (set)
-static int Color_ass_item(ColorObject * self, int i, PyObject * value)
+static int Color_ass_item(ColorObject * self, int i, PyObject *value)
{
float f = PyFloat_AsDouble(value);
@@ -233,7 +233,7 @@ static PyObject *Color_slice(ColorObject * self, int begin, int end)
}
//----------------------------object[z:y]------------------------
//sequence slice (set)
-static int Color_ass_slice(ColorObject * self, int begin, int end, PyObject * seq)
+static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
{
int i, size;
float col[COLOR_SIZE];
@@ -344,13 +344,279 @@ static PyMappingMethods Color_AsMapping = {
(objobjargproc)Color_ass_subscript
};
+/* numeric */
+
+
+/* addition: obj + obj */
+static PyObject *Color_add(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+ float col[COLOR_SIZE];
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color addition: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ add_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
+
+ return newColorObject(col, Py_NEW, Py_TYPE(v1));
+}
+
+/* addition in-place: obj += obj */
+static PyObject *Color_iadd(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color addition: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ add_vn_vn(color1->col, color2->col, COLOR_SIZE);
+
+ (void)BaseMath_WriteCallback(color1);
+ Py_INCREF(v1);
+ return v1;
+}
+
+/* subtraction: obj - obj */
+static PyObject *Color_sub(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+ float col[COLOR_SIZE];
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color subtraction: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
+
+ return newColorObject(col, Py_NEW, Py_TYPE(v1));
+}
+
+/* subtraction in-place: obj -= obj */
+static PyObject *Color_isub(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1= NULL, *color2= NULL;
+
+ if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) {
+ PyErr_SetString(PyExc_AttributeError, "Color subtraction: arguments not valid for this operation");
+ return NULL;
+ }
+ color1 = (ColorObject*)v1;
+ color2 = (ColorObject*)v2;
+
+ if(BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+
+ sub_vn_vn(color1->col, color2->col, COLOR_SIZE);
+
+ (void)BaseMath_WriteCallback(color1);
+ Py_INCREF(v1);
+ return v1;
+}
+
+static PyObject *color_mul_float(ColorObject *color, const float scalar)
+{
+ float tcol[COLOR_SIZE];
+ mul_vn_vn_fl(tcol, color->col, COLOR_SIZE, scalar);
+ return newColorObject(tcol, Py_NEW, Py_TYPE(color));
+}
+
+
+static PyObject *Color_mul(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL, *color2 = NULL;
+ float scalar;
+
+ if ColorObject_Check(v1) {
+ color1= (ColorObject *)v1;
+ if(BaseMath_ReadCallback(color1) == -1)
+ return NULL;
+ }
+ if ColorObject_Check(v2) {
+ color2= (ColorObject *)v2;
+ if(BaseMath_ReadCallback(color2) == -1)
+ return NULL;
+ }
+
+
+ /* make sure v1 is always the vector */
+ if (color1 && color2) {
+ /* col * col, dont support yet! */
+ }
+ else if (color1) {
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR * FLOAT */
+ return color_mul_float(color1, scalar);
+ }
+ }
+ else if (color2) {
+ if (((scalar= PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred())==0) { /* FLOAT * COLOR */
+ return color_mul_float(color2, scalar);
+ }
+ }
+ else {
+ BLI_assert(!"internal error");
+ }
+
+ PyErr_Format(PyExc_TypeError, "Color multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name);
+ return NULL;
+}
+
+static PyObject *Color_div(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color1 = NULL;
+ float scalar;
+
+ if ColorObject_Check(v1) {
+ color1= (ColorObject *)v1;
+ if(BaseMath_ReadCallback(color1) == -1)
+ return NULL;
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Color division not supported in this order");
+ return NULL;
+ }
+
+ /* make sure v1 is always the vector */
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR * FLOAT */
+ if(scalar==0.0f) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "Color division: divide by zero error");
+ return NULL;
+ }
+ return color_mul_float(color1, 1.0f / scalar);
+ }
+
+ PyErr_Format(PyExc_TypeError, "Color multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name);
+ return NULL;
+}
+
+/* mulplication in-place: obj *= obj */
+static PyObject *Color_imul(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color = (ColorObject *)v1;
+ float scalar;
+
+ if(BaseMath_ReadCallback(color) == -1)
+ return NULL;
+
+ /* only support color *= float */
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR *= FLOAT */
+ mul_vn_fl(color->col, COLOR_SIZE, scalar);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Color multiplication: arguments not acceptable for this operation");
+ return NULL;
+ }
+
+ (void)BaseMath_WriteCallback(color);
+ Py_INCREF(v1);
+ return v1;
+}
+
+/* mulplication in-place: obj *= obj */
+static PyObject *Color_idiv(PyObject *v1, PyObject *v2)
+{
+ ColorObject *color = (ColorObject *)v1;
+ float scalar;
+
+ if(BaseMath_ReadCallback(color) == -1)
+ return NULL;
+
+ /* only support color /= float */
+ if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* COLOR /= FLOAT */
+ if(scalar==0.0f) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "Color division: divide by zero error");
+ return NULL;
+ }
+
+ mul_vn_fl(color->col, COLOR_SIZE, 1.0f / scalar);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Color multiplication: arguments not acceptable for this operation");
+ return NULL;
+ }
+
+ (void)BaseMath_WriteCallback(color);
+ Py_INCREF(v1);
+ return v1;
+}
+
+/* -obj
+ returns the negative of this object*/
+static PyObject *Color_neg(ColorObject *self)
+{
+ float tcol[COLOR_SIZE];
+
+ if(BaseMath_ReadCallback(self) == -1)
+ return NULL;
+
+ negate_vn_vn(tcol, self->col, COLOR_SIZE);
+ return newColorObject(tcol, Py_NEW, Py_TYPE(self));
+}
+
+
+static PyNumberMethods Color_NumMethods = {
+ (binaryfunc) Color_add, /*nb_add*/
+ (binaryfunc) Color_sub, /*nb_subtract*/
+ (binaryfunc) Color_mul, /*nb_multiply*/
+ NULL, /*nb_remainder*/
+ NULL, /*nb_divmod*/
+ NULL, /*nb_power*/
+ (unaryfunc) Color_neg, /*nb_negative*/
+ (unaryfunc) NULL, /*tp_positive*/
+ (unaryfunc) NULL, /*tp_absolute*/
+ (inquiry) NULL, /*tp_bool*/
+ (unaryfunc) NULL, /*nb_invert*/
+ NULL, /*nb_lshift*/
+ (binaryfunc)NULL, /*nb_rshift*/
+ NULL, /*nb_and*/
+ NULL, /*nb_xor*/
+ NULL, /*nb_or*/
+ NULL, /*nb_int*/
+ NULL, /*nb_reserved*/
+ NULL, /*nb_float*/
+ Color_iadd, /* nb_inplace_add */
+ Color_isub, /* nb_inplace_subtract */
+ Color_imul, /* nb_inplace_multiply */
+ NULL, /* nb_inplace_remainder */
+ NULL, /* nb_inplace_power */
+ NULL, /* nb_inplace_lshift */
+ NULL, /* nb_inplace_rshift */
+ NULL, /* nb_inplace_and */
+ NULL, /* nb_inplace_xor */
+ NULL, /* nb_inplace_or */
+ NULL, /* nb_floor_divide */
+ Color_div, /* nb_true_divide */
+ NULL, /* nb_inplace_floor_divide */
+ Color_idiv, /* nb_inplace_true_divide */
+ NULL, /* nb_index */
+};
+
/* color channel, vector.r/g/b */
static PyObject *Color_getChannel(ColorObject * self, void *type)
{
return Color_item(self, GET_INT_FROM_POINTER(type));
}
-static int Color_setChannel(ColorObject * self, PyObject * value, void * type)
+static int Color_setChannel(ColorObject * self, PyObject *value, void * type)
{
return Color_ass_item(self, GET_INT_FROM_POINTER(type), value);
}
@@ -369,7 +635,7 @@ static PyObject *Color_getChannelHSV(ColorObject * self, void *type)
return PyFloat_FromDouble(hsv[i]);
}
-static int Color_setChannelHSV(ColorObject * self, PyObject * value, void * type)
+static int Color_setChannelHSV(ColorObject * self, PyObject *value, void * type)
{
float hsv[3];
int i= GET_INT_FROM_POINTER(type);
@@ -412,7 +678,7 @@ static PyObject *Color_getHSV(ColorObject * self, void *UNUSED(closure))
return ret;
}
-static int Color_setHSV(ColorObject * self, PyObject * value, void *UNUSED(closure))
+static int Color_setHSV(ColorObject * self, PyObject *value, void *UNUSED(closure))
{
float hsv[3];
@@ -473,7 +739,7 @@ PyTypeObject color_Type = {
NULL, //tp_setattr
NULL, //tp_compare
(reprfunc) Color_repr, //tp_repr
- NULL, //tp_as_number
+ &Color_NumMethods, //tp_as_number
&Color_SeqMethods, //tp_as_sequence
&Color_AsMapping, //tp_as_mapping
NULL, //tp_hash
diff --git a/source/blender/python/generic/mathutils_Euler.c b/source/blender/python/generic/mathutils_Euler.c
index 9adf0ee905b..4281c7bf6c5 100644
--- a/source/blender/python/generic/mathutils_Euler.c
+++ b/source/blender/python/generic/mathutils_Euler.c
@@ -419,7 +419,7 @@ static PyObject *Euler_slice(EulerObject * self, int begin, int end)
}
//----------------------------object[z:y]------------------------
//sequence slice (set)
-static int Euler_ass_slice(EulerObject * self, int begin, int end, PyObject * seq)
+static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
{
int i, size;
float eul[EULER_SIZE];
diff --git a/source/blender/python/generic/mathutils_Matrix.c b/source/blender/python/generic/mathutils_Matrix.c
index 982a8e63282..4b7f9dc0d97 100644
--- a/source/blender/python/generic/mathutils_Matrix.c
+++ b/source/blender/python/generic/mathutils_Matrix.c
@@ -1485,7 +1485,7 @@ static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar)
return newMatrixObject(tmat, mat->row_size, mat->col_size, Py_NEW, Py_TYPE(mat));
}
-static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
+static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
{
float scalar;
diff --git a/source/blender/python/generic/mathutils_Vector.c b/source/blender/python/generic/mathutils_Vector.c
index fd8d1b5f481..d0ba94474d4 100644
--- a/source/blender/python/generic/mathutils_Vector.c
+++ b/source/blender/python/generic/mathutils_Vector.c
@@ -869,8 +869,7 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
return tuple;
}
/* sequence slice (set): vector[a:b] = value */
-static int Vector_ass_slice(VectorObject *self, int begin, int end,
- PyObject * seq)
+static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *seq)
{
int y, size = 0;
float vec[MAX_DIMENSIONS];
@@ -899,7 +898,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end,
/* Numeric Protocols */
/* addition: obj + obj */
-static PyObject *Vector_add(PyObject * v1, PyObject * v2)
+static PyObject *Vector_add(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float vec[MAX_DIMENSIONS];
@@ -926,7 +925,7 @@ static PyObject *Vector_add(PyObject * v1, PyObject * v2)
}
/* addition in-place: obj += obj */
-static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
+static PyObject *Vector_iadd(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
@@ -953,7 +952,7 @@ static PyObject *Vector_iadd(PyObject * v1, PyObject * v2)
}
/* subtraction: obj - obj */
-static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
+static PyObject *Vector_sub(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float vec[MAX_DIMENSIONS];
@@ -979,7 +978,7 @@ static PyObject *Vector_sub(PyObject * v1, PyObject * v2)
}
/* subtraction in-place: obj -= obj */
-static PyObject *Vector_isub(PyObject * v1, PyObject * v2)
+static PyObject *Vector_isub(PyObject *v1, PyObject *v2)
{
VectorObject *vec1= NULL, *vec2= NULL;
@@ -1055,7 +1054,7 @@ static PyObject *vector_mul_float(VectorObject *vec, const float scalar)
return newVectorObject(tvec, vec->size, Py_NEW, Py_TYPE(vec));
}
-static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
+static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
{
VectorObject *vec1 = NULL, *vec2 = NULL;
float scalar;
@@ -1116,12 +1115,12 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
mul_qt_v3(quat2->quat, tvec);
return newVectorObject(tvec, 3, Py_NEW, Py_TYPE(vec1));
}
- else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC*FLOAT */
+ else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC * FLOAT */
return vector_mul_float(vec1, scalar);
}
}
else if (vec2) {
- if (((scalar= PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred())==0) { /* VEC*FLOAT */
+ if (((scalar= PyFloat_AsDouble(v1)) == -1.0f && PyErr_Occurred())==0) { /* FLOAT * VEC */
return vector_mul_float(vec2, scalar);
}
}
@@ -1134,7 +1133,7 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
}
/* mulplication in-place: obj *= obj */
-static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
+static PyObject *Vector_imul(PyObject *v1, PyObject *v2)
{
VectorObject *vec = (VectorObject *)v1;
float scalar;
@@ -1168,7 +1167,7 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
}
mul_qt_v3(quat2->quat, vec->vec);
}
- else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC*=FLOAT */
+ else if (((scalar= PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred())==0) { /* VEC *= FLOAT */
mul_vn_fl(vec->vec, vec->size, scalar);
}
else {
@@ -1182,7 +1181,7 @@ static PyObject *Vector_imul(PyObject * v1, PyObject * v2)
}
/* divid: obj / obj */
-static PyObject *Vector_div(PyObject * v1, PyObject * v2)
+static PyObject *Vector_div(PyObject *v1, PyObject *v2)
{
int i;
float vec[4], scalar;
@@ -1214,7 +1213,7 @@ static PyObject *Vector_div(PyObject * v1, PyObject * v2)
}
/* divide in-place: obj /= obj */
-static PyObject *Vector_idiv(PyObject * v1, PyObject * v2)
+static PyObject *Vector_idiv(PyObject *v1, PyObject *v2)
{
int i;
float scalar;
@@ -1489,7 +1488,7 @@ static PyObject *Vector_getAxis(VectorObject *self, void *type)
return vector_item_internal(self, GET_INT_FROM_POINTER(type), TRUE);
}
-static int Vector_setAxis(VectorObject *self, PyObject * value, void *type)
+static int Vector_setAxis(VectorObject *self, PyObject *value, void *type)
{
return vector_ass_item_internal(self, GET_INT_FROM_POINTER(type), value, TRUE);
}
@@ -1596,7 +1595,7 @@ static PyObject *Vector_getSwizzle(VectorObject *self, void *closure)
Returns 0 on success and -1 on failure. On failure, the vector will be
unchanged. */
-static int Vector_setSwizzle(VectorObject *self, PyObject * value, void *closure)
+static int Vector_setSwizzle(VectorObject *self, PyObject *value, void *closure)
{
size_t size_from;
float scalarVal;
diff --git a/source/blender/python/generic/mathutils_geometry.c b/source/blender/python/generic/mathutils_geometry.c
index c4917199e59..53c066d1a85 100644
--- a/source/blender/python/generic/mathutils_geometry.c
+++ b/source/blender/python/generic/mathutils_geometry.c
@@ -169,7 +169,7 @@ PyDoc_STRVAR(M_Geometry_intersect_line_line_doc,
);
static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject *args)
{
- PyObject * tuple;
+ PyObject *tuple;
VectorObject *vec1, *vec2, *vec3, *vec4;
float v1[3], v2[3], v3[3], v4[3], i1[3], i2[3];
@@ -720,7 +720,7 @@ static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
return 0;
}
-static void boxPack_ToPyObject(PyObject * value, boxPack **boxarray)
+static void boxPack_ToPyObject(PyObject *value, boxPack **boxarray)
{
int len, i;
PyObject *list_item;
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt
index ab08dc14f07..454a706a16b 100644
--- a/source/blender/python/intern/CMakeLists.txt
+++ b/source/blender/python/intern/CMakeLists.txt
@@ -34,6 +34,9 @@ set(INC
../../editors/include
../../../../intern/guardedalloc
../../../../intern/audaspace/intern
+)
+
+set(INC_SYS
${PYTHON_INCLUDE_DIRS}
)
@@ -81,4 +84,4 @@ if(WITH_PYTHON_SAFETY)
add_definitions(-DWITH_PYTHON_SAFETY)
endif()
-blender_add_lib(bf_python "${SRC}" "${INC}")
+blender_add_lib(bf_python "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index 450151ee870..cb11b53c83c 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -231,7 +231,7 @@ static PyObject *bpy_import_test(const char *modname)
/*****************************************************************************
* Description: Creates the bpy module and adds it to sys.modules for importing
*****************************************************************************/
-void BPy_init_modules( void )
+void BPy_init_modules(void)
{
extern BPy_StructRNA *bpy_context_module;
extern int bpy_lib_init(PyObject *);
@@ -262,17 +262,17 @@ void BPy_init_modules( void )
/* run first, initializes rna types */
BPY_rna_init();
- PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
+ PyModule_AddObject(mod, "types", BPY_rna_types()); /* needs to be first so bpy_types can run */
PyModule_AddObject(mod, "StructMetaPropGroup", (PyObject *)&pyrna_struct_meta_idprop_Type); /* metaclass for idprop types, bpy_types.py needs access */
bpy_lib_init(mod); /* adds '_bpy._library_load', must be called before 'bpy_types' which uses it */
bpy_import_test("bpy_types");
- PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */
+ PyModule_AddObject(mod, "data", BPY_rna_module()); /* imports bpy_types by running this */
bpy_import_test("bpy_types");
- PyModule_AddObject( mod, "props", BPY_rna_props() );
- PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
- PyModule_AddObject( mod, "app", BPY_app_struct() );
+ PyModule_AddObject(mod, "props", BPY_rna_props());
+ PyModule_AddObject(mod, "ops", BPY_operator_module()); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
+ PyModule_AddObject(mod, "app", BPY_app_struct());
/* bpy context */
RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr);
diff --git a/source/blender/python/intern/bpy.h b/source/blender/python/intern/bpy.h
index 0f298c1daf1..0ebc6bb2438 100644
--- a/source/blender/python/intern/bpy.h
+++ b/source/blender/python/intern/bpy.h
@@ -26,5 +26,5 @@
*/
-void BPy_init_modules( void );
+void BPy_init_modules(void);
extern PyObject *bpy_package_py;
diff --git a/source/blender/python/intern/bpy_app.h b/source/blender/python/intern/bpy_app.h
index d57e4688f46..fbc5696875a 100644
--- a/source/blender/python/intern/bpy_app.h
+++ b/source/blender/python/intern/bpy_app.h
@@ -29,6 +29,6 @@
#ifndef BPY_APP_H
#define BPY_APP_H
-PyObject *BPY_app_struct( void );
+PyObject *BPY_app_struct(void);
#endif // BPY_APP_H
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c
index df31fab6bde..6f124d959cb 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -60,7 +60,7 @@ int bpy_pydriver_create_dict(void)
else
bpy_pydriver_Dict= d;
- /* import some modules: builtins, bpy, math, (Blender.noise )*/
+ /* import some modules: builtins, bpy, math, (Blender.noise)*/
PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins());
mod= PyImport_ImportModule("math");
diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c
index 10e97573447..85bffb5a8cc 100644
--- a/source/blender/python/intern/bpy_library.c
+++ b/source/blender/python/intern/bpy_library.c
@@ -213,7 +213,7 @@ static PyObject *_bpy_names(BPy_Library *self, int blocktype)
int counter= 0;
list= PyList_New(totnames);
for(l= names; l; l= l->next) {
- PyList_SET_ITEM(list, counter, PyUnicode_FromString((char * )l->link));
+ PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link));
counter++;
}
BLI_linklist_free(names, free); /* free linklist *and* each node's data */
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index 0ee9d7e5bd5..4fef084f093 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -642,16 +642,29 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
Py_RETURN_NONE;
}
+#if 0
+/* copies orig to buf, then sets orig to buf, returns copy length */
+static size_t strswapbufcpy(char *buf, const char **orig)
+{
+ const char *src= *orig;
+ char *dst= buf;
+ size_t i= 0;
+ *orig= buf;
+ while((*dst= *src)) { dst++; src++; i++; }
+ return i + 1; /* include '\0' */
+}
+#endif
+
static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const short is_enum_flag)
{
- EnumPropertyItem *items= NULL;
+ EnumPropertyItem *items;
PyObject *item;
- int seq_len, i, totitem= 0;
+ const Py_ssize_t seq_len= PySequence_Fast_GET_SIZE(seq_fast);
+ Py_ssize_t totbuf= 0;
+ int i;
short def_used= 0;
const char *def_cmp= NULL;
- seq_len= PySequence_Fast_GET_SIZE(seq_fast);
-
if(is_enum_flag) {
if(seq_len > RNA_ENUM_BITFLAG_SIZE) {
PyErr_SetString(PyExc_TypeError, "EnumProperty(...): maximum " STRINGIFY(RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property");
@@ -681,43 +694,52 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
/* blank value */
*defvalue= 0;
+ items= MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1");
+
for(i=0; i<seq_len; i++) {
EnumPropertyItem tmp= {0, "", 0, "", ""};
+ Py_ssize_t id_str_size;
+ Py_ssize_t name_str_size;
+ Py_ssize_t desc_str_size;
item= PySequence_Fast_GET_ITEM(seq_fast, i);
- if(PyTuple_Check(item)==0) {
- PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected a sequence of tuples for the enum items");
- if(items) MEM_freeN(items);
- return NULL;
- }
-
- if(!PyArg_ParseTuple(item, "sss", &tmp.identifier, &tmp.name, &tmp.description)) {
- PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an identifier, name and description in the tuple");
- return NULL;
- }
- if(is_enum_flag) {
- tmp.value= 1<<i;
+ if( (PyTuple_CheckExact(item)) &&
+ (PyTuple_GET_SIZE(item) == 3) &&
+ (tmp.identifier= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
+ (tmp.name= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
+ (tmp.description= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size))
+ ) {
+ if(is_enum_flag) {
+ tmp.value= 1<<i;
+
+ if(def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
+ *defvalue |= tmp.value;
+ def_used++;
+ }
+ }
+ else {
+ tmp.value= i;
- if(def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
- *defvalue |= tmp.value;
- def_used++;
+ if(def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) {
+ *defvalue= tmp.value;
+ def_used++; /* only ever 1 */
+ }
}
+
+ items[i]= tmp;
+
+ /* calculate combine string length */
+ totbuf += id_str_size + name_str_size + desc_str_size + 3; /* 3 is for '\0's */
}
else {
- tmp.value= i;
-
- if(def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) {
- *defvalue= tmp.value;
- def_used++; /* only ever 1 */
- }
+ MEM_freeN(items);
+ PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an tuple containing (identifier, name description)");
+ return NULL;
}
- RNA_enum_item_add(&items, &totitem, &tmp);
}
- RNA_enum_item_end(&items, &totitem);
-
if(is_enum_flag) {
/* strict check that all set members were used */
if(def && def_used != PySet_GET_SIZE(def)) {
@@ -740,6 +762,29 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
}
}
+ /* disabled duplicating strings because the array can still be freed and
+ * the strings from it referenced, for now we can't support dynamically
+ * created strings from python. */
+#if 0
+ /* this would all work perfectly _but_ the python strings may be freed
+ * immediately after use, so we need to duplicate them, ugh.
+ * annoying because it works most of the time without this. */
+ {
+ EnumPropertyItem *items_dup= MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf), "enum_items_from_py2");
+ EnumPropertyItem *items_ptr= items_dup;
+ char *buf= ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
+ memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1));
+ for(i=0; i<seq_len; i++, items_ptr++) {
+ buf += strswapbufcpy(buf, &items_ptr->identifier);
+ buf += strswapbufcpy(buf, &items_ptr->name);
+ buf += strswapbufcpy(buf, &items_ptr->description);
+ }
+ MEM_freeN(items);
+ items=items_dup;
+ }
+ /* end string duplication */
+#endif
+
return items;
}
@@ -1156,7 +1201,7 @@ static struct PyModuleDef props_module= {
NULL, NULL, NULL, NULL
};
-PyObject *BPY_rna_props( void )
+PyObject *BPY_rna_props(void)
{
PyObject *submodule;
PyObject *submodule_dict;
diff --git a/source/blender/python/intern/bpy_props.h b/source/blender/python/intern/bpy_props.h
index f306d6898d1..8b64d04e092 100644
--- a/source/blender/python/intern/bpy_props.h
+++ b/source/blender/python/intern/bpy_props.h
@@ -30,7 +30,7 @@
#ifndef BPY_PROPS_H
#define BPY_PROPS_H
-PyObject *BPY_rna_props( void );
+PyObject *BPY_rna_props(void);
#define PYRNA_STACK_ARRAY 32
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 8b361de17fa..4fe13bc6818 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1200,7 +1200,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
return ret;
}
-PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
+PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
{
PyObject *ret;
int type= RNA_property_type(prop);
@@ -1334,7 +1334,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha
return error_val;
}
-static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw);
+static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw);
static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
{
@@ -5882,7 +5882,6 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
PyObject *py_class= (PyObject*)py_data;
PyObject *base_class= RNA_struct_py_type_get(srna);
PyObject *item;
- PyObject *py_arg_count;
int i, flag, arg_count, func_arg_count;
const char *py_class_name= ((PyTypeObject *)py_class)->tp_name; // __name__
@@ -5945,9 +5944,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
func_arg_count= rna_function_arg_count(func);
if (func_arg_count >= 0) { /* -1 if we dont care*/
- py_arg_count= PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
- arg_count= PyLong_AsLong(py_arg_count);
- Py_DECREF(py_arg_count);
+ arg_count= ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount;
/* note, the number of args we check for and the number of args we give to
* @classmethods are different (quirk of python), this is why rna_function_arg_count() doesn't return the value -1*/
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index ea8af61c9bf..dbb5fc2feb7 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -148,18 +148,18 @@ typedef struct {
StructRNA *srna_from_self(PyObject *self, const char *error_prefix);
StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_prefix);
-void BPY_rna_init( void );
-PyObject *BPY_rna_module( void );
-void BPY_update_rna_module( void );
-/*PyObject *BPY_rna_doc( void );*/
-PyObject *BPY_rna_types( void );
+void BPY_rna_init(void);
+PyObject *BPY_rna_module(void);
+void BPY_update_rna_module(void);
+/*PyObject *BPY_rna_doc(void);*/
+PyObject *BPY_rna_types(void);
-PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
-PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
+PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr);
+PyObject *pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop);
/* operators also need this to set args */
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
-PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
+PyObject *pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);