--- rpl/src/rpl.h 2014/10/05 19:53:16 1.251 +++ rpl/src/rpl.h 2015/07/18 12:32:03 1.273 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.19 - Copyright (C) 1989-2014 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.22 + Copyright (C) 1989-2015 Dr. BERTRAND Joël This file is part of RPL/2. @@ -38,6 +38,10 @@ # ifdef OpenBSD # define _BSD_SOURCE # endif + +# ifdef FreeBSD +# define __BSD_VISIBLE 1 +# endif #endif #ifdef OS2 @@ -212,7 +216,6 @@ # undef HAVE_STACK_OVERFLOW_RECOVERY # endif -# define HAVE_INLINE # define GSL_RANGE_CHECK_OFF # include "gsl/gsl_cdf.h" # include "gsl/gsl_cblas.h" @@ -347,11 +350,6 @@ __EXTERN__ int f_queue_signaux; # endif #endif -#ifdef OS2 -# define readline(s) readline_wrapper(s) - unsigned char *readline_wrapper(unsigned char *s); -#endif - #if ! defined(UNION_SEMUN) && defined(IPCS_SYSV) union semun { @@ -370,6 +368,7 @@ union semun # define SIGSTKSZ 65536 #endif + /* ================================================================================ SÉMAPHORES @@ -525,7 +524,7 @@ union semun __EXTERN__ volatile int routine_recursive; -# define SEM_FORK 0 +# define SEM_FORK 0 # define SEM_QUEUE 1 # define SEM_SIGNALISATION 2 # define SEM_ARRET_SIGNALISATION 3 @@ -568,10 +567,8 @@ union semun stderr, __VA_ARGS__) #define fprintf(flux, ...) transliterated_fprintf(s_etat_processus, \ flux, __VA_ARGS__) -#define uprintf(...) transliterated_fprintf(NULL, \ - stderr, __VA_ARGS__) -#define ufprintf(flux, ...) transliterated_fprintf(NULL, \ - flux, __VA_ARGS__) +#define uprintf(...) std_fprintf(stderr, __VA_ARGS__) +#define ufprintf(flux, ...) std_fprintf(flux, __VA_ARGS__) #ifdef SunOS # define fopen(...) ({ FILE *desc; \ @@ -653,7 +650,7 @@ union semun { \ for(i = 0; i < nb; i++) \ uprintf(" %s\n", appels[i]); \ - free(appels); \ + sys_free(appels); \ } \ else \ uprintf("Nullified backtrace\n"); \ @@ -1057,7 +1054,7 @@ enum t_type { ADR = 0, ALG, BIN, CHN, C Sans objet. Type C/Fortran : unsigned integer8 - CHN : chaine de caracteres (character*(*), unsigned char *) + CHN : chaine de caracteres (unsigned char *) Sans objet. CPL : complexe sur 2*64 bits (complex*16, struct_complexe16 *) @@ -1706,10 +1703,10 @@ typedef struct tableau typedef struct arbre { - struct_objet *objet; + struct_liste_chainee *feuille; - unsigned long nombre_feuilles; - struct arbre **feuilles; + integer8 nombre_branches; + struct arbre **branches; } struct_arbre; @@ -1890,6 +1887,42 @@ typedef struct liste_variables_partagees } struct_liste_variables_partagees; #endif + +/* +-------------------------------------------------------------------------------- + Structure fonction +-------------------------------------------------------------------------------- +*/ + +#ifndef RPLARGS +typedef struct fonction +{ + unsigned char *nom_fonction; + integer8 nombre_arguments; + + void (*fonction)(struct processus *); + + volatile struct_liste_chainee *prediction_saut; + volatile logical1 prediction_execution; +} struct_fonction; +#endif + + +/* +-------------------------------------------------------------------------------- + Structure buffer +-------------------------------------------------------------------------------- +*/ + +typedef struct buffer +{ + unsigned char *buffer; + + size_t longueur_requise; + int classe; +} struct_buffer; + + /* -------------------------------------------------------------------------------- Structure processus @@ -2327,6 +2360,7 @@ typedef struct processus struct timeval horodatage_profilage; pthread_mutex_t mutex_allocation; + pthread_mutex_t mutex_allocation_buffer; pthread_mutex_t mutex_interruptions; pthread_mutex_t mutex_pile_processus; pthread_mutex_t mutex_signaux; @@ -2361,82 +2395,67 @@ typedef struct processus integer8 taille_pile_objets; struct_objet *pile_objets; -# define TAILLE_CACHE 1024 - - integer8 *objets_adr[TAILLE_CACHE]; - int pointeur_adr; - - logical8 *objets_bin[TAILLE_CACHE]; - int pointeur_bin; - - complex16 *objets_cpl[TAILLE_CACHE]; - int pointeur_cpl; - - struct fonction *objets_fct[TAILLE_CACHE]; - int pointeur_fct; - - integer8 *objets_int[TAILLE_CACHE]; - int pointeur_int; - - struct_matrice *objets_mat[TAILLE_CACHE]; - int pointeur_mat; - - struct_nom *objets_nom[TAILLE_CACHE]; - int pointeur_nom; - - real8 *objets_rel[TAILLE_CACHE]; - int pointeur_rel; - - struct_tableau *objets_tab[TAILLE_CACHE]; - int pointeur_tab; - - struct_vecteur *objets_vec[TAILLE_CACHE]; - int pointeur_vec; - - struct_liste_chainee *maillons[TAILLE_CACHE]; - int pointeur_maillons; - - struct_arbre_variables *variables_noeud[TAILLE_CACHE]; - int pointeur_variables_noeud; - - struct_arbre_variables_partagees - *variables_partagees_noeud[TAILLE_CACHE]; - int pointeur_variables_partagees_noeud; - - struct_liste_variables *variables_feuille[TAILLE_CACHE]; - int pointeur_variables_feuille; - - struct_variable *variables_variable[TAILLE_CACHE]; - int pointeur_variables_variable; - - struct_arbre_variables **variables_tableau_noeuds[TAILLE_CACHE]; - int pointeur_variables_tableau_noeuds; - - struct_arbre_variables_partagees - **variables_tableau_noeuds_partages - [TAILLE_CACHE]; - int pointeur_variables_tableau_noeuds_partages; +# define TAILLE_CACHE 1024 +# define CACHE(type, nom) \ + type *objets_##nom[TAILLE_CACHE]; \ + volatile int pointeur_##nom; + +# define CACHE2(type, nom) \ + type *nom[TAILLE_CACHE]; \ + volatile int pointeur_##nom; + + CACHE(integer8, adr) + CACHE(logical8, bin) + CACHE(complex16, cpl) + CACHE(struct_fonction, fct) + CACHE(integer8, int) + CACHE(struct_matrice, mat) + CACHE(struct_nom, nom) + CACHE(real8, rel) + CACHE(struct_tableau, tab) + CACHE(struct_vecteur, vec) + + CACHE2(struct_liste_chainee, maillons) + CACHE2(struct_arbre_variables, variables_noeud) + CACHE2(struct_arbre_variables_partagees, variables_partagees_noeud) + CACHE2(struct_liste_variables, variables_feuille) + CACHE2(struct_variable, variables_variable) + CACHE2(struct_arbre_variables *, variables_tableau_noeuds) + CACHE2(struct_arbre_variables_partagees *, + variables_tableau_noeuds_partages) + + CACHE2(struct_buffer, enveloppes_buffers) + unsigned char ***cache_buffer; + int *pointeur_cache_buffer; } struct_processus; #endif + /* --------------------------------------------------------------------------------- - Structure fonction --------------------------------------------------------------------------------- -*/ +================================================================================ + MISE EN PLACE DE L'ALLOCATEUR SPÉCIFIQUE +================================================================================*/ -#ifndef RPLARGS -typedef struct fonction -{ - unsigned char *nom_fonction; - integer8 nombre_arguments; +#ifndef DEBUG_MEMOIRE +# define malloc(a) rpl_malloc(s_etat_processus, a) +# define realloc(a, b) rpl_realloc(s_etat_processus, a, b) +# define free(a) rpl_free(s_etat_processus, a) +#endif - void (*fonction)(struct_processus *); +void *rpl_malloc(struct_processus *s_etat_processus, size_t s); +void *rpl_realloc(struct_processus *s_etat_processus, void *ptr, size_t s); +void rpl_free(struct_processus *s_etat_processus, void *ptr); +void *sys_malloc(size_t s); +void sys_free(void *ptr); - volatile struct_liste_chainee *prediction_saut; - volatile logical1 prediction_execution; -} struct_fonction; -#endif +/* + * Wrapper de readline() pour que la fonction renvoie un pointeur sur un + * buffer alloué par rpl_malloc(). + */ + +#define readline(s) readline_wrapper(s_etat_processus, s) +unsigned char *readline_wrapper(struct_processus *s_etat_processus, + unsigned char *s); /* @@ -3010,12 +3029,14 @@ void conversion_chaine(struct_processus unsigned char *chaine, unsigned char type); void conversion_decimal_vers_hms(real8 *angle); void conversion_degres_vers_radians(real8 *angle); -void conversion_element_tex(unsigned char **element, unsigned char *fonction); +void conversion_element_tex(struct_processus *s_etat_processus, + unsigned char **element, unsigned char *fonction); void conversion_format(struct_processus *s_etat_processus, unsigned char *chaine); void conversion_hms_vers_decimal(real8 *angle); -void conversion_majuscule_limitee(unsigned char *chaine_entree, - unsigned char *chaine_sortie, integer8 longueur); +void conversion_majuscule_limitee( + unsigned char *chaine_entree, unsigned char *chaine_sortie, + integer8 longueur); void conversion_radians_vers_degres(real8 *angle); void copie_arbre_variables(struct_processus *s_etat_processus, struct_processus *s_nouvel_etat_processus); @@ -3206,16 +3227,20 @@ real8 correlation_statistique(struct_mat real8 covariance_statistique(struct_matrice *s_matrice, integer8 colonne_1, integer8 colonne_2, unsigned char type, logical1 *erreur); -struct_vecteur *ecart_type_statistique(struct_matrice *s_matrice, - unsigned char type); -struct_vecteur *moyenne_statistique(struct_matrice *s_matrice); -struct_vecteur *sommation_colonne_statistique(struct_matrice *s_matrice, +struct_vecteur *ecart_type_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice, unsigned char type); +struct_vecteur *moyenne_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice); +struct_vecteur *sommation_colonne_statistique( + struct_processus *s_etat_processus, struct_matrice *s_matrice, integer8 colonne); -struct_vecteur *sommation_produits_colonnes_statistiques(struct_matrice +struct_vecteur *sommation_produits_colonnes_statistiques( + struct_processus *s_etat_processus, struct_matrice *s_matrice, integer8 colonne_1, integer8 colonne_2); -struct_vecteur *sommation_statistique(struct_matrice *s_matrice); -struct_vecteur *variance_statistique(struct_matrice *s_matrice, - unsigned char type); +struct_vecteur *sommation_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice); +struct_vecteur *variance_statistique(struct_processus *s_etat_processus, + struct_matrice *s_matrice, unsigned char type); #endif /* @@ -3251,17 +3276,21 @@ unsigned char *analyse_algebrique(struct unsigned char *chaine_algebrique, struct_liste_chainee **l_base_liste); unsigned char *analyse_flux(struct_processus *s_etat_processus, unsigned char *flux, integer8 longueur); -unsigned char *chiffrement(const EVP_CIPHER *type_chiffrement, +unsigned char *chiffrement(struct_processus *s_etat_processus, + const EVP_CIPHER *type_chiffrement, logical1 encodage, unsigned char *message, integer8 longueur_message, unsigned char *clef, integer8 longueur_clef, unsigned char *vecteur_initialisation, integer8 *longueur_message_chiffre); -unsigned char *compactage(unsigned char *chaine); -unsigned char *conversion_majuscule(unsigned char *chaine); +unsigned char *compactage(struct_processus *s_etat_processus, + unsigned char *chaine); +unsigned char *conversion_majuscule(struct_processus *s_etat_processus, + unsigned char *chaine); unsigned char *creation_nom_fichier(struct_processus *s_etat_processus, unsigned char *chemin); -unsigned char *date_compilation(); -unsigned char *extraction_chaine(unsigned char *chaine, integer8 i, integer8 j); +unsigned char *date_compilation(struct_processus *s_etat_processus); +unsigned char *extraction_chaine(struct_processus *s_etat_processus, + unsigned char *chaine, integer8 i, integer8 j); unsigned char *formateur(struct_processus *s_etat_processus, long offset, struct_objet *s_objet); unsigned char *formateur_fichier(struct_processus *s_etat_processus, @@ -3287,7 +3316,8 @@ unsigned char *formateur_reel(struct_pro unsigned char *messages(struct_processus *s_etat_processus); unsigned char *pointeur_ieme_caractere(struct_processus *s_etat_processus, unsigned char *chaine, integer8 position); -unsigned char *purification_chaine(unsigned char *chaine); +unsigned char *purification_chaine(struct_processus *s_etat_processus, + unsigned char *chaine); unsigned char *recherche_chemin_fichiers_temporaires(struct_processus *s_etat_processus); unsigned char *reencodage(struct_processus *s_etat_processus, @@ -3401,20 +3431,28 @@ ssize_t write_atomic(struct_processus *s -------------------------------------------------------------------------------- */ -int alsprintf(unsigned char **strp, const char *fmt, ...); +int alsprintf(struct_processus *s_etat_processus, + unsigned char **strp, const char *fmt, ...); +#ifndef RPLARGS +int association_etat_processus_readline(); +#endif int interruption_violation_access(void *adresse_fautive, int gravite); #ifndef RPLARGS +int initialisation_etat_processus_readline(); +int liberation_etat_processus_readline(); integer8 liste_variables(struct_processus *s_etat_processus, struct_tableau_variables *tableau); integer8 nombre_variables(struct_processus *s_etat_processus); int readline_analyse_syntaxique(int count, int key); int readline_effacement(int count, int key); #endif +int std_fprintf(file *flux, const char *format, ...); int tex_fprintf(struct_processus *s_etat_processus, file *flux, const char *format, ...); int transliterated_fprintf(struct_processus *s_etat_processus, file *flux, const char *format, ...); -int valsprintf(unsigned char **strp, const char *fmt, va_list ap); +int valsprintf(struct_processus *s_etat_processus, + unsigned char **strp, const char *fmt, va_list ap); int wrapper_instruction_intrinseque(void (*fonction)(), struct_rpl_arguments *rpl_arguments); @@ -3465,6 +3503,19 @@ struct_liste_chainee *analyse_rpn(struct /* -------------------------------------------------------------------------------- + Allocateur de buffers à cache +-------------------------------------------------------------------------------- +*/ + +void initialisation_allocateur_buffer(struct_processus *s_etat_processus); +void liberation_allocateur_buffer(struct_processus *s_etat_pocessus); +struct_buffer *allocation_buffer(struct_processus *s_etat_processus, + size_t longueur); +void liberation_buffer(struct_processus *s_etat_processus, + struct_buffer *buffer); + +/* +-------------------------------------------------------------------------------- Fonctions renvoyant une copie de la structure de description des processus -------------------------------------------------------------------------------- */ @@ -3526,22 +3577,6 @@ struct_liste_variables_partagees *recher #endif /* --------------------------------------------------------------------------------- - Fonctions gérant les arbres de simplification --------------------------------------------------------------------------------- -*/ - -#ifndef RPLARGS -struct_arbre *creation_arbre(struct_processus *s_etat_processus, - struct_objet **t_objets, integer8 indice, integer8 indice_maximal); -void liberation_arbre(struct_processus *s_etat_processus, - struct_arbre *s_noeud); -void parcours_arbre(struct_processus *s_etat_processus, struct_arbre *s_noeud); -void simplification_arbre(struct_processus *s_etat_processus, - struct_arbre *s_noeud); -#endif - -/* -------------------------------------------------------------------------------- Fonctions gérant la complétion automatique --------------------------------------------------------------------------------