diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arch/processor-int.h | 7 | ||||
-rw-r--r-- | src/arch/processor.c | 10 | ||||
-rw-r--r-- | src/arch/processor.h | 2 | ||||
-rw-r--r-- | src/core/processors.c | 18 |
4 files changed, 26 insertions, 11 deletions
diff --git a/src/arch/processor-int.h b/src/arch/processor-int.h index 821ce06..34ba66a 100644 --- a/src/arch/processor-int.h +++ b/src/arch/processor-int.h @@ -33,6 +33,9 @@ #define COV_ALLOC_BLOCK 100 +/* Fournit la désignation interne du processeur d'architecture. */ +typedef char * (* get_processor_key_fc) (const GArchProcessor *); + /* Fournit un contexte propre au processeur d'une architecture. */ typedef GProcContext * (* get_processor_context_fc) (const GArchProcessor *); @@ -92,7 +95,6 @@ struct _GArchProcessorClass { GObjectClass parent; /* A laisser en premier */ - const char *key; /* Désignation interne */ const char *desc; /* Description humaine liée */ SourceEndian endianness; /* Boutisme de l'architecture */ @@ -100,7 +102,8 @@ struct _GArchProcessorClass MemoryDataSize inssize; /* Taille min. d'encodage */ bool virt_space; /* Présence d'espace virtuel ? */ - get_processor_context_fc get_ctx; /* Obtention d'un contexte #1 */ + get_processor_key_fc get_key; /* Code représentant la classe */ + get_processor_context_fc get_ctx; /* Obtention d'un contexte */ disass_instr_fc disassemble; /* Traduction en instructions */ diff --git a/src/arch/processor.c b/src/arch/processor.c index 777b01e..7dbd8eb 100644 --- a/src/arch/processor.c +++ b/src/arch/processor.c @@ -282,14 +282,18 @@ static GProcContext *_g_arch_processor_get_context(const GArchProcessor *proc) * * ******************************************************************************/ -const char *g_arch_processor_get_key(const GArchProcessor *proc) +char *g_arch_processor_get_key(const GArchProcessor *proc) { - const char *result; /* Désignation à renvoyer */ + char *result; /* Désignation à renvoyer */ GArchProcessorClass *class; /* Classe de l'instance */ class = G_ARCH_PROCESSOR_GET_CLASS(proc); - result = class->key; + if (class->get_key == NULL) + result = NULL; + + else + result = class->get_key(proc); return result; diff --git a/src/arch/processor.h b/src/arch/processor.h index d3d4623..7edf341 100644 --- a/src/arch/processor.h +++ b/src/arch/processor.h @@ -56,7 +56,7 @@ typedef struct _GArchProcessorClass GArchProcessorClass; GType g_arch_processor_get_type(void); /* Fournit la désignation interne du processeur d'architecture. */ -const char *g_arch_processor_get_key(const GArchProcessor *); +char *g_arch_processor_get_key(const GArchProcessor *); /* Fournit le nom humain de l'architecture visée. */ const char *g_arch_processor_get_desc(const GArchProcessor *); diff --git a/src/core/processors.c b/src/core/processors.c index 224e9f7..7234365 100644 --- a/src/core/processors.c +++ b/src/core/processors.c @@ -98,33 +98,41 @@ bool register_processor_type(GType type) { bool result; /* Bilan à retourner */ GArchProcessor *proc; /* Instance pour consultation */ - const char *key; /* Désignation associée */ + char *key; /* Désignation associée */ proc_t *new; /* Nouvel élément à définir */ + result = false; + proc = g_object_new(type, NULL); key = g_arch_processor_get_key(proc); + if (key == NULL) goto done; + + result = (key != NULL); + G_LOCK(_pdef_access); new = find_processor_by_key(key); - result = (new == NULL); - - if (result) + if (new == NULL) { _processors_definitions = realloc(_processors_definitions, ++_processors_definitions_count * sizeof(proc_t)); new = &_processors_definitions[_processors_definitions_count - 1]; - new->key = strdup(key); + new->key = key; new->type = type; + result = true; + } G_UNLOCK(_pdef_access); + done: + g_object_unref(G_OBJECT(proc)); return result; |