Blender V4.5
bpy_driver.cc File Reference
#include <Python.h>
#include "DNA_anim_types.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BKE_animsys.h"
#include "BKE_fcurve_driver.h"
#include "BKE_global.hh"
#include "BKE_idtype.hh"
#include "RNA_access.hh"
#include "RNA_prototypes.hh"
#include "bpy_rna_driver.hh"
#include "bpy_intern_string.hh"
#include "bpy_driver.hh"
#include "bpy_rna.hh"
#include "BPY_extern.hh"
#include <opcode.h>

Go to the source code of this file.

Classes

struct  [struct].g_pydriver_state_prev

Macros

#define USE_RNA_AS_PYOBJECT
#define USE_BYTECODE_WHITELIST
#define OK_OP(op)

Functions

int bpy_pydriver_create_dict ()
static void bpy_pydriver_namespace_update_frame (const float evaltime)
static void bpy_pydriver_namespace_update_self (PathResolvedRNA *anim_rna)
static void bpy_pydriver_namespace_clear_self ()
static PyObject * bpy_pydriver_depsgraph_as_pyobject (Depsgraph *depsgraph)
static void bpy_pydriver_namespace_update_depsgraph (Depsgraph *depsgraph)
void BPY_driver_exit ()
void BPY_driver_reset ()
static void pydriver_error (ChannelDriver *driver, const PathResolvedRNA *anim_rna)
static bool is_opcode_secure (const int opcode)
bool BPY_driver_secure_bytecode_test_ex (PyObject *expr_code, PyObject *py_namespace_array[], const bool verbose, const char *error_prefix)
bool BPY_driver_secure_bytecode_test (PyObject *expr_code, PyObject *py_namespace, const bool verbose)
float BPY_driver_exec (PathResolvedRNA *anim_rna, ChannelDriver *driver, ChannelDriver *driver_orig, const AnimationEvalContext *anim_eval_context)

Variables

PyObject * bpy_pydriver_Dict = nullptr
static PyObject * bpy_pydriver_Dict__whitelist = nullptr
static struct  g_pydriver_state_prev

Detailed Description

This file defines the BPY_driver_exec to execute python driver expressions, called by the animation system, there are also some utility functions to deal with the name-space used for driver execution.

Definition in file bpy_driver.cc.

Macro Definition Documentation

◆ OK_OP

#define OK_OP ( op)
Value:
case op: \
return true;

Referenced by is_opcode_secure().

◆ USE_BYTECODE_WHITELIST

#define USE_BYTECODE_WHITELIST

Definition at line 39 of file bpy_driver.cc.

◆ USE_RNA_AS_PYOBJECT

#define USE_RNA_AS_PYOBJECT

Definition at line 37 of file bpy_driver.cc.

Function Documentation

◆ BPY_driver_exec()

◆ BPY_driver_exit()

void BPY_driver_exit ( )

Run on exit to free any cached data.

Definition at line 241 of file bpy_driver.cc.

References BPY_driver_exit(), bpy_pydriver_Dict, bpy_pydriver_Dict__whitelist, FLT_MAX, and g_pydriver_state_prev.

Referenced by BPY_driver_exit(), BPY_driver_reset(), and BPY_python_end().

◆ BPY_driver_reset()

void BPY_driver_reset ( )

Update function, it gets rid of python-drivers global dictionary: bpy.app.driver_namespace, forcing BPY_driver_exec to recreate it. Use this when loading a new .blend file so any variables setup by the previous blend file are cleared.

Definition at line 264 of file bpy_driver.cc.

References BPY_driver_exit(), and BPY_driver_reset().

Referenced by BPY_driver_reset(), and BPY_python_reset().

◆ BPY_driver_secure_bytecode_test()

bool BPY_driver_secure_bytecode_test ( PyObject * expr_code,
PyObject * py_namespace,
const bool verbose )

◆ BPY_driver_secure_bytecode_test_ex()

bool BPY_driver_secure_bytecode_test_ex ( PyObject * expr_code,
PyObject * py_namespace_array[],
const bool verbose,
const char * error_prefix )

◆ bpy_pydriver_create_dict()

int bpy_pydriver_create_dict ( )

For faster execution we keep a special dictionary for py-drivers, with the needed modules and aliases.

Definition at line 58 of file bpy_driver.cc.

References arg_str, bpy_pydriver_create_dict(), bpy_pydriver_Dict, bpy_pydriver_Dict__whitelist, i, and mod.

Referenced by bpy_app_driver_dict_get(), BPY_driver_exec(), BPY_driver_secure_bytecode_test(), and bpy_pydriver_create_dict().

◆ bpy_pydriver_depsgraph_as_pyobject()

PyObject * bpy_pydriver_depsgraph_as_pyobject ( Depsgraph * depsgraph)
static

◆ bpy_pydriver_namespace_clear_self()

void bpy_pydriver_namespace_clear_self ( )
static

◆ bpy_pydriver_namespace_update_depsgraph()

void bpy_pydriver_namespace_update_depsgraph ( Depsgraph * depsgraph)
static

Adds a variable Dependency Graph to the name-space. This can then be used to obtain evaluated data-blocks, and the current view layer and scene. See #75553.

Definition at line 219 of file bpy_driver.cc.

References BLI_assert, bpy_intern_str_depsgraph, bpy_pydriver_depsgraph_as_pyobject(), bpy_pydriver_Dict, bpy_pydriver_namespace_update_depsgraph(), g_pydriver_state_prev, and UNLIKELY.

Referenced by BPY_driver_exec(), and bpy_pydriver_namespace_update_depsgraph().

◆ bpy_pydriver_namespace_update_frame()

void bpy_pydriver_namespace_update_frame ( const float evaltime)
static

◆ bpy_pydriver_namespace_update_self()

◆ is_opcode_secure()

bool is_opcode_secure ( const int opcode)
static

Definition at line 309 of file bpy_driver.cc.

References CALL, is_opcode_secure(), OK_OP, and SWAP.

Referenced by BPY_driver_secure_bytecode_test_ex(), and is_opcode_secure().

◆ pydriver_error()

void pydriver_error ( ChannelDriver * driver,
const PathResolvedRNA * anim_rna )
static

Error return function for BPY_driver_exec.

Parameters
anim_rnaUsed to show the target when printing the error to give additional context.

Definition at line 285 of file bpy_driver.cc.

References BKE_idtype_idcode_to_name(), DRIVER_FLAG_INVALID, ChannelDriver::expression, ChannelDriver::flag, GS, ID::name, PointerRNA::owner_id, PathResolvedRNA::prop, PathResolvedRNA::prop_index, PathResolvedRNA::ptr, pydriver_error(), and RNA_property_identifier().

Referenced by BPY_driver_exec(), and pydriver_error().

Variable Documentation

◆ bpy_pydriver_Dict

PyObject* bpy_pydriver_Dict = nullptr

◆ bpy_pydriver_Dict__whitelist

PyObject* bpy_pydriver_Dict__whitelist = nullptr
static

◆ g_pydriver_state_prev