diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2025-03-17 07:36:58 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2025-03-17 07:36:58 (GMT) |
commit | a28e1b94a83bee9a2424ab84818a5547eafaf0cf (patch) | |
tree | ecaf5556433afd4f19f4bfcbf378cdde3f619e51 /src/arch/operand.c | |
parent | b18c64b69c8c048c640b5d9f6c45b1cfda605ae8 (diff) |
Restore the definition of main operands.gtk4
Diffstat (limited to 'src/arch/operand.c')
-rw-r--r-- | src/arch/operand.c | 653 |
1 files changed, 195 insertions, 458 deletions
diff --git a/src/arch/operand.c b/src/arch/operand.c index 0f5ffd5..f2f356b 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * operand.c - gestion générique des opérandes * - * Copyright (C) 2008-2020 Cyrille Bagard + * Copyright (C) 2008-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -25,17 +25,16 @@ #include <assert.h> -#include <malloc.h> -#include <string.h> #include "operand-int.h" -#include "storage.h" -#include "../analysis/storage/serialize-int.h" #include "../common/fnv1a.h" #include "../common/sort.h" -#include "../core/logs.h" +#include "../glibext/comparable-int.h" +#include "../glibext/hashable-int.h" +#include "../glibext/serialize-int.h" #include "../glibext/singleton-int.h" +#include "../glibext/strbuilder-int.h" @@ -45,66 +44,67 @@ /* Initialise la classe générique des opérandes. */ static void g_arch_operand_class_init(GArchOperandClass *); -/* Initialise une instance d'opérande d'architecture. */ -static void g_arch_operand_init(GArchOperand *); +/* Procède à l'initialisation de l'interface de comparaison. */ +static void g_arch_operand_comparable_object_iface_init(GComparableObjectInterface *); -/* Procède à l'initialisation de l'interface de singleton. */ -static void g_arch_operand_singleton_init(GSingletonCandidateInterface *); +/* Procède à l'initialisation de l'interface de détermination. */ +static void g_arch_operand_hashable_object_iface_init(GHashableObjectInterface *); /* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_arch_operand_serializable_init(GSerializableObjectInterface *); +static void g_arch_operand_serializable_iface_init(GSerializableObjectInterface *); + +/* Procède à l'initialisation de l'interface de rassemblement. */ +static void g_arch_operand_singleton_candidate_iface_init(GSingletonCandidateInterface *); + +/* Procède à l'initialisation de l'interface d'exportation. */ +static void g_arch_operand_string_builder_iface_init(GStringBuilderInterface *); + +/* Initialise une instance d'opérande d'architecture. */ +static void g_arch_operand_init(GArchOperand *); /* Supprime toutes les références externes. */ -static void g_arch_operand_dispose(GArchOperand *); +static void g_arch_operand_dispose(GObject *); /* Procède à la libération totale de la mémoire. */ -static void g_arch_operand_finalize(GArchOperand *); +static void g_arch_operand_finalize(GObject *); -/* Compare un opérande avec un autre. */ -static int _g_arch_operand_compare(const GArchOperand *, const GArchOperand *, bool); +/* ---------------------- COMPARAISON DETAILLEE DE DEUX OBJETS ---------------------- */ -/* ------------------------ CONTROLE DU VOLUME DES INSTANCES ------------------------ */ +/* Réalise une comparaison étendue entre objets. */ +static int g_arch_operand_compare(const GComparableObject *, const GComparableObject *); -/* Fournit une liste de candidats embarqués par un candidat. */ -GArchOperand **g_arch_operand_list_inner_instances(const GArchOperand *, size_t *); -/* Met à jour une liste de candidats embarqués par un candidat. */ -void g_arch_operand_update_inner_instances(GArchOperand *, GArchOperand **, size_t); -/* Fournit l'empreinte d'un candidat à une centralisation. */ -static guint _g_arch_operand_hash(const GArchOperand *, bool); +/* ---------------------- CALCUL D'UNE EMPREINTE DE L'INSTANCE ---------------------- */ -/* Fournit l'empreinte d'un candidat à une centralisation. */ -static guint g_arch_operand_hash(const GArchOperand *); -/* Détermine si deux candidats à l'unicité sont identiques. */ -static gboolean g_arch_operand_is_equal(const GArchOperand *, const GArchOperand *); +/* Calcule l'empreinte sur 32 bits d'un objet. */ +static guint g_arch_operand_hash(const GHashableObject *); -/* Marque un candidat comme figé. */ -static void g_arch_operand_set_read_only(GArchOperand *); -/* Indique si le candidat est figé. */ -static bool g_arch_operand_is_read_only(GArchOperand *); +/* ------------------- MECANISMES DE CONSERVATION ET RESTAURATION ------------------- */ -/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ +/* Charge un objet depuis un flux de données. */ +static bool g_arch_operand_load(GSerializableObject *, GObjectStorage *, int); +/* Sauvegarde un objet dans un flux de données. */ +static bool g_arch_operand_store(const GSerializableObject *, GObjectStorage *, int); -/* Charge un contenu depuis une mémoire tampon. */ -static bool _g_arch_operand_load(GArchOperand *, GObjectStorage *, packed_buffer_t *); -/* Charge un contenu depuis une mémoire tampon. */ -static bool g_arch_operand_load(GArchOperand *, GObjectStorage *, packed_buffer_t *); -/* Sauvegarde un contenu dans une mémoire tampon. */ -static bool _g_arch_operand_store(GArchOperand *, GObjectStorage *, packed_buffer_t *); +/* ------------------------ CONTROLE DU VOLUME DES INSTANCES ------------------------ */ -/* Sauvegarde un contenu dans une mémoire tampon. */ -static bool g_arch_operand_store(GArchOperand *, GObjectStorage *, packed_buffer_t *); + +/* Marque un candidat comme figé. */ +static void g_arch_operand_mark_as_read_only(GSingletonCandidate *); + +/* Indique si le candidat est figé. */ +static bool g_arch_operand_is_read_only(const GSingletonCandidate *); @@ -114,9 +114,12 @@ static bool g_arch_operand_store(GArchOperand *, GObjectStorage *, packed_buffer /* Indique le type défini pour un opérande d'architecture. */ -G_DEFINE_TYPE_WITH_CODE(GArchOperand, g_arch_operand, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE(G_TYPE_SINGLETON_CANDIDATE, g_arch_operand_singleton_init) - G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_arch_operand_serializable_init)); +G_DEFINE_TYPE_WITH_CODE(GArchOperand, g_arch_operand, G_TYPE_THICK_OBJECT, + G_IMPLEMENT_INTERFACE(G_TYPE_COMPARABLE_OBJECT, g_arch_operand_comparable_object_iface_init) + G_IMPLEMENT_INTERFACE(G_TYPE_HASHABLE_OBJECT, g_arch_operand_hashable_object_iface_init) + G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_arch_operand_serializable_iface_init) + G_IMPLEMENT_INTERFACE(G_TYPE_SINGLETON_CANDIDATE, g_arch_operand_singleton_candidate_iface_init) + G_IMPLEMENT_INTERFACE(G_TYPE_STRING_BUILDER, g_arch_operand_string_builder_iface_init)); /****************************************************************************** @@ -134,30 +137,20 @@ G_DEFINE_TYPE_WITH_CODE(GArchOperand, g_arch_operand, G_TYPE_OBJECT, static void g_arch_operand_class_init(GArchOperandClass *klass) { GObjectClass *object; /* Autre version de la classe */ - GArchOperandClass *operand; /* Encore une autre vision... */ object = G_OBJECT_CLASS(klass); - object->dispose = (GObjectFinalizeFunc/* ! */)g_arch_operand_dispose; - object->finalize = (GObjectFinalizeFunc)g_arch_operand_finalize; - - operand = G_ARCH_OPERAND_CLASS(klass); - - operand->compare = (operand_compare_fc)_g_arch_operand_compare; - - operand->hash = _g_arch_operand_hash; - - operand->load = (load_operand_fc)_g_arch_operand_load; - operand->store = (store_operand_fc)_g_arch_operand_store; + object->dispose = g_arch_operand_dispose; + object->finalize = g_arch_operand_finalize; } /****************************************************************************** * * -* Paramètres : operand = instance à initialiser. * +* Paramètres : iface = interface GLib à initialiser. * * * -* Description : Initialise une instance d'opérande d'architecture. * +* Description : Procède à l'initialisation de l'interface de comparaison. * * * * Retour : - * * * @@ -165,13 +158,9 @@ static void g_arch_operand_class_init(GArchOperandClass *klass) * * ******************************************************************************/ -static void g_arch_operand_init(GArchOperand *operand) +static void g_arch_operand_comparable_object_iface_init(GComparableObjectInterface *iface) { - operand_extra_data_t *extra; /* Données insérées à modifier */ - - extra = GET_ARCH_OP_EXTRA(operand); - - INIT_GOBJECT_EXTRA_LOCK(extra); + iface->compare = g_arch_operand_compare; } @@ -180,7 +169,7 @@ static void g_arch_operand_init(GArchOperand *operand) * * * Paramètres : iface = interface GLib à initialiser. * * * -* Description : Procède à l'initialisation de l'interface de singleton. * +* Description : Procède à l'initialisation de l'interface de détermination. * * * * Retour : - * * * @@ -188,16 +177,9 @@ static void g_arch_operand_init(GArchOperand *operand) * * ******************************************************************************/ -static void g_arch_operand_singleton_init(GSingletonCandidateInterface *iface) +static void g_arch_operand_hashable_object_iface_init(GHashableObjectInterface *iface) { - iface->list_inner = (list_inner_instances_fc)g_arch_operand_list_inner_instances; - iface->update_inner = (update_inner_instances_fc)g_arch_operand_update_inner_instances; - - iface->hash = (hash_candidate_fc)g_arch_operand_hash; - iface->is_equal = (is_candidate_equal_fc)g_arch_operand_is_equal; - - iface->set_ro = (set_candidate_ro_fc)g_arch_operand_set_read_only; - iface->is_ro = (is_candidate_ro_fc)g_arch_operand_is_read_only; + iface->hash = g_arch_operand_hash; } @@ -214,38 +196,19 @@ static void g_arch_operand_singleton_init(GSingletonCandidateInterface *iface) * * ******************************************************************************/ -static void g_arch_operand_serializable_init(GSerializableObjectInterface *iface) +static void g_arch_operand_serializable_iface_init(GSerializableObjectInterface *iface) { - iface->load = (load_serializable_object_cb)g_arch_operand_load; - iface->store = (store_serializable_object_cb)g_arch_operand_store; + iface->load = g_arch_operand_load; + iface->store = g_arch_operand_store; } /****************************************************************************** * * -* Paramètres : operand = instance d'objet GLib à traiter. * -* * -* Description : Supprime toutes les références externes. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_arch_operand_dispose(GArchOperand *operand) -{ - G_OBJECT_CLASS(g_arch_operand_parent_class)->dispose(G_OBJECT(operand)); - -} - - -/****************************************************************************** -* * -* Paramètres : operand = instance d'objet GLib à traiter. * +* Paramètres : iface = interface GLib à initialiser. * * * -* Description : Procède à la libération totale de la mémoire. * +* Description : Procède à l'initialisation de l'interface de rassemblement. * * * * Retour : - * * * @@ -253,147 +216,59 @@ static void g_arch_operand_dispose(GArchOperand *operand) * * ******************************************************************************/ -static void g_arch_operand_finalize(GArchOperand *operand) +static void g_arch_operand_singleton_candidate_iface_init(GSingletonCandidateInterface *iface) { - G_OBJECT_CLASS(g_arch_operand_parent_class)->finalize(G_OBJECT(operand)); - -} - - -/****************************************************************************** -* * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * -* lock = précise le besoin en verrouillage. * -* * -* Description : Compare un opérande avec un autre. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int _g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b, bool lock) -{ - int result; /* Bilan à faire remonter */ - operand_extra_data_t *ea; /* Données insérées à consulter*/ - operand_extra_data_t *eb; /* Données insérées à consulter*/ - - assert(!lock); - - ea = GET_ARCH_OP_EXTRA(a); - eb = GET_ARCH_OP_EXTRA(b); + iface->list_inner = NULL; + iface->update_inner = NULL; - result = sort_unsigned_long(ea->flags, eb->flags); - - return result; + iface->mark_as_ro = g_arch_operand_mark_as_read_only; + iface->is_ro = g_arch_operand_is_read_only; } /****************************************************************************** * * -* Paramètres : a = premier opérande à consulter. * -* b = second opérande à consulter. * -* * -* Description : Compare un opérande avec un autre. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -int g_arch_operand_compare(const GArchOperand *a, const GArchOperand *b) -{ - int result; /* Bilan à faire remonter */ - GType type_a; /* Type de l'object A */ - GType type_b; /* Type de l'object B */ - - type_a = G_OBJECT_TYPE(G_OBJECT(a)); - type_b = G_OBJECT_TYPE(G_OBJECT(b)); - - assert(sizeof(GType) <= sizeof(unsigned long)); - - result = sort_unsigned_long(type_a, type_b); - - if (result == 0) - result = G_ARCH_OPERAND_GET_CLASS(a)->compare(a, b, true); - - return result; - -} - - -/****************************************************************************** +* Paramètres : iface = interface GLib à initialiser. * * * -* Paramètres : operand = opérande à consulter. * -* target = instruction à venir retrouver. * +* Description : Procède à l'initialisation de l'interface d'exportation. * * * -* Description : Détermine le chemin conduisant à un opérande interne. * -* * -* Retour : Chemin d'accès à l'opérande ou NULL en cas d'absence. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -char *g_arch_operand_find_inner_operand_path(const GArchOperand *operand, const GArchOperand *target) +static void g_arch_operand_string_builder_iface_init(GStringBuilderInterface *iface) { - char *result; /* Chemin à retourner */ - GArchOperandClass *class; /* Classe associée à l'objet */ - - class = G_ARCH_OPERAND_GET_CLASS(operand); - - if (class->find_inner != NULL) - result = class->find_inner(operand, target); - - else - result = NULL; - - return result; + iface->to_string = NULL; } /****************************************************************************** * * -* Paramètres : operand = opérande à consulter. * -* path = chemin d'accès à un opérande à retrouver. * +* Paramètres : operand = instance à initialiser. * * * -* Description : Obtient l'opérande correspondant à un chemin donné. * +* Description : Initialise une instance d'opérande d'architecture. * * * -* Retour : Opérande trouvé ou NULL en cas d'échec. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_arch_operand_get_inner_operand_from_path(const GArchOperand *operand, const char *path) +static void g_arch_operand_init(GArchOperand *operand) { - GArchOperand *result; /* Opérande trouvée à renvoyer */ - GArchOperandClass *class; /* Classe associée à l'objet */ - - class = G_ARCH_OPERAND_GET_CLASS(operand); - - if (class->get_inner != NULL) - result = class->get_inner(operand, path); - - else - result = NULL; - - return result; } /****************************************************************************** * * -* Paramètres : operand = opérande à traiter. * -* line = ligne tampon où imprimer l'opérande donné. * +* Paramètres : object = instance d'objet GLib à traiter. * * * -* Description : Traduit un opérande en version humainement lisible. * +* Description : Supprime toutes les références externes. * * * * Retour : - * * * @@ -401,54 +276,36 @@ GArchOperand *g_arch_operand_get_inner_operand_from_path(const GArchOperand *ope * * ******************************************************************************/ -void g_arch_operand_print(const GArchOperand *operand, GBufferLine *line) +static void g_arch_operand_dispose(GObject *object) { - G_ARCH_OPERAND_GET_CLASS(operand)->print(operand, line); + G_OBJECT_CLASS(g_arch_operand_parent_class)->dispose(object); } -#ifdef INCLUDE_GTK_SUPPORT - - /****************************************************************************** * * -* Paramètres : operand = opérande à consulter. * -* binary = informations relatives au binaire chargé. * +* Paramètres : object = instance d'objet GLib à traiter. * * * -* Description : Construit un petit résumé concis de l'opérande. * +* Description : Procède à la libération totale de la mémoire. * * * -* Retour : Chaîne de caractères à libérer après usage ou NULL. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -char *g_arch_operand_build_tooltip(const GArchOperand *operand, const GLoadedBinary *binary) +static void g_arch_operand_finalize(GObject *object) { - char *result; /* Description à retourner */ - GArchOperandClass *class; /* Classe associée à l'objet */ - - class = G_ARCH_OPERAND_GET_CLASS(operand); - - if (class->build_tooltip != NULL) - result = class->build_tooltip(operand, binary); - else - result = NULL; - - return result; + G_OBJECT_CLASS(g_arch_operand_parent_class)->finalize(object); } -#endif - - /****************************************************************************** * * * Paramètres : operand = opérande à venir modifier. * * flag = drapeau d'information complémentaire à planter. * -* lock = indique un besoin de verrouillage des données. * * * * Description : Ajoute une information complémentaire à un opérande. * * * @@ -458,48 +315,20 @@ char *g_arch_operand_build_tooltip(const GArchOperand *operand, const GLoadedBin * * ******************************************************************************/ -bool _g_arch_operand_set_flag(GArchOperand *operand, ArchOperandFlag flag, bool lock) +bool g_arch_operand_set_flag(GArchOperand *operand, ArchOperandFlag flag) { bool result; /* Bilan à retourner */ - operand_extra_data_t *extra; /* Données insérées à modifier */ + operand_extra_data_t extra; /* Données insérées à modifier */ assert(flag <= AOF_HIGH_USER); extra = GET_ARCH_OP_EXTRA(operand); - if (lock) - LOCK_GOBJECT_EXTRA(extra); - - result = !(extra->flags & flag); - - extra->flags |= flag; - - if (lock) - UNLOCK_GOBJECT_EXTRA(extra); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à venir modifier. * -* flag = drapeau d'information complémentaire à planter. * -* * -* Description : Ajoute une information complémentaire à un opérande. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ + result = !(extra.flags & flag); -bool g_arch_operand_set_flag(GArchOperand *operand, ArchOperandFlag flag) -{ - bool result; /* Bilan à retourner */ + extra.flags |= flag; - result = _g_arch_operand_set_flag(operand, flag, true); + SET_ARCH_OP_EXTRA(operand, &extra); return result; @@ -510,7 +339,6 @@ bool g_arch_operand_set_flag(GArchOperand *operand, ArchOperandFlag flag) * * * Paramètres : operand = opérande à venir modifier. * * flag = drapeau d'information complémentaire à planter. * -* lock = indique un besoin de verrouillage des données. * * * * Description : Retire une information complémentaire à un opérande. * * * @@ -520,46 +348,20 @@ bool g_arch_operand_set_flag(GArchOperand *operand, ArchOperandFlag flag) * * ******************************************************************************/ -bool _g_arch_operand_unset_flag(GArchOperand *operand, ArchOperandFlag flag, bool lock) +bool g_arch_operand_unset_flag(GArchOperand *operand, ArchOperandFlag flag) { bool result; /* Bilan à retourner */ - operand_extra_data_t *extra; /* Données insérées à modifier */ + operand_extra_data_t extra; /* Données insérées à modifier */ assert(flag <= AOF_HIGH_USER); extra = GET_ARCH_OP_EXTRA(operand); - LOCK_GOBJECT_EXTRA(extra); - - result = (extra->flags & flag); - - extra->flags &= ~flag; - - UNLOCK_GOBJECT_EXTRA(extra); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : operand = opérande à venir modifier. * -* flag = drapeau d'information complémentaire à planter. * -* * -* Description : Retire une information complémentaire à un opérande. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ + result = (extra.flags & flag); -bool g_arch_operand_unset_flag(GArchOperand *operand, ArchOperandFlag flag) -{ - bool result; /* Bilan à retourner */ + extra.flags &= ~flag; - result = _g_arch_operand_unset_flag(operand, flag, true); + SET_ARCH_OP_EXTRA(operand, &extra); return result; @@ -582,17 +384,13 @@ bool g_arch_operand_unset_flag(GArchOperand *operand, ArchOperandFlag flag) bool g_arch_operand_has_flag(const GArchOperand *operand, ArchOperandFlag flag) { bool result; /* Bilan à retourner */ - operand_extra_data_t *extra; /* Données insérées à modifier */ + operand_extra_data_t extra; /* Données insérées à modifier */ assert(flag <= AOF_HIGH_USER); extra = GET_ARCH_OP_EXTRA(operand); - LOCK_GOBJECT_EXTRA(extra); - - result = (extra->flags & flag); - - UNLOCK_GOBJECT_EXTRA(extra); + result = (extra.flags & flag); return result; @@ -614,15 +412,11 @@ bool g_arch_operand_has_flag(const GArchOperand *operand, ArchOperandFlag flag) ArchOperandFlag g_arch_operand_get_flags(const GArchOperand *operand) { ArchOperandFlag result; /* Fanions à retourner */ - operand_extra_data_t *extra; /* Données insérées à modifier */ + operand_extra_data_t extra; /* Données insérées à modifier */ extra = GET_ARCH_OP_EXTRA(operand); - LOCK_GOBJECT_EXTRA(extra); - - result = extra->flags; - - UNLOCK_GOBJECT_EXTRA(extra); + result = extra.flags; return result; @@ -630,39 +424,40 @@ ArchOperandFlag g_arch_operand_get_flags(const GArchOperand *operand) -/* ---------------------------------------------------------------------------------- */ -/* CONTROLE DU VOLUME DES INSTANCES */ -/* ---------------------------------------------------------------------------------- */ + + + + +#if 0 + + /****************************************************************************** * * -* Paramètres : operand = objet dont l'instance se veut unique. * -* count = quantité d'instances à l'unicité internes. * +* Paramètres : operand = opérande à consulter. * +* target = instruction à venir retrouver. * * * -* Description : Fournit une liste de candidats embarqués par un candidat. * +* Description : Détermine le chemin conduisant à un opérande interne. * * * -* Retour : Liste de candidats internes ou NULL si aucun. * +* Retour : Chemin d'accès à l'opérande ou NULL en cas d'absence. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand **g_arch_operand_list_inner_instances(const GArchOperand *operand, size_t *count) +char *g_arch_operand_find_inner_operand_path(const GArchOperand *operand, const GArchOperand *target) { - GArchOperand **result; /* Instances à retourner */ + char *result; /* Chemin à retourner */ GArchOperandClass *class; /* Classe associée à l'objet */ class = G_ARCH_OPERAND_GET_CLASS(operand); - if (class->list_inner == NULL) - { - *count = 0; - result = NULL; - } + if (class->find_inner != NULL) + result = class->find_inner(operand, target); else - result = class->list_inner(operand, count); + result = NULL; return result; @@ -671,105 +466,59 @@ GArchOperand **g_arch_operand_list_inner_instances(const GArchOperand *operand, /****************************************************************************** * * -* Paramètres : operand = objet dont l'instance se veut unique. * -* instances = liste de candidats internes devenus singletons. * -* count = quantité d'instances à l'unicité internes. * +* Paramètres : operand = opérande à consulter. * +* path = chemin d'accès à un opérande à retrouver. * * * -* Description : Met à jour une liste de candidats embarqués par un candidat. * +* Description : Obtient l'opérande correspondant à un chemin donné. * * * -* Retour : - * +* Retour : Opérande trouvé ou NULL en cas d'échec. * * * * Remarques : - * * * ******************************************************************************/ -void g_arch_operand_update_inner_instances(GArchOperand *operand, GArchOperand **instances, size_t count) +GArchOperand *g_arch_operand_get_inner_operand_from_path(const GArchOperand *operand, const char *path) { + GArchOperand *result; /* Opérande trouvée à renvoyer */ GArchOperandClass *class; /* Classe associée à l'objet */ class = G_ARCH_OPERAND_GET_CLASS(operand); - if (class->update_inner == NULL) - assert(class->list_inner == NULL); + if (class->get_inner != NULL) + result = class->get_inner(operand, path); else - { - assert(class->list_inner != NULL); - class->update_inner(operand, instances, count); - } + result = NULL; + + return result; } -/****************************************************************************** -* * -* Paramètres : operand = objet dont l'instance se veut unique. * -* lock = précise le besoin en verrouillage. * -* * -* Description : Fournit l'empreinte d'un candidat à une centralisation. * -* * -* Retour : Empreinte de l'élément représenté. * -* * -* Remarques : - * -* * -******************************************************************************/ +#endif -static guint _g_arch_operand_hash(const GArchOperand *operand, bool lock) -{ - guint result; /* Valeur à retourner */ - const char *name; /* Désignation du type d'object*/ - fnv64_t name_hash; /* Empreinte du nom */ - operand_extra_data_t *extra; /* Données insérées à modifier */ - assert(!lock); - name = G_OBJECT_TYPE_NAME(G_OBJECT(operand)); - name_hash = fnv_64a_hash(name); - result = (name_hash & 0xffffffff); - result ^= (name_hash >> 32); - extra = GET_ARCH_OP_EXTRA(operand); - result ^= extra->flags; - return result; -} -/****************************************************************************** -* * -* Paramètres : operand = objet dont l'instance se veut unique. * -* * -* Description : Fournit l'empreinte d'un candidat à une centralisation. * -* * -* Retour : Empreinte de l'élément représenté. * -* * -* Remarques : - * -* * -******************************************************************************/ -static guint g_arch_operand_hash(const GArchOperand *operand) -{ - guint result; /* Valeur à retourner */ - GArchOperandClass *class; /* Classe associée à l'objet */ - - class = G_ARCH_OPERAND_GET_CLASS(operand); - - result = class->hash(operand, true); - return result; - -} +/* ---------------------------------------------------------------------------------- */ +/* COMPARAISON DETAILLEE DE DEUX OBJETS */ +/* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * -* Paramètres : operand = objet dont l'instance se veut unique. * -* other = second élément à analyser. * +* Paramètres : object = premier objet à consulter pour une comparaison. * +* other = second objet à consulter pour une comparaison. * * * -* Description : Détermine si deux candidats à l'unicité sont identiques. * +* Description : Réalise une comparaison étendue entre objets. * * * * Retour : Bilan de la comparaison. * * * @@ -777,56 +526,56 @@ static guint g_arch_operand_hash(const GArchOperand *operand) * * ******************************************************************************/ -static gboolean g_arch_operand_is_equal(const GArchOperand *operand, const GArchOperand *other) +static int g_arch_operand_compare(const GComparableObject *object, const GComparableObject *other) { - gboolean result; /* Bilan à renvoyer */ - int ret; /* Bilan d'une comparaison */ + int result; /* Bilan à retourner */ + operand_extra_data_t extra_op; /* Données insérées à consulter*/ + operand_extra_data_t extra_other; /* Données insérées à consulter*/ - ret = g_arch_operand_compare(operand, other); + extra_op = GET_ARCH_OP_EXTRA(object); + extra_other = GET_ARCH_OP_EXTRA(other); - result = (ret == 0); + result = sort_unsigned_long(extra_op.flags, extra_other.flags); return result; } -/****************************************************************************** -* * -* Paramètres : operand = objet dont l'instance se veut unique. * -* * -* Description : Marque un candidat comme figé. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_arch_operand_set_read_only(GArchOperand *operand) -{ - g_arch_operand_set_flag(operand, AOF_READ_ONLY); -} +/* ---------------------------------------------------------------------------------- */ +/* CALCUL D'UNE EMPREINTE DE L'INSTANCE */ +/* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * -* Paramètres : operand = objet dont l'instance se veut unique. * +* Paramètres : object = objet dont l'instance est à consulter. * * * -* Description : Indique si le candidat est figé. * +* Description : Calcule l'empreinte sur 32 bits d'un objet. * * * -* Retour : true si le contenu du candidat ne peut plus être modifié. * +* Retour : Valeur de représentation, unique pour l'objet ou non. * * * * Remarques : - * * * ******************************************************************************/ -static bool g_arch_operand_is_read_only(GArchOperand *operand) +static guint g_arch_operand_hash(const GHashableObject *object) { - bool result; /* Etat à retourner */ + guint result; /* Valeur à retourner */ + const char *name; /* Désignation du type d'object*/ + fnv64_t name_hash; /* Empreinte du nom */ + operand_extra_data_t extra; /* Données insérées à consulter*/ - result = g_arch_operand_has_flag(operand, AOF_READ_ONLY); + name = G_OBJECT_TYPE_NAME(G_OBJECT(object)); + name_hash = fnv_64a_hash(name); + + result = (name_hash & 0xffffffff); + result ^= (name_hash >> 32); + + extra = GET_ARCH_OP_EXTRA(object); + + result ^= extra.flags; return result; @@ -835,17 +584,17 @@ static bool g_arch_operand_is_read_only(GArchOperand *operand) /* ---------------------------------------------------------------------------------- */ -/* CONSERVATION ET RECHARGEMENT DES DONNEES */ +/* MECANISMES DE CONSERVATION ET RESTAURATION */ /* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * -* Paramètres : operand = élément GLib à constuire. * -* storage = conservateur de données à manipuler ou NULL. * -* pbuf = zone tampon à lire. * +* Paramètres : object = élément GLib à constuire. * +* storage = conservateur de données à manipuler. * +* fd = flux ouvert en lecture. * * * -* Description : Charge un contenu depuis une mémoire tampon. * +* Description : Charge un objet depuis un flux de données. * * * * Retour : Bilan de l'opération. * * * @@ -853,22 +602,15 @@ static bool g_arch_operand_is_read_only(GArchOperand *operand) * * ******************************************************************************/ -static bool _g_arch_operand_load(GArchOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_arch_operand_load(GSerializableObject *object, GObjectStorage *storage, int fd) { bool result; /* Bilan à retourner */ - operand_extra_data_t *extra; /* Données insérées à consulter*/ - uleb128_t value; /* Valeur ULEB128 à charger */ - - extra = GET_ARCH_OP_EXTRA(operand); + uleb128_t extra; /* Données embarquées */ - LOCK_GOBJECT_EXTRA(extra); - - result = unpack_uleb128(&value, pbuf); + result = load_uleb128(&extra, fd); if (result) - extra->flags = value; - - UNLOCK_GOBJECT_EXTRA(extra); + g_thick_object_set_extra(G_THICK_OBJECT(object), extra); return result; @@ -877,11 +619,11 @@ static bool _g_arch_operand_load(GArchOperand *operand, GObjectStorage *storage, /****************************************************************************** * * -* Paramètres : operand = élément GLib à constuire. * -* storage = conservateur de données à manipuler ou NULL. * -* pbuf = zone tampon à lire. * +* Paramètres : object = élément GLib à consulter. * +* storage = conservateur de données à manipuler. * +* fd = flux ouvert en écriture. * * * -* Description : Charge un contenu depuis une mémoire tampon. * +* Description : Sauvegarde un objet dans un flux de données. * * * * Retour : Bilan de l'opération. * * * @@ -889,74 +631,69 @@ static bool _g_arch_operand_load(GArchOperand *operand, GObjectStorage *storage, * * ******************************************************************************/ -static bool g_arch_operand_load(GArchOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_arch_operand_store(const GSerializableObject *object, GObjectStorage *storage, int fd) { bool result; /* Bilan à retourner */ - GArchOperandClass *class; /* Classe à activer */ + guint extra; /* Données embarquées */ - class = G_ARCH_OPERAND_GET_CLASS(operand); + extra = g_thick_object_get_extra(G_THICK_OBJECT(object)); - result = class->load(operand, storage, pbuf); + result = store_uleb128((uleb128_t []) { extra }, fd); return result; } + +/* ---------------------------------------------------------------------------------- */ +/* CONTROLE DU VOLUME DES INSTANCES */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * -* Paramètres : operand = élément GLib à consulter. * -* storage = conservateur de données à manipuler ou NULL. * -* pbuf = zone tampon à remplir. * +* Paramètres : candidate = objet dont l'instance se veut unique. * * * -* Description : Sauvegarde un contenu dans une mémoire tampon. * +* Description : Marque un candidat comme figé. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool _g_arch_operand_store(GArchOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf) +static void g_arch_operand_mark_as_read_only(GSingletonCandidate *candidate) { - bool result; /* Bilan à retourner */ - operand_extra_data_t *extra; /* Données insérées à consulter*/ - - extra = GET_ARCH_OP_EXTRA(operand); - - LOCK_GOBJECT_EXTRA(extra); - - result = pack_uleb128((uleb128_t []){ extra->flags }, pbuf); + GArchOperand *operand; /* Version spécialisée */ - UNLOCK_GOBJECT_EXTRA(extra); + operand = G_ARCH_OPERAND(candidate); - return result; + g_arch_operand_set_flag(operand, AOF_READ_ONLY); } /****************************************************************************** * * -* Paramètres : operand = élément GLib à consulter. * -* storage = conservateur de données à manipuler ou NULL. * -* pbuf = zone tampon à remplir. * +* Paramètres : operand = objet dont l'instance se veut unique. * * * -* Description : Sauvegarde un contenu dans une mémoire tampon. * +* Description : Indique si le candidat est figé. * * * -* Retour : Bilan de l'opération. * +* Retour : true si le contenu du candidat ne peut plus être modifié. * * * * Remarques : - * * * ******************************************************************************/ -static bool g_arch_operand_store(GArchOperand *operand, GObjectStorage *storage, packed_buffer_t *pbuf) +static bool g_arch_operand_is_read_only(const GSingletonCandidate *candidate) { - bool result; /* Bilan à retourner */ - GArchOperandClass *class; /* Classe à activer */ + bool result; /* Etat à retourner */ + GArchOperand *operand; /* Version spécialisée */ - class = G_ARCH_OPERAND_GET_CLASS(operand); + operand = G_ARCH_OPERAND(candidate); - result = class->store(operand, storage, pbuf); + result = g_arch_operand_has_flag(operand, AOF_READ_ONLY); return result; |