[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20403] branches/blender2.5/blender/source /blender/python/intern: Store the context for python in a static variable with assessor functions - BPy_GetContext /BPy_SetContext,
Campbell Barton
ideasman42 at gmail.com
Mon May 25 15:48:44 CEST 2009
Revision: 20403
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20403
Author: campbellbarton
Date: 2009-05-25 15:48:44 +0200 (Mon, 25 May 2009)
Log Message:
-----------
Store the context for python in a static variable with assessor functions - BPy_GetContext/BPy_SetContext,
Still not happy with this in the long term but its less problematic then storing the context in pythons namespace which couldn't be set before importing modules.
This might fix a crash quite a few people have reported (but I cant reproduce).
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c
branches/blender2.5/blender/source/blender/python/intern/bpy_util.c
branches/blender2.5/blender/source/blender/python/intern/bpy_util.h
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c 2009-05-25 13:07:54 UTC (rev 20402)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c 2009-05-25 13:48:44 UTC (rev 20403)
@@ -90,9 +90,7 @@
Py_DECREF(item);
// XXX - evil, need to access context
- item = PyCObject_FromVoidPtr( C, NULL );
- PyDict_SetItemString( dict, "__bpy_context__", item );
- Py_DECREF(item);
+ BPy_SetContext(C);
// XXX - put somewhere more logical
{
@@ -386,6 +384,8 @@
PySys_SetObject("path", sys_path_new);
Py_DECREF(sys_path_new);
+ // XXX - evil, need to access context
+ BPy_SetContext(C);
while((de = readdir(dir)) != NULL) {
/* We could stat the file but easier just to let python
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c 2009-05-25 13:07:54 UTC (rev 20402)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c 2009-05-25 13:48:44 UTC (rev 20403)
@@ -126,7 +126,7 @@
PointerRNA ptr;
// 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 = (bContext *)PyCObject_AsVoidPtr(PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__"));
+ bContext *C = BPy_GetContext();
char *opname = _PyUnicode_AsString(self);
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c 2009-05-25 13:07:54 UTC (rev 20402)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c 2009-05-25 13:48:44 UTC (rev 20403)
@@ -1968,11 +1968,8 @@
}
/* get the context, so register callback can do necessary refreshes */
- item= PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__"); /* borrow ref */
+ C= BPy_GetContext();
- if(item)
- C= (bContext*)PyCObject_AsVoidPtr(item);
-
/* call the register callback */
BKE_reports_init(&reports, RPT_PRINT);
srna= reg(C, &reports, py_class, bpy_class_validate, bpy_class_call, bpy_class_free);
@@ -2031,11 +2028,9 @@
}
/* get the context, so register callback can do necessary refreshes */
- item= PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__"); /* borrow ref */
+ C= BPy_GetContext();
+
- if(item)
- C= (bContext*)PyCObject_AsVoidPtr(item);
-
/* call unregister */
unreg(C, py_srna->ptr.data);
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c 2009-05-25 13:07:54 UTC (rev 20402)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_ui.c 2009-05-25 13:48:44 UTC (rev 20403)
@@ -303,17 +303,9 @@
Py_RETURN_NONE;
}
-/* internal use only */
-static bContext *get_py_context__internal(void)
-{
- PyObject *globals = PyEval_GetGlobals();
- PyObject *val= PyDict_GetItemString(globals, "__bpy_context__"); /* borrow ref */
- return PyCObject_AsVoidPtr(val);
-}
-
static PyObject *Method_getRegonPtr( PyObject * self )
{
- bContext *C= get_py_context__internal();
+ bContext *C= BPy_GetContext();
ARegion *ar = CTX_wm_region(C);
return PyCObject_FromVoidPtr(ar, NULL);
@@ -321,7 +313,7 @@
static PyObject *Method_getAreaPtr( PyObject * self )
{
- bContext *C= get_py_context__internal();
+ bContext *C= BPy_GetContext();
ScrArea *area = CTX_wm_area(C);
return PyCObject_FromVoidPtr(area, NULL);
@@ -329,7 +321,7 @@
static PyObject *Method_getScreenPtr( PyObject * self )
{
- bContext *C= get_py_context__internal();
+ bContext *C= BPy_GetContext();
bScreen *screen= CTX_wm_screen(C);
return PyCObject_FromVoidPtr(screen, NULL);
@@ -337,7 +329,7 @@
static PyObject *Method_getSpacePtr( PyObject * self )
{
- bContext *C= get_py_context__internal();
+ bContext *C= BPy_GetContext();
SpaceLink *sl= CTX_wm_space_data(C);
return PyCObject_FromVoidPtr(sl, NULL);
@@ -345,7 +337,7 @@
static PyObject *Method_getWindowPtr( PyObject * self )
{
- bContext *C= get_py_context__internal();
+ bContext *C= BPy_GetContext();
wmWindow *window= CTX_wm_window(C);
return PyCObject_FromVoidPtr(window, NULL);
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_util.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_util.c 2009-05-25 13:07:54 UTC (rev 20402)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_util.c 2009-05-25 13:48:44 UTC (rev 20403)
@@ -29,6 +29,13 @@
#include "MEM_guardedalloc.h"
#include "BKE_report.h"
+
+#include "BKE_context.h"
+bContext* __py_context = NULL;
+bContext* BPy_GetContext(void) { return __py_context; };
+void BPy_SetContext(bContext *C) { __py_context= C; };
+
+
PyObject *BPY_flag_to_list(struct BPY_flag_def *flagdef, int flag)
{
PyObject *list = PyList_New(0);
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_util.h
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_util.h 2009-05-25 13:07:54 UTC (rev 20402)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_util.h 2009-05-25 13:48:44 UTC (rev 20403)
@@ -74,4 +74,8 @@
/* error reporting */
int BPy_reports_to_error(struct ReportList *reports);
+/* TODO - find a better solution! */
+struct bContext *BPy_GetContext(void);
+void BPy_SetContext(struct bContext *C);
+
#endif
More information about the Bf-blender-cvs
mailing list