access pythons code object directly rather than attribute access.
This commit is contained in:
@@ -34,9 +34,6 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "compile.h" /* for the PyCodeObject */
|
|
||||||
#include "eval.h" /* for PyEval_EvalCode */
|
|
||||||
|
|
||||||
#include "bpy_internal_import.h"
|
#include "bpy_internal_import.h"
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
@@ -51,7 +48,6 @@
|
|||||||
/* UNUSED */
|
/* UNUSED */
|
||||||
#include "BKE_text.h" /* txt_to_buf */
|
#include "BKE_text.h" /* txt_to_buf */
|
||||||
#include "BKE_main.h"
|
#include "BKE_main.h"
|
||||||
#include "BKE_global.h" /* grr, only for G.main->name */
|
|
||||||
|
|
||||||
static Main *bpy_import_main= NULL;
|
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 */
|
/* 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)
|
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)
|
PyObject *bpy_text_import(Text *text)
|
||||||
|
@@ -5882,7 +5882,6 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
|
|||||||
PyObject *py_class= (PyObject*)py_data;
|
PyObject *py_class= (PyObject*)py_data;
|
||||||
PyObject *base_class= RNA_struct_py_type_get(srna);
|
PyObject *base_class= RNA_struct_py_type_get(srna);
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
PyObject *py_arg_count;
|
|
||||||
int i, flag, arg_count, func_arg_count;
|
int i, flag, arg_count, func_arg_count;
|
||||||
const char *py_class_name= ((PyTypeObject *)py_class)->tp_name; // __name__
|
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);
|
func_arg_count= rna_function_arg_count(func);
|
||||||
|
|
||||||
if (func_arg_count >= 0) { /* -1 if we dont care*/
|
if (func_arg_count >= 0) { /* -1 if we dont care*/
|
||||||
py_arg_count= PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
|
arg_count= ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount;
|
||||||
arg_count= PyLong_AsLong(py_arg_count);
|
|
||||||
Py_DECREF(py_arg_count);
|
|
||||||
|
|
||||||
/* note, the number of args we check for and the number of args we give to
|
/* 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*/
|
* @classmethods are different (quirk of python), this is why rna_function_arg_count() doesn't return the value -1*/
|
||||||
|
@@ -1198,14 +1198,13 @@ void PyDebugLine()
|
|||||||
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
|
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
|
||||||
f_code= PyObject_GetAttrString(frame, "f_code");
|
f_code= PyObject_GetAttrString(frame, "f_code");
|
||||||
if (f_lineno && 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) {
|
if (co_filename) {
|
||||||
|
|
||||||
printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno));
|
printf("\t%s:%d\n", _PyUnicode_AsString(co_filename), (int)PyLong_AsSsize_t(f_lineno));
|
||||||
|
|
||||||
Py_DECREF(f_lineno);
|
Py_DECREF(f_lineno);
|
||||||
Py_DECREF(f_code);
|
Py_DECREF(f_code);
|
||||||
Py_DECREF(co_filename);
|
|
||||||
Py_DECREF(frame);
|
Py_DECREF(frame);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -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 */
|
m_function_argc = 0; /* rare cases this could be a function that isnt defined in python, assume zero args */
|
||||||
if (PyFunction_Check(m_function)) {
|
if (PyFunction_Check(m_function)) {
|
||||||
PyObject *py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(m_function), "co_argcount");
|
m_function_argc= ((PyCodeObject *)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 */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_function_argc > 1) {
|
if(m_function_argc > 1) {
|
||||||
|
Reference in New Issue
Block a user