1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * SWIG library file containing macros that can be used to create objects using
8 * the C malloc function.
9 * ----------------------------------------------------------------------------- */
15 /* %malloc(TYPE [, NAME = TYPE])
16 %calloc(TYPE [, NAME = TYPE])
17 %realloc(TYPE [, NAME = TYPE])
18 %free(TYPE [, NAME = TYPE])
19 %allocators(TYPE [,NAME = TYPE])
21 Creates functions for allocating/reallocating memory.
23 TYPE *malloc_NAME(int nbytes = sizeof(TYPE);
24 TYPE *calloc_NAME(int nobj=1, int size=sizeof(TYPE));
25 TYPE *realloc_NAME(TYPE *ptr, int nbytes);
26 void free_NAME(TYPE *ptr);
30 %define %malloc(TYPE,NAME...)
32 %rename(malloc_##NAME) ::malloc(int nbytes);
34 %rename(malloc_##TYPE) ::malloc(int nbytes);
38 %typemap(default) int nbytes "$1 = (int) sizeof(TYPE);"
40 TYPE *malloc(int nbytes);
41 %typemap(default) int nbytes;
44 %define %calloc(TYPE,NAME...)
46 %rename(calloc_##NAME) ::calloc(int nobj, int sz);
48 %rename(calloc_##TYPE) ::calloc(int nobj, int sz);
51 %typemap(default) int sz "$1 = (int) sizeof(TYPE);"
53 %typemap(default) int sz "$1 = 1;"
55 %typemap(default) int nobj "$1 = 1;"
56 TYPE *calloc(int nobj, int sz);
57 %typemap(default) int sz;
58 %typemap(default) int nobj;
61 %define %realloc(TYPE,NAME...)
64 TYPE *realloc_##NAME(TYPE *ptr, int nitems)
66 TYPE *realloc_##TYPE(TYPE *ptr, int nitems)
70 return (TYPE *) realloc(ptr, nitems*sizeof(TYPE));
72 return (TYPE *) realloc(ptr, nitems);
77 TYPE *realloc_##NAME(TYPE *ptr, int nitems);
79 TYPE *realloc_##TYPE(TYPE *ptr, int nitems);
83 %define %free(TYPE,NAME...)
85 %rename(free_##NAME) ::free(TYPE *ptr);
87 %rename(free_##TYPE) ::free(TYPE *ptr);
92 %define %sizeof(TYPE,NAME...)
94 %constant int sizeof_##NAME = sizeof(TYPE);
96 %constant int sizeof_##TYPE = sizeof(TYPE);
100 %define %allocators(TYPE,NAME...)