diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-05-21 16:48:11 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-05-21 16:48:11 (GMT) |
commit | acd355c4c5ae25fb9cac64b8dc17407a2bcc979b (patch) | |
tree | d5b43201049116cd9734ff554e61ed8a7e0084cc /src/arch/dalvik/operands/args.c | |
parent | 4691a434a34a19317156a761967f719e408b73bb (diff) |
Refined the whole share system for operands.
Diffstat (limited to 'src/arch/dalvik/operands/args.c')
-rw-r--r-- | src/arch/dalvik/operands/args.c | 154 |
1 files changed, 119 insertions, 35 deletions
diff --git a/src/arch/dalvik/operands/args.c b/src/arch/dalvik/operands/args.c index 8a687db..2092e6b 100644 --- a/src/arch/dalvik/operands/args.c +++ b/src/arch/dalvik/operands/args.c @@ -69,10 +69,16 @@ static void g_dalvik_args_operand_dispose(GDalvikArgsOperand *); static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *); /* Initialise un nouvel objet partagé avec des informations. */ -static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *, const GDalvikArgsOperand *); +static bool g_dalvik_args_operand_apply_template(GDalvikArgsOperand *, const GDalvikArgsOperand *); + +/* Réalise une copie minimale d'un contenu partagé. */ +static void g_dalvik_args_operand_define_template(const GDalvikArgsOperand *, GDalvikArgsOperand *); + +/* Libère la mémoire utilisée par un patron d'instance. */ +static void g_dalvik_args_operand_free_template(const GDalvikArgsOperand *, GDalvikArgsOperand *); /* Compare un opérande avec un autre. */ -static int g_dalvik_args_operand_compare(const GDalvikArgsOperand * const *, const GDalvikArgsOperand * const *); +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *, const GDalvikArgsOperand *); /* Traduit un opérande en version humainement lisible. */ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *, AsmSyntax); @@ -86,6 +92,10 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine static GShareManager *_dalvik_args_operand_manager = NULL; +/* Fournit le gestionnaire de partages attribué à un type. */ +static GShareManager *get_dalvik_args_operand_share_manager(void); + + /* ---------------------------------------------------------------------------------- */ /* MANIPULATION D'OPERANDES INDIVIDUELLES */ @@ -119,7 +129,11 @@ static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_dalvik_args_operand_dispose; object->finalize = (GObjectFinalizeFunc)g_dalvik_args_operand_finalize; - operand->init = (operand_do_init_fc)g_dalvik_args_operand_do_init; + operand->get_manager = (get_operand_manager_fc)get_dalvik_args_operand_share_manager; + + operand->apply_template = (apply_operand_template_fc)g_dalvik_args_operand_apply_template; + operand->define_template = (define_operand_template_fc)g_dalvik_args_operand_define_template; + operand->free_template = (free_operand_template_fc)g_dalvik_args_operand_free_template; operand->compare = (operand_compare_fc)g_dalvik_args_operand_compare; operand->print = (operand_print_fc)g_dalvik_args_operand_print; @@ -190,62 +204,95 @@ static void g_dalvik_args_operand_finalize(GDalvikArgsOperand *operand) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : operand = objet partagé à initialiser. * +* template = information à utiliser pour la mise en place. * * * -* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* Description : Initialise un nouvel objet partagé avec des informations. * * * -* Retour : Opérande mis en place. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -GArchOperand *g_dalvik_args_operand_new(void) +static bool g_dalvik_args_operand_apply_template(GDalvikArgsOperand *operand, const GDalvikArgsOperand *template) { - GArchOperand *result; /* Structure à retourner */ + size_t i; /* Boucle de parcours */ + + if (template == NULL) + { + operand->args = NULL; + operand->count = 0; + } - result = G_ARCH_OPERAND(g_share_manager_get(_dalvik_args_operand_manager, NULL)); + else + { + g_dalvik_args_operand_define_template(template, operand); - return result; + for (i = 0; i < operand->count; i++) + g_object_ref(G_OBJECT(operand->args[i])); + + } + + return true; } /****************************************************************************** * * -* Paramètres : operand = objet partagé à initialiser. * -* fake = coquille vide contenant les infos à enregistrer. * +* Paramètres : operand = objet partagé à consulter. * +* template = informations à retrouver intégralement. * * * -* Description : Initialise un nouvel objet partagé avec des informations. * +* Description : Réalise une copie minimale d'un contenu partagé. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *operand, const GDalvikArgsOperand *fake) +static void g_dalvik_args_operand_define_template(const GDalvikArgsOperand *operand, GDalvikArgsOperand *template) { size_t i; /* Boucle de parcours */ - if (fake == NULL) + if (operand->count == 0) { - operand->args = NULL; - operand->count = 0; + template->args = NULL; + template->count = 0; } else { - operand->args = (GArchOperand **)calloc(fake->count, sizeof(GArchOperand *)); + template->args = (GArchOperand **)calloc(operand->count, sizeof(GArchOperand *)); - for (i = 0; i < fake->count; i++) - operand->args[i] = fake->args[i]; + for (i = 0; i < operand->count; i++) + template->args[i] = operand->args[i]; - operand->count = fake->count; + template->count = operand->count; } - return true; +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet partagé à consulter. * +* template = informations dont le contenu est à libérer. * +* * +* Description : Libère la mémoire utilisée par un patron d'instance. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_args_operand_free_template(const GDalvikArgsOperand *operand, GDalvikArgsOperand *template) +{ + if (template != NULL && template->args != NULL) + free(template->args); } @@ -263,26 +310,21 @@ static bool g_dalvik_args_operand_do_init(GDalvikArgsOperand *operand, const GDa * * ******************************************************************************/ -static int g_dalvik_args_operand_compare(const GDalvikArgsOperand * const *a, const GDalvikArgsOperand * const *b) +static int g_dalvik_args_operand_compare(const GDalvikArgsOperand *a, const GDalvikArgsOperand *b) { int result; /* Bilan à renvoyer */ - const GDalvikArgsOperand *_a; /* Accès rapide à l'élément A */ - const GDalvikArgsOperand *_b; /* Accès rapide à l'élément B */ size_t i; /* Boucle de parcours */ - _a = *a; - _b = *b; - - if (_b == NULL) - result = sort_unsigned_long(_a->count, 0); + /* Création de l'objet... */ + if (b == NULL) + result = 1; else { - result = sort_unsigned_long(_a->count, _b->count); + result = sort_unsigned_long(a->count, b->count); - for (i = 0; i < _a->count && result == 0; i++) - result = g_arch_operand_compare((const GArchOperand * const *)&_a->args[i], - (const GArchOperand * const *)&_b->args[i]); + for (i = 0; i < a->count && result == 0; i++) + result = g_arch_operand_compare(a->args[i], b->args[i]); } @@ -333,6 +375,29 @@ static void g_dalvik_args_operand_print(const GDalvikArgsOperand *operand, GBuff /****************************************************************************** * * +* Paramètres : - * +* * +* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.* +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_dalvik_args_operand_new(void) +{ + GArchOperand *result; /* Structure à retourner */ + + result = G_ARCH_OPERAND(g_share_manager_build(_dalvik_args_operand_manager, NULL)); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : operand = opérande à compléter. * * arg = nouvel argument pour un appel. * * * @@ -419,6 +484,25 @@ GArchOperand *g_dalvik_args_operand_get(const GDalvikArgsOperand *operand, size_ * * * Paramètres : - * * * +* Description : Fournit le gestionnaire de partages attribué à un type. * +* * +* Retour : Gestionnaire de partages en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GShareManager *get_dalvik_args_operand_share_manager(void) +{ + return _dalvik_args_operand_manager; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Met en place les mécanismes de partage des opérandes Dalvik. * * * * Retour : Bilan de l'opération. * |