[TT #592][docs] Add docs about assigning to registers in docs/debugger.pod
[parrot.git] / include / parrot / memory.h
blob7c76f6cd1baafc2a48acefc010ad0cf1fb2e2110
1 /* memory.h
2 * Copyright (C) 2001-2008, Parrot Foundation.
3 * SVN Info
4 * $Id$
5 * Overview:
6 * This is the API header for the memory subsystem
7 * Data Structure and Algorithms:
8 * History:
9 * Notes:
10 * References:
13 #ifndef PARROT_MEMORY_H_GUARD
14 #define PARROT_MEMORY_H_GUARD
15 #include <assert.h>
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), \
24 __FILE__, __LINE__)
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. */
47 PARROT_EXPORT
48 PARROT_MALLOC
49 PARROT_CANNOT_RETURN_NULL
50 void * mem_sys_allocate(size_t size);
52 PARROT_EXPORT
53 PARROT_MALLOC
54 PARROT_CANNOT_RETURN_NULL
55 void * mem_sys_allocate_zeroed(size_t size);
57 PARROT_EXPORT
58 void mem_sys_free(ARGFREE(void *from));
60 PARROT_EXPORT
61 PARROT_MALLOC
62 PARROT_CANNOT_RETURN_NULL
63 void * mem_sys_realloc(ARGFREE(void *from), size_t size);
65 PARROT_EXPORT
66 PARROT_MALLOC
67 PARROT_CANNOT_RETURN_NULL
68 void * mem_sys_realloc_zeroed(
69 ARGFREE(void *from),
70 size_t size,
71 size_t old_size);
73 PARROT_EXPORT
74 PARROT_MALLOC
75 PARROT_CANNOT_RETURN_NULL
76 char * mem_sys_strdup(ARGIN(const char *src))
77 __attribute__nonnull__(1);
79 PARROT_MALLOC
80 PARROT_CANNOT_RETURN_NULL
81 void * mem__internal_allocate(
82 size_t size,
83 ARGIN(const char *file),
84 int line)
85 __attribute__nonnull__(2);
87 PARROT_MALLOC
88 PARROT_CANNOT_RETURN_NULL
89 void * mem__internal_allocate_zeroed(
90 size_t size,
91 ARGIN(const char *file),
92 int line)
93 __attribute__nonnull__(2);
95 void mem__internal_free(
96 ARGFREE(void *from),
97 ARGIN(const char *file),
98 int line)
99 __attribute__nonnull__(2);
101 PARROT_MALLOC
102 PARROT_CANNOT_RETURN_NULL
103 void * mem__internal_realloc(
104 ARGFREE(void *from),
105 size_t size,
106 ARGIN(const char *file),
107 int line)
108 __attribute__nonnull__(3);
110 PARROT_MALLOC
111 PARROT_CANNOT_RETURN_NULL
112 void * mem__internal_realloc_zeroed(
113 ARGFREE(void *from),
114 size_t size,
115 size_t old_size,
116 ARGIN(const char *file),
117 int line)
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 */
143 * Local variables:
144 * c-file-style: "parrot"
145 * End:
146 * vim: expandtab shiftwidth=4: