--- rpl/src/bibliotheques_externes.c 2010/01/26 15:22:44 1.1 +++ rpl/src/bibliotheques_externes.c 2015/01/05 13:12:29 1.60 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.9 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.19 + Copyright (C) 1989-2015 Dr. BERTRAND Joël This file is part of RPL/2. @@ -20,7 +20,7 @@ */ -#include "rpl.conv.h" +#include "rpl-conv.h" static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -41,9 +41,13 @@ void * chargement_bibliotheque(struct_processus *s_etat_processus, unsigned char *bibliotheque) { - char **(*fonction)(unsigned long *); + char **(*fonction)(struct_rpl_arguments *, + integer8 *, const char *); char *message; + integer8 i; + integer8 nombre_symboles; + struct_rpl_arguments rpl_arguments; struct_liste_chainee *l_element_courant; @@ -52,11 +56,8 @@ chargement_bibliotheque(struct_processus unsigned char **tableau; unsigned char *tampon; - unsigned long nombre_symboles; - unsigned long i; - void *descripteur_bibliotheque; - void (*onloading)(struct_rpl_arguments *); + int (*onloading)(struct_rpl_arguments *); /* * On vérifie que la bibliothèque n'est pas déjà chargée. @@ -161,7 +162,11 @@ chargement_bibliotheque(struct_processus } } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return(NULL); @@ -169,7 +174,11 @@ chargement_bibliotheque(struct_processus (*onloading)(&rpl_arguments); - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -315,6 +324,8 @@ chargement_bibliotheque(struct_processus } } + dlerror(); + if (pthread_mutex_unlock(&mutex) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -325,12 +336,24 @@ chargement_bibliotheque(struct_processus * Ajout des symboles externes */ - if ((tableau = (unsigned char **) (*fonction)(&nombre_symboles)) == NULL) + if ((tableau = (unsigned char **) (*fonction)(&rpl_arguments, + (&nombre_symboles), d_version_rpl)) == NULL) { + /* + * Nombre symboles : + * 0 : aucun symbole exporté + * >0 : nombre de symboles exportés + * -1 : version de bibliothèque incompatible + */ + if (nombre_symboles == 0) { (*s_etat_processus).erreur_execution = d_ex_aucun_symbole; } + else if (nombre_symboles == -1) + { + (*s_etat_processus).erreur_execution = d_ex_version_bibliotheque; + } else { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -340,9 +363,9 @@ chargement_bibliotheque(struct_processus } if (((*s_etat_processus).s_instructions_externes = realloc( - (*s_etat_processus).s_instructions_externes, - ((*s_etat_processus).nombre_instructions_externes + nombre_symboles) - * sizeof(struct_instruction_externe))) == NULL) + (*s_etat_processus).s_instructions_externes, ((size_t) + ((*s_etat_processus).nombre_instructions_externes + + nombre_symboles)) * sizeof(struct_instruction_externe))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return(NULL); @@ -380,6 +403,7 @@ chargement_bibliotheque(struct_processus strcpy((*s_etat_processus).s_instructions_externes[(*s_etat_processus) .nombre_instructions_externes].nom_bibliotheque, tableau[i]); (*s_etat_processus).nombre_instructions_externes++; + free(tableau[i]); } @@ -462,11 +486,11 @@ retrait_bibliotheque(struct_processus *s unsigned char *tampon; - unsigned long i; - unsigned long j; - unsigned long nombre_symboles_residuels; + integer8 i; + integer8 j; + integer8 nombre_symboles_residuels; - void (*onclosing)(struct_rpl_arguments *); + int (*onclosing)(struct_rpl_arguments *); l_element_courant = (*s_etat_processus).s_bibliotheques; presence_bibliotheque = d_faux; @@ -557,7 +581,11 @@ retrait_bibliotheque(struct_processus *s } } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return(d_erreur); @@ -565,7 +593,11 @@ retrait_bibliotheque(struct_processus *s (*onclosing)(&rpl_arguments); - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -755,7 +787,7 @@ retrait_bibliotheque(struct_processus *s registre = (*s_etat_processus).s_instructions_externes; if (((*s_etat_processus).s_instructions_externes = - malloc(nombre_symboles_residuels * + malloc(((size_t) nombre_symboles_residuels) * sizeof(struct_instruction_externe))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -821,10 +853,9 @@ execution_fonction_de_bibliotheque(struc logical1 presence_bibliotheque; logical1 unicite_symbole; - long difference; - long difference_inferieure; - long difference_superieure; - long i; + int difference; + int difference_inferieure; + int difference_superieure; struct_liste_chainee *l_element_courant; @@ -833,13 +864,14 @@ execution_fonction_de_bibliotheque(struc unsigned char *nom_fonction_externe; unsigned char *tampon; - unsigned long borne_inferieure; - unsigned long borne_superieure; - unsigned long moyenne; - unsigned long nombre_iterations_maximal; - unsigned long ordre_iteration; + integer8 borne_inferieure; + integer8 borne_superieure; + integer8 i; + integer8 moyenne; + integer8 nombre_iterations_maximal; + integer8 ordre_iteration; - void (*fonction)(struct_rpl_arguments *); + int (*fonction)(struct_rpl_arguments *); /* * Recherche dichotomique de la définition externe @@ -874,9 +906,9 @@ execution_fonction_de_bibliotheque(struc } ordre_iteration = 0; - nombre_iterations_maximal = ((unsigned long) - (log((*s_etat_processus).nombre_instructions_externes) / log(2))) - + 2; + nombre_iterations_maximal = ((integer8) + (log((real8) (*s_etat_processus).nombre_instructions_externes) / + log(2))) + 2; borne_inferieure = 0; borne_superieure = (*s_etat_processus).nombre_instructions_externes - 1; @@ -886,7 +918,7 @@ execution_fonction_de_bibliotheque(struc moyenne = (borne_inferieure + borne_superieure) / 2; ordre_iteration++; - if ((2 * ((unsigned long) ((borne_inferieure + borne_superieure) / 2))) + if ((2 * ((integer8) ((borne_inferieure + borne_superieure) / 2))) == (borne_inferieure + borne_superieure)) { difference = strcmp(nom_fonction, (*s_etat_processus) @@ -973,8 +1005,7 @@ execution_fonction_de_bibliotheque(struc { i = moyenne; - while((unsigned long) i < - (*s_etat_processus).nombre_instructions_externes) + while(i < (*s_etat_processus).nombre_instructions_externes) { if (strcmp((*s_etat_processus).s_instructions_externes[i] .nom, nom_fonction) != 0) @@ -1067,6 +1098,8 @@ execution_fonction_de_bibliotheque(struc } } + dlerror(); + if (pthread_mutex_unlock(&mutex) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -1122,7 +1155,11 @@ execution_fonction_de_bibliotheque(struc } } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return(d_faux); @@ -1130,7 +1167,11 @@ execution_fonction_de_bibliotheque(struc (*fonction)(&rpl_arguments); - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { if (errno != EINTR) { @@ -1435,7 +1476,7 @@ depilement_pile_operationnelle(struct_rp struct_liste_chainee * sauvegarde_arguments(struct_rpl_arguments *s_rpl_arguments, - unsigned long nombre_arguments) + integer8 nombre_arguments) { struct_liste_chainee *l_ancienne_base_liste; struct_liste_chainee *l_element_courant; @@ -1453,7 +1494,7 @@ sauvegarde_arguments(struct_rpl_argument unsigned char indice_drapeau; unsigned char taille_bloc; - unsigned long i; + integer8 i; struct_processus *s_etat_processus; @@ -1466,7 +1507,7 @@ sauvegarde_arguments(struct_rpl_argument indice_bloc = indice_drapeau / taille_bloc; indice_bit = indice_drapeau % taille_bloc; - masque = ((t_8_bits) 1) << (taille_bloc - indice_bit - 1); + masque = (t_8_bits) ((1 << (taille_bloc - indice_bit - 1)) & 0xFF); if (((*s_rpl_arguments).drapeaux_etat[indice_bloc] & masque) == 0) { @@ -1564,15 +1605,14 @@ tri_base_symboles_externes(struct_proces logical1 terminaison_boucle_2; logical1 terminaison_boucle_3; - signed long indice_i; - signed long indice_j; - signed long indice_k; - signed long indice_l; - - unsigned long borne_inferieure; - unsigned long borne_superieure; - unsigned long ecartement; - unsigned long indice; + integer8 borne_inferieure; + integer8 borne_superieure; + integer8 ecartement; + integer8 indice; + integer8 indice_i; + integer8 indice_j; + integer8 indice_k; + integer8 indice_l; ecartement = (*s_etat_processus).nombre_instructions_externes; @@ -1593,7 +1633,6 @@ tri_base_symboles_externes(struct_proces do { indice_i = indice_j; - terminaison_boucle_3 = d_faux; do @@ -1652,7 +1691,7 @@ tri_base_symboles_externes(struct_proces { indice_j = indice_i; - while(((unsigned long) (indice_i + 1) < (*s_etat_processus) + while(((indice_i + 1) < (*s_etat_processus) .nombre_instructions_externes) && (strcmp(((*s_etat_processus) .s_instructions_externes[indice_i]).nom, ((*s_etat_processus) .s_instructions_externes[indice_i + 1]).nom) == 0)) @@ -1686,8 +1725,7 @@ tri_base_symboles_externes(struct_proces } while(terminaison_boucle == d_faux); indice_i++; - } while((unsigned long) (indice_i + 1) < - (*s_etat_processus).nombre_variables); + } while((indice_i + 1) < (*s_etat_processus).nombre_instructions_externes); return; }