Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/generic/bpy_internal_import.c
| Show All 28 Lines | |||||
| * \note | * \note | ||||
| * This should eventually be replaced by import hooks (pep 302). | * This should eventually be replaced by import hooks (pep 302). | ||||
| */ | */ | ||||
| #include <Python.h> | #include <Python.h> | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include "CLG_log.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "DNA_text_types.h" | #include "DNA_text_types.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| /* UNUSED */ | /* UNUSED */ | ||||
| #include "BKE_text.h" /* txt_to_buf */ | #include "BKE_text.h" /* txt_to_buf */ | ||||
| #include "py_capi_utils.h" | #include "py_capi_utils.h" | ||||
| #include "bpy_internal_import.h" /* own include */ | #include "bpy_internal_import.h" /* own include */ | ||||
| static CLG_LogRef LOG = {"bpy.internal_import"}; | |||||
| static Main *bpy_import_main = NULL; | static Main *bpy_import_main = NULL; | ||||
| static ListBase bpy_import_main_list; | static ListBase bpy_import_main_list; | ||||
| static PyMethodDef bpy_import_meth; | static PyMethodDef bpy_import_meth; | ||||
| static PyMethodDef bpy_reload_meth; | static PyMethodDef bpy_reload_meth; | ||||
| static PyObject *imp_reload_orig = NULL; | static PyObject *imp_reload_orig = NULL; | ||||
| /* 'builtins' is most likely PyEval_GetBuiltins() */ | /* 'builtins' is most likely PyEval_GetBuiltins() */ | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | PyObject *bpy_text_import_name(const char *name, int *found) | ||||
| char txtname[MAX_ID_NAME - 2]; | char txtname[MAX_ID_NAME - 2]; | ||||
| int namelen = strlen(name); | int namelen = strlen(name); | ||||
| //XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; | //XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; | ||||
| Main *maggie = bpy_import_main; | Main *maggie = bpy_import_main; | ||||
| *found = 0; | *found = 0; | ||||
| if (!maggie) { | if (!maggie) { | ||||
| printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); | CLOG_ERROR(&LOG, "bpy_import_main_set() was not called before running python. this is a bug."); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* we know this cant be importable, the name is too long for blender! */ | /* we know this cant be importable, the name is too long for blender! */ | ||||
| if (namelen >= (MAX_ID_NAME - 2) - 3) | if (namelen >= (MAX_ID_NAME - 2) - 3) | ||||
| return NULL; | return NULL; | ||||
| memcpy(txtname, name, namelen); | memcpy(txtname, name, namelen); | ||||
| Show All 30 Lines | |||||
| { | { | ||||
| Text *text; | Text *text; | ||||
| const char *name; | const char *name; | ||||
| const char *filepath; | const char *filepath; | ||||
| //XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; | //XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN; | ||||
| Main *maggie = bpy_import_main; | Main *maggie = bpy_import_main; | ||||
| if (!maggie) { | if (!maggie) { | ||||
| printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n"); | CLOG_ERROR(&LOG, "bpy_import_main_set() was not called before running python. this is a bug."); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| *found = 0; | *found = 0; | ||||
| /* get name, filename from the module itself */ | /* get name, filename from the module itself */ | ||||
| if ((name = PyModule_GetName(module)) == NULL) | if ((name = PyModule_GetName(module)) == NULL) | ||||
| return NULL; | return NULL; | ||||
| ▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines | |||||