diff options
Diffstat (limited to 'source/blender/python/intern/bpy_driver.c')
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 161b56d39aa..df31fab6bde 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -21,6 +21,11 @@ * * ***** END GPL LICENSE BLOCK ***** */ + +/** \file blender/python/intern/bpy_driver.c + * \ingroup pythonintern + */ + /* ****************************************** */ /* Drivers - PyExpression Evaluation */ @@ -34,8 +39,10 @@ #include "BKE_fcurve.h" #include "BKE_global.h" +#include "bpy_driver.h" + /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ -PyObject *bpy_pydriver_Dict = NULL; +PyObject *bpy_pydriver_Dict= NULL; /* For faster execution we keep a special dictionary for pydrivers, with * the needed modules and aliases. @@ -47,16 +54,16 @@ int bpy_pydriver_create_dict(void) /* validate namespace for driver evaluation */ if (bpy_pydriver_Dict) return -1; - d = PyDict_New(); + d= PyDict_New(); if (d == NULL) return -1; else - bpy_pydriver_Dict = d; + bpy_pydriver_Dict= d; /* import some modules: builtins, bpy, math, (Blender.noise )*/ PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins()); - mod = PyImport_ImportModule("math"); + mod= PyImport_ImportModule("math"); if (mod) { PyDict_Merge(d, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */ Py_DECREF(mod); @@ -83,12 +90,12 @@ void BPY_driver_reset(void) int use_gil= 1; // (PyThreadState_Get()==NULL); if(use_gil) - gilstate = PyGILState_Ensure(); + gilstate= PyGILState_Ensure(); if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */ PyDict_Clear(bpy_pydriver_Dict); Py_DECREF(bpy_pydriver_Dict); - bpy_pydriver_Dict = NULL; + bpy_pydriver_Dict= NULL; } if(use_gil) @@ -125,13 +132,13 @@ float BPY_driver_exec(ChannelDriver *driver) int use_gil; DriverVar *dvar; - double result = 0.0; /* default return */ - char *expr = NULL; + double result= 0.0; /* default return */ + char *expr= NULL; short targets_ok= 1; int i; /* get the py expression to be evaluated */ - expr = driver->expression; + expr= driver->expression; if ((expr == NULL) || (expr[0]=='\0')) return 0.0f; @@ -143,7 +150,7 @@ float BPY_driver_exec(ChannelDriver *driver) use_gil= 1; //(PyThreadState_Get()==NULL); if(use_gil) - gilstate = PyGILState_Ensure(); + gilstate= PyGILState_Ensure(); /* init global dictionary for py-driver evaluation settings */ if (!bpy_pydriver_Dict) { @@ -193,10 +200,10 @@ float BPY_driver_exec(ChannelDriver *driver) } /* add target values to a dict that will be used as '__locals__' dict */ - driver_vars = PyDict_New(); // XXX do we need to decref this? + driver_vars= PyDict_New(); // XXX do we need to decref this? for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) { - PyObject *driver_arg = NULL; - float tval = 0.0f; + PyObject *driver_arg= NULL; + float tval= 0.0f; /* try to get variable value */ tval= driver_get_variable_value(driver, dvar); @@ -221,7 +228,7 @@ float BPY_driver_exec(ChannelDriver *driver) #if 0 // slow, with this can avoid all Py_CompileString above. /* execute expression to get a value */ - retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); + retval= PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars); #else /* evaluate the compiled expression */ if (expr_code) @@ -234,10 +241,11 @@ float BPY_driver_exec(ChannelDriver *driver) /* process the result */ if (retval == NULL) { pydriver_error(driver); - } else if((result= PyFloat_AsDouble(retval)) == -1.0 && PyErr_Occurred()) { + } + else if((result= PyFloat_AsDouble(retval)) == -1.0 && PyErr_Occurred()) { pydriver_error(driver); Py_DECREF(retval); - result = 0.0; + result= 0.0; } else { /* all fine, make sure the "invalid expression" flag is cleared */ @@ -247,7 +255,7 @@ float BPY_driver_exec(ChannelDriver *driver) if(use_gil) PyGILState_Release(gilstate); - + if(finite(result)) { return (float)result; } |