summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format/constants.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/format/constants.c')
-rw-r--r--plugins/pychrysalide/format/constants.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/pychrysalide/format/constants.c b/plugins/pychrysalide/format/constants.c
index 9669b46..df40479 100644
--- a/plugins/pychrysalide/format/constants.c
+++ b/plugins/pychrysalide/format/constants.c
@@ -89,6 +89,62 @@ bool define_binary_format_constants(PyTypeObject *type)
/******************************************************************************
* *
+* 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 BinaryFormatError. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_binary_format_error(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 BinaryFormatError");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if ((value & (BFE_SPECIFICATION | BFE_STRUCTURE)) != 0)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for BinaryFormatError");
+ result = 0;
+ }
+
+ else
+ *((BinaryFormatError *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : type = type dont le dictionnaire est à compléter. *
* *
* Description : Définit les constantes pour les symboles binaires. *