1 | /* ------------------ */ |
---|
2 | /* --- nralloc1.c --- */ |
---|
3 | /* ------------------ */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
7 | * Univ Paris Sud XI, CNRS |
---|
8 | * |
---|
9 | * Distributed under the Boost Software License, Version 1.0 |
---|
10 | * see accompanying file LICENSE.txt or copy it at |
---|
11 | * http://www.boost.org/LICENSE_1_0.txt |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | * this code is based on the "Numerical Recipes in C 2nd edition" nrutil.c nrutil.h files from |
---|
16 | * William H. Press, Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery |
---|
17 | * |
---|
18 | * The original code is not-copyrighted. |
---|
19 | * The original routines are placed into the public domain |
---|
20 | * (see Appendix B: utility routines, pp 964) |
---|
21 | * for more information, visit http://www.nr.com |
---|
22 | */ |
---|
23 | |
---|
24 | /* |
---|
25 | * 2002/06/11 ajout des fonctions endline |
---|
26 | */ |
---|
27 | #include <stdio.h> |
---|
28 | #include <stddef.h> |
---|
29 | #include <stdlib.h> |
---|
30 | #include <malloc.h> |
---|
31 | #include <stdint.h> |
---|
32 | |
---|
33 | #include "nrc_os_config.h" |
---|
34 | #include "mypredef.h" |
---|
35 | #include "nrtype.h" |
---|
36 | #include "nrdef.h" |
---|
37 | #include "nrmacro.h" |
---|
38 | #include "nrkernel.h" |
---|
39 | |
---|
40 | #include "nralloc1.h" |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | #undef type_vector |
---|
45 | #define type_vector(t) \ |
---|
46 | t * short_name(t,,vector)(int32_t nl, int32_t nh) \ |
---|
47 | { \ |
---|
48 | t * v; \ |
---|
49 | v = malloc((nh - nl + 1 + NR_END) * sizeof(t)); \ |
---|
50 | if (v == NULL) { \ |
---|
51 | nrerror("*** Error: allocation failure in %s\n", __func__); \ |
---|
52 | } \ |
---|
53 | return v - nl + NR_END; \ |
---|
54 | } |
---|
55 | |
---|
56 | type_vector(int8_t); |
---|
57 | type_vector(uint8_t); |
---|
58 | type_vector(int16_t); |
---|
59 | type_vector(uint16_t); |
---|
60 | type_vector(int32_t); |
---|
61 | type_vector(uint32_t); |
---|
62 | type_vector(int64_t); |
---|
63 | type_vector(uint64_t); |
---|
64 | type_vector(float); |
---|
65 | type_vector(double); |
---|
66 | type_vector(void_p); |
---|
67 | type_vector(rgb8); |
---|
68 | type_vector(rgbx8); |
---|
69 | type_vector(rgb32); |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | #undef type_vector0 |
---|
74 | #define type_vector0(t) \ |
---|
75 | t * short_name(t,,vector0)(int32_t nl, int32_t nh) \ |
---|
76 | { \ |
---|
77 | t * v; \ |
---|
78 | v = calloc((nh - nl + 1 + NR_END), sizeof(t)); \ |
---|
79 | if (v == NULL) { \ |
---|
80 | nrerror("*** Error: allocation failure in %s\n", __func__); \ |
---|
81 | } \ |
---|
82 | return v - nl + NR_END; \ |
---|
83 | } |
---|
84 | |
---|
85 | type_vector0(int8_t); |
---|
86 | type_vector0(uint8_t); |
---|
87 | type_vector0(int16_t); |
---|
88 | type_vector0(uint16_t); |
---|
89 | type_vector0(int32_t); |
---|
90 | type_vector0(uint32_t); |
---|
91 | type_vector0(int64_t); |
---|
92 | type_vector0(uint64_t); |
---|
93 | type_vector0(float); |
---|
94 | type_vector0(double); |
---|
95 | type_vector0(void_p); |
---|
96 | type_vector0(rgb8); |
---|
97 | type_vector0(rgbx8); |
---|
98 | type_vector0(rgb32); |
---|
99 | |
---|
100 | |
---|
101 | #undef realloc_type_vector |
---|
102 | #define realloc_type_vector(t) \ |
---|
103 | t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh) \ |
---|
104 | { \ |
---|
105 | v += nl; \ |
---|
106 | v -= NR_END; \ |
---|
107 | v = realloc(v, (nh - nl + 1 + NR_END) * sizeof(t)); \ |
---|
108 | if (v == NULL) { \ |
---|
109 | nrerror("*** Error: allocation failure in %s\n", __func__); \ |
---|
110 | } \ |
---|
111 | return v - nl + NR_END; \ |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | realloc_type_vector(int8_t); |
---|
116 | realloc_type_vector(uint8_t); |
---|
117 | realloc_type_vector(int16_t); |
---|
118 | realloc_type_vector(uint16_t); |
---|
119 | realloc_type_vector(int32_t); |
---|
120 | realloc_type_vector(uint32_t); |
---|
121 | realloc_type_vector(int64_t); |
---|
122 | realloc_type_vector(uint64_t); |
---|
123 | realloc_type_vector(float); |
---|
124 | realloc_type_vector(double); |
---|
125 | realloc_type_vector(void_p); |
---|
126 | realloc_type_vector(rgb8); |
---|
127 | realloc_type_vector(rgbx8); |
---|
128 | realloc_type_vector(rgb32); |
---|
129 | |
---|
130 | |
---|
131 | #undef free_type_vector |
---|
132 | #define free_type_vector(t) \ |
---|
133 | void short_name(t,free_,vector)(t * v, long nl, long nh) \ |
---|
134 | { \ |
---|
135 | free((FREE_ARG) (v + nl - NR_END)); \ |
---|
136 | } |
---|
137 | |
---|
138 | free_type_vector(int8_t); |
---|
139 | free_type_vector(uint8_t); |
---|
140 | free_type_vector(int16_t); |
---|
141 | free_type_vector(uint16_t); |
---|
142 | free_type_vector(int32_t); |
---|
143 | free_type_vector(uint32_t); |
---|
144 | free_type_vector(int64_t); |
---|
145 | free_type_vector(uint64_t); |
---|
146 | free_type_vector(float); |
---|
147 | free_type_vector(double); |
---|
148 | free_type_vector(void_p); |
---|
149 | free_type_vector(rgb8); |
---|
150 | free_type_vector(rgbx8); |
---|
151 | free_type_vector(rgb32); |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | #if TARGET_OS == GIETVM |
---|
157 | #undef remote_type_vector |
---|
158 | #define remote_type_vector(t) \ |
---|
159 | t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y) \ |
---|
160 | { \ |
---|
161 | t * v; \ |
---|
162 | v = remote_malloc((nh - nl + 1 + NR_END) * sizeof(t), x, y); \ |
---|
163 | if (v == NULL) { \ |
---|
164 | nrerror("*** Error: allocation failure in %s\n", __func__); \ |
---|
165 | } \ |
---|
166 | return v - nl + NR_END; \ |
---|
167 | } |
---|
168 | |
---|
169 | remote_type_vector(int8_t); |
---|
170 | remote_type_vector(uint8_t); |
---|
171 | remote_type_vector(int16_t); |
---|
172 | remote_type_vector(uint16_t); |
---|
173 | remote_type_vector(int32_t); |
---|
174 | remote_type_vector(uint32_t); |
---|
175 | remote_type_vector(int64_t); |
---|
176 | remote_type_vector(uint64_t); |
---|
177 | remote_type_vector(float); |
---|
178 | remote_type_vector(double); |
---|
179 | remote_type_vector(void_p); |
---|
180 | remote_type_vector(rgb8); |
---|
181 | remote_type_vector(rgbx8); |
---|
182 | remote_type_vector(rgb32); |
---|
183 | |
---|
184 | #endif |
---|
185 | |
---|
186 | // Local Variables: |
---|
187 | // tab-width: 4 |
---|
188 | // c-basic-offset: 4 |
---|
189 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
190 | // indent-tabs-mode: nil |
---|
191 | // End: |
---|
192 | |
---|
193 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
194 | |
---|