File: mxstdlib.h

package info (click to toggle)
python-mxtools 0.8-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 204 kB
  • ctags: 209
  • sloc: ansic: 1,961; python: 140; makefile: 41; sh: 19
file content (66 lines) | stat: -rw-r--r-- 1,809 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef MXSTDLIB_H
#define MXSTDLIB_H

/* Standard stuff I use often -- not Python specific */

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif

/* My own macros for memory allocation... */
#ifdef MAL_MEM_DEBUG
# define newstruct(x) \
         (printf("* malloc for struct "#x" (%s:%i)\n",__FILE__,__LINE__),\
	  (x *)malloc(sizeof(x)))
# define cnewstruct(x) \
         (printf("* calloc for struct "#x" (%s:%i)\n",c,__FILE__,__LINE__),\
	  (x *)calloc(sizeof(x),1))
# define new(x,c) \
         (printf("* malloc for "#c"=%i '"#x"'s (%s:%i)\n",c,__FILE__,__LINE__),\
	  (x *)malloc(sizeof(x)*(c)))
# define cnew(x,c) \
         (printf("* calloc for "#c"=%i '"#x"'s (%s:%i)\n",c,__FILE__,__LINE__),\
	  (x *)calloc((c),sizeof(x)))
# define resize(var,x,c) \
         (printf("* realloc "#x" at %X to size "#c"=%i (%s:%i)\n",x,c,__FILE__,__LINE__),\
	  (x *)realloc((void*)(var),sizeof(x)*(c)))
# define free(x) \
         (printf("* freeing "#x" at %X (%s:%i)\n",x,__FILE__,__LINE__),\
	  free((void*)(x)))
#else
# define newstruct(x) (x *)malloc(sizeof(x))
# define cnewstruct(x) (x *)calloc(sizeof(x),1)
# define new(x,c) (x *)malloc(sizeof(x)*(c))
# define cnew(x,c) (x *)calloc((c),sizeof(x))
# define resize(var,x,c) (x *)realloc((void*)(var),sizeof(x)*(c))
# define free(x) free((void*)(x))
#endif

/* Debugging printf's */
#ifdef MAL_DEBUG
# ifdef PyFloat_AS_DOUBLE /* check whether we're compiling a Python ext. */
#  define DPRINTF if (Py_DebugFlag) printf
# else
#  define DPRINTF printf
# endif
#else
# define DPRINTF if (0) printf
#endif

/* The usual bunch... */
#ifndef max
#define max(a,b) ((a>b)?(a):(b))
#endif
#ifndef min
#define min(a,b) ((a<b)?(a):(b))
#endif

/* EOF */
#endif