UCommon
cpr.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
26 #ifndef _UCOMMON_CONFIG_H_
27 #include <ucommon/platform.h>
28 #endif
29 
30 #ifndef _UCOMMON_CPR_H_
31 #define _UCOMMON_CPR_H_
32 
33 #ifdef _MSWINDOWS_
34 
35 extern "C" {
36  __EXPORT int cpr_setenv(const char *s, const char *v, int p);
37 
38  inline int setenv(const char *s, const char *v, int overwrite)
39  {
40  return cpr_setenv(s, v, overwrite);
41  }
42 }
43 
44 #endif
45 
46 
53 __EXPORT void cpr_runtime_error(const char *text);
54 
55 extern "C" __EXPORT void *cpr_newp(void **handle, size_t size);
56 
57 extern "C" __EXPORT void cpr_freep(void **handle);
58 
65 extern "C" __EXPORT void *cpr_memalloc(size_t size) __MALLOC;
66 
76 extern "C" __EXPORT void *cpr_memassign(size_t size, caddr_t address, size_t known) __MALLOC;
77 
84 extern "C" __EXPORT void cpr_memswap(void *mem1, void *mem2, size_t size);
85 
86 #ifdef UCOMMON_SYSRUNTIME
87 
92 __EXPORT void *operator new(size_t size);
93 
99 __EXPORT void *operator new[](size_t size);
100 
109 __EXPORT void *operator new[](size_t size, void *address);
110 
120 __EXPORT void *operator new[](size_t size, void *address, size_t known);
121 
126 #if __cplusplus <= 199711L
127 __EXPORT void operator delete(void *object);
128 #else
129 __EXPORT void operator delete(void *object) noexcept (true);
130 #endif
131 
136 #if __cplusplus <= 199711L
137 __EXPORT void operator delete[](void *array);
138 #else
139 __EXPORT void operator delete[](void *array) noexcept(true);
140 #endif
141 
142 #ifdef __GNUC__
143 extern "C" __EXPORT void __cxa_pure_virtual(void);
144 #endif
145 #endif
146 
147 extern "C" {
148  __EXPORT uint16_t lsb_getshort(uint8_t *b);
149  __EXPORT uint32_t lsb_getlong(uint8_t *b);
150  __EXPORT uint16_t msb_getshort(uint8_t *b);
151  __EXPORT uint32_t msb_getlong(uint8_t *b);
152 
153  __EXPORT void lsb_setshort(uint8_t *b, uint16_t v);
154  __EXPORT void lsb_setlong(uint8_t *b, uint32_t v);
155  __EXPORT void msb_setshort(uint8_t *b, uint16_t v);
156  __EXPORT void msb_setlong(uint8_t *b, uint32_t v);
157 }
158 
159 template <typename T>
160 T *newp(T **handle) {
161  return static_cast<T*>(cpr_newp(handle, sizeof(T)));
162 }
163 
164 template <typename T>
165 void freep(T **handle) {
166  cpr_freep(handle);
167 }
168 
169 #endif
void * cpr_memalloc(size_t size)
Portable memory allocation helper function.
Various miscellaneous platform specific headers and defines.
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.
void cpr_runtime_error(const char *text)
Function to handle runtime errors.