--- rpl/src/rpl.h 2017/06/29 14:54:42 1.306 +++ rpl/src/rpl.h 2020/11/01 08:51:42 1.342 @@ -1,8 +1,7 @@ -#define DEBUG_ERREURS /* ================================================================================ - RPL/2 (R) version 4.1.27 - Copyright (C) 1989-2017 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.32 + Copyright (C) 1989-2020 Dr. BERTRAND Joël This file is part of RPL/2. @@ -93,10 +92,10 @@ #include #include #include +#include #ifndef RPLARGS # include -# include # include # include # include @@ -105,6 +104,7 @@ # include # include # include +# include # include # include @@ -269,8 +269,11 @@ #ifndef RPLARGS # ifndef UNIX_PATH_MAX - struct sockaddr_un sizecheck; +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" + static struct sockaddr_un sizecheck; # define UNIX_PATH_MAX sizeof(sizecheck.sun_path) +# pragma GCC diagnostic pop # endif #endif @@ -325,7 +328,8 @@ enum signaux_rpl rpl_sighup, rpl_sigtstp, rpl_sigexcept, - rpl_sigmax + rpl_sigmax, + rpl_siguser // Base des signaux à la discrétion de l'utilisateur }; #define LONGUEUR_QUEUE_SIGNAUX 1024 @@ -394,23 +398,40 @@ union semun #ifdef IPCS_SYSV # ifdef DEBUG_SEMAPHORES +# define sem_init(a, b, c) ({ \ + uprintf("[%d-%llu] Semaphore %s (%p) "\ + "initialization at %s() " \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ + pthread_self(), \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ + sem_init_SysV(a, b, c); }) # define sem_wait(a) ({ int value; sem_getvalue(a, &value); \ uprintf("[%d-%llu] Semaphore %s (%p) "\ "waiting at %s() " \ - "line #%d\n", (int) getpid(), (unsigned long long) i\ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) i\ pthread_self(), \ - #a, a, __FUNCTION__, __LINE__), fflush(stdout); \ - if (value > 1) BUG(1, uprintf("Value %d\n", value)); \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ sem_wait_SysV(a); }) -# define sem_post(a) ({ int value; sem_getvalue(a, &value); \ +# define sem_trywait(a) ({ int value; sem_getvalue(a, &value); \ + uprintf("[%d-%llu] Semaphore %s (%p) "\ + "trywaiting at %s() " \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) i\ + pthread_self(), \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ + sem_trywait_SysV(a); }) +# define sem_post(a) ({ int value; sem_getvalue(a, &value); \ uprintf("[%d-%llu] Semaphore %s (%p) "\ "posting at %s() " \ - "line #%d\n", (int) getpid(), (unsigned long long) \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ pthread_self(), \ - #a, a, __FUNCTION__, __LINE__), fflush(stdout); \ - if (value > 0) BUG(1, uprintf("Value %d\n", value)); \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ sem_post_SysV(a); }) -# define sem_destroy(a) ({ int value; sem_getvalue(a, &value); \ +# define sem_destroy(a) ({ int value; sem_getvalue(a, &value); \ + uprintf("[%d-%llu] Semaphore %s (%p) "\ + "destroying at %s() " \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ + pthread_self(), \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ if (value == 0) BUG(1, uprintf("Value %d\n", value)); \ sem_destroy_SysV(a); }) # else @@ -428,21 +449,40 @@ union semun # define sem_unlink(a) sem_unlink_SysV(a) #else # ifdef DEBUG_SEMAPHORES +# define sem_init(a, b, c) ({ \ + uprintf("[%d-%llu] Semaphore %s (%p) "\ + "initialization at %s() " \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ + pthread_self(), \ + #a, a, __FUNCTION__, __LINE__, c), fflush(stdout); \ + sem_init(a, b, c); }) # define sem_wait(a) ({ int value; sem_getvalue(a, &value); \ uprintf("[%d-%llu] Semaphore %s (%p) "\ "waiting at %s() " \ - "line #%d\n", (int) getpid(), (unsigned long long) \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ pthread_self(), \ - #a, a, __FUNCTION__, __LINE__), fflush(stdout); \ - if (value > 1) BUG(1, uprintf("Value %d\n", value)); sem_wait(a); }) + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ + sem_wait(a); }) +# define sem_trywait(a) ({ int value; sem_getvalue(a, &value); \ + uprintf("[%d-%llu] Semaphore %s (%p) "\ + "trywaiting at %s() " \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ + pthread_self(), \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ + sem_trywait(a); }) # define sem_post(a) ({ int value; sem_getvalue(a, &value); \ uprintf("[%d-%llu] Semaphore %s (%p) "\ "posting at %s() " \ - "line #%d\n", (int) getpid(), (unsigned long long) \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ pthread_self(), \ - #a, a, __FUNCTION__, __LINE__), fflush(stdout); \ - if (value > 0) BUG(1, uprintf("Value %d\n", value)); sem_post(a); }) + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ + sem_post(a); }) # define sem_destroy(a) ({ int value; sem_getvalue(a, &value); \ + uprintf("[%d-%llu] Semaphore %s (%p) "\ + "destroying at %s() " \ + "line #%d <%d>\n", (int) getpid(), (unsigned long long) \ + pthread_self(), \ + #a, a, __FUNCTION__, __LINE__, value), fflush(stdout); \ if (value == 0) BUG(1, uprintf("Value %d\n", value)); \ sem_destroy(a); }) # endif @@ -531,7 +571,9 @@ union semun __EXTERN__ pid_t pid_processus_pere; + __EXTERN__ pthread_mutex_t mutex_sigaction; __EXTERN__ pthread_mutex_t mutex_liste_threads; + __EXTERN__ pthread_mutex_t mutex_liste_threads_surveillance; __EXTERN__ pthread_mutex_t mutex_creation_variable_partagee __STATIC_MUTEX_INITIALIZATION__; __EXTERN__ pthread_mutex_t mutex_sections_critiques; @@ -539,7 +581,7 @@ union semun __EXTERN__ pthread_mutex_t mutex_sem __STATIC_MUTEX_INITIALIZATION__; __EXTERN__ volatile int routine_recursive; - __EXTERN__ volatile int nombre_thread_surveillance_processus; + __EXTERN__ volatile int nombre_threads_surveillance_processus; # define SEM_FORK 0 # define SEM_QUEUE 1 @@ -629,9 +671,9 @@ union semun } while(0) #ifdef __GLIBC__ -#include -#define __BACKTRACE -#define BACKTRACE(n) \ +# include +# define __BACKTRACE +# define BACKTRACE(n) \ do \ { \ void *buffer[n]; \ @@ -656,7 +698,7 @@ union semun pthread_mutex_unlock(&mutex); \ } while(0) #else -#define BACKTRACE(n) NOTICE("BACKTRACE only defined in glibc") +# define BACKTRACE(n) NOTICE("BACKTRACE only defined in glibc") #endif #ifdef __BACKTRACE @@ -692,33 +734,55 @@ void *debug_memoire_modification(void *p void debug_memoire_retrait(void *ptr); void debug_memoire_verification(); -pid_t debug_fork(); - -#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) -#define fork() debug_fork() +#ifdef RPLCXX +# define malloc(s) debug_memoire_ajout(s, \ + const_cast \ + (reinterpret_cast \ + (const_cast(__FUNCTION__))), __LINE__, \ + const_cast \ + (reinterpret_cast \ + (const_cast(#s)))) +# define realloc(s, t) debug_memoire_modification(s, t, \ + const_cast \ + (reinterpret_cast \ + (const_cast(__FUNCTION__))), __LINE__, \ + const_cast \ + (reinterpret_cast \ + (const_cast(#t)))) +#else +# define malloc(s) debug_memoire_ajout(s, __FUNCTION__, __LINE__, \ + (const unsigned char *) #s) +# define realloc(s, t) debug_memoire_modification(s, t, \ + __FUNCTION__, __LINE__, (const unsigned char *) #t) +#endif +#define fork() debug_fork(s_etat_processus) #endif #ifdef DEBUG_RETURN -#define return uprintf("[%d] Return from <%s()> at line #%d " \ +# 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 #endif #ifdef DEBUG_MUTEX -#define pthread_mutex_lock(mutex) uprintf("[%d-%llu] Mutex %s (%p) " \ +# define pthread_mutex_lock(mutex) uprintf("[%d-%llu] Mutex %s (%p) " \ "locking at %s() " \ "line #%d\n", (int) getpid(), (unsigned long long) pthread_self(), \ #mutex, mutex, __FUNCTION__, __LINE__), fflush(stdout), \ pthread_mutex_lock(mutex) -#define pthread_mutex_unlock(mutex) uprintf("[%d-%llu] Mutex %s (%p) " \ +# define pthread_mutex_unlock(mutex) uprintf("[%d-%llu] Mutex %s (%p) " \ "unlocking at " \ "%s() line #%d\n", (int) getpid(), (unsigned long long) \ pthread_self(), #mutex, mutex, __FUNCTION__, __LINE__), \ fflush(stdout), \ pthread_mutex_unlock(mutex) +# define pthread_mutex_trylock(mutex) uprintf("[%d-%llu] Mutex %s (%p) " \ + "trylocking at " \ + "%s() line #%d\n", (int) getpid(), (unsigned long long) \ + pthread_self(), #mutex, mutex, __FUNCTION__, __LINE__), \ + fflush(stdout), \ + pthread_mutex_trylock(mutex) #endif @@ -769,7 +833,7 @@ pid_t debug_fork(); #define d_SPH "Semaphore $n 'name'" #define d_TAB "<[ table ]>" #define d_MTX "Mutex $n" -#define d_REC "Record /'name_1', ..., 'name_n'/" +#define d_REC "|[ record ]|" /* -------------------------------------------------------------------------------- @@ -1015,6 +1079,9 @@ pid_t debug_fork(); # define d_ex_chiffrement_indisponible __erreur(90) # define d_ex_longueur_clef_chiffrement __erreur(91) # define d_ex_taille_message __erreur(92) +# define d_ex_type_externe_dup __erreur(93) +# define d_ex_type_externe_drop __erreur(94) +# define d_ex_simplification __erreur(95) #endif @@ -1067,7 +1134,8 @@ pid_t debug_fork(); #define VIN __RPL_VIN #define VRL __RPL_VRL -enum t_rplcas_commandes { RPLCAS_INTEGRATION = 0, RPLCAS_LIMITE }; +enum t_rplcas_commandes { RPLCAS_INTEGRATION = 0, RPLCAS_LIMITE, + RPLCAS_SIMPLIFICATION }; enum t_type { ADR = 0, ALG, BIN, CHN, CPL, EXT, FCH, FCT, INT, LST, MCX, MIN, MRL, MTX, NOM, NON, PRC, REC, REL, RPN, SCK, @@ -1129,6 +1197,8 @@ enum t_type { ADR = 0, ALG, BIN, CHN, C PRC : processus (struct_processus_fils *) Sans objet. + REC : enregistrement (struct_record *) + REL : reel sur 64 bits (real*8, real8 *) Sans objet. @@ -1574,6 +1644,7 @@ typedef struct liste_pile_systeme logical1 creation_variables_statiques; logical1 creation_variables_partagees; logical1 evaluation_expression; + logical1 debug_programme; unsigned char clause; @@ -1754,6 +1825,19 @@ typedef struct tableau /* -------------------------------------------------------------------------------- + Structure enregistrement +-------------------------------------------------------------------------------- +*/ + +typedef struct record +{ + struct_objet *noms; + struct_objet *donnees; +} struct_record; + + +/* +-------------------------------------------------------------------------------- Structure arbre -------------------------------------------------------------------------------- */ @@ -1778,6 +1862,7 @@ typedef struct instruction_externe unsigned char *nom; unsigned char *nom_bibliotheque; void *descripteur_bibliotheque; + integer8 position_fleche; } struct_instruction_externe; @@ -1819,7 +1904,10 @@ typedef struct rpl_arguments unsigned char test_instruction; integer8 nombre_arguments; - // Nombre d'arguments de la fonction, positif ou nul. + // Nombre d'arguments de la fonction + // 0 : instruction infixe + // positif : nombre d'arguments (notation algébrique possible) + // -1 : notation algrébrique non autorisée void *s_etat_processus; } struct_rpl_arguments; @@ -2469,6 +2557,7 @@ typedef struct processus CACHE(integer8, int) CACHE(struct_matrice, mat) CACHE(struct_nom, nom) + CACHE(struct_record, rec) CACHE(real8, rel) CACHE(struct_tableau, tab) CACHE(struct_vecteur, vec) @@ -2483,11 +2572,15 @@ typedef struct processus variables_tableau_noeuds_partages) CACHE2(struct_buffer, enveloppes_buffers) - unsigned char ***cache_buffer; - int *pointeur_cache_buffer; + unsigned char ***cache_buffer; + int *pointeur_cache_buffer; } struct_processus; #endif +#ifdef DEBUG_MEMOIRE +pid_t debug_fork(struct_processus *s_etat_processus); +#endif + /* ================================================================================ @@ -2794,6 +2887,7 @@ void instruction_mtxtrylock(struct_proce void instruction_mtxunlock(struct_processus *s_etat_processus); void instruction_multiplication(struct_processus *s_etat_processus); +void instruction_nbrcpus(struct_processus *s_etat_prorcessus); void instruction_ne(struct_processus *s_etat_processus); void instruction_neg(struct_processus *s_etat_processus); void instruction_next(struct_processus *s_etat_processus); @@ -2883,6 +2977,7 @@ void instruction_rdz(struct_processus *s void instruction_re(struct_processus *s_etat_processus); void instruction_read(struct_processus *s_etat_processus); void instruction_recode(struct_processus *s_etat_processus); +void instruction_record(struct_processus *s_etat_processus); void instruction_recv(struct_processus *s_etat_processus); void instruction_redraw(struct_processus *s_etat_processus); void instruction_regex(struct_processus *s_etat_processus); @@ -3253,7 +3348,8 @@ int envoi_signal_contexte(struct_process enum signaux_rpl signal); int envoi_signal_processus(pid_t pid, enum signaux_rpl signal, logical1 test_ouverture); -int envoi_signal_thread(pthread_t tid, enum signaux_rpl signal); +int envoi_signal_thread(struct_processus *s_etat_processus, + pthread_t tid, enum signaux_rpl signal); #endif /* @@ -3337,8 +3433,10 @@ struct_liste_chainee *sauvegarde_argumen #ifndef RPLARGS unsigned char *analyse_algebrique(struct_processus *s_etat_processus, unsigned char *chaine_algebrique, struct_liste_chainee **l_base_liste); +#endif unsigned char *analyse_flux(struct_processus *s_etat_processus, unsigned char *flux, integer8 longueur); +#ifndef RPLARGS unsigned char *chiffrement(struct_processus *s_etat_processus, const EVP_CIPHER *type_chiffrement, logical1 encodage, unsigned char *message, integer8 longueur_message, @@ -3361,8 +3459,10 @@ unsigned char *formateur_fichier(struct_ integer8 longueur, integer8 longueur_champ, unsigned char format, unsigned char type, integer8 *longueur_effective, integer8 *recursivite, logical1 export_fichier); +#endif unsigned char *formateur_flux(struct_processus *s_etat_processus, unsigned char *donnees, integer8 *longueur); +#ifndef RPLARGS unsigned char *formateur_fichier_nombre(struct_processus *s_etat_processus, void *valeur_numerique, unsigned char type, integer8 longueur, integer8 longueur_champ, unsigned char format); @@ -3446,7 +3546,8 @@ logical1 retrait_variable_statique(struc logical1 retrait_variables_statiques_locales( struct_processus *s_etat_processus); logical1 sequenceur(struct_processus *s_etat_processus); -logical1 sequenceur_optimise(struct_processus *s_etat_processus); +logical1 sequenceur_optimise(struct_processus *s_etat_processus, + struct_liste_chainee *l_bibliotheques); #endif /* @@ -3484,6 +3585,8 @@ logical1 validation_chaine(unsigned char #ifndef RPLARGS ssize_t read_atomic(struct_processus *s_etat_processus, int fd, void *buf, size_t count); +ssize_t read_atomic_signal(struct_processus *s_etat_processus, + int fd, void *buf, size_t count); ssize_t write_atomic(struct_processus *s_etat_processus, int fd, void *buf, size_t count); #endif