Sha256: 9d8228d80e35fb89d386eb7943493193e04486e843fe10de6ad76028c7a9dd48

Contents?: true

Size: 1.59 KB

Versions: 88

Compression:

Stored size: 1.59 KB

Contents

#include "utils.h"

#include <errno.h>

static void rb_save_exception(VALUE exception, VALUE message) {
    VALUE current_thread = rb_thread_current();

    rb_thread_local_aset(current_thread, rb_intern("prometheus_last_exception"), exception);
    rb_thread_local_aset(current_thread, rb_intern("prometheus_last_exception_message"), message);
}
/* @deprecated - use with_exception ignoring return value */
void save_exception(VALUE exception, const char *fmt, ...) {
    va_list args;

    va_start(args, fmt);
    VALUE message = rb_vsprintf(fmt, args);

    rb_save_exception(exception, message);
    va_end(args);
}

int with_exception(VALUE exception, const char *fmt, ...) {
    va_list args;

    va_start(args, fmt);
    VALUE message = rb_vsprintf(fmt, args);

    rb_save_exception(exception, message);
    va_end(args);

    return FAILURE;
}

int with_exception_errno(VALUE exception, const char *fmt, ...) {
    va_list args;

    va_start(args, fmt);
    VALUE message = rb_vsprintf(fmt, args);
    rb_str_catf(message, " (%s)", strerror(errno));

    rb_save_exception(exception, message);
    va_end(args);

    return FAILURE;
}

NORETURN(void raise_last_exception()) {
    VALUE current_thread = rb_thread_current();
    VALUE exception = rb_thread_local_aref(current_thread, rb_intern("prometheus_last_exception"));
    VALUE message = rb_thread_local_aref(current_thread, rb_intern("prometheus_last_exception_message"));
    if (exception != Qnil) {
        rb_raise(exception, "%s", StringValueCStr(message));
    } else {
        rb_raise(rb_eRuntimeError, "no exception found in thread local");
    }
}

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
prometheus-client-mmap-0.28.1 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.1-x86_64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.1-x86_64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.1-arm64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.1-aarch64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.0 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.0-x86_64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.0-x86_64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.0-arm64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.28.0-aarch64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.27.0 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.27.0-x86_64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.27.0-x86_64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.27.0-arm64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.27.0-aarch64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.26.1 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.26.1-x86_64-linux ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.26.1-x86_64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.26.1-arm64-darwin ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.26.1-aarch64-linux ext/fast_mmaped_file/utils.c