1 /* memory.h 2 * Copyright (C) 2001-2011, Parrot Foundation. 3 * Overview: 4 * This is the API header for the memory subsystem 5 * Data Structure and Algorithms: 6 * History: 7 * Notes: 8 * References: 9 */ 10 11 #ifndef PARROT_MEMORY_H_GUARD 12 #define PARROT_MEMORY_H_GUARD 13 #include <assert.h> 14 15 /* Use these macros instead of calling the functions listed below. */ 16 /* They protect against things like passing null to mem__sys_realloc, */ 17 /* which is not portable. */ 18 19 /* It was decided that having a second set of memory allocation functions 20 is a waste. These macros were rewritten to use the much more prevalent 21 mem_sys_* functions and then the mem__internal_* functions were 22 eliminated. */ 23 24 #define mem_internal_allocate(x) mem_sys_allocate(x) 25 26 #define mem_internal_allocate_typed(type) (type *)mem_sys_allocate(sizeof (type)) 27 28 #define mem_internal_allocate_zeroed(x) mem_sys_allocate_zeroed(x) 29 30 #define mem_internal_allocate_zeroed_typed(type) \ 31 (type *)mem_sys_allocate_zeroed(sizeof (type)) 32 33 #define mem_internal_allocate_n_zeroed_typed(n, type) \ 34 (type *)mem_sys_allocate_zeroed((n) * sizeof (type)) 35 36 #define mem_internal_realloc(x, y) mem_sys_realloc((x), (y)) 37 38 #define mem_internal_realloc_zeroed(p, x, y) mem_sys_realloc_zeroed((p), (x), (y)) 39 40 #define mem_internal_realloc_n_zeroed_typed(p, x, y, type) \ 41 (type *)mem_sys_realloc_zeroed((p), (x) * sizeof (type), (y) * sizeof (type)) 42 43 #define mem_internal_realloc_n_typed(p, n, type) \ 44 (p) = (type *)mem_sys_realloc((p), (n) * sizeof (type)) 45 #define mem_internal_free(x) mem_sys_free(x) 46 47 #define mem_sys_memcopy memcpy 48 #define mem_sys_memmove memmove 49 50 #define mem_allocate_typed(type) (type *)mem_sys_allocate(sizeof (type)) 51 #define mem_allocate_n_typed(n, type) (type *)mem_sys_allocate((n) * sizeof (type)) 52 #define mem_allocate_zeroed_typed(type) (type *)mem_sys_allocate_zeroed(sizeof (type)) 53 #define mem_allocate_n_zeroed_typed(n, type) (type *)mem_sys_allocate_zeroed((n) * sizeof (type)) 54 #define mem_realloc_n_typed(p, n, type) (p) = (type *)mem_sys_realloc((p), (n) * sizeof (type)) 55 56 #define mem_gc_allocate_typed(i, type) \ 57 (type *)Parrot_gc_allocate_memory_chunk((i), sizeof (type)) 58 #define mem_gc_allocate_n_typed(i, n, type) \ 59 (type *)Parrot_gc_allocate_memory_chunk((i), (n) * sizeof (type)) 60 #define mem_gc_realloc_n_typed(i, p, n, type) \ 61 (type *)Parrot_gc_reallocate_memory_chunk((i), (p), (n) * sizeof (type)) 62 #define mem_gc_allocate_zeroed_typed(i, type) \ 63 (type *)Parrot_gc_allocate_memory_chunk_with_interior_pointers((i), sizeof (type)) 64 #define mem_gc_allocate_n_zeroed_typed(i, n, type) \ 65 (type *)Parrot_gc_allocate_memory_chunk_with_interior_pointers((i), (n) * sizeof (type)) 66 #define mem_gc_realloc_n_typed_zeroed(i, p, n, o, type) \ 67 (type *)Parrot_gc_reallocate_memory_chunk_with_interior_pointers((i), (p), \ 68 (n) * sizeof (type), (o) * sizeof (type)) 69 #define mem_gc_free(i, p) \ 70 Parrot_gc_free_memory_chunk((i), (p)) 71 72 #define mem_copy_n_typed(dest, src, n, type) memcpy((dest), (src), (n)*sizeof (type)) 73 74 /* HEADERIZER BEGIN: src/gc/alloc_memory.c */ 75 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 76 77 PARROT_EXPORT 78 PARROT_MALLOC 79 PARROT_CANNOT_RETURN_NULL 80 void * mem_sys_allocate(size_t size); 81 82 PARROT_EXPORT 83 PARROT_MALLOC 84 PARROT_CANNOT_RETURN_NULL 85 void * mem_sys_allocate_zeroed(size_t size); 86 87 PARROT_EXPORT 88 void mem_sys_free(ARGFREE(void *from)); 89 90 PARROT_EXPORT 91 PARROT_MALLOC 92 PARROT_CANNOT_RETURN_NULL 93 void * mem_sys_realloc(ARGFREE(void *from), size_t size); 94 95 PARROT_EXPORT 96 PARROT_MALLOC 97 PARROT_CANNOT_RETURN_NULL 98 void * mem_sys_realloc_zeroed( 99 ARGFREE(void *from), 100 size_t size, 101 size_t old_size); 102 103 PARROT_EXPORT 104 PARROT_MALLOC 105 PARROT_CANNOT_RETURN_NULL 106 char * mem_sys_strdup(ARGIN(const char *src)) 107 __attribute__nonnull__(1); 108 109 PARROT_EXPORT 110 PARROT_MALLOC 111 PARROT_CANNOT_RETURN_NULL 112 char * mem_sys_strndup(ARGIN(const char *src), size_t size) 113 __attribute__nonnull__(1); 114 115 #define ASSERT_ARGS_mem_sys_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) 116 #define ASSERT_ARGS_mem_sys_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) 117 #define ASSERT_ARGS_mem_sys_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) 118 #define ASSERT_ARGS_mem_sys_realloc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) 119 #define ASSERT_ARGS_mem_sys_realloc_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) 120 #define ASSERT_ARGS_mem_sys_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 121 PARROT_ASSERT_ARG(src)) 122 #define ASSERT_ARGS_mem_sys_strndup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 123 PARROT_ASSERT_ARG(src)) 124 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 125 /* HEADERIZER END: src/gc/alloc_memory.c */ 126 127 #endif /* PARROT_MEMORY_H_GUARD */ 128 129 /* 130 * Local variables: 131 * c-file-style: "parrot" 132 * End: 133 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : 134 */ 135