bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
1 |
/*
|
2 |
*/
|
|
3 |
||
4 |
#ifndef __H_DEFS__
|
|
5 |
#define __H_DEFS__
|
|
6 |
||
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
7 |
#include <limits.h> |
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
8 |
#include <stddef.h> |
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
9 |
|
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
10 |
/** @file
|
11 |
*
|
|
12 |
*/
|
|
13 |
||
14 |
#ifdef __cplusplus
|
|
15 |
#define BEGIN_DECLS extern "C" {
|
|
16 |
#else
|
|
17 |
#define BEGIN_DECLS
|
|
18 |
#endif /*__cplusplus*/ |
|
19 |
||
20 |
||
21 |
#ifdef __cplusplus
|
|
22 |
#define END_DECLS }
|
|
23 |
#else
|
|
24 |
#define END_DECLS
|
|
25 |
#endif /* __cplusplus */ |
|
26 |
||
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
27 |
BEGIN_DECLS
|
28 |
||
|
57
by Gustav Hartvigsson
* Tested print_backtrace() macro using MingW and Wine... Still needs testing on a real windows system. |
29 |
#include <stdio.h> |
30 |
#include <stdlib.h> |
|
31 |
||
32 |
||
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
33 |
#ifndef FALSE
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
34 |
/**
|
35 |
* FALSE has the absolute value of 0, it is used in as a way to represet a false
|
|
36 |
* value. A "not" value.
|
|
37 |
*/
|
|
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
38 |
#define FALSE 0
|
39 |
#endif
|
|
40 |
||
41 |
#ifndef TRUE
|
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
42 |
/** |
43 |
* TRUE represets a value that is true. A value that is "not false".
|
|
44 |
*/
|
|
45 |
#define TRUE (!FALSE)
|
|
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
46 |
#endif
|
47 |
||
|
53
by Gustav Hartvigsson
* Finnished up s_map_add () ??? |
48 |
#define S_POINTER_TO_HASH_T(p) ((hash_t)(unsigned long) p)
|
49 |
||
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
50 |
/**
|
51 |
* sboolean is the standard definition of a boolean value in SSTS.
|
|
52 |
*
|
|
53 |
* @sa TRUE
|
|
54 |
* @sa FALSE
|
|
55 |
*
|
|
56 |
* @note
|
|
57 |
* This is the way it is done in GLib, so it is done here too.
|
|
58 |
*/
|
|
59 |
typedef int sboolean; |
|
60 |
||
|
43
by Gustav Hartvigsson
* Code cleanup |
61 |
/** hash type */
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
62 |
typedef size_t hash_t; |
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
63 |
|
|
43
by Gustav Hartvigsson
* Code cleanup |
64 |
/** spointer is a convinience typedef of void * */
|
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
65 |
typedef void* spointer; |
66 |
||
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
67 |
/** sconstpointer is a convinience typedef of const void * */
|
68 |
typedef const void* sconstpointer; |
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
69 |
|
70 |
/**
|
|
71 |
* Represents different types of objects.
|
|
72 |
*
|
|
73 |
* @se STypeName
|
|
74 |
*/
|
|
|
23
by Gustav Hartvigsson
* Fixed some of the build warnings. |
75 |
typedef enum { |
|
43
by Gustav Hartvigsson
* Code cleanup |
76 |
S_TYPE_NONE = 0, |
77 |
S_TYPE_INT, |
|
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
78 |
S_TYPE_LONG, |
79 |
S_TYPE_SHORT, |
|
|
43
by Gustav Hartvigsson
* Code cleanup |
80 |
S_TYPE_CHAR, |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
81 |
S_TYPE_WCHAR, |
82 |
S_TYPE_UINT, |
|
83 |
S_TYPE_ULONG, |
|
84 |
S_TYPE_USHORT, |
|
|
43
by Gustav Hartvigsson
* Code cleanup |
85 |
S_TYPE_BOOLEAN, |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
86 |
S_TYPE_STRING, |
87 |
S_TYPE_WSTRING, |
|
|
43
by Gustav Hartvigsson
* Code cleanup |
88 |
S_TYPE_UNUSED_0, |
89 |
S_TYPE_UNUSED_1, |
|
90 |
S_TYPE_UNUSED_2, |
|
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
91 |
S_TYPE_POINTER, |
|
43
by Gustav Hartvigsson
* Code cleanup |
92 |
S_TYPE_OBJECT, |
93 |
S_TYPE_INVALID |
|
94 |
} SType; |
|
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
95 |
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
96 |
/** @brief
|
97 |
* The names of the SType's
|
|
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
98 |
*
|
99 |
*
|
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
100 |
*/
|
|
50
by Gustav Hartvigsson
* Added a bindings friendly way of getting the SType name. |
101 |
static char * STypeName[] __attribute__((unused)) = { |
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
102 |
"NONE", |
103 |
"INT", |
|
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
104 |
"LONG", |
105 |
"SHORT", |
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
106 |
"CHAR", |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
107 |
"WCHAR", |
108 |
"UINT", |
|
109 |
"ULONG", |
|
110 |
"USHORT" |
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
111 |
"BOOLEAN", |
|
49
by Gustav Hartvigsson
* started work SBox (Untested). |
112 |
"STRING", |
113 |
"WSTRING", |
|
114 |
"UNUSED_0/INVALID", |
|
115 |
"UNUSED_1/INVALID", |
|
116 |
"UNUSED_2/INVALID", |
|
117 |
"POINTER", |
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
118 |
"OBJECT", |
119 |
"INVALID", |
|
120 |
0x0, |
|
121 |
0x0, |
|
|
43
by Gustav Hartvigsson
* Code cleanup |
122 |
};
|
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
123 |
|
|
50
by Gustav Hartvigsson
* Added a bindings friendly way of getting the SType name. |
124 |
/**
|
125 |
* @brief Get the name of the SType.
|
|
126 |
*
|
|
127 |
* For use in bindings.
|
|
128 |
*/
|
|
129 |
char * s_type_get_name (SType k); |
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
130 |
|
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
131 |
/* Colour definitions for console prints */
|
132 |
#define RESET "\033[0m"
|
|
133 |
#define BLACK "\033[30m" /* Black */ |
|
134 |
#define RED "\033[31m" /* Red */ |
|
135 |
#define GREEN "\033[32m" /* Green */ |
|
136 |
#define YELLOW "\033[33m" /* Yellow */ |
|
137 |
#define BLUE "\033[34m" /* Blue */ |
|
138 |
#define MAGENTA "\033[35m" /* Magenta */ |
|
139 |
#define CYAN "\033[36m" /* Cyan */ |
|
140 |
#define WHITE "\033[37m" /* White */ |
|
141 |
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ |
|
142 |
#define BOLDRED "\033[1m\033[31m" /* Bold Red */ |
|
143 |
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ |
|
144 |
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ |
|
145 |
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ |
|
146 |
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ |
|
147 |
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ |
|
148 |
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ |
|
149 |
||
|
33
by Gustav Hartvigsson
* made test_macros.h a lil' bit more portable |
150 |
|
|
58
by Gustav Hartvigsson
* Added preliminary CMake commands for Windows. |
151 |
/* -------- TraceBack stuff ---- */
|
152 |
||
153 |
#define S_STACK_TRACKE_SIZE 128
|
|
154 |
||
155 |
#ifdef __unix__
|
|
156 |
//#pragma message ("We are a UNIX.") |
|
157 |
#include <execinfo.h> |
|
158 |
/** |
|
159 |
* Get a platform specific traceback.
|
|
160 |
*
|
|
161 |
* Works on UNIX's and Windows.
|
|
162 |
*/
|
|
163 |
#define print_backtrace() {\ |
|
164 |
fprintf (stderr, "[BACKTRACE:]\n");\
|
|
165 |
void ** _backtrace_data_ = calloc (S_STACK_TRACKE_SIZE, sizeof (void *));\
|
|
166 |
int _backtrace_len_ = backtrace (_backtrace_data_, 10);\
|
|
167 |
char ** _backtrace_strs_ = backtrace_symbols (_backtrace_data_, _backtrace_len_);\
|
|
168 |
if (_backtrace_strs_ == NULL) {\
|
|
169 |
fprintf (stderr, "Could not get backtrace...\n");\
|
|
170 |
} else {\
|
|
171 |
for (int i = 0; i < _backtrace_len_; i++) {\
|
|
172 |
fprintf (stderr, "%s\n", _backtrace_strs_[i]);\
|
|
173 |
}\
|
|
174 |
free (_backtrace_strs_);\
|
|
175 |
}\
|
|
176 |
fprintf (stderr, "[END BACKTRACE]\n");\
|
|
177 |
}
|
|
178 |
#elif __WIN32__ || __WIN64__
|
|
179 |
//#pragma message ("We are a Windows (why, oh why?)") |
|
180 |
#include <windows.h> |
|
181 |
#include <dbghelp.h> |
|
182 |
#include <winbase.h> |
|
183 |
#if __WIN64__ |
|
184 |
#define _PLATFORM_SPECIFIC_DWORD DWORD64 |
|
185 |
#else |
|
186 |
#define _PLATFORM_SPECIFIC_DWORD DWORD |
|
187 |
#endif |
|
188 |
#define print_backtrace() {\ |
|
189 |
fprintf (stderr, "[BACKTRACE:]\n");\
|
|
190 |
void * _backtrace_stack[S_STACK_TRACKE_SIZE];\
|
|
191 |
HANDLE _backtrace_proc = GetCurrentProcess ();\
|
|
192 |
SymInitialize (_backtrace_proc, 0, TRUE);\
|
|
193 |
unsigned short _backtrace_frames = CaptureStackBackTrace ( 0, S_STACK_TRACKE_SIZE, _backtrace_stack, NULL );\
|
|
194 |
SYMBOL_INFO * _backtrace_symbol = calloc (1, sizeof (SYMBOL_INFOW) + (sizeof (char) * 256));\
|
|
195 |
_backtrace_symbol->MaxNameLen = 255;\
|
|
196 |
_backtrace_symbol->SizeOfStruct = sizeof (SYMBOL_INFO);\
|
|
197 |
for (int i = 0; i <= _backtrace_frames; i++) {\
|
|
198 |
SymFromAddr (_backtrace_proc, (_PLATFORM_SPECIFIC_DWORD)(_backtrace_stack[i]), 0, _backtrace_symbol);\
|
|
199 |
fprintf (stderr, "%i: %s - 0x%0X\n", _backtrace_frames - i, _backtrace_symbol->Name, _backtrace_symbol->Address);\
|
|
200 |
}\
|
|
201 |
SymCleanup (_backtrace_proc);\
|
|
202 |
free (_backtrace_symbol);\
|
|
203 |
fprintf (stderr, "[END BACKTRACE]\n");\
|
|
204 |
}
|
|
205 |
#else
|
|
206 |
//#pragma message ("We are not a UNIX or a Windows") |
|
207 |
#define print_backtrace() {\ |
|
208 |
fprintf(stdout, "[Can not get backtrace]\nCurrent Function:" __func__);\
|
|
209 |
fprintf (stderr, "[END BACKTRACE]\n");\
|
|
210 |
}
|
|
211 |
#endif
|
|
212 |
||
|
26
by Gustav Hartvigsson
* Added something to config.h.in, still not sure how it cmake works. |
213 |
END_DECLS
|
214 |
||
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
215 |
#endif
|