UCommon
cpr.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 //
3 // This file is part of GNU uCommon C++.
4 //
5 // GNU uCommon C++ is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GNU uCommon C++ is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17 
25 #ifndef _UCOMMON_CONFIG_H_
26 #include <ucommon/platform.h>
27 #endif
28 
29 #ifndef _UCOMMON_CPR_H_
30 #define _UCOMMON_CPR_H_
31 
32 #ifdef _MSWINDOWS_
33 
34 extern "C" {
35  __EXPORT int cpr_setenv(const char *s, const char *v, int p);
36 
37  inline int setenv(const char *s, const char *v, int overwrite)
38  {return cpr_setenv(s, v, overwrite);}
39 }
40 
41 #endif
42 
43 
50 __EXPORT void cpr_runtime_error(const char *text);
51 
52 extern "C" __EXPORT void *cpr_newp(void **handle, size_t size);
53 
54 extern "C" __EXPORT void cpr_freep(void **handle);
55 
62 extern "C" __EXPORT void *cpr_memalloc(size_t size) __MALLOC;
63 
73 extern "C" __EXPORT void *cpr_memassign(size_t size, caddr_t address, size_t known) __MALLOC;
74 
81 extern "C" __EXPORT void cpr_memswap(void *mem1, void *mem2, size_t size);
82 
83 #ifndef _UCOMMON_EXTENDED_
84 
89 __EXPORT void *operator new(size_t size);
90 
96 __EXPORT void *operator new[](size_t size);
97 #endif
98 
99 #ifndef _UCOMMON_EXTENDED_
100 
108 __EXPORT void *operator new[](size_t size, caddr_t address);
109 
119 __EXPORT void *operator new[](size_t size, caddr_t address, size_t known);
120 #endif
121 
131 __EXPORT void *operator new(size_t size, size_t extra);
132 
141 __EXPORT void *operator new(size_t size, caddr_t address);
142 
153 __EXPORT void *operator new(size_t size, caddr_t address, size_t known);
154 
155 #ifndef _UCOMMON_EXTENDED_
156 
160 #if __cplusplus <= 199711L
161 __EXPORT void operator delete(void *object);
162 #else
163 __EXPORT void operator delete(void *object) noexcept (true);
164 #endif
165 
170 #if __cplusplus <= 199711L
171 __EXPORT void operator delete[](void *array);
172 #else
173 __EXPORT void operator delete[](void *array) noexcept(true);
174 #endif
175 
176 #ifdef __GNUC__
177 extern "C" __EXPORT void __cxa_pure_virtual(void);
178 #endif
179 #endif
180 
181 extern "C" {
182  __EXPORT uint16_t lsb_getshort(uint8_t *b);
183  __EXPORT uint32_t lsb_getlong(uint8_t *b);
184  __EXPORT uint16_t msb_getshort(uint8_t *b);
185  __EXPORT uint32_t msb_getlong(uint8_t *b);
186 
187  __EXPORT void lsb_setshort(uint8_t *b, uint16_t v);
188  __EXPORT void lsb_setlong(uint8_t *b, uint32_t v);
189  __EXPORT void msb_setshort(uint8_t *b, uint16_t v);
190  __EXPORT void msb_setlong(uint8_t *b, uint32_t v);
191 }
192 
193 template <typename T>
194 T *newp(T **handle) {
195  return (T*)cpr_newp(handle, sizeof(T));
196 }
197 
198 template <typename T>
199 void freep(T **handle) {
200  cpr_freep(handle);
201 }
202 
203 #endif
void cpr_runtime_error(const char *text)
Function to handle runtime errors.
Various miscellaneous platform specific headers and defines.
void * cpr_memalloc(size_t size)
Portable memory allocation helper function.
void cpr_memswap(void *mem1, void *mem2, size_t size)
Portable swap code.
void * cpr_memassign(size_t size, caddr_t address, size_t known)
Portable memory placement helper function.