Diff for /rpl/src/gestion_variables.c between versions 1.66 and 1.89

version 1.66, 2012/12/18 13:19:35 version 1.89, 2015/01/29 09:33:41
Line 1 Line 1
 /*  /*
 ================================================================================  ================================================================================
   RPL/2 (R) version 4.1.12    RPL/2 (R) version 4.1.20
   Copyright (C) 1989-2012 Dr. BERTRAND Joël    Copyright (C) 1989-2015 Dr. BERTRAND Joël
   
   This file is part of RPL/2.    This file is part of RPL/2.
   
Line 284  allocation_tableau_noeuds(struct_process Line 284  allocation_tableau_noeuds(struct_process
     }      }
     else      else
     {      {
         objet = malloc((*s_etat_processus).nombre_caracteres_variables          objet = malloc(((size_t) (*s_etat_processus)
                   .nombre_caracteres_variables)
                 * sizeof(struct_arbre_variables *));                  * sizeof(struct_arbre_variables *));
     }      }
   
Line 988  recherche_variable(struct_processus *s_e Line 989  recherche_variable(struct_processus *s_e
   
     unsigned char               *ptr;      unsigned char               *ptr;
   
     unsigned long               niveau_appel;      integer8                    niveau_appel;
   
     if ((*s_etat_processus).s_arbre_variables == NULL)      if ((*s_etat_processus).s_arbre_variables == NULL)
     {      {
Line 1203  retrait_variable(struct_processus *s_eta Line 1204  retrait_variable(struct_processus *s_eta
     struct_liste_variables      *variable_a_supprimer;      struct_liste_variables      *variable_a_supprimer;
     struct_liste_variables      *variables_par_niveau;      struct_liste_variables      *variables_par_niveau;
   
     unsigned long               niveau;      integer8                    niveau;
   
     (*s_etat_processus).niveau_supprime = d_faux;      (*s_etat_processus).niveau_supprime = d_faux;
   
Line 1530  retrait_variables_par_niveau(struct_proc Line 1531  retrait_variables_par_niveau(struct_proc
                 break;                  break;
             }              }
   
               if (((*s_etat_processus).at_exit != NULL) &&
                       ((*s_etat_processus).niveau_courant == 0))
               {
                   // Il y a une routine ATEXIT enregistrée. On ne détruit pas
                   // les variables globales qui pourraient y être utilisées.
   
                   break;
               }
   
             while((*(*s_etat_processus).l_liste_variables_par_niveau).liste              while((*(*s_etat_processus).l_liste_variables_par_niveau).liste
                     != NULL)                      != NULL)
             {              {
Line 1789  liberation_arbre_variables(struct_proces Line 1799  liberation_arbre_variables(struct_proces
 ================================================================================  ================================================================================
 */  */
   
 static int  static integer8
 nombre_variables_locales(struct_processus *s_etat_processus,  nombre_variables_locales(struct_processus *s_etat_processus,
         struct_arbre_variables *l_element_courant)          struct_arbre_variables *l_element_courant)
 {  {
     int                                 i;      integer8                            i;
     int                                 n;      integer8                            n;
   
     struct_liste_variables              *l_variable;      struct_liste_variables              *l_variable;
     struct_liste_variables_statiques    *l_variable_statique;      struct_liste_variables_statiques    *l_variable_statique;
Line 1848  nombre_variables_locales(struct_processu Line 1858  nombre_variables_locales(struct_processu
 }  }
   
   
 static int  static integer8
 nombre_variables_partagees(struct_processus *s_etat_processus,  nombre_variables_partagees(struct_processus *s_etat_processus,
         struct_arbre_variables_partagees *l_element_courant)          struct_arbre_variables_partagees *l_element_courant)
 {  {
     int                                 i;      integer8                            i;
     int                                 n;      integer8                            n;
   
     struct_liste_variables_partagees    *l_variable;      struct_liste_variables_partagees    *l_variable;
   
Line 1862  nombre_variables_partagees(struct_proces Line 1872  nombre_variables_partagees(struct_proces
         return(0);          return(0);
     }      }
   
       // Mutex deverrouillé par liste_variables_partagees();
     if (pthread_mutex_lock(&((*l_element_courant).mutex_feuille)) != 0)      if (pthread_mutex_lock(&((*l_element_courant).mutex_feuille)) != 0)
     {      {
         (*s_etat_processus).erreur_systeme = d_es_processus;          (*s_etat_processus).erreur_systeme = d_es_processus;
Line 1894  nombre_variables_partagees(struct_proces Line 1905  nombre_variables_partagees(struct_proces
 }  }
   
   
 int  integer8
 nombre_variables(struct_processus *s_etat_processus)  nombre_variables(struct_processus *s_etat_processus)
 {  {
     return(nombre_variables_locales(s_etat_processus,      return(nombre_variables_locales(s_etat_processus,
Line 1940  liberation_mutexes_arbre_variables_parta Line 1951  liberation_mutexes_arbre_variables_parta
 }  }
   
   
 static int  static integer8
 liste_variables_locales(struct_processus *s_etat_processus,  liste_variables_locales(struct_processus *s_etat_processus,
         struct_tableau_variables *tableau, int position,          struct_tableau_variables *tableau, integer8 position,
         struct_arbre_variables *l_element_courant)          struct_arbre_variables *l_element_courant)
 {  {
     int                                 i;      integer8                            i;
   
     struct_liste_variables              *l_variable;      struct_liste_variables              *l_variable;
     struct_liste_variables_statiques    *l_variable_statique;      struct_liste_variables_statiques    *l_variable_statique;
   
     if (l_element_courant == NULL)      if (l_element_courant == NULL)
     {      {
         return(0);          return(position);
     }      }
   
     if ((*l_element_courant).feuille != NULL)      if ((*l_element_courant).feuille != NULL)
Line 1972  liste_variables_locales(struct_processus Line 1983  liste_variables_locales(struct_processus
             tableau[position].variable_partagee =              tableau[position].variable_partagee =
                     (*(*l_variable).variable).variable_partagee;                      (*(*l_variable).variable).variable_partagee;
             tableau[position].variable_masquee = d_faux;              tableau[position].variable_masquee = d_faux;
               tableau[position].mutex = NULL;
   
             position++;              position++;
   
             l_variable = (*l_variable).suivant;              l_variable = (*l_variable).suivant;
         } while(l_variable != (*l_element_courant).feuille);          } while(l_variable != (*l_element_courant).feuille);
     }      }
Line 1990  liste_variables_locales(struct_processus Line 2003  liste_variables_locales(struct_processus
                 tableau[position].nom = (*(*l_variable_statique).variable).nom;                  tableau[position].nom = (*(*l_variable_statique).variable).nom;
                 tableau[position].niveau =                  tableau[position].niveau =
                         (*(*l_variable_statique).variable).niveau;                          (*(*l_variable_statique).variable).niveau;
                 tableau[position].objet =                  tableau[position].objet = (*(*l_variable_statique).variable)
                         (*(*l_variable_statique).variable).objet;                          .objet;
                 tableau[position].variable_verrouillee = d_faux;                  tableau[position].variable_verrouillee = d_faux;
                 tableau[position].variable_statique =                  tableau[position].variable_statique =
                         (*(*l_variable_statique).variable).variable_statique;                          (*(*l_variable_statique).variable).variable_statique;
                 tableau[position].variable_partagee.pointeur = NULL;                  tableau[position].variable_partagee.pointeur = NULL;
                 tableau[position].variable_masquee = d_vrai;                  tableau[position].variable_masquee = d_vrai;
                   tableau[position].mutex = NULL;
   
                 position++;                  position++;
             }              }
Line 2018  liste_variables_locales(struct_processus Line 2032  liste_variables_locales(struct_processus
 }  }
   
   
 static int  static integer8
 liste_variables_partagees(struct_processus *s_etat_processus,  liste_variables_partagees(struct_processus *s_etat_processus,
         struct_tableau_variables *tableau, int position,          struct_tableau_variables *tableau, integer8 position,
         struct_arbre_variables_partagees *l_element_courant)          struct_arbre_variables_partagees *l_element_courant)
 {  {
     int                                 i;      integer8                            i;
   
     struct_liste_variables_partagees    *l_variable;      struct_liste_variables_partagees    *l_variable;
   
     if (l_element_courant == NULL)      if (l_element_courant == NULL)
     {      {
         return(0);          return(position);
     }      }
   
     if ((*l_element_courant).feuille != NULL)      if ((*l_element_courant).feuille != NULL)
Line 2045  liste_variables_partagees(struct_process Line 2059  liste_variables_partagees(struct_process
             tableau[position].variable_verrouillee = d_faux;              tableau[position].variable_verrouillee = d_faux;
             tableau[position].variable_partagee =              tableau[position].variable_partagee =
                     (*(*l_variable).variable).variable_partagee;                      (*(*l_variable).variable).variable_partagee;
             tableau[position].variable_partagee.pointeur = NULL;              tableau[position].variable_statique.pointeur = NULL;
             tableau[position].variable_masquee = d_faux;              tableau[position].variable_masquee = d_faux;
               tableau[position].mutex = &((*(*l_variable).variable).mutex);
               pthread_mutex_lock(tableau[position].mutex);
   
             position++;              position++;
   
Line 2063  liste_variables_partagees(struct_process Line 2079  liste_variables_partagees(struct_process
         }          }
     }      }
   
       // Mutex verrouillé par nombre_variables_partagees();
       if (pthread_mutex_unlock(&((*l_element_courant).mutex_feuille)) != 0)
       {
           (*s_etat_processus).erreur_systeme = d_es_processus;
           return(0);
       }
   
     return(position);      return(position);
 }  }
   
Line 2086  fonction_ordre_variables(const void *arg Line 2109  fonction_ordre_variables(const void *arg
     }      }
     else      else
     {      {
         return((*a1).niveau - (*a2).niveau);          return(((((*a1).niveau - (*a2).niveau)) > 0) ? 1 : -1);
     }      }
 }  }
   
   
 int  integer8
 liste_variables(struct_processus *s_etat_processus,  liste_variables(struct_processus *s_etat_processus,
         struct_tableau_variables *tableau)          struct_tableau_variables *tableau)
 {  {
     int     nombre_elements;      integer8        nombre_elements;
   
     nombre_elements = liste_variables_locales(s_etat_processus,      nombre_elements = liste_variables_locales(s_etat_processus,
             tableau, 0, (*s_etat_processus).s_arbre_variables);              tableau, 0, (*s_etat_processus).s_arbre_variables);
     nombre_elements += liste_variables_partagees(s_etat_processus,      nombre_elements = liste_variables_partagees(s_etat_processus,
             tableau, nombre_elements, (*(*s_etat_processus)              tableau, nombre_elements, (*(*s_etat_processus)
             .s_arbre_variables_partagees));              .s_arbre_variables_partagees));
   
     qsort(tableau, nombre_elements, sizeof(struct_tableau_variables),      qsort(tableau, (size_t) nombre_elements, sizeof(struct_tableau_variables),
             fonction_ordre_variables);              fonction_ordre_variables);
   
     return(nombre_elements);      return(nombre_elements);
Line 2213  copie_arbre_variables(struct_processus * Line 2236  copie_arbre_variables(struct_processus *
                     s_variable = (*((struct_variable *)                      s_variable = (*((struct_variable *)
                             (*l_element_courant).donnee));                              (*l_element_courant).donnee));
   
                     if ((s_variable.nom = strdup((*((struct_variable *)                      if ((s_variable.nom = malloc((strlen((*((struct_variable *)
                             (*l_element_courant).donnee)).nom)) == NULL)                              (*l_element_courant).donnee)).nom) + 1) *
                               sizeof(unsigned char))) == NULL)
                     {                      {
                         (*s_nouvel_etat_processus).erreur_systeme =                          (*s_nouvel_etat_processus).erreur_systeme =
                                 d_es_allocation_memoire;                                  d_es_allocation_memoire;
                         return;                          return;
                     }                      }
   
                       strcpy(s_variable.nom, (*((struct_variable *)
                               (*l_element_courant).donnee)).nom);
   
                     if ((s_variable.objet = copie_objet(s_nouvel_etat_processus,                      if ((s_variable.objet = copie_objet(s_nouvel_etat_processus,
                             (*((struct_variable *) (*l_element_courant).donnee))                              (*((struct_variable *) (*l_element_courant).donnee))
                             .objet, 'P')) == NULL)                              .objet, 'P')) == NULL)
Line 2426  copie_arbre_variables(struct_processus * Line 2453  copie_arbre_variables(struct_processus *
 */  */
   
 /*  /*
  * Caractères autorisés dans les instructions   * Caractères autorisés dans les variables
  *   *
  * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z   * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  * a b c d e f g h i j k l m n o p q r s t u v w x y z   * a b c d e f g h i j k l m n o p q r s t u v w x y z
Line 2456  initialisation_variables(struct_processu Line 2483  initialisation_variables(struct_processu
     }      }
   
     if (((*s_etat_processus).pointeurs_caracteres_variables =      if (((*s_etat_processus).pointeurs_caracteres_variables =
             malloc(longueur_tableau * sizeof(int))) == NULL)              malloc(((size_t) longueur_tableau) * sizeof(int))) == NULL)
     {      {
         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;          (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
         return;          return;

Removed from v.1.66  
changed lines
  Added in v.1.89


CVSweb interface <joel.bertrand@systella.fr>