Files | Defines | Typedefs | Functions | Variables

General Macros

Files

file  eg_macros.c
 

implementation of some macros.


file  eg_macros.h

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.

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

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.

Detailed Description

global macros and types for EGlib

Version:
0.9.2
History:
  • 2011-12-06
    • Add generic signal handler and necesary macros
  • 2011-05-16
    • Add WARNIF(xxx) to warn (on screen) non-zero return values
  • 2010-08-31
  • 2010-04-30
    • Add IFMESSAGE messaging macro
  • 2010-02-20
    • Add EGcall macro to resume tracing calls.
  • 2009-07-21
    • Change macro-variables to __name convention to avoid name clashes
  • 2008-08-29
    • Add EG_RETURN
  • 2008-07-24
    • Add TESTGL
  • 2007-12-07
    • Add FTESTG and FTEST, that always test the parameters regardless of the debug level
  • 2007-01-19
    • Delete EGosGetOffset
  • 2006-09-28
    • Add function that display basic process information, including version and date of compilation of EGlib
  • 2005-12-19
    • Add float128 support ussing SoftFloat.
  • 2005-10-28
    • Add some status definitions for algorithms.
  • 2005-06-14
    • Add strdup definition, just for cleanliness when compiling
  • 2005-05-23
    • Add EGcontainerOf
  • 2005-05-03
    • Add typeof definition;
  • 2004-07-14
    • Add GNU_MP_Z GNU_MP_F and GNU_MP_Q to the type definitions.
  • 2004-07-12
    • Add EGRAT_TYPE to the type definitions.
  • 2004-03-17
    • Add TESTG that if recives something that is nonzero print an user message and the go to the given location.
  • 2004-02-05
    • Add CHECKRVALG that checks a return value, display a mesage, and then perform a goto.
  • 2003-12-01
    • Add definition of a 'copy' function and its MP version.
  • 2003-11-20
    • Add PTRTEST that check if a pointer points to the first 64Kb of memory internal memory. Althought such situation may happend (if we work in kernel-related stuff), it is usually an error when we try to access such a memory.
  • 2003-09-08
    • Add ADVTESTL
  • 2003-07-10
    • Add MESSAGEF, ADVCHECKRVAL
  • 2003-07-02
    • Add EGosGetData, EGosSetData, EGosGetOffset
  • 2003-06-16
    • Add EXITL macro
  • 2003-06-06
    • Add TESTL macro to test conditions but only when the debug level is at least some value
  • 2003-05-22
    • Add EXITRVAL
  • 2003-05-15
    • Add CHECKRVAL MESSAGE and WARNING macros.
  • 2003-05-08
    • Add support for variadic macros for EXIT and TEST
    • Define EGRAND_MAX for SUN and LINUX acordingly, this is becouse for some reason the value of RAND_MAX in SUN is not as specified in stdlib.h but rather 1 << 31 - 1. Still I am not sure about the maximum value of rand() on sun... will fix that later on to.
    • Add a mesage macro, it only print if the debug level is as high as required by the first field. Again the definition is variadric and if the debug level is 0 we reduce the macro to the empty instruction.

Define Documentation

#define __EG_PRINTLOC2__   __EG_PRINTLOC2F__(stderr)

Definition at line 146 of file eg_macros.h.

#define __EG_PRINTLOC2F__ (   __F  )     fprintf(((__F==((FILE*)0))?stderr:__F),"in %s (%s:%d)\n",__func__,__FILE__,__LINE__)

Definition at line 145 of file eg_macros.h.

#define __EG_PRINTLOC__   __EG_PRINTLOCF__(stderr)

Definition at line 144 of file eg_macros.h.

#define __EG_PRINTLOCF__ (   __F  )     fprintf(((__F==((FILE*)0))?stderr:__F),", in %s (%s:%d)\n",__func__,__FILE__,__LINE__)

Definition at line 143 of file eg_macros.h.

#define ADVCHECKRVAL (   __A,
  __B 
)
Value:
({\
  if(__A){\
    __EG_PRINTLOC2__;\
    return __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

Definition at line 337 of file eg_macros.h.

#define ADVTESTL (   __L,
  __A,
  __RVAL,
  ... 
)
Value:
({\
  if((DEBUG>=__L)&&(__A)){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return __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.

Definition at line 346 of file eg_macros.h.

#define CHECKRVAL (   __A  ) 
Value:
({\
  if(__A){\
    __EG_PRINTLOC2__;\
    return __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

Examples:
eg_net.ex.c, eg_simula.ex.c, and eg_slk.ex.c.

Definition at line 356 of file eg_macros.h.

Referenced by EGalgPRglobalRelabel(), EGalgPRpreprocess(), and main().

#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

Examples:
eg_dmatrix.ex.c, eg_ebtree.ex.c, eg_eheap.ex.c, eg_ekheap.ex.c, eg_keytab.ex.c, eg_min_cut.ex.c, eg_octree.ex.c, eg_push_relabel.ex.c, eg_slk.ex.c, and eg_symtab.ex.c.

Definition at line 376 of file eg_macros.h.

Referenced by EGalgMCtestNode(), EGalgPRmaxSTflow(), EGalgPRminSTcut(), EGalgPRoptimalityTest(), EGsimNewEvent(), and main().

#define EG_ALGSTAT_ERROR   3

the algorithm stop because of some unforeseen error

Definition at line 417 of file eg_macros.h.

#define EG_ALGSTAT_NUMERROR   2

the algorithm stop because of some numerical problem

Definition at line 415 of file eg_macros.h.

#define EG_ALGSTAT_PARTIAL   1

the algorithm could only partially finish

Definition at line 413 of file eg_macros.h.

#define EG_ALGSTAT_SUCCESS   0

the algorithm finish successfully.

Definition at line 411 of file eg_macros.h.

#define EG_M_PI   3.1415926535897932384626433832795029L

definition of $\pi$ as a constant, suitable for quad-IEEE operations.

Definition at line 427 of file eg_macros.h.

#define EG_RETURN (   __A  ) 
Value:
{\
  const int __RVAL__ = (__A);\
  if(__RVAL__){\
    fprintf(stderr,"rval %d",__RVAL__);\
    __EG_PRINTLOC__;}\
  return __RVAL__;}

return value macro, if the value is non-zero, write to standard error the returning code and where this happen

Definition at line 206 of file eg_macros.h.

#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.

Note:
each parameter is evaluated once, thus ensuring correct evaluation of parameters, even if they are an expresion.
Examples:
eg_maxclosure.ex.c.

Definition at line 439 of file eg_macros.h.

Referenced by EGalgMaxClosure_PR(), and main().

#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

Examples:
eg_dijkstra.ex.c, and eg_raset.ex.c.

Definition at line 444 of file eg_macros.h.

Referenced by main().

#define EGcontainerOf (   __ptr,
  __type,
  __member 
)
Value:
({\
  typeof(((__type *)0)->__member) *const __EGcOf_ptr = (__ptr);\
  (__type *)( (char*)__EGcOf_ptr - ((size_t) &((__type *)0)->__member));})

given a pointer to a member of a structure, return the pointer to the head of the structure. (idea taken from Linux Kernel).

Parameters:
__ptr pointer to the member of the containing structure.
__type name type of the containing structure.
__member name of the given member in the containing structure.
Returns:
pointer to the containing structure.
Examples:
eg_edgraph.ex.c, eg_elist.ex.c, eg_eugraph.ex.c, eg_push_relabel.ex.c, eg_shrink_graph.ex.c, and eg_slk.ex.c.

Definition at line 133 of file eg_macros.h.

Referenced by display_DG(), display_srkG(), display_UG(), EGalgMCbuildPRgraph(), EGalgMCcomputeT(), EGalgMCexpandNode(), EGalgPRcomputeLabels(), EGalgPRglobalRelabel(), EGalgPRmaxSTflow(), EGalgPRminSTcut(), EGalgPRnumb(), EGalgPRoptimalityTest(), EGalgPRpreprocess(), EGalgPRpush(), EGalgPRpushRelabel(), and main().

#define EGoffsetOf (   __type,
  __member 
)    ((size_t) &((__type *)0)->__member)

return the offset of a member inside a structure.

Parameters:
type the type of the containing structure.
member the name of the member that we are interested in compute the offset.
Returns:
the number of bytes between the member and the beginning of the structure.

Definition at line 123 of file eg_macros.h.

#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'.

Definition at line 381 of file eg_macros.h.

#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'.

Definition at line 386 of file eg_macros.h.

#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.

Parameters:
__status__ the returning status of the call, zero when set, non-zero when comming back from a long-jump.
__LABEL__ where to jump when returning from a long-jump.
Examples:
eg_adgraph.ex.c, eg_dijkstra.ex.c, eg_dmatrix.ex.c, eg_ebtree.ex.c, eg_edgraph.ex.c, eg_ehash.ex.c, eg_eheap.ex.c, eg_ekheap.ex.c, eg_elist.ex.c, eg_eugraph.ex.c, eg_gcit.ex.c, eg_keytab.ex.c, eg_maxclosure.ex.c, eg_memslab.ex.c, eg_min_cut.ex.c, eg_net.ex.c, eg_octree.ex.c, eg_perm_it.ex.c, eg_push_relabel.ex.c, eg_random.ex.c, eg_raset.ex.c, eg_shrink_graph.ex.c, eg_simula.ex.c, eg_slk.ex.c, and eg_symtab.ex.c.

Definition at line 477 of file eg_macros.h.

Referenced by main().

#define EXIT (   __A,
  ... 
)
Value:
({if(__A){\
    fprintf(stderr,"EXIT: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    exit(EXIT_FAILURE);}})

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.

Examples:
eg_slk.ex.c.

Definition at line 327 of file eg_macros.h.

Referenced by EGbitNext(), EGbitPrev(), and main().

#define EXITL (   __L,
  __A,
  ... 
)
Value:
({\
  if(__L<=DEBUG){\
  if(__A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    _exit(1);}}})

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.

Definition at line 167 of file eg_macros.h.

Referenced by EGalgPRpush(), and EGalgPRpushRelabel().

#define EXITRVAL (   __A  ) 
Value:
({\
  if(__A){\
    __EG_PRINTLOC2__;\
    exit(EXIT_FAILURE);}})

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.

Definition at line 318 of file eg_macros.h.

#define FTEST (   __A,
  ... 
)
Value:
({\
  if(__A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}})

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.

Definition at line 289 of file eg_macros.h.

#define FTESTG (   __A,
  __B,
  ... 
)
Value:
({\
  if(__A){\
    fprintf(stderr,"ERROR: " __VA_ARGS__);\
    __EG_PRINTLOC__;\
    goto __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.

Definition at line 299 of file eg_macros.h.

#define IFMESSAGE (   __display,
  ... 
)
Value:
do{\
  if((__display)>0){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}}while(0)

if the given display level is over the given treshold, display the given message and location information

Examples:
eg_eheap.ex.c.

Definition at line 151 of file eg_macros.h.

Referenced by EGalgMaxClosure_PR(), and main().

#define MESSAGE (   __A,
  ... 
)
Value:
({\
  if(__A <= DEBUG ){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})

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.

Examples:
eg_dmatrix.ex.c, eg_ehash.ex.c, eg_ekheap.ex.c, eg_net.ex.c, and eg_slk.ex.c.

Definition at line 244 of file eg_macros.h.

Referenced by EGalgMCbuildPRgraph(), EGalgMCcomputeT(), EGalgMCtestNode(), EGalgPRcomputeLabels(), EGalgPRglobalRelabel(), EGalgPRmaxSTflow(), EGalgPRminSTcut(), EGalgPRnumb(), EGalgPRoptimalityTest(), EGalgPRpreprocess(), EGalgPRpush(), EGalgPRpushRelabel(), EGbitSet(), EGbitTest(), EGbitUnset(), EGsetLimits(), EGsimNewEvent(), main(), and parseargs().

#define MESSAGEF (   __A,
  __F,
  ... 
)
Value:
({\
  if(__A <= DEBUG ){\
    fprintf(((__F==0)?stderr:__F),__VA_ARGS__);\
    __EG_PRINTLOCF__(__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.

Definition at line 235 of file eg_macros.h.

#define nullCopy   ((EGcopy_f)0)

Define a null copy function.

Definition at line 402 of file eg_macros.h.

#define OUTPUT (   __A,
  ... 
)
Value:
({\
  if(__A <= VERBOSE_LEVEL ){\
    fprintf(stderr,__VA_ARGS__);}})

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.

Definition at line 254 of file eg_macros.h.

#define PTRTEST (   __PTR,
  __RVAL 
)
Value:
{\
  if(__PTR) ADVTESTL(0,((size_t)(__PTR)) < (1U<<16),__RVAL, \
                 "%s=%p is not a valid pointer",\
                  #__PTR, (void*)(__PTR));}

this macro check if the value of a pointer is not bellow the first 64Kb, if so it return the given value

Definition at line 189 of file eg_macros.h.

#define TEST (   __A,
  ... 
)
Value:
({\
  if(__A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}})

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.

Examples:
eg_eheap.ex.c, eg_ekheap.ex.c, eg_net.ex.c, and eg_octree.ex.c.

Definition at line 225 of file eg_macros.h.

Referenced by CheckSeed(), and main().

#define TESTERRNOIF (   __value  ) 
Value:
do{\
  if(__value){\
    const int __EGserrno = errno;\
    fprintf(stderr,"failed with errno %d, %s\n",__EGserrno, strerror(__EGserrno));\
    __EG_PRINTLOC2__;\
    return __value;}}while(0)

, 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.

Parameters:
__value if non-zero check systems errors, and return this value

Definition at line 367 of file eg_macros.h.

#define TESTG (   __A,
  __B,
  ... 
)
Value:
({\
  if(__A){\
    fprintf(stderr,"ERROR: " __VA_ARGS__);\
    __EG_PRINTLOC__;\
    goto __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.

Examples:
eg_eheap.ex.c, eg_ekheap.ex.c, eg_maxclosure.ex.c, eg_min_cut.ex.c, eg_octree.ex.c, eg_push_relabel.ex.c, and eg_shrink_graph.ex.c.

Definition at line 215 of file eg_macros.h.

Referenced by EGalgMCbuildPRgraph(), and main().

#define TESTGL (   __L,
  __A,
  __B,
  ... 
)
Value:
({\
  if((__L)<=DEBUG && (__A)){\
    fprintf(stderr,"ERROR: " __VA_ARGS__);\
    __EG_PRINTLOC__;\
    goto __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.

Definition at line 197 of file eg_macros.h.

#define TESTL (   __L,
  __A,
  ... 
)
Value:
({\
  if(__L<=DEBUG){\
  if(__A){\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;\
    return 1;}}})

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.

Definition at line 179 of file eg_macros.h.

Referenced by EGalgMCtestNode().

#define WARNIF (   __L__  ) 
Value:
do{\
  const int __Wval__= (__L__);\
  if(__Wval__){fprintf(stderr,"WARNING: In %s (%s:%d) "#__L__" = %d\n",__func__,__FILE__,__LINE__,__Wval__);}}while(0)

if return value is non-zero warn on screen

Definition at line 158 of file eg_macros.h.

Referenced by EGsetLimits().

#define WARNING (   __A,
  ... 
)
Value:
({if(__A){\
    fprintf(stderr,"WARNING: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})

This macro print messages to the screen when the condition __A is true.

Definition at line 308 of file eg_macros.h.

#define WARNINGL (   __L,
  __A,
  ... 
)
Value:
({\
  if((__A)&&(DEBUG>=__L)){\
    fprintf(stderr,"WARNING: ");\
    fprintf(stderr,__VA_ARGS__);\
    __EG_PRINTLOC__;}})

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.

Definition at line 266 of file eg_macros.h.


Typedef Documentation

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.

Definition at line 398 of file eg_macros.h.


Function Documentation

void __EGsigSetSignal ( void   ) 

use EGsighandler for SIGXCPU, SIGINT and SIGSEGV as signal handler.

Definition at line 83 of file eg_macros.c.

References EGsighandler().

Here is the call graph for this function:

void EGlib_info ( void   ) 
void EGlib_version ( void   ) 
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.

Parameters:
max_rtime maximum running time.
mem_limit maximum memory allowed for the process, this include RLIMIT_AS and RLIMIT_DATA.

Definition at line 90 of file eg_macros.c.

References MESSAGE, and WARNIF.

Referenced by main().

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

Parameters:
s the signal number received

Definition at line 55 of file eg_macros.c.

Referenced by __EGsigSetSignal().


Variable Documentation

jmp_buf __EGljmp

needed global jump-control variable

Definition at line 53 of file eg_macros.c.