formatting edits only to use more consisted style

This commit is contained in:
2011-12-26 12:26:11 +00:00
parent f48fb385ea
commit e17fd46c71
18 changed files with 1841 additions and 1824 deletions

View File

@@ -47,7 +47,7 @@ extern void BPY_update_rna_module(void);
/* 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.
@@ -59,32 +59,32 @@ 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);
}
/* add bpy to global namespace */
mod= PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0);
mod = PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0);
if (mod) {
PyDict_SetItemString(bpy_pydriver_Dict, "bpy", mod);
Py_DECREF(mod);
}
/* add noise to global namespace */
mod= PyImport_ImportModuleLevel((char *)"mathutils", NULL, NULL, NULL, 0);
mod = PyImport_ImportModuleLevel((char *)"mathutils", NULL, NULL, NULL, 0);
if (mod) {
PyObject *modsub= PyDict_GetItemString(PyModule_GetDict(mod), "noise");
PyObject *modsub = PyDict_GetItemString(PyModule_GetDict(mod), "noise");
PyDict_SetItemString(bpy_pydriver_Dict, "noise", modsub);
Py_DECREF(mod);
}
@@ -93,9 +93,9 @@ int bpy_pydriver_create_dict(void)
}
/* note, this function should do nothing most runs, only when changing frame */
static PyObject *bpy_pydriver_InternStr__frame= NULL;
static PyObject *bpy_pydriver_InternStr__frame = NULL;
/* not thread safe but neither is python */
static float bpy_pydriver_evaltime_prev= FLT_MAX;
static float bpy_pydriver_evaltime_prev = FLT_MAX;
static void bpy_pydriver_update_dict(const float evaltime)
{
@@ -103,14 +103,14 @@ static void bpy_pydriver_update_dict(const float evaltime)
/* currently only update the frame */
if (bpy_pydriver_InternStr__frame == NULL) {
bpy_pydriver_InternStr__frame= PyUnicode_FromString("frame");
bpy_pydriver_InternStr__frame = PyUnicode_FromString("frame");
}
PyDict_SetItem(bpy_pydriver_Dict,
bpy_pydriver_InternStr__frame,
PyFloat_FromDouble(evaltime));
bpy_pydriver_evaltime_prev= evaltime;
bpy_pydriver_evaltime_prev = evaltime;
}
}
@@ -122,21 +122,21 @@ static void bpy_pydriver_update_dict(const float evaltime)
void BPY_driver_reset(void)
{
PyGILState_STATE gilstate;
int use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */
int use_gil = 1; /* !PYC_INTERPRETER_ACTIVE; */
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 (bpy_pydriver_InternStr__frame) {
Py_DECREF(bpy_pydriver_InternStr__frame);
bpy_pydriver_InternStr__frame= NULL;
bpy_pydriver_evaltime_prev= FLT_MAX;
bpy_pydriver_InternStr__frame = NULL;
bpy_pydriver_evaltime_prev = FLT_MAX;
}
if (use_gil)
@@ -170,22 +170,22 @@ static void pydriver_error(ChannelDriver *driver)
*/
float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
{
PyObject *driver_vars=NULL;
PyObject *retval= NULL;
PyObject *driver_vars = NULL;
PyObject *retval = NULL;
PyObject *expr_vars; /* speed up by pre-hashing string & avoids re-converting unicode strings for every execution */
PyObject *expr_code;
PyGILState_STATE gilstate;
int use_gil;
DriverVar *dvar;
double result= 0.0; /* default return */
char *expr= NULL;
short targets_ok= 1;
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;
if ((expr == NULL) || (expr[0]=='\0'))
expr = driver->expression;
if ((expr == NULL) || (expr[0] == '\0'))
return 0.0f;
if (!(G.f & G_SCRIPT_AUTOEXEC)) {
@@ -193,10 +193,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
return 0.0f;
}
use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */
use_gil = 1; /* !PYC_INTERPRETER_ACTIVE; */
if (use_gil)
gilstate= PyGILState_Ensure();
gilstate = PyGILState_Ensure();
/* needed since drivers are updated directly after undo where 'main' is
* re-allocated [#28807] */
@@ -216,51 +216,51 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
bpy_pydriver_update_dict(evaltime);
if (driver->expr_comp==NULL)
if (driver->expr_comp == NULL)
driver->flag |= DRIVER_FLAG_RECOMPILE;
/* compile the expression first if it hasn't been compiled or needs to be rebuilt */
if (driver->flag & DRIVER_FLAG_RECOMPILE) {
Py_XDECREF(driver->expr_comp);
driver->expr_comp= PyTuple_New(2);
driver->expr_comp = PyTuple_New(2);
expr_code= Py_CompileString(expr, "<bpy driver>", Py_eval_input);
expr_code = Py_CompileString(expr, "<bpy driver>", Py_eval_input);
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 0, expr_code);
driver->flag &= ~DRIVER_FLAG_RECOMPILE;
driver->flag |= DRIVER_FLAG_RENAMEVAR; /* maybe this can be removed but for now best keep until were sure */
}
else {
expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0);
expr_code = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0);
}
if (driver->flag & DRIVER_FLAG_RENAMEVAR) {
/* may not be set */
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
expr_vars = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
Py_XDECREF(expr_vars);
expr_vars= PyTuple_New(BLI_countlist(&driver->variables));
expr_vars = PyTuple_New(BLI_countlist(&driver->variables));
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 1, expr_vars);
for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) {
for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) {
PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_FromString(dvar->name));
}
driver->flag &= ~DRIVER_FLAG_RENAMEVAR;
}
else {
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
expr_vars = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
}
/* add target values to a dict that will be used as '__locals__' dict */
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;
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;
/* try to get variable value */
tval= driver_get_variable_value(driver, dvar);
driver_arg= PyFloat_FromDouble((double)tval);
tval = driver_get_variable_value(driver, dvar);
driver_arg = PyFloat_FromDouble((double)tval);
/* try to add to dictionary */
/* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */
@@ -269,7 +269,7 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
if (targets_ok) {
/* first one - print some extra info for easier identification */
fprintf(stderr, "\nBPY_driver_eval() - Error while evaluating PyDriver:\n");
targets_ok= 0;
targets_ok = 0;
}
fprintf(stderr, "\tBPY_driver_eval() - couldn't add variable '%s' to namespace\n", dvar->name);
@@ -282,11 +282,11 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
#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)
retval= PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars);
retval = PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars);
#endif
/* decref the driver vars first... */
@@ -296,10 +296,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
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 */