Sha256: 2c4b6e46ccee59248391389da04dd14ef7c754fb36a197ca9bf3680beecc1025

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 Bytes

Contents

#include <ruby.h>
#include "utils.h"

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

    va_start(args, fmt);
    VALUE message = rb_vsprintf(fmt, args);
    va_end(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 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

2 entries across 2 versions & 1 rubygems

Version Path
prometheus-client-mmap-0.7.0.beta41 ext/fast_mmaped_file/utils.c
prometheus-client-mmap-0.7.0.beta40 ext/fast_mmaped_file/utils.c