2 Copyright (C) 2005,2006,2007,2008 Eugene K. Ressler, Jr.
4 This file is part of Sketch, a small, simple system for making
5 3d drawings with LaTeX and the PSTricks or TikZ package.
7 Sketch is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Sketch is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Sketch; see the file COPYING.txt. If not, see
19 http://www.gnu.org/copyleft */
31 #define bit(N) (1u << (N))
33 // size of a static or auto declared array
34 #define ARRAY_SIZE(A) (sizeof (A) / sizeof (A)[0])
36 // zero the memory of struct at *P to zero
37 #define SET_STRUCT_ZERO(P) memset((P), 0, sizeof *(P))
39 // zero the array A to zero
40 #define SET_ARRAY_ZERO(A) memset((A), 0, sizeof (A))
42 // checking memory allocators
43 void *safe_malloc (unsigned size
);
44 void *safe_realloc (void *p
, unsigned size
);
45 char *safe_strdup (char *str
);
46 void safe_free (void *p
);
48 #define MALLOC_STRUCT(P) (P) = safe_malloc(sizeof *(P))
50 // deliberately cause compilation errors if caller uses
51 // system memory routines
53 #define malloc(N) __call_safe_malloc_instead()
54 #define realloc(P,N) __call_safe_alloc_instead()
55 #define strdup(S) __call_safe_alloc_instead()
56 #define free(P) __call_safe_free_instead()