[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60808] trunk/blender/source/blender/ python/generic/idprop_py_api.c: fix [#37105] Long int IDproperties produces errors at weird spots.

Campbell Barton ideasman42 at gmail.com
Thu Oct 17 04:36:33 CEST 2013


Revision: 60808
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60808
Author:   campbellbarton
Date:     2013-10-17 02:36:33 +0000 (Thu, 17 Oct 2013)
Log Message:
-----------
fix [#37105] Long int IDproperties produces errors at weird spots.

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/idprop_py_api.c

Modified: trunk/blender/source/blender/python/generic/idprop_py_api.c
===================================================================
--- trunk/blender/source/blender/python/generic/idprop_py_api.c	2013-10-16 23:42:44 UTC (rev 60807)
+++ trunk/blender/source/blender/python/generic/idprop_py_api.c	2013-10-17 02:36:33 UTC (rev 60808)
@@ -351,7 +351,10 @@
 		prop = IDP_New(IDP_DOUBLE, &val, name);
 	}
 	else if (PyLong_Check(ob)) {
-		val.i = (int)PyLong_AsLong(ob);
+		val.i = _PyLong_AsInt(ob);
+		if (val.i == -1 && PyErr_Occurred()) {
+			return "error converting to an int";
+		}
 		prop = IDP_New(IDP_INT, &val, name);
 	}
 	else if (PyUnicode_Check(ob)) {
@@ -409,7 +412,7 @@
 				prop = IDP_New(IDP_ARRAY, &val, name);
 				for (i = 0; i < val.array.len; i++) {
 					item = PySequence_Fast_GET_ITEM(ob_seq_fast, i);
-					((int *)IDP_Array(prop))[i] = (int)PyLong_AsLong(item);
+					((int *)IDP_Array(prop))[i] = _PyLong_AsInt(item);
 				}
 				break;
 			case IDP_IDPARRAY:
@@ -1052,10 +1055,6 @@
 
 static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *value)
 {
-	int i;
-	float f;
-	double d;
-
 	if (index < 0 || index >= self->prop->len) {
 		PyErr_SetString(PyExc_RuntimeError, "index out of range!");
 		return -1;
@@ -1063,30 +1062,33 @@
 
 	switch (self->prop->subtype) {
 		case IDP_FLOAT:
-			f = (float)PyFloat_AsDouble(value);
+		{
+			const float f = (float)PyFloat_AsDouble(value);
 			if (f == -1 && PyErr_Occurred()) {
-				PyErr_SetString(PyExc_TypeError, "expected a float");
 				return -1;
 			}
 			((float *)IDP_Array(self->prop))[index] = f;
 			break;
+		}
 		case IDP_DOUBLE:
-			d = PyFloat_AsDouble(value);
+		{
+			const double d = PyFloat_AsDouble(value);
 			if (d == -1 && PyErr_Occurred()) {
-				PyErr_SetString(PyExc_TypeError, "expected a float");
 				return -1;
 			}
 			((double *)IDP_Array(self->prop))[index] = d;
 			break;
+		}
 		case IDP_INT:
-			i = PyLong_AsLong(value);
+		{
+			const int i = _PyLong_AsInt(value);
 			if (i == -1 && PyErr_Occurred()) {
-				PyErr_SetString(PyExc_TypeError, "expected an int type");
 				return -1;
 			}
 
 			((int *)IDP_Array(self->prop))[index] = i;
 			break;
+		}
 	}
 	return 0;
 }




More information about the Bf-blender-cvs mailing list