diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 1c98d6a5a59..1f35ebad9f7 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -285,8 +285,6 @@ void BPY_end_python( void ) next_script = script->id.next; free_libblock( &G.main->script, script ); } - - Mathutils_Free(NULL); Py_Finalize( ); diff --git a/source/blender/python/api2_2x/Mathutils.c b/source/blender/python/api2_2x/Mathutils.c index 83a58193a8b..8f99723e12d 100644 --- a/source/blender/python/api2_2x/Mathutils.c +++ b/source/blender/python/api2_2x/Mathutils.c @@ -107,11 +107,6 @@ struct PyMethodDef M_Mathutils_methods[] = { /*----------------------------MODULE INIT-------------------------*/ /* from can be Blender.Mathutils or GameLogic.Mathutils for the BGE */ -void Mathutils_Free(void * closure) -{ - Vector_Free(); -} - #if (PY_VERSION_HEX >= 0x03000000) static struct PyModuleDef M_Mathutils_module_def = { {}, /* m_base */ @@ -122,7 +117,7 @@ static struct PyModuleDef M_Mathutils_module_def = { 0, /* m_reload */ 0, /* m_traverse */ 0, /* m_clear */ - Mathutils_Free, /* m_free */ + 0, /* m_free */ }; #endif @@ -133,11 +128,6 @@ PyObject *Mathutils_Init(const char *from) //seed the generator for the rand function BLI_srand((unsigned int) (PIL_check_seconds_timer() * 0x7FFFFFFF)); - /* needed for getseters */ - if(!(vector_Type.tp_flags & Py_TPFLAGS_READY)) - if (Vector_Init() != 0) /* setup dynamic getset array */ - return NULL; - if( PyType_Ready( &vector_Type ) < 0 ) return NULL; if( PyType_Ready( &matrix_Type ) < 0 ) diff --git a/source/blender/python/api2_2x/Mathutils.h b/source/blender/python/api2_2x/Mathutils.h index ec6c3f548d9..b511f2046a6 100644 --- a/source/blender/python/api2_2x/Mathutils.h +++ b/source/blender/python/api2_2x/Mathutils.h @@ -38,7 +38,6 @@ #include "euler.h" PyObject *Mathutils_Init( const char * from ); -void Mathutils_Free(void *); PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat); PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec); diff --git a/source/blender/python/api2_2x/vector.c b/source/blender/python/api2_2x/vector.c index bef2917b0fa..f4504a13f72 100644 --- a/source/blender/python/api2_2x/vector.c +++ b/source/blender/python/api2_2x/vector.c @@ -39,17 +39,6 @@ #define SWIZZLE_VALID_AXIS 0x4 #define SWIZZLE_AXIS 0x3 - -/* An array of getseters, some of which have members on the stack and some on - the heap. - - Vector_dyn_getseters: The getseter structures. Terminated with a NULL sentinel. - Vector_dyn_names: All the names of the getseters that were allocated on the heap. - Each name is terminated with a null character, but there is - currently no way to find the length of this array. */ -PyGetSetDef* Vector_dyn_getseters = NULL; -char* Vector_dyn_names = NULL; - /*-------------------------DOC STRINGS ---------------------------*/ char Vector_Zero_doc[] = "() - set all values in the vector to 0"; char Vector_Normalize_doc[] = "() - normalize the vector"; @@ -1105,41 +1094,6 @@ static PyObject *Vector_getWrapped( VectorObject * self, void *type ) } -/*****************************************************************************/ -/* Python attributes get/set structure: */ -/*****************************************************************************/ -static PyGetSetDef Vector_getseters[] = { - {"x", - (getter)Vector_getAxis, (setter)Vector_setAxis, - "Vector X axis", - (void *)'X'}, - {"y", - (getter)Vector_getAxis, (setter)Vector_setAxis, - "Vector Y axis", - (void *)'Y'}, - {"z", - (getter)Vector_getAxis, (setter)Vector_setAxis, - "Vector Z axis", - (void *)'Z'}, - {"w", - (getter)Vector_getAxis, (setter)Vector_setAxis, - "Vector Z axis", - (void *)'W'}, - {"length", - (getter)Vector_getLength, (setter)Vector_setLength, - "Vector Length", - NULL}, - {"magnitude", - (getter)Vector_getLength, (setter)Vector_setLength, - "Vector Length", - NULL}, - {"wrapped", - (getter)Vector_getWrapped, (setter)NULL, - "True when this wraps blenders internal data", - NULL}, - {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ -}; - /* Get a new Vector according to the provided swizzle. This function has little error checking, as we are in control of the inputs: the closure is set by us in Vector_createSwizzleGetSeter. */ @@ -1264,163 +1218,422 @@ static int Vector_setSwizzle(VectorObject * self, PyObject * value, void *closur } } -/* Create a getseter that operates on the axes defined in swizzle. - Parameters: - gsd: An empty PyGetSetDef object. This will be modified. - swizzle: An array of axis indices. - dimensions: The number of axes to swizzle. Must be >= 2 and <= - MAX_DIMENSIONS. - name: A pointer to string that the name will be stored in. This is - purely to reduce the number of allocations. Before this function - returns, name will be advanced to the point immediately after - the name of the new getseter. Therefore, do not attempt to read - its contents. */ -static void Vector_createSwizzleGetSeter -( - PyGetSetDef *gsd, - unsigned short *swizzle, - size_t dimensions, - char **name -) -{ - const char axes[] = {'x', 'y', 'z', 'w'}; - unsigned int closure; - int i; +/*****************************************************************************/ +/* Python attributes get/set structure: */ +/*****************************************************************************/ +static PyGetSetDef Vector_getseters[] = { + {"x", + (getter)Vector_getAxis, (setter)Vector_setAxis, + "Vector X axis", + (void *)'X'}, + {"y", + (getter)Vector_getAxis, (setter)Vector_setAxis, + "Vector Y axis", + (void *)'Y'}, + {"z", + (getter)Vector_getAxis, (setter)Vector_setAxis, + "Vector Z axis", + (void *)'Z'}, + {"w", + (getter)Vector_getAxis, (setter)Vector_setAxis, + "Vector Z axis", + (void *)'W'}, + {"length", + (getter)Vector_getLength, (setter)Vector_setLength, + "Vector Length", + NULL}, + {"magnitude", + (getter)Vector_getLength, (setter)Vector_setLength, + "Vector Length", + NULL}, + {"wrapped", + (getter)Vector_getWrapped, (setter)NULL, + "True when this wraps blenders internal data", + NULL}, - /* Convert the index array into named axes. Store the name in the string - that was passed in, and make the getseter structure point to the same - address. */ - gsd->name = *name; - for (i = 0; i < dimensions; i++) - gsd->name[i] = axes[swizzle[i]]; - gsd->name[i] = '\0'; - /* Advance the name pointer to the next available address. */ - (*name) = (*name) + dimensions + 1; - - gsd->get = (getter)Vector_getSwizzle; - gsd->set = (setter)Vector_setSwizzle; - - gsd->doc = Vector_swizzle_doc; - - /* Pack the axes into a single value to use as the closure. Pack these in - in reverse so they come out in the right order when unpacked. */ - closure = 0; - for (i = MAX_DIMENSIONS - 1; i >= 0; i--) - { - closure = closure << SWIZZLE_BITS_PER_AXIS; - if (i < dimensions) - closure = closure | swizzle[i] | SWIZZLE_VALID_AXIS; - } - gsd->closure = (void*) closure; -} + /* autogenerated swizzle attrs, see python script below */ + {"xx", (getter)Vector_getSwizzle, (setter)Vector_setSwizzle, Vector_swizzle_doc, (void *)((unsigned int)((0|SWIZZLE_VALID_AXIS) | ((0|SWIZZLE_VALID_AXIS)<= 2: - /* Count the explicit getseters. */ - for (len_orig = 0; Vector_getseters[len_orig].name != NULL; len_orig++); + for axis_0 in axises: + axis_0_pos = axis_pos[axis_0] + for axis_1 in axises: + axis_1_pos = axis_pos[axis_1] + axis_dict[axis_0+axis_1] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<2: + for axis_2 in axises: + axis_2_pos = axis_pos[axis_2] + axis_dict[axis_0+axis_1+axis_2] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<3: + for axis_3 in axises: + axis_3_pos = axis_pos[axis_3] + axis_dict[axis_0+axis_1+axis_2+axis_3] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<