Diff for /rpl/src/bibliotheques_externes.c between versions 1.32 and 1.79

version 1.32, 2011/07/25 07:44:53 version 1.79, 2018/12/24 15:54:59
Line 1 Line 1
 /*  /*
 ================================================================================  ================================================================================
   RPL/2 (R) version 4.1.2    RPL/2 (R) version 4.1.30
   Copyright (C) 1989-2011 Dr. BERTRAND Joël    Copyright (C) 1989-2018 Dr. BERTRAND Joël
   
   This file is part of RPL/2.    This file is part of RPL/2.
   
Line 41  void * Line 41  void *
 chargement_bibliotheque(struct_processus *s_etat_processus,  chargement_bibliotheque(struct_processus *s_etat_processus,
         unsigned char *bibliotheque)          unsigned char *bibliotheque)
 {  {
     char                    **(*fonction)(unsigned long *, const char *);      char                    **(*fonction)(struct_rpl_arguments *,
                                       integer8 *, const char *);
     char                    *message;      char                    *message;
   
     long                    i;      integer8                i;
     long                    nombre_symboles;      integer8                nombre_symboles;
   
     struct_rpl_arguments    rpl_arguments;      struct_rpl_arguments    rpl_arguments;
   
     struct_liste_chainee    *l_element_courant;      struct_liste_chainee    *l_element_courant;
     struct_liste_chainee    *l_nouvel_element;      struct_liste_chainee    *l_nouvel_element;
   
       unsigned char           *fleche;
     unsigned char           **tableau;      unsigned char           **tableau;
     unsigned char           *tampon;      unsigned char           *tampon;
   
     void                    *descripteur_bibliotheque;      void                    *descripteur_bibliotheque;
     void                    (*onloading)(struct_rpl_arguments *);      int                     (*onloading)(struct_rpl_arguments *, void *);
   
     /*      /*
      * On vérifie que la bibliothèque n'est pas déjà chargée.       * On vérifie que la bibliothèque n'est pas déjà chargée.
Line 162  chargement_bibliotheque(struct_processus Line 164  chargement_bibliotheque(struct_processus
         }          }
   
 #       ifndef SEMAPHORES_NOMMES  #       ifndef SEMAPHORES_NOMMES
         if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)              if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
         {  
             (*s_etat_processus).erreur_systeme = d_es_processus;  
             return(NULL);  
         }  
 #       else  #       else
         if (sem_post((*s_etat_processus).semaphore_fork) != 0)              if (sem_post((*s_etat_processus).semaphore_fork) != 0)
   #       endif
         {          {
             (*s_etat_processus).erreur_systeme = d_es_processus;              (*s_etat_processus).erreur_systeme = d_es_processus;
             return(NULL);              return(NULL);
         }          }
 #       endif  
   
         (*onloading)(&rpl_arguments);          (*onloading)(&rpl_arguments, descripteur_bibliotheque);
   
 #       ifndef SEMAPHORES_NOMMES  #       ifndef SEMAPHORES_NOMMES
         while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)              while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
         {  
             if (errno != EINTR)  
             {  
                 (*s_etat_processus).erreur_systeme = d_es_processus;  
                 return(NULL);  
             }  
         }  
 #       else  #       else
         while(sem_wait((*s_etat_processus).semaphore_fork) == -1)              while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
   #       endif
         {          {
             if (errno != EINTR)              if (errno != EINTR)
             {              {
Line 195  chargement_bibliotheque(struct_processus Line 187  chargement_bibliotheque(struct_processus
                 return(NULL);                  return(NULL);
             }              }
         }          }
 #       endif  
   
         if ((*s_etat_processus).profilage == d_vrai)          if ((*s_etat_processus).profilage == d_vrai)
         {          {
Line 315  chargement_bibliotheque(struct_processus Line 306  chargement_bibliotheque(struct_processus
     }      }
   
     dlerror();      dlerror();
     fonction = dlsym(descripteur_bibliotheque, "__external_symbols");      fonction = dlsym(descripteur_bibliotheque, "___external_symbols");
   
     if (fonction == NULL)      if (fonction == NULL)
     {      {
Line 346  chargement_bibliotheque(struct_processus Line 337  chargement_bibliotheque(struct_processus
      * Ajout des symboles externes       * Ajout des symboles externes
      */       */
   
     if ((tableau = (unsigned char **) (*fonction)((&nombre_symboles),      if ((tableau = (unsigned char **) (*fonction)(&rpl_arguments,
             d_version_rpl)) == NULL)              (&nombre_symboles), d_version_rpl)) == NULL)
     {      {
         /*          /*
          * Nombre symboles :           * Nombre symboles :
Line 373  chargement_bibliotheque(struct_processus Line 364  chargement_bibliotheque(struct_processus
     }      }
   
     if (((*s_etat_processus).s_instructions_externes = realloc(      if (((*s_etat_processus).s_instructions_externes = realloc(
             (*s_etat_processus).s_instructions_externes,              (*s_etat_processus).s_instructions_externes, ((size_t)
             ((*s_etat_processus).nombre_instructions_externes + nombre_symboles)              ((*s_etat_processus).nombre_instructions_externes +
             * sizeof(struct_instruction_externe))) == NULL)              nombre_symboles)) * sizeof(struct_instruction_externe))) == NULL)
     {      {
         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;          (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
         return(NULL);          return(NULL);
Line 383  chargement_bibliotheque(struct_processus Line 374  chargement_bibliotheque(struct_processus
   
     for(i = 0; i < nombre_symboles; i++)      for(i = 0; i < nombre_symboles; i++)
     {      {
           if ((fleche = strstr(tableau[i], "->")) != NULL)
           {
               memcpy(fleche, "to", 2);
               (*s_etat_processus).s_instructions_externes[(*s_etat_processus)
                       .nombre_instructions_externes].position_fleche =
                       fleche - tableau[i];
           }
           else
           {
               (*s_etat_processus).s_instructions_externes[(*s_etat_processus)
                       .nombre_instructions_externes].position_fleche = -1;
           }
   
         (*s_etat_processus).s_instructions_externes[(*s_etat_processus)          (*s_etat_processus).s_instructions_externes[(*s_etat_processus)
                 .nombre_instructions_externes].descripteur_bibliotheque =                  .nombre_instructions_externes].descripteur_bibliotheque =
                 descripteur_bibliotheque;                  descripteur_bibliotheque;
Line 456  chargement_bibliotheque(struct_processus Line 460  chargement_bibliotheque(struct_processus
             [(*s_etat_processus).nombre_instructions_externes - 1]              [(*s_etat_processus).nombre_instructions_externes - 1]
             .nom_bibliotheque);              .nom_bibliotheque);
   
       // La nouvelle bibliothèque est mise en tête de la liste pour que
       // les bibliothèques soient implicitement déchargées dans l'ordre
       // inverse de leur chargement.
   
     (*l_nouvel_element).suivant = (*s_etat_processus).s_bibliotheques;      (*l_nouvel_element).suivant = (*s_etat_processus).s_bibliotheques;
     (*s_etat_processus).s_bibliotheques = l_nouvel_element;      (*s_etat_processus).s_bibliotheques = l_nouvel_element;
   
Line 496  retrait_bibliotheque(struct_processus *s Line 504  retrait_bibliotheque(struct_processus *s
   
     unsigned char               *tampon;      unsigned char               *tampon;
   
     unsigned long               i;      integer8                    i;
     unsigned long               j;      integer8                    j;
     unsigned long               nombre_symboles_residuels;      integer8                    nombre_symboles_residuels;
   
     void                        (*onclosing)(struct_rpl_arguments *);      int                         (*onclosing)(struct_rpl_arguments *, void *);
   
     l_element_courant = (*s_etat_processus).s_bibliotheques;      l_element_courant = (*s_etat_processus).s_bibliotheques;
     presence_bibliotheque = d_faux;      presence_bibliotheque = d_faux;
Line 592  retrait_bibliotheque(struct_processus *s Line 600  retrait_bibliotheque(struct_processus *s
             }              }
   
 #           ifndef SEMAPHORES_NOMMES  #           ifndef SEMAPHORES_NOMMES
             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)                  if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
             {  
                 (*s_etat_processus).erreur_systeme = d_es_processus;  
                 return(d_erreur);  
             }  
 #           else  #           else
             if (sem_post((*s_etat_processus).semaphore_fork) != 0)                  if (sem_post((*s_etat_processus).semaphore_fork) != 0)
   #           endif
             {              {
                 (*s_etat_processus).erreur_systeme = d_es_processus;                  (*s_etat_processus).erreur_systeme = d_es_processus;
                 return(d_erreur);                  return(d_erreur);
             }              }
 #           endif  
   
             (*onclosing)(&rpl_arguments);              (*onclosing)(&rpl_arguments, (*descripteur).descripteur);
   
 #           ifndef SEMAPHORES_NOMMES  #           ifndef SEMAPHORES_NOMMES
             while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)                  while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
             {  
                 if (errno != EINTR)  
                 {  
                     (*s_etat_processus).erreur_systeme = d_es_processus;  
                     return(d_erreur);  
                 }  
             }  
 #           else  #           else
             while(sem_wait((*s_etat_processus).semaphore_fork) == -1)                  while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
   #           endif
             {              {
                 if (errno != EINTR)                  if (errno != EINTR)
                 {                  {
Line 625  retrait_bibliotheque(struct_processus *s Line 623  retrait_bibliotheque(struct_processus *s
                     return(d_erreur);                      return(d_erreur);
                 }                  }
             }              }
 #           endif  
   
             if ((*s_etat_processus).profilage == d_vrai)              if ((*s_etat_processus).profilage == d_vrai)
             {              {
Line 808  retrait_bibliotheque(struct_processus *s Line 805  retrait_bibliotheque(struct_processus *s
             registre = (*s_etat_processus).s_instructions_externes;              registre = (*s_etat_processus).s_instructions_externes;
   
             if (((*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)                      sizeof(struct_instruction_externe))) == NULL)
             {              {
                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;                  (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
Line 874  execution_fonction_de_bibliotheque(struc Line 871  execution_fonction_de_bibliotheque(struc
     logical1                        presence_bibliotheque;      logical1                        presence_bibliotheque;
     logical1                        unicite_symbole;      logical1                        unicite_symbole;
   
     long                            difference;      int                             difference;
     long                            difference_inferieure;      int                             difference_inferieure;
     long                            difference_superieure;      int                             difference_superieure;
     long                            i;  
   
     struct_liste_chainee            *l_element_courant;      struct_liste_chainee            *l_element_courant;
   
     struct_rpl_arguments            rpl_arguments;      struct_rpl_arguments            rpl_arguments;
   
       unsigned char                   *fleche;
     unsigned char                   *nom_fonction_externe;      unsigned char                   *nom_fonction_externe;
     unsigned char                   *tampon;      unsigned char                   *tampon;
   
     unsigned long                   borne_inferieure;      integer8                        borne_inferieure;
     unsigned long                   borne_superieure;      integer8                        borne_superieure;
     unsigned long                   moyenne;      integer8                        i;
     unsigned long                   nombre_iterations_maximal;      integer8                        moyenne;
     unsigned long                   ordre_iteration;      integer8                        nombre_iterations_maximal;
       integer8                        ordre_iteration;
   
     void                            (*fonction)(struct_rpl_arguments *);      int                             (*fonction)(struct_rpl_arguments *);
   
     /*      /*
      * Recherche dichotomique de la définition externe       * Recherche dichotomique de la définition externe
Line 926  execution_fonction_de_bibliotheque(struc Line 924  execution_fonction_de_bibliotheque(struc
         }          }
     }      }
   
       if ((fleche = strstr(nom_fonction, "->")) != NULL)
       {
           memcpy(fleche, "to", 2);
       }
   
     ordre_iteration = 0;      ordre_iteration = 0;
     nombre_iterations_maximal = ((unsigned long)      nombre_iterations_maximal = ((integer8)
             (log((*s_etat_processus).nombre_instructions_externes) / log(2)))              (log((real8) (*s_etat_processus).nombre_instructions_externes) /
             + 2;              log(2))) + 2;
   
     borne_inferieure = 0;      borne_inferieure = 0;
     borne_superieure = (*s_etat_processus).nombre_instructions_externes - 1;      borne_superieure = (*s_etat_processus).nombre_instructions_externes - 1;
Line 939  execution_fonction_de_bibliotheque(struc Line 942  execution_fonction_de_bibliotheque(struc
         moyenne = (borne_inferieure + borne_superieure) / 2;          moyenne = (borne_inferieure + borne_superieure) / 2;
         ordre_iteration++;          ordre_iteration++;
   
         if ((2 * ((unsigned long) ((borne_inferieure + borne_superieure) / 2)))          if ((2 * ((integer8) ((borne_inferieure + borne_superieure) / 2)))
                 == (borne_inferieure + borne_superieure))                  == (borne_inferieure + borne_superieure))
         {          {
             difference = strcmp(nom_fonction, (*s_etat_processus)              difference = strcmp(nom_fonction, (*s_etat_processus)
Line 1026  execution_fonction_de_bibliotheque(struc Line 1029  execution_fonction_de_bibliotheque(struc
         {          {
             i = moyenne;              i = moyenne;
   
             while((unsigned long) i <              while(i < (*s_etat_processus).nombre_instructions_externes)
                     (*s_etat_processus).nombre_instructions_externes)  
             {              {
                 if (strcmp((*s_etat_processus).s_instructions_externes[i]                  if (strcmp((*s_etat_processus).s_instructions_externes[i]
                         .nom, nom_fonction) != 0)                          .nom, nom_fonction) != 0)
Line 1178  execution_fonction_de_bibliotheque(struc Line 1180  execution_fonction_de_bibliotheque(struc
     }      }
   
 #   ifndef SEMAPHORES_NOMMES  #   ifndef SEMAPHORES_NOMMES
     if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)          if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
     {  
         (*s_etat_processus).erreur_systeme = d_es_processus;  
         return(d_faux);  
     }  
 #   else  #   else
     if (sem_post((*s_etat_processus).semaphore_fork) != 0)          if (sem_post((*s_etat_processus).semaphore_fork) != 0)
   #   endif
     {      {
         (*s_etat_processus).erreur_systeme = d_es_processus;          (*s_etat_processus).erreur_systeme = d_es_processus;
         return(d_faux);          return(d_faux);
     }      }
 #   endif  
   
     (*fonction)(&rpl_arguments);      (*fonction)(&rpl_arguments);
   
 #   ifndef SEMAPHORES_NOMMES  #   ifndef SEMAPHORES_NOMMES
     while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)          while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
     {  
         if (errno != EINTR)  
         {  
             (*s_etat_processus).erreur_systeme = d_es_processus;  
             return(d_faux);  
         }  
     }  
 #   else  #   else
     while(sem_wait((*s_etat_processus).semaphore_fork) == -1)          while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
   #   endif
     {      {
         if (errno != EINTR)          if (errno != EINTR)
         {          {
Line 1211  execution_fonction_de_bibliotheque(struc Line 1203  execution_fonction_de_bibliotheque(struc
             return(d_faux);              return(d_faux);
         }          }
     }      }
 #   endif  
   
     if ((*s_etat_processus).profilage == d_vrai)      if ((*s_etat_processus).profilage == d_vrai)
     {      {
Line 1439  empilement_pile_operationnelle(struct_rp Line 1430  empilement_pile_operationnelle(struct_rp
     struct_liste_chainee        *l_ancienne_base_liste;      struct_liste_chainee        *l_ancienne_base_liste;
     struct_liste_chainee        *l_nouvelle_base_liste;      struct_liste_chainee        *l_nouvelle_base_liste;
   
       struct_processus            *s_etat_processus;
   
     l_ancienne_base_liste = (*s_rpl_arguments).l_base_pile;      l_ancienne_base_liste = (*s_rpl_arguments).l_base_pile;
       s_etat_processus = (*s_rpl_arguments).s_etat_processus;
   
     l_nouvelle_base_liste = (struct_liste_chainee *) malloc(      l_nouvelle_base_liste = (struct_liste_chainee *) malloc(
             sizeof(struct_liste_chainee));              sizeof(struct_liste_chainee));
Line 1475  depilement_pile_operationnelle(struct_rp Line 1469  depilement_pile_operationnelle(struct_rp
     struct_liste_chainee        *l_ancienne_base_liste;      struct_liste_chainee        *l_ancienne_base_liste;
     struct_liste_chainee        *l_nouvelle_base_liste;      struct_liste_chainee        *l_nouvelle_base_liste;
   
       struct_processus            *s_etat_processus;
   
     if ((*s_rpl_arguments).l_base_pile == NULL)      if ((*s_rpl_arguments).l_base_pile == NULL)
     {      {
         *s_objet = NULL;          *s_objet = NULL;
Line 1484  depilement_pile_operationnelle(struct_rp Line 1480  depilement_pile_operationnelle(struct_rp
     {      {
         l_ancienne_base_liste = (*s_rpl_arguments).l_base_pile;          l_ancienne_base_liste = (*s_rpl_arguments).l_base_pile;
         l_nouvelle_base_liste = (*l_ancienne_base_liste).suivant;          l_nouvelle_base_liste = (*l_ancienne_base_liste).suivant;
           s_etat_processus = (*s_rpl_arguments).s_etat_processus;
   
         *s_objet = (*l_ancienne_base_liste).donnee;          *s_objet = (*l_ancienne_base_liste).donnee;
         free(l_ancienne_base_liste);          free(l_ancienne_base_liste);
Line 1509  depilement_pile_operationnelle(struct_rp Line 1506  depilement_pile_operationnelle(struct_rp
   
 struct_liste_chainee *  struct_liste_chainee *
 sauvegarde_arguments(struct_rpl_arguments *s_rpl_arguments,  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_ancienne_base_liste;
     struct_liste_chainee            *l_element_courant;      struct_liste_chainee            *l_element_courant;
Line 1527  sauvegarde_arguments(struct_rpl_argument Line 1524  sauvegarde_arguments(struct_rpl_argument
     unsigned char                   indice_drapeau;      unsigned char                   indice_drapeau;
     unsigned char                   taille_bloc;      unsigned char                   taille_bloc;
   
     unsigned long                   i;      integer8                        i;
   
     struct_processus                *s_etat_processus;      struct_processus                *s_etat_processus;
   
Line 1540  sauvegarde_arguments(struct_rpl_argument Line 1537  sauvegarde_arguments(struct_rpl_argument
     indice_bloc = indice_drapeau / taille_bloc;      indice_bloc = indice_drapeau / taille_bloc;
     indice_bit = 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)      if (((*s_rpl_arguments).drapeaux_etat[indice_bloc] & masque) == 0)
     {      {
Line 1638  tri_base_symboles_externes(struct_proces Line 1635  tri_base_symboles_externes(struct_proces
     logical1            terminaison_boucle_2;      logical1            terminaison_boucle_2;
     logical1            terminaison_boucle_3;      logical1            terminaison_boucle_3;
   
     signed long         indice_i;      integer8            borne_inferieure;
     signed long         indice_j;      integer8            borne_superieure;
     signed long         indice_k;      integer8            ecartement;
     signed long         indice_l;      integer8            indice;
       integer8            indice_i;
     unsigned long       borne_inferieure;      integer8            indice_j;
     unsigned long       borne_superieure;      integer8            indice_k;
     unsigned long       ecartement;      integer8            indice_l;
     unsigned long       indice;  
   
     ecartement = (*s_etat_processus).nombre_instructions_externes;      ecartement = (*s_etat_processus).nombre_instructions_externes;
   
Line 1725  tri_base_symboles_externes(struct_proces Line 1721  tri_base_symboles_externes(struct_proces
     {      {
         indice_j = indice_i;          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)                  .nombre_instructions_externes) && (strcmp(((*s_etat_processus)
                 .s_instructions_externes[indice_i]).nom, ((*s_etat_processus)                  .s_instructions_externes[indice_i]).nom, ((*s_etat_processus)
                 .s_instructions_externes[indice_i + 1]).nom) == 0))                  .s_instructions_externes[indice_i + 1]).nom) == 0))
Line 1759  tri_base_symboles_externes(struct_proces Line 1755  tri_base_symboles_externes(struct_proces
         } while(terminaison_boucle == d_faux);          } while(terminaison_boucle == d_faux);
   
         indice_i++;          indice_i++;
     } while((unsigned long) (indice_i + 1) <      } while((indice_i + 1) < (*s_etat_processus).nombre_instructions_externes);
             (*s_etat_processus).nombre_instructions_externes);  
   
     return;      return;
 }  }

Removed from v.1.32  
changed lines
  Added in v.1.79


CVSweb interface <joel.bertrand@systella.fr>