--- rpl/src/rpl.h 2010/02/10 08:09:29 1.7 +++ rpl/src/rpl.h 2010/05/16 19:36:20 1.35 @@ -1,6 +1,6 @@ /* ================================================================================ - RPL/2 (R) version 4.0.10 + RPL/2 (R) version 4.0.15 Copyright (C) 1989-2010 Dr. BERTRAND Joël This file is part of RPL/2. @@ -22,7 +22,15 @@ #ifndef INCLUSION_RPL #define INCLUSION_RPL + #define _GNU_SOURCE +#define _POSIX_C_SOURCE 200112L +#define _REENTRANT + +#ifdef Darwin +# define SIGPOLL SIGIO +# define _DARWIN_C_SOURCE +#endif /* ================================================================================ @@ -37,8 +45,10 @@ #include #include #include +#include #ifndef RPLARGS +# include # include # include # include @@ -70,6 +80,9 @@ # include "termcap.h" # include "iconv.h" +# include "openssl/evp.h" +# include "sqlite3.h" + # define HAVE_INLINE # define GSL_RANGE_CHECK_OFF # include "gsl/gsl_cdf.h" @@ -86,6 +99,11 @@ # include #endif +// Définition spécifique à Hurd +#ifndef PIPE_BUF +# define fpathconf (".", _PC_PIPE_BUF) +#endif + #ifdef MYSQL_SUPPORT # include # define mysqlclose(arg) mysql_close(arg.mysql) @@ -100,9 +118,7 @@ # define postgresqlclose(arg) #endif -#ifdef LIBRPL -# include "librplprototypes.h" -#endif +#include "librplprototypes.h" /* ================================================================================ @@ -111,10 +127,16 @@ */ #ifndef RPLARGS +// Arrêt par STOP # define SIGFSTOP SIGUSR1 +// Démarrage d'un processus fils # define SIGSTART SIGUSR2 +// Injection de données # define SIGINJECT SIGQUIT +// Arrêt général # define SIGABORT SIGPROF +// Arrêt d'un processus fils depuis autre chose que STOP +# define SIGFABORT SIGPOLL # define d_NOMBRE_INTERRUPTIONS 64 #endif @@ -175,27 +197,102 @@ typedef unsigned char t_8_bits; */ #ifndef RPLARGS +# ifdef SEMAPHORES_NOMMES +# define LONGUEUR_NOM_SEMAPHORE 64 +# endif # ifndef MAIN_RPL - extern jmp_buf contexte; - extern jmp_buf contexte_initial; + extern jmp_buf contexte; + extern jmp_buf contexte_initial; + +# ifdef SEMAPHORES_NOMMES + extern pthread_mutex_t mutex_sem; +# endif + + extern pthread_key_t semaphore_fork_processus_courant; + + extern sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_liste_threads; + + extern sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_gestionnaires_signaux; - extern pthread_key_t semaphore_fork_processus_courant; + extern sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_gestionnaires_signaux_atomique; - extern sem_t semaphore_liste_threads; - extern sem_t semaphore_gestionnaires_signaux; - extern sem_t semaphore_gestionnaires_signaux_atomique; +# ifdef SEMAPHORES_NOMMES + // 0 -> liste_threads + // 1 -> gestionnaire_signaux + // 2 -> gestionnaire_signaux_atomique + // 3 -> &((*s_etat_processus).semaphore_fork) + extern unsigned char noms_semaphores[4][LONGUEUR_NOM_SEMAPHORE]; + extern sem_t *semaphores_nommes[4]; +# endif # else - jmp_buf contexte; - jmp_buf contexte_initial; + jmp_buf contexte; + jmp_buf contexte_initial; + +# ifdef SEMAPHORES_NOMMES + pthread_mutex_t mutex_sem = PTHREAD_MUTEX_INITIALIZER; +# endif - pthread_key_t semaphore_fork_processus_courant; + pthread_key_t semaphore_fork_processus_courant; + + sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_liste_threads; + + sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_gestionnaires_signaux; - sem_t semaphore_liste_threads; - sem_t semaphore_gestionnaires_signaux; - sem_t semaphore_gestionnaires_signaux_atomique; + sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_gestionnaires_signaux_atomique; + +# ifdef SEMAPHORES_NOMMES + unsigned char noms_semaphores[4][LONGUEUR_NOM_SEMAPHORE]; + sem_t *semaphores_nommes[4]; +# endif # endif #endif +#ifdef SEMAPHORES_NOMMES +enum t_semaphore { sem_liste_threads = 0, + sem_gestionnaires_signaux = 1, + sem_gestionnaires_signaux_atomique = 2, + sem_fork = 3 }; + +sem_t *sem_init2(unsigned int valeur, enum t_semaphore semaphore); +int sem_destroy2(sem_t *semaphore_p, enum t_semaphore semaphore); +int sem_getvalue2(sem_t *semaphore, int *valeur); + +#define sem_getvalue(semaphore, value) sem_getvalue2(semaphore, value) +#define sem_post(semaphore) \ + ({ int r; pthread_mutex_lock(&mutex_sem); \ + r = sem_post(semaphore), pthread_mutex_unlock(&mutex_sem); r; }) +#define sem_wait(semaphore) \ + ({ int r; pthread_mutex_lock(&mutex_sem); \ + r = sem_wait(semaphore), pthread_mutex_unlock(&mutex_sem); r; }) +#define sem_trywait(semaphore) \ + ({ int r; pthread_mutex_lock(&mutex_sem); \ + r = sem_trywait(semaphore), pthread_mutex_unlock(&mutex_sem); r; }) +#endif + /* ================================================================================ Macros @@ -270,12 +367,18 @@ typedef unsigned char t_8_bits; # define abs(i) (((i) >= 0) ? (i) : (-i)) #endif -#define BUG(b, ...) \ - do { if (b) { uprintf("[%d] BUG! <%s()> at line #%d of %s\n", \ - (int) getpid(), __FUNCTION__, __LINE__, __FILE__); \ - __VA_ARGS__; fflush(stdout); \ - pthread_kill(pthread_self(), SIGBUS); }} while(0) +#define NOTICE(m) \ + do \ + { \ + ufprintf(stderr, "[%d-%llu] %s() from %s at line %d: %s\n", \ + getpid(), (unsigned long long) pthread_self(), \ + __FUNCTION__, __FILE__, __LINE__, m); \ + fflush(stderr); \ + } while(0) +#ifdef __GLIBC__ +#include +#define __BACKTRACE #define BACKTRACE(n) \ do \ { \ @@ -291,7 +394,7 @@ typedef unsigned char t_8_bits; if (appels != NULL) \ { \ for(i = 0; i < nb; i++) \ - uprintf("%s\n", appels[i]); \ + uprintf(" %s\n", appels[i]); \ free(appels); \ } \ else \ @@ -300,15 +403,24 @@ typedef unsigned char t_8_bits; fflush(stdout); \ pthread_mutex_unlock(&mutex); \ } while(0) +#else +#define BACKTRACE(n) NOTICE("BACKTRACE only defined in glibc") +#endif -#define NOTICE(m) \ - do \ - { \ - ufprintf(stderr, "[%d-%llu] %s() from %s at line %d: %s\n", \ - getpid(), pthread_self(), __FUNCTION__, __FILE__, __LINE__, \ - m); \ - fflush(stderr); \ - } while(0) +#ifdef __BACKTRACE +# define BUG(b, ...) \ + do { if (b) { uprintf("[%d] BUG! <%s()> at line #%d of %s\n", \ + (int) getpid(), __FUNCTION__, __LINE__, __FILE__); \ + __VA_ARGS__; fflush(stdout); \ + BACKTRACE(64); \ + pthread_kill(pthread_self(), SIGBUS); }} while(0) +#else +# define BUG(b, ...) \ + do { if (b) { uprintf("[%d] BUG! <%s()> at line #%d of %s\n", \ + (int) getpid(), __FUNCTION__, __LINE__, __FILE__); \ + __VA_ARGS__; fflush(stdout); \ + pthread_kill(pthread_self(), SIGBUS); }} while(0) +#endif /* @@ -317,10 +429,26 @@ typedef unsigned char t_8_bits; ================================================================================ */ +#ifdef DEBUG_MEMOIRE +void analyse_post_mortem(); +void *debug_memoire_ajout(size_t taille, const unsigned char *fonction, + unsigned long ligne, const unsigned char *argument); +void *debug_memoire_modification(void *pointeur, size_t taille, + const unsigned char *fonction, unsigned long ligne, + const unsigned char *argument); +void debug_memoire_retrait(void *ptr); +void debug_memoire_verification(); + +#define malloc(s) debug_memoire_ajout(s, __FUNCTION__, __LINE__, #s) +#define free(s) debug_memoire_retrait(s) +#define realloc(s, t) debug_memoire_modification(s, t, \ + __FUNCTION__, __LINE__, #t) +#endif + #ifdef DEBUG_RETURN #define return uprintf("[%d] Return from <%s()> at line #%d " \ "(%s [%d])\n", (int) getpid(), __FUNCTION__, \ - __LINE__, strerror(errno), errno); fflush(stdout); errno=0; return + __LINE__, strerror(errno), errno); fflush(stdout); errno = 0; return #endif #ifdef DEBUG_MUTEX @@ -388,10 +516,11 @@ typedef unsigned char t_8_bits; #define d_absence_erreur ((logical1) d_faux) #define d_erreur ((logical1) d_vrai) -#define d_code_fin_chaine '\0' -#define d_code_espace ' ' -#define d_code_retour_chariot '\n' -#define d_code_tabulation '\t' +#define d_code_fin_chaine '\0' +#define d_code_espace ' ' +#define d_code_retour_chariot '\n' +#define d_code_tabulation '\t' +#define d_longueur_maximale_instruction 16 #define d_INT "integer" #define d_REL "real" @@ -460,6 +589,7 @@ typedef unsigned char t_8_bits; # define d_es_nombre_max_descripteurs 2011 # define d_es_interruption_invalide 2012 # define d_es_contexte 2013 +# define d_es_somme_controle 2014 #endif /* @@ -592,19 +722,11 @@ typedef unsigned char t_8_bits; # define d_ex_locales 76 # define d_ex_representation 77 # define d_ex_erreur_profilage 78 +# define d_ex_enregistrement_inexistant 79 +# define d_ex_clef_inexistante 80 +# define d_ex_nom_implicite 81 #endif -/* --------------------------------------------------------------------------------- - Erreurs de la ligne de commande --------------------------------------------------------------------------------- -*/ - -#ifndef RPLARGS -# define d_os 4000 -# define d_os_ligne_de_commande 4001 -# define d_os_fichier_introuvable 4002 -#endif /* ================================================================================ @@ -820,12 +942,14 @@ typedef struct descripteur_fichier unsigned long identifiant; unsigned char effacement; + unsigned char type; // C (file *) ou S (sqlite *) unsigned char *nom; pid_t pid; pthread_t tid; - file *descripteur; + file *descripteur_c; + sqlite3 *descripteur_sqlite; } struct_descripteur_fichier; #endif @@ -996,8 +1120,8 @@ typedef struct descripteur_thread struct_objet *argument; - pid_t pid; - volatile pthread_t tid; + pid_t pid; + volatile pthread_t tid; pthread_t thread_pere; @@ -1334,6 +1458,7 @@ typedef struct processus unsigned char autorisation_conversion_chaine; /*Y/N*/ unsigned char autorisation_empilement_programme; /*Y/N*/ unsigned char autorisation_evaluation_nom; /*Y/N*/ + unsigned char autorisation_nom_implicite; /*Y/N*/ unsigned char evaluation_forcee; /*Y/N*/ unsigned char instruction_valide; /*Y/N*/ unsigned char instruction_intrinseque; /*Y/I/N*/ @@ -1396,7 +1521,12 @@ typedef struct processus pthread_t thread_fusible; pthread_t thread_surveille_par_fusible; +# ifndef Cygwin stack_t pile_signal; +# else +# define SA_ONSTACK 0 +# define RTLD_LOCAL 0 +# endif /* Contextes */ @@ -1655,6 +1785,8 @@ typedef struct processus unsigned char traitement_interruption; /* Y/N */ unsigned char traitement_interruptible; /* Y/N */ + struct_objet *at_exit; + /* Variables volatiles */ volatile sig_atomic_t var_volatile_alarme; @@ -1668,10 +1800,14 @@ typedef struct processus volatile sig_atomic_t var_volatile_processus_pere; volatile sig_atomic_t var_volatile_recursivite; + volatile sig_atomic_t arret_depuis_abort; + volatile int var_volatile_exception_gsl; /* Autres */ + char *rpl_home; + gsl_rng *generateur_aleatoire; const gsl_rng_type *type_generateur_aleatoire; @@ -1712,7 +1848,11 @@ typedef struct processus pthread_mutex_t mutex; // Sémaphore autorisant les fork() - sem_t semaphore_fork; + sem_t +# ifdef SEMAPHORES_NOMMES + * +# endif + semaphore_fork; /* Mutexes */ @@ -1732,7 +1872,7 @@ typedef struct processus unsigned long taille_pile_objets; struct_objet *pile_objets; -# define TAILLE_CACHE 1024 +# define TAILLE_CACHE 16384 unsigned long *objets_adr[TAILLE_CACHE]; int pointeur_adr; @@ -1836,6 +1976,7 @@ void instruction_asl(struct_processus *s void instruction_asr(struct_processus *s_etat_processus); void instruction_atan(struct_processus *s_etat_processus); void instruction_atanh(struct_processus *s_etat_processus); +void instruction_atexit(struct_processus *s_etat_processus); void instruction_autoscale(struct_processus *s_etat_processus); void instruction_axes(struct_processus *s_etat_processus); @@ -1855,6 +1996,7 @@ void instruction_clear(struct_processus void instruction_cllcd(struct_processus *s_etat_processus); void instruction_clmf(struct_processus *s_etat_processus); void instruction_close(struct_processus *s_etat_processus); +void instruction_clratexit(struct_processus *s_etat_processus); void instruction_clrcntxt(struct_processus *s_etat_processus); void instruction_clrerr(struct_processus *s_etat_processus); void instruction_clrfuse(struct_processus *s_etat_processus); @@ -2005,6 +2147,7 @@ void instruction_ifft(struct_processus * void instruction_ift(struct_processus *s_etat_processus); void instruction_ifte(struct_processus *s_etat_processus); void instruction_im(struct_processus *s_etat_processus); +void instruction_implicit(struct_processus *s_etat_processus); void instruction_in(struct_processus *s_etat_processus); void instruction_incr(struct_processus *s_etat_processus); void instruction_indep(struct_processus *s_etat_processus); @@ -2053,6 +2196,8 @@ void instruction_maxs(struct_processus * void instruction_mclrin(struct_processus *s_etat_processus); void instruction_mean(struct_processus *s_etat_processus); void instruction_mem(struct_processus *s_etat_processus); +void instruction_memlock(struct_processus *s_etat_processus); +void instruction_memunlock(struct_processus *s_etat_processus); void instruction_min(struct_processus *s_etat_processus); void instruction_mins(struct_processus *s_etat_processus); void instruction_mod(struct_processus *s_etat_processus); @@ -2107,6 +2252,7 @@ void instruction_print(struct_processus void instruction_private(struct_processus *s_etat_processus); void instruction_prlcd(struct_processus *s_etat_processus); void instruction_prmd(struct_processus *s_etat_processus); +void instruction_procid(struct_processus *s_etat_processus); void instruction_prompt(struct_processus *s_etat_processus); void instruction_protect(struct_processus *s_etat_processus); void instruction_prst(struct_processus *s_etat_processus); @@ -2340,7 +2486,7 @@ void *allocation_maillon(struct_processu #ifndef RPLARGS void analyse(struct_processus *s_etat_processus, void (*fonction)()); -inline void *analyse_instruction(struct_processus *s_etat_processus, +void *analyse_instruction(struct_processus *s_etat_processus, unsigned char *candidat); void appel_gnuplot(struct_processus *s_etat_processus, unsigned char persistance); @@ -2353,6 +2499,8 @@ void conversion_element_tex(unsigned cha 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, unsigned long longueur); void conversion_radians_vers_degres(real8 *angle); void correction_formateur_tex(struct_processus *s_etat_processus, unsigned char **ligne); @@ -2365,6 +2513,7 @@ void deverrouillage_threads_concurrents( void ecriture_pile(struct_processus *s_etat_processus, file *flux, struct_liste_chainee *l_element_courant, unsigned long niveau_courant); void ecriture_profil(struct_processus *s_etat_processus); +void effacement_pile_systeme(struct_processus *s_etat_processus); void empilement_pile_systeme(struct_processus *s_etat_processus); void encart(struct_processus *s_etat_processus, unsigned long duree); void evaluation_romberg(struct_processus *s_etat_processus, @@ -2448,7 +2597,7 @@ void retrait_thread(struct_processus *s_ void retrait_thread_surveillance(struct_processus *s_etat_processus, struct_descripteur_thread *s_argument_thread); void rplcore(struct_processus *s_etat_processus); -inline void scrutation_injection(struct_processus *s_etat_processus); +void scrutation_injection(struct_processus *s_etat_processus); void sf(struct_processus *s_etat_processus, unsigned char indice_drapeau); void *surveillance_processus(void *argument); void swap(void *variable_1, void *variable_2, unsigned long taille_octets); @@ -2493,7 +2642,7 @@ complex16 sommation_vecteur_complexe(com */ #ifndef RPLARGS -int rplinit(int argc, char *argv[], unsigned char ***resultats); +int rplinit(int argc, char *argv[], unsigned char ***resultats, char *rpl_home); #endif /* @@ -2596,6 +2745,8 @@ logical1 analyse_syntaxique(struct_proce logical1 caracteristiques_fichier(struct_processus *s_etat_processus, unsigned char *nom, logical1 *existence, logical1 *ouverture, unsigned long *unite); +logical1 controle(struct_processus *s_etat_processus, unsigned char *fichier, + unsigned char *type, unsigned char *somme_candidate); logical1 creation_variable(struct_processus *s_etat_processus, struct_variable *s_variable, unsigned char autorisation_creation_variable_statique, @@ -2615,6 +2766,10 @@ logical1 empilement_pile_last(struct_pro unsigned long nombre_arguments); logical1 evaluation(struct_processus *s_etat_processus, struct_objet *s_objet, unsigned char type_evaluation); +logical1 initialisation_fichier_acces_direct(struct_processus *s_etat_processus, + sqlite3 *sqlite, logical1 binaire); +logical1 initialisation_fichier_acces_indexe(struct_processus *s_etat_processus, + sqlite3 *sqlite, integer8 position_clef, logical1 binaire); logical1 recherche_instruction_suivante(struct_processus *s_etat_processus); logical1 retrait_variable(struct_processus *s_etat_processus, unsigned char *nom_variable, unsigned char type); @@ -2662,9 +2817,9 @@ logical1 test_fonction(unsigned char *ch */ #ifndef RPLARGS -inline ssize_t read_atomic(struct_processus *s_etat_processus, +ssize_t read_atomic(struct_processus *s_etat_processus, int fd, void *buf, size_t count); -inline ssize_t write_atomic(struct_processus *s_etat_processus, +ssize_t write_atomic(struct_processus *s_etat_processus, int fd, void *buf, size_t count); #endif @@ -2675,6 +2830,8 @@ inline ssize_t write_atomic(struct_proce */ int alsprintf(unsigned char **strp, const char *fmt, ...); +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); @@ -2735,14 +2892,14 @@ struct_processus *copie_etat_processus(s /* -------------------------------------------------------------------------------- - Fonctions renvoyant un pointeur sur un fichier (file *) + Fonctions renvoyant un pointeur sur un fichier (file *) ou un descripteur -------------------------------------------------------------------------------- */ #ifndef RPLARGS file *creation_fichier_tex(struct_processus *s_etat_processus); -file *descripteur_fichier(struct_processus *s_etat_processus, - struct_fichier *s_fichier); +struct_descripteur_fichier *descripteur_fichier(struct_processus + *s_etat_processus, struct_fichier *s_fichier); #endif /* @@ -3052,7 +3209,7 @@ void zgelsy_(integer4 *m, integer4 *n, i * drapeau depuis une bibliothèque). */ -inline int test_arret(struct_processus *s_etat_processus); +int test_arret(struct_processus *s_etat_processus); #endif