Blender  V3.3
Functions | Variables
bpy_interface.c File Reference
#include <Python.h>
#include <frameobject.h>
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "RNA_types.h"
#include "bpy.h"
#include "bpy_capi_utils.h"
#include "bpy_intern_string.h"
#include "bpy_path.h"
#include "bpy_props.h"
#include "bpy_rna.h"
#include "bpy_traceback.h"
#include "bpy_app_translations.h"
#include "DNA_text_types.h"
#include "BKE_appdir.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_text.h"
#include "BPY_extern.h"
#include "BPY_extern_python.h"
#include "BPY_extern_run.h"
#include "../generic/py_capi_utils.h"
#include "../bmesh/bmesh_py_api.h"
#include "../generic/bgl.h"
#include "../generic/bl_math_py_api.h"
#include "../generic/blf_py_api.h"
#include "../generic/idprop_py_api.h"
#include "../generic/imbuf_py_api.h"
#include "../gpu/gpu_py_api.h"
#include "../mathutils/mathutils.h"

Go to the source code of this file.

Functions

 CLG_LOGREF_DECLARE_GLOBAL (BPY_LOG_CONTEXT, "bpy.context")
 
 CLG_LOGREF_DECLARE_GLOBAL (BPY_LOG_INTERFACE, "bpy.interface")
 
 CLG_LOGREF_DECLARE_GLOBAL (BPY_LOG_RNA, "bpy.rna")
 
void BPY_context_update (bContext *C)
 
void bpy_context_set (bContext *C, PyGILState_STATE *gilstate)
 
void bpy_context_clear (bContext *UNUSED(C), const PyGILState_STATE *gilstate)
 
static void bpy_context_end (bContext *C)
 
void BPY_context_dict_clear_members_array (void **dict_p, void *dict_orig, const char *context_members[], uint context_members_len)
 
void BPY_text_free_code (Text *text)
 
void BPY_modules_update (void)
 
bContextBPY_context_get (void)
 
void BPY_context_set (bContext *C)
 
static void pystatus_exit_on_error (PyStatus status)
 
void BPY_python_start (bContext *C, int argc, const char **argv)
 
void BPY_python_end (void)
 
void BPY_python_reset (bContext *C)
 
void BPY_python_use_system_env (void)
 
void BPY_python_backtrace (FILE *fp)
 
void BPY_DECREF (void *pyob_ptr)
 
void BPY_DECREF_RNA_INVALIDATE (void *pyob_ptr)
 
void BPY_modules_load_user (bContext *C)
 
int BPY_context_member_get (bContext *C, const char *member, bContextDataResult *result)
 
bool BPY_string_is_keyword (const char *str)
 
int text_check_identifier_unicode (const uint ch)
 
int text_check_identifier_nodigit_unicode (const uint ch)
 

Variables

static int py_call_level = 0
 
static bool py_use_system_env = false
 
static struct _inittab bpy_internal_modules []
 

Detailed Description

This file deals with embedding the python interpreter within blender, starting and stopping python and exposing blender/python modules so they can be accesses from scripts.

Definition in file bpy_interface.c.

Function Documentation

◆ bpy_context_clear()

void bpy_context_clear ( bContext UNUSEDC,
const PyGILState_STATE *  gilstate 
)

Definition at line 128 of file bpy_interface.c.

References BPY_context_set(), NULL, PIL_check_seconds_timer(), and py_call_level.

Referenced by BPY_modules_load_user().

◆ BPY_context_dict_clear_members_array()

void BPY_context_dict_clear_members_array ( void **  dict_p,
void dict_orig,
const char *  context_members[],
uint  context_members_len 
)

Use for CTX_*_set(..) functions need to set values which are later read back as expected. In this case we don't want the Python context to override the values as it causes problems see T66256.

Parameters
dict_pA pointer to #bContext.data.py_context so we can assign a new value.
dict_origThe value of #bContext.data.py_context_orig to check if we need to copy.
Note
Typically accessed via BPY_context_dict_clear_members macro.

Definition at line 161 of file bpy_interface.c.

References BLI_assert, and PyC_IsInterpreterActive().

◆ bpy_context_end()

static void bpy_context_end ( bContext C)
static

Definition at line 153 of file bpy_interface.c.

References C, CTX_wm_operator_poll_msg_clear(), NULL, and UNLIKELY.

Referenced by BPY_python_end().

◆ BPY_context_get()

bContext* BPY_context_get ( void  )

◆ BPY_context_member_get()

int BPY_context_member_get ( bContext C,
const char *  member,
bContextDataResult result 
)

◆ BPY_context_set()

void BPY_context_set ( bContext C)

Definition at line 231 of file bpy_interface.c.

References bpy_context_module, C, PointerRNA::data, and BPy_StructRNA::ptr.

Referenced by bpy_context_clear(), and BPY_context_update().

◆ bpy_context_set()

void bpy_context_set ( bContext C,
PyGILState_STATE *  gilstate 
)

◆ BPY_context_update()

void BPY_context_update ( struct bContext C)

Use for updating while a python script runs - in case of file load.

Definition at line 91 of file bpy_interface.c.

References BLI_thread_is_main(), BPY_context_set(), BPY_modules_update(), and C.

Referenced by bpy_context_set(), BPY_modules_load_user(), and setup_app_data().

◆ BPY_DECREF()

void BPY_DECREF ( void pyob_ptr)

Acquire the global-interpreter-lock (GIL) and wrap Py_DECREF. as there are some cases when this needs to be called outside the Python API code.

Definition at line 606 of file bpy_interface.c.

Referenced by fcurve_free_driver(), and pyop_poll_message_free_fn().

◆ BPY_DECREF_RNA_INVALIDATE()

void BPY_DECREF_RNA_INVALIDATE ( void pyob_ptr)

◆ BPY_modules_load_user()

void BPY_modules_load_user ( bContext C)

◆ BPY_modules_update()

void BPY_modules_update ( void  )

Needed so the Main pointer in bpy.data doesn't become out of date.

Definition at line 214 of file bpy_interface.c.

References BPY_rna_module(), BPY_rna_types(), BPY_update_rna_module(), mod(), and NULL.

Referenced by BPY_context_update(), and pyop_call().

◆ BPY_python_backtrace()

void BPY_python_backtrace ( FILE *  fp)

Definition at line 585 of file bpy_interface.c.

Referenced by sig_handle_crash().

◆ BPY_python_end()

void BPY_python_end ( void  )

◆ BPY_python_reset()

void BPY_python_reset ( bContext C)

◆ BPY_python_start()

void BPY_python_start ( struct bContext C,
int  argc,
const char **  argv 
)

◆ BPY_python_use_system_env()

void BPY_python_use_system_env ( void  )

Definition at line 579 of file bpy_interface.c.

References BLI_assert, and py_use_system_env.

Referenced by arg_handle_python_use_system_env_set().

◆ BPY_string_is_keyword()

bool BPY_string_is_keyword ( const char *  str)

Avoids duplicating keyword list.

Definition at line 870 of file bpy_interface.c.

References NULL, str, and STREQ.

Referenced by driver_variable_name_validate().

◆ BPY_text_free_code()

void BPY_text_free_code ( Text text)

◆ CLG_LOGREF_DECLARE_GLOBAL() [1/3]

CLG_LOGREF_DECLARE_GLOBAL ( BPY_LOG_CONTEXT  ,
"bpy.context"   
)

◆ CLG_LOGREF_DECLARE_GLOBAL() [2/3]

CLG_LOGREF_DECLARE_GLOBAL ( BPY_LOG_INTERFACE  ,
"bpy.interface"   
)

◆ CLG_LOGREF_DECLARE_GLOBAL() [3/3]

CLG_LOGREF_DECLARE_GLOBAL ( BPY_LOG_RNA  ,
"bpy.rna"   
)

◆ pystatus_exit_on_error()

static void pystatus_exit_on_error ( PyStatus  status)
static

Convenience function for BPY_python_start.

These should happen so rarely that having comprehensive errors isn't needed. For example if sys.argv fails to allocate memory.

Show an error just to avoid silent failure in the unlikely event something goes wrong, in this case a developer will need to track down the root cause.

Definition at line 296 of file bpy_interface.c.

References UNLIKELY.

Referenced by BPY_python_start().

◆ text_check_identifier_nodigit_unicode()

int text_check_identifier_nodigit_unicode ( const uint  ch)

Definition at line 897 of file bpy_interface.c.

References text_check_identifier_nodigit().

Referenced by text_autocomplete_build().

◆ text_check_identifier_unicode()

int text_check_identifier_unicode ( const uint  ch)

Definition at line 892 of file bpy_interface.c.

References text_check_identifier().

Referenced by text_autocomplete_build().

Variable Documentation

◆ bpy_internal_modules

struct _inittab bpy_internal_modules[]
static

Definition at line 231 of file bpy_interface.c.

Referenced by BPY_python_start().

◆ py_call_level

int py_call_level = 0
static

Definition at line 76 of file bpy_interface.c.

Referenced by bpy_context_clear(), bpy_context_set(), and BPY_modules_load_user().

◆ py_use_system_env

bool py_use_system_env = false
static

Definition at line 79 of file bpy_interface.c.

Referenced by BPY_python_start(), and BPY_python_use_system_env().