journald-native 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62f14b24b4e9636244fd45956b5aa2804748099f
4
- data.tar.gz: a373cd433f9a905a0c4e1310a42979b50b6f06cb
3
+ metadata.gz: f07112165499f340a1a856b2f5eb952ab67512c3
4
+ data.tar.gz: 084815636014a24e2cc2500853b15b2aba90f713
5
5
  SHA512:
6
- metadata.gz: 3df15346ea9c39be6bff77310c24e26e03bb23f654d21f15388c8785d09532b88ac47f7cb0ff939dece01535a18d20785790f9faf245044bb9d1258c5509808d
7
- data.tar.gz: 34326f6563d13d955da83995d16345a2c385d4f2d87fefee4a248087e703c7c61b8dfb05e4df273db880d4638f6a752abccae058f6b143542efc4cf62588d00c
6
+ metadata.gz: 846465074f639a88087fa6a7b164a7c177c49877fa7b0115392917fd5f229c0860450a7632cacda6c835518bba766fbc98260fa2c45a7f2cef403853283c02c5
7
+ data.tar.gz: 27e0430e831019f557f68e715a9bf60b9902c108617a103481a3251d514d66f3acc79620cc8dcb1a06be94c3003e83cd4fd3c405ff6a36ba8f5c80ad692809ef
@@ -1,3 +1,5 @@
1
+ # dummy cmake file for CLion
2
+
1
3
  cmake_minimum_required(VERSION 2.8.4)
2
4
  project(journald_native)
3
5
 
@@ -7,6 +7,9 @@
7
7
 
8
8
  namespace journald_native {
9
9
 
10
+ namespace {
11
+
12
+ /* aux */
10
13
  // just a short alias for ruby_raisable_call()
11
14
  template <typename Func, typename... Args>
12
15
  inline auto r(Func f, Args... args) -> decltype(f(args...))
@@ -14,91 +17,39 @@ inline auto r(Func f, Args... args) -> decltype(f(args...))
14
17
  return ruby_exception_wrapper::ruby_raisable_call(f, args...);
15
18
  }
16
19
 
17
- /* initializers */
18
- inline void init_constants(VALUE module);
19
- inline void init_methods(VALUE module);
20
-
21
- /* methods */
22
- VALUE native_print(VALUE self, VALUE priority, VALUE message);
23
- VALUE native_send(int argc, VALUE* argv, VALUE self);
24
- VALUE native_perror(VALUE self, VALUE message);
25
- inline VALUE native_print_impl(VALUE v_self, VALUE v_priority, VALUE v_message);
26
- inline VALUE native_send_impl(int argc, VALUE* argv, VALUE self);
27
- inline VALUE native_perror_impl(VALUE v_self, VALUE v_message);
28
-
29
- /* aux */
30
- std::string create_safe_string(VALUE string); // throws ruby exceptions
31
-
32
- /* initializers */
33
- void init_modules()
34
- {
35
- // no nontrivial destructors during initialization, no need for ruby catch
36
-
37
- VALUE mJournald = rb_define_module("Journald");
38
- VALUE mNative = rb_define_module_under(mJournald, "Native");
39
-
40
- init_constants(mJournald); // add constants to Journald
41
- init_methods(mNative); // add methods to Journald::Native
42
- }
43
-
44
- inline void init_constants(VALUE module)
20
+ // Remove zeros from the string
21
+ std::string create_safe_string(VALUE v_string)
45
22
  {
46
- rb_define_const(module, "LOG_EMERG", INT2NUM(LOG_EMERG)); /* system is unusable */
47
- rb_define_const(module, "LOG_ALERT", INT2NUM(LOG_ALERT)); /* action must be taken immediately */
48
- rb_define_const(module, "LOG_CRIT", INT2NUM(LOG_CRIT)); /* critical conditions */
49
- rb_define_const(module, "LOG_ERR", INT2NUM(LOG_ERR)); /* error conditions */
50
- rb_define_const(module, "LOG_WARNING", INT2NUM(LOG_WARNING)); /* warning conditions */
51
- rb_define_const(module, "LOG_NOTICE", INT2NUM(LOG_NOTICE)); /* normal but significant condition */
52
- rb_define_const(module, "LOG_INFO", INT2NUM(LOG_INFO)); /* informational */
53
- rb_define_const(module, "LOG_DEBUG", INT2NUM(LOG_DEBUG)); /* debug-level messages */
54
- }
23
+ /* convert to string */
24
+ r(rb_string_value, &v_string);
55
25
 
56
- inline void init_methods(VALUE module)
57
- {
58
- rb_define_singleton_method(module, "print", RUBY_METHOD_FUNC(native_print), 2);
59
- rb_define_singleton_method(module, "send", RUBY_METHOD_FUNC(native_send), -1); /* -1 to pass as C array */
60
- rb_define_singleton_method(module, "perror", RUBY_METHOD_FUNC(native_perror), 1);
61
- }
26
+ char* str = (char *)RSTRING_PTR(v_string);
27
+ size_t len = (size_t)RSTRING_LEN(v_string);
62
28
 
63
- VALUE native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
64
- {
65
- try {
66
- return native_print_impl(v_self, v_priority, v_message);
67
- } catch(ruby_exception_wrapper::RbWrappedException &e) {
68
- rb_exc_raise(e.getRubyException());
69
- }
70
- }
29
+ std::string safe_str;
30
+ safe_str.reserve(len);
71
31
 
72
- VALUE native_send(int argc, VALUE* argv, VALUE v_self)
73
- {
74
- try {
75
- return native_send_impl(argc, argv, v_self);
76
- } catch(ruby_exception_wrapper::RbWrappedException &e) {
77
- rb_exc_raise(e.getRubyException());
32
+ for (size_t i = 0; i < len; i++) {
33
+ if (str[i]) {
34
+ safe_str += str[i];
35
+ }
78
36
  }
79
- }
80
37
 
81
- VALUE native_perror(VALUE v_self, VALUE v_message)
82
- {
83
- try {
84
- return native_perror_impl(v_self, v_message);
85
- } catch(ruby_exception_wrapper::RbWrappedException &e) {
86
- rb_exc_raise(e.getRubyException());
87
- }
38
+ return safe_str;
88
39
  }
89
40
 
90
41
  /* methods */
91
- inline VALUE native_print_impl(VALUE v_self, VALUE v_priority, VALUE v_message)
42
+ inline VALUE native_print(VALUE v_self, VALUE v_priority, VALUE v_message)
92
43
  {
93
44
  int priority = NUM2INT(v_priority);
94
- auto message = create_safe_string(v_message); // ruby exception here
45
+ auto message = create_safe_string(v_message);
95
46
 
96
47
  int result = sd_journal_print(priority, "%s", message.c_str());
97
48
 
98
49
  return INT2NUM(result);
99
50
  }
100
51
 
101
- inline VALUE native_send_impl(int argc, VALUE* argv, VALUE v_self)
52
+ inline VALUE native_send(int argc, VALUE* argv, VALUE v_self)
102
53
  {
103
54
  auto msgs = std::make_unique<iovec[]>((size_t)argc);
104
55
 
@@ -114,36 +65,57 @@ inline VALUE native_send_impl(int argc, VALUE* argv, VALUE v_self)
114
65
  return INT2NUM(result);
115
66
  }
116
67
 
117
- inline VALUE native_perror_impl(VALUE v_self, VALUE v_message)
68
+ inline VALUE native_perror(VALUE v_self, VALUE v_message)
118
69
  {
119
- auto message = create_safe_string(v_message); // ruby exception here
70
+ auto message = create_safe_string(v_message);
120
71
 
121
72
  int result = sd_journal_perror(message.c_str());
122
73
 
123
74
  return INT2NUM(result);
124
75
  }
125
76
 
126
- /**
127
- * Remove zeros from the string
128
- */
129
- std::string create_safe_string(VALUE v_string)
77
+ VALUE is_dummy(VALUE v_self = Qnil)
130
78
  {
131
- /* convert to string */
132
- r(rb_string_value, &v_string);
79
+ constexpr VALUE dummy = JOURNALD_NATIVE_SD_JOURNAL_DUMMY ? Qtrue : Qfalse;
80
+ return dummy;
81
+ }
133
82
 
134
- char* str = (char *)RSTRING_PTR(v_string);
135
- size_t len = (size_t)RSTRING_LEN(v_string);
83
+ /* initializers */
84
+ inline void init_journald(VALUE module)
85
+ {
86
+ rb_define_const(module, "LOG_EMERG", INT2NUM(LOG_EMERG)); /* system is unusable */
87
+ rb_define_const(module, "LOG_ALERT", INT2NUM(LOG_ALERT)); /* action must be taken immediately */
88
+ rb_define_const(module, "LOG_CRIT", INT2NUM(LOG_CRIT)); /* critical conditions */
89
+ rb_define_const(module, "LOG_ERR", INT2NUM(LOG_ERR)); /* error conditions */
90
+ rb_define_const(module, "LOG_WARNING", INT2NUM(LOG_WARNING)); /* warning conditions */
91
+ rb_define_const(module, "LOG_NOTICE", INT2NUM(LOG_NOTICE)); /* normal but significant condition */
92
+ rb_define_const(module, "LOG_INFO", INT2NUM(LOG_INFO)); /* informational */
93
+ rb_define_const(module, "LOG_DEBUG", INT2NUM(LOG_DEBUG)); /* debug-level messages */
94
+ }
136
95
 
137
- std::string safe_str;
138
- safe_str.reserve(len);
96
+ inline void init_native(VALUE module)
97
+ {
98
+ // methods
99
+ rb_define_singleton_method(module, "print", RXW_WRAPPED_METHOD_FUNC(native_print, VALUE, VALUE, VALUE), 2);
100
+ rb_define_singleton_method(module, "send", RXW_WRAPPED_METHOD_FUNC(native_send, int, VALUE*, VALUE), -1); /* -1 to pass as C array */
101
+ rb_define_singleton_method(module, "perror", RXW_WRAPPED_METHOD_FUNC(native_perror, VALUE, VALUE), 1);
102
+
103
+ // dummy detection
104
+ rb_define_const(module, "IS_DUMMY", is_dummy());
105
+ rb_define_singleton_method(module, "dummy?", RUBY_METHOD_FUNC(is_dummy), 0);
106
+ }
139
107
 
140
- for (size_t i = 0; i < len; i++) {
141
- if (str[i]) {
142
- safe_str += str[i];
143
- }
144
- }
108
+ } // private namespace
145
109
 
146
- return safe_str;
110
+ void init_modules()
111
+ {
112
+ // no nontrivial destructors during initialization, no need for ruby catch
113
+
114
+ VALUE mJournald = rb_define_module("Journald");
115
+ VALUE mNative = rb_define_module_under(mJournald, "Native");
116
+
117
+ init_journald(mJournald); // add constants to Journald
118
+ init_native(mNative); // add methods to Journald::Native
147
119
  }
148
120
 
149
121
  }
@@ -9,6 +9,10 @@
9
9
 
10
10
  #include "cpp14shiv.h" // make this c++14 code c++11 compatible; remove for c++14
11
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
+
12
16
  namespace ruby_exception_wrapper {
13
17
 
14
18
  class RbWrappedException: public std::exception {
@@ -22,7 +26,7 @@ namespace ruby_exception_wrapper {
22
26
  VALUE rethrow_as_cpp(VALUE put_exception_here_ptr, VALUE exception);
23
27
 
24
28
  namespace {
25
- // do real call of function from template for func with params
29
+ // do real call of function from template
26
30
  template <typename FuncPointer, typename... Args>
27
31
  inline VALUE call_wrapper_tuple_impl(FuncPointer& fp, Args... args)
28
32
  {
@@ -86,6 +90,16 @@ namespace ruby_exception_wrapper {
86
90
  return result;
87
91
  }
88
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
+
89
103
  }
90
104
 
91
105
  #endif
@@ -3,6 +3,8 @@
3
3
 
4
4
  #ifdef __linux__
5
5
 
6
+ #define JOURNALD_NATIVE_SD_JOURNAL_DUMMY false
7
+
6
8
  /* do the real stuff */
7
9
 
8
10
  #include "extconf.h"
@@ -32,6 +34,8 @@
32
34
 
33
35
  #else
34
36
 
37
+ #define JOURNALD_NATIVE_SD_JOURNAL_DUMMY true
38
+
35
39
  #warning Compiling dummy version of the gem for non-Linux OS
36
40
 
37
41
  #include "sd_journal_dummy.h"
@@ -1,5 +1,5 @@
1
1
  module Journald
2
2
  module Native
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.5'
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.4
4
+ version: 1.0.5
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-09 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.2.2
101
+ rubygems_version: 2.4.3
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: systemd-journal logging native lib wrapper