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 * This library file contains 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(size_t nbytes = sizeof(TYPE);
24 TYPE *calloc_NAME(size_t nobj=1, size_t size=sizeof(TYPE));
25 TYPE *realloc_NAME(TYPE *ptr, size_t nbytes);
26 void free_NAME(TYPE *ptr);
30 %define %malloc(TYPE,NAME...)
32 %rename(malloc_##NAME) ::malloc(size_t nbytes);
34 %rename(malloc_##TYPE) ::malloc(size_t nbytes);
38 %typemap(default) size_t nbytes "$1 = (size_t) sizeof(TYPE);"
40 TYPE *malloc(size_t nbytes);
41 %typemap(default) size_t nbytes;
44 %define %calloc(TYPE,NAME...)
46 %rename(calloc_##NAME) ::calloc(size_t nobj, size_t sz);
48 %rename(calloc_##TYPE) ::calloc(size_t nobj, size_t sz);
51 %typemap(default) size_t sz "$1 = (size_t) sizeof(TYPE);"
53 %typemap(default) size_t sz "$1 = 1;"
55 %typemap(default) size_t nobj "$1 = 1;"
56 TYPE *calloc(size_t nobj, size_t sz);
57 %typemap(default) size_t sz;
58 %typemap(default) size_t nobj;
61 %define %realloc(TYPE,NAME...)
64 TYPE *realloc_##NAME(TYPE *ptr, size_t nitems)
66 TYPE *realloc_##TYPE(TYPE *ptr, size_t nitems)
70 return (TYPE *) realloc(ptr, nitems*sizeof(TYPE));
72 return (TYPE *) realloc(ptr, nitems);
77 TYPE *realloc_##NAME(TYPE *ptr, size_t nitems);
79 TYPE *realloc_##TYPE(TYPE *ptr, size_t 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 size_t sizeof_##NAME = sizeof(TYPE);
96 %constant size_t sizeof_##TYPE = sizeof(TYPE);
100 %define %allocators(TYPE,NAME...)