version 1.1.1.1, 2010/01/26 15:22:44
|
version 1.75, 2017/07/31 12:03:30
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.9 |
RPL/2 (R) version 4.1.27 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2017 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 20
|
Line 20
|
*/ |
*/ |
|
|
|
|
#include "rpl.conv.h" |
#include "rpl-conv.h" |
|
|
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
|
|
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 *); |
char **(*fonction)(struct_rpl_arguments *, |
|
integer8 *, const char *); |
char *message; |
char *message; |
|
|
|
integer8 i; |
|
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; |
|
|
unsigned long nombre_symboles; |
|
unsigned long i; |
|
|
|
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 161 chargement_bibliotheque(struct_processus
|
Line 163 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; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return(NULL); |
return(NULL); |
} |
} |
|
|
(*onloading)(&rpl_arguments); |
(*onloading)(&rpl_arguments, descripteur_bibliotheque); |
|
|
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) |
if (errno != EINTR) |
{ |
{ |
Line 296 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 315 chargement_bibliotheque(struct_processus
|
Line 325 chargement_bibliotheque(struct_processus
|
} |
} |
} |
} |
|
|
|
dlerror(); |
|
|
if (pthread_mutex_unlock(&mutex) != 0) |
if (pthread_mutex_unlock(&mutex) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 325 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)) == 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) |
if (nombre_symboles == 0) |
{ |
{ |
(*s_etat_processus).erreur_execution = d_ex_aucun_symbole; |
(*s_etat_processus).erreur_execution = d_ex_aucun_symbole; |
} |
} |
|
else if (nombre_symboles == -1) |
|
{ |
|
(*s_etat_processus).erreur_execution = d_ex_version_bibliotheque; |
|
} |
else |
else |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
Line 340 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 350 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) |
|
{ |
|
strncpy(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 380 chargement_bibliotheque(struct_processus
|
Line 417 chargement_bibliotheque(struct_processus
|
strcpy((*s_etat_processus).s_instructions_externes[(*s_etat_processus) |
strcpy((*s_etat_processus).s_instructions_externes[(*s_etat_processus) |
.nombre_instructions_externes].nom_bibliotheque, tableau[i]); |
.nombre_instructions_externes].nom_bibliotheque, tableau[i]); |
(*s_etat_processus).nombre_instructions_externes++; |
(*s_etat_processus).nombre_instructions_externes++; |
|
|
free(tableau[i]); |
free(tableau[i]); |
} |
} |
|
|
Line 422 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 462 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 557 retrait_bibliotheque(struct_processus *s
|
Line 599 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; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return(d_erreur); |
return(d_erreur); |
} |
} |
|
|
(*onclosing)(&rpl_arguments); |
(*onclosing)(&rpl_arguments, (*descripteur).descripteur); |
|
|
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) |
if (errno != EINTR) |
{ |
{ |
Line 755 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 821 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 873 execution_fonction_de_bibliotheque(struc
|
Line 924 execution_fonction_de_bibliotheque(struc
|
} |
} |
} |
} |
|
|
|
if ((fleche = strstr(nom_fonction, "->")) != NULL) |
|
{ |
|
strncpy(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 886 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 973 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 1067 execution_fonction_de_bibliotheque(struc
|
Line 1122 execution_fonction_de_bibliotheque(struc
|
} |
} |
} |
} |
|
|
|
dlerror(); |
|
|
if (pthread_mutex_unlock(&mutex) != 0) |
if (pthread_mutex_unlock(&mutex) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
Line 1122 execution_fonction_de_bibliotheque(struc
|
Line 1179 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; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return(d_faux); |
return(d_faux); |
Line 1130 execution_fonction_de_bibliotheque(struc
|
Line 1191 execution_fonction_de_bibliotheque(struc
|
|
|
(*fonction)(&rpl_arguments); |
(*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) |
if (errno != EINTR) |
{ |
{ |
Line 1365 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 1401 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 1410 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 1435 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 1453 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 1466 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 1564 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 1593 tri_base_symboles_externes(struct_proces
|
Line 1663 tri_base_symboles_externes(struct_proces
|
do |
do |
{ |
{ |
indice_i = indice_j; |
indice_i = indice_j; |
|
|
terminaison_boucle_3 = d_faux; |
terminaison_boucle_3 = d_faux; |
|
|
do |
do |
Line 1652 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 1686 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_variables); |
|
|
|
return; |
return; |
} |
} |