Cleanup: get rid of last G.main's in bpy area.

Essentially 'validating' them as G_MAIN, and adding some asserts in
dubious places, that handled IDs are actually in G_MAIN.
This commit is contained in:
Bastien Montagne
2018-06-22 11:37:47 +02:00
parent 1870a1adc7
commit cbf5c738d6
9 changed files with 21 additions and 14 deletions

View File

@@ -38,6 +38,7 @@
#include "BKE_customdata.h" #include "BKE_customdata.h"
#include "BKE_DerivedMesh.h" #include "BKE_DerivedMesh.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_library.h"
#include "bmesh.h" #include "bmesh.h"
@@ -905,8 +906,9 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
/* python won't ensure matching uv/mtex */ /* python won't ensure matching uv/mtex */
BM_mesh_cd_validate(bm); BM_mesh_cd_validate(bm);
BLI_assert(BKE_id_is_in_gobal_main(&me->id));
BM_mesh_bm_to_me( BM_mesh_bm_to_me(
G.main, /* XXX UGLY! */ G_MAIN, /* XXX UGLY! */
bm, me, bm, me,
(&(struct BMeshToMeshParams){ (&(struct BMeshToMeshParams){
.calc_object_remap = true, .calc_object_remap = true,

View File

@@ -185,7 +185,7 @@ PyObject *bpy_text_import_name(const char *name, int *found)
Text *text; Text *text;
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;
@@ -234,7 +234,7 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
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) {

View File

@@ -51,7 +51,7 @@ PyObject *bpy_text_reimport(PyObject *module, int *found);
void bpy_text_filename_get(char *fn, size_t fn_len, struct Text *text); void bpy_text_filename_get(char *fn, size_t fn_len, struct Text *text);
/* The game engine has its own Main struct, if this is set search this rather than G.main */ /* The game engine has its own Main struct, if this is set search this rather than G_MAIN */
struct Main *bpy_import_main_get(void); struct Main *bpy_import_main_get(void);
void bpy_import_main_set(struct Main *maggie); void bpy_import_main_set(struct Main *maggie);

View File

@@ -34,7 +34,7 @@
#include "BLI_string.h" #include "BLI_string.h"
#include "BKE_appdir.h" #include "BKE_appdir.h"
#include "BKE_global.h" /* XXX, G.main only */ #include "BKE_global.h" /* XXX, G_MAIN only */
#include "BKE_blender_version.h" #include "BKE_blender_version.h"
#include "BKE_bpath.h" #include "BKE_bpath.h"
@@ -136,7 +136,7 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
list = PyList_New(0); list = PyList_New(0);
BKE_bpath_traverse_main(G.main, bpy_blend_paths_visit_cb, flag, (void *)list); BKE_bpath_traverse_main(G_MAIN, bpy_blend_paths_visit_cb, flag, (void *)list);
return list; return list;
} }

View File

@@ -95,7 +95,7 @@ static PyObject *bpy_lib_write(PyObject *UNUSED(self), PyObject *args, PyObject
return NULL; return NULL;
} }
Main *bmain_src = G.main; Main *bmain_src = G_MAIN;
int write_flags = 0; int write_flags = 0;
if (use_relative_remap) { if (use_relative_remap) {

View File

@@ -7017,7 +7017,7 @@ PyObject *BPY_rna_module(void)
PointerRNA ptr; PointerRNA ptr;
/* for now, return the base RNA type rather than a real module */ /* for now, return the base RNA type rather than a real module */
RNA_main_pointer_create(G.main, &ptr); RNA_main_pointer_create(G_MAIN, &ptr);
pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
rna_module_ptr = &pyrna->ptr; rna_module_ptr = &pyrna->ptr;
@@ -7028,9 +7028,9 @@ void BPY_update_rna_module(void)
{ {
if (rna_module_ptr) { if (rna_module_ptr) {
#if 0 #if 0
RNA_main_pointer_create(G.main, rna_module_ptr); RNA_main_pointer_create(G_MAIN, rna_module_ptr);
#else #else
rna_module_ptr->data = G.main; /* just set data is enough */ rna_module_ptr->data = G_MAIN; /* just set data is enough */
#endif #endif
} }
} }

View File

@@ -45,6 +45,7 @@
#include "BKE_fcurve.h" #include "BKE_fcurve.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_idcode.h" #include "BKE_idcode.h"
#include "BKE_library.h"
#include "BKE_report.h" #include "BKE_report.h"
#include "RNA_access.h" #include "RNA_access.h"
@@ -266,12 +267,14 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
return PyBool_FromLong(result); return PyBool_FromLong(result);
} }
else { else {
ID *id = self->ptr.id.data;
ReportList reports; ReportList reports;
short result; short result;
BKE_reports_init(&reports, RPT_STORE); BKE_reports_init(&reports, RPT_STORE);
result = insert_keyframe(G.main, &reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, keytype, options); BLI_assert(BKE_id_is_in_gobal_main(id));
result = insert_keyframe(G_MAIN, &reports, id, NULL, group_name, path_full, index, cfra, keytype, options);
MEM_freeN((void *)path_full); MEM_freeN((void *)path_full);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)

View File

@@ -160,7 +160,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
BPy_StructRNA *pyrna = (BPy_StructRNA *)self; BPy_StructRNA *pyrna = (BPy_StructRNA *)self;
Main *bmain = pyrna->ptr.data; Main *bmain = pyrna->ptr.data;
#else #else
Main *bmain = G.main; /* XXX Ugly, but should work! */ Main *bmain = G_MAIN; /* XXX Ugly, but should work! */
#endif #endif
PyObject *subset = NULL; PyObject *subset = NULL;
@@ -230,7 +230,6 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
lb_index = set_listbasepointers(bmain, lb_array); lb_index = set_listbasepointers(bmain, lb_array);
while (lb_index--) { while (lb_index--) {
if (val_types_bitmap && lb_array[lb_index]->first) { if (val_types_bitmap && lb_array[lb_index]->first) {
if (!id_check_type(lb_array[lb_index]->first, val_types_bitmap)) { if (!id_check_type(lb_array[lb_index]->first, val_types_bitmap)) {
continue; continue;

View File

@@ -36,6 +36,7 @@
#include "WM_types.h" #include "WM_types.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_library.h"
#include "ED_screen.h" #include "ED_screen.h"
@@ -169,7 +170,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
MatrixObject *py_mat_modelview, *py_mat_projection; MatrixObject *py_mat_modelview, *py_mat_projection;
PyObject *py_scene, *py_region, *py_view3d; PyObject *py_scene, *py_region, *py_view3d;
struct Main *bmain = G.main; /* XXX UGLY! */ struct Main *bmain = G_MAIN; /* XXX UGLY! */
Scene *scene; Scene *scene;
View3D *v3d; View3D *v3d;
ARegion *ar; ARegion *ar;
@@ -191,6 +192,8 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
return NULL; return NULL;
} }
BLI_assert(BKE_id_is_in_gobal_main(&scene->id));
fx = GPU_fx_compositor_create(); fx = GPU_fx_compositor_create();
fx_settings = v3d->fx_settings; /* full copy */ fx_settings = v3d->fx_settings; /* full copy */