List like processing

While restructuring the ants program it seemed wise to start with the minimal implementation and determine that every phase was clean in all aspects. By starting with just main and a signal handler for faults it became clear that something was amiss when run with valgrind. It seems that the structures created for signal handling had an uninitialized field that was actually used by the library.


int setup_sigsegv() { sigset_t a; sigemptyset(&a); /* Initialize empty set */ struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_sigaction = signal_segv; action.sa_flags = SA_SIGINFO; action.sa_mask=a;

The above code solves the problem. sigset_t is an array of bits and so has to be handled using different methods than any other type and cannot be type cast to int or long(AFAIK). By using all the facilities of gcc, and the Linux utilities it is possible to have safe code. There has never been a case where the SIGSEGV failed to act on a fault, however this was an accident waiting to happen on top of another accident. The use of valgrind and -Wall helps to identify and correct many common problems that arise due to the sheer complexity of the systems.

The process is being documented in a book done with LaTeX, and I like those latex equations. It gives an opportunity to document the code, create figures that demonstrate the functions and have a ready resource to refresh the understanding of the more complex aspects of mixing scheme, C, and Python within a list-like framework.

It is my hope to extend the structure interface so that when a structure is created, required fields are analyzed and any use without initialization is flagged.

BTW, there are some new open courses up at Harvard, Stanford, Yale and MIT. Lots of fun, probability, programming, tries, hash , physics, matrices, multi-variable math, astronomy, genetics, AI, and a vast array of useful information.

While proof reading the blog post I noticed "memset" and thus that value was in fact cleared to 0 anyway, oh well, tempest in a teapot.

0 comments:

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen