--- rpl/src/instructions_v1.c 2011/07/24 15:43:05 1.29 +++ rpl/src/instructions_v1.c 2013/03/23 16:14:39 1.51 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.1 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.13 + Copyright (C) 1989-2013 Dr. BERTRAND Joël This file is part of RPL/2. @@ -42,7 +42,7 @@ instruction_var(struct_processus *s_etat struct_objet *s_objet_resultat; struct_objet *s_objet_temporaire; - unsigned long nombre_colonnes; + integer8 nombre_colonnes; (*s_etat_processus).erreur_execution = d_ex; @@ -500,16 +500,12 @@ instruction_version(struct_processus *s_ return; } - if (((*(*l_element_courant).donnee).objet = malloc((strlen(d_date_en_rpl) - + 1) * sizeof(unsigned char))) == NULL) + if (((*(*l_element_courant).donnee).objet = date_compilation()) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - strcpy((unsigned char *) (*(*l_element_courant).donnee).objet, - d_date_en_rpl); - /* * Ajout des options de compilation */ @@ -909,7 +905,7 @@ instruction_version(struct_processus *s_ return; } - sprintf(tampon, "%d BITS ABI", sizeof(void *) * 8); + sprintf(tampon, "%zu BITS ABI", sizeof(void *) * 8); if (((*(*l_element_courant).donnee).objet = malloc((strlen(tampon) + 1 ) * sizeof(unsigned char))) == NULL) @@ -973,8 +969,8 @@ instruction_version(struct_processus *s_ void instruction_vars(struct_processus *s_etat_processus) { - int i; - int nb_variables; + integer8 i; + integer8 nb_variables; logical1 variable_partagee; @@ -1027,18 +1023,31 @@ instruction_vars(struct_processus *s_eta (*s_objet_resultat).objet = NULL; l_element_precedent = NULL; - nb_variables = nombre_variables(s_etat_processus, - (*s_etat_processus).s_arbre_variables); + if (pthread_mutex_lock(&mutex_liste_variables_partagees) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } - if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables))) - == NULL) + nb_variables = nombre_variables(s_etat_processus); + + if ((tableau = malloc(((size_t) nb_variables) * + sizeof(struct_tableau_variables))) == NULL) { + liberation_mutexes_arbre_variables_partagees(s_etat_processus, + (*(*s_etat_processus).s_arbre_variables_partagees)); + pthread_mutex_unlock(&mutex_liste_variables_partagees); (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - liste_variables(s_etat_processus, tableau, 0, - (*s_etat_processus).s_arbre_variables); + nb_variables = liste_variables(s_etat_processus, tableau); + + if (pthread_mutex_unlock(&mutex_liste_variables_partagees) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } for(i = 0; i < nb_variables; i++) { @@ -1092,26 +1101,11 @@ instruction_vars(struct_processus *s_eta if (tableau[i].objet == NULL) { - if (pthread_mutex_lock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - if (recherche_variable_partagee(s_etat_processus, tableau[i].nom, tableau[i].variable_partagee, - tableau[i].origine) == d_faux) + tableau[i].origine) == NULL) { // La variable partagée n'existe plus. - - if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - continue; } @@ -1133,13 +1127,19 @@ instruction_vars(struct_processus *s_eta if (variable_partagee == d_vrai) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1156,13 +1156,19 @@ instruction_vars(struct_processus *s_eta if (variable_partagee == d_vrai) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1182,13 +1188,19 @@ instruction_vars(struct_processus *s_eta if (variable_partagee == d_vrai) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1200,13 +1212,19 @@ instruction_vars(struct_processus *s_eta if (variable_partagee == d_vrai) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1226,13 +1244,19 @@ instruction_vars(struct_processus *s_eta if (variable_partagee == d_vrai) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1244,25 +1268,37 @@ instruction_vars(struct_processus *s_eta if (((*(*(*((struct_liste_chainee *) (*((struct_objet *) (*l_element_courant).donnee)).objet)).suivant).suivant) .donnee = copie_objet(s_etat_processus, - (*(*s_etat_processus) - .s_liste_variables_partagees).table[(*(*s_etat_processus) - .s_liste_variables_partagees).position_variable].objet, - 'P')) == NULL) + (*(*s_etat_processus).pointeur_variable_partagee_courante) + .objet, 'P')) == NULL) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_processus; return; } @@ -1276,6 +1312,13 @@ instruction_vars(struct_processus *s_eta .donnee = copie_objet(s_etat_processus, tableau[i].objet, 'P')) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1289,6 +1332,12 @@ instruction_vars(struct_processus *s_eta (*l_element_courant).donnee)).objet)).suivant).suivant) .suivant = allocation_maillon(s_etat_processus)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1297,6 +1346,12 @@ instruction_vars(struct_processus *s_eta (*l_element_courant).donnee)).objet)).suivant).suivant).suivant) .donnee = allocation(s_etat_processus, CHN)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1310,13 +1365,31 @@ instruction_vars(struct_processus *s_eta .suivant).donnee).objet = malloc(7 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - strcpy((unsigned char *) (*(*(*(*(*((struct_liste_chainee *) - (*((struct_objet *) (*l_element_courant).donnee)).objet)) - .suivant).suivant) .suivant).donnee).objet, "STATIC"); + if (tableau[i].variable_masquee == d_vrai) + { + strcpy((unsigned char *) (*(*(*(*(*((struct_liste_chainee *) + (*((struct_objet *) (*l_element_courant).donnee)) + .objet)).suivant).suivant).suivant).donnee).objet, + "SHADOW"); + } + else + { + strcpy((unsigned char *) (*(*(*(*(*((struct_liste_chainee *) + (*((struct_objet *) (*l_element_courant).donnee)) + .objet)).suivant).suivant).suivant).donnee).objet, + "STATIC"); + } } else { @@ -1324,7 +1397,14 @@ instruction_vars(struct_processus *s_eta (*l_element_courant).donnee)).objet)).suivant).suivant) .suivant).donnee).objet = malloc(9 * sizeof(unsigned char))) == NULL) - { + { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1343,6 +1423,12 @@ instruction_vars(struct_processus *s_eta .suivant).suivant = allocation_maillon(s_etat_processus)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1352,6 +1438,12 @@ instruction_vars(struct_processus *s_eta .suivant).donnee = allocation(s_etat_processus, CHN)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1363,6 +1455,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).donnee).objet = malloc(7 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1379,6 +1478,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).donnee).objet = malloc(9 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1398,6 +1504,12 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant = allocation_maillon(s_etat_processus)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1407,6 +1519,12 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).donnee = allocation(s_etat_processus, CHN)) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1418,6 +1536,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant).donnee).objet = malloc(7 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1434,6 +1559,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant).donnee).objet = malloc(8 * sizeof(unsigned char))) == NULL) { + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } @@ -1453,6 +1585,13 @@ instruction_vars(struct_processus *s_eta .suivant).suivant).suivant).suivant = NULL; l_element_precedent = l_element_courant; + + if (tableau[i].mutex != NULL) + { + // La variable est une variable partagée. On libère + // le mutex. + pthread_mutex_unlock(tableau[i].mutex); + } } free(tableau); @@ -1486,7 +1625,7 @@ instruction_visit(struct_processus *s_et struct_objet *s_objet; - unsigned long profondeur_initiale; + integer8 profondeur_initiale; (*s_etat_processus).erreur_execution = d_ex;