access pythons code object directly rather than attribute access.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 29 May 2011 11:05:52 +0000 (11:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 29 May 2011 11:05:52 +0000 (11:05 +0000)
source/blender/python/generic/bpy_internal_import.c
source/blender/python/intern/bpy_rna.c
source/gameengine/Expressions/PyObjectPlus.cpp
source/gameengine/GameLogic/SCA_PythonController.cpp

index 96fe13bf6fc149a34677c7a61b9b724f74b5041d..cb145cc453b097101aea3e305233bf6295157af8 100644 (file)
@@ -34,9 +34,6 @@
 #include <Python.h>
 #include <stddef.h>
 
-#include "compile.h"   /* for the PyCodeObject */
-#include "eval.h"              /* for PyEval_EvalCode */
-
 #include "bpy_internal_import.h"
 
 #include "MEM_guardedalloc.h"
@@ -51,7 +48,6 @@
  /* UNUSED */  
 #include "BKE_text.h" /* txt_to_buf */ 
 #include "BKE_main.h"
-#include "BKE_global.h" /* grr, only for G.main->name */
 
 static Main *bpy_import_main= NULL;
 
@@ -97,7 +93,7 @@ void bpy_import_main_set(struct Main *maggie)
 /* returns a dummy filename for a textblock so we can tell what file a text block comes from */
 void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
 {
-       BLI_snprintf(fn, fn_len, "%s%c%s", text->id.lib ? text->id.lib->filepath : G.main->name, SEP, text->id.name+2);
+       BLI_snprintf(fn, fn_len, "%s%c%s", text->id.lib ? text->id.lib->filepath : bpy_import_main->name, SEP, text->id.name+2);
 }
 
 PyObject *bpy_text_import(Text *text)
index 8b361de17fae90035f5ac3638530c492340eb11c..72d391fed32aca725c9ca65170038fd623d4a32a 100644 (file)
@@ -5882,7 +5882,6 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
        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 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
                        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*/
index 65c20cad518da406b3867e1626ad889e2dd69e14..10906cdae02a8dd7e51db4467532a51539741ebf 100644 (file)
@@ -1198,14 +1198,13 @@ void PyDebugLine()
                        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;
                                }
index d0c1155de96f25891ca4b2690d32677d4355756a..19ddce137575549c64f68518a2a4a39d3097a20b 100644 (file)
@@ -357,14 +357,7 @@ bool SCA_PythonController::Import()
        
        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) {