next up previous contents
Next: References Up: Description of the Previous: timer

handlers


system handlers warning, error, memory and debug handlers


LiDIA 's system handlers are functions which allow easy warning, error, memory and debug handling in LiDIA programs.


Let xxx stand in the following for warning, lidia_error, memory or debug. A xxx_handler in LiDIA consists of three parts:

void default_xxx_handler()

this is the function which realizes the handling proposed by the LiDIA system. For example, the default_error_handler

prints an error message and then exits the program.

xxx_handler_ptr xxx_handler()

this is a pointer which by default points to the default_xxx_handler .

xxx_handler_ptr set_xxx_handler(xxx_handler_ptr)

this is a function which allows to replace the default handler by a user-defined handler. The new handler must have the type xxx_handler_ptr .

According to the description above, the following handlers are available:

typedef void (*error_handler_ptr)(char *, char *);
error_handler_ptr lidia_error_handler;

The lidia_error_handler  must be called with two character pointers (strings). The first string should include the name of the class in which the error occured and the second the exact position and the description of the error. The lidia_error_handler produces an error message of the format lidia_error_handler::classname::exact position and description

and exits using abort() .

An extended version of lidia_error_handler is lidia_error_handler_c . This function must be called with two character pointers and a non-empty, valid piece of C++ code (commas are not allowed in this code). On call, it executes the code and the lidia_error_handler . lidia_error_handler_c is implemented by the macro

#define lidia_error_handler_c(f, m, code)\
{ code; lidia_error_handler(f, m); }

The warning_handler and the debug_handler work in the same way but in contrast to the error_handler they do not abort execution. To include warning and debug handling in LiDIA , the following compilation flags have to be defined before building LiDIA :

-DLIDIA_WARNINGS -DLIDIA_DEBUG=level.

level can be any integer greater than zero. The greater the level the less debug information will be produced on execution. The default value of LIDIA_DEBUG is equal to 1 (print all debug information).

#define debug_handler(file, msg)\
        lidia_debug_handler(file, msg)

#define debug_handler_l(file, msg, level)\
        if (LIDIA_DEBUG <= level)\
          lidia_debug_handler(file, msg)

#define debug_handler_c(name, msg, level, code)\
        { if (LIDIA_DEBUG <= level)\
          lidia_debug_handler(name, msg);\
	  code; }

Finally, the memory_handler is intented to be used as a check after allocating vectors of objects. Therefore, it has an additional pointer argument (the vector the user tried to allocate). If the allocation was not successful (memory exhausted) then a message is printed and the program aborts execution. Otherwise no message is printed. Again, to allow memory handling in LiDIA , it is necessary to define the compilation flag

-DLIDIA_MEMORY.


abort(3)


The compilation flags LIDIA_WARNINGS , LIDIA_DEBUG and LIDIA_MEMORY must be defined before compiling LiDIA .


#include <LiDIA/error.h>
#include <LiDIA/memory.h>

int main()
{
  char *s;
  if (1 != (2-1))
    lidia_error_handler("main()", "if::math. error");

  s = new char[100000];
  memory_handler(s, "main()", "allocating 100000 chars");
}


Thomas Papanikolaou

Copyright 1995 by the LiDIA -Group, Universität des Saarlandes

 

COPYRIGHT NOTICE

Copyright © 1995 by LiDIA -Group
Universität des Saarlandes

Postfach 151150
D--66041 Saarbrücken, Germany

LiDIA is not in the public domain but it can be copied and distributed freely for any non-commercial purpose.

If you copy LiDIA for somebody else, you may ask this person for refund of your expenses. This should cover cost of media, copying and shipping. You are not allowed to ask for more than this. In any case you must give a copy of this copyright notice along with the program.

If you obtain LiDIA please send us a short notice to that effect, e.g., an e-mail message to lidia@cs.uni-sb.de containing your full name and address. This allows us to keep track of the number of LiDIA users.

If you publish a mathematical result that was partly obtained using LiDIA , please cite LiDIA ( LiDIA -Group, LiDIA--- A library for computational number theory, Universität des Saarlandes, 1995.), just as you would cite another paper that you used. Also we would appreciate it if you could inform us about such a paper.

You are permitted to modify and redistribute LiDIA , but you are not allowed to restrict further redistribution. That is to say proprietary modifications will not be allowed. We want all versions of LiDIA to remain free.

If you modify any part of LiDIA and redistribute it, you must supply a README file containing information about the changes you made. We do not want to take credit or be blamed for your modifications.

Of course we are interested in all of your modifications. In particular we would like to see bug-fixes, improvements and new functions. So again we would appreciate it if you informed us about all modifications you make.

LiDIA is distributed by us without any warranty, to the extent permitted by applicable state law. We distribute LiDIA *as is* without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.

The entire risk as to the quality and performance of the program is with you. Should LiDIA prove defective, you have to take over the cost of all necessary servicing, repair or correction.

In no case unless required by applicable law will we, and/or any other party who may modify and redistribute LiDIA as permitted above, be liable to you for damages, including lost profits, lost money or other special, incidental or consequential damages arising out of the use or inability to use LiDIA .



next up previous contents
Next: References Up: Description of the Previous: timer



LiDIA Administrator
Thu Aug 10 16:41:08 MET DST 1995