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:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-07-26 20:15:28 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2009-07-26 20:15:28 +0400
commit730fb1021c8b189229625866dac0f6e83db6418c (patch)
tree7985373b62cea17b3247a4e80842fbd372181058 /source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
parent78ce17fce88c23ba2c32b561bd9cc398a60a8278 (diff)
Made predicate and function types callable in the sense that
callable(I, T) returns True when I is an object of a type T or of a subtype of T. Also implemented a measure to avoid an infinite loop when user-defined predicate and function classes do not properly overload the __call__ method (including the cases of directly instantiating the base classes such as UnaryPredicate0D and BinaryPredicate1D).
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
index 8712b374209..7bf4cfbbc6d 100644
--- a/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
+++ b/source/blender/freestyle/intern/python/BPy_UnaryPredicate1D.cpp
@@ -25,12 +25,11 @@ static void UnaryPredicate1D___dealloc__(BPy_UnaryPredicate1D *self);
static PyObject * UnaryPredicate1D___repr__(BPy_UnaryPredicate1D *self);
static PyObject * UnaryPredicate1D_getName( BPy_UnaryPredicate1D *self, PyObject *args);
-static PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args);
+static PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds);
/*----------------------UnaryPredicate1D instance definitions ----------------------------*/
static PyMethodDef BPy_UnaryPredicate1D_methods[] = {
{"getName", ( PyCFunction ) UnaryPredicate1D_getName, METH_NOARGS, ""},
- {"__call__", ( PyCFunction ) UnaryPredicate1D___call__, METH_VARARGS, "" },
{NULL, NULL, 0, NULL}
};
@@ -60,7 +59,7 @@ PyTypeObject UnaryPredicate1D_Type = {
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
- NULL, /* ternaryfunc tp_call; */
+ (ternaryfunc)UnaryPredicate1D___call__, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
@@ -203,10 +202,14 @@ PyObject * UnaryPredicate1D_getName( BPy_UnaryPredicate1D *self, PyObject *args)
return PyString_FromString( self->up1D->getName().c_str() );
}
-PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args)
+static PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args, PyObject *kwds)
{
PyObject *py_if1D;
+ if( kwds != NULL ) {
+ PyErr_SetString(PyExc_TypeError, "keyword argument(s) not supported");
+ return NULL;
+ }
if( !PyArg_ParseTuple(args, "O!", &Interface1D_Type, &py_if1D) )
return NULL;
@@ -217,6 +220,10 @@ PyObject * UnaryPredicate1D___call__( BPy_UnaryPredicate1D *self, PyObject *args
PyErr_SetString(PyExc_RuntimeError, msg.c_str());
return NULL;
}
+ if( typeid(*(self->up1D)) == typeid(UnaryPredicate1D) ) {
+ PyErr_SetString(PyExc_TypeError, "__call__ method must be overloaded");
+ return NULL;
+ }
if( self->up1D->operator()(*if1D) < 0 ) {
if (!PyErr_Occurred()) {
string msg(self->up1D->getName() + " __call__ method failed");