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:
authorCampbell Barton <ideasman42@gmail.com>2013-05-03 05:13:51 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-05-03 05:13:51 +0400
commit854fd940165736db01eeff05719f1a60a6a89a8b (patch)
treef3269fc7c96cf8f8b685ec9fde379504609a6988 /source/gameengine/Expressions/Value.cpp
parentd92bd6bb0421ff98b209aba3aac34edfd1a08ab3 (diff)
bge py api: raise an overflow exception when assigning a float to a bge object which is out of the float range.
also avoid raising exceptions by ConvertPythonToValue when they will be ignored.
Diffstat (limited to 'source/gameengine/Expressions/Value.cpp')
-rw-r--r--source/gameengine/Expressions/Value.cpp31
1 files changed, 24 insertions, 7 deletions
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index 383e83dcd89..e5c4001de4c 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -537,10 +537,17 @@ PyObject *CValue::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrde
return PyUnicode_From_STR_String(self->GetName());
}
-CValue* CValue::ConvertPythonToValue(PyObject *pyobj, const char *error_prefix)
+/**
+ * There are 2 reasons this could return NULL
+ * - unsupported type.
+ * - error converting (overflow).
+ *
+ * \param do_type_exception Use to skip raising an exception for unknown types.
+ */
+CValue *CValue::ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix)
{
- CValue* vallie = NULL;
+ CValue *vallie;
/* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */
#if 0
if (PyList_Check(pyobj))
@@ -581,7 +588,14 @@ CValue* CValue::ConvertPythonToValue(PyObject *pyobj, const char *error_prefix)
} else
if (PyFloat_Check(pyobj))
{
- vallie = new CFloatValue( (float)PyFloat_AsDouble(pyobj) );
+ const double tval = PyFloat_AsDouble(pyobj);
+ if (tval > (double)FLT_MAX || tval < (double)-FLT_MAX) {
+ PyErr_Format(PyExc_OverflowError, "%soverflow converting from float, out of internal range", error_prefix);
+ vallie = NULL;
+ }
+ else {
+ vallie = new CFloatValue((float)tval);
+ }
} else
if (PyLong_Check(pyobj))
{
@@ -594,10 +608,13 @@ CValue* CValue::ConvertPythonToValue(PyObject *pyobj, const char *error_prefix)
if (PyObject_TypeCheck(pyobj, &CValue::Type)) /* Note, don't let these get assigned to GameObject props, must check elsewhere */
{
vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
- } else
- {
- /* return an error value from the caller */
- PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix);
+ }
+ else {
+ if (do_type_exception) {
+ /* return an error value from the caller */
+ PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix);
+ }
+ vallie = NULL;
}
return vallie;