Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-22 10:57:18 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-22 10:57:18 +0300
commit1e120098fc7e668a28d7eed6a082f5a8b134e39c (patch)
tree39a838b39efe3c26b6a4a316db69b222e4ad1279
parent91357ae2ea11894adf1519eb149ac3dd48bc26f8 (diff)
pyapi, use direct access to the frame rather then python attributes.
-rw-r--r--source/blender/python/generic/py_capi_utils.c45
-rw-r--r--source/blender/python/intern/bpy_rna.c12
2 files changed, 20 insertions, 37 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index e8618883874..8e8da87b85f 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -21,6 +21,7 @@
*/
#include <Python.h>
+#include <frameobject.h>
#include "py_capi_utils.h"
@@ -56,37 +57,20 @@ void PyC_LineSpit(void) {
void PyC_FileAndNum(const char **filename, int *lineno)
{
- PyObject *getframe, *frame;
- PyObject *f_lineno= NULL, *co_filename= NULL;
+ PyFrameObject *frame;
if (filename) *filename= NULL;
if (lineno) *lineno = -1;
-
- getframe = PySys_GetObject("_getframe"); // borrowed
- if (getframe==NULL) {
- PyErr_Clear();
- return;
- }
-
- frame = PyObject_CallObject(getframe, NULL);
- if (frame==NULL) {
- PyErr_Clear();
+
+ if (!(frame= PyThreadState_GET()->frame)) {
return;
}
-
+
/* when executing a script */
if (filename) {
- co_filename= PyC_Object_GetAttrStringArgs(frame, 2, "f_code", "co_filename");
- if (co_filename==NULL) {
- PyErr_SetString(PyExc_RuntimeError, "Could not access sys._getframe().f_code.co_filename");
- Py_DECREF(frame);
- return;
- }
-
- *filename = _PyUnicode_AsString(co_filename);
- Py_DECREF(co_filename);
+ *filename = _PyUnicode_AsString(frame->f_code->co_filename);
}
-
+
/* when executing a module */
if(filename && *filename == NULL) {
/* try an alternative method to get the filename - module based
@@ -104,21 +88,10 @@ void PyC_FileAndNum(const char **filename, int *lineno)
}
}
}
-
-
+
if (lineno) {
- f_lineno= PyObject_GetAttrString(frame, "f_lineno");
- if (f_lineno==NULL) {
- PyErr_SetString(PyExc_RuntimeError, "Could not access sys._getframe().f_lineno");
- Py_DECREF(frame);
- return;
- }
-
- *lineno = (int)PyLong_AsSsize_t(f_lineno);
- Py_DECREF(f_lineno);
+ *lineno = PyFrame_GetLineNumber(frame);
}
-
- Py_DECREF(frame);
}
/* Would be nice if python had this built in */
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index bc89dc01f9a..561e93b338a 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -3937,6 +3937,16 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
+ /* for testing */
+ /*
+ {
+ const char *fn;
+ int lineno;
+ PyC_FileAndNum(&fn, &lineno);
+ printf("pyrna_func_call > %.200s.%.200s : %.200s:%d\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), fn, lineno);
+ }
+ */
+
/* include the ID pointer for pyrna_param_to_py() so we can include the
* ID pointer on return values, this only works when returned values have
* the same ID as the functions. */
@@ -5415,7 +5425,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
/* testing, for correctness, not operator and not draw function */
const short is_readonly= strstr("draw", func_id) || /*strstr("render", func_id) ||*/ !RNA_struct_is_a(ptr->type, &RNA_Operator);
#endif
-
+
py_class= RNA_struct_py_type_get(ptr->type);
/* rare case. can happen when registering subclasses */