Defines | Typedefs | Functions | Variables

eg_macros.h File Reference

#include "eg_config.h"
Include dependency graph for eg_macros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ADVCHECKRVAL(__A, __B)
 this macro test if a value is non zero, if it is it print where is it and return __B. The idea is to use it to check return values of functions
#define ADVTESTL(__L, __A, __RVAL,...)
 This macro test a condition '__A' when the debug level used at compile time is at least '__L'. If the condition is true, it print the message and return the '__RVAL' value.
#define CHECKRVAL(__A)
 this macro test if a value is non zero, if it is it print where is it and return 1. The idea is to use it to check return values of functions
#define CHECKRVALG(__A, __B)   do{if(__A){__EG_PRINTLOC2__;goto __B;}}while(0)
 this function, if the input is non zero, print a message of function, file and line and then goto the second parameter
#define EG_RETURN(__A)
 return value macro, if the value is non-zero, write to standard error the returning code and where this happen
#define EGcall(__rval__, __cleanup__, __myfunc__)   do{const int __EGrval__=__myfunc__;(__rval__)=__EGrval__;TESTG(__EGrval__,__cleanup__,"Function " #__myfunc__ " failed with code %d ",__EGrval__);}while(0)
 Call macro. The idea is to replace the following call: rval = myfunction(mypar); CHECKRVALG(rval,mygoto); with the call EGcall(rval,mygoto,myfunction(mypar)); this should help simplify calls and clean-up the code.
#define EGcallD(__myfunc2__)   EGcall(rval,CLEANUP,__myfunc2__)
 call macro with default arguments, it assumes that rval is an integer variable to be used to store return value, and CLEANUP is a valid label for an exit point in the code
#define EGcontainerOf(__ptr, __type, __member)
 given a pointer to a member of a structure, return the pointer to the head of the structure. (idea taken from Linux Kernel).
#define EGoffsetOf(__type, __member)   ((size_t) &((__type *)0)->__member)
 return the offset of a member inside a structure.
#define EGosGetData(__DATA, __OFFS, __TYPE)   (*((__TYPE*)(((char*)__DATA)+__OFFS)))
 retrieve the data of type '__TYPE' in the structure '__DATA' that is located in the offset '__OFFS'.
#define EGosSetData(__DATA, __OFFS, __TYPE, val)   (EGosGetData(__DATA,__OFFS,__TYPE)=val)
 set the data of type '__TYPE' in the structure '__DATA' that is located in the offset '__OFFS' to the value 'val'.
#define EGsigSet(__status__, __LABEL__)   do{MESSAGE(0,"setjmp here");if((__status__=setjmp(__EGljmp))) goto __LABEL__;__EGsigSetSignal();}while(0)
 set the jump point, and the sginal handler. it must receive a label where to jump, and where to save the returning status, typically this will be the clean-up section of the main function and the status variable in the mian program.
#define EXIT(__A,...)
 This macro is to print error messages and exit the program with code one from the current function, it also print the file and line where this happend.
#define EXITL(__L, __A,...)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least __L.
#define EXITRVAL(__A)
 this macro test if a value is non zero, if it is it print where is it and exit EXIT_FAILURE. The idea is to use it to check return values of functions, and the calling function can't return a status, and then we are forced to exit.
#define FTEST(__A,...)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.
#define FTESTG(__A, __B,...)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.
#define IFMESSAGE(__display,...)
 if the given display level is over the given treshold, display the given message and location information
#define MESSAGE(__A,...)
 This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction.
#define MESSAGEF(__A, __F,...)
 This macro print messages to the screen when the debug level is as big as the first parameter, if the debug level is zero we eliminate the code and reduce it to the empty instruction.
#define nullCopy   ((EGcopy_f)0)
 Define a null copy function.
#define OUTPUT(__A,...)
 This macro print messages to the screen when the verbose level is as big as the first parameter, if the verbose level is zero we eliminate the code and reduce it to the empty instruction.
#define PTRTEST(__PTR, __RVAL)
 this macro check if the value of a pointer is not bellow the first 64Kb, if so it return the given value
#define TEST(__A,...)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend.
#define TESTERRNOIF(__value)
 , if a non-zero value is given as an argument, check the errno stored in the system, print the related message, and return the non-zero given parameter, otherwise, do nothing.
#define TESTG(__A, __B,...)
 This macro is to print error messages and jump to the given point in the code, it also print the file and line where this happend.
#define TESTGL(__L, __A, __B,...)
 This macro is to print error messages and jump to the given point in the code, it also print the file and line where this happend.
#define TESTL(__L, __A,...)
 This macro is to print error messages and to return with value one from the current function, it also print the file and line where this happend, but the condition is looked only if the debug level is at least __L.
#define WARNIF(__L__)
 if return value is non-zero warn on screen
#define WARNING(__A,...)
 This macro print messages to the screen when the condition __A is true.
#define WARNINGL(__L, __A,...)
 This macro print messages to the screen when the condition __A is true .if the debug level is one we don't print any warning message. if the debug level is zero we eliminate the code and reduce it to the empty instruction.
Code Location Utility:

this are utility macros to print information about where we are.

Note:
For some reason __func__ don't work correctly for sun's cc in inline functions, so we don't use in SUN architecture
#define __EG_PRINTLOCF__(__F)   fprintf(((__F==((FILE*)0))?stderr:__F),", in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
#define __EG_PRINTLOC__   __EG_PRINTLOCF__(stderr)
#define __EG_PRINTLOC2F__(__F)   fprintf(((__F==((FILE*)0))?stderr:__F),"in %s (%s:%d)\n",__func__,__FILE__,__LINE__)
#define __EG_PRINTLOC2__   __EG_PRINTLOC2F__(stderr)
Algorithms Return Status

Here we define some general status for algorithms, the exact meaning should be sought in the actual algorithm definition, but the definitions here provide a first overview of their meaning.

#define EG_ALGSTAT_SUCCESS   0
 the algorithm finish successfully.
#define EG_ALGSTAT_PARTIAL   1
 the algorithm could only partially finish
#define EG_ALGSTAT_NUMERROR   2
 the algorithm stop because of some numerical problem
#define EG_ALGSTAT_ERROR   3
 the algorithm stop because of some unforeseen error
Mathematical Constants

Here we define some mathematical constants needed in some parts of the code that are of general use

#define EG_M_PI   3.1415926535897932384626433832795029L
 definition of $\pi$ as a constant, suitable for quad-IEEE operations.

Typedefs

typedef void *(* EGcopy_f )(void *p)
 Defione copy functions, these functions return copy of objects but with independent storage space, there are two versions, one that require a memory pool from where to look for memory, and another where we don't care about that.... the place from where the memory was asked for depend on the function, se the function definition for details. Note that if the is no more memory available the function should call exit(EXIT_FAILURE). This is only intended as a readibility help.

Functions

void __EGsigSetSignal (void)
 use EGsighandler for SIGXCPU, SIGINT and SIGSEGV as signal handler.
void EGlib_info (void)
 Display information about the library and the running process.
void EGlib_version (void)
 print versioning info of the library
void EGsetLimits (double max_rtime, unsigned long memlimit)
 set memory and run-time limits (soft and hard); if the current limits are bellow the porposed limits, it will warn on screen, but will not fail. Note that this function will set RLMIT_CORE to zero.
void EGsighandler (int s)
 a generic signal handler, it can handle SIGXCPU, SIGINT and SIGSEGV signals by displaying a proper indication to stderr; note that a call to EGsigSetjmp should be performed at the very beggining of the main function for this to be robust. When receiving a SIGXCPU, SIGINT signal, the function report the signal and jump-back to the setjmp position. When receiving a SIGINT signal, the function report the signal and jump-back

Variables

jmp_buf __EGljmp
 needed global jump-control variable

Detailed Description

Definition in file eg_macros.h.