diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_library_load.c | 15 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_library_write.c | 6 |
2 files changed, 12 insertions, 9 deletions
diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index 020c8f7ea49..24eb9a61512 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -34,7 +34,6 @@ #include "BLI_string.h" #include "BLI_utildefines.h" -#include "BKE_context.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_main.h" @@ -68,9 +67,11 @@ typedef struct { BlendHandle *blo_handle; int flag; PyObject *dict; + /* Borrowed reference to the `bmain`, taken from the RNA instance of #RNA_BlendDataLibraries. */ + Main *bmain; } BPy_Library; -static PyObject *bpy_lib_load(PyObject *self, PyObject *args, PyObject *kwds); +static PyObject *bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kwds); static PyObject *bpy_lib_enter(BPy_Library *self); static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *args); static PyObject *bpy_lib_dir(BPy_Library *self); @@ -182,9 +183,9 @@ PyDoc_STRVAR( " :type relative: bool\n" " :arg assets_only: If True, only list data-blocks marked as assets.\n" " :type assets_only: bool\n"); -static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +static PyObject *bpy_lib_load(BPy_PropertyRNA *self, PyObject *args, PyObject *kw) { - Main *bmain = CTX_data_main(BPY_context_get()); + Main *bmain = self->ptr.data; /* Typically #G_MAIN */ BPy_Library *ret; const char *filename = NULL; bool is_rel = false, is_link = false, use_assets_only = false; @@ -210,6 +211,8 @@ static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject * BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath)); BLI_path_abs(ret->abspath, BKE_main_blendfile_path(bmain)); + ret->bmain = bmain; + ret->blo_handle = NULL; ret->flag = ((is_link ? FILE_LINK : 0) | (is_rel ? FILE_RELPATH : 0) | (use_assets_only ? FILE_ASSETS_ONLY : 0)); @@ -333,7 +336,7 @@ static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item) static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) { - Main *bmain = CTX_data_main(BPY_context_get()); + Main *bmain = self->bmain; Main *mainl = NULL; const int err = 0; const bool do_append = ((self->flag & FILE_LINK) == 0); @@ -477,7 +480,7 @@ static PyObject *bpy_lib_dir(BPy_Library *self) PyMethodDef BPY_library_load_method_def = { "load", (PyCFunction)bpy_lib_load, - METH_STATIC | METH_VARARGS | METH_KEYWORDS, + METH_VARARGS | METH_KEYWORDS, bpy_lib_load_doc, }; diff --git a/source/blender/python/intern/bpy_library_write.c b/source/blender/python/intern/bpy_library_write.c index 66d20dd357f..f26f305cca8 100644 --- a/source/blender/python/intern/bpy_library_write.c +++ b/source/blender/python/intern/bpy_library_write.c @@ -71,7 +71,7 @@ PyDoc_STRVAR( " :type fake_user: bool\n" " :arg compress: When True, write a compressed blend file.\n" " :type compress: bool\n"); -static PyObject *bpy_lib_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +static PyObject *bpy_lib_write(BPy_PropertyRNA *self, PyObject *args, PyObject *kw) { /* args */ const char *filepath; @@ -114,7 +114,7 @@ static PyObject *bpy_lib_write(PyObject *UNUSED(self), PyObject *args, PyObject return NULL; } - Main *bmain_src = G_MAIN; + Main *bmain_src = self->ptr.data; /* Typically #G_MAIN */ int write_flags = 0; if (use_compress) { @@ -220,6 +220,6 @@ finally: PyMethodDef BPY_library_write_method_def = { "write", (PyCFunction)bpy_lib_write, - METH_STATIC | METH_VARARGS | METH_KEYWORDS, + METH_VARARGS | METH_KEYWORDS, bpy_lib_write_doc, }; |