journald-native 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7074ca755c39b71b382f63b7befe21e0dc7e18ec
4
- data.tar.gz: 585840efef3b5ee2b50f97e830ecf21df0ec811b
3
+ metadata.gz: 4020a007bf01dcb53dde8935a7772ab71e28c882
4
+ data.tar.gz: b95b33ae4d6014cf76c0b1b6e138829274f3d433
5
5
  SHA512:
6
- metadata.gz: e19cdf3224ca356c47319c5dd6897cc364a8f4d87a1f9c7d9319a31be19be2b4298cbc1b869024e8f0846f48115947dc296afb9d809de368bc16ae18434cdb2a
7
- data.tar.gz: 214828671762b128ae1875fffce35e8a3db25217db47e6bca8d4a127750c3ad1ca55d9c8999c623829dce3a8b998ffe70d2fe62395b3dedf75b3479d3487532a
6
+ metadata.gz: 6ab72f2d53e00b60be3489609ee7065e293bef46c13145c14cfae7eae4adddbb465e1a4a785ba05930a50f1b97fa5de809a20f0b2d628a9073d7655c82dd3f74
7
+ data.tar.gz: 3983b62b9f1dc7367013048cab266f2adc71b5c0ed14ae9ad77bafe214866d6310c5d7b70f672d10636319815d7d815b4cab5a1078cbf672909d69c8659ebbef
data/README.md CHANGED
@@ -30,13 +30,13 @@ Journald::LOG_DEBUG # debug-level messages
30
30
  ```
31
31
 
32
32
  systemd-journal uses syslog constants to denote level therefore they are equal to those of the Syslog module,
33
- e.g. ```Journald::LOG_WARNING == Syslog::LOG_WARNING```.
33
+ e.g. ```Journald::LOG_WARNING == Syslog::LOG_WARNING```.
34
34
  [See syslog man page for more info](http://man7.org/linux/man-pages/man3/syslog.3.html)
35
35
 
36
36
  ### Methods
37
37
 
38
- Methods of Journald::Native class wrap systemd-journal calls.
39
- [See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
38
+ Methods of Journald::Native class wrap systemd-journal calls.
39
+ [See sd-journal help for more info](http://www.freedesktop.org/software/systemd/man/sd_journal_print.html)
40
40
 
41
41
  ```ruby
42
42
  Journald::Native.send "MESSAGE=message", "PRIORITY=#{Journald::LOG_WARNING}"
@@ -8,7 +8,7 @@ LIB_DIRS = [LIBDIR]
8
8
 
9
9
  dir_config('systemd', HEADER_DIRS, LIB_DIRS)
10
10
 
11
- $CPPFLAGS = '-std=c++11'
11
+ $CFLAGS = '-std=c99'
12
12
 
13
13
  def have_funcs
14
14
  have_funcs = true
@@ -0,0 +1,117 @@
1
+ /* Do not add C line and file to the log messages */
2
+ #define SD_JOURNAL_SUPPRESS_LOCATION
3
+
4
+ #include <ruby.h>
5
+ #include "sd_journal.h"
6
+
7
+ void Init_journald_native();
8
+
9
+ /* initializers */
10
+ static void jdl_init_modules();
11
+ static void jdl_init_constants();
12
+ static void jdl_init_methods();
13
+
14
+ /* methods */
15
+ static VALUE jdl_native_print(VALUE self, VALUE priority, VALUE message);
16
+ static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self);
17
+ static VALUE jdl_native_perror(VALUE self, VALUE message);
18
+ static VALUE jdl_native_is_dummy();
19
+
20
+ /* globals */
21
+ static VALUE mJournald;
22
+ static VALUE mNative;
23
+
24
+ void Init_journald_native()
25
+ {
26
+ jdl_init_modules();
27
+ jdl_init_constants();
28
+ jdl_init_methods();
29
+ }
30
+
31
+ static void jdl_init_modules()
32
+ {
33
+ mJournald = rb_define_module("Journald");
34
+ mNative = rb_define_module_under(mJournald, "Native");
35
+ }
36
+
37
+ static void jdl_init_constants()
38
+ {
39
+ rb_define_const(mJournald, "LOG_EMERG", INT2NUM(LOG_EMERG)); /* system is unusable */
40
+ rb_define_const(mJournald, "LOG_ALERT", INT2NUM(LOG_ALERT)); /* action must be taken immediately */
41
+ rb_define_const(mJournald, "LOG_CRIT", INT2NUM(LOG_CRIT)); /* critical conditions */
42
+ rb_define_const(mJournald, "LOG_ERR", INT2NUM(LOG_ERR)); /* error conditions */
43
+ rb_define_const(mJournald, "LOG_WARNING", INT2NUM(LOG_WARNING)); /* warning conditions */
44
+ rb_define_const(mJournald, "LOG_NOTICE", INT2NUM(LOG_NOTICE)); /* normal but significant condition */
45
+ rb_define_const(mJournald, "LOG_INFO", INT2NUM(LOG_INFO)); /* informational */
46
+ rb_define_const(mJournald, "LOG_DEBUG", INT2NUM(LOG_DEBUG)); /* debug-level messages */
47
+
48
+ // dummy detection const
49
+ rb_define_const(mNative, "IS_DUMMY", jdl_native_is_dummy());
50
+ }
51
+
52
+ static void jdl_init_methods()
53
+ {
54
+ rb_define_singleton_method(mNative, "print", jdl_native_print, 2);
55
+ rb_define_singleton_method(mNative, "send", jdl_native_send, -1); /* -1 to pass as C array */
56
+ rb_define_singleton_method(mNative, "perror", jdl_native_perror, 1);
57
+
58
+ // dummy detection method
59
+ rb_define_singleton_method(mNative, "dummy?", jdl_native_is_dummy, 0);
60
+ }
61
+
62
+ static VALUE jdl_native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
63
+ {
64
+ int priority, result;
65
+ char *message;
66
+
67
+ priority = NUM2INT(v_priority);
68
+ message = StringValueCStr(v_message);
69
+
70
+ result = sd_journal_print(priority, "%s", message);
71
+
72
+ return INT2NUM(result);
73
+ }
74
+
75
+ static VALUE jdl_native_send(int argc, VALUE* argv, VALUE self)
76
+ {
77
+ struct iovec *msgs;
78
+ int i;
79
+ int result;
80
+
81
+ /* first check everything is a string / convertable to string */
82
+ for (i = 0; i < argc; i++) {
83
+ StringValue(argv[i]); /* you may get a ruby exception here */
84
+ }
85
+
86
+ /* allocate memory after all checks to avoid possible memory leak */
87
+ msgs = calloc(argc, sizeof(struct iovec));
88
+
89
+ for (i = 0; i < argc; i++) {
90
+ VALUE v = argv[i];
91
+ msgs[i].iov_base = RSTRING_PTR(v);
92
+ msgs[i].iov_len = RSTRING_LEN(v);
93
+ }
94
+
95
+ result = sd_journal_sendv(msgs, argc);
96
+
97
+ free(msgs);
98
+
99
+ return INT2NUM(result);
100
+ }
101
+
102
+ static VALUE jdl_native_perror(VALUE v_self, VALUE v_message)
103
+ {
104
+ int result;
105
+ char *message;
106
+
107
+ message = StringValueCStr(v_message);
108
+
109
+ result = sd_journal_perror(message);
110
+
111
+ return INT2NUM(result);
112
+ }
113
+
114
+ static VALUE jdl_native_is_dummy()
115
+ {
116
+ return JOURNALD_NATIVE_SD_JOURNAL_DUMMY ? Qtrue : Qfalse;
117
+ }
@@ -1,45 +1,55 @@
1
+ #include <stdbool.h>
2
+
3
+ #ifdef __cplusplus
4
+ extern "C" {
5
+ #endif
6
+
1
7
  #ifndef JOURNALD_NATIVE_SD_JOURNAL_H
2
- #define JOURNALD_NATIVE_SD_JOURNAL_H
8
+ #define JOURNALD_NATIVE_SD_JOURNAL_H
3
9
 
4
- #ifdef __linux__
10
+ #ifdef __linux__
5
11
 
6
- #define JOURNALD_NATIVE_SD_JOURNAL_DUMMY false
12
+ #define JOURNALD_NATIVE_SD_JOURNAL_DUMMY false
7
13
 
8
- /* do the real stuff */
14
+ /* do the real stuff */
9
15
 
10
- #include "extconf.h"
16
+ #include "extconf.h"
11
17
 
12
- /* check for extconf results */
18
+ /* check for extconf results */
13
19
 
14
- #ifndef HAVE_SYSTEMD_SD_JOURNAL_H
15
- #error Cannot include <systemd/sd-journal.h>. Please use linux version with systemd-journal installed
16
- #endif
20
+ #ifndef HAVE_SYSTEMD_SD_JOURNAL_H
21
+ #error Cannot include <systemd/sd-journal.h>. Please use linux version with systemd-journal installed
22
+ #endif
17
23
 
18
- #ifndef HAVE_SD_JOURNAL_PRINT
19
- #error Required function sd_journal_print is missing
20
- #endif
24
+ #ifndef HAVE_SD_JOURNAL_PRINT
25
+ #error Required function sd_journal_print is missing
26
+ #endif
21
27
 
22
- #ifndef HAVE_SD_JOURNAL_SENDV
23
- #error Required function sd_journal_sendv is missing
24
- #endif
28
+ #ifndef HAVE_SD_JOURNAL_SENDV
29
+ #error Required function sd_journal_sendv is missing
30
+ #endif
25
31
 
26
- #ifndef HAVE_SD_JOURNAL_PERROR
27
- #error Required function sd_journal_perror is missing
28
- #endif
32
+ #ifndef HAVE_SD_JOURNAL_PERROR
33
+ #error Required function sd_journal_perror is missing
34
+ #endif
29
35
 
30
- /* Do not add C line and file to the log messages */
31
- #define SD_JOURNAL_SUPPRESS_LOCATION
32
- /* include systemd-journal headers */
33
- #include <systemd/sd-journal.h>
36
+ /* Do not add C line and file to the log messages */
37
+ #define SD_JOURNAL_SUPPRESS_LOCATION
38
+ /* include systemd-journal headers */
39
+ #include <systemd/sd-journal.h>
34
40
 
35
- #else
41
+ #else
36
42
 
37
- #define JOURNALD_NATIVE_SD_JOURNAL_DUMMY true
43
+ #define JOURNALD_NATIVE_SD_JOURNAL_DUMMY true
38
44
 
39
- #warning Compiling dummy version of the gem for non-Linux OS
45
+ #warning Compiling dummy version of the gem for non-Linux OS
40
46
 
41
- #include "sd_journal_dummy.h"
47
+ #include "sd_journal_dummy.h"
48
+
49
+ #endif
42
50
 
51
+ #ifdef __cplusplus
52
+ }
43
53
  #endif
44
54
 
45
55
  #endif // JOURNALD_NATIVE_SD_JOURNAL_H
@@ -1,5 +1,5 @@
1
1
  module Journald
2
2
  module Native
3
- VERSION = '1.0.6'
3
+ VERSION = '1.0.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journald-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Smirnov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,14 +65,8 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
- - ext/journald_native/CMakeLists.txt
69
- - ext/journald_native/cpp14shiv.h
70
68
  - ext/journald_native/extconf.rb
71
- - ext/journald_native/extinit.cpp
72
- - ext/journald_native/journald_native.cpp
73
- - ext/journald_native/journald_native.h
74
- - ext/journald_native/ruby_exception_wrapper.cpp
75
- - ext/journald_native/ruby_exception_wrapper.h
69
+ - ext/journald_native/journald_native.c
76
70
  - ext/journald_native/sd_journal.h
77
71
  - ext/journald_native/sd_journal_dummy.h
78
72
  - journald-native.gemspec
@@ -98,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
92
  version: '0'
99
93
  requirements: []
100
94
  rubyforge_project:
101
- rubygems_version: 2.4.3
95
+ rubygems_version: 2.4.5
102
96
  signing_key:
103
97
  specification_version: 4
104
98
  summary: systemd-journal logging native lib wrapper
@@ -1,9 +0,0 @@
1
- # dummy cmake file for CLion
2
-
3
- cmake_minimum_required(VERSION 2.8.4)
4
- project(journald_native)
5
-
6
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
7
-
8
- set(SOURCE_FILES extinit.cpp journald_native.cpp ruby_exception_wrapper.cpp)
9
- add_executable(journald_native ${SOURCE_FILES})
@@ -1,78 +0,0 @@
1
- /*
2
- unique_ptr from http://isocpp.org/files/papers/N3656.txt
3
- index sequence from gcc 4.9 sources
4
- */
5
-
6
- #include <cstddef>
7
- #include <memory>
8
- #include <type_traits>
9
- #include <utility>
10
-
11
- namespace std {
12
- template<class T> struct _Unique_if {
13
- typedef unique_ptr<T> _Single_object;
14
- };
15
-
16
- template<class T> struct _Unique_if<T[]> {
17
- typedef unique_ptr<T[]> _Unknown_bound;
18
- };
19
-
20
- template<class T, size_t N> struct _Unique_if<T[N]> {
21
- typedef void _Known_bound;
22
- };
23
-
24
- template<class T, class... Args>
25
- typename _Unique_if<T>::_Single_object
26
- make_unique(Args&&... args) {
27
- return unique_ptr<T>(new T(std::forward<Args>(args)...));
28
- }
29
-
30
- template<class T>
31
- typename _Unique_if<T>::_Unknown_bound
32
- make_unique(size_t n) {
33
- typedef typename remove_extent<T>::type U;
34
- return unique_ptr<T>(new U[n]());
35
- }
36
-
37
- template<class T, class... Args>
38
- typename _Unique_if<T>::_Known_bound
39
- make_unique(Args&&...) = delete;
40
-
41
- /// Class template integer_sequence
42
- template<typename _Tp, _Tp... _Idx>
43
- struct integer_sequence
44
- {
45
- typedef _Tp value_type;
46
- static constexpr size_t size() { return sizeof...(_Idx); }
47
- };
48
-
49
- template<typename _Tp, _Tp _Num,
50
- typename _ISeq = typename _Build_index_tuple<_Num>::__type>
51
- struct _Make_integer_sequence;
52
-
53
- template<typename _Tp, _Tp _Num, size_t... _Idx>
54
- struct _Make_integer_sequence<_Tp, _Num, _Index_tuple<_Idx...>>
55
- {
56
- static_assert( _Num >= 0,
57
- "Cannot make integer sequence of negative length" );
58
-
59
- typedef integer_sequence<_Tp, static_cast<_Tp>(_Idx)...> __type;
60
- };
61
-
62
- /// Alias template make_integer_sequence
63
- template<typename _Tp, _Tp _Num>
64
- using make_integer_sequence
65
- = typename _Make_integer_sequence<_Tp, _Num>::__type;
66
-
67
- /// Alias template index_sequence
68
- template<size_t... _Idx>
69
- using index_sequence = integer_sequence<size_t, _Idx...>;
70
-
71
- /// Alias template make_index_sequence
72
- template<size_t _Num>
73
- using make_index_sequence = make_integer_sequence<size_t, _Num>;
74
-
75
- /// Alias template index_sequence_for
76
- template<typename... _Types>
77
- using index_sequence_for = make_index_sequence<sizeof...(_Types)>;
78
- }
@@ -1,7 +0,0 @@
1
- #include "journald_native.h"
2
-
3
- /* initialize ruby extension */
4
- extern "C" void Init_journald_native()
5
- {
6
- journald_native::init_modules();
7
- }
@@ -1,100 +0,0 @@
1
- #include "journald_native.h"
2
- #include "sd_journal.h"
3
-
4
- #include <memory>
5
-
6
- #include "ruby_exception_wrapper.h"
7
-
8
- namespace journald_native {
9
-
10
- namespace {
11
-
12
- /* aux */
13
- // just a short alias for ruby_raisable_call()
14
- template <typename Func, typename... Args>
15
- inline auto r(Func f, Args... args) -> decltype(f(args...))
16
- {
17
- return ruby_exception_wrapper::ruby_raisable_call(f, args...);
18
- }
19
-
20
- /* methods */
21
- inline VALUE native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
22
- {
23
- int priority = NUM2INT(v_priority);
24
- std::string message = r(rb_string_value_cstr, &v_message);
25
-
26
- int result = sd_journal_print(priority, "%s", message.c_str());
27
-
28
- return INT2NUM(result);
29
- }
30
-
31
- inline VALUE native_send(int argc, VALUE* argv, VALUE v_self)
32
- {
33
- auto msgs = std::make_unique<iovec[]>((size_t)argc);
34
-
35
- for (int i = 0; i < argc; i++) {
36
- VALUE v = r(rb_string_value, &argv[i]);
37
-
38
- msgs[i].iov_base = (char *)RSTRING_PTR(v);
39
- msgs[i].iov_len = (size_t)RSTRING_LEN(v);
40
- }
41
-
42
- int result = sd_journal_sendv(msgs.get(), argc);
43
-
44
- return INT2NUM(result);
45
- }
46
-
47
- inline VALUE native_perror(VALUE v_self, VALUE v_message)
48
- {
49
- std::string message = r(rb_string_value_cstr, &v_message);
50
-
51
- int result = sd_journal_perror(message.c_str());
52
-
53
- return INT2NUM(result);
54
- }
55
-
56
- VALUE is_dummy(VALUE v_self = Qnil)
57
- {
58
- constexpr VALUE dummy = JOURNALD_NATIVE_SD_JOURNAL_DUMMY ? Qtrue : Qfalse;
59
- return dummy;
60
- }
61
-
62
- /* initializers */
63
- inline void init_journald(VALUE module)
64
- {
65
- rb_define_const(module, "LOG_EMERG", INT2NUM(LOG_EMERG)); /* system is unusable */
66
- rb_define_const(module, "LOG_ALERT", INT2NUM(LOG_ALERT)); /* action must be taken immediately */
67
- rb_define_const(module, "LOG_CRIT", INT2NUM(LOG_CRIT)); /* critical conditions */
68
- rb_define_const(module, "LOG_ERR", INT2NUM(LOG_ERR)); /* error conditions */
69
- rb_define_const(module, "LOG_WARNING", INT2NUM(LOG_WARNING)); /* warning conditions */
70
- rb_define_const(module, "LOG_NOTICE", INT2NUM(LOG_NOTICE)); /* normal but significant condition */
71
- rb_define_const(module, "LOG_INFO", INT2NUM(LOG_INFO)); /* informational */
72
- rb_define_const(module, "LOG_DEBUG", INT2NUM(LOG_DEBUG)); /* debug-level messages */
73
- }
74
-
75
- inline void init_native(VALUE module)
76
- {
77
- // methods
78
- rb_define_singleton_method(module, "print", RXW_WRAPPED_METHOD_FUNC(native_print, VALUE, VALUE, VALUE), 2);
79
- rb_define_singleton_method(module, "send", RXW_WRAPPED_METHOD_FUNC(native_send, int, VALUE*, VALUE), -1); /* -1 to pass as C array */
80
- rb_define_singleton_method(module, "perror", RXW_WRAPPED_METHOD_FUNC(native_perror, VALUE, VALUE), 1);
81
-
82
- // dummy detection
83
- rb_define_const(module, "IS_DUMMY", is_dummy());
84
- rb_define_singleton_method(module, "dummy?", RUBY_METHOD_FUNC(is_dummy), 0);
85
- }
86
-
87
- } // private namespace
88
-
89
- void init_modules()
90
- {
91
- // no nontrivial destructors during initialization, no need for ruby catch
92
-
93
- VALUE mJournald = rb_define_module("Journald");
94
- VALUE mNative = rb_define_module_under(mJournald, "Native");
95
-
96
- init_journald(mJournald); // add constants to Journald
97
- init_native(mNative); // add methods to Journald::Native
98
- }
99
-
100
- }
@@ -1,12 +0,0 @@
1
- #ifndef JOURNALD_NATIVE_JOURNALD_NATIVE_H
2
- #define JOURNALD_NATIVE_JOURNALD_NATIVE_H
3
-
4
- #include <string>
5
- #include <ruby.h>
6
-
7
- namespace journald_native {
8
- /* initializers */
9
- void init_modules();
10
- }
11
-
12
- #endif // JOURNALD_NATIVE_JOURNALD_NATIVE_H
@@ -1,16 +0,0 @@
1
- #include "ruby_exception_wrapper.h"
2
-
3
- namespace ruby_exception_wrapper {
4
-
5
- // callback for rb_rescue2 to catch ruby exception and wrap it by RbWrappedException
6
- VALUE rethrow_as_cpp(VALUE put_exception_here_ptr, VALUE exception)
7
- {
8
- // cannot actually throw here, just pass the exception
9
- VALUE* excptr = reinterpret_cast<VALUE*>(put_exception_here_ptr);
10
-
11
- *excptr = exception;
12
-
13
- return exception;
14
- }
15
-
16
- }
@@ -1,105 +0,0 @@
1
- #ifndef RUBY_EXCEPTION_WRAPPER_H
2
- #define RUBY_EXCEPTION_WRAPPER_H
3
-
4
- #include <ruby.h>
5
-
6
- #include <functional>
7
- #include <type_traits>
8
- #include <utility>
9
-
10
- #include "cpp14shiv.h" // make this c++14 code c++11 compatible; remove for c++14
11
-
12
- // wrap functions, prototype required, i.e. RXW_WRAPPED_METHOD_FUNC(native_send, int, VALUE*, VALUE)
13
- // functions can be inline
14
- #define RXW_WRAPPED_METHOD_FUNC(method, ...) ((VALUE (*)(ANYARGS))::ruby_exception_wrapper::method_wrapper_call<decltype(&method), method, __VA_ARGS__>)
15
-
16
- namespace ruby_exception_wrapper {
17
-
18
- class RbWrappedException: public std::exception {
19
- VALUE ruby_exception;
20
- public:
21
- RbWrappedException(VALUE e): ruby_exception(e) {};
22
- VALUE getRubyException() { return ruby_exception; }
23
- };
24
-
25
- // callback for rb_rescue2 to catch ruby exception and wrap it by RbWrappedException
26
- VALUE rethrow_as_cpp(VALUE put_exception_here_ptr, VALUE exception);
27
-
28
- namespace {
29
- // do real call of function from template
30
- template <typename FuncPointer, typename... Args>
31
- inline VALUE call_wrapper_tuple_impl(FuncPointer& fp, Args... args)
32
- {
33
- // only pointers and VALUE permitted
34
- // VALUE guaranteed to be able to contain pointer
35
- return reinterpret_cast<VALUE>(fp(args...));
36
- }
37
-
38
- // unpack params to do real call
39
- template <typename CallTuple, std::size_t... Is>
40
- inline VALUE call_wrapper_tuple_unpack(CallTuple& call_tuple, std::index_sequence<Is...>)
41
- {
42
- return call_wrapper_tuple_impl(std::get<Is>(call_tuple)...);
43
- }
44
-
45
- // callback for rb_rescue2 for no exceptions
46
- template <typename CallTuple>
47
- VALUE call_wrapper_tuple(VALUE v_ct) {
48
- CallTuple call_tuple = std::move(*reinterpret_cast<CallTuple*>(v_ct));
49
-
50
- return call_wrapper_tuple_unpack(call_tuple, std::make_index_sequence<std::tuple_size<CallTuple>::value> {});
51
- };
52
-
53
- // safely call function
54
- template <typename Func, typename... Args>
55
- inline auto do_raisable_call(Func f, Args... args) -> decltype(f(args...))
56
- {
57
- typedef std::function<typename std::remove_pointer<Func>::type> FuncPointer;
58
- typedef std::tuple<FuncPointer, Args...> CallTuple;
59
-
60
- FuncPointer fp = f;
61
-
62
- CallTuple call_tuple = std::make_tuple(fp, args...);
63
-
64
- VALUE exception = 0; // get raised exception if any
65
-
66
- VALUE result = rb_rescue2(
67
- RUBY_METHOD_FUNC(call_wrapper_tuple<CallTuple>), reinterpret_cast<VALUE>(&call_tuple),
68
- RUBY_METHOD_FUNC(rethrow_as_cpp), reinterpret_cast<VALUE>(&exception),
69
- rb_eException, Qfalse
70
- );
71
-
72
- if (exception) { // nonzero here if rescue called unless some pervert throws Qfalse
73
- throw RbWrappedException(exception);
74
- }
75
-
76
- return reinterpret_cast<decltype(f(args...))>(result);
77
- }
78
- }
79
-
80
- template <typename Func, typename... Args>
81
- inline auto ruby_raisable_call(Func f, Args... args) -> decltype(f(args...))
82
- {
83
- static_assert(
84
- std::is_same<decltype(f(args...)), VALUE>::value || std::is_pointer<decltype(f(args...))>::value,
85
- "Only for funcs returning VALUE or pointer"
86
- );
87
-
88
- auto result = do_raisable_call(f, args...);
89
-
90
- return result;
91
- }
92
-
93
- template <typename Func, Func func, typename... Args>
94
- VALUE method_wrapper_call(Args... args)
95
- {
96
- try {
97
- return func(args...);
98
- } catch(RbWrappedException &e) {
99
- rb_exc_raise(e.getRubyException());
100
- }
101
- }
102
-
103
- }
104
-
105
- #endif