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/mathutils/mathutils_Vector.c')
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 8fb3a3f74d6..79285b7778d 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -54,11 +54,18 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v
/* Supports 2D, 3D, and 4D vector objects both int and float values
* accepted. Mixed float and int values accepted. Ints are parsed to float
*/
-static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED(kwds))
+static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
float *vec = NULL;
int size = 3; /* default to a 3D vector */
+ if (kwds && PyDict_Size(kwds)) {
+ PyErr_SetString(PyExc_TypeError,
+ "Vector(): "
+ "takes no keyword args");
+ return NULL;
+ }
+
switch (PyTuple_GET_SIZE(args)) {
case 0:
vec = PyMem_Malloc(size * sizeof(float));
@@ -74,9 +81,6 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED
break;
case 1:
if ((size = mathutils_array_parse_alloc(&vec, 2, PyTuple_GET_ITEM(args, 0), "mathutils.Vector()")) == -1) {
- if (vec) {
- PyMem_Free(vec);
- }
return NULL;
}
break;
@@ -86,7 +90,7 @@ static PyObject *Vector_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED
"more then a single arg given");
return NULL;
}
- return Vector_CreatePyObject(vec, size, Py_NEW, type);
+ return Vector_CreatePyObject_alloc(vec, size, type);
}
static PyObject *vec__apply_to_copy(PyNoArgsFunction vec_func, VectorObject *self)
@@ -294,7 +298,6 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args)
if ((value_size = mathutils_array_parse_alloc(&iter_vec, 2, value,
"Vector.Repeat(vector, size), invalid 'vector' arg")) == -1)
{
- PyMem_Free(iter_vec);
return NULL;
}
@@ -308,6 +311,7 @@ static PyObject *C_Vector_Repeat(PyObject *cls, PyObject *args)
vec = PyMem_Malloc(size * sizeof(float));
if (vec == NULL) {
+ PyMem_Free(iter_vec);
PyErr_SetString(PyExc_MemoryError,
"Vector.Repeat(): "
"problem allocating pointer space");
@@ -891,19 +895,18 @@ PyDoc_STRVAR(Vector_dot_doc,
static PyObject *Vector_dot(VectorObject *self, PyObject *value)
{
float *tvec;
+ PyObject *ret;
if (BaseMath_ReadCallback(self) == -1)
return NULL;
if (mathutils_array_parse_alloc(&tvec, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1) {
- goto cleanup;
+ return NULL;
}
- return PyFloat_FromDouble(dot_vn_vn(self->vec, tvec, self->size));
-
-cleanup:
+ ret = PyFloat_FromDouble(dot_vn_vn(self->vec, tvec, self->size));
PyMem_Free(tvec);
- return NULL;
+ return ret;
}
PyDoc_STRVAR(Vector_angle_doc,
@@ -1133,12 +1136,12 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac))
return NULL;
- if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.lerp(other), invalid 'other' arg") == -1) {
- goto cleanup;
+ if (BaseMath_ReadCallback(self) == -1) {
+ return NULL;
}
- if (BaseMath_ReadCallback(self) == -1) {
- goto cleanup;
+ if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.lerp(other), invalid 'other' arg") == -1) {
+ return NULL;
}
vec = PyMem_Malloc(size * sizeof(float));
@@ -1158,10 +1161,6 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
PyMem_Free(tvec);
return Vector_CreatePyObject_alloc(vec, size, Py_TYPE(self));
-
-cleanup:
- PyMem_Free(tvec);
- return NULL;
}
PyDoc_STRVAR(Vector_rotate_doc,
@@ -1363,7 +1362,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
size = (end - begin);
if (mathutils_array_parse_alloc(&vec, size, seq, "vector[begin:end] = [...]") == -1) {
- goto cleanup;
+ return -1;
}
if (vec == NULL) {
@@ -1376,16 +1375,12 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
/*parsed well - now set in vector*/
memcpy(self->vec + begin, vec, size * sizeof(float));
+ PyMem_Free(vec);
+
if (BaseMath_WriteCallback(self) == -1)
return -1;
- PyMem_Free(vec);
-
return 0;
-
-cleanup:
- PyMem_Free(vec);
- return -1;
}
/* Numeric Protocols */