iodine 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of iodine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -2
- data/ext/iodine/fio.c +319 -46
- data/ext/iodine/fio.h +851 -37
- data/ext/iodine/fio_cli.c +17 -16
- data/ext/iodine/fio_json_parser.h +28 -3
- data/ext/iodine/fiobj_ary.c +44 -46
- data/ext/iodine/fiobj_data.c +12 -13
- data/ext/iodine/fiobj_hash.c +28 -27
- data/ext/iodine/fiobj_json.c +40 -33
- data/ext/iodine/fiobj_numbers.c +2 -304
- data/ext/iodine/fiobj_str.c +0 -1
- data/ext/iodine/fiobject.c +268 -38
- data/ext/iodine/iodine_json.c +13 -14
- data/ext/iodine/iodine_store.c +33 -29
- data/iodine.gemspec +1 -3
- data/lib/iodine.rb +2 -2
- data/lib/iodine/json.rb +3 -1
- data/lib/iodine/version.rb +1 -1
- metadata +5 -4
- data/ext/iodine/fio_ary.h +0 -717
data/ext/iodine/fio_cli.c
CHANGED
@@ -28,11 +28,11 @@ typedef struct {
|
|
28
28
|
#define FIO_SET_KEY_COMPARE(o1, o2) \
|
29
29
|
(o1.len == o2.len && \
|
30
30
|
(o1.data == o2.data || !memcmp(o1.data, o2.data, o1.len)))
|
31
|
-
#define FIO_SET_NAME
|
31
|
+
#define FIO_SET_NAME fio_cli_hash
|
32
32
|
#include <fio.h>
|
33
33
|
|
34
|
-
static
|
35
|
-
static
|
34
|
+
static fio_cli_hash_s fio_aliases = FIO_SET_INIT;
|
35
|
+
static fio_cli_hash_s fio_values = FIO_SET_INIT;
|
36
36
|
static size_t fio_unknown_count = 0;
|
37
37
|
|
38
38
|
typedef struct {
|
@@ -63,7 +63,8 @@ static void fio_cli_map_line2alias(char const *line) {
|
|
63
63
|
++n.len;
|
64
64
|
}
|
65
65
|
const char *old = NULL;
|
66
|
-
|
66
|
+
fio_cli_hash_insert(&fio_aliases, FIO_CLI_HASH_VAL(n), n, (void *)line,
|
67
|
+
&old);
|
67
68
|
if (old) {
|
68
69
|
FIO_LOG_WARNING("CLI argument name conflict detected\n"
|
69
70
|
" The following two directives conflict:\n"
|
@@ -122,7 +123,7 @@ static void fio_cli_set_arg(cstr_s arg, char const *value, char const *line,
|
|
122
123
|
goto print_help;
|
123
124
|
}
|
124
125
|
cstr_s n = {.len = ++parser->unknown_count};
|
125
|
-
|
126
|
+
fio_cli_hash_insert(&fio_values, n.len, n, value, NULL);
|
126
127
|
if (!parser->allow_unknown) {
|
127
128
|
arg.len = 0;
|
128
129
|
goto error;
|
@@ -170,7 +171,7 @@ static void fio_cli_set_arg(cstr_s arg, char const *value, char const *line,
|
|
170
171
|
while (n.data[n.len] && n.data[n.len] != ' ' && n.data[n.len] != ',') {
|
171
172
|
++n.len;
|
172
173
|
}
|
173
|
-
|
174
|
+
fio_cli_hash_insert(&fio_values, FIO_CLI_HASH_VAL(n), n, value, NULL);
|
174
175
|
while (n.data[n.len] && (n.data[n.len] == ' ' || n.data[n.len] == ',')) {
|
175
176
|
++n.len;
|
176
177
|
}
|
@@ -295,7 +296,7 @@ void fio_cli_start AVOID_MACRO(int argc, char const *argv[], int allow_unknown,
|
|
295
296
|
.pos = 0,
|
296
297
|
};
|
297
298
|
|
298
|
-
if (
|
299
|
+
if (fio_cli_hash_count(&fio_values)) {
|
299
300
|
fio_cli_end();
|
300
301
|
}
|
301
302
|
|
@@ -324,7 +325,7 @@ void fio_cli_start AVOID_MACRO(int argc, char const *argv[], int allow_unknown,
|
|
324
325
|
}
|
325
326
|
const char *l = NULL;
|
326
327
|
while (n.len &&
|
327
|
-
!(l =
|
328
|
+
!(l = fio_cli_hash_find(&fio_aliases, FIO_CLI_HASH_VAL(n), n))) {
|
328
329
|
--n.len;
|
329
330
|
value = n.data + n.len;
|
330
331
|
}
|
@@ -336,13 +337,13 @@ void fio_cli_start AVOID_MACRO(int argc, char const *argv[], int allow_unknown,
|
|
336
337
|
}
|
337
338
|
|
338
339
|
/* Cleanup and save state for API */
|
339
|
-
|
340
|
+
fio_cli_hash_free(&fio_aliases);
|
340
341
|
fio_unknown_count = parser.unknown_count;
|
341
342
|
}
|
342
343
|
|
343
344
|
void fio_cli_end(void) {
|
344
|
-
|
345
|
-
|
345
|
+
fio_cli_hash_free(&fio_values);
|
346
|
+
fio_cli_hash_free(&fio_aliases);
|
346
347
|
fio_unknown_count = 0;
|
347
348
|
}
|
348
349
|
/* *****************************************************************************
|
@@ -352,10 +353,10 @@ CLI Data Access
|
|
352
353
|
/** Returns the argument's value as a NUL terminated C String. */
|
353
354
|
char const *fio_cli_get(char const *name) {
|
354
355
|
cstr_s n = {.data = name, .len = strlen(name)};
|
355
|
-
if (!
|
356
|
+
if (!fio_cli_hash_count(&fio_values)) {
|
356
357
|
return NULL;
|
357
358
|
}
|
358
|
-
return
|
359
|
+
return fio_cli_hash_find(&fio_values, FIO_CLI_HASH_VAL(n), n);
|
359
360
|
}
|
360
361
|
|
361
362
|
/** Returns the argument's value as an integer. */
|
@@ -388,11 +389,11 @@ unsigned int fio_cli_unknown_count(void) {
|
|
388
389
|
|
389
390
|
/** Returns the unrecognized argument using a 0 based `index`. */
|
390
391
|
char const *fio_cli_unknown(unsigned int index) {
|
391
|
-
if (!
|
392
|
+
if (!fio_cli_hash_count(&fio_values) || !fio_unknown_count) {
|
392
393
|
return NULL;
|
393
394
|
}
|
394
395
|
cstr_s n = {.data = NULL, .len = index + 1};
|
395
|
-
return
|
396
|
+
return fio_cli_hash_find(&fio_values, index + 1, n);
|
396
397
|
}
|
397
398
|
|
398
399
|
/**
|
@@ -403,5 +404,5 @@ char const *fio_cli_unknown(unsigned int index) {
|
|
403
404
|
*/
|
404
405
|
void fio_cli_set(char const *name, char const *value) {
|
405
406
|
cstr_s n = (cstr_s){.data = name, .len = strlen(name)};
|
406
|
-
|
407
|
+
fio_cli_hash_insert(&fio_values, FIO_CLI_HASH_VAL(n), n, value, NULL);
|
407
408
|
}
|
@@ -275,6 +275,30 @@ static inline int seek2eos(uint8_t **buffer,
|
|
275
275
|
return 0;
|
276
276
|
}
|
277
277
|
|
278
|
+
/* *****************************************************************************
|
279
|
+
JSON String to Numeral Helpers - allowing for stand-alone mode
|
280
|
+
***************************************************************************** */
|
281
|
+
|
282
|
+
#ifndef H_FACIL_IO_H /* defined in fio.h */
|
283
|
+
|
284
|
+
/**
|
285
|
+
* We include this in case the parser is used outside of facil.io.
|
286
|
+
*/
|
287
|
+
int64_t __attribute__((weak)) fio_atol(char **pstr) {
|
288
|
+
return strtoll((char *)*pstr, (char **)pstr, 0);
|
289
|
+
}
|
290
|
+
#pragma weak fio_atol
|
291
|
+
|
292
|
+
/**
|
293
|
+
* We include this in case the parser is used outside of facil.io.
|
294
|
+
*/
|
295
|
+
double __attribute__((weak)) fio_atof(char **pstr) {
|
296
|
+
return strtod((char *)*pstr, (char **)pstr);
|
297
|
+
}
|
298
|
+
#pragma weak fio_atof
|
299
|
+
|
300
|
+
#endif
|
301
|
+
|
278
302
|
/* *****************************************************************************
|
279
303
|
JSON Consumption (astract parsing)
|
280
304
|
***************************************************************************** */
|
@@ -425,12 +449,13 @@ fio_json_parse(json_parser_s *parser, const char *buffer, size_t length) {
|
|
425
449
|
case 'i': /* overflow */
|
426
450
|
case 'I': /* overflow */
|
427
451
|
numeral : {
|
428
|
-
uint8_t *tmp =
|
429
|
-
long long i =
|
452
|
+
uint8_t *tmp = pos;
|
453
|
+
long long i = fio_atol((char **)&tmp);
|
430
454
|
if (tmp > limit)
|
431
455
|
goto stop;
|
432
456
|
if (!tmp || JSON_NUMERAL[*tmp]) {
|
433
|
-
|
457
|
+
tmp = pos;
|
458
|
+
double f = fio_atof((char **)&tmp);
|
434
459
|
if (tmp > limit)
|
435
460
|
goto stop;
|
436
461
|
if (!tmp || JSON_NUMERAL[*tmp])
|
data/ext/iodine/fiobj_ary.c
CHANGED
@@ -2,32 +2,25 @@
|
|
2
2
|
Copyright: Boaz Segev, 2017-2018
|
3
3
|
License: MIT
|
4
4
|
*/
|
5
|
-
|
6
|
-
#define FIO_OVERRIDE_MALLOC 1
|
7
5
|
#include <fio.h>
|
8
6
|
#include <fiobject.h>
|
9
7
|
|
8
|
+
#define FIO_ARY_NAME fio_ary__
|
10
9
|
#define FIO_ARY_TYPE FIOBJ
|
11
10
|
#define FIO_ARY_TYPE_INVALID FIOBJ_INVALID
|
12
11
|
#define FIO_ARY_TYPE_COMPARE(a, b) (fiobj_iseq((a), (b)))
|
13
|
-
#
|
12
|
+
#define FIO_ARY_INVALID FIOBJ_INVALID
|
13
|
+
#include <fio.h>
|
14
14
|
|
15
15
|
#include <assert.h>
|
16
16
|
|
17
|
-
#ifndef FIOBJ_ARRAY_DEFAULT_CAPA
|
18
|
-
#define FIOBJ_ARRAY_DEFAULT_CAPA 8
|
19
|
-
#endif
|
20
|
-
#ifndef FIOBJ_ARRAY_DEFAULT_OFFSET
|
21
|
-
#define FIOBJ_ARRAY_DEFAULT_OFFSET (FIOBJ_ARRAY_DEFAULT_CAPA >> 2)
|
22
|
-
#endif
|
23
|
-
|
24
17
|
/* *****************************************************************************
|
25
18
|
Array Type
|
26
19
|
***************************************************************************** */
|
27
20
|
|
28
21
|
typedef struct {
|
29
22
|
fiobj_object_header_s head;
|
30
|
-
|
23
|
+
fio_ary___s ary;
|
31
24
|
} fiobj_ary_s;
|
32
25
|
|
33
26
|
#define obj2ary(o) ((fiobj_ary_s *)(o))
|
@@ -37,20 +30,20 @@ VTable
|
|
37
30
|
***************************************************************************** */
|
38
31
|
|
39
32
|
static void fiobj_ary_dealloc(FIOBJ o, void (*task)(FIOBJ, void *), void *arg) {
|
40
|
-
FIO_ARY_FOR(&obj2ary(o)->ary, i) { task(i
|
41
|
-
|
42
|
-
|
33
|
+
FIO_ARY_FOR((&obj2ary(o)->ary), i) { task(*i, arg); }
|
34
|
+
fio_ary___free(&obj2ary(o)->ary);
|
35
|
+
fio_free(FIOBJ2PTR(o));
|
43
36
|
}
|
44
37
|
|
45
38
|
static size_t fiobj_ary_each1(FIOBJ o, size_t start_at,
|
46
39
|
int (*task)(FIOBJ obj, void *arg), void *arg) {
|
47
|
-
return
|
40
|
+
return fio_ary___each(&obj2ary(o)->ary, start_at, task, arg);
|
48
41
|
}
|
49
42
|
|
50
43
|
static size_t fiobj_ary_is_eq(const FIOBJ self, const FIOBJ other) {
|
51
|
-
|
52
|
-
|
53
|
-
if (
|
44
|
+
fio_ary___s *a = &obj2ary(self)->ary;
|
45
|
+
fio_ary___s *b = &obj2ary(other)->ary;
|
46
|
+
if (fio_ary___count(a) != fio_ary___count(b))
|
54
47
|
return 0;
|
55
48
|
return 1;
|
56
49
|
}
|
@@ -58,7 +51,7 @@ static size_t fiobj_ary_is_eq(const FIOBJ self, const FIOBJ other) {
|
|
58
51
|
/** Returns the number of elements in the Array. */
|
59
52
|
size_t fiobj_ary_count(const FIOBJ ary) {
|
60
53
|
assert(FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
61
|
-
return
|
54
|
+
return fio_ary___count(&obj2ary(ary)->ary);
|
62
55
|
}
|
63
56
|
|
64
57
|
static size_t fiobj_ary_is_true(const FIOBJ ary) {
|
@@ -85,8 +78,8 @@ const fiobj_object_vtable_s FIOBJECT_VTABLE_ARRAY = {
|
|
85
78
|
Allocation
|
86
79
|
***************************************************************************** */
|
87
80
|
|
88
|
-
static FIOBJ fiobj_ary_alloc(size_t capa
|
89
|
-
fiobj_ary_s *ary =
|
81
|
+
static inline FIOBJ fiobj_ary_alloc(size_t capa) {
|
82
|
+
fiobj_ary_s *ary = fio_malloc(sizeof(*ary));
|
90
83
|
if (!ary) {
|
91
84
|
perror("ERROR: fiobj array couldn't allocate memory");
|
92
85
|
exit(errno);
|
@@ -98,17 +91,15 @@ static FIOBJ fiobj_ary_alloc(size_t capa, size_t start_at) {
|
|
98
91
|
.type = FIOBJ_T_ARRAY,
|
99
92
|
},
|
100
93
|
};
|
101
|
-
|
102
|
-
|
94
|
+
if (capa)
|
95
|
+
fio_ary_____require_on_top(&ary->ary, capa);
|
103
96
|
return (FIOBJ)ary;
|
104
97
|
}
|
105
98
|
|
106
99
|
/** Creates a mutable empty Array object. Use `fiobj_free` when done. */
|
107
|
-
FIOBJ fiobj_ary_new(void) {
|
108
|
-
return fiobj_ary_alloc(FIOBJ_ARRAY_DEFAULT_CAPA, FIOBJ_ARRAY_DEFAULT_OFFSET);
|
109
|
-
}
|
100
|
+
FIOBJ fiobj_ary_new(void) { return fiobj_ary_alloc(0); }
|
110
101
|
/** Creates a mutable empty Array object with the requested capacity. */
|
111
|
-
FIOBJ fiobj_ary_new2(size_t capa) { return fiobj_ary_alloc(capa
|
102
|
+
FIOBJ fiobj_ary_new2(size_t capa) { return fiobj_ary_alloc(capa); }
|
112
103
|
|
113
104
|
/* *****************************************************************************
|
114
105
|
Array direct entry access API
|
@@ -117,7 +108,7 @@ Array direct entry access API
|
|
117
108
|
/** Returns the current, temporary, array capacity (it's dynamic). */
|
118
109
|
size_t fiobj_ary_capa(FIOBJ ary) {
|
119
110
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
120
|
-
return
|
111
|
+
return fio_ary___capa(&obj2ary(ary)->ary);
|
121
112
|
}
|
122
113
|
|
123
114
|
/**
|
@@ -139,7 +130,7 @@ FIOBJ *fiobj_ary2ptr(FIOBJ ary) {
|
|
139
130
|
*/
|
140
131
|
FIOBJ fiobj_ary_index(FIOBJ ary, int64_t pos) {
|
141
132
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
142
|
-
return
|
133
|
+
return fio_ary___get(&obj2ary(ary)->ary, pos);
|
143
134
|
}
|
144
135
|
|
145
136
|
/**
|
@@ -147,7 +138,8 @@ FIOBJ fiobj_ary_index(FIOBJ ary, int64_t pos) {
|
|
147
138
|
*/
|
148
139
|
void fiobj_ary_set(FIOBJ ary, FIOBJ obj, int64_t pos) {
|
149
140
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
150
|
-
FIOBJ old =
|
141
|
+
FIOBJ old = FIOBJ_INVALID;
|
142
|
+
fio_ary___set(&obj2ary(ary)->ary, pos, obj, &old);
|
151
143
|
fiobj_free(old);
|
152
144
|
}
|
153
145
|
|
@@ -160,13 +152,15 @@ Array push / shift API
|
|
160
152
|
*/
|
161
153
|
void fiobj_ary_push(FIOBJ ary, FIOBJ obj) {
|
162
154
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
163
|
-
|
155
|
+
fio_ary___push(&obj2ary(ary)->ary, obj);
|
164
156
|
}
|
165
157
|
|
166
158
|
/** Pops an object from the end of the Array. */
|
167
159
|
FIOBJ fiobj_ary_pop(FIOBJ ary) {
|
168
160
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
169
|
-
|
161
|
+
FIOBJ ret = FIOBJ_INVALID;
|
162
|
+
fio_ary___pop(&obj2ary(ary)->ary, &ret);
|
163
|
+
return ret;
|
170
164
|
}
|
171
165
|
|
172
166
|
/**
|
@@ -175,13 +169,15 @@ FIOBJ fiobj_ary_pop(FIOBJ ary) {
|
|
175
169
|
*/
|
176
170
|
void fiobj_ary_unshift(FIOBJ ary, FIOBJ obj) {
|
177
171
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
178
|
-
|
172
|
+
fio_ary___unshift(&obj2ary(ary)->ary, obj);
|
179
173
|
}
|
180
174
|
|
181
175
|
/** Shifts an object from the beginning of the Array. */
|
182
176
|
FIOBJ fiobj_ary_shift(FIOBJ ary) {
|
183
177
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
184
|
-
|
178
|
+
FIOBJ ret = FIOBJ_INVALID;
|
179
|
+
fio_ary___shift(&obj2ary(ary)->ary, &ret);
|
180
|
+
return ret;
|
185
181
|
}
|
186
182
|
|
187
183
|
/* *****************************************************************************
|
@@ -205,7 +201,7 @@ FIOBJ fiobj_ary_replace(FIOBJ ary, FIOBJ obj, int64_t pos) {
|
|
205
201
|
*/
|
206
202
|
int64_t fiobj_ary_find(FIOBJ ary, FIOBJ data) {
|
207
203
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
208
|
-
return (int64_t)
|
204
|
+
return (int64_t)fio_ary___find(&obj2ary(ary)->ary, data);
|
209
205
|
}
|
210
206
|
|
211
207
|
/**
|
@@ -216,8 +212,8 @@ int64_t fiobj_ary_find(FIOBJ ary, FIOBJ data) {
|
|
216
212
|
*/
|
217
213
|
int fiobj_ary_remove(FIOBJ ary, int64_t pos) {
|
218
214
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
219
|
-
FIOBJ old =
|
220
|
-
if (
|
215
|
+
FIOBJ old = FIOBJ_INVALID;
|
216
|
+
if (fio_ary___remove(&obj2ary(ary)->ary, (intptr_t)pos, &old)) {
|
221
217
|
return -1;
|
222
218
|
}
|
223
219
|
fiobj_free(old);
|
@@ -232,8 +228,7 @@ int fiobj_ary_remove(FIOBJ ary, int64_t pos) {
|
|
232
228
|
*/
|
233
229
|
int fiobj_ary_remove2(FIOBJ ary, FIOBJ data) {
|
234
230
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
235
|
-
|
236
|
-
if (found == -1) {
|
231
|
+
if (-1 == fio_ary___remove2(&obj2ary(ary)->ary, data, &data)) {
|
237
232
|
return -1;
|
238
233
|
}
|
239
234
|
fiobj_free(data);
|
@@ -253,7 +248,7 @@ Array compacting (untested)
|
|
253
248
|
*/
|
254
249
|
void fiobj_ary_compact(FIOBJ ary) {
|
255
250
|
assert(ary && FIOBJ_TYPE_IS(ary, FIOBJ_T_ARRAY));
|
256
|
-
|
251
|
+
fio_ary___compact(&obj2ary(ary)->ary);
|
257
252
|
}
|
258
253
|
|
259
254
|
/* *****************************************************************************
|
@@ -271,7 +266,7 @@ void fiobj_test_array(void) {
|
|
271
266
|
}
|
272
267
|
FIOBJ a = fiobj_ary_new2(4);
|
273
268
|
TEST_ASSERT(FIOBJ_TYPE_IS(a, FIOBJ_T_ARRAY), "Array type isn't an array!\n");
|
274
|
-
TEST_ASSERT(fiobj_ary_capa(a)
|
269
|
+
TEST_ASSERT(fiobj_ary_capa(a) > 4, "Array capacity ignored!\n");
|
275
270
|
fiobj_ary_push(a, fiobj_null());
|
276
271
|
TEST_ASSERT(fiobj_ary2ptr(a)[0] == fiobj_null(),
|
277
272
|
"Array direct access failed!\n");
|
@@ -279,7 +274,8 @@ void fiobj_test_array(void) {
|
|
279
274
|
fiobj_ary_push(a, fiobj_false());
|
280
275
|
TEST_ASSERT(fiobj_ary_count(a) == 3, "Array count isn't 3\n");
|
281
276
|
fiobj_ary_set(a, fiobj_true(), 63);
|
282
|
-
TEST_ASSERT(fiobj_ary_count(a) == 64, "Array count isn't 64\n"
|
277
|
+
TEST_ASSERT(fiobj_ary_count(a) == 64, "Array count isn't 64 (%zu)\n",
|
278
|
+
fiobj_ary_count(a));
|
283
279
|
TEST_ASSERT(fiobj_ary_index(a, 0) == fiobj_null(),
|
284
280
|
"Array index retrival error for fiobj_null\n");
|
285
281
|
TEST_ASSERT(fiobj_ary_index(a, 1) == fiobj_true(),
|
@@ -303,8 +299,9 @@ void fiobj_test_array(void) {
|
|
303
299
|
"Array replace didn't return correct value\n");
|
304
300
|
|
305
301
|
FIO_ARY_FOR(&obj2ary(a)->ary, pos) {
|
306
|
-
if (pos
|
307
|
-
fprintf(stderr, "%lu) %s\n", pos
|
302
|
+
if (*pos) {
|
303
|
+
fprintf(stderr, "%lu) %s\n", pos - obj2ary(a)->ary.arry,
|
304
|
+
fiobj_obj2cstr(*pos).data);
|
308
305
|
}
|
309
306
|
}
|
310
307
|
|
@@ -315,8 +312,9 @@ void fiobj_test_array(void) {
|
|
315
312
|
TEST_ASSERT(fiobj_ary_count(a) == 3, "Array remove error\n");
|
316
313
|
|
317
314
|
FIO_ARY_FOR(&obj2ary(a)->ary, pos) {
|
318
|
-
if (pos
|
319
|
-
fprintf(stderr, "%lu) %s\n", pos
|
315
|
+
if (*pos) {
|
316
|
+
fprintf(stderr, "%lu) %s\n", pos - obj2ary(a)->ary.arry,
|
317
|
+
fiobj_obj2cstr(*pos).data);
|
320
318
|
}
|
321
319
|
}
|
322
320
|
|
data/ext/iodine/fiobj_data.c
CHANGED
@@ -29,7 +29,6 @@ License: MIT
|
|
29
29
|
#include <sys/types.h>
|
30
30
|
#include <unistd.h>
|
31
31
|
|
32
|
-
#define FIO_OVERRIDE_MALLOC 1
|
33
32
|
#include <fio.h>
|
34
33
|
|
35
34
|
/* *****************************************************************************
|
@@ -66,19 +65,19 @@ Object required VTable and functions
|
|
66
65
|
|
67
66
|
static void fiobj_data_copy_buffer(FIOBJ o) {
|
68
67
|
obj2io(o)->capa = (((obj2io(o)->len) >> 12) + 1) << 12;
|
69
|
-
void *tmp =
|
68
|
+
void *tmp = fio_malloc(obj2io(o)->capa);
|
70
69
|
REQUIRE_MEM(tmp);
|
71
70
|
memcpy(tmp, obj2io(o)->buffer, obj2io(o)->len);
|
72
71
|
if (obj2io(o)->source.dealloc)
|
73
72
|
obj2io(o)->source.dealloc(obj2io(o)->buffer);
|
74
|
-
obj2io(o)->source.dealloc =
|
73
|
+
obj2io(o)->source.dealloc = fio_free;
|
75
74
|
obj2io(o)->buffer = tmp;
|
76
75
|
}
|
77
76
|
|
78
77
|
static void fiobj_data_copy_parent(FIOBJ o) {
|
79
78
|
switch (obj2io(obj2io(o)->source.parent)->fd) {
|
80
79
|
case -1:
|
81
|
-
obj2io(o)->buffer =
|
80
|
+
obj2io(o)->buffer = fio_malloc(obj2io(o)->len + 1);
|
82
81
|
memcpy(obj2io(o)->buffer,
|
83
82
|
obj2io(obj2io(o)->source.parent)->buffer + obj2io(o)->capa,
|
84
83
|
obj2io(o)->len);
|
@@ -86,7 +85,7 @@ static void fiobj_data_copy_parent(FIOBJ o) {
|
|
86
85
|
obj2io(o)->capa = obj2io(o)->len;
|
87
86
|
obj2io(o)->fd = -1;
|
88
87
|
fiobj_free(obj2io(o)->source.parent);
|
89
|
-
obj2io(o)->source.dealloc =
|
88
|
+
obj2io(o)->source.dealloc = fio_free;
|
90
89
|
return;
|
91
90
|
default:
|
92
91
|
obj2io(o)->fd = fio_tmpfile();
|
@@ -125,7 +124,7 @@ static void fiobj_data_copy_parent(FIOBJ o) {
|
|
125
124
|
static inline void fiobj_data_pre_write(FIOBJ o, uintptr_t length) {
|
126
125
|
switch (obj2io(o)->fd) {
|
127
126
|
case -1:
|
128
|
-
if (obj2io(o)->source.dealloc !=
|
127
|
+
if (obj2io(o)->source.dealloc != fio_free) {
|
129
128
|
fiobj_data_copy_buffer(o);
|
130
129
|
}
|
131
130
|
break;
|
@@ -137,7 +136,7 @@ static inline void fiobj_data_pre_write(FIOBJ o, uintptr_t length) {
|
|
137
136
|
return;
|
138
137
|
/* add rounded pages (4096) to capacity */
|
139
138
|
obj2io(o)->capa = (((obj2io(o)->len + length) >> 12) + 1) << 12;
|
140
|
-
obj2io(o)->buffer =
|
139
|
+
obj2io(o)->buffer = fio_realloc(obj2io(o)->buffer, obj2io(o)->capa);
|
141
140
|
REQUIRE_MEM(obj2io(o)->buffer);
|
142
141
|
}
|
143
142
|
|
@@ -153,7 +152,7 @@ retry:
|
|
153
152
|
}
|
154
153
|
|
155
154
|
static FIOBJ fiobj_data_alloc(void *buffer, int fd) {
|
156
|
-
fiobj_data_s *io =
|
155
|
+
fiobj_data_s *io = fio_malloc(sizeof(*io));
|
157
156
|
REQUIRE_MEM(io);
|
158
157
|
*io = (fiobj_data_s){
|
159
158
|
.head = {.ref = 1, .type = FIOBJ_T_DATA},
|
@@ -175,10 +174,10 @@ static void fiobj_data_dealloc(FIOBJ o, void (*task)(FIOBJ, void *),
|
|
175
174
|
break;
|
176
175
|
default:
|
177
176
|
close(obj2io(o)->fd);
|
178
|
-
|
177
|
+
fio_free(obj2io(o)->buffer);
|
179
178
|
break;
|
180
179
|
}
|
181
|
-
|
180
|
+
fio_free((void *)o);
|
182
181
|
(void)task;
|
183
182
|
(void)arg;
|
184
183
|
}
|
@@ -325,10 +324,10 @@ Creating the IO object
|
|
325
324
|
|
326
325
|
/** Creates a new local in-memory IO object */
|
327
326
|
FIOBJ fiobj_data_newstr(void) {
|
328
|
-
FIOBJ o = fiobj_data_alloc(
|
327
|
+
FIOBJ o = fiobj_data_alloc(fio_malloc(4096), -1);
|
329
328
|
REQUIRE_MEM(obj2io(o)->buffer);
|
330
329
|
obj2io(o)->capa = 4096;
|
331
|
-
obj2io(o)->source.dealloc =
|
330
|
+
obj2io(o)->source.dealloc = fio_free;
|
332
331
|
return o;
|
333
332
|
}
|
334
333
|
|
@@ -348,7 +347,7 @@ FIOBJ fiobj_data_newstr2(void *buffer, uintptr_t length,
|
|
348
347
|
|
349
348
|
/** Creates a new local file IO object */
|
350
349
|
FIOBJ fiobj_data_newfd(int fd) {
|
351
|
-
FIOBJ o = fiobj_data_alloc(
|
350
|
+
FIOBJ o = fiobj_data_alloc(fio_malloc(4096), fd);
|
352
351
|
REQUIRE_MEM(obj2io(o)->buffer);
|
353
352
|
obj2io(o)->source.fpos = 0;
|
354
353
|
return o;
|