[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19621] branches/blender2.5/blender/source /blender/python/intern: Experimental removal of pyrna_func_Type (ifdef' d out)

Campbell Barton ideasman42 at gmail.com
Thu Apr 9 15:20:50 CEST 2009


Revision: 19621
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19621
Author:   campbellbarton
Date:     2009-04-09 15:20:48 +0200 (Thu, 09 Apr 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.h

Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c	2009-04-09 12:53:56 UTC (rev 19620)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c	2009-04-09 13:20:48 UTC (rev 19621)
@@ -45,13 +45,13 @@
 {
 	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 @@
 
 	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 @@
 
 	return Py_CmpToRich(op, cmp_result);
 }
+#endif
 
 /*----------------------repr--------------------------------------------*/
 static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
@@ -120,12 +121,12 @@
 
 	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 @@
 	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 @@
 
 	return;
 }
-
+#endif
 static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
 {
 	const EnumPropertyItem *item;
@@ -231,9 +232,28 @@
 	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 @@
 	}
 }
 
+#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 @@
 		return (PyObject *)ret;
 	}
 }
+#endif
 
 int pyrna_py_to_param(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value)
 {
@@ -1260,8 +1282,19 @@
 	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 @@
 	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 @@
 			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 @@
 	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 @@
 	NULL
 };
 
+#ifdef USE_RNA_FUNC
 /*-----------------------BPy_FunctionRNA method def------------------------------*/
 PyTypeObject pyrna_func_Type = {
 #if (PY_VERSION_HEX >= 0x02060000)
@@ -1596,6 +1630,7 @@
 	NULL,                       /* PyObject *tp_weaklist; */
 	NULL
 };
+#endif
 
 PyObject* pyrna_struct_Subtype(PointerRNA *ptr)
 {
@@ -1718,6 +1753,7 @@
 	return ( PyObject * ) pyrna;
 }
 
+#ifdef USE_RNA_FUNC
 PyObject *pyrna_func_CreatePyObject( PointerRNA *ptr, FunctionRNA *func )
 {
 	BPy_FunctionRNA *pyrna;
@@ -1736,8 +1772,8 @@
 
 	return ( PyObject * ) pyrna;
 }
+#endif
 
-
 PyObject *BPY_rna_module( void )
 {
 	PointerRNA ptr;
@@ -1752,9 +1788,10 @@
 	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);
 	

Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.h
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.h	2009-04-09 12:53:56 UTC (rev 19620)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.h	2009-04-09 13:20:48 UTC (rev 19621)
@@ -34,12 +34,16 @@
 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 @@
 	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 *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);





More information about the Bf-blender-cvs mailing list