[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15581] branches/soc-2008-mxcurioni/source /blender/freestyle: soc-2008-mxcurioni: reimplemented the initialization/ allocation for base classes.

Maxime Curioni maxime.curioni at gmail.com
Tue Jul 15 07:33:13 CEST 2008


Revision: 15581
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15581
Author:   mxcurioni
Date:     2008-07-15 07:33:12 +0200 (Tue, 15 Jul 2008)

Log Message:
-----------
soc-2008-mxcurioni: reimplemented the initialization/allocation for base classes. The Python object type tp_new slot is now set to PyType_GenericNew, instead of the former custom functions. As a note, by default, Python does not set this slot: it is therefore mandatory for the base classes. For children classes, only __init__ is needed.

To make our base classes subclasses, the Py_TPFLAGS_BASETYPE flag was added to the object type tp_flags slot.

Finally, I began to implement CurvePoint, descendant of Interface0D. This commit allowed me to verify that my SWIG replacement method works: interfaces are well taken into account by children. For a test, use the following code:

================================

import Blender
from Blender import Freestyle
from Blender.Freestyle import *

print Interface0D()
print CurvePoint()

================================

The __repr__ method is only implemented in Interface0D:

PyObject * Interface0D___repr__(BPy_Interface0D* self)
{
   return PyString_FromFormat("type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D );}

and the result is of the form:

type: Interface0D - address: 0x18e5ccc0
type: CurvePoint - address: 0x18e473f0

As you can see, the correct getExactTypeName of the class is called. 

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Freestyle.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface1D.cpp

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-07-15 02:06:05 UTC (rev 15580)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/SConscript	2008-07-15 05:33:12 UTC (rev 15581)
@@ -66,6 +66,7 @@
 					prefix + '/BinaryPredicate1D.cpp',
 					prefix + '/Id.cpp',
 					prefix + '/Interface0D.cpp',
+					prefix + '/Interface0D/CurvePoint.cpp',
 					prefix + '/Interface1D.cpp'
 				]
 

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp	2008-07-15 02:06:05 UTC (rev 15580)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate0D.cpp	2008-07-15 05:33:12 UTC (rev 15581)
@@ -10,7 +10,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 /*---------------  Python API function prototypes for BinaryPredicate0D instance  -----------*/
-static PyObject * BinaryPredicate0D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds);
+static int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds);
 static void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D *self);
 static PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D *self);
 
@@ -59,7 +59,7 @@
 	NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
   /*** Flags to define presence of optional/expanded features ***/
-	Py_TPFLAGS_DEFAULT, 		/* long tp_flags; */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 		/* long tp_flags; */
 
 	NULL,                       /*  char *tp_doc;  Documentation string */
   /*** Assigned meaning in release 2.0 ***/
@@ -90,9 +90,9 @@
 	NULL,							/* descrgetfunc tp_descr_get; */
 	NULL,							/* descrsetfunc tp_descr_set; */
 	0,                          	/* long tp_dictoffset; */
-	NULL,                       	/* initproc tp_init; */
+	(initproc)BinaryPredicate0D___init__, /* initproc tp_init; */
 	NULL,							/* allocfunc tp_alloc; */
-	(newfunc)BinaryPredicate0D___new__,		/* newfunc tp_new; */
+	PyType_GenericNew,		/* newfunc tp_new; */
 	
 	/*  Low-level free-memory routine */
 	NULL,                       /* freefunc tp_free;  */
@@ -124,16 +124,10 @@
 
 //------------------------INSTANCE METHODS ----------------------------------
 
-PyObject * BinaryPredicate0D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds)
+int BinaryPredicate0D___init__(BPy_BinaryPredicate0D *self, PyObject *args, PyObject *kwds)
 {
-    BPy_BinaryPredicate0D *self;
-
-    self = (BPy_BinaryPredicate0D *)type->tp_alloc(type, 0);
-    if (self != NULL) {
-        self->bp0D = new BinaryPredicate0D();
-    }
-
-    return (PyObject *)self;
+	self->bp0D = new BinaryPredicate0D();
+	return 0;
 }
 
 void BinaryPredicate0D___dealloc__(BPy_BinaryPredicate0D* self)
@@ -142,6 +136,7 @@
     self->ob_type->tp_free((PyObject*)self);
 }
 
+
 PyObject * BinaryPredicate0D___repr__(BPy_BinaryPredicate0D* self)
 {
     return PyString_FromFormat("type: %s - address: %p", self->bp0D->getName().c_str(), self->bp0D );

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp	2008-07-15 02:06:05 UTC (rev 15580)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/BinaryPredicate1D.cpp	2008-07-15 05:33:12 UTC (rev 15581)
@@ -10,7 +10,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 /*---------------  Python API function prototypes for BinaryPredicate1D instance  -----------*/
-static PyObject * BinaryPredicate1D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds);
+static int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds);
 static void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D *self);
 static PyObject * BinaryPredicate1D___repr__(BPy_BinaryPredicate1D *self);
 
@@ -58,7 +58,7 @@
 	NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
   /*** Flags to define presence of optional/expanded features ***/
-	Py_TPFLAGS_DEFAULT, 		/* long tp_flags; */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 		/* long tp_flags; */
 
 	NULL,                       /*  char *tp_doc;  Documentation string */
   /*** Assigned meaning in release 2.0 ***/
@@ -89,9 +89,9 @@
 	NULL,                       	/* descrgetfunc tp_descr_get; */
 	NULL,                       	/* descrsetfunc tp_descr_set; */
 	0,                          	/* long tp_dictoffset; */
-	NULL,                       	/* initproc tp_init; */
+	(initproc)BinaryPredicate1D___init__,                       	/* initproc tp_init; */
 	NULL,                       	/* allocfunc tp_alloc; */
-	BinaryPredicate1D___new__,		/* newfunc tp_new; */
+	PyType_GenericNew,		/* newfunc tp_new; */
 	
 	/*  Low-level free-memory routine */
 	NULL,                       /* freefunc tp_free;  */
@@ -124,16 +124,10 @@
 
 //------------------------INSTANCE METHODS ----------------------------------
 
-PyObject * BinaryPredicate1D___new__(PyTypeObject *type, PyObject *args, PyObject *kwds)
+int BinaryPredicate1D___init__(BPy_BinaryPredicate1D *self, PyObject *args, PyObject *kwds)
 {
-    BPy_BinaryPredicate1D *self;
-
-    self = (BPy_BinaryPredicate1D *)type->tp_alloc(type, 0);
-    if (self != NULL) {
-        self->bp1D = new BinaryPredicate1D();
-    }
-
-    return (PyObject *)self;
+	self->bp1D = new BinaryPredicate1D();
+	return 0;
 }
 
 void BinaryPredicate1D___dealloc__(BPy_BinaryPredicate1D* self)

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Freestyle.cpp	2008-07-15 02:06:05 UTC (rev 15580)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Freestyle.cpp	2008-07-15 05:33:12 UTC (rev 15581)
@@ -4,8 +4,10 @@
 #include "BinaryPredicate1D.h"
 #include "Id.h"
 #include "Interface0D.h"
+#include "Interface0D/CurvePoint.h"
 #include "Interface1D.h"
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp	2008-07-15 02:06:05 UTC (rev 15580)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Id.cpp	2008-07-15 05:33:12 UTC (rev 15581)
@@ -9,9 +9,8 @@
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 /*---------------  Python API function prototypes for Id instance  -----------*/
-static PyObject * Id___new__(PyTypeObject *type, PyObject *args, PyObject *kwds);
-static void Id___dealloc__(BPy_Id *self);
 static int Id___init__(BPy_Id *self, PyObject *args, PyObject *kwds);
+static void Id___dealloc__(BPy_Id *self);
 static PyObject * Id___repr__(BPy_Id* self);
 
 static PyObject * Id_getFirst( BPy_Id *self );
@@ -69,7 +68,7 @@
 	NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
   /*** Flags to define presence of optional/expanded features ***/
-	Py_TPFLAGS_DEFAULT, 		/* long tp_flags; */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 		/* long tp_flags; */
 
 	NULL,                       /*  char *tp_doc;  Documentation string */
   /*** Assigned meaning in release 2.0 ***/
@@ -102,7 +101,7 @@
 	0,                          	/* long tp_dictoffset; */
 	(initproc)Id___init__,           /* initproc tp_init; */
 	NULL,							/* allocfunc tp_alloc; */
-	Id___new__,						/* newfunc tp_new; */
+	PyType_GenericNew,						/* newfunc tp_new; */
 	
 	/*  Low-level free-memory routine */
 	NULL,                       /* freefunc tp_free;  */
@@ -134,24 +133,6 @@
 
 //------------------------INSTANCE METHODS ----------------------------------
 
-PyObject * Id___new__(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
-    BPy_Id *self;
-
-    self = (BPy_Id *)type->tp_alloc(type, 0);
-    if (self != NULL) {
-        self->id = new Id();
-    }
-
-    return (PyObject *)self;
-}
-
-void Id___dealloc__(BPy_Id* self)
-{
-	delete self->id;
-    self->ob_type->tp_free((PyObject*)self);
-}
-
 int Id___init__(BPy_Id *self, PyObject *args, PyObject *kwds)
 {
     int first = 0, second = 0;
@@ -160,12 +141,17 @@
     if (! PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwlist, &first, &second) )
         return -1;
 
-	self->id->setFirst( first );
-	self->id->setSecond( second );
+	self->id = new Id( first, second );
 
     return 0;
 }
 
+void Id___dealloc__(BPy_Id* self)
+{
+	delete self->id;
+    self->ob_type->tp_free((PyObject*)self);
+}
+
 PyObject * Id___repr__(BPy_Id* self)
 {
     return PyString_FromFormat("[ first: %i, second: %i ](BPy_Id)", self->id->getFirst(), self->id->getSecond() );

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp	2008-07-15 02:06:05 UTC (rev 15580)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/python/Interface0D/CurvePoint.cpp	2008-07-15 05:33:12 UTC (rev 15581)
@@ -1,176 +1,238 @@
-PyObject *CurvePoint_getExactTypeName(PyObject *self , PyObject *args) {
-}
+#include "CurvePoint.h"
 
+#include "../Convert.h"
+#include "../../stroke/Curve.h"
 
-PyObject *CurvePoint_getX(PyObject *self , PyObject *args) {
-}
+#ifdef __cplusplus
+extern "C" {
+#endif
 
+///////////////////////////////////////////////////////////////////////////////////////////
 
-PyObject *CurvePoint_getY(PyObject *self , PyObject *args) {
-}
+/*---------------  Python API function prototypes for CurvePoint instance  -----------*/
+static int CurvePoint___init__(BPy_CurvePoint *self, PyObject *args, PyObject *kwds);
 
+/*----------------------CurvePoint instance definitions ----------------------------*/
+static PyMethodDef BPy_CurvePoint_methods[] = {	
+	{NULL, NULL, 0, NULL}
+};
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list