prometheus-client-mmap 0.28.0-arm64-darwin → 1.0.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -1
- data/README.md +2 -30
- data/ext/fast_mmaped_file_rs/extconf.rb +1 -3
- data/ext/fast_mmaped_file_rs/src/error.rs +8 -0
- data/ext/fast_mmaped_file_rs/src/mmap/inner.rs +38 -23
- data/ext/fast_mmaped_file_rs/src/mmap.rs +71 -8
- data/lib/2.7/fast_mmaped_file_rs.bundle +0 -0
- data/lib/3.0/fast_mmaped_file_rs.bundle +0 -0
- data/lib/3.1/fast_mmaped_file_rs.bundle +0 -0
- data/lib/3.2/fast_mmaped_file_rs.bundle +0 -0
- data/lib/prometheus/client/configuration.rb +1 -2
- data/lib/prometheus/client/formats/text.rb +1 -12
- data/lib/prometheus/client/helper/mmaped_file.rb +3 -14
- data/lib/prometheus/client/rack/exporter.rb +1 -3
- data/lib/prometheus/client/version.rb +1 -1
- metadata +4 -46
- data/ext/fast_mmaped_file/extconf.rb +0 -30
- data/ext/fast_mmaped_file/fast_mmaped_file.c +0 -122
- data/ext/fast_mmaped_file/file_format.c +0 -5
- data/ext/fast_mmaped_file/file_format.h +0 -11
- data/ext/fast_mmaped_file/file_parsing.c +0 -195
- data/ext/fast_mmaped_file/file_parsing.h +0 -27
- data/ext/fast_mmaped_file/file_reading.c +0 -102
- data/ext/fast_mmaped_file/file_reading.h +0 -30
- data/ext/fast_mmaped_file/globals.h +0 -14
- data/ext/fast_mmaped_file/mmap.c +0 -438
- data/ext/fast_mmaped_file/mmap.h +0 -61
- data/ext/fast_mmaped_file/rendering.c +0 -199
- data/ext/fast_mmaped_file/rendering.h +0 -8
- data/ext/fast_mmaped_file/utils.c +0 -56
- data/ext/fast_mmaped_file/utils.h +0 -22
- data/ext/fast_mmaped_file/value_access.c +0 -242
- data/ext/fast_mmaped_file/value_access.h +0 -15
- data/lib/2.7/fast_mmaped_file.bundle +0 -0
- data/lib/3.0/fast_mmaped_file.bundle +0 -0
- data/lib/3.1/fast_mmaped_file.bundle +0 -0
- data/lib/3.2/fast_mmaped_file.bundle +0 -0
- data/lib/prometheus/client/helper/loader.rb +0 -44
- data/vendor/c/hashmap/.gitignore +0 -52
- data/vendor/c/hashmap/LICENSE +0 -21
- data/vendor/c/hashmap/README.md +0 -90
- data/vendor/c/hashmap/_config.yml +0 -1
- data/vendor/c/hashmap/src/hashmap.c +0 -692
- data/vendor/c/hashmap/src/hashmap.h +0 -267
- data/vendor/c/hashmap/test/Makefile +0 -22
- data/vendor/c/hashmap/test/hashmap_test.c +0 -608
- data/vendor/c/jsmn/.travis.yml +0 -4
- data/vendor/c/jsmn/LICENSE +0 -20
- data/vendor/c/jsmn/Makefile +0 -41
- data/vendor/c/jsmn/README.md +0 -168
- data/vendor/c/jsmn/example/jsondump.c +0 -126
- data/vendor/c/jsmn/example/simple.c +0 -76
- data/vendor/c/jsmn/jsmn.c +0 -314
- data/vendor/c/jsmn/jsmn.h +0 -76
- data/vendor/c/jsmn/library.json +0 -16
- data/vendor/c/jsmn/test/test.h +0 -27
- data/vendor/c/jsmn/test/tests.c +0 -407
- data/vendor/c/jsmn/test/testutil.h +0 -94
@@ -1,122 +0,0 @@
|
|
1
|
-
#include <errno.h>
|
2
|
-
#include <hashmap.h>
|
3
|
-
#include <jsmn.h>
|
4
|
-
#include <ruby.h>
|
5
|
-
#include <ruby/intern.h>
|
6
|
-
#include <sys/mman.h>
|
7
|
-
|
8
|
-
#include "file_parsing.h"
|
9
|
-
#include "file_reading.h"
|
10
|
-
#include "globals.h"
|
11
|
-
#include "mmap.h"
|
12
|
-
#include "rendering.h"
|
13
|
-
#include "utils.h"
|
14
|
-
#include "value_access.h"
|
15
|
-
|
16
|
-
VALUE MMAPED_FILE = Qnil;
|
17
|
-
|
18
|
-
ID sym_min;
|
19
|
-
ID sym_max;
|
20
|
-
ID sym_livesum;
|
21
|
-
ID sym_gauge;
|
22
|
-
ID sym_pid;
|
23
|
-
ID sym_samples;
|
24
|
-
|
25
|
-
VALUE prom_eParsingError;
|
26
|
-
|
27
|
-
int aggregate_files(struct hashmap *map, VALUE list_of_files) {
|
28
|
-
buffer_t reading_buffer;
|
29
|
-
memset(&reading_buffer, 0, sizeof(buffer_t));
|
30
|
-
|
31
|
-
for (int i = 0; i < RARRAY_LEN(list_of_files); i++) {
|
32
|
-
VALUE params = RARRAY_PTR(list_of_files)[i];
|
33
|
-
file_t file;
|
34
|
-
|
35
|
-
if (!file_open_from_params(&file, params)) {
|
36
|
-
buffer_dispose(&reading_buffer);
|
37
|
-
return 0;
|
38
|
-
}
|
39
|
-
|
40
|
-
if (!read_from_file(&file, &reading_buffer)) {
|
41
|
-
buffer_dispose(&reading_buffer);
|
42
|
-
file_close(&file);
|
43
|
-
return 0;
|
44
|
-
}
|
45
|
-
|
46
|
-
if (!process_buffer(&file, &reading_buffer, map)) {
|
47
|
-
buffer_dispose(&reading_buffer);
|
48
|
-
file_close(&file);
|
49
|
-
return 0;
|
50
|
-
}
|
51
|
-
|
52
|
-
if (!file_close(&file)) {
|
53
|
-
buffer_dispose(&reading_buffer);
|
54
|
-
return 0;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
buffer_dispose(&reading_buffer);
|
59
|
-
return 1;
|
60
|
-
}
|
61
|
-
|
62
|
-
VALUE method_to_metrics(VALUE UNUSED(self), VALUE file_list) {
|
63
|
-
struct hashmap map;
|
64
|
-
hashmap_setup(&map);
|
65
|
-
|
66
|
-
if (!aggregate_files(&map, file_list)) { // all entries in map are now copies that need to be disposed
|
67
|
-
hashmap_destroy(&map);
|
68
|
-
raise_last_exception();
|
69
|
-
return Qnil;
|
70
|
-
}
|
71
|
-
|
72
|
-
entry_t **sorted_entries;
|
73
|
-
|
74
|
-
if (!sort_map_entries(&map, &sorted_entries)) {
|
75
|
-
hashmap_destroy(&map);
|
76
|
-
|
77
|
-
raise_last_exception();
|
78
|
-
return Qnil;
|
79
|
-
}
|
80
|
-
|
81
|
-
VALUE rv = rb_str_new("", 0);
|
82
|
-
if (!entries_to_string(rv, sorted_entries, hashmap_size(&map))) {
|
83
|
-
free(sorted_entries);
|
84
|
-
hashmap_destroy(&map);
|
85
|
-
|
86
|
-
raise_last_exception();
|
87
|
-
return Qnil;
|
88
|
-
}
|
89
|
-
|
90
|
-
RB_GC_GUARD(file_list); // ensure file list is not GCed before this point
|
91
|
-
free(sorted_entries);
|
92
|
-
hashmap_destroy(&map);
|
93
|
-
return rv;
|
94
|
-
}
|
95
|
-
|
96
|
-
void Init_fast_mmaped_file() {
|
97
|
-
sym_gauge = rb_intern("gauge");
|
98
|
-
sym_min = rb_intern("min");
|
99
|
-
sym_max = rb_intern("max");
|
100
|
-
sym_livesum = rb_intern("livesum");
|
101
|
-
sym_pid = rb_intern("pid");
|
102
|
-
sym_samples = rb_intern("samples");
|
103
|
-
|
104
|
-
prom_eParsingError = rb_define_class("PrometheusParsingError", rb_eRuntimeError);
|
105
|
-
|
106
|
-
MMAPED_FILE = rb_define_class("FastMmapedFile", rb_cObject);
|
107
|
-
rb_define_const(MMAPED_FILE, "MAP_SHARED", INT2FIX(MAP_SHARED));
|
108
|
-
|
109
|
-
rb_define_singleton_method(MMAPED_FILE, "to_metrics", method_to_metrics, 1);
|
110
|
-
|
111
|
-
rb_define_alloc_func(MMAPED_FILE, mm_s_alloc);
|
112
|
-
rb_define_singleton_method(MMAPED_FILE, "new", mm_s_new, -1);
|
113
|
-
rb_define_method(MMAPED_FILE, "initialize", mm_init, 1);
|
114
|
-
rb_define_method(MMAPED_FILE, "slice", mm_aref_m, -1);
|
115
|
-
rb_define_method(MMAPED_FILE, "sync", mm_msync, -1);
|
116
|
-
rb_define_method(MMAPED_FILE, "munmap", mm_unmap, 0);
|
117
|
-
|
118
|
-
rb_define_method(MMAPED_FILE, "used", method_load_used, 0);
|
119
|
-
rb_define_method(MMAPED_FILE, "used=", method_save_used, 1);
|
120
|
-
rb_define_method(MMAPED_FILE, "fetch_entry", method_fetch_entry, 3);
|
121
|
-
rb_define_method(MMAPED_FILE, "upsert_entry", method_upsert_entry, 3);
|
122
|
-
}
|
@@ -1,195 +0,0 @@
|
|
1
|
-
#include "file_parsing.h"
|
2
|
-
|
3
|
-
#include <hashmap.h>
|
4
|
-
#include <jsmn.h>
|
5
|
-
|
6
|
-
#include "file_format.h"
|
7
|
-
#include "globals.h"
|
8
|
-
#include "utils.h"
|
9
|
-
|
10
|
-
HASHMAP_FUNCS_CREATE(entry, const entry_t, entry_t)
|
11
|
-
|
12
|
-
typedef int (*compare_fn)(const void *a, const void *b);
|
13
|
-
|
14
|
-
static size_t hashmap_hash_entry(const entry_t *entry) { return hashmap_hash_string(entry->json); }
|
15
|
-
|
16
|
-
static int hashmap_compare_entry(const entry_t *a, const entry_t *b) {
|
17
|
-
if (a->json_size != b->json_size) {
|
18
|
-
return -1;
|
19
|
-
}
|
20
|
-
|
21
|
-
if (is_pid_significant(a) && (rb_str_equal(a->pid, b->pid) == Qfalse)) {
|
22
|
-
return -1;
|
23
|
-
}
|
24
|
-
|
25
|
-
return strncmp(a->json, b->json, a->json_size);
|
26
|
-
}
|
27
|
-
|
28
|
-
static void entry_free(entry_t *entry) {
|
29
|
-
free(entry->json);
|
30
|
-
free(entry);
|
31
|
-
}
|
32
|
-
|
33
|
-
static inline double min(double a, double b) { return a < b ? a : b; }
|
34
|
-
|
35
|
-
static inline double max(double a, double b) { return a > b ? a : b; }
|
36
|
-
|
37
|
-
static void merge_entry(entry_t *found, const entry_t *entry) {
|
38
|
-
if (entry->type == sym_gauge) {
|
39
|
-
if (entry->multiprocess_mode == sym_min) {
|
40
|
-
found->value = min(found->value, entry->value);
|
41
|
-
} else if (entry->multiprocess_mode == sym_max) {
|
42
|
-
found->value = max(found->value, entry->value);
|
43
|
-
} else if (entry->multiprocess_mode == sym_livesum) {
|
44
|
-
found->value += entry->value;
|
45
|
-
} else {
|
46
|
-
found->value = entry->value;
|
47
|
-
}
|
48
|
-
} else {
|
49
|
-
found->value += entry->value;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
void merge_or_store(struct hashmap *map, entry_t *entry) {
|
54
|
-
entry_t *found = entry_hashmap_get(map, entry);
|
55
|
-
if (found) {
|
56
|
-
merge_entry(found, entry);
|
57
|
-
entry_free(entry);
|
58
|
-
} else {
|
59
|
-
entry_hashmap_put(map, entry, entry); // use the hashmap like hashset actually
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
entry_t *entry_new(buffer_t *source, uint32_t pos, uint32_t encoded_len, file_t *file_info) {
|
64
|
-
entry_t *entry = calloc(1, sizeof(entry_t));
|
65
|
-
if (entry == NULL) {
|
66
|
-
return NULL;
|
67
|
-
}
|
68
|
-
|
69
|
-
entry->json = malloc(encoded_len + 1);
|
70
|
-
if (entry->json == NULL) {
|
71
|
-
free(entry);
|
72
|
-
return NULL;
|
73
|
-
}
|
74
|
-
|
75
|
-
memcpy(entry->json, source->buffer + pos, encoded_len);
|
76
|
-
entry->json[encoded_len] = '\0';
|
77
|
-
entry->json_size = encoded_len;
|
78
|
-
|
79
|
-
entry->pid = file_info->pid;
|
80
|
-
entry->multiprocess_mode = file_info->multiprocess_mode;
|
81
|
-
entry->type = file_info->type;
|
82
|
-
|
83
|
-
char *value_ptr = source->buffer + pos + encoded_len + padding_length(encoded_len);
|
84
|
-
memcpy(&(entry->value), value_ptr, sizeof(double));
|
85
|
-
|
86
|
-
return entry;
|
87
|
-
}
|
88
|
-
|
89
|
-
static int add_parsed_name(entry_t *entry) {
|
90
|
-
jsmn_parser parser;
|
91
|
-
jsmn_init(&parser);
|
92
|
-
|
93
|
-
jsmntok_t tokens[2];
|
94
|
-
memset(&tokens, 0, sizeof(tokens));
|
95
|
-
|
96
|
-
jsmn_parse(&parser, entry->json, entry->json_size, tokens, 2);
|
97
|
-
jsmntok_t *name_token = &tokens[1];
|
98
|
-
|
99
|
-
if (name_token->start < name_token->end && name_token->start > 0) {
|
100
|
-
entry->name = entry->json + name_token->start;
|
101
|
-
entry->name_len = name_token->end - name_token->start;
|
102
|
-
return 1;
|
103
|
-
}
|
104
|
-
return 0;
|
105
|
-
}
|
106
|
-
|
107
|
-
static int entry_lexical_comparator(const entry_t **a, const entry_t **b) {
|
108
|
-
size_t size_a = (*a)->json_size;
|
109
|
-
size_t size_b = (*b)->json_size;
|
110
|
-
size_t min_length = size_a < size_b ? size_a : size_b;
|
111
|
-
|
112
|
-
return strncmp((*a)->json, (*b)->json, min_length);
|
113
|
-
}
|
114
|
-
|
115
|
-
void hashmap_setup(struct hashmap *map) {
|
116
|
-
hashmap_init(map, (size_t(*)(const void *))hashmap_hash_entry,
|
117
|
-
(int (*)(const void *, const void *))hashmap_compare_entry, 1000);
|
118
|
-
hashmap_set_key_alloc_funcs(map, NULL, (void (*)(void *))entry_free);
|
119
|
-
}
|
120
|
-
|
121
|
-
int process_buffer(file_t *file_info, buffer_t *source, struct hashmap *map) {
|
122
|
-
if (source->size < START_POSITION) {
|
123
|
-
// nothing to read
|
124
|
-
return 1;
|
125
|
-
}
|
126
|
-
uint32_t used;
|
127
|
-
memcpy(&used, source->buffer, sizeof(uint32_t));
|
128
|
-
|
129
|
-
if (used > source->size) {
|
130
|
-
save_exception(prom_eParsingError, "source file %s corrupted, used %u > file size %u", file_info->path, used,
|
131
|
-
source->size);
|
132
|
-
return 0;
|
133
|
-
}
|
134
|
-
|
135
|
-
uint32_t pos = START_POSITION;
|
136
|
-
while (pos + sizeof(uint32_t) < used) {
|
137
|
-
uint32_t encoded_len;
|
138
|
-
memcpy(&encoded_len, source->buffer + pos, sizeof(uint32_t));
|
139
|
-
pos += sizeof(uint32_t);
|
140
|
-
|
141
|
-
uint32_t value_offset = encoded_len + padding_length(encoded_len);
|
142
|
-
|
143
|
-
if (pos + value_offset + sizeof(double) > used) {
|
144
|
-
save_exception(prom_eParsingError, "source file %s corrupted, used %u < stored data length %u",
|
145
|
-
file_info->path, used, pos + value_offset + sizeof(double));
|
146
|
-
return 0;
|
147
|
-
}
|
148
|
-
|
149
|
-
entry_t *entry = entry_new(source, pos, encoded_len, file_info);
|
150
|
-
if (entry == NULL) {
|
151
|
-
save_exception(rb_eNoMemError, "Failed creating metrics entry");
|
152
|
-
return 0;
|
153
|
-
}
|
154
|
-
|
155
|
-
merge_or_store(map, entry);
|
156
|
-
|
157
|
-
pos += value_offset + sizeof(double);
|
158
|
-
}
|
159
|
-
return 1;
|
160
|
-
}
|
161
|
-
|
162
|
-
int sort_map_entries(const struct hashmap *map, entry_t ***sorted_entries) {
|
163
|
-
size_t num = hashmap_size(map);
|
164
|
-
|
165
|
-
entry_t **list = calloc(num, sizeof(entry_t *));
|
166
|
-
|
167
|
-
if (list == NULL) {
|
168
|
-
save_exception(rb_eNoMemError, "Couldn't allocate for %zu memory", num * sizeof(entry_t *));
|
169
|
-
return 0;
|
170
|
-
}
|
171
|
-
|
172
|
-
size_t cnt = 0;
|
173
|
-
struct hashmap_iter *iter;
|
174
|
-
for (iter = hashmap_iter(map); iter; iter = hashmap_iter_next(map, iter)) {
|
175
|
-
entry_t *entry = (entry_t *)entry_hashmap_iter_get_key(iter);
|
176
|
-
if (add_parsed_name(entry)) {
|
177
|
-
list[cnt] = entry;
|
178
|
-
cnt++;
|
179
|
-
}
|
180
|
-
}
|
181
|
-
if (cnt != num) {
|
182
|
-
save_exception(rb_eRuntimeError, "Processed entries %zu != map entries %zu", cnt, num);
|
183
|
-
free(list);
|
184
|
-
return 0;
|
185
|
-
}
|
186
|
-
|
187
|
-
qsort(list, cnt, sizeof(entry_t *), (compare_fn)&entry_lexical_comparator);
|
188
|
-
*sorted_entries = list;
|
189
|
-
return 1;
|
190
|
-
}
|
191
|
-
|
192
|
-
int is_pid_significant(const entry_t *e) {
|
193
|
-
ID mp = e->multiprocess_mode;
|
194
|
-
return e->type == sym_gauge && !(mp == sym_min || mp == sym_max || mp == sym_livesum);
|
195
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#ifndef FILE_PARSING_H
|
2
|
-
#define FILE_PARSING_H
|
3
|
-
#include <file_reading.h>
|
4
|
-
#include <hashmap.h>
|
5
|
-
#include <ruby.h>
|
6
|
-
|
7
|
-
typedef struct {
|
8
|
-
char *json;
|
9
|
-
size_t json_size;
|
10
|
-
char *name;
|
11
|
-
size_t name_len;
|
12
|
-
|
13
|
-
ID multiprocess_mode;
|
14
|
-
ID type;
|
15
|
-
VALUE pid;
|
16
|
-
|
17
|
-
double value;
|
18
|
-
} entry_t;
|
19
|
-
|
20
|
-
void hashmap_setup(struct hashmap *map);
|
21
|
-
|
22
|
-
int process_buffer(file_t *file_info, buffer_t *source, struct hashmap *map);
|
23
|
-
int sort_map_entries(const struct hashmap *map, entry_t ***sorted_entries);
|
24
|
-
|
25
|
-
int is_pid_significant(const entry_t *e);
|
26
|
-
|
27
|
-
#endif
|
@@ -1,102 +0,0 @@
|
|
1
|
-
#include "file_reading.h"
|
2
|
-
|
3
|
-
#include <errno.h>
|
4
|
-
#include <fcntl.h>
|
5
|
-
|
6
|
-
#include "utils.h"
|
7
|
-
|
8
|
-
static int file_open(file_t *source, const char *filepath) {
|
9
|
-
source->file = fopen(filepath, "r");
|
10
|
-
size_t filepath_len = strlen(filepath) + sizeof(char);
|
11
|
-
source->path = malloc(filepath_len);
|
12
|
-
memcpy(source->path, filepath, filepath_len);
|
13
|
-
|
14
|
-
if (source->file == NULL) {
|
15
|
-
save_exception(rb_eArgError, "Can't open %s, errno: %d", filepath, errno);
|
16
|
-
|
17
|
-
return 0;
|
18
|
-
}
|
19
|
-
|
20
|
-
struct stat sb;
|
21
|
-
if (fstat(fileno(source->file), &sb) != 0) {
|
22
|
-
fclose(source->file);
|
23
|
-
save_exception(rb_eIOError, "Can't stat file, errno: %d", errno);
|
24
|
-
|
25
|
-
return 0;
|
26
|
-
}
|
27
|
-
source->length = sb.st_size;
|
28
|
-
|
29
|
-
// go to start
|
30
|
-
if (fseek(source->file, 0L, SEEK_SET) != 0) {
|
31
|
-
fclose(source->file);
|
32
|
-
save_exception(rb_eIOError, "Can't fseek %zu, errno: %d", 0, errno);
|
33
|
-
|
34
|
-
return 0;
|
35
|
-
}
|
36
|
-
|
37
|
-
return 1;
|
38
|
-
}
|
39
|
-
|
40
|
-
int file_close(file_t *source) {
|
41
|
-
free(source->path);
|
42
|
-
if (fclose(source->file) != 0) {
|
43
|
-
save_exception(rb_eIOError, "Can't fclose file, errno: %d", 0, errno);
|
44
|
-
return 0;
|
45
|
-
}
|
46
|
-
source->file = 0;
|
47
|
-
|
48
|
-
return 1;
|
49
|
-
}
|
50
|
-
|
51
|
-
int file_open_from_params(file_t *source, VALUE params) {
|
52
|
-
if (RARRAY_LEN(params) != 4) {
|
53
|
-
save_exception(rb_eArgError, "wrong number of arguments %lu instead of 4", RARRAY_LEN(params));
|
54
|
-
return 0;
|
55
|
-
}
|
56
|
-
|
57
|
-
VALUE filepath = rb_ary_entry(params, 0);
|
58
|
-
|
59
|
-
source->multiprocess_mode = rb_sym2id(rb_ary_entry(params, 1));
|
60
|
-
source->type = rb_sym2id(rb_ary_entry(params, 2));
|
61
|
-
source->pid = rb_ary_entry(params, 3);
|
62
|
-
|
63
|
-
return file_open(source, StringValueCStr(filepath));
|
64
|
-
}
|
65
|
-
|
66
|
-
int read_from_file(const file_t *source, buffer_t *data) {
|
67
|
-
data->size = 0;
|
68
|
-
if (data->buffer == NULL) {
|
69
|
-
data->buffer = malloc(source->length);
|
70
|
-
if (data->buffer == NULL) {
|
71
|
-
save_exception(rb_eIOError, "Can't malloc %zu, errno: %d", source->length, errno);
|
72
|
-
return 0;
|
73
|
-
}
|
74
|
-
|
75
|
-
data->capacity = source->length;
|
76
|
-
} else if (data->capacity < source->length) {
|
77
|
-
data->buffer = realloc(data->buffer, source->length);
|
78
|
-
if (data->buffer == NULL) {
|
79
|
-
save_exception(rb_eIOError, "Can't realloc %zu, errno: %d", source->length, errno);
|
80
|
-
return 0;
|
81
|
-
}
|
82
|
-
|
83
|
-
data->capacity = source->length;
|
84
|
-
}
|
85
|
-
|
86
|
-
data->size = fread(data->buffer, sizeof(char), source->length, source->file);
|
87
|
-
if (data->size != source->length) {
|
88
|
-
save_exception(rb_eIOError, "Couldn't read whole file, read %zu, instead of %zu", data->size, source->length);
|
89
|
-
return 0;
|
90
|
-
}
|
91
|
-
|
92
|
-
return 1;
|
93
|
-
}
|
94
|
-
|
95
|
-
void buffer_dispose(buffer_t *buffer) {
|
96
|
-
if (buffer->buffer) {
|
97
|
-
free(buffer->buffer);
|
98
|
-
}
|
99
|
-
buffer->buffer = NULL;
|
100
|
-
buffer->size = 0;
|
101
|
-
buffer->capacity = 0;
|
102
|
-
}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#ifndef FILE_READING_H
|
2
|
-
#define FILE_READING_H
|
3
|
-
#include <ruby.h>
|
4
|
-
|
5
|
-
typedef struct {
|
6
|
-
FILE *file;
|
7
|
-
size_t length;
|
8
|
-
char *path;
|
9
|
-
|
10
|
-
// Information processed from file path
|
11
|
-
ID multiprocess_mode;
|
12
|
-
ID type;
|
13
|
-
VALUE pid;
|
14
|
-
} file_t;
|
15
|
-
|
16
|
-
typedef struct {
|
17
|
-
char *buffer;
|
18
|
-
size_t size;
|
19
|
-
size_t capacity;
|
20
|
-
} buffer_t;
|
21
|
-
|
22
|
-
int file_close(file_t *file);
|
23
|
-
|
24
|
-
int file_open_from_params(file_t *file, VALUE params);
|
25
|
-
|
26
|
-
int read_from_file(const file_t *source, buffer_t *data);
|
27
|
-
|
28
|
-
void buffer_dispose(buffer_t *buffer);
|
29
|
-
|
30
|
-
#endif
|