prometheus-client-mmap 0.9.1.pre.rc.1 → 0.9.1.pre.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_mmaped_file/hashmap.c +465 -408
- data/ext/fast_mmaped_file/jsmn.c +244 -259
- data/ext/fast_mmaped_file/mmap.c +1 -0
- data/ext/fast_mmaped_file/mmap.h +8 -9
- data/ext/fast_mmaped_file/utils.c +23 -6
- data/ext/fast_mmaped_file/utils.h +1 -0
- data/ext/fast_mmaped_file/value_access.c +11 -10
- data/lib/fast_mmaped_file.bundle +0 -0
- data/lib/prometheus/client/version.rb +1 -1
- metadata +1 -1
data/ext/fast_mmaped_file/mmap.c
CHANGED
data/ext/fast_mmaped_file/mmap.h
CHANGED
@@ -25,11 +25,10 @@ typedef struct {
|
|
25
25
|
int smode, pmode, vscope;
|
26
26
|
int advice, flag;
|
27
27
|
VALUE key;
|
28
|
-
int semid, shmid;
|
29
28
|
size_t len, real;
|
30
29
|
off_t offset;
|
31
30
|
int fd;
|
32
|
-
char *path
|
31
|
+
char *path;
|
33
32
|
} mm_mmap;
|
34
33
|
|
35
34
|
typedef struct {
|
@@ -37,13 +36,13 @@ typedef struct {
|
|
37
36
|
mm_mmap *t;
|
38
37
|
} mm_ipc;
|
39
38
|
|
40
|
-
#define GET_MMAP(obj, i_mm, t_modify)
|
41
|
-
Data_Get_Struct(obj, mm_ipc, i_mm);
|
42
|
-
if (!i_mm->t->path || i_mm->t->fd
|
43
|
-
rb_raise(rb_eIOError, "unmapped file");
|
44
|
-
}
|
45
|
-
if ((t_modify & MM_MODIFY) && (i_mm->t->flag & MM_FROZEN)) {
|
46
|
-
rb_error_frozen("mmap");
|
39
|
+
#define GET_MMAP(obj, i_mm, t_modify) \
|
40
|
+
Data_Get_Struct(obj, mm_ipc, i_mm); \
|
41
|
+
if (!i_mm->t->path || i_mm->t->fd < 0 || i_mm->t->addr == NULL || i_mm->t->addr == MAP_FAILED) { \
|
42
|
+
rb_raise(rb_eIOError, "unmapped file"); \
|
43
|
+
} \
|
44
|
+
if ((t_modify & MM_MODIFY) && (i_mm->t->flag & MM_FROZEN)) { \
|
45
|
+
rb_error_frozen("mmap"); \
|
47
46
|
}
|
48
47
|
|
49
48
|
VALUE mm_s_alloc(VALUE obj);
|
@@ -1,20 +1,22 @@
|
|
1
|
+
#include <errno.h>
|
1
2
|
#include <ruby.h>
|
2
3
|
|
3
4
|
#include "utils.h"
|
4
5
|
|
5
|
-
static void
|
6
|
-
VALUE message = rb_vsprintf(fmt, args);
|
7
|
-
|
6
|
+
static void rb_save_exception(VALUE exception, VALUE message) {
|
8
7
|
VALUE current_thread = rb_thread_current();
|
8
|
+
|
9
9
|
rb_thread_local_aset(current_thread, rb_intern("prometheus_last_exception"), exception);
|
10
10
|
rb_thread_local_aset(current_thread, rb_intern("prometheus_last_exception_message"), message);
|
11
11
|
}
|
12
|
-
|
12
|
+
/* @deprecated - use with_exception ignoring return value */
|
13
13
|
void save_exception(VALUE exception, const char *fmt, ...) {
|
14
14
|
va_list args;
|
15
15
|
|
16
16
|
va_start(args, fmt);
|
17
|
-
|
17
|
+
VALUE message = rb_vsprintf(fmt, args);
|
18
|
+
|
19
|
+
rb_save_exception(exception, message);
|
18
20
|
va_end(args);
|
19
21
|
}
|
20
22
|
|
@@ -22,7 +24,22 @@ int with_exception(VALUE exception, const char *fmt, ...) {
|
|
22
24
|
va_list args;
|
23
25
|
|
24
26
|
va_start(args, fmt);
|
25
|
-
|
27
|
+
VALUE message = rb_vsprintf(fmt, args);
|
28
|
+
|
29
|
+
rb_save_exception(exception, message);
|
30
|
+
va_end(args);
|
31
|
+
|
32
|
+
return FAILURE;
|
33
|
+
}
|
34
|
+
|
35
|
+
int with_exception_errno(VALUE exception, const char *fmt, ...) {
|
36
|
+
va_list args;
|
37
|
+
|
38
|
+
va_start(args, fmt);
|
39
|
+
VALUE message = rb_vsprintf(fmt, args);
|
40
|
+
rb_str_catf(message, " (%s)", strerror(errno));
|
41
|
+
|
42
|
+
rb_save_exception(exception, message);
|
26
43
|
va_end(args);
|
27
44
|
|
28
45
|
return FAILURE;
|
@@ -14,28 +14,29 @@
|
|
14
14
|
|
15
15
|
static void close_file(mm_ipc *i_mm) {
|
16
16
|
close(i_mm->t->fd);
|
17
|
-
i_mm->t->fd =
|
17
|
+
i_mm->t->fd = -1;
|
18
18
|
}
|
19
19
|
|
20
20
|
static int open_and_extend_file(mm_ipc *i_mm, size_t len) {
|
21
|
-
if (i_mm->t->fd
|
22
|
-
int fd
|
21
|
+
if (i_mm->t->fd < 0) {
|
22
|
+
int fd;
|
23
23
|
|
24
24
|
if ((fd = open(i_mm->t->path, i_mm->t->smode)) == -1) {
|
25
|
-
return
|
25
|
+
return with_exception_errno(rb_eArgError, "%s: Can't open %s", __FILE__, i_mm->t->path);
|
26
26
|
}
|
27
27
|
i_mm->t->fd = fd;
|
28
28
|
}
|
29
29
|
|
30
|
-
if (lseek(i_mm->t->fd, len -
|
30
|
+
if (lseek(i_mm->t->fd, len - 1, SEEK_SET) == -1) {
|
31
31
|
close_file(i_mm);
|
32
|
-
return
|
32
|
+
return with_exception_errno(rb_eIOError, "Can't lseek %zu", len - 1);
|
33
33
|
}
|
34
34
|
|
35
35
|
if (write(i_mm->t->fd, "\000", 1) != 1) {
|
36
36
|
close_file(i_mm);
|
37
|
-
return
|
37
|
+
return with_exception_errno(rb_eIOError, "Can't extend %s", i_mm->t->path);
|
38
38
|
}
|
39
|
+
i_mm->t->len = len;
|
39
40
|
|
40
41
|
return SUCCESS;
|
41
42
|
}
|
@@ -43,7 +44,7 @@ static int open_and_extend_file(mm_ipc *i_mm, size_t len) {
|
|
43
44
|
static int perform_munmap(mm_ipc *i_mm) {
|
44
45
|
if (i_mm->t->addr != NULL && munmap(i_mm->t->addr, i_mm->t->len)) {
|
45
46
|
i_mm->t->addr = NULL;
|
46
|
-
return
|
47
|
+
return with_exception_errno(rb_eArgError, "munmap failed");
|
47
48
|
}
|
48
49
|
|
49
50
|
i_mm->t->addr = NULL;
|
@@ -57,7 +58,7 @@ static int perform_mmap(mm_ipc *i_mm, size_t len) {
|
|
57
58
|
MMAP_RETTYPE addr = mmap(0, len, i_mm->t->pmode, i_mm->t->vscope, i_mm->t->fd, i_mm->t->offset);
|
58
59
|
|
59
60
|
if (addr == MAP_FAILED) {
|
60
|
-
return
|
61
|
+
return with_exception_errno(rb_eArgError, "mmap failed");
|
61
62
|
}
|
62
63
|
|
63
64
|
i_mm->t->addr = addr;
|
@@ -86,7 +87,7 @@ static int expand(mm_ipc *i_mm, size_t len) {
|
|
86
87
|
}
|
87
88
|
|
88
89
|
if ((i_mm->t->flag & MM_LOCK) && mlock(i_mm->t->addr, len) == -1) {
|
89
|
-
return
|
90
|
+
return with_exception_errno(rb_eArgError, "mlock(%d)", errno);
|
90
91
|
}
|
91
92
|
|
92
93
|
return SUCCESS;
|
data/lib/fast_mmaped_file.bundle
CHANGED
Binary file
|