[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36998] trunk/blender/source: access pythons code object directly rather than attribute access.

Campbell Barton ideasman42 at gmail.com
Sun May 29 13:05:52 CEST 2011


Revision: 36998
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36998
Author:   campbellbarton
Date:     2011-05-29 11:05:52 +0000 (Sun, 29 May 2011)
Log Message:
-----------
access pythons code object directly rather than attribute access.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_rna.c
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2011-05-29 10:13:28 UTC (rev 36997)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2011-05-29 11:05:52 UTC (rev 36998)
@@ -5882,7 +5882,6 @@
 	PyObject *py_class= (PyObject*)py_data;
 	PyObject *base_class= RNA_struct_py_type_get(srna);
 	PyObject *item;
-	PyObject *py_arg_count;
 	int i, flag, arg_count, func_arg_count;
 	const char *py_class_name= ((PyTypeObject *)py_class)->tp_name; // __name__
 
@@ -5945,9 +5944,7 @@
 			func_arg_count= rna_function_arg_count(func);
 
 			if (func_arg_count >= 0) { /* -1 if we dont care*/
-				py_arg_count= PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
-				arg_count= PyLong_AsLong(py_arg_count);
-				Py_DECREF(py_arg_count);
+				arg_count= ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount;
 
 				/* note, the number of args we check for and the number of args we give to
 				 * @classmethods are different (quirk of python), this is why rna_function_arg_count() doesn't return the value -1*/

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2011-05-29 10:13:28 UTC (rev 36997)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2011-05-29 11:05:52 UTC (rev 36998)
@@ -1198,14 +1198,13 @@
 			f_lineno= PyObject_GetAttrString(frame, "f_lineno");
 			f_code= PyObject_GetAttrString(frame, "f_code");
 			if (f_lineno && f_code) {
-				co_filename= PyObject_GetAttrString(f_code, "co_filename");
+				co_filename= ((PyCodeObject *)f_code)->co_filename; /* borrow */
 				if (co_filename) {
 
 					printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno));
 
 					Py_DECREF(f_lineno);
 					Py_DECREF(f_code);
-					Py_DECREF(co_filename);
 					Py_DECREF(frame);
 					return;
 				}

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp	2011-05-29 10:13:28 UTC (rev 36997)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp	2011-05-29 11:05:52 UTC (rev 36998)
@@ -357,14 +357,7 @@
 	
 	m_function_argc = 0; /* rare cases this could be a function that isnt defined in python, assume zero args */
 	if (PyFunction_Check(m_function)) {
-		PyObject *py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(m_function), "co_argcount");
-		if(py_arg_count) {
-			m_function_argc = PyLong_AsLong(py_arg_count);
-			Py_DECREF(py_arg_count);
-		}
-		else {
-			PyErr_Clear(); /* unlikely to fail but just incase */
-		}
+		m_function_argc ((PyCodeObject *)PyFunction_GET_CODE(m_function))->co_argcount;
 	}
 	
 	if(m_function_argc > 1) {




More information about the Bf-blender-cvs mailing list