pass along the context to extension functions, this was already being done in all cases except for the render engine.
this allows python to NULL its internal context while scripts are not running.
This commit is contained in:
@@ -124,7 +124,7 @@ void CTX_store_free_list(ListBase *contexts);
|
||||
int CTX_py_init_get(bContext *C);
|
||||
void CTX_py_init_set(bContext *C, int value);
|
||||
|
||||
void *CTX_py_dict_get(bContext *C);
|
||||
void *CTX_py_dict_get(const bContext *C);
|
||||
void CTX_py_dict_set(bContext *C, void *value);
|
||||
|
||||
/* Window Manager Context */
|
||||
|
||||
@@ -179,7 +179,7 @@ void CTX_py_init_set(bContext *C, int value)
|
||||
C->data.py_init= value;
|
||||
}
|
||||
|
||||
void *CTX_py_dict_get(bContext *C)
|
||||
void *CTX_py_dict_get(const bContext *C)
|
||||
{
|
||||
return C->data.py_context;
|
||||
}
|
||||
|
||||
@@ -311,9 +311,9 @@ typedef enum StructFlag {
|
||||
} StructFlag;
|
||||
|
||||
typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function);
|
||||
typedef int (*StructCallbackFunc)(struct PointerRNA *ptr, struct FunctionRNA *func, ParameterList *list);
|
||||
typedef int (*StructCallbackFunc)(struct bContext *C, struct PointerRNA *ptr, struct FunctionRNA *func, ParameterList *list);
|
||||
typedef void (*StructFreeFunc)(void *data);
|
||||
typedef struct StructRNA *(*StructRegisterFunc)(const struct bContext *C, struct ReportList *reports, void *data,
|
||||
typedef struct StructRNA *(*StructRegisterFunc)(struct bContext *C, struct ReportList *reports, void *data,
|
||||
const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free);
|
||||
typedef void (*StructUnregisterFunc)(const struct bContext *C, struct StructRNA *type);
|
||||
|
||||
@@ -333,9 +333,9 @@ typedef struct BlenderRNA BlenderRNA;
|
||||
typedef struct ExtensionRNA {
|
||||
void *data;
|
||||
StructRNA *srna;
|
||||
StructCallbackFunc call;
|
||||
StructFreeFunc free;
|
||||
|
||||
int (*call)(PointerRNA *, FunctionRNA *, ParameterList *);
|
||||
void (*free)(void *data);
|
||||
} ExtensionRNA;
|
||||
|
||||
/* fake struct definitions, needed otherwise collections end up owning the C
|
||||
|
||||
@@ -208,7 +208,7 @@ void rna_IDPropertyGroup_unregister(const bContext *C, StructRNA *type)
|
||||
RNA_struct_free(&BLENDER_RNA, type);
|
||||
}
|
||||
|
||||
StructRNA *rna_IDPropertyGroup_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
StructRNA *rna_IDPropertyGroup_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
PointerRNA dummyptr;
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ static int RKS_POLL_rna_internal(KeyingSetInfo *ksi, bContext *C)
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
|
||||
/* execute the function */
|
||||
ksi->ext.call(&ptr, func, &list);
|
||||
ksi->ext.call(C, &ptr, func, &list);
|
||||
|
||||
/* read the result */
|
||||
RNA_parameter_get_lookup(&list, "ok", &ret);
|
||||
@@ -107,7 +107,7 @@ static void RKS_ITER_rna_internal(KeyingSetInfo *ksi, bContext *C, KeyingSet *ks
|
||||
RNA_parameter_set_lookup(&list, "ks", &ks);
|
||||
|
||||
/* execute the function */
|
||||
ksi->ext.call(&ptr, func, &list);
|
||||
ksi->ext.call(C, &ptr, func, &list);
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ static void RKS_GEN_rna_internal(KeyingSetInfo *ksi, bContext *C, KeyingSet *ks,
|
||||
RNA_parameter_set_lookup(&list, "data", data);
|
||||
|
||||
/* execute the function */
|
||||
ksi->ext.call(&ptr, func, &list);
|
||||
ksi->ext.call(C, &ptr, func, &list);
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ static void rna_KeyingSetInfo_unregister(const bContext *C, StructRNA *type)
|
||||
ANIM_keyingset_info_unregister(C, ksi);
|
||||
}
|
||||
|
||||
static StructRNA *rna_KeyingSetInfo_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_KeyingSetInfo_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
KeyingSetInfo dummyksi = {0};
|
||||
KeyingSetInfo *ksi;
|
||||
|
||||
@@ -193,7 +193,7 @@ struct IDProperty *rna_ID_idprops(struct PointerRNA *ptr, int create);
|
||||
void rna_ID_fake_user_set(struct PointerRNA *ptr, int value);
|
||||
struct IDProperty *rna_IDPropertyGroup_idprops(struct PointerRNA *ptr, int create);
|
||||
void rna_IDPropertyGroup_unregister(const struct bContext *C, struct StructRNA *type);
|
||||
struct StructRNA *rna_IDPropertyGroup_register(const struct bContext *C, struct ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free);
|
||||
struct StructRNA *rna_IDPropertyGroup_register(struct bContext *C, struct ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free);
|
||||
struct StructRNA* rna_IDPropertyGroup_refine(struct PointerRNA *ptr);
|
||||
|
||||
void rna_object_vgroup_name_index_get(struct PointerRNA *ptr, char *value, int index);
|
||||
|
||||
@@ -91,7 +91,7 @@ static void engine_render(RenderEngine *engine, struct Scene *scene)
|
||||
|
||||
RNA_parameter_list_create(&list, &ptr, func);
|
||||
RNA_parameter_set_lookup(&list, "scene", &scene);
|
||||
engine->type->ext.call(&ptr, func, &list);
|
||||
engine->type->ext.call(NULL, &ptr, func, &list);
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ static void rna_RenderEngine_unregister(const bContext *C, StructRNA *type)
|
||||
RNA_struct_free(&BLENDER_RNA, type);
|
||||
}
|
||||
|
||||
static StructRNA *rna_RenderEngine_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_RenderEngine_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
RenderEngineType *et, dummyet = {0};
|
||||
RenderEngine dummyengine= {0};
|
||||
|
||||
@@ -101,7 +101,7 @@ static int panel_poll(const bContext *C, PanelType *pt)
|
||||
|
||||
RNA_parameter_list_create(&list, &ptr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
pt->ext.call(&ptr, func, &list);
|
||||
pt->ext.call((bContext *)C, &ptr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "visible", &ret);
|
||||
visible= *(int*)ret;
|
||||
@@ -122,7 +122,7 @@ static void panel_draw(const bContext *C, Panel *pnl)
|
||||
|
||||
RNA_parameter_list_create(&list, &ptr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
pnl->type->ext.call(&ptr, func, &list);
|
||||
pnl->type->ext.call((bContext *)C, &ptr, func, &list);
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ static void panel_draw_header(const bContext *C, Panel *pnl)
|
||||
|
||||
RNA_parameter_list_create(&list, &ptr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
pnl->type->ext.call(&ptr, func, &list);
|
||||
pnl->type->ext.call((bContext *)C, &ptr, func, &list);
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ static void rna_Panel_unregister(const bContext *C, StructRNA *type)
|
||||
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
||||
}
|
||||
|
||||
static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_Panel_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
ARegionType *art;
|
||||
PanelType *pt, dummypt = {0};
|
||||
@@ -241,7 +241,7 @@ static void header_draw(const bContext *C, Header *hdr)
|
||||
|
||||
RNA_parameter_list_create(&list, &htr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
hdr->type->ext.call(&htr, func, &list);
|
||||
hdr->type->ext.call((bContext *)C, &htr, func, &list);
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ static void rna_Header_unregister(const bContext *C, StructRNA *type)
|
||||
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
||||
}
|
||||
|
||||
static StructRNA *rna_Header_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_Header_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
ARegionType *art;
|
||||
HeaderType *ht, dummyht = {0};
|
||||
@@ -341,7 +341,7 @@ static int menu_poll(const bContext *C, MenuType *pt)
|
||||
|
||||
RNA_parameter_list_create(&list, &ptr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
pt->ext.call(&ptr, func, &list);
|
||||
pt->ext.call((bContext *)C, &ptr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "visible", &ret);
|
||||
visible= *(int*)ret;
|
||||
@@ -362,7 +362,7 @@ static void menu_draw(const bContext *C, Menu *hdr)
|
||||
|
||||
RNA_parameter_list_create(&list, &mtr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
hdr->type->ext.call(&mtr, func, &list);
|
||||
hdr->type->ext.call((bContext *)C, &mtr, func, &list);
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
@@ -385,7 +385,7 @@ static void rna_Menu_unregister(const bContext *C, StructRNA *type)
|
||||
WM_main_add_notifier(NC_SCREEN|NA_EDITED, NULL);
|
||||
}
|
||||
|
||||
static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_Menu_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
MenuType *mt, dummymt = {0};
|
||||
Menu dummymenu= {0};
|
||||
|
||||
@@ -693,7 +693,7 @@ static int operator_poll(bContext *C, wmOperatorType *ot)
|
||||
|
||||
RNA_parameter_list_create(&list, &ptr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
ot->ext.call(&ptr, func, &list);
|
||||
ot->ext.call(C, &ptr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "visible", &ret);
|
||||
visible= *(int*)ret;
|
||||
@@ -716,7 +716,7 @@ static int operator_execute(bContext *C, wmOperator *op)
|
||||
|
||||
RNA_parameter_list_create(&list, &opr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
op->type->ext.call(&opr, func, &list);
|
||||
op->type->ext.call(C, &opr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "result", &ret);
|
||||
result= *(int*)ret;
|
||||
@@ -740,7 +740,7 @@ static int operator_check(bContext *C, wmOperator *op)
|
||||
|
||||
RNA_parameter_list_create(&list, &opr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
op->type->ext.call(&opr, func, &list);
|
||||
op->type->ext.call(C, &opr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "result", &ret);
|
||||
result= *(int*)ret;
|
||||
@@ -764,7 +764,7 @@ static int operator_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
RNA_parameter_list_create(&list, &opr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
RNA_parameter_set_lookup(&list, "event", &event);
|
||||
op->type->ext.call(&opr, func, &list);
|
||||
op->type->ext.call(C, &opr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "result", &ret);
|
||||
result= *(int*)ret;
|
||||
@@ -789,7 +789,7 @@ static int operator_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
RNA_parameter_list_create(&list, &opr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
RNA_parameter_set_lookup(&list, "event", &event);
|
||||
op->type->ext.call(&opr, func, &list);
|
||||
op->type->ext.call(C, &opr, func, &list);
|
||||
|
||||
RNA_parameter_get_lookup(&list, "result", &ret);
|
||||
result= *(int*)ret;
|
||||
@@ -810,7 +810,7 @@ static void operator_draw(bContext *C, wmOperator *op)
|
||||
|
||||
RNA_parameter_list_create(&list, &opr, func);
|
||||
RNA_parameter_set_lookup(&list, "context", &C);
|
||||
op->type->ext.call(&opr, func, &list);
|
||||
op->type->ext.call(C, &opr, func, &list);
|
||||
|
||||
RNA_parameter_list_free(&list);
|
||||
}
|
||||
@@ -821,7 +821,7 @@ void macro_wrapper(wmOperatorType *ot, void *userdata);
|
||||
static char _operator_idname[OP_MAX_TYPENAME];
|
||||
static char _operator_name[OP_MAX_TYPENAME];
|
||||
static char _operator_descr[1024];
|
||||
static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_Operator_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
wmOperatorType dummyot = {0};
|
||||
wmOperator dummyop= {0};
|
||||
@@ -894,7 +894,7 @@ static StructRNA *rna_Operator_register(const bContext *C, ReportList *reports,
|
||||
}
|
||||
|
||||
|
||||
static StructRNA *rna_MacroOperator_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
static StructRNA *rna_MacroOperator_register(bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
|
||||
{
|
||||
wmOperatorType dummyot = {0};
|
||||
wmOperator dummyop= {0};
|
||||
|
||||
@@ -223,7 +223,7 @@ void BPy_init_modules( void )
|
||||
PyModule_AddObject( mod, "app", BPY_app_struct() );
|
||||
|
||||
/* bpy context */
|
||||
RNA_pointer_create(NULL, &RNA_Context, BPy_GetContext(), &ctx_ptr);
|
||||
RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr);
|
||||
bpy_context_module= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ctx_ptr);
|
||||
/* odd that this is needed, 1 ref on creation and another for the module
|
||||
* but without we get a crash on exit */
|
||||
|
||||
@@ -52,7 +52,12 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
int context= WM_OP_EXEC_DEFAULT;
|
||||
|
||||
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
|
||||
bContext *C = BPy_GetContext();
|
||||
bContext *C= (bContext *)BPy_GetContext();
|
||||
|
||||
if(C==NULL) {
|
||||
PyErr_SetString(PyExc_SystemError, "Context is None, cant poll any operators");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str))
|
||||
return NULL;
|
||||
@@ -114,7 +119,12 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
int context= WM_OP_EXEC_DEFAULT;
|
||||
|
||||
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
|
||||
bContext *C = BPy_GetContext();
|
||||
bContext *C = (bContext *)BPy_GetContext();
|
||||
|
||||
if(C==NULL) {
|
||||
PyErr_SetString(PyExc_SystemError, "Context is None, cant poll any operators");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str))
|
||||
return NULL;
|
||||
@@ -232,7 +242,12 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
||||
char *buf = NULL;
|
||||
PyObject *pybuf;
|
||||
|
||||
bContext *C = BPy_GetContext();
|
||||
bContext *C = (bContext *)BPy_GetContext();
|
||||
|
||||
if(C==NULL) {
|
||||
PyErr_SetString(PyExc_SystemError, "Context is None, cant get the string representation of this object.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args))
|
||||
return NULL;
|
||||
|
||||
@@ -5125,7 +5125,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
||||
extern void BPY_update_modules( void ); //XXX temp solution
|
||||
|
||||
/* TODO - multiple return values like with rna functions */
|
||||
static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
|
||||
static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
|
||||
{
|
||||
PyObject *args;
|
||||
PyObject *ret= NULL, *py_srna= NULL, *py_class, *py_class_instance= NULL, *parmitem;
|
||||
@@ -5141,7 +5141,6 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
|
||||
|
||||
PyGILState_STATE gilstate;
|
||||
|
||||
bContext *C= BPy_GetContext(); // XXX - NEEDS FIXING, QUITE BAD.
|
||||
#ifdef USE_PEDANTIC_WRITE
|
||||
/* testing, for correctness, not operator and not draw function */
|
||||
const short is_readonly= strstr("draw", RNA_function_identifier(func)) || !RNA_struct_is_a(ptr->type, &RNA_Operator);
|
||||
|
||||
Reference in New Issue
Block a user