summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-12-08 20:47:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-12-08 20:47:09 (GMT)
commitcf11fcf862b98ef57935bcfccd6f2f6ae3f925f6 (patch)
treed7ae9d965b8eea03adfaf7a4d42907aae683d0f9 /plugins/pychrysa/arch
parent48ac5e6e8fe50c1ff4b9e77440a6365f8b01021f (diff)
Improved the way vmpa_t types are compared.
Diffstat (limited to 'plugins/pychrysa/arch')
-rw-r--r--plugins/pychrysa/arch/vmpa.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/plugins/pychrysa/arch/vmpa.c b/plugins/pychrysa/arch/vmpa.c
index af1557d..aaaede8 100644
--- a/plugins/pychrysa/arch/vmpa.c
+++ b/plugins/pychrysa/arch/vmpa.c
@@ -25,9 +25,13 @@
#include "vmpa.h"
+#include <assert.h>
#include <string.h>
+#include <i18n.h>
+
+
#include "../helpers.h"
@@ -208,23 +212,43 @@ static PyObject *py_vmpa_richcompare(PyObject *a, PyObject *b, int op)
PyObject *result; /* Bilan à retourner */
vmpa2t *addr_a; /* Première adresse à traiter */
vmpa2t addr_b; /* Seconde adresse à traiter */
+ int comp; /* Résultat d'une comparaison */
addr_a = &((py_vmpa_t *)a)->addr;
if (!convert_pyobj_to_vmpa(b, &addr_b))
return NULL;
+ comp = cmp_vmpa(addr_a, &addr_b);
+
switch (op)
{
+ case Py_LT:
+ result = comp < 0 ? Py_True : Py_False;
+ break;
+
+ case Py_LE:
+ result = comp <= 0 ? Py_True : Py_False;
+ break;
+
case Py_EQ:
- result = are_equal(addr_a, &addr_b) ? Py_True : Py_False;
+ result = comp == 0 ? Py_True : Py_False;
break;
case Py_NE:
- result = are_equal(addr_a, &addr_b) ? Py_False : Py_True;
+ result = comp != 0 ? Py_True : Py_False;
+ break;
+
+ case Py_GT:
+ result = comp > 0 ? Py_True : Py_False;
+ break;
+
+ case Py_GE:
+ result = comp >= 0 ? Py_True : Py_False;
break;
default:
+ assert(false);
result = Py_NotImplemented;
break;
@@ -436,7 +460,10 @@ static bool convert_pyobj_to_vmpa(PyObject *obj, vmpa2t *addr)
value = PyLong_AsLongLongAndOverflow(obj, &overflow);
if (value == -1 && (overflow == 1 || PyErr_Occurred()))
+ {
PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, _("Unable to cast object as VMPA."));
+ }
else
{