summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/operands/constants.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch/operands/constants.c')
-rw-r--r--plugins/pychrysalide/arch/operands/constants.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/plugins/pychrysalide/arch/operands/constants.c b/plugins/pychrysalide/arch/operands/constants.c
index 464f70d..b9d80e4 100644
--- a/plugins/pychrysalide/arch/operands/constants.c
+++ b/plugins/pychrysalide/arch/operands/constants.c
@@ -25,6 +25,9 @@
#include "constants.h"
+#include <assert.h>
+
+
#include <arch/operands/immediate.h>
@@ -73,3 +76,59 @@ bool define_imm_operand_constants(PyTypeObject *type)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en constante ImmOperandDisplay. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_imm_operand_display(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ unsigned long value; /* Valeur transcrite */
+
+ result = PyObject_IsInstance(arg, (PyObject *)&PyLong_Type);
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to ImmOperandDisplay");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > IOD_COUNT)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for ImmOperandDisplay");
+ result = 0;
+ }
+
+ else
+ *((ImmOperandDisplay *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}