sq_detailed_metrics 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/extconf.rb +26 -0
  3. data/include/half.hpp +4575 -0
  4. data/include/msgpack.h +24 -0
  5. data/include/msgpack/fbuffer.h +42 -0
  6. data/include/msgpack/gcc_atomic.h +25 -0
  7. data/include/msgpack/object.h +118 -0
  8. data/include/msgpack/pack.h +174 -0
  9. data/include/msgpack/pack_define.h +18 -0
  10. data/include/msgpack/pack_template.h +952 -0
  11. data/include/msgpack/sbuffer.h +115 -0
  12. data/include/msgpack/sysdep.h +221 -0
  13. data/include/msgpack/timestamp.h +58 -0
  14. data/include/msgpack/unpack.h +281 -0
  15. data/include/msgpack/unpack_define.h +89 -0
  16. data/include/msgpack/unpack_template.h +471 -0
  17. data/include/msgpack/util.h +15 -0
  18. data/include/msgpack/version.h +38 -0
  19. data/include/msgpack/version_master.h +3 -0
  20. data/include/msgpack/vrefbuffer.h +144 -0
  21. data/include/msgpack/zbuffer.h +205 -0
  22. data/include/msgpack/zone.h +163 -0
  23. data/include/rapidjson/allocators.h +271 -0
  24. data/include/rapidjson/document.h +2575 -0
  25. data/include/rapidjson/encodedstream.h +299 -0
  26. data/include/rapidjson/encodings.h +716 -0
  27. data/include/rapidjson/error/en.h +74 -0
  28. data/include/rapidjson/error/error.h +155 -0
  29. data/include/rapidjson/filereadstream.h +99 -0
  30. data/include/rapidjson/filewritestream.h +104 -0
  31. data/include/rapidjson/fwd.h +151 -0
  32. data/include/rapidjson/internal/biginteger.h +290 -0
  33. data/include/rapidjson/internal/diyfp.h +258 -0
  34. data/include/rapidjson/internal/dtoa.h +245 -0
  35. data/include/rapidjson/internal/ieee754.h +78 -0
  36. data/include/rapidjson/internal/itoa.h +304 -0
  37. data/include/rapidjson/internal/meta.h +181 -0
  38. data/include/rapidjson/internal/pow10.h +55 -0
  39. data/include/rapidjson/internal/regex.h +701 -0
  40. data/include/rapidjson/internal/stack.h +230 -0
  41. data/include/rapidjson/internal/strfunc.h +55 -0
  42. data/include/rapidjson/internal/strtod.h +269 -0
  43. data/include/rapidjson/internal/swap.h +46 -0
  44. data/include/rapidjson/istreamwrapper.h +115 -0
  45. data/include/rapidjson/memorybuffer.h +70 -0
  46. data/include/rapidjson/memorystream.h +71 -0
  47. data/include/rapidjson/msinttypes/inttypes.h +316 -0
  48. data/include/rapidjson/msinttypes/stdint.h +300 -0
  49. data/include/rapidjson/ostreamwrapper.h +81 -0
  50. data/include/rapidjson/pointer.h +1358 -0
  51. data/include/rapidjson/prettywriter.h +255 -0
  52. data/include/rapidjson/rapidjson.h +615 -0
  53. data/include/rapidjson/reader.h +1879 -0
  54. data/include/rapidjson/schema.h +2006 -0
  55. data/include/rapidjson/stream.h +179 -0
  56. data/include/rapidjson/stringbuffer.h +117 -0
  57. data/include/rapidjson/writer.h +610 -0
  58. data/include/xxhash.h +328 -0
  59. data/json_conv.cpp +284 -0
  60. data/json_conv.hpp +17 -0
  61. data/metrics.cpp +239 -0
  62. data/metrics.hpp +84 -0
  63. data/msgpack/objectc.c +482 -0
  64. data/msgpack/unpack.c +703 -0
  65. data/msgpack/version.c +22 -0
  66. data/msgpack/vrefbuffer.c +250 -0
  67. data/msgpack/zone.c +222 -0
  68. data/sq_detailed_metrics.cpp +248 -0
  69. metadata +199 -0
@@ -0,0 +1,15 @@
1
+ /*
2
+ * MessagePack for C utilities
3
+ *
4
+ * Copyright (C) 2014 FURUHASHI Sadayuki
5
+ *
6
+ * Distributed under the Boost Software License, Version 1.0.
7
+ * (See accompanying file LICENSE_1_0.txt or copy at
8
+ * http://www.boost.org/LICENSE_1_0.txt)
9
+ */
10
+ #ifndef MSGPACK_UTIL_H
11
+ #define MSGPACK_UTIL_H
12
+
13
+ #define MSGPACK_UNUSED(a) (void)(a)
14
+
15
+ #endif /* MSGPACK_UTIL_H */
@@ -0,0 +1,38 @@
1
+ /*
2
+ * MessagePack for C version information
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Distributed under the Boost Software License, Version 1.0.
7
+ * (See accompanying file LICENSE_1_0.txt or copy at
8
+ * http://www.boost.org/LICENSE_1_0.txt)
9
+ */
10
+ #ifndef MSGPACK_VERSION_H
11
+ #define MSGPACK_VERSION_H
12
+
13
+ #ifdef __cplusplus
14
+ extern "C" {
15
+ #endif
16
+
17
+ MSGPACK_DLLEXPORT
18
+ const char* msgpack_version(void);
19
+ MSGPACK_DLLEXPORT
20
+ int msgpack_version_major(void);
21
+ MSGPACK_DLLEXPORT
22
+ int msgpack_version_minor(void);
23
+ MSGPACK_DLLEXPORT
24
+ int msgpack_version_revision(void);
25
+
26
+ #include "version_master.h"
27
+
28
+ #define MSGPACK_STR(v) #v
29
+ #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev)
30
+
31
+ #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION)
32
+
33
+ #ifdef __cplusplus
34
+ }
35
+ #endif
36
+
37
+ #endif /* msgpack/version.h */
38
+
@@ -0,0 +1,3 @@
1
+ #define MSGPACK_VERSION_MAJOR 3
2
+ #define MSGPACK_VERSION_MINOR 3
3
+ #define MSGPACK_VERSION_REVISION 0
@@ -0,0 +1,144 @@
1
+ /*
2
+ * MessagePack for C zero-copy buffer implementation
3
+ *
4
+ * Copyright (C) 2008-2009 FURUHASHI Sadayuki
5
+ *
6
+ * Distributed under the Boost Software License, Version 1.0.
7
+ * (See accompanying file LICENSE_1_0.txt or copy at
8
+ * http://www.boost.org/LICENSE_1_0.txt)
9
+ */
10
+ #ifndef MSGPACK_VREFBUFFER_H
11
+ #define MSGPACK_VREFBUFFER_H
12
+
13
+ #include "zone.h"
14
+ #include <stdlib.h>
15
+ #include <assert.h>
16
+
17
+ #if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__)
18
+ #include <sys/uio.h>
19
+ #else
20
+ struct iovec {
21
+ void *iov_base;
22
+ size_t iov_len;
23
+ };
24
+ #endif
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+
31
+ /**
32
+ * @defgroup msgpack_vrefbuffer Vectored Referencing buffer
33
+ * @ingroup msgpack_buffer
34
+ * @{
35
+ */
36
+
37
+ struct msgpack_vrefbuffer_chunk;
38
+ typedef struct msgpack_vrefbuffer_chunk msgpack_vrefbuffer_chunk;
39
+
40
+ typedef struct msgpack_vrefbuffer_inner_buffer {
41
+ size_t free;
42
+ char* ptr;
43
+ msgpack_vrefbuffer_chunk* head;
44
+ } msgpack_vrefbuffer_inner_buffer;
45
+
46
+ typedef struct msgpack_vrefbuffer {
47
+ struct iovec* tail;
48
+ struct iovec* end;
49
+ struct iovec* array;
50
+
51
+ size_t chunk_size;
52
+ size_t ref_size;
53
+
54
+ msgpack_vrefbuffer_inner_buffer inner_buffer;
55
+ } msgpack_vrefbuffer;
56
+
57
+
58
+ #ifndef MSGPACK_VREFBUFFER_REF_SIZE
59
+ #define MSGPACK_VREFBUFFER_REF_SIZE 32
60
+ #endif
61
+
62
+ #ifndef MSGPACK_VREFBUFFER_CHUNK_SIZE
63
+ #define MSGPACK_VREFBUFFER_CHUNK_SIZE 8192
64
+ #endif
65
+
66
+ MSGPACK_DLLEXPORT
67
+ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
68
+ size_t ref_size, size_t chunk_size);
69
+ MSGPACK_DLLEXPORT
70
+ void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf);
71
+
72
+ static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size);
73
+ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf);
74
+
75
+ static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len);
76
+
77
+ static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref);
78
+ static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref);
79
+
80
+ MSGPACK_DLLEXPORT
81
+ int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
82
+ const char* buf, size_t len);
83
+
84
+ MSGPACK_DLLEXPORT
85
+ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
86
+ const char* buf, size_t len);
87
+
88
+ MSGPACK_DLLEXPORT
89
+ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to);
90
+
91
+ MSGPACK_DLLEXPORT
92
+ void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref);
93
+
94
+ /** @} */
95
+
96
+
97
+ static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size)
98
+ {
99
+ msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer));
100
+ if (vbuf == NULL) return NULL;
101
+ if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) {
102
+ free(vbuf);
103
+ return NULL;
104
+ }
105
+ return vbuf;
106
+ }
107
+
108
+ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf)
109
+ {
110
+ if(vbuf == NULL) { return; }
111
+ msgpack_vrefbuffer_destroy(vbuf);
112
+ free(vbuf);
113
+ }
114
+
115
+ static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len)
116
+ {
117
+ msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data;
118
+ assert(buf || len == 0);
119
+
120
+ if(!buf) return 0;
121
+
122
+ if(len < vbuf->ref_size) {
123
+ return msgpack_vrefbuffer_append_copy(vbuf, buf, len);
124
+ } else {
125
+ return msgpack_vrefbuffer_append_ref(vbuf, buf, len);
126
+ }
127
+ }
128
+
129
+ static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref)
130
+ {
131
+ return vref->array;
132
+ }
133
+
134
+ static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref)
135
+ {
136
+ return (size_t)(vref->tail - vref->array);
137
+ }
138
+
139
+
140
+ #ifdef __cplusplus
141
+ }
142
+ #endif
143
+
144
+ #endif /* msgpack/vrefbuffer.h */
@@ -0,0 +1,205 @@
1
+ /*
2
+ * MessagePack for C deflate buffer implementation
3
+ *
4
+ * Copyright (C) 2010 FURUHASHI Sadayuki
5
+ *
6
+ * Distributed under the Boost Software License, Version 1.0.
7
+ * (See accompanying file LICENSE_1_0.txt or copy at
8
+ * http://www.boost.org/LICENSE_1_0.txt)
9
+ */
10
+ #ifndef MSGPACK_ZBUFFER_H
11
+ #define MSGPACK_ZBUFFER_H
12
+
13
+ #include "sysdep.h"
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+ #include <assert.h>
17
+ #include <zlib.h>
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+
24
+ /**
25
+ * @defgroup msgpack_zbuffer Compressed buffer
26
+ * @ingroup msgpack_buffer
27
+ * @{
28
+ */
29
+
30
+ typedef struct msgpack_zbuffer {
31
+ z_stream stream;
32
+ char* data;
33
+ size_t init_size;
34
+ } msgpack_zbuffer;
35
+
36
+ #ifndef MSGPACK_ZBUFFER_INIT_SIZE
37
+ #define MSGPACK_ZBUFFER_INIT_SIZE 8192
38
+ #endif
39
+
40
+ static inline bool msgpack_zbuffer_init(
41
+ msgpack_zbuffer* zbuf, int level, size_t init_size);
42
+ static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf);
43
+
44
+ static inline msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size);
45
+ static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf);
46
+
47
+ static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf);
48
+
49
+ static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf);
50
+ static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf);
51
+
52
+ static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf);
53
+ static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf);
54
+ static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf);
55
+
56
+
57
+ #ifndef MSGPACK_ZBUFFER_RESERVE_SIZE
58
+ #define MSGPACK_ZBUFFER_RESERVE_SIZE 512
59
+ #endif
60
+
61
+ static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len);
62
+
63
+ static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf);
64
+
65
+
66
+ static inline bool msgpack_zbuffer_init(msgpack_zbuffer* zbuf,
67
+ int level, size_t init_size)
68
+ {
69
+ memset(zbuf, 0, sizeof(msgpack_zbuffer));
70
+ zbuf->init_size = init_size;
71
+ if(deflateInit(&zbuf->stream, level) != Z_OK) {
72
+ free(zbuf->data);
73
+ return false;
74
+ }
75
+ return true;
76
+ }
77
+
78
+ static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf)
79
+ {
80
+ deflateEnd(&zbuf->stream);
81
+ free(zbuf->data);
82
+ }
83
+
84
+ static inline msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size)
85
+ {
86
+ msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer));
87
+ if (zbuf == NULL) return NULL;
88
+ if(!msgpack_zbuffer_init(zbuf, level, init_size)) {
89
+ free(zbuf);
90
+ return NULL;
91
+ }
92
+ return zbuf;
93
+ }
94
+
95
+ static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf)
96
+ {
97
+ if(zbuf == NULL) { return; }
98
+ msgpack_zbuffer_destroy(zbuf);
99
+ free(zbuf);
100
+ }
101
+
102
+ static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf)
103
+ {
104
+ size_t used = (size_t)((char *)(zbuf->stream.next_out) - zbuf->data);
105
+ size_t csize = used + zbuf->stream.avail_out;
106
+
107
+ size_t nsize = (csize == 0) ? zbuf->init_size : csize * 2;
108
+
109
+ char* tmp = (char*)realloc(zbuf->data, nsize);
110
+ if(tmp == NULL) {
111
+ return false;
112
+ }
113
+
114
+ zbuf->data = tmp;
115
+ zbuf->stream.next_out = (Bytef*)(tmp + used);
116
+ zbuf->stream.avail_out = (uInt)(nsize - used);
117
+
118
+ return true;
119
+ }
120
+
121
+ static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len)
122
+ {
123
+ msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data;
124
+
125
+ assert(buf || len == 0);
126
+ if(!buf) return 0;
127
+
128
+ zbuf->stream.next_in = (Bytef*)buf;
129
+ zbuf->stream.avail_in = (uInt)len;
130
+
131
+ while(zbuf->stream.avail_in > 0) {
132
+ if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) {
133
+ if(!msgpack_zbuffer_expand(zbuf)) {
134
+ return -1;
135
+ }
136
+ }
137
+
138
+ if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) {
139
+ return -1;
140
+ }
141
+ }
142
+
143
+ return 0;
144
+ }
145
+
146
+ static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf)
147
+ {
148
+ while(true) {
149
+ switch(deflate(&zbuf->stream, Z_FINISH)) {
150
+ case Z_STREAM_END:
151
+ return zbuf->data;
152
+ case Z_OK:
153
+ case Z_BUF_ERROR:
154
+ if(!msgpack_zbuffer_expand(zbuf)) {
155
+ return NULL;
156
+ }
157
+ break;
158
+ default:
159
+ return NULL;
160
+ }
161
+ }
162
+ }
163
+
164
+ static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf)
165
+ {
166
+ return zbuf->data;
167
+ }
168
+
169
+ static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf)
170
+ {
171
+ return (size_t)((char *)(zbuf->stream.next_out) - zbuf->data);
172
+ }
173
+
174
+ static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf)
175
+ {
176
+ zbuf->stream.avail_out += (uInt)((char*)zbuf->stream.next_out - zbuf->data);
177
+ zbuf->stream.next_out = (Bytef*)zbuf->data;
178
+ }
179
+
180
+ static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf)
181
+ {
182
+ if(deflateReset(&zbuf->stream) != Z_OK) {
183
+ return false;
184
+ }
185
+ msgpack_zbuffer_reset_buffer(zbuf);
186
+ return true;
187
+ }
188
+
189
+ static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf)
190
+ {
191
+ char* tmp = zbuf->data;
192
+ zbuf->data = NULL;
193
+ zbuf->stream.next_out = NULL;
194
+ zbuf->stream.avail_out = 0;
195
+ return tmp;
196
+ }
197
+
198
+ /** @} */
199
+
200
+
201
+ #ifdef __cplusplus
202
+ }
203
+ #endif
204
+
205
+ #endif /* msgpack/zbuffer.h */
@@ -0,0 +1,163 @@
1
+ /*
2
+ * MessagePack for C memory pool implementation
3
+ *
4
+ * Copyright (C) 2008-2010 FURUHASHI Sadayuki
5
+ *
6
+ * Distributed under the Boost Software License, Version 1.0.
7
+ * (See accompanying file LICENSE_1_0.txt or copy at
8
+ * http://www.boost.org/LICENSE_1_0.txt)
9
+ */
10
+ #ifndef MSGPACK_ZONE_H
11
+ #define MSGPACK_ZONE_H
12
+
13
+ #include "sysdep.h"
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+
20
+ /**
21
+ * @defgroup msgpack_zone Memory zone
22
+ * @ingroup msgpack
23
+ * @{
24
+ */
25
+
26
+ typedef struct msgpack_zone_finalizer {
27
+ void (*func)(void* data);
28
+ void* data;
29
+ } msgpack_zone_finalizer;
30
+
31
+ typedef struct msgpack_zone_finalizer_array {
32
+ msgpack_zone_finalizer* tail;
33
+ msgpack_zone_finalizer* end;
34
+ msgpack_zone_finalizer* array;
35
+ } msgpack_zone_finalizer_array;
36
+
37
+ struct msgpack_zone_chunk;
38
+ typedef struct msgpack_zone_chunk msgpack_zone_chunk;
39
+
40
+ typedef struct msgpack_zone_chunk_list {
41
+ size_t free;
42
+ char* ptr;
43
+ msgpack_zone_chunk* head;
44
+ } msgpack_zone_chunk_list;
45
+
46
+ typedef struct msgpack_zone {
47
+ msgpack_zone_chunk_list chunk_list;
48
+ msgpack_zone_finalizer_array finalizer_array;
49
+ size_t chunk_size;
50
+ } msgpack_zone;
51
+
52
+ #ifndef MSGPACK_ZONE_CHUNK_SIZE
53
+ #define MSGPACK_ZONE_CHUNK_SIZE 8192
54
+ #endif
55
+
56
+ MSGPACK_DLLEXPORT
57
+ bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size);
58
+ MSGPACK_DLLEXPORT
59
+ void msgpack_zone_destroy(msgpack_zone* zone);
60
+
61
+ MSGPACK_DLLEXPORT
62
+ msgpack_zone* msgpack_zone_new(size_t chunk_size);
63
+ MSGPACK_DLLEXPORT
64
+ void msgpack_zone_free(msgpack_zone* zone);
65
+
66
+ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size);
67
+ static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size);
68
+
69
+ static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone,
70
+ void (*func)(void* data), void* data);
71
+
72
+ static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b);
73
+
74
+ MSGPACK_DLLEXPORT
75
+ bool msgpack_zone_is_empty(msgpack_zone* zone);
76
+
77
+ MSGPACK_DLLEXPORT
78
+ void msgpack_zone_clear(msgpack_zone* zone);
79
+
80
+ /** @} */
81
+
82
+
83
+ #ifndef MSGPACK_ZONE_ALIGN
84
+ #define MSGPACK_ZONE_ALIGN sizeof(void*)
85
+ #endif
86
+
87
+ MSGPACK_DLLEXPORT
88
+ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size);
89
+
90
+ static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size)
91
+ {
92
+ char* ptr;
93
+ msgpack_zone_chunk_list* cl = &zone->chunk_list;
94
+
95
+ if(zone->chunk_list.free < size) {
96
+ return msgpack_zone_malloc_expand(zone, size);
97
+ }
98
+
99
+ ptr = cl->ptr;
100
+ cl->free -= size;
101
+ cl->ptr += size;
102
+
103
+ return ptr;
104
+ }
105
+
106
+ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size)
107
+ {
108
+ char* aligned =
109
+ (char*)(
110
+ (size_t)(
111
+ zone->chunk_list.ptr + (MSGPACK_ZONE_ALIGN - 1)
112
+ ) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN
113
+ );
114
+ size_t adjusted_size = size + (size_t)(aligned - zone->chunk_list.ptr);
115
+ if(zone->chunk_list.free >= adjusted_size) {
116
+ zone->chunk_list.free -= adjusted_size;
117
+ zone->chunk_list.ptr += adjusted_size;
118
+ return aligned;
119
+ }
120
+ {
121
+ void* ptr = msgpack_zone_malloc_expand(zone, size + (MSGPACK_ZONE_ALIGN - 1));
122
+ if (ptr) {
123
+ return (char*)((size_t)(ptr) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN);
124
+ }
125
+ }
126
+ return NULL;
127
+ }
128
+
129
+
130
+ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
131
+ void (*func)(void* data), void* data);
132
+
133
+ static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone,
134
+ void (*func)(void* data), void* data)
135
+ {
136
+ msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
137
+ msgpack_zone_finalizer* fin = fa->tail;
138
+
139
+ if(fin == fa->end) {
140
+ return msgpack_zone_push_finalizer_expand(zone, func, data);
141
+ }
142
+
143
+ fin->func = func;
144
+ fin->data = data;
145
+
146
+ ++fa->tail;
147
+
148
+ return true;
149
+ }
150
+
151
+ static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b)
152
+ {
153
+ msgpack_zone tmp = *a;
154
+ *a = *b;
155
+ *b = tmp;
156
+ }
157
+
158
+
159
+ #ifdef __cplusplus
160
+ }
161
+ #endif
162
+
163
+ #endif /* msgpack/zone.h */