--- rpl/src/rpl.c 2017/07/02 22:28:20 1.194 +++ rpl/src/rpl.c 2017/07/04 10:28:08 1.195 @@ -86,6 +86,10 @@ rplinit(int argc, char *argv[], char *en struct_processus *s_etat_processus; + struct_liste_chainee *l_bibliotheques; + struct_liste_chainee *l_bibliotheque_courante; + struct_liste_chainee *l_nouvelle_bibliotheque; + struct_liste_variables_partagees *l_element_partage_courant; struct_liste_variables_partagees *l_element_partage_suivant; @@ -125,6 +129,7 @@ rplinit(int argc, char *argv[], char *en routine_recursive = 0; nombre_thread_surveillance_processus = 0; pid_processus_pere = getpid(); + affichage_rplso = d_vrai; # ifdef DEBUG_PROC __proc = 0; @@ -1004,6 +1009,7 @@ rplinit(int argc, char *argv[], char *en drapeau_encart = 'Y'; debug = d_faux; arguments = NULL; + l_bibliotheques = NULL; (*s_etat_processus).s_fichiers = NULL; (*s_etat_processus).s_sockets = NULL; @@ -1594,6 +1600,301 @@ rplinit(int argc, char *argv[], char *en break; } + case 'm' : + { + while(*(++argv[0]) == ' '); + argv[0]--; + + if ((*(++argv[0])) != '\0') + { + if ((l_nouvelle_bibliotheque = malloc( + sizeof(struct_liste_chainee))) == NULL) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + (*l_nouvelle_bibliotheque).suivant = + l_bibliotheques; + + if (((*l_nouvelle_bibliotheque).donnee = + allocation(s_etat_processus, CHN)) + == NULL) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + if (((*(*l_nouvelle_bibliotheque).donnee) + .objet = malloc((strlen(argv[0]) + 1) * + sizeof(unsigned char))) == NULL) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + strcpy((*(*l_nouvelle_bibliotheque).donnee) + .objet, argv[0]); + argv[0] += strlen((unsigned char *) + (*(*l_nouvelle_bibliotheque).donnee) + .objet) - 1; + + l_bibliotheques = l_nouvelle_bibliotheque; + } + else if ((--argc) > 0) + { + argv++; + + if ((l_nouvelle_bibliotheque = malloc( + sizeof(struct_liste_chainee))) == NULL) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + (*l_nouvelle_bibliotheque).suivant = + l_bibliotheques; + + if (((*l_nouvelle_bibliotheque).donnee = + allocation(s_etat_processus, CHN)) + == NULL) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + if (((*(*l_nouvelle_bibliotheque).donnee) + .objet = malloc((strlen(argv[0]) + 1) * + sizeof(unsigned char))) == NULL) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + strcpy((*(*l_nouvelle_bibliotheque).donnee) + .objet, argv[0]); + argv[0] += strlen((unsigned char *) + (*(*l_nouvelle_bibliotheque).donnee) + .objet) - 1; + + l_bibliotheques = l_nouvelle_bibliotheque; + } + else + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus).semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus).semaphore_fork); + sem_destroy3((*s_etat_processus).semaphore_fork, + getpid(), pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Erreur : Aucune bibliothèque " + "spécifiée après l'option -A\n"); + } + else + { + printf("+++Error : Library required after " + "-m option\n"); + } + + return(EXIT_FAILURE); + } + + break; + } + case 'n' : { if (option_n == d_vrai) @@ -3765,6 +4066,140 @@ rplinit(int argc, char *argv[], char *en } } + /* + * Chargement des bibliothèques pour gérer des + * types externes lors des l'analyse syntaxique et + * compilation. + */ + + l_bibliotheque_courante = l_bibliotheques; + + while(l_bibliotheque_courante != NULL) + { + if (empilement(s_etat_processus, &((*s_etat_processus) + .l_base_pile), (*l_bibliotheque_courante) + .donnee) == d_erreur) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus).semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus).semaphore_fork); + sem_destroy3((*s_etat_processus).semaphore_fork, + getpid(), pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + +# ifdef HAVE_SIGSEGV_RECOVERY + if (debug == d_faux) + { + sigsegv_deinstall_handler(); + } +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Fatal :" + " Chargement de la bibliothèse %s" + " impossible\n", (unsigned char *) + (*(*l_bibliotheque_courante).donnee) + .objet); + } + else + { + printf("+++Fatal : Cannot load library %s\n", + (*(*l_bibliotheque_courante).donnee) + .objet); + } + + if (traitement_fichier_temporaire == 'Y') + { + if (destruction_fichier( + nom_fichier_temporaire) + == d_erreur) + { + return(EXIT_FAILURE); + } + + free(nom_fichier_temporaire); + } + + return(EXIT_FAILURE); + } + + affichage_rplso = d_faux; + instruction_use(s_etat_processus); + affichage_rplso = d_vrai; + + if (depilement(s_etat_processus, &((*s_etat_processus) + .l_base_pile), &((*l_bibliotheque_courante) + .donnee)) == d_erreur) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus).semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus).semaphore_fork); + sem_destroy3((*s_etat_processus).semaphore_fork, + getpid(), pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas(s_etat_processus); + destruction_queue_signaux(s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + +# ifdef HAVE_SIGSEGV_RECOVERY + if (debug == d_faux) + { + sigsegv_deinstall_handler(); + } +# endif + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Fatal :" + " Chargement de la bibliothèse %s" + " impossible\n", (unsigned char *) + (*(*l_bibliotheque_courante).donnee) + .objet); + } + else + { + printf("+++Fatal : Cannot load library %s\n", + (*(*l_bibliotheque_courante).donnee) + .objet); + } + + if (traitement_fichier_temporaire == 'Y') + { + if (destruction_fichier( + nom_fichier_temporaire) + == d_erreur) + { + return(EXIT_FAILURE); + } + + free(nom_fichier_temporaire); + } + + return(EXIT_FAILURE); + } + + l_bibliotheque_courante = + (*l_bibliotheque_courante).suivant; + } + if ((erreur = compilation(s_etat_processus)) != d_absence_erreur) { @@ -4650,6 +5085,73 @@ rplinit(int argc, char *argv[], char *en { if (setjmp(contexte_initial) == 0) { + // Libération des bibliothèques + + l_bibliotheque_courante = l_bibliotheques; + + while(l_bibliotheque_courante != NULL) + { + if (empilement(s_etat_processus, + &((*s_etat_processus).l_base_pile), + (*l_bibliotheque_courante).donnee) + == d_erreur) + { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus) + .semaphore_fork)); + sem_destroy(&((*s_etat_processus) + .semaphore_fork)); +# else + sem_post((*s_etat_processus) + .semaphore_fork); + sem_destroy3((*s_etat_processus) + .semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif + + liberation_contexte_cas( + s_etat_processus); + destruction_queue_signaux( + s_etat_processus); + +# ifdef HAVE_STACK_OVERFLOW_RECOVERY + stackoverflow_deinstall_handler(); +# endif + +# ifdef HAVE_SIGSEGV_RECOVERY + if (debug == d_faux) + { + sigsegv_deinstall_handler(); + } +# endif + + erreur = d_es_allocation_memoire; + + if ((*s_etat_processus).langue == 'F') + { + printf("+++Système : Mémoire " + "insuffisante\n"); + } + else + { + printf("+++System : Not enough " + "memory\n"); + } + + return(EXIT_FAILURE); + } + + affichage_rplso = d_faux; + instruction_remove(s_etat_processus); + affichage_rplso = d_vrai; + + l_nouvelle_bibliotheque = + (*l_bibliotheque_courante).suivant; + free(l_bibliotheque_courante); + l_bibliotheque_courante = + l_nouvelle_bibliotheque; + } + erreur = sequenceur(s_etat_processus); if (erreur == d_absence_erreur) @@ -4751,7 +5253,8 @@ rplinit(int argc, char *argv[], char *en { if (setjmp(contexte_initial) == 0) { - erreur = sequenceur_optimise(s_etat_processus); + erreur = sequenceur_optimise(s_etat_processus, + l_bibliotheques); if (erreur == d_absence_erreur) {