diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-05-12 21:15:45 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-05-12 21:17:31 (GMT) |
commit | 90d1fa65a1d13128a66117095a44224e8c9de656 (patch) | |
tree | 024674c4d199018d93f0064a3ec1ddd8f3bd4321 /plugins/pychrysalide/glibext/constants.c | |
parent | d2861533cc53fbcc217048bafebf34b1f70ba3aa (diff) |
Described the Python API for binary portions.
Diffstat (limited to 'plugins/pychrysalide/glibext/constants.c')
-rw-r--r-- | plugins/pychrysalide/glibext/constants.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/plugins/pychrysalide/glibext/constants.c b/plugins/pychrysalide/glibext/constants.c index 823465a..680feaf 100644 --- a/plugins/pychrysalide/glibext/constants.c +++ b/plugins/pychrysalide/glibext/constants.c @@ -26,6 +26,7 @@ #include <glibext/linesegment.h> +#include <glibext/gbinportion.h> #include <glibext/gbufferline.h> @@ -37,6 +38,102 @@ * * * Paramètres : type = type dont le dictionnaire est à compléter. * * * +* Description : Définit les constantes relatives aux portions de binaires. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool define_binary_portion_constants(PyTypeObject *type) +{ + bool result; /* Bilan à retourner */ + PyObject *values; /* Groupe de valeurs à établir */ + + values = PyDict_New(); + + result = add_const_to_group(values, "NONE", PAC_NONE); + if (result) result = add_const_to_group(values, "READ", PAC_READ); + if (result) result = add_const_to_group(values, "WRITE", PAC_WRITE); + if (result) result = add_const_to_group(values, "EXEC", PAC_EXEC); + + if (!result) + { + Py_DECREF(values); + goto exit; + } + + result = attach_constants_group_to_type(type, false, "PortionAccessRights", values, + "Access rights for binary portions."); + + exit: + + 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 PortionAccessRights. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_portion_access_rights(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + unsigned long value; /* Valeur récupérée */ + + 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 PortionAccessRights"); + break; + + case 1: + value = PyLong_AsUnsignedLong(arg); + + if ((value & ~PAC_ALL) != 0) + { + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to PortionAccessRights"); + result = 0; + } + + else + *((PortionAccessRights *)dst) = value; + + break; + + default: + assert(false); + break; + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type dont le dictionnaire est à compléter. * +* * * Description : Définit les constantes relatives aux segments de ligne. * * * * Retour : true en cas de succès de l'opération, false sinon. * |