2 * Copyright (C) 2001-2008, Parrot Foundation.
6 * This is the API header for the memory subsystem
7 * Data Structure and Algorithms:
13 #ifndef PARROT_MEMORY_H_GUARD
14 #define PARROT_MEMORY_H_GUARD
17 /* Use these macros instead of calling the functions listed below. */
18 /* They protect against things like passing null to mem__sys_realloc, */
19 /* which is not portable. */
20 #define mem_internal_allocate(x) mem__internal_allocate((x), __FILE__, __LINE__)
21 #define mem_internal_allocate_typed(type) \
22 (type *)mem__internal_allocate(sizeof (type), __FILE__, __LINE__)
23 #define mem_internal_allocate_zeroed(x) mem__internal_allocate_zeroed((x), \
25 #define mem_internal_allocate_zeroed_typed(type) \
26 (type *)mem__internal_allocate_zeroed(sizeof (type), __FILE__, __LINE__)
28 #define mem_internal_realloc(x, y) mem__internal_realloc((x), (y), __FILE__, __LINE__)
29 #define mem_internal_realloc_zeroed(p, x, y) mem__internal_realloc_zeroed((p), (x), (y), __FILE__, __LINE__)
30 #define mem_internal_free(x) mem__internal_free((x), __FILE__, __LINE__)
32 #define mem_allocate_new_stash() NULL
33 #define mem_allocate_new_stack() NULL
34 #define mem_sys_memcopy memcpy
35 #define mem_sys_memmove memmove
37 #define mem_allocate_typed(type) (type *)mem_sys_allocate(sizeof (type))
38 #define mem_allocate_n_typed(n, type) (type *)mem_sys_allocate((n) * sizeof(type))
39 #define mem_allocate_zeroed_typed(type) (type *)mem_sys_allocate_zeroed(sizeof (type))
40 #define mem_allocate_n_zeroed_typed(n, type) (type *)mem_sys_allocate_zeroed((n) * sizeof(type))
41 #define mem_realloc_n_typed(p, n, type) (p) = (type *)mem_sys_realloc((p), (n)*sizeof(type))
42 #define mem_copy_n_typed(dest, src, n, type) memcpy((dest), (src), (n)*sizeof(type))
44 /* HEADERIZER BEGIN: src/gc/alloc_memory.c */
45 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
49 PARROT_CANNOT_RETURN_NULL
50 void * mem_sys_allocate(size_t size
);
54 PARROT_CANNOT_RETURN_NULL
55 void * mem_sys_allocate_zeroed(size_t size
);
58 void mem_sys_free(ARGFREE(void *from
));
62 PARROT_CANNOT_RETURN_NULL
63 void * mem_sys_realloc(ARGFREE(void *from
), size_t size
);
67 PARROT_CANNOT_RETURN_NULL
68 void * mem_sys_realloc_zeroed(
75 PARROT_CANNOT_RETURN_NULL
76 char * mem_sys_strdup(ARGIN(const char *src
))
77 __attribute__nonnull__(1);
80 PARROT_CANNOT_RETURN_NULL
81 void * mem__internal_allocate(
83 ARGIN(const char *file
),
85 __attribute__nonnull__(2);
88 PARROT_CANNOT_RETURN_NULL
89 void * mem__internal_allocate_zeroed(
91 ARGIN(const char *file
),
93 __attribute__nonnull__(2);
95 void mem__internal_free(
97 ARGIN(const char *file
),
99 __attribute__nonnull__(2);
102 PARROT_CANNOT_RETURN_NULL
103 void * mem__internal_realloc(
106 ARGIN(const char *file
),
108 __attribute__nonnull__(3);
111 PARROT_CANNOT_RETURN_NULL
112 void * mem__internal_realloc_zeroed(
116 ARGIN(const char *file
),
118 __attribute__nonnull__(4);
120 #define ASSERT_ARGS_mem_sys_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
121 #define ASSERT_ARGS_mem_sys_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
122 #define ASSERT_ARGS_mem_sys_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
123 #define ASSERT_ARGS_mem_sys_realloc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
124 #define ASSERT_ARGS_mem_sys_realloc_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
125 #define ASSERT_ARGS_mem_sys_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
126 PARROT_ASSERT_ARG(src))
127 #define ASSERT_ARGS_mem__internal_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
128 PARROT_ASSERT_ARG(file))
129 #define ASSERT_ARGS_mem__internal_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
130 PARROT_ASSERT_ARG(file))
131 #define ASSERT_ARGS_mem__internal_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
132 PARROT_ASSERT_ARG(file))
133 #define ASSERT_ARGS_mem__internal_realloc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
134 PARROT_ASSERT_ARG(file))
135 #define ASSERT_ARGS_mem__internal_realloc_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
136 PARROT_ASSERT_ARG(file))
137 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
138 /* HEADERIZER END: src/gc/alloc_memory.c */
140 #endif /* PARROT_MEMORY_H_GUARD */
144 * c-file-style: "parrot"
146 * vim: expandtab shiftwidth=4: