Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r--source/blender/python/intern/bpy_interface.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index e6f4c5713a1..e5e90380d61 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -43,6 +43,7 @@
#include "bpy_rna.h"
#include "bpy_util.h"
#include "bpy_traceback.h"
+#include "bpy_intern_string.h"
#include "DNA_space_types.h"
#include "DNA_text_types.h"
@@ -65,10 +66,10 @@
#include "../generic/py_capi_utils.h"
/* inittab initialization functions */
-#include "../generic/noise_py_api.h"
-#include "../generic/mathutils.h"
#include "../generic/bgl.h"
#include "../generic/blf_py_api.h"
+#include "../generic/noise_py_api.h"
+#include "../mathutils/mathutils.h"
/* for internal use, when starting and ending python scripts */
@@ -86,6 +87,14 @@ static double bpy_timer_run; /* time for each python script run */
static double bpy_timer_run_tot; /* accumulate python runs */
#endif
+/* use for updating while a python script runs - in case of file load */
+void bpy_context_update(bContext *C)
+{
+ BPy_SetContext(C);
+ bpy_import_main_set(CTX_data_main(C));
+ BPY_modules_update(C); /* can give really bad results if this isnt here */
+}
+
void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
{
py_call_level++;
@@ -94,16 +103,7 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
*gilstate= PyGILState_Ensure();
if(py_call_level==1) {
-
- if(C) { // XXX - should always be true.
- BPy_SetContext(C);
- bpy_import_main_set(CTX_data_main(C));
- }
- else {
- fprintf(stderr, "ERROR: Python context called with a NULL Context. this should not happen!\n");
- }
-
- BPY_modules_update(C); /* can give really bad results if this isnt here */
+ bpy_context_update(C);
#ifdef TIME_PY_RUN
if(bpy_timer_count==0) {
@@ -174,11 +174,13 @@ extern PyObject *AUD_initPython(void);
static struct _inittab bpy_internal_modules[]= {
{(char *)"noise", BPyInit_noise},
- {(char *)"mathutils", BPyInit_mathutils},
-// {(char *)"mathutils.geometry", BPyInit_mathutils_geometry},
+ {(char *)"mathutils", PyInit_mathutils},
+// {(char *)"mathutils.geometry", PyInit_mathutils_geometry},
{(char *)"bgl", BPyInit_bgl},
{(char *)"blf", BPyInit_blf},
+#ifdef WITH_AUDASPACE
{(char *)"aud", AUD_initPython},
+#endif
{NULL, NULL}
};
@@ -199,13 +201,13 @@ void BPY_python_start(int argc, const char **argv)
/* allow to use our own included python */
PyC_SetHomePath(BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL));
- /* Python 3.2 now looks for '2.57/python/include/python3.2d/pyconfig.h' to parse
+ /* Python 3.2 now looks for '2.58/python/include/python3.2d/pyconfig.h' to parse
* from the 'sysconfig' module which is used by 'site', so for now disable site.
* alternatively we could copy the file. */
Py_NoSiteFlag= 1;
Py_Initialize();
-
+
// PySys_SetArgv(argc, argv); // broken in py3, not a huge deal
/* sigh, why do python guys not have a char** version anymore? :( */
{
@@ -228,6 +230,8 @@ void BPY_python_start(int argc, const char **argv)
PyImport_ExtendInittab(bpy_internal_modules);
#endif
+ bpy_intern_string_init();
+
/* bpy.* and lets us import it */
BPy_init_modules();
@@ -251,7 +255,9 @@ void BPY_python_end(void)
pyrna_free_types();
/* clear all python data from structs */
-
+
+ bpy_intern_string_exit();
+
Py_Finalize();
#ifdef TIME_PY_RUN
@@ -563,6 +569,12 @@ void BPY_modules_load_user(bContext *C)
if(bmain==NULL)
return;
+ /* update pointers since this can run from a nested script
+ * on file load */
+ if(py_call_level) {
+ bpy_context_update(C);
+ }
+
bpy_context_set(C, &gilstate);
for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
@@ -656,7 +668,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
#include "BLI_storage.h"
/* TODO, reloading the module isnt functional at the moment. */
-extern int main_python(int argc, const char **argv);
+static void bpy_module_free(void *mod);
+extern int main_python_enter(int argc, const char **argv);
+extern void main_python_exit(void);
static struct PyModuleDef bpy_proxy_def= {
PyModuleDef_HEAD_INIT,
"bpy", /* m_name */
@@ -666,8 +680,8 @@ static struct PyModuleDef bpy_proxy_def= {
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
- NULL, /* m_free */
-};
+ bpy_module_free, /* m_free */
+};
typedef struct {
PyObject_HEAD
@@ -692,7 +706,7 @@ void bpy_module_delay_init(PyObject *bpy_proxy)
// printf("module found %s\n", argv[0]);
- main_python(argc, argv);
+ main_python_enter(argc, argv);
/* initialized in BPy_init_modules() */
PyDict_Update(PyModule_GetDict(bpy_proxy), PyModule_GetDict(bpy_package_py));
@@ -749,4 +763,9 @@ PyInit_bpy(void)
return bpy_proxy;
}
+static void bpy_module_free(void *UNUSED(mod))
+{
+ main_python_exit();
+}
+
#endif