+/* Helper for valpy_richcompare. Implements comparison operations for
+ value objects. Returns true/false on success. Returns -1 with a
+ Python exception set if a Python error is detected. Throws a GDB
+ exception on other errors (memory error, etc.). */
+
+static int
+valpy_richcompare_throw (PyObject *self, PyObject *other, int op)
+{
+ int result;
+ struct value *value_other;
+ struct value *value_self;
+ struct value *mark = value_mark ();
+ struct cleanup *cleanup;
+
+ value_other = convert_value_from_python (other);
+ if (value_other == NULL)
+ return -1;
+
+ cleanup = make_cleanup_value_free_to_mark (mark);
+
+ value_self = ((value_object *) self)->value;
+
+ switch (op)
+ {
+ case Py_LT:
+ result = value_less (value_self, value_other);
+ break;
+ case Py_LE:
+ result = value_less (value_self, value_other)
+ || value_equal (value_self, value_other);
+ break;
+ case Py_EQ:
+ result = value_equal (value_self, value_other);
+ break;
+ case Py_NE:
+ result = !value_equal (value_self, value_other);
+ break;
+ case Py_GT:
+ result = value_less (value_other, value_self);
+ break;
+ case Py_GE:
+ result = (value_less (value_other, value_self)
+ || value_equal (value_self, value_other));
+ break;
+ default:
+ /* Can't happen. */
+ PyErr_SetString (PyExc_NotImplementedError,
+ _("Invalid operation on gdb.Value."));
+ result = -1;
+ break;
+ }
+
+ do_cleanups (cleanup);
+ return result;
+}
+
+