Sha256: 2a59675329f7d2db3eda5ada8558a2addc20b762bd54675677f38f818ab6b439

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

#include <ruby.h>

#include "utils.h"

static void va_save_exception(VALUE exception, const char *fmt, va_list args) {
    VALUE message = rb_vsprintf(fmt, args);

    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);
}

void save_exception(VALUE exception, const char *fmt, ...) {
    va_list args;

    va_start(args, fmt);
    va_save_exception(exception, fmt, args);
    va_end(args);
}

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

    va_start(args, fmt);
    va_save_exception(exception, fmt, args);
    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

6 entries across 6 versions & 1 rubygems

Version Path
prometheus-client-mmap-0.9.1.pre.rc.1 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.9.0.pre.rc.1 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.9.0 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.7.0.beta45.10 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.7.0.beta45.9 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.7.0.beta45.8 ext/fast_mmaped_file/utils.c