summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-01-15 19:19:40 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-01-15 19:19:40 (GMT)
commitd75fe33356f22c1c41925bffe179a55b9cea6cd1 (patch)
tree37b9a32d3a2b688326791392b338e025bb4c84f3 /plugins/pychrysalide/format
parent55935908085677432f746f8378e600f4fd8234b0 (diff)
Reorganized the architecture operands.
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r--plugins/pychrysalide/format/format.c45
-rw-r--r--plugins/pychrysalide/format/format.h3
2 files changed, 48 insertions, 0 deletions
diff --git a/plugins/pychrysalide/format/format.c b/plugins/pychrysalide/format/format.c
index 8afbca9..409e085 100644
--- a/plugins/pychrysalide/format/format.c
+++ b/plugins/pychrysalide/format/format.c
@@ -796,3 +796,48 @@ bool ensure_python_binary_format_is_registered(void)
return true;
}
+
+
+/******************************************************************************
+* *
+* 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 format de binaire. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_binary_format(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_binary_format_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 binary format");
+ break;
+
+ case 1:
+ *((GBinFormat **)dst) = G_BIN_FORMAT(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/format/format.h b/plugins/pychrysalide/format/format.h
index 6423821..c7d5ee6 100644
--- a/plugins/pychrysalide/format/format.h
+++ b/plugins/pychrysalide/format/format.h
@@ -51,6 +51,9 @@ PyTypeObject *get_python_binary_format_type(void);
/* Prend en charge l'objet 'pychrysalide.format.BinFormat'. */
bool ensure_python_binary_format_is_registered(void);
+/* Tente de convertir en format de binaire. */
+int convert_to_binary_format(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_FORMAT_H */