[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35056] trunk/blender/source/blender/ python: pyapi, use direct access to the frame rather then python attributes .

Campbell Barton ideasman42 at gmail.com
Tue Feb 22 08:57:19 CET 2011


Revision: 35056
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35056
Author:   campbellbarton
Date:     2011-02-22 07:57:18 +0000 (Tue, 22 Feb 2011)
Log Message:
-----------
pyapi, use direct access to the frame rather then python attributes.

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/py_capi_utils.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/generic/py_capi_utils.c
===================================================================
--- trunk/blender/source/blender/python/generic/py_capi_utils.c	2011-02-22 06:45:47 UTC (rev 35055)
+++ trunk/blender/source/blender/python/generic/py_capi_utils.c	2011-02-22 07:57:18 UTC (rev 35056)
@@ -21,6 +21,7 @@
 */
 
 #include <Python.h>
+#include <frameobject.h>
 
 #include "py_capi_utils.h"
 
@@ -56,37 +57,20 @@
 
 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();
+
+	if (!(frame= PyThreadState_GET()->frame)) {
 		return;
 	}
-	
-	frame = PyObject_CallObject(getframe, NULL);
-	if (frame==NULL) {
-		PyErr_Clear();
-		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 @@
 			}
 		}
 	}
-		
-	
+
 	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 */

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2011-02-22 06:45:47 UTC (rev 35055)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2011-02-22 07:57:18 UTC (rev 35056)
@@ -3937,6 +3937,16 @@
 		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 @@
 	/* 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 */




More information about the Bf-blender-cvs mailing list