diff options
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 61 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.c | 38 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_util.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 41 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonSeq.cpp | 32 |
5 files changed, 75 insertions, 99 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 3902a9fd9b5..8ba3b5f8732 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -144,25 +144,64 @@ static int pyrna_prop_compare( BPy_PropertyRNA * a, BPy_PropertyRNA * b ) return (a->prop==b->prop && a->ptr.data==b->ptr.data ) ? 0 : -1; } -/* For some reason python3 needs these :/ */ -static PyObject *pyrna_struct_richcmp(BPy_StructRNA * a, BPy_StructRNA * b, int op) +static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op) { - int cmp_result= -1; /* assume false */ - if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) { - cmp_result= pyrna_struct_compare(a, b); + PyObject *res; + int ok= -1; /* zero is true */ + + if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) + ok= pyrna_struct_compare((BPy_StructRNA *)a, (BPy_StructRNA *)b); + + switch (op) { + case Py_NE: + ok = !ok; /* pass through */ + case Py_EQ: + res = ok ? Py_False : Py_True; + break; + + case Py_LT: + case Py_LE: + case Py_GT: + case Py_GE: + res = Py_NotImplemented; + break; + default: + PyErr_BadArgument(); + return NULL; } - return Py_CmpToRich(op, cmp_result); + Py_INCREF(res); + return res; } -static PyObject *pyrna_prop_richcmp(BPy_PropertyRNA * a, BPy_PropertyRNA * b, int op) +static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op) { - int cmp_result= -1; /* assume false */ - if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) { - cmp_result= pyrna_prop_compare(a, b); + PyObject *res; + int ok= -1; /* zero is true */ + + if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) + ok= pyrna_prop_compare((BPy_PropertyRNA *)a, (BPy_PropertyRNA *)b); + + switch (op) { + case Py_NE: + ok = !ok; /* pass through */ + case Py_EQ: + res = ok ? Py_False : Py_True; + break; + + case Py_LT: + case Py_LE: + case Py_GT: + case Py_GE: + res = Py_NotImplemented; + break; + default: + PyErr_BadArgument(); + return NULL; } - return Py_CmpToRich(op, cmp_result); + Py_INCREF(res); + return res; } /*----------------------repr--------------------------------------------*/ diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index be343843acc..1766be62c83 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -122,44 +122,6 @@ int BPY_flag_from_seq(BPY_flag_def *flagdef, PyObject *seq, int *flag) return 0; /* ok */ } - -/* Copied from pythons 3's Object.c */ -PyObject * -Py_CmpToRich(int op, int cmp) -{ - PyObject *res; - int ok; - - if (PyErr_Occurred()) - return NULL; - switch (op) { - case Py_LT: - ok = cmp < 0; - break; - case Py_LE: - ok = cmp <= 0; - break; - case Py_EQ: - ok = cmp == 0; - break; - case Py_NE: - ok = cmp != 0; - break; - case Py_GT: - ok = cmp > 0; - break; - case Py_GE: - ok = cmp >= 0; - break; - default: - PyErr_BadArgument(); - return NULL; - } - res = ok ? Py_True : Py_False; - Py_INCREF(res); - return res; -} - /* for debugging */ void PyObSpit(char *name, PyObject *var) { fprintf(stderr, "<%s> : ", name); diff --git a/source/blender/python/intern/bpy_util.h b/source/blender/python/intern/bpy_util.h index 0400d595520..83fa7a5b7c4 100644 --- a/source/blender/python/intern/bpy_util.h +++ b/source/blender/python/intern/bpy_util.h @@ -50,8 +50,6 @@ void PyObSpit(char *name, PyObject *var); void PyLineSpit(void); void BPY_getFileAndNum(char **filename, int *lineno); -PyObject *Py_CmpToRich(int op, int cmp); - PyObject *BPY_exception_buffer(void); /* own python like utility function */ diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 667b4cd5d89..9e81bcb3871 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -2016,44 +2016,3 @@ void resetGamePythonPath() { gp_GamePythonPathOrig[0] = '\0'; } - - -/* Copied from pythons 3's Object.c - * also in blenders bpy_uitl.c, mailed the python-dev - * list about enabling something like this again for py3 */ -PyObject * -Py_CmpToRich(int op, int cmp) -{ - PyObject *res; - int ok; - - if (PyErr_Occurred()) - return NULL; - switch (op) { - case Py_LT: - ok = cmp < 0; - break; - case Py_LE: - ok = cmp <= 0; - break; - case Py_EQ: - ok = cmp == 0; - break; - case Py_NE: - ok = cmp != 0; - break; - case Py_GT: - ok = cmp > 0; - break; - case Py_GE: - ok = cmp >= 0; - break; - default: - PyErr_BadArgument(); - return NULL; - } - res = ok ? Py_True : Py_False; - Py_INCREF(res); - return res; -} - diff --git a/source/gameengine/Ketsji/KX_PythonSeq.cpp b/source/gameengine/Ketsji/KX_PythonSeq.cpp index 165a85e2c14..75a7c9b8aeb 100644 --- a/source/gameengine/Ketsji/KX_PythonSeq.cpp +++ b/source/gameengine/Ketsji/KX_PythonSeq.cpp @@ -340,24 +340,42 @@ static PyObject *KX_PythonSeq_nextIter(KX_PythonSeq *self) } -static int KX_PythonSeq_compare( KX_PythonSeq * a, KX_PythonSeq * b ) /* TODO - python3.x wants richcmp */ +static int KX_PythonSeq_compare( KX_PythonSeq * a, KX_PythonSeq * b ) { return ( a->type == b->type && a->base == b->base) ? 0 : -1; } -extern PyObject *Py_CmpToRich(int op, int cmp); - static PyObject *KX_PythonSeq_richcmp(PyObject *a, PyObject *b, int op) { - int cmp_result= -1; /* assume false */ + PyObject *res; + int ok= -1; /* zero is true */ + + if(BPy_KX_PythonSeq_Check(a) && BPy_KX_PythonSeq_Check(b)) + ok= KX_PythonSeq_compare((KX_PythonSeq *)a, (KX_PythonSeq *)b); - if(BPy_KX_PythonSeq_Check(a) && BPy_KX_PythonSeq_Check(b)) { - cmp_result= KX_PythonSeq_compare((KX_PythonSeq *)a, (KX_PythonSeq *)b); + switch (op) { + case Py_NE: + ok = !ok; /* pass through */ + case Py_EQ: + res = ok ? Py_False : Py_True; + break; + + case Py_LT: + case Py_LE: + case Py_GT: + case Py_GE: + res = Py_NotImplemented; + break; + default: + PyErr_BadArgument(); + return NULL; } - return Py_CmpToRich(op, cmp_result); + Py_INCREF(res); + return res; } + /* * repr function * convert to a list and get its string value |