diff options
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r-- | plugins/pychrysalide/format/executable.c | 46 | ||||
-rw-r--r-- | plugins/pychrysalide/format/executable.h | 3 |
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 ---------------------------- */ |