diff options
Diffstat (limited to 'source/blender/python/intern/bpy_library_load.c')
-rw-r--r-- | source/blender/python/intern/bpy_library_load.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index 020c8f7ea49..03771a8c294 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,11 +211,13 @@ 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)); - ret->dict = _PyDict_NewPresized(MAX_LIBARRAY); + ret->dict = _PyDict_NewPresized(INDEX_ID_MAX); return (PyObject *)ret; } @@ -245,7 +248,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self) { PyObject *ret; BPy_Library *self_from; - PyObject *from_dict = _PyDict_NewPresized(MAX_LIBARRAY); + PyObject *from_dict = _PyDict_NewPresized(INDEX_ID_MAX); ReportList reports; BKE_reports_init(&reports, RPT_STORE); @@ -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, }; |