The error facilities have been designed to minimize the overhead of error checking and to allow the use of user defined error handler functions. Conditional compilation options exist to include more extensive error checking during the software development phase which can be removed from production software for performance optimization.
Each module in DevTools contains a function to return the current error flag (type Vint) of an object. For example, to return the error flag for a Contour object, use vis_ContourError as follows.
Vint errorflag; errorflag = vis_ContourError (contour);When an error is detected by an object, the object error flag is set to the appropriate error flag value. When the error query function (eg. vis_ContourError) is called, the current error flag is returned and the flag is reset to SYS_ERROR_NONE. Possible error flags are the following,
Also, each DevTools component library defines error flags, such as the VisTools error flag VIS_ERROR_ENUM, which have the same meaning and value as the related system error flags.SYS_ERROR_NONE No error recorded. This value is zero SYS_ERROR_VALUE Argument with an improper value SYS_ERROR_ENUM Argument is not a valid option SYS_ERROR_OBJECTTYPE Argument is not a valid object type SYS_ERROR_MEMORY Memory allocation failure SYS_ERROR_NULLOBJECT A NULL object pointer has been encountered SYS_ERROR_FILE Argument is not a valid file name SYS_ERROR_COMPUTE A compute error has occurred SYS_ERROR_OPERATION An operation is illegal in current state SYS_ERROR_OVERFLOW A data structure overflow has occurred SYS_ERROR_UNDERFLOW A data structure underflow has occurred SYS_ERROR_UNKNOWN An error of unknown type has occurred SYS_ERROR_FORMAT Improper or incomplete file format or contents SYS_ERROR_SEVERE Severe internal error has occurred
The Error module performs the error handling tasks. The default error handler prints error information to standard output. The user may install a custom error handler. Also the Error module can be used to return a descriptive string corresponding to a given error flag.
Error checking within an object can be a performance consideration when a function may be called literally hundreds of millions of times. This is most likely the case in query functions which may be retrieving data from the private data of an object. In this case the user may define VKI_CHECK_ERRS at compile time to include error checking code during the software development phase which can be removed from production software when it can be shown that functions of interest are used error free. In summary, the compile time definitions related to error checking are the following.
Table of ContentsVKI_CHECK_ERRS Include additional error checking
The Error module supports the following functions.
vut_ErrorCall - call installed error handler vut_ErrorHandler - default error handler vut_ErrorSetHandler - install a pointer to the error handler vut_ErrorGetHandler - query pointer to the current error handler vut_ErrorSetObject - set a pointer to the error object vut_ErrorGetObject - get pointer to the current error object vut_ErrorString - return a descriptive error string
*vut_ErrorCall - call installed error handler
void vut_ErrorCall (const Vchar *funcname, Vint errorflag, const Vchar *message)
funcname Name of calling function errorflag Error flag message Message string
None
To invoke the default error handler directly call
void vut_ErrorHandler (const Vchar *funcname, Vint errorflag, const Vchar *message)The default error handler prints the name of the calling function, the integer error flag and the message string to standard output. Note that standard output may be redirected to a file descriptor using the Print module function vut_PrintSetFile. If the message string is a NULL or an empty string, then the descriptive error string is printed.
vut_ErrorSetHandler - install a pointer to the error handler
void vut_ErrorSetHandler (void (*func) (const Vchar*, Vint, const Vchar*))
func Pointer to error handler
None
vut_ErrorGetHandler - query pointer to the current error handler
void vut_ErrorGetHandler (void (**func) (const Vchar*, Vint, const Vchar*))
None
func Pointer to error handler
vut_ErrorSetObject - set a pointer to the error object
void vut_ErrorSetObject (Vobject *object)
object Pointer to user defined object
None
vut_ErrorGetObject - get pointer to the current error object
void vut_ErrorGetObject (Vobject **object)
None
object Pointer to user defined object
vut_ErrorString - return a descriptive error string
Vchar *vut_ErrorString (Vint errorflag)
errorflag Error flag
None
By default, DevTools performs all memory management through the C language system functions malloc, realloc and free. Each of these three basic memory functions is wrapped by a Memory module function with an identical prototype. DevTools modules then access the underlying malloc, realloc and free system functions through these wrapper functions. The user may install replacements for the basic malloc, realloc and free functions called within the Memory module if desired.
If the Memory module is compiled using VKI_CHECK_MEM, then the memory system perform memory protection and checking functions. In addtion, if the Memory module is compiled using VKI_CHECK_MEMSTATS, the memory system will compute memory statistics which the user may query. These features are only available if user has not installed functions for malloc, realloc and free.
The Memory module supports the following functions.
vut_MemoryFree - call free function vut_MemoryMalloc - call malloc function vut_MemoryRealloc - call realloc function vut_MemorySetFunctions - install malloc, realloc and free functions vut_MemoryStatistics - query for memory system statistics
vut_MemoryFree,vut_MemoryMalloc,vut_MemoryRealloc - call memory functions
void vut_MemoryFree (void *ptr) void *vut_MemoryMalloc (size_t bytes) void *vut_MemoryRealloc (void *ptr, size_t bytes)
ptr Pointer to memory to be freed or realloced bytes Number of bytes of memory to allocate
None
vut_MemorySetFunctions - install malloc, realloc and free functions
void vut_MemorySetFunctions (void*(*mallocfun)(size_t), void*(*reallocfun)(void*, size_t), void(*freefun)(void*))
mallocfun Pointer to malloc function reallocfun Pointer to realloc function freefun Pointer to free function
None
vut_MemoryStatistics - query for memory system statistics
void vut_MemoryStatistics (size_t *cursize, size_t *maxsize, Vint *nummalloc, Vint *numrealloc, Vint *numfree)
None
cursize Current memory allocated in bytes. maxsize Maximum memory allocated in bytes. nummalloc Number of vut_MemoryMalloc calls numrealloc Number of vut_MemoryRealloc calls numfree Number of vut_MemoryFree calls
By default, the file descriptor (type FILE*), used by DevTools is stdout. The user may install an alternative file descriptor if desired. This is useful when building Microsoft Windows applications in which a console does not exist by default.
The Print module supports the following functions.
vut_PrintSetFile - install printing file descriptor vut_PrintSetPath - install printing file path
vut_PrintSetFile - install printing file descriptor
void vut_PrintSetFile (FILE* fd)
fd Print to file descriptor
None
vut_PrintSetPath - install printing file path
void vut_PrintSetPath (Vchar* path)
path Print to file path
None
Quadruple precision variables are declared with the Vquad data type. Operators such as +, -, *, etc. are not defined for this data type. Instead, all operations are performed via VQuad functions.
The VQuad module supports the following functions.
vut_VQuadSPrintf - prints variable to a string vut_VQuadPrintf - prints variable to console
vut_VQuadLoad - loads a Vdouble into a Vquad vut_VQuadStore - stores a Vquad into a Vdouble
vut_VQuadEQ - checks for Vquad a == Vquad b vut_VQuadGE - checks for Vquad a >= Vquad b vut_VQuadGT - checks for Vquad a > Vquad b vut_VQuadLE - checks for Vquad a <= Vquad b vut_VQuadLT - checks for Vquad a < Vquad b
vut_VQuadAbs - performs ABS(Vquad a) vut_VQuadAdd - performs Vquad a + Vquad b vut_VQuadDiv - performs Vquad a / Vquad b vut_VQuadHalf - performs (Vquad a)/2 vut_VQuadMult - performs Vquad a * Vquad b vut_VQuadNeg - performs -(Vquad a) vut_VQuadSqrt - performs sqrt(Vquad a) vut_VQuadSub - performs Vquad a - Vquad b
vut_VQuadCross3 - cross product of two 3-vectors vut_VQuadDot3 - dot product of two 3-vectors vut_VQuadMag3 - computes the magnitude of a 3-vector vut_VQuadScale3 - scales a 3-vector vut_VQuadUnit3 - scales a 3-vector to a unit 3-vector
vut_VQuadSPrintf - prints variable to a string
void vut_VQuadSPrintf (Vquad f, Vint width, Vint sign, Vchar buf[], Vint *ierr)
f Quadruple precision variable to be printed width Width of output field sign Flag for printed positive sign buf The output string
ierr Error, if any
If width is less than 9 or if an arithmetic error occurs during the print operation then ierr is set to 1. Otherwise it is set to 0.
vut_VQuadPrintf - prints variable to console
void vut_VQuadPrintf (Vquad f, Vint width, Vint sign, Vint *ierr)
f Quadruple precision variable to be printed width Width of output field sign Flag for printed positive sign
ierr Error, if any
vut_VQuadLoad - loads a Vdouble into a Vquad
Vquad vut_VQuadLoad (Vdouble a)
a Double precision variable to be loaded
None
vut_VQuadStore - stores a Vquad into a Vdouble
Vdouble vut_VQuadStore (Vquad a, Vint *ierr)
a Quadruple precision variable to be stored
ierr Error, if any
vut_VQuadEQ - checks for Vquad a == Vquad b
Vint vut_VQuadEQ (Vquad a, Vquad b)
a First number to compare b Second number to compare
None
vut_VQuadGE - checks for Vquad a >= Vquad b
Vint vut_VQuadGE (Vquad a, Vquad b)
a First number to compare b Second number to compare
None
vut_VQuadGT - checks for Vquad a > Vquad b
Vint vut_VQuadGT (Vquad a, Vquad b)
a First number to compare b Second number to compare
None
vut_VQuadLE - checks for Vquad a <= Vquad b
Vint vut_VQuadLE (Vquad a, Vquad b)
a First number to compare b Second number to compare
None
vut_VQuadLT - checks for Vquad a < Vquad b
Vint vut_VQuadGT (Vquad a, Vquad b)
a First number to compare b Second number to compare
None
vut_VQuadAbs - performs ABS(Vquad a)
Vquad vut_VQuadAbs (Vquad a)
a Number whose absolute value is required
None
vut_VQuadAdd - performs Vquad a + Vquad b
Vquad vut_VQuadAdd (Vquad a, Vquad b, Vint *ierr)
a First number to be added b Second number to be added
ierr Error, if any
vut_VQuadDiv - performs Vquad a / Vquad b
Vquad vut_VQuadDiv (Vquad a, Vquad b, Vint *ierr)
a Numerator b Denominator
ierr Error, if any
vut_VQuadHalf - performs (Vquad a)/2
Vquad vut_VQuadHalf (Vquad a)
a Number whose half is requested
None
vut_VQuadMult - performs Vquad a * Vquad b
Vquad vut_VQuadMult (Vquad a, Vquad b, Vint *ierr)
a First multiplier b Second multiplier
ierr Error, if any
vut_VQuadNeg - performs -(Vquad a)
Vquad vut_VQuadNeg (Vquad a)
a Number whose negative is needed
None
vut_VQuadSqrt - performs sqrt(Vquad a)
Vquad vut_VQuadSqrt (Vquad a, Vint *ierr)
a Number whose square root is needed
ierr Error, if any
vut_VQuadSub - performs Vquad a - Vquad b
Vquad vut_VQuadSub (Vquad a, Vquad b, Vint *ierr)
a Number to be added b Number to be subtracted
ierr Error, if any
vut_VQuadCross3 - cross product of two 3-vectors
void vut_VQuadCross3 (Vquad a[3], Vquad b[3], Vquad c[3], Vint *ierr)
a First vector b Second vector
c Cross product of a and b. ierr Error, if any
vut_VQuadDot3 - dot product of two 3-vectors
Vquad vut_VQuadDot3 (Vquad a[3], Vquad b[3], Vint *ierr)
a First vector b Second vector
ierr Error, if any
vut_VQuadMag3 - computes the magnitude of a 3-vector
Vquad vut_VQuadMag3 (Vquad a[3], Vint *ierr)
a Vector whose magnitude is required
ierr Error, if any
vut_VQuadScale3 - scales a 3-vector
void vut_VQuadScale3 (Vquad a[3], Vquad s, Vquad b[3], Vint *ierr)
a Vector to be scaled s Scalar value
b The scaled vector ierr Error, if any
vut_VQuadUnit3 - scales a 3-vector to a unit 3-vector
void vut_VQuadUnit3 (Vquad a[3], Vquad b[3], Vint *ierr)
a Vector whose unit is requested
b Resulting unit vector ierr Error, if any