File: linnet.h

package info (click to toggle)
libobject-pad-perl 0.821-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ansic: 3,361; perl: 3,328; pascal: 28; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 931 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef __LINNET_H__
#define __LINNET_H__

/* A linnet is a bird in the finch family, similar to a canary. */

/* Here, a linnet a debugging feature. We put a field at the start of every
 * kind of struct, which is always initialised to a unique static value per
 * type. Whenever we cast a pointer to this type, we also assert that the
 * linnet field has the right value. In this way we hope to detect invalid 
 * pointer accesses.
 */

#ifdef DEBUGGING
#  define DEBUG_LINNETS
#endif

#ifdef DEBUG_LINNETS
#  define LINNET_FIELD          U32 debug_linnet;
#  define LINNET_INIT(val)      .debug_linnet = (val),
#  define LINNET_CHECK_CAST(ptr, type, val) \
                                ({ type castptr = (type)ptr; assert(castptr->debug_linnet == val), castptr;})
#else
#  define LINNET_FIELD
#  define LINNET_INIT(val)
#  define LINNET_CHECK_CAST(ptr, type, val) \
                                ((type)ptr)
#endif

#endif