[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31828] trunk/blender/source/blender/ python/intern: py/rna internals

Campbell Barton ideasman42 at gmail.com
Wed Sep 8 12:43:37 CEST 2010


Revision: 31828
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31828
Author:   campbellbarton
Date:     2010-09-08 12:43:36 +0200 (Wed, 08 Sep 2010)

Log Message:
-----------
py/rna internals
- rna internal deferred properties now store the functions as PyObjects rather then C function pointers
- Property functions now allow the first non keyword argument to be a class.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_props.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/intern/bpy_props.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_props.c	2010-09-08 08:48:40 UTC (rev 31827)
+++ trunk/blender/source/blender/python/intern/bpy_props.c	2010-09-08 10:43:36 UTC (rev 31828)
@@ -77,16 +77,36 @@
 	{PROP_NONE, "NONE", 0, "None", ""},
 	{0, NULL, 0, NULL, NULL}};
 
+/* PyObject's */
+static PyObject *pymeth_BoolProperty = NULL;
+static PyObject *pymeth_BoolVectorProperty = NULL;
+static PyObject *pymeth_IntProperty = NULL;
+static PyObject *pymeth_IntVectorProperty = NULL;
+static PyObject *pymeth_FloatProperty = NULL;
+static PyObject *pymeth_FloatVectorProperty = NULL;
+static PyObject *pymeth_StringProperty = NULL;
+static PyObject *pymeth_EnumProperty = NULL;
+static PyObject *pymeth_PointerProperty = NULL;
+static PyObject *pymeth_CollectionProperty = NULL;
+static PyObject *pymeth_RemoveProperty = NULL;
+
+
 /* operators use this so it can store the args given but defer running
  * it until the operator runs where these values are used to setup the
  * default args for that operator instance */
-static PyObject *bpy_prop_deferred_return(void *func, PyObject *kw)
+static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
 {
 	PyObject *ret = PyTuple_New(2);
-	PyTuple_SET_ITEM(ret, 0, PyCapsule_New(func, NULL, NULL));
-	if(kw==NULL)	kw= PyDict_New();
-	else			Py_INCREF(kw);
+	PyTuple_SET_ITEM(ret, 0, func);
+	Py_INCREF(func);
+
+	if(kw==NULL)
+		kw= PyDict_New();
+	else
+		Py_INCREF(kw);
+
 	PyTuple_SET_ITEM(ret, 1, kw);
+
 	return ret;
 }
 
@@ -95,14 +115,20 @@
 		PyObject *ret; \
 		self= PyTuple_GET_ITEM(args, 0); \
 		args= PyTuple_New(0); \
-		ret= _func(self, args, kw); \
+		ret= BPy_##_func(self, args, kw); \
 		Py_DECREF(args); \
 		return ret; \
 	} \
-	if (PyTuple_GET_SIZE(args) > 0) { \
+	else if (PyTuple_GET_SIZE(args) > 1) { \
 		 PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
 		return NULL; \
 	} \
+	srna= srna_from_self(self, "##_func(...):"); \
+	if(srna==NULL) { \
+		if(PyErr_Occurred()) \
+			return NULL; \
+		return bpy_prop_deferred_return((void *)pymeth_##_func, kw); \
+	} \
 
 
 #if 0
@@ -131,13 +157,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_BoolProperty)
+	BPY_PROPDEF_HEAD(BoolProperty)
 
-	srna= srna_from_self(self, "BoolProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static char *kwlist[] = {"attr", "name", "description", "default", "options", "subtype", NULL};
 		char *id=NULL, *name="", *description="";
 		int def=0;
@@ -173,11 +195,9 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_BoolProperty, kw);
-	}
+
+	Py_RETURN_NONE;
 }
 
 char BPy_BoolVectorProperty_doc[] =
@@ -193,13 +213,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_BoolVectorProperty)
+	BPY_PROPDEF_HEAD(BoolVectorProperty)
 
-	srna= srna_from_self(self, "BoolVectorProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "name", "description", "default", "options", "subtype", "size", NULL};
 		char *id=NULL, *name="", *description="";
 		int def[PYRNA_STACK_ARRAY]={0};
@@ -246,11 +262,9 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_BoolVectorProperty, kw);
-	}
+	
+	Py_RETURN_NONE;
 }
 
 char BPy_IntProperty_doc[] =
@@ -266,13 +280,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_IntProperty)
+	BPY_PROPDEF_HEAD(IntProperty)
 
-	srna= srna_from_self(self, "IntProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", NULL};
 		char *id=NULL, *name="", *description="";
 		int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def=0;
@@ -309,11 +319,8 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_IntProperty, kw);
-	}
+	Py_RETURN_NONE;
 }
 
 char BPy_IntVectorProperty_doc[] =
@@ -329,13 +336,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_IntVectorProperty)
+	BPY_PROPDEF_HEAD(IntVectorProperty)
 
-	srna= srna_from_self(self, "IntVectorProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "size", NULL};
 		char *id=NULL, *name="", *description="";
 		int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def[PYRNA_STACK_ARRAY]={0};
@@ -383,11 +386,8 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_IntVectorProperty, kw);
-	}
+	Py_RETURN_NONE;
 }
 
 
@@ -406,13 +406,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_FloatProperty)
+	BPY_PROPDEF_HEAD(FloatProperty)
 
-	srna= srna_from_self(self, "FloatProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", NULL};
 		char *id=NULL, *name="", *description="";
 		float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
@@ -457,11 +453,8 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_FloatProperty, kw);
-	}
+	Py_RETURN_NONE;
 }
 
 char BPy_FloatVectorProperty_doc[] =
@@ -477,13 +470,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_FloatVectorProperty)
+	BPY_PROPDEF_HEAD(FloatVectorProperty)
 
-	srna= srna_from_self(self, "FloatVectorProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", NULL};
 		char *id=NULL, *name="", *description="";
 		float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f};
@@ -531,11 +520,8 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_FloatVectorProperty, kw);
-	}
+	Py_RETURN_NONE;
 }
 
 char BPy_StringProperty_doc[] =
@@ -551,13 +537,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_StringProperty)
+	BPY_PROPDEF_HEAD(StringProperty)
 
-	srna= srna_from_self(self, "StringProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "name", "description", "default", "maxlen", "options", "subtype", NULL};
 		char *id=NULL, *name="", *description="", *def="";
 		int maxlen=0;
@@ -593,11 +575,8 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_StringProperty, kw);
-	}
+	Py_RETURN_NONE;
 }
 
 static EnumPropertyItem *enum_items_from_py(PyObject *value, const char *def, int *defvalue)
@@ -659,13 +638,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_EnumProperty)
-
-	srna= srna_from_self(self, "EnumProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	BPY_PROPDEF_HEAD(EnumProperty)
+	
+	if(srna) {
 		static const char *kwlist[] = {"attr", "items", "name", "description", "default", "options", NULL};
 		char *id=NULL, *name="", *description="", *def="";
 		int defvalue=0;
@@ -697,12 +672,8 @@
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
 		MEM_freeN(eitems);
-
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */
-		return bpy_prop_deferred_return((void *)BPy_EnumProperty, kw);
-	}
+	Py_RETURN_NONE;
 }
 
 static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
@@ -740,13 +711,9 @@
 {
 	StructRNA *srna;
 
-	BPY_PROPDEF_HEAD(BPy_PointerProperty)
+	BPY_PROPDEF_HEAD(PointerProperty)
 
-	srna= srna_from_self(self, "PointerProperty(...):");
-	if(srna==NULL && PyErr_Occurred()) {
-		return NULL; /* self's type was compatible but error getting the srna */
-	}
-	else if(srna) {
+	if(srna) {
 		static const char *kwlist[] = {"attr", "type", "name", "description", "options", NULL};
 		char *id=NULL, *name="", *description="";
 		PropertyRNA *prop;
@@ -776,12 +743,8 @@
 			if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 		}
 		RNA_def_property_duplicate_pointers(srna, prop);
-		Py_RETURN_NONE;
 	}
-	else { /* operators defer running this function */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list