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 #ifdef UCOMMON_SYSRUNTIME
84 
89 __EXPORT void *operator new(size_t size);
90 
96 __EXPORT void *operator new[](size_t size);
97 #endif
98 
99 #ifdef UCOMMON_SYSRUNTIME
100 
108 __EXPORT void *operator new[](size_t size, void *address);
109 
119 __EXPORT void *operator new[](size_t size, void *address, size_t known);
120 #endif
121 
122 #ifdef UCOMMON_SYSRUNTIME
123 
127 #if __cplusplus <= 199711L
128 __EXPORT void operator delete(void *object);
129 #else
130 __EXPORT void operator delete(void *object) noexcept (true);
131 #endif
132 
137 #if __cplusplus <= 199711L
138 __EXPORT void operator delete[](void *array);
139 #else
140 __EXPORT void operator delete[](void *array) noexcept(true);
141 #endif
142 
143 #ifdef __GNUC__
144 extern "C" __EXPORT void __cxa_pure_virtual(void);
145 #endif
146 #endif
147 
148 extern "C" {
149  __EXPORT uint16_t lsb_getshort(uint8_t *b);
150  __EXPORT uint32_t lsb_getlong(uint8_t *b);
151  __EXPORT uint16_t msb_getshort(uint8_t *b);
152  __EXPORT uint32_t msb_getlong(uint8_t *b);
153 
154  __EXPORT void lsb_setshort(uint8_t *b, uint16_t v);
155  __EXPORT void lsb_setlong(uint8_t *b, uint32_t v);
156  __EXPORT void msb_setshort(uint8_t *b, uint16_t v);
157  __EXPORT void msb_setlong(uint8_t *b, uint32_t v);
158 }
159 
160 template <typename T>
161 T *newp(T **handle) {
162  return (T*)cpr_newp(handle, sizeof(T));
163 }
164 
165 template <typename T>
166 void freep(T **handle) {
167  cpr_freep(handle);
168 }
169 
170 #endif
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_memalloc(size_t size)
Portable memory allocation helper function.
Various miscellaneous platform specific headers and defines.
void cpr_runtime_error(const char *text)
Function to handle runtime errors.