From 85bd3c6c415d42c0722298cf8e4542c94a87d7f1 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 16 May 2020 20:41:37 +0200 Subject: Added a way to get all registered architectures. --- plugins/pychrysalide/core/processors.c | 50 ++++++++++++++++++++++++++++++++++ src/core/processors.c | 32 ++++++++++++++++++++++ src/core/processors.h | 4 +++ 3 files changed, 86 insertions(+) diff --git a/plugins/pychrysalide/core/processors.c b/plugins/pychrysalide/core/processors.c index 262cc11..b1f85bc 100644 --- a/plugins/pychrysalide/core/processors.c +++ b/plugins/pychrysalide/core/processors.c @@ -25,6 +25,7 @@ #include "processors.h" +#include #include @@ -43,6 +44,9 @@ /* Enregistre un processeur pour une architecture donnée. */ static PyObject *py_processors_register_processor(PyObject *, PyObject *); +/* Fournit la liste des processeurs d'architecture disponibles. */ +static PyObject *py_processors_get_all_processor_keys(PyObject *, PyObject *); + /* Fournit le processeur d'architecture correspondant à un nom. */ static PyObject *py_processors_get_processor_for_key(PyObject *, PyObject *); @@ -131,6 +135,51 @@ static PyObject *py_processors_register_processor(PyObject *self, PyObject *args * Paramètres : self = objet Python concerné par l'appel. * * args = arguments fournis à l'appel. * * * +* Description : Fournit la liste des processeurs d'architecture disponibles. * +* * +* Retour : Liste de nom technique des processeurs enregistrés. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_processors_get_all_processor_keys(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + size_t count; /* Taille de la liste retournée*/ + char **keys; /* Noms techniques à traiter */ + size_t i; /* Boucle de parcours */ + +#define PROCESSORS_GET_ALL_PROCESSOR_KEYS_METHOD PYTHON_METHOD_DEF \ +( \ + get_all_processor_keys, "", \ + METH_NOARGS, py_processors, \ + "Provide the list of keys from all registered architecture processors." \ +) + + keys = get_all_processor_keys(&count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + PyTuple_SetItem(result, i, PyUnicode_FromString(keys[i])); + free(keys[i]); + } + + if (keys != NULL) + free(keys); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* args = arguments fournis à l'appel. * +* * * Description : Fournit le processeur d'architecture correspondant à un nom. * * * * Retour : Processeur d'architecture trouvé. * @@ -196,6 +245,7 @@ bool populate_core_module_with_processors(void) static PyMethodDef py_processors_methods[] = { PROCESSORS_REGISTER_PROCESSOR_METHOD, + PROCESSORS_GET_ALL_PROCESSOR_KEYS_METHOD, PROCESSORS_GET_PROCESSOR_FOR_KEY_METHOD, { NULL } }; diff --git a/src/core/processors.c b/src/core/processors.c index 48e2cd2..81f7494 100644 --- a/src/core/processors.c +++ b/src/core/processors.c @@ -171,6 +171,38 @@ void unload_processors_definitions(void) /****************************************************************************** * * +* Paramètres : count = taille de la liste retournée. [OUT] * +* * +* Description : Fournit la liste des processeurs d'architecture disponibles. * +* * +* Retour : Liste de nom technique des processeurs enregistrés. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char **get_all_processor_keys(size_t *count) +{ + char **result; /* Liste à retourner */ + size_t i; /* Boucle de parcours */ + + G_LOCK(_pdef_access); + + result = malloc(_processors_definitions_count * sizeof(char *)); + *count = _processors_definitions_count; + + for (i = 0; i < _processors_definitions_count; i++) + result[i] = strdup(_processors_definitions[i].key); + + G_UNLOCK(_pdef_access); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : key = nom technique du processeur recherché. * * * * Description : Retrouve l'enregistrement correspondant à une architecture. * diff --git a/src/core/processors.h b/src/core/processors.h index d07ceb0..f95c6c2 100644 --- a/src/core/processors.h +++ b/src/core/processors.h @@ -32,6 +32,7 @@ #include "../arch/processor.h" + /* Assure l'enregistrement de types pour les caches à charger. */ void register_arch_gtypes(void); @@ -41,6 +42,9 @@ bool register_processor_type(GType); /* Décharge toutes les définitions de processeurs. */ void unload_processors_definitions(void); +/* Fournit la liste des processeurs d'architecture disponibles. */ +char **get_all_processor_keys(size_t *); + /* Fournit le processeur d'architecture correspondant à un nom. */ GArchProcessor *get_arch_processor_for_key(const char *); -- cgit v0.11.2-87-g4458