Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/intern/bpy_driver.c
| Context not available. | |||||
| #include <Python.h> | #include <Python.h> | ||||
| #include "CLG_log.h" | |||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| Context not available. | |||||
| # include <opcode.h> | # include <opcode.h> | ||||
| #endif | #endif | ||||
| static CLG_LogRef LOG = { "bpy.driver" }; | |||||
| /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ | /* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */ | ||||
| PyObject *bpy_pydriver_Dict = NULL; | PyObject *bpy_pydriver_Dict = NULL; | ||||
| Context not available. | |||||
| static void pydriver_error(ChannelDriver *driver) | static void pydriver_error(ChannelDriver *driver) | ||||
| { | { | ||||
| driver->flag |= DRIVER_FLAG_INVALID; /* py expression failed */ | driver->flag |= DRIVER_FLAG_INVALID; /* py expression failed */ | ||||
| fprintf(stderr, "\nError in Driver: The following Python expression failed:\n\t'%s'\n\n", driver->expression); | CLOG_ERROR(&LOG, "The following Python expression failed:\n\t'%s'", driver->expression); | ||||
| // BPy_errors_to_report(NULL); // TODO - reports | // BPy_errors_to_report(NULL); // TODO - reports | ||||
| PyErr_Print(); | PyErr_Print(); | ||||
| Context not available. | |||||
| } | } | ||||
| if (contains_name == false) { | if (contains_name == false) { | ||||
| fprintf(stderr, "\tBPY_driver_eval() - restructed access disallows name '%s', " | CLOG_ERROR(&LOG, "restructed access disallows name '%s', " | ||||
| "enable auto-execution to support\n", _PyUnicode_AsString(name)); | "enable auto-execution to support", _PyUnicode_AsString(name)); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| for (Py_ssize_t i = 0; i < code_len; i++) { | for (Py_ssize_t i = 0; i < code_len; i++) { | ||||
| const int opcode = _Py_OPCODE(codestr[i]); | const int opcode = _Py_OPCODE(codestr[i]); | ||||
| if (secure_opcodes[opcode] == 0) { | if (secure_opcodes[opcode] == 0) { | ||||
| fprintf(stderr, "\tBPY_driver_eval() - restructed access disallows opcode '%d', " | CLOG_ERROR(&LOG, "restructed access disallows opcode '%d', " | ||||
| "enable auto-execution to support\n", opcode); | "enable auto-execution to support", opcode); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| G.f |= G_SCRIPT_AUTOEXEC_FAIL; | G.f |= G_SCRIPT_AUTOEXEC_FAIL; | ||||
| BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Driver '%s'", expr); | BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Driver '%s'", expr); | ||||
| printf("skipping driver '%s', automatic scripts are disabled\n", expr); | CLOG_WARN(&LOG, "skipping driver '%s', automatic scripts are disabled", expr); | ||||
| } | } | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| Context not available. | |||||
| /* init global dictionary for py-driver evaluation settings */ | /* init global dictionary for py-driver evaluation settings */ | ||||
| if (!bpy_pydriver_Dict) { | if (!bpy_pydriver_Dict) { | ||||
| if (bpy_pydriver_create_dict() != 0) { | if (bpy_pydriver_create_dict() != 0) { | ||||
| fprintf(stderr, "PyDriver error: couldn't create Python dictionary\n"); | CLOG_ERROR(&LOG, "couldn't create Python dictionary"); | ||||
| if (use_gil) | if (use_gil) | ||||
| PyGILState_Release(gilstate); | PyGILState_Release(gilstate); | ||||
| return 0.0f; | return 0.0f; | ||||
| Context not available. | |||||
| /* this target failed - bad name */ | /* this target failed - bad name */ | ||||
| if (targets_ok) { | if (targets_ok) { | ||||
| /* first one - print some extra info for easier identification */ | /* first one - print some extra info for easier identification */ | ||||
| fprintf(stderr, "\nBPY_driver_eval() - Error while evaluating PyDriver:\n"); | CLOG_ERROR(&LOG, "Error while evaluating PyDriver:"); | ||||
| targets_ok = 0; | targets_ok = 0; | ||||
| } | } | ||||
| fprintf(stderr, "\tBPY_driver_eval() - couldn't add variable '%s' to namespace\n", dvar->name); | CLOG_ERROR(&LOG, "couldn't add variable '%s' to namespace", dvar->name); | ||||
| // BPy_errors_to_report(NULL); // TODO - reports | // BPy_errors_to_report(NULL); // TODO - reports | ||||
| // TODO: access pyerr data and send through CLOG? | |||||
| PyErr_Print(); | PyErr_Print(); | ||||
| PyErr_Clear(); | PyErr_Clear(); | ||||
| } | } | ||||
| Context not available. | |||||
| return (float)result; | return (float)result; | ||||
| } | } | ||||
| else { | else { | ||||
| fprintf(stderr, "\tBPY_driver_eval() - driver '%s' evaluates to '%f'\n", driver->expression, result); | CLOG_ERROR(&LOG, "driver '%s' evaluates to '%f'", driver->expression, result); | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||