-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
148 lines (132 loc) · 3.42 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifdef __GNUC__
#if __x86_64__
#define __LINUX__
#define __64__
#elif __i386__
#define __LINUX__
#define __32__
#else
#define __LINUX__
#define __32__
#endif
#elif _MSC_VER
#if _WIN64
#define __WINDOWS__
#define __64__
#elif _WIN32
#define __WINDOWS__
#define __32__
#else
#error "WINDOWS UNSUPPORTED BITS"
#endif
#else
#error "UNKNOWN PLATFORM"
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
#ifdef __WINDOWS__
#include <windows.h>
#endif
#include <lib/common/khash.h>
typedef struct td_delete_cb delete_cb;
typedef struct td_delete_cb_list delete_cb_list;
typedef struct td_bool_option bool_option;
typedef struct td_int32_option int32_option;
typedef struct td_uint32_option uint32_option;
typedef struct td_int64_option int64_option;
typedef struct td_uint64_option uint64_option;
typedef struct td_sjs_object sjs_object;
typedef struct td_sjs_interface sjs_interface;
typedef struct td_void_option void_option;
typedef struct td_char_option char_option;
typedef struct td_float_option float_option;
typedef struct td_double_option double_option;
struct td_delete_cb {
void* _parent;
void (*_cb)(void* _parent, void* object);
};
struct td_delete_cb_list {
int size;
delete_cb cb[5];
delete_cb_list* next;
};
struct td_bool_option {
bool isvalid;
bool value;
};
const bool_option bool_empty = { false };
struct td_int32_option {
bool isvalid;
int32_t value;
};
const int32_option int32_empty = { false };
struct td_uint32_option {
bool isvalid;
uint32_t value;
};
const uint32_option uint32_empty = { false };
struct td_int64_option {
bool isvalid;
int64_t value;
};
const int64_option int64_empty = { false };
struct td_uint64_option {
bool isvalid;
uint64_t value;
};
const uint64_option uint64_empty = { false };
struct td_void_option {
bool isvalid;
void* value;
};
const void_option void_empty = { false };
struct td_char_option {
bool isvalid;
char value;
};
const char_option char_empty = { false };
struct td_float_option {
bool isvalid;
float value;
};
const float_option float_empty = { false };
struct td_double_option {
bool isvalid;
double value;
};
const double_option double_empty = { false };
struct td_sjs_object {
int _refCount;
};
struct td_sjs_interface {
sjs_object* _parent;
void* _vtbl;
};
void halt(const char * format, ...);
void debugout(const char * format, ...);
void debugoutv(const char * format, va_list args);
void ptr_hash(void* p, uint32_t* result);
void ptr_isequal(void *p1, void* p2, bool* result);
void delete_cb_list_free(delete_cb_list* d);
void delete_cb_list_add(delete_cb_list* d, delete_cb cb);
void delete_cb_list_remove(delete_cb_list* d, delete_cb cb);
void delete_cb_list_invoke(delete_cb_list* d, void* p);
void weakptr_init();
void weakptr_release(void* v);
void weakptr_cb_add(void* v, delete_cb cb);
void weakptr_cb_remove(void* v, delete_cb cb);
void weakptr_clear(void* parent, void* v);
void ptr_init();
void ptr_retain(void* ptr);
bool ptr_release(void* ptr);
void _object_init(sjs_object* obj, int typeid, char* funcname);
void _object_retain(sjs_object* obj, char* funcname);
void _object_release(sjs_object* obj, char* funcname);
void _object_report(void);