--- rpl/src/rplexternals.h 2010/01/27 22:22:17 1.2 +++ rpl/src/rplexternals.h 2013/03/27 15:47:36 1.45 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.10 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.13 + Copyright (C) 1989-2013 Dr. BERTRAND Joël This file is part of RPL/2. @@ -39,9 +39,10 @@ ================================================================================ */ -#define allocation(a) allocation((*rpl_arguments).s_etat_processus, a) -#define copie_objet(a, b) copie_objet((*rpl_arguments).s_etat_processus, a, b) -#define liberation(a) liberation((*rpl_arguments).s_etat_processus, a) +#define allocation(a) librpl_allocation((*rpl_arguments).s_etat_processus, a) +#define copie_objet(a, b) librpl_copie_objet( \ + (*rpl_arguments).s_etat_processus, a, b) +#define liberation(a) librpl_liberation((*rpl_arguments).s_etat_processus, a) /* -------------------------------------------------------------------------------- @@ -69,6 +70,7 @@ #define replaceElementIntoDaisyChain(daisyChain, element) \ do { typeof(daisyChain) __daisyChain = daisyChain; \ if (__daisyChain == NULL) executionError("Nullified daisy chain"); \ + freeObject((*__daisyChain).donnee); \ (*__daisyChain).donnee = element; } while(0) #define nextElementOfDaisyChain(daisyChain) \ @@ -103,11 +105,14 @@ #define logical int #define string char * #define integer int +#define object struct_objet * #define declareStructure typedef struct { #define declareUnion typedef union { #define as(name) } name; +#define __RPL__ struct_rpl_arguments rpl_arguments + #define target(a) (*a) #define address(a) (&a) @@ -119,10 +124,23 @@ /* -------------------------------------------------------------------------------- + Signaux +--------------------------------------------------------------------------------*/ + +#define blockSignals \ + { sigset_t set, oldset; sigfillset(&set); \ + pthread_sigmask(SIG_BLOCK, &set, &oldset); +#define unblockSignals \ + pthread_sigmask(SIG_SETMASK, &oldset, NULL); } + +/* +-------------------------------------------------------------------------------- Constructeurs -------------------------------------------------------------------------------- */ +#define DISABLE_SET_BUT_NOT_USED_WARNING(a) if (&a != ((&a) + 1)); + #define HEADER \ int __constante; \ logical1 __evaluation; \ @@ -138,7 +156,13 @@ (*rpl_arguments).instruction_valide = 'Y'; \ (*rpl_arguments).erreur = 0; \ __constante = 0; \ - __evaluation = d_faux; + __evaluation = d_faux; \ + DISABLE_SET_BUT_NOT_USED_WARNING(__evaluation); \ + DISABLE_SET_BUT_NOT_USED_WARNING(__type); \ + DISABLE_SET_BUT_NOT_USED_WARNING(__indice_bit); \ + DISABLE_SET_BUT_NOT_USED_WARNING(__indice_bloc); \ + DISABLE_SET_BUT_NOT_USED_WARNING(__taille_bloc); \ + DISABLE_SET_BUT_NOT_USED_WARNING(__masque); #define FUNCTION \ if (__validation_instruction == d_vrai) return; \ @@ -166,13 +190,55 @@ /* -------------------------------------------------------------------------------- + Destruction d'un objet +-------------------------------------------------------------------------------- +*/ + +#define freeObject(object) \ + { \ + if (object == NULL) \ + systemError("Nullified object"); \ + liberation(object); \ + object = NULL; \ + } while(0) + +/* +-------------------------------------------------------------------------------- + Copie d'un objet +-------------------------------------------------------------------------------- +*/ + +#define dupObject(object) \ + { if (copie_objet(object, 'P') != object) \ + systemError("Memory allocation error"); } while(0) + +/* +-------------------------------------------------------------------------------- + Déclaration des fonctions internes +-------------------------------------------------------------------------------- +*/ + +#define declareInternalFunction(name, ...) \ + __internal_##name(struct_rpl_arguments *rpl_arguments, __VA_ARGS__) { + +#define endInternalFunction } + +#define useInternalFunction(name, ...) \ + __internal_##name(struct_rpl_arguments *rpl_arguments, __VA_ARGS__) + +#define callInternalFunction(name, ...) \ + __internal_##name(rpl_arguments, __VA_ARGS__) + +/* +-------------------------------------------------------------------------------- Déclaration des fonctions externes -------------------------------------------------------------------------------- */ #define declareExternalFunction(name) \ void __external_##name(struct_rpl_arguments *rpl_arguments) { \ - char __function_name[] = "__external_"#name; + char __function_name[] = "__external_"#name; \ + __static_rpl_arguments = (*rpl_arguments); #define useExternalFunction(function) \ void __external_##function(struct_rpl_arguments *rpl_arguments) @@ -183,6 +249,7 @@ #define __onClosing void __runOnClosing(struct_rpl_arguments *rpl_arguments) #define declareSubroutine(when) __##when { \ char __function_name[] = #when; \ + __static_rpl_arguments = (*rpl_arguments); \ HEADER \ declareHelpString(""); \ numberOfArguments(0); \ @@ -193,12 +260,19 @@ #define logger(...) do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0) #define exportExternalFunctions(...) \ - char **__external_symbols(unsigned long *nb_symbols) { \ + char **__external_symbols(unsigned long *nb_symbols, \ + const char *version) { \ char arguments[] = #__VA_ARGS__; \ char **tableau; \ char *ptr1, *ptr2; \ int drapeau; \ unsigned long i; \ + if (strcmp(version, _d_version_rpl) != 0) \ + { \ + notice(stdout, "Versions mismatch : library %s, expected %s\n", \ + _d_version_rpl, version); \ + (*nb_symbols) = -1; return(NULL); \ + } \ (*nb_symbols) = 0; ptr1 = arguments; drapeau = 0; \ while((*ptr1) != 0) \ { \ @@ -346,6 +420,15 @@ (*rpl_arguments).type_erreur = 'E'; \ (*rpl_arguments).message_erreur = (unsigned char *) message; } while(0) +#define onSystemError(...) { \ + if ((*rpl_arguments).erreur != 0) \ + { \ + __VA_ARGS__; \ + blockSignals; \ + kill(getpid(), SIGTERM); \ + unblockSignals; \ + } } while(0) + #define onError(...) \ do { if (((*rpl_arguments).type_erreur == 'E') && \ ((*rpl_arguments).erreur != 0)) { __VA_ARGS__; \ @@ -988,31 +1071,6 @@ } \ } } while(0) - -/* --------------------------------------------------------------------------------- - Destruction d'un objet --------------------------------------------------------------------------------- -*/ - -#define freeObject(object) \ - { \ - if (object == NULL) \ - systemError("Nullified object"); \ - liberation(object); \ - object = NULL; \ - } while(0) - -/* --------------------------------------------------------------------------------- - Copie d'un objet --------------------------------------------------------------------------------- -*/ - -#define dupObject(object) \ - { if (copie_objet(object, 'P') != object) \ - systemError("Memory allocation error"); } while(0) - /* -------------------------------------------------------------------------------- Allocation mémoire @@ -1029,18 +1087,31 @@ /* -------------------------------------------------------------------------------- + Récupération des interruptions et des signaux +-------------------------------------------------------------------------------- +*/ + +#define pollSignalsAndInterrupts() \ + { scrutation_injection((*rpl_arguments).s_etat_processus); } while(0) + +/* +-------------------------------------------------------------------------------- Exécution d'une fonction intrinsèque -------------------------------------------------------------------------------- */ #define intrinsic(function) { \ int __status; \ - __status = wrapper_instruction_intrinseque(instruction_##function, \ - rpl_arguments); \ + __status = wrapper_instruction_intrinseque( \ + instruction_##function, rpl_arguments); \ if (__status == 1) executionError(#function); \ if (__status == 2) systemError(#function); \ } while(0) #endif +static struct_rpl_arguments __static_rpl_arguments; +#define __RPL__ struct_rpl_arguments *rpl_arguments; \ + rpl_arguments = &__static_rpl_arguments; + // vim: ts=4