summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/format
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-12-07 20:33:21 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-12-07 20:33:21 (GMT)
commitc0af4cc392a246b05d41b7b7c05bbcd8b0cfb39e (patch)
tree0d645c71c40fc4b625271d0ab1ef8e7ebab04075 /plugins/pychrysalide/format
parenta13d12c758184449bf3305785ef33273802a761c (diff)
Relied on GObject introspection and dynamic gtypes to inherit in Python.
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r--plugins/pychrysalide/format/executable.c46
-rw-r--r--plugins/pychrysalide/format/executable.h3
2 files changed, 49 insertions, 0 deletions
diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c
index 0346ecb..cc0dd33 100644
--- a/plugins/pychrysalide/format/executable.c
+++ b/plugins/pychrysalide/format/executable.c
@@ -25,6 +25,7 @@
#include "executable.h"
+#include <assert.h>
#include <pygobject.h>
@@ -236,6 +237,51 @@ bool ensure_python_executable_format_is_registered(void)
}
+/******************************************************************************
+* *
+* 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 exécutable. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_executable_format(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+
+ result = PyObject_IsInstance(arg, (PyObject *)get_python_executable_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 executable format");
+ break;
+
+ case 1:
+ *((GExeFormat **)dst) = G_EXE_FORMAT(pygobject_get(arg));
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* TRADUCTION D'EMPLACEMENT */
diff --git a/plugins/pychrysalide/format/executable.h b/plugins/pychrysalide/format/executable.h
index d2308e0..f94058d 100644
--- a/plugins/pychrysalide/format/executable.h
+++ b/plugins/pychrysalide/format/executable.h
@@ -43,6 +43,9 @@ PyTypeObject *get_python_executable_format_type(void);
/* Prend en charge l'objet 'pychrysalide.format.ExeFormat'. */
bool ensure_python_executable_format_is_registered(void);
+/* Tente de convertir en format exécutable. */
+int convert_to_executable_format(PyObject *, void *);
+
/* ---------------------------- TRADUCTION D'EMPLACEMENT ---------------------------- */