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>2009-04-09 17:20:48 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-09 17:20:48 +0400
commit9196d88242af69abc3f4c44c1060f9c25ed34611 (patch)
treea8ca3cdaa4df718a13c669739b050161f6c8d257 /source/blender/python/intern
parent84f3e7d94d8ebb9d8daac9c1d7c0e9239c686dfc (diff)
Experimental removal of pyrna_func_Type (ifdef'd out)
Since adding a new type gives quite a lot of extra boiler plate functions. Return PyCFunction's main disadvantage is it does not have a uniqie name when you print it.
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r--source/blender/python/intern/bpy_rna.c69
-rw-r--r--source/blender/python/intern/bpy_rna.h11
2 files changed, 63 insertions, 17 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index e0202076c4f..4ba7214cf5c 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -45,12 +45,12 @@ static int pyrna_prop_compare( BPy_PropertyRNA * a, BPy_PropertyRNA * b )
{
return (a->prop==b->prop && a->ptr.data==b->ptr.data ) ? 0 : -1;
}
-
+#ifdef USE_RNA_FUNC
static int pyrna_func_compare( BPy_FunctionRNA * a, BPy_FunctionRNA * b )
{
return (a->func==b->func && a->ptr.data==b->ptr.data ) ? 0 : -1;
}
-
+#endif
/* For some reason python3 needs these :/ */
static PyObject *pyrna_struct_richcmp(BPy_StructRNA * a, BPy_StructRNA * b, int op)
@@ -72,7 +72,7 @@ static PyObject *pyrna_prop_richcmp(BPy_PropertyRNA * a, BPy_PropertyRNA * b, in
return Py_CmpToRich(op, cmp_result);
}
-
+#ifdef USE_RNA_FUNC
static PyObject *pyrna_func_richcmp(BPy_FunctionRNA * a, BPy_FunctionRNA * b, int op)
{
int cmp_result= -1; /* assume false */
@@ -82,6 +82,7 @@ static PyObject *pyrna_func_richcmp(BPy_FunctionRNA * a, BPy_FunctionRNA * b, in
return Py_CmpToRich(op, cmp_result);
}
+#endif
/*----------------------repr--------------------------------------------*/
static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
@@ -120,12 +121,12 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self )
return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop));
}
-
+#ifdef USE_RNA_FUNC
static PyObject *pyrna_func_repr( BPy_FunctionRNA * self )
{
return PyUnicode_FromFormat( "[BPy_FunctionRNA \"%s\"]", RNA_function_identifier(&self->ptr, self->func));
}
-
+#endif
static long pyrna_struct_hash( BPy_StructRNA * self )
{
return (long)self->ptr.data;
@@ -144,7 +145,7 @@ static void pyrna_struct_dealloc( BPy_StructRNA * self )
Py_TYPE(self)->tp_free(self);
return;
}
-
+#ifdef USE_RNA_FUNC
/* use our own dealloc so we can free a property if we use one */
static void pyrna_function_dealloc( BPy_FunctionRNA * self )
{
@@ -153,7 +154,7 @@ static void pyrna_function_dealloc( BPy_FunctionRNA * self )
return;
}
-
+#endif
static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
{
const EnumPropertyItem *item;
@@ -231,9 +232,28 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
return ret;
}
+#ifndef USE_RNA_FUNC
+static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw);
+#endif
+
PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func)
-{
+{
+#ifdef USE_RNA_FUNC
return pyrna_func_CreatePyObject(ptr, func);
+#else
+ static PyMethodDef func_meth = {"<generic rna function>", (PyCFunction)pyrna_func_call, METH_VARARGS|METH_KEYWORDS, "python rna function"};
+ PyObject *self= PyTuple_New(2);
+ PyObject *ret;
+ PyTuple_SET_ITEM(self, 0, pyrna_struct_CreatePyObject(ptr));
+ PyTuple_SET_ITEM(self, 1, PyCObject_FromVoidPtr((void *)func, NULL));
+
+ ret= PyCFunction_New(&func_meth, self);
+ Py_DECREF(self);
+
+ return ret;
+#endif
+
+
}
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
@@ -953,6 +973,7 @@ static PyObject * pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *k
}
}
+#ifdef USE_RNA_FUNC
/* only needed for subtyping, so a new class gets a valid BPy_FunctionRNA
* todo - also accept useful args */
static PyObject * pyrna_func_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
@@ -971,6 +992,7 @@ static PyObject * pyrna_func_new(PyTypeObject *type, PyObject *args, PyObject *k
return (PyObject *)ret;
}
}
+#endif
int pyrna_py_to_param(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value)
{
@@ -1260,8 +1282,19 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
return ret;
}
+#ifdef USE_RNA_FUNC
static PyObject * pyrna_func_call(BPy_FunctionRNA * self, PyObject *args, PyObject *kw)
{
+ PointerRNA *self_ptr= &self->ptr;
+ FunctionRNA *self_func= self->func;
+#else
+static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
+{
+ PointerRNA *self_ptr= &(((BPy_StructRNA *)PyTuple_GET_ITEM(self, 0))->ptr);
+ FunctionRNA *self_func= PyCObject_AsVoidPtr(PyTuple_GET_ITEM(self, 1));
+
+#endif
+
PointerRNA funcptr;
ParameterList *parms;
ParameterIterator iter;
@@ -1272,12 +1305,12 @@ static PyObject * pyrna_func_call(BPy_FunctionRNA * self, PyObject *args, PyObje
void *retdata= NULL;
/* setup */
- RNA_pointer_create(NULL, &RNA_Function, self->func, &funcptr);
+ RNA_pointer_create(NULL, &RNA_Function, self_func, &funcptr);
- pret= RNA_function_return(&self->ptr, self->func);
+ pret= RNA_function_return(self_ptr, self_func);
tlen= PyTuple_GET_SIZE(args);
- parms= RNA_parameter_list_create(&self->ptr, self->func);
+ parms= RNA_parameter_list_create(self_ptr, self_func);
RNA_parameter_list_begin(parms, &iter);
/* parse function parameters */
@@ -1303,8 +1336,8 @@ static PyObject * pyrna_func_call(BPy_FunctionRNA * self, PyObject *args, PyObje
if (flag & PARAM_OPTIONAL)
continue; */
- tid= RNA_struct_identifier(&self->ptr);
- fid= RNA_function_identifier(&self->ptr, self->func);
+ tid= RNA_struct_identifier(self_ptr);
+ fid= RNA_function_identifier(self_ptr, self_func);
PyErr_Format(PyExc_AttributeError, "%s.%s(): required parameter \"%s\" not specified", tid, fid, pid);
err= -1;
@@ -1320,7 +1353,7 @@ static PyObject * pyrna_func_call(BPy_FunctionRNA * self, PyObject *args, PyObje
ret= NULL;
if (err==0) {
/* call function */
- RNA_function_call(&self->ptr, self->func, parms);
+ RNA_function_call(self_ptr, self_func, parms);
/* return value */
if(pret)
@@ -1511,6 +1544,7 @@ PyTypeObject pyrna_prop_Type = {
NULL
};
+#ifdef USE_RNA_FUNC
/*-----------------------BPy_FunctionRNA method def------------------------------*/
PyTypeObject pyrna_func_Type = {
#if (PY_VERSION_HEX >= 0x02060000)
@@ -1596,6 +1630,7 @@ PyTypeObject pyrna_func_Type = {
NULL, /* PyObject *tp_weaklist; */
NULL
};
+#endif
PyObject* pyrna_struct_Subtype(PointerRNA *ptr)
{
@@ -1718,6 +1753,7 @@ PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop )
return ( PyObject * ) pyrna;
}
+#ifdef USE_RNA_FUNC
PyObject *pyrna_func_CreatePyObject( PointerRNA *ptr, FunctionRNA *func )
{
BPy_FunctionRNA *pyrna;
@@ -1736,7 +1772,7 @@ PyObject *pyrna_func_CreatePyObject( PointerRNA *ptr, FunctionRNA *func )
return ( PyObject * ) pyrna;
}
-
+#endif
PyObject *BPY_rna_module( void )
{
@@ -1752,9 +1788,10 @@ PyObject *BPY_rna_module( void )
if( PyType_Ready( &pyrna_prop_Type ) < 0 )
return NULL;
+#ifdef USE_RNA_FUNC
if( PyType_Ready( &pyrna_func_Type ) < 0 )
return NULL;
-
+#endif
/* for now, return the base RNA type rather then a real module */
RNA_main_pointer_create(G.main, &ptr);
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 059eedb4020..f2ea7efb354 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -34,12 +34,16 @@ extern PyTypeObject pyrna_struct_Type;
extern PyTypeObject pyrna_prop_Type;
extern PyTypeObject pyrna_func_Type;
+/* #define USE_RNA_FUNC 1 */
+
#define BPy_StructRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_struct_Type))
#define BPy_StructRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_struct_Type)
#define BPy_PropertyRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_prop_Type))
#define BPy_PropertyRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_prop_Type)
+#ifdef USE_RNA_FUNC
#define BPy_FunctionRNA_Check(v) (PyObject_TypeCheck(v, &pyrna_func_Type))
#define BPy_FunctionRNA_CheckExact(v) (Py_TYPE(v) == &pyrna_func_Type)
+#endif
typedef struct {
void * _a;
@@ -60,11 +64,13 @@ typedef struct {
PropertyRNA *prop;
} BPy_PropertyRNA;
+#ifdef USE_RNA_FUNC
typedef struct {
PyObject_HEAD /* required python macro */
PointerRNA ptr;
FunctionRNA *func;
} BPy_FunctionRNA;
+#endif
/* cheap trick */
#define BPy_BaseTypeRNA BPy_PropertyRNA
@@ -75,13 +81,16 @@ PyObject *BPY_rna_types( void );
PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
+#ifdef USE_RNA_FUNC
PyObject *pyrna_func_CreatePyObject( PointerRNA *ptr, FunctionRNA *func );
+#endif
/* operators also need this to set args */
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, PyObject *value);
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
-
+#ifdef USE_RNA_FUNC
PyObject *pyrna_func_to_py( PointerRNA *ptr, FunctionRNA *func );
+#endif
/* functions for setting up new props - experemental */
PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw);