isomorfeus-iodine 0.7.47 → 0.7.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.github/workflows/ruby.yml +2 -1
- data/.gitlab-ci.yml +8 -0
- data/CHANGELOG.md +1052 -1038
- data/Gemfile +10 -11
- data/Rakefile +1 -9
- data/bin/console +18 -22
- data/bitbucket-pipelines.yml +9 -0
- data/examples/etag.ru +16 -0
- data/ext/{iodine → iodine_ext}/extconf.rb +1 -1
- data/ext/{iodine → iodine_ext}/fio.c +0 -0
- data/ext/{iodine → iodine_ext}/fio.h +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.h +189 -189
- data/ext/{iodine → iodine_ext}/fio_json_parser.h +687 -687
- data/ext/{iodine → iodine_ext}/fio_siphash.c +157 -157
- data/ext/{iodine → iodine_ext}/fio_siphash.h +37 -37
- data/ext/{iodine → iodine_ext}/fio_tls.h +129 -129
- data/ext/{iodine → iodine_ext}/fio_tls_missing.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tls_openssl.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tmpfile.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj.h +44 -44
- data/ext/{iodine → iodine_ext}/fiobj4fio.h +21 -21
- data/ext/{iodine → iodine_ext}/fiobj_ary.c +333 -333
- data/ext/{iodine → iodine_ext}/fiobj_ary.h +139 -139
- data/ext/{iodine → iodine_ext}/fiobj_data.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_data.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.h +176 -176
- data/ext/{iodine → iodine_ext}/fiobj_json.c +622 -622
- data/ext/{iodine → iodine_ext}/fiobj_json.h +68 -68
- data/ext/{iodine → iodine_ext}/fiobj_mem.h +71 -71
- data/ext/{iodine → iodine_ext}/fiobj_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_mustache.h +62 -62
- data/ext/{iodine → iodine_ext}/fiobj_numbers.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_numbers.h +127 -127
- data/ext/{iodine → iodine_ext}/fiobj_str.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_str.h +172 -172
- data/ext/{iodine → iodine_ext}/fiobject.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobject.h +0 -0
- data/ext/{iodine → iodine_ext}/hpack.h +1923 -1923
- data/ext/{iodine → iodine_ext}/http.c +14 -27
- data/ext/{iodine → iodine_ext}/http.h +1002 -1002
- data/ext/{iodine → iodine_ext}/http1.c +0 -0
- data/ext/{iodine → iodine_ext}/http1.h +29 -29
- data/ext/{iodine → iodine_ext}/http1_parser.h +873 -873
- data/ext/{iodine → iodine_ext}/http_internal.c +0 -0
- data/ext/{iodine → iodine_ext}/http_internal.h +0 -0
- data/ext/{iodine → iodine_ext}/http_mime_parser.h +350 -350
- data/ext/{iodine → iodine_ext}/iodine.c +1 -1
- data/ext/{iodine → iodine_ext}/iodine.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.h +55 -55
- data/ext/{iodine → iodine_ext}/iodine_defer.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_defer.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_fiobj2rb.h +120 -120
- data/ext/{iodine → iodine_ext}/iodine_helpers.c +282 -282
- data/ext/{iodine → iodine_ext}/iodine_helpers.h +12 -12
- data/ext/{iodine → iodine_ext}/iodine_http.c +0 -2
- data/ext/{iodine → iodine_ext}/iodine_http.h +23 -23
- data/ext/{iodine → iodine_ext}/iodine_json.c +302 -302
- data/ext/{iodine → iodine_ext}/iodine_json.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_mustache.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_pubsub.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_pubsub.h +26 -26
- data/ext/{iodine → iodine_ext}/iodine_rack_io.c +0 -8
- data/ext/{iodine → iodine_ext}/iodine_rack_io.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_store.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_store.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_tcp.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tcp.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.h +13 -13
- data/ext/{iodine → iodine_ext}/mustache_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.c +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.h +0 -0
- data/ext/{iodine → iodine_ext}/resp_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/websocket_parser.h +505 -505
- data/ext/{iodine → iodine_ext}/websockets.c +0 -0
- data/ext/{iodine → iodine_ext}/websockets.h +185 -185
- data/isomorfeus-iodine.gemspec +1 -2
- data/lib/iodine/version.rb +1 -1
- data/lib/iodine.rb +1 -1
- metadata +82 -79
@@ -1,68 +1,68 @@
|
|
1
|
-
#ifndef H_FIOBJ_JSON_H
|
2
|
-
#define H_FIOBJ_JSON_H
|
3
|
-
|
4
|
-
/*
|
5
|
-
Copyright: Boaz Segev, 2017-2019
|
6
|
-
License: MIT
|
7
|
-
*/
|
8
|
-
|
9
|
-
#include <fiobj_ary.h>
|
10
|
-
#include <fiobj_hash.h>
|
11
|
-
#include <fiobj_numbers.h>
|
12
|
-
#include <fiobj_str.h>
|
13
|
-
#include <fiobject.h>
|
14
|
-
|
15
|
-
#ifdef __cplusplus
|
16
|
-
extern "C" {
|
17
|
-
#endif
|
18
|
-
|
19
|
-
/* *****************************************************************************
|
20
|
-
JSON API
|
21
|
-
***************************************************************************** */
|
22
|
-
|
23
|
-
/** Limit JSON nesting, 32 is the limit to accomodate a 32 bit type. */
|
24
|
-
#if !defined(JSON_MAX_DEPTH) || JSON_MAX_DEPTH > 32
|
25
|
-
#undef JSON_MAX_DEPTH
|
26
|
-
#define JSON_MAX_DEPTH 32
|
27
|
-
#endif
|
28
|
-
|
29
|
-
/**
|
30
|
-
* Parses JSON, setting `pobj` to point to the new Object.
|
31
|
-
*
|
32
|
-
* Returns the number of bytes consumed. On Error, 0 is returned and no data is
|
33
|
-
* consumed.
|
34
|
-
*/
|
35
|
-
size_t fiobj_json2obj(FIOBJ *pobj, const void *data, size_t len);
|
36
|
-
/**
|
37
|
-
* Stringify an object into a JSON string. Remember to `fiobj_free`.
|
38
|
-
*
|
39
|
-
* Note that only the foloowing basic fiobj types are supported: Primitives
|
40
|
-
* (True / False / NULL), Numbers (Number / Float), Strings, Hashes and Arrays.
|
41
|
-
*
|
42
|
-
* Some objects (such as the POSIX specific IO type) are unsupported and may be
|
43
|
-
* formatted incorrectly.
|
44
|
-
*/
|
45
|
-
FIOBJ fiobj_obj2json(FIOBJ, uint8_t pretty);
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Formats an object into a JSON string, appending the JSON string to an
|
49
|
-
* existing String. Remember to `fiobj_free` as usual.
|
50
|
-
*
|
51
|
-
* Note that only the following basic fiobj types are supported: Primitives
|
52
|
-
* (True / False / NULL), Numbers (Number / Float), Strings, Hashes and
|
53
|
-
* Arrays.
|
54
|
-
*
|
55
|
-
* Some objects (such as the POSIX specific IO type) are unsupported and may be
|
56
|
-
* formatted incorrectly.
|
57
|
-
*/
|
58
|
-
FIOBJ fiobj_obj2json2(FIOBJ dest, FIOBJ object, uint8_t pretty);
|
59
|
-
|
60
|
-
#if DEBUG
|
61
|
-
void fiobj_test_json(void);
|
62
|
-
#endif
|
63
|
-
|
64
|
-
#ifdef __cplusplus
|
65
|
-
} /* extern "C" */
|
66
|
-
#endif
|
67
|
-
|
68
|
-
#endif
|
1
|
+
#ifndef H_FIOBJ_JSON_H
|
2
|
+
#define H_FIOBJ_JSON_H
|
3
|
+
|
4
|
+
/*
|
5
|
+
Copyright: Boaz Segev, 2017-2019
|
6
|
+
License: MIT
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <fiobj_ary.h>
|
10
|
+
#include <fiobj_hash.h>
|
11
|
+
#include <fiobj_numbers.h>
|
12
|
+
#include <fiobj_str.h>
|
13
|
+
#include <fiobject.h>
|
14
|
+
|
15
|
+
#ifdef __cplusplus
|
16
|
+
extern "C" {
|
17
|
+
#endif
|
18
|
+
|
19
|
+
/* *****************************************************************************
|
20
|
+
JSON API
|
21
|
+
***************************************************************************** */
|
22
|
+
|
23
|
+
/** Limit JSON nesting, 32 is the limit to accomodate a 32 bit type. */
|
24
|
+
#if !defined(JSON_MAX_DEPTH) || JSON_MAX_DEPTH > 32
|
25
|
+
#undef JSON_MAX_DEPTH
|
26
|
+
#define JSON_MAX_DEPTH 32
|
27
|
+
#endif
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Parses JSON, setting `pobj` to point to the new Object.
|
31
|
+
*
|
32
|
+
* Returns the number of bytes consumed. On Error, 0 is returned and no data is
|
33
|
+
* consumed.
|
34
|
+
*/
|
35
|
+
size_t fiobj_json2obj(FIOBJ *pobj, const void *data, size_t len);
|
36
|
+
/**
|
37
|
+
* Stringify an object into a JSON string. Remember to `fiobj_free`.
|
38
|
+
*
|
39
|
+
* Note that only the foloowing basic fiobj types are supported: Primitives
|
40
|
+
* (True / False / NULL), Numbers (Number / Float), Strings, Hashes and Arrays.
|
41
|
+
*
|
42
|
+
* Some objects (such as the POSIX specific IO type) are unsupported and may be
|
43
|
+
* formatted incorrectly.
|
44
|
+
*/
|
45
|
+
FIOBJ fiobj_obj2json(FIOBJ, uint8_t pretty);
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Formats an object into a JSON string, appending the JSON string to an
|
49
|
+
* existing String. Remember to `fiobj_free` as usual.
|
50
|
+
*
|
51
|
+
* Note that only the following basic fiobj types are supported: Primitives
|
52
|
+
* (True / False / NULL), Numbers (Number / Float), Strings, Hashes and
|
53
|
+
* Arrays.
|
54
|
+
*
|
55
|
+
* Some objects (such as the POSIX specific IO type) are unsupported and may be
|
56
|
+
* formatted incorrectly.
|
57
|
+
*/
|
58
|
+
FIOBJ fiobj_obj2json2(FIOBJ dest, FIOBJ object, uint8_t pretty);
|
59
|
+
|
60
|
+
#if DEBUG
|
61
|
+
void fiobj_test_json(void);
|
62
|
+
#endif
|
63
|
+
|
64
|
+
#ifdef __cplusplus
|
65
|
+
} /* extern "C" */
|
66
|
+
#endif
|
67
|
+
|
68
|
+
#endif
|
@@ -1,71 +1,71 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz Segev, 2018
|
3
|
-
License: MIT
|
4
|
-
|
5
|
-
Feel free to copy, use and enjoy according to the license provided.
|
6
|
-
*/
|
7
|
-
#ifndef H_FIOBJ_MEM_H
|
8
|
-
|
9
|
-
/**
|
10
|
-
* This is a placeholder for facil.io memory allocator functions in fio.h.
|
11
|
-
*
|
12
|
-
* In cases where the FIOBJ library is extracted from facil.io, these functions
|
13
|
-
* will call the system's memory allocator (`malloc`, `free`, etc').
|
14
|
-
*/
|
15
|
-
#define H_FIOBJ_MEM_H
|
16
|
-
|
17
|
-
#include <stdlib.h>
|
18
|
-
|
19
|
-
/**
|
20
|
-
* Allocates memory using a per-CPU core block memory pool.
|
21
|
-
* Memory is zeroed out.
|
22
|
-
*
|
23
|
-
* Allocations above FIO_MEMORY_BLOCK_ALLOC_LIMIT (12,288 bytes when using 32Kb
|
24
|
-
* blocks) will be redirected to `mmap`, as if `fio_mmap` was called.
|
25
|
-
*/
|
26
|
-
void *fio_malloc(size_t size);
|
27
|
-
|
28
|
-
/**
|
29
|
-
* same as calling `fio_malloc(size_per_unit * unit_count)`;
|
30
|
-
*
|
31
|
-
* Allocations above FIO_MEMORY_BLOCK_ALLOC_LIMIT (12,288 bytes when using 32Kb
|
32
|
-
* blocks) will be redirected to `mmap`, as if `fio_mmap` was called.
|
33
|
-
*/
|
34
|
-
void *fio_calloc(size_t size_per_unit, size_t unit_count);
|
35
|
-
|
36
|
-
/** Frees memory that was allocated using this library. */
|
37
|
-
void fio_free(void *ptr);
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Re-allocates memory. An attept to avoid copying the data is made only for big
|
41
|
-
* memory allocations (larger than FIO_MEMORY_BLOCK_ALLOC_LIMIT).
|
42
|
-
*/
|
43
|
-
void *fio_realloc(void *ptr, size_t new_size);
|
44
|
-
|
45
|
-
/**
|
46
|
-
* Re-allocates memory. An attept to avoid copying the data is made only for big
|
47
|
-
* memory allocations (larger than FIO_MEMORY_BLOCK_ALLOC_LIMIT).
|
48
|
-
*
|
49
|
-
* This variation is slightly faster as it might copy less data.
|
50
|
-
*/
|
51
|
-
void *fio_realloc2(void *ptr, size_t new_size, size_t copy_length);
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Allocates memory directly using `mmap`, this is prefered for objects that
|
55
|
-
* both require almost a page of memory (or more) and expect a long lifetime.
|
56
|
-
*
|
57
|
-
* However, since this allocation will invoke the system call (`mmap`), it will
|
58
|
-
* be inherently slower.
|
59
|
-
*
|
60
|
-
* `fio_free` can be used for deallocating the memory.
|
61
|
-
*/
|
62
|
-
void *fio_mmap(size_t size);
|
63
|
-
|
64
|
-
#if FIO_OVERRIDE_MALLOC
|
65
|
-
#define malloc fio_malloc
|
66
|
-
#define free fio_free
|
67
|
-
#define realloc fio_realloc
|
68
|
-
#define calloc fio_calloc
|
69
|
-
#endif
|
70
|
-
|
71
|
-
#endif /* H_FIOBJ_MEM_H */
|
1
|
+
/*
|
2
|
+
Copyright: Boaz Segev, 2018
|
3
|
+
License: MIT
|
4
|
+
|
5
|
+
Feel free to copy, use and enjoy according to the license provided.
|
6
|
+
*/
|
7
|
+
#ifndef H_FIOBJ_MEM_H
|
8
|
+
|
9
|
+
/**
|
10
|
+
* This is a placeholder for facil.io memory allocator functions in fio.h.
|
11
|
+
*
|
12
|
+
* In cases where the FIOBJ library is extracted from facil.io, these functions
|
13
|
+
* will call the system's memory allocator (`malloc`, `free`, etc').
|
14
|
+
*/
|
15
|
+
#define H_FIOBJ_MEM_H
|
16
|
+
|
17
|
+
#include <stdlib.h>
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Allocates memory using a per-CPU core block memory pool.
|
21
|
+
* Memory is zeroed out.
|
22
|
+
*
|
23
|
+
* Allocations above FIO_MEMORY_BLOCK_ALLOC_LIMIT (12,288 bytes when using 32Kb
|
24
|
+
* blocks) will be redirected to `mmap`, as if `fio_mmap` was called.
|
25
|
+
*/
|
26
|
+
void *fio_malloc(size_t size);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* same as calling `fio_malloc(size_per_unit * unit_count)`;
|
30
|
+
*
|
31
|
+
* Allocations above FIO_MEMORY_BLOCK_ALLOC_LIMIT (12,288 bytes when using 32Kb
|
32
|
+
* blocks) will be redirected to `mmap`, as if `fio_mmap` was called.
|
33
|
+
*/
|
34
|
+
void *fio_calloc(size_t size_per_unit, size_t unit_count);
|
35
|
+
|
36
|
+
/** Frees memory that was allocated using this library. */
|
37
|
+
void fio_free(void *ptr);
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Re-allocates memory. An attept to avoid copying the data is made only for big
|
41
|
+
* memory allocations (larger than FIO_MEMORY_BLOCK_ALLOC_LIMIT).
|
42
|
+
*/
|
43
|
+
void *fio_realloc(void *ptr, size_t new_size);
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Re-allocates memory. An attept to avoid copying the data is made only for big
|
47
|
+
* memory allocations (larger than FIO_MEMORY_BLOCK_ALLOC_LIMIT).
|
48
|
+
*
|
49
|
+
* This variation is slightly faster as it might copy less data.
|
50
|
+
*/
|
51
|
+
void *fio_realloc2(void *ptr, size_t new_size, size_t copy_length);
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Allocates memory directly using `mmap`, this is prefered for objects that
|
55
|
+
* both require almost a page of memory (or more) and expect a long lifetime.
|
56
|
+
*
|
57
|
+
* However, since this allocation will invoke the system call (`mmap`), it will
|
58
|
+
* be inherently slower.
|
59
|
+
*
|
60
|
+
* `fio_free` can be used for deallocating the memory.
|
61
|
+
*/
|
62
|
+
void *fio_mmap(size_t size);
|
63
|
+
|
64
|
+
#if FIO_OVERRIDE_MALLOC
|
65
|
+
#define malloc fio_malloc
|
66
|
+
#define free fio_free
|
67
|
+
#define realloc fio_realloc
|
68
|
+
#define calloc fio_calloc
|
69
|
+
#endif
|
70
|
+
|
71
|
+
#endif /* H_FIOBJ_MEM_H */
|
File without changes
|
@@ -1,62 +1,62 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz Segev, 2018-2019
|
3
|
-
License: MIT
|
4
|
-
*/
|
5
|
-
#ifndef H_FIOBJ_MUSTACHE_H
|
6
|
-
#define H_FIOBJ_MUSTACHE_H
|
7
|
-
|
8
|
-
#include <fiobject.h>
|
9
|
-
|
10
|
-
#include <mustache_parser.h>
|
11
|
-
|
12
|
-
/**
|
13
|
-
* Loads a mustache template, converting it into an opaque instruction array.
|
14
|
-
*
|
15
|
-
* Returns a pointer to the instruction array or NULL (on error).
|
16
|
-
*
|
17
|
-
* The `filename` argument should contain the template's file name.
|
18
|
-
*/
|
19
|
-
mustache_s *fiobj_mustache_load(fio_str_info_s filename);
|
20
|
-
|
21
|
-
/**
|
22
|
-
* Loads a mustache template, either from memory of a file, converting it into
|
23
|
-
* an opaque instruction array.
|
24
|
-
*
|
25
|
-
* Returns a pointer to the instruction array or NULL (on error).
|
26
|
-
*
|
27
|
-
* Accepts any of the following named arguments:
|
28
|
-
* * `char const *filename` - The root template's file name.
|
29
|
-
* * `size_t filename_len` - The file name's length.
|
30
|
-
* * `char const *data` - If set, will be used as the file's contents.
|
31
|
-
* * `size_t data_len` - If set, `data` will be used as the file's contents.
|
32
|
-
* * `mustache_error_en *err` - A container for any template load errors (see
|
33
|
-
* mustache_parser.h).
|
34
|
-
*/
|
35
|
-
mustache_s *fiobj_mustache_new(mustache_load_args_s args);
|
36
|
-
#define fiobj_mustache_new(...) \
|
37
|
-
fiobj_mustache_new((mustache_load_args_s){__VA_ARGS__})
|
38
|
-
|
39
|
-
/** Free the mustache template */
|
40
|
-
void fiobj_mustache_free(mustache_s *mustache);
|
41
|
-
|
42
|
-
/**
|
43
|
-
* Creates a FIOBJ String containing the rendered template using the information
|
44
|
-
* in the `data` object.
|
45
|
-
*
|
46
|
-
* Returns FIOBJ_INVALID if an error occurred and a FIOBJ String on success.
|
47
|
-
*/
|
48
|
-
FIOBJ fiobj_mustache_build(mustache_s *mustache, FIOBJ data);
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Renders a template into an existing FIOBJ String (`dest`'s end), using the
|
52
|
-
* information in the `data` object.
|
53
|
-
*
|
54
|
-
* Returns FIOBJ_INVALID if an error occurred and a FIOBJ String on success.
|
55
|
-
*/
|
56
|
-
FIOBJ fiobj_mustache_build2(FIOBJ dest, mustache_s *mustache, FIOBJ data);
|
57
|
-
|
58
|
-
#if DEBUG
|
59
|
-
void fiobj_mustache_test(void);
|
60
|
-
#endif
|
61
|
-
|
62
|
-
#endif /* H_FIOBJ_MUSTACHE_H */
|
1
|
+
/*
|
2
|
+
Copyright: Boaz Segev, 2018-2019
|
3
|
+
License: MIT
|
4
|
+
*/
|
5
|
+
#ifndef H_FIOBJ_MUSTACHE_H
|
6
|
+
#define H_FIOBJ_MUSTACHE_H
|
7
|
+
|
8
|
+
#include <fiobject.h>
|
9
|
+
|
10
|
+
#include <mustache_parser.h>
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Loads a mustache template, converting it into an opaque instruction array.
|
14
|
+
*
|
15
|
+
* Returns a pointer to the instruction array or NULL (on error).
|
16
|
+
*
|
17
|
+
* The `filename` argument should contain the template's file name.
|
18
|
+
*/
|
19
|
+
mustache_s *fiobj_mustache_load(fio_str_info_s filename);
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Loads a mustache template, either from memory of a file, converting it into
|
23
|
+
* an opaque instruction array.
|
24
|
+
*
|
25
|
+
* Returns a pointer to the instruction array or NULL (on error).
|
26
|
+
*
|
27
|
+
* Accepts any of the following named arguments:
|
28
|
+
* * `char const *filename` - The root template's file name.
|
29
|
+
* * `size_t filename_len` - The file name's length.
|
30
|
+
* * `char const *data` - If set, will be used as the file's contents.
|
31
|
+
* * `size_t data_len` - If set, `data` will be used as the file's contents.
|
32
|
+
* * `mustache_error_en *err` - A container for any template load errors (see
|
33
|
+
* mustache_parser.h).
|
34
|
+
*/
|
35
|
+
mustache_s *fiobj_mustache_new(mustache_load_args_s args);
|
36
|
+
#define fiobj_mustache_new(...) \
|
37
|
+
fiobj_mustache_new((mustache_load_args_s){__VA_ARGS__})
|
38
|
+
|
39
|
+
/** Free the mustache template */
|
40
|
+
void fiobj_mustache_free(mustache_s *mustache);
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Creates a FIOBJ String containing the rendered template using the information
|
44
|
+
* in the `data` object.
|
45
|
+
*
|
46
|
+
* Returns FIOBJ_INVALID if an error occurred and a FIOBJ String on success.
|
47
|
+
*/
|
48
|
+
FIOBJ fiobj_mustache_build(mustache_s *mustache, FIOBJ data);
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Renders a template into an existing FIOBJ String (`dest`'s end), using the
|
52
|
+
* information in the `data` object.
|
53
|
+
*
|
54
|
+
* Returns FIOBJ_INVALID if an error occurred and a FIOBJ String on success.
|
55
|
+
*/
|
56
|
+
FIOBJ fiobj_mustache_build2(FIOBJ dest, mustache_s *mustache, FIOBJ data);
|
57
|
+
|
58
|
+
#if DEBUG
|
59
|
+
void fiobj_mustache_test(void);
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#endif /* H_FIOBJ_MUSTACHE_H */
|
File without changes
|
@@ -1,127 +1,127 @@
|
|
1
|
-
#ifndef H_FIOBJ_NUMBERS_H
|
2
|
-
#define H_FIOBJ_NUMBERS_H
|
3
|
-
/*
|
4
|
-
Copyright: Boaz Segev, 2017-2019
|
5
|
-
License: MIT
|
6
|
-
*/
|
7
|
-
|
8
|
-
#include <fiobject.h>
|
9
|
-
|
10
|
-
#ifdef __cplusplus
|
11
|
-
extern "C" {
|
12
|
-
#endif
|
13
|
-
|
14
|
-
/* *****************************************************************************
|
15
|
-
Numbers API (Integers)
|
16
|
-
***************************************************************************** */
|
17
|
-
|
18
|
-
/** Creates a Number object. Remember to use `fiobj_free`. */
|
19
|
-
FIO_INLINE FIOBJ fiobj_num_new(intptr_t num);
|
20
|
-
|
21
|
-
/** Creates a temporary Number object. Avoid using `fiobj_free`. */
|
22
|
-
FIOBJ fiobj_num_tmp(intptr_t num);
|
23
|
-
|
24
|
-
/* *****************************************************************************
|
25
|
-
Float API (Double)
|
26
|
-
***************************************************************************** */
|
27
|
-
|
28
|
-
/** Creates a Float object. Remember to use `fiobj_free`. */
|
29
|
-
FIOBJ fiobj_float_new(double num);
|
30
|
-
|
31
|
-
/** Mutates a Float object's value. Effects every object's reference! */
|
32
|
-
void fiobj_float_set(FIOBJ obj, double num);
|
33
|
-
|
34
|
-
/** Creates a temporary Float object. Avoid using `fiobj_free`. */
|
35
|
-
FIOBJ fiobj_float_tmp(double num);
|
36
|
-
|
37
|
-
/* *****************************************************************************
|
38
|
-
Numerical Helpers: not FIOBJ specific, but included as part of the library
|
39
|
-
***************************************************************************** */
|
40
|
-
|
41
|
-
/**
|
42
|
-
* A helper function that converts between String data to a signed int64_t.
|
43
|
-
*
|
44
|
-
* Numbers are assumed to be in base 10.
|
45
|
-
*
|
46
|
-
* The `0x##` (or `x##`) and `0b##` (or `b##`) are recognized as base 16 and
|
47
|
-
* base 2 (binary MSB first) respectively.
|
48
|
-
*
|
49
|
-
* The pointer will be updated to point to the first byte after the number.
|
50
|
-
*/
|
51
|
-
int64_t fio_atol(char **pstr);
|
52
|
-
|
53
|
-
/** A helper function that converts between String data to a signed double. */
|
54
|
-
double fio_atof(char **pstr);
|
55
|
-
|
56
|
-
/**
|
57
|
-
* A helper function that converts between a signed int64_t to a string.
|
58
|
-
*
|
59
|
-
* No overflow guard is provided, make sure there's at least 66 bytes available
|
60
|
-
* (for base 2).
|
61
|
-
*
|
62
|
-
* Supports base 2, base 10 and base 16. An unsupported base will silently
|
63
|
-
* default to base 10. Prefixes aren't added (i.e., no "0x" or "0b" at the
|
64
|
-
* beginning of the string).
|
65
|
-
*
|
66
|
-
* Returns the number of bytes actually written (excluding the NUL terminator).
|
67
|
-
*/
|
68
|
-
size_t fio_ltoa(char *dest, int64_t num, uint8_t base);
|
69
|
-
|
70
|
-
/**
|
71
|
-
* A helper function that converts between a double to a string.
|
72
|
-
*
|
73
|
-
* No overflow guard is provided, make sure there's at least 130 bytes available
|
74
|
-
* (for base 2).
|
75
|
-
*
|
76
|
-
* Supports base 2, base 10 and base 16. An unsupported base will silently
|
77
|
-
* default to base 10. Prefixes aren't added (i.e., no "0x" or "0b" at the
|
78
|
-
* beginning of the string).
|
79
|
-
*
|
80
|
-
* Returns the number of bytes actually written (excluding the NUL terminator).
|
81
|
-
*/
|
82
|
-
size_t fio_ftoa(char *dest, double num, uint8_t base);
|
83
|
-
|
84
|
-
/** Converts a number to a temporary, thread safe, C string object */
|
85
|
-
fio_str_info_s __attribute__((deprecated("use local buffer with fio_ltoa")))
|
86
|
-
fio_ltocstr(long);
|
87
|
-
|
88
|
-
/** Converts a float to a temporary, thread safe, C string object */
|
89
|
-
fio_str_info_s __attribute__((deprecated("use local buffer with fio_ftoa")))
|
90
|
-
fio_ftocstr(double);
|
91
|
-
|
92
|
-
/* *****************************************************************************
|
93
|
-
Pointer Wrapping Helper MACROs (uses integers)
|
94
|
-
***************************************************************************** */
|
95
|
-
|
96
|
-
#define fiobj_ptr_wrap(ptr) fiobj_num_new((uintptr_t)(ptr))
|
97
|
-
#define fiobj_ptr_unwrap(obj) ((void *)fiobj_obj2num((obj)))
|
98
|
-
|
99
|
-
/* *****************************************************************************
|
100
|
-
Inline Number Initialization
|
101
|
-
***************************************************************************** */
|
102
|
-
|
103
|
-
FIOBJ fiobj_num_new_bignum(intptr_t num);
|
104
|
-
|
105
|
-
/** Creates a Number object. Remember to use `fiobj_free`. */
|
106
|
-
FIO_INLINE FIOBJ fiobj_num_new(intptr_t num) {
|
107
|
-
if ((((uintptr_t)num &
|
108
|
-
(FIOBJ_NUMBER_SIGN_BIT | FIOBJ_NUMBER_SIGN_EXCLUDE_BIT)) == 0) ||
|
109
|
-
(((uintptr_t)num &
|
110
|
-
(FIOBJ_NUMBER_SIGN_BIT | FIOBJ_NUMBER_SIGN_EXCLUDE_BIT)) ==
|
111
|
-
(FIOBJ_NUMBER_SIGN_BIT | FIOBJ_NUMBER_SIGN_EXCLUDE_BIT))) {
|
112
|
-
const uintptr_t num_abs = (uintptr_t)num & FIOBJ_NUMBER_SIGN_MASK;
|
113
|
-
const uintptr_t num_sign = (uintptr_t)num & FIOBJ_NUMBER_SIGN_BIT;
|
114
|
-
return ((num_abs << 1) | num_sign | FIOBJECT_NUMBER_FLAG);
|
115
|
-
}
|
116
|
-
return fiobj_num_new_bignum(num);
|
117
|
-
}
|
118
|
-
|
119
|
-
#if DEBUG
|
120
|
-
void fiobj_test_numbers(void);
|
121
|
-
#endif
|
122
|
-
|
123
|
-
#ifdef __cplusplus
|
124
|
-
} /* extern "C" */
|
125
|
-
#endif
|
126
|
-
|
127
|
-
#endif
|
1
|
+
#ifndef H_FIOBJ_NUMBERS_H
|
2
|
+
#define H_FIOBJ_NUMBERS_H
|
3
|
+
/*
|
4
|
+
Copyright: Boaz Segev, 2017-2019
|
5
|
+
License: MIT
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <fiobject.h>
|
9
|
+
|
10
|
+
#ifdef __cplusplus
|
11
|
+
extern "C" {
|
12
|
+
#endif
|
13
|
+
|
14
|
+
/* *****************************************************************************
|
15
|
+
Numbers API (Integers)
|
16
|
+
***************************************************************************** */
|
17
|
+
|
18
|
+
/** Creates a Number object. Remember to use `fiobj_free`. */
|
19
|
+
FIO_INLINE FIOBJ fiobj_num_new(intptr_t num);
|
20
|
+
|
21
|
+
/** Creates a temporary Number object. Avoid using `fiobj_free`. */
|
22
|
+
FIOBJ fiobj_num_tmp(intptr_t num);
|
23
|
+
|
24
|
+
/* *****************************************************************************
|
25
|
+
Float API (Double)
|
26
|
+
***************************************************************************** */
|
27
|
+
|
28
|
+
/** Creates a Float object. Remember to use `fiobj_free`. */
|
29
|
+
FIOBJ fiobj_float_new(double num);
|
30
|
+
|
31
|
+
/** Mutates a Float object's value. Effects every object's reference! */
|
32
|
+
void fiobj_float_set(FIOBJ obj, double num);
|
33
|
+
|
34
|
+
/** Creates a temporary Float object. Avoid using `fiobj_free`. */
|
35
|
+
FIOBJ fiobj_float_tmp(double num);
|
36
|
+
|
37
|
+
/* *****************************************************************************
|
38
|
+
Numerical Helpers: not FIOBJ specific, but included as part of the library
|
39
|
+
***************************************************************************** */
|
40
|
+
|
41
|
+
/**
|
42
|
+
* A helper function that converts between String data to a signed int64_t.
|
43
|
+
*
|
44
|
+
* Numbers are assumed to be in base 10.
|
45
|
+
*
|
46
|
+
* The `0x##` (or `x##`) and `0b##` (or `b##`) are recognized as base 16 and
|
47
|
+
* base 2 (binary MSB first) respectively.
|
48
|
+
*
|
49
|
+
* The pointer will be updated to point to the first byte after the number.
|
50
|
+
*/
|
51
|
+
int64_t fio_atol(char **pstr);
|
52
|
+
|
53
|
+
/** A helper function that converts between String data to a signed double. */
|
54
|
+
double fio_atof(char **pstr);
|
55
|
+
|
56
|
+
/**
|
57
|
+
* A helper function that converts between a signed int64_t to a string.
|
58
|
+
*
|
59
|
+
* No overflow guard is provided, make sure there's at least 66 bytes available
|
60
|
+
* (for base 2).
|
61
|
+
*
|
62
|
+
* Supports base 2, base 10 and base 16. An unsupported base will silently
|
63
|
+
* default to base 10. Prefixes aren't added (i.e., no "0x" or "0b" at the
|
64
|
+
* beginning of the string).
|
65
|
+
*
|
66
|
+
* Returns the number of bytes actually written (excluding the NUL terminator).
|
67
|
+
*/
|
68
|
+
size_t fio_ltoa(char *dest, int64_t num, uint8_t base);
|
69
|
+
|
70
|
+
/**
|
71
|
+
* A helper function that converts between a double to a string.
|
72
|
+
*
|
73
|
+
* No overflow guard is provided, make sure there's at least 130 bytes available
|
74
|
+
* (for base 2).
|
75
|
+
*
|
76
|
+
* Supports base 2, base 10 and base 16. An unsupported base will silently
|
77
|
+
* default to base 10. Prefixes aren't added (i.e., no "0x" or "0b" at the
|
78
|
+
* beginning of the string).
|
79
|
+
*
|
80
|
+
* Returns the number of bytes actually written (excluding the NUL terminator).
|
81
|
+
*/
|
82
|
+
size_t fio_ftoa(char *dest, double num, uint8_t base);
|
83
|
+
|
84
|
+
/** Converts a number to a temporary, thread safe, C string object */
|
85
|
+
fio_str_info_s __attribute__((deprecated("use local buffer with fio_ltoa")))
|
86
|
+
fio_ltocstr(long);
|
87
|
+
|
88
|
+
/** Converts a float to a temporary, thread safe, C string object */
|
89
|
+
fio_str_info_s __attribute__((deprecated("use local buffer with fio_ftoa")))
|
90
|
+
fio_ftocstr(double);
|
91
|
+
|
92
|
+
/* *****************************************************************************
|
93
|
+
Pointer Wrapping Helper MACROs (uses integers)
|
94
|
+
***************************************************************************** */
|
95
|
+
|
96
|
+
#define fiobj_ptr_wrap(ptr) fiobj_num_new((uintptr_t)(ptr))
|
97
|
+
#define fiobj_ptr_unwrap(obj) ((void *)fiobj_obj2num((obj)))
|
98
|
+
|
99
|
+
/* *****************************************************************************
|
100
|
+
Inline Number Initialization
|
101
|
+
***************************************************************************** */
|
102
|
+
|
103
|
+
FIOBJ fiobj_num_new_bignum(intptr_t num);
|
104
|
+
|
105
|
+
/** Creates a Number object. Remember to use `fiobj_free`. */
|
106
|
+
FIO_INLINE FIOBJ fiobj_num_new(intptr_t num) {
|
107
|
+
if ((((uintptr_t)num &
|
108
|
+
(FIOBJ_NUMBER_SIGN_BIT | FIOBJ_NUMBER_SIGN_EXCLUDE_BIT)) == 0) ||
|
109
|
+
(((uintptr_t)num &
|
110
|
+
(FIOBJ_NUMBER_SIGN_BIT | FIOBJ_NUMBER_SIGN_EXCLUDE_BIT)) ==
|
111
|
+
(FIOBJ_NUMBER_SIGN_BIT | FIOBJ_NUMBER_SIGN_EXCLUDE_BIT))) {
|
112
|
+
const uintptr_t num_abs = (uintptr_t)num & FIOBJ_NUMBER_SIGN_MASK;
|
113
|
+
const uintptr_t num_sign = (uintptr_t)num & FIOBJ_NUMBER_SIGN_BIT;
|
114
|
+
return ((num_abs << 1) | num_sign | FIOBJECT_NUMBER_FLAG);
|
115
|
+
}
|
116
|
+
return fiobj_num_new_bignum(num);
|
117
|
+
}
|
118
|
+
|
119
|
+
#if DEBUG
|
120
|
+
void fiobj_test_numbers(void);
|
121
|
+
#endif
|
122
|
+
|
123
|
+
#ifdef __cplusplus
|
124
|
+
} /* extern "C" */
|
125
|
+
#endif
|
126
|
+
|
127
|
+
#endif
|
File without changes
|