rice 2.1.0 → 3.0.0

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.
Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +2 -2
  3. data/Doxyfile +4 -16
  4. data/Makefile.am +2 -2
  5. data/Makefile.in +28 -17
  6. data/{README → README.md} +323 -328
  7. data/aclocal.m4 +104 -107
  8. data/ax_cxx_compile_stdcxx.m4 +951 -0
  9. data/configure +549 -238
  10. data/configure.ac +3 -3
  11. data/extconf.rb +11 -10
  12. data/rice/Array.hpp +16 -16
  13. data/rice/Array.ipp +11 -11
  14. data/rice/Class_defn.hpp +1 -0
  15. data/rice/Constructor.hpp +27 -371
  16. data/rice/Data_Object_defn.hpp +3 -3
  17. data/rice/Director.hpp +3 -3
  18. data/rice/Enum.ipp +1 -1
  19. data/rice/Exception.cpp +2 -7
  20. data/rice/Hash.hpp +8 -5
  21. data/rice/Hash.ipp +2 -2
  22. data/rice/Makefile.am +1 -4
  23. data/rice/Makefile.in +80 -35
  24. data/rice/Module_impl.ipp +1 -1
  25. data/rice/Object.cpp +1 -1
  26. data/rice/Object.ipp +15 -1
  27. data/rice/Object_defn.hpp +24 -1
  28. data/rice/String.cpp +2 -7
  29. data/rice/Struct.cpp +2 -2
  30. data/rice/Struct.hpp +1 -1
  31. data/rice/Struct.ipp +1 -1
  32. data/rice/config.hpp +2 -2
  33. data/rice/config.hpp.in +2 -2
  34. data/rice/detail/Arguments.hpp +1 -1
  35. data/rice/detail/Auto_Function_Wrapper.ipp +512 -1025
  36. data/rice/detail/Auto_Member_Function_Wrapper.ipp +272 -545
  37. data/rice/detail/Iterator.hpp +2 -2
  38. data/rice/detail/method_data.cpp +8 -2
  39. data/rice/detail/ruby.hpp +1 -4
  40. data/rice/detail/ruby_version_code.hpp +1 -1
  41. data/rice/detail/wrap_function.hpp +32 -307
  42. data/rice/protect.hpp +3 -57
  43. data/rice/to_from_ruby.ipp +128 -4
  44. data/ruby/Makefile.in +11 -8
  45. data/ruby/lib/Makefile.in +10 -7
  46. data/ruby/lib/version.rb +1 -1
  47. data/sample/Makefile.am +10 -4
  48. data/sample/Makefile.in +20 -11
  49. data/sample/callbacks/extconf.rb +3 -0
  50. data/sample/callbacks/sample_callbacks.cpp +38 -0
  51. data/sample/callbacks/test.rb +28 -0
  52. data/test/Makefile.am +1 -0
  53. data/test/Makefile.in +118 -49
  54. data/test/embed_ruby.cpp +21 -0
  55. data/test/embed_ruby.hpp +4 -0
  56. data/test/ext/Makefile.in +10 -7
  57. data/test/test_Address_Registration_Guard.cpp +2 -1
  58. data/test/test_Array.cpp +2 -1
  59. data/test/test_Builtin_Object.cpp +2 -1
  60. data/test/test_Class.cpp +7 -4
  61. data/test/test_Data_Object.cpp +2 -1
  62. data/test/test_Data_Type.cpp +2 -1
  63. data/test/test_Director.cpp +2 -1
  64. data/test/test_Enum.cpp +24 -3
  65. data/test/test_Exception.cpp +2 -1
  66. data/test/test_Hash.cpp +2 -1
  67. data/test/test_Identifier.cpp +2 -1
  68. data/test/test_Memory_Management.cpp +2 -1
  69. data/test/test_Module.cpp +2 -1
  70. data/test/test_Object.cpp +13 -1
  71. data/test/test_String.cpp +2 -1
  72. data/test/test_Struct.cpp +2 -1
  73. data/test/test_Symbol.cpp +2 -1
  74. data/test/test_To_From_Ruby.cpp +102 -1
  75. data/test/test_global_functions.cpp +2 -1
  76. data/test/test_rice.rb +4 -0
  77. data/test/unittest.cpp +35 -9
  78. metadata +72 -16
  79. data/check_stdcxx_11.ac +0 -142
  80. data/rice/detail/object_call.hpp +0 -69
  81. data/rice/detail/object_call.ipp +0 -131
  82. data/rice/detail/traits.hpp +0 -43
  83. data/rice/detail/wrap_function.ipp +0 -514
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Data_Object.hpp"
3
4
  #include "rice/Data_Type.hpp"
4
5
  #include "rice/Exception.hpp"
@@ -22,7 +23,7 @@ void ruby_mark(Foo * foo)
22
23
 
23
24
  SETUP(Data_Object)
24
25
  {
25
- ruby_init();
26
+ embed_ruby();
26
27
 
27
28
  if(!Data_Type<Foo>::is_bound())
28
29
  {
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Data_Type.hpp"
3
4
  #include "rice/Exception.hpp"
4
5
  #include "rice/Constructor.hpp"
@@ -63,7 +64,7 @@ namespace {
63
64
 
64
65
  SETUP(Data_Type)
65
66
  {
66
- ruby_init();
67
+ embed_ruby();
67
68
 
68
69
  define_class<Listener>("Listener")
69
70
  .define_constructor(Constructor<Listener>())
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Exception.hpp"
3
4
  #include "rice/Director.hpp"
4
5
  #include "rice/Constructor.hpp"
@@ -87,7 +88,7 @@ namespace {
87
88
 
88
89
  SETUP(Director)
89
90
  {
90
- ruby_init();
91
+ embed_ruby();
91
92
  }
92
93
 
93
94
  TESTCASE(exposes_worker_as_instantiatable_class)
@@ -1,8 +1,10 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Enum.hpp"
3
4
  #include "rice/Array.hpp"
4
5
  #include "rice/String.hpp"
5
6
  #include "rice/Constructor.hpp"
7
+ #include "rice/global_function.hpp"
6
8
  #include <iostream>
7
9
 
8
10
  using namespace Rice;
@@ -25,7 +27,7 @@ namespace
25
27
 
26
28
  SETUP(Enum)
27
29
  {
28
- ruby_init();
30
+ embed_ruby();
29
31
  }
30
32
 
31
33
  TESTCASE(copy_construct)
@@ -147,14 +149,12 @@ TESTCASE(different_objects_eql)
147
149
  ASSERT_EQUAL(true, red1 == red2);
148
150
  }
149
151
 
150
- /*
151
152
  TESTCASE(hash)
152
153
  {
153
154
  Enum<Color> rb_cColor = define_color_enum();
154
155
  Data_Object<Color> red(new Color(RED));
155
156
  ASSERT_EQUAL(to_ruby(int(RED)), red.call("hash"));
156
157
  }
157
- */
158
158
 
159
159
  TESTCASE(from_int)
160
160
  {
@@ -193,3 +193,24 @@ TESTCASE(nested_enums)
193
193
  ASSERT_EQUAL(to_ruby(int(2)), Object(protect(rb_eval_string, "Inner::Props::VALUE3.to_i")));
194
194
  }
195
195
 
196
+ namespace
197
+ {
198
+ Color getEnum()
199
+ {
200
+ return GREEN;
201
+ }
202
+ }
203
+
204
+ TESTCASE(return_enum_value_to_ruby)
205
+ {
206
+ Enum<Color> rb_cColor = define_color_enum();
207
+ define_global_function("get_enum", &getEnum);
208
+
209
+ ASSERT_EQUAL(
210
+ Data_Object<Color>(protect(rb_eval_string, "Color::GREEN")),
211
+ Data_Object<Color>(protect(rb_eval_string, "get_enum"))
212
+ );
213
+
214
+ ASSERT_EQUAL(String("GREEN"), String(protect(rb_eval_string, "get_enum.to_s")));
215
+ ASSERT_EQUAL(String("#<Color::GREEN>"), String(protect(rb_eval_string, "get_enum.inspect")));
216
+ }
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Exception.hpp"
3
4
  #include "rice/String.hpp"
4
5
 
@@ -8,7 +9,7 @@ TESTSUITE(Exception);
8
9
 
9
10
  SETUP(Exception)
10
11
  {
11
- ruby_init();
12
+ embed_ruby();
12
13
  }
13
14
 
14
15
  TESTCASE(construct_from_exception_object)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Hash.hpp"
3
4
  #include "rice/global_function.hpp"
4
5
  #include <vector>
@@ -11,7 +12,7 @@ TESTSUITE(Hash);
11
12
 
12
13
  SETUP(Hash)
13
14
  {
14
- ruby_init();
15
+ embed_ruby();
15
16
  }
16
17
 
17
18
  TESTCASE(default_construct)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Identifier.hpp"
3
4
  #include "rice/Symbol.hpp"
4
5
 
@@ -8,7 +9,7 @@ TESTSUITE(Identifier);
8
9
 
9
10
  SETUP(Identifier)
10
11
  {
11
- ruby_init();
12
+ embed_ruby();
12
13
  }
13
14
 
14
15
  TESTCASE(construct_from_id)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/String.hpp"
3
4
  #include "rice/Class.hpp"
4
5
  #include "rice/global_function.hpp"
@@ -9,7 +10,7 @@ TESTSUITE(Memory_Management);
9
10
 
10
11
  SETUP(Memory_Management)
11
12
  {
12
- ruby_init();
13
+ embed_ruby();
13
14
  }
14
15
 
15
16
  namespace
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Module.hpp"
3
4
  #include "rice/Exception.hpp"
4
5
  #include "rice/Array.hpp"
@@ -12,7 +13,7 @@ TESTSUITE(Module);
12
13
 
13
14
  SETUP(Object)
14
15
  {
15
- ruby_init();
16
+ embed_ruby();
16
17
  }
17
18
 
18
19
  TESTCASE(construct_from_value)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Object.hpp"
3
4
  #include "rice/Class.hpp"
4
5
  #include "rice/String.hpp"
@@ -10,7 +11,7 @@ TESTSUITE(Object);
10
11
 
11
12
  SETUP(Object)
12
13
  {
13
- ruby_init();
14
+ embed_ruby();
14
15
  }
15
16
 
16
17
  TESTCASE(default_construct)
@@ -146,3 +147,14 @@ TESTCASE(rb_type)
146
147
  ASSERT_EQUAL(T_UNDEF, Object(Qundef).rb_type());
147
148
  }
148
149
 
150
+ TESTCASE(call_no_arguments)
151
+ {
152
+ Object three = to_ruby(3).call("to_s");
153
+ ASSERT_EQUAL(String("3"), three);
154
+ }
155
+
156
+ TESTCASE(call_return_rice_object)
157
+ {
158
+ Object three = to_ruby(1).call("+", 2);
159
+ ASSERT_EQUAL(to_ruby(3), three);
160
+ }
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/String.hpp"
3
4
  #include "rice/global_function.hpp"
4
5
 
@@ -8,7 +9,7 @@ TESTSUITE(String);
8
9
 
9
10
  SETUP(String)
10
11
  {
11
- ruby_init();
12
+ embed_ruby();
12
13
  }
13
14
 
14
15
  TESTCASE(default_construct)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Struct.hpp"
3
4
  #include "rice/Symbol.hpp"
4
5
  #include "rice/global_function.hpp"
@@ -22,7 +23,7 @@ namespace
22
23
 
23
24
  SETUP(Struct)
24
25
  {
25
- ruby_init();
26
+ embed_ruby();
26
27
  }
27
28
 
28
29
  TESTCASE(default_construct)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/Symbol.hpp"
3
4
  #include "rice/Identifier.hpp"
4
5
 
@@ -8,7 +9,7 @@ TESTSUITE(Symbol);
8
9
 
9
10
  SETUP(Symbol)
10
11
  {
11
- ruby_init();
12
+ embed_ruby();
12
13
  }
13
14
 
14
15
  TESTCASE(construct_from_symbol)
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/to_from_ruby.hpp"
3
4
  #include "rice/String.hpp"
4
5
  #include "rice/Array.hpp"
@@ -12,7 +13,7 @@ TESTSUITE(To_From_Ruby);
12
13
 
13
14
  SETUP(To_From_Ruby)
14
15
  {
15
- ruby_init();
16
+ embed_ruby();
16
17
  }
17
18
 
18
19
  TESTCASE(object_to_ruby)
@@ -27,6 +28,32 @@ TESTCASE(object_from_ruby)
27
28
  ASSERT_EQUAL(o.value(), from_ruby<Object>(o).value());
28
29
  }
29
30
 
31
+ TESTCASE(short_to_ruby)
32
+ {
33
+ ASSERT_EQUAL(INT2NUM(0), to_ruby((short)0).value());
34
+ ASSERT_EQUAL(INT2NUM(-1), to_ruby((short)-1).value());
35
+ ASSERT_EQUAL(INT2NUM(1), to_ruby((short)1).value());
36
+ ASSERT_EQUAL(
37
+ Object(INT2NUM(std::numeric_limits<short>::min())),
38
+ to_ruby(std::numeric_limits<short>::min()));
39
+ ASSERT_EQUAL(
40
+ Object(INT2NUM(std::numeric_limits<short>::max())),
41
+ to_ruby(std::numeric_limits<short>::max()));
42
+ }
43
+
44
+ TESTCASE(short_from_ruby)
45
+ {
46
+ ASSERT_EQUAL(0, from_ruby<short>(INT2NUM(0)));
47
+ ASSERT_EQUAL(-1, from_ruby<short>(INT2NUM(-1)));
48
+ ASSERT_EQUAL(1, from_ruby<short>(INT2NUM(1)));
49
+ ASSERT_EQUAL(
50
+ std::numeric_limits<short>::min(),
51
+ from_ruby<short>(INT2NUM(std::numeric_limits<short>::min())));
52
+ ASSERT_EQUAL(
53
+ std::numeric_limits<short>::max(),
54
+ from_ruby<short>(INT2NUM(std::numeric_limits<short>::max())));
55
+ }
56
+
30
57
  TESTCASE(int_to_ruby)
31
58
  {
32
59
  ASSERT_EQUAL(INT2NUM(0), to_ruby((int)0).value());
@@ -91,6 +118,56 @@ TESTCASE(long_from_ruby)
91
118
  from_ruby<long>(LONG2NUM(std::numeric_limits<long>::max())));
92
119
  }
93
120
 
121
+ TESTCASE(long_long_to_ruby)
122
+ {
123
+ ASSERT_EQUAL(LL2NUM(0), to_ruby((long long)0).value());
124
+ ASSERT_EQUAL(LL2NUM(-1), to_ruby((long long)-1).value());
125
+ ASSERT_EQUAL(LL2NUM(1), to_ruby((long long)1).value());
126
+ ASSERT_EQUAL(
127
+ Object(LL2NUM(std::numeric_limits<long long>::min())),
128
+ to_ruby(std::numeric_limits<long long>::min()));
129
+ ASSERT_EQUAL(
130
+ Object(LL2NUM(std::numeric_limits<long long>::max())),
131
+ to_ruby(std::numeric_limits<long long>::max()));
132
+ }
133
+
134
+ TESTCASE(long_long_from_ruby)
135
+ {
136
+ ASSERT_EQUAL(0, from_ruby<long long>(LL2NUM(0)));
137
+ ASSERT_EQUAL(-1, from_ruby<long long>(LL2NUM(-1)));
138
+ ASSERT_EQUAL(1, from_ruby<long long>(LL2NUM(1)));
139
+ ASSERT_EQUAL(
140
+ std::numeric_limits<long long>::min(),
141
+ from_ruby<long long>(LL2NUM(std::numeric_limits<long long>::min())));
142
+ ASSERT_EQUAL(
143
+ std::numeric_limits<long long>::max(),
144
+ from_ruby<long long>(LL2NUM(std::numeric_limits<long long>::max())));
145
+ }
146
+
147
+ TESTCASE(unsigned_short_to_ruby)
148
+ {
149
+ ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned short)0).value());
150
+ ASSERT_EQUAL(UINT2NUM(1), to_ruby((unsigned short)1).value());
151
+ ASSERT_EQUAL(
152
+ Object(UINT2NUM(std::numeric_limits<unsigned short>::min())),
153
+ to_ruby(std::numeric_limits<unsigned short>::min()));
154
+ ASSERT_EQUAL(
155
+ Object(UINT2NUM(std::numeric_limits<unsigned short>::max())),
156
+ to_ruby(std::numeric_limits<unsigned short>::max()));
157
+ }
158
+
159
+ TESTCASE(unsigned_short_from_ruby)
160
+ {
161
+ ASSERT_EQUAL(0u, from_ruby<unsigned short>(UINT2NUM(0)));
162
+ ASSERT_EQUAL(1u, from_ruby<unsigned short>(UINT2NUM(1)));
163
+ ASSERT_EQUAL(
164
+ std::numeric_limits<unsigned short>::min(),
165
+ from_ruby<unsigned short>(UINT2NUM(std::numeric_limits<unsigned short>::min())));
166
+ ASSERT_EQUAL(
167
+ std::numeric_limits<unsigned short>::max(),
168
+ from_ruby<unsigned short>(UINT2NUM(std::numeric_limits<unsigned short>::max())));
169
+ }
170
+
94
171
  TESTCASE(unsigned_int_to_ruby)
95
172
  {
96
173
  ASSERT_EQUAL(UINT2NUM(0), to_ruby((unsigned int)0).value());
@@ -145,6 +222,30 @@ TESTCASE(unsigned_long_from_ruby)
145
222
  from_ruby<unsigned long>(ULONG2NUM(std::numeric_limits<unsigned long>::max())));
146
223
  }
147
224
 
225
+ TESTCASE(unsigned_long_long_to_ruby)
226
+ {
227
+ ASSERT_EQUAL(ULL2NUM(0), to_ruby((unsigned long long)0).value());
228
+ ASSERT_EQUAL(ULL2NUM(1), to_ruby((unsigned long long)1).value());
229
+ ASSERT_EQUAL(
230
+ Object(ULL2NUM(std::numeric_limits<unsigned long long>::min())),
231
+ to_ruby(std::numeric_limits<unsigned long long>::min()));
232
+ ASSERT_EQUAL(
233
+ Object(ULL2NUM(std::numeric_limits<unsigned long long>::max())),
234
+ to_ruby(std::numeric_limits<unsigned long long>::max()));
235
+ }
236
+
237
+ TESTCASE(unsigned_long_long_from_ruby)
238
+ {
239
+ ASSERT_EQUAL(0u, from_ruby<unsigned long>(ULL2NUM(0)));
240
+ ASSERT_EQUAL(1u, from_ruby<unsigned long>(ULL2NUM(1)));
241
+ ASSERT_EQUAL(
242
+ std::numeric_limits<unsigned long long>::min(),
243
+ from_ruby<unsigned long long>(ULL2NUM(std::numeric_limits<unsigned long long>::min())));
244
+ ASSERT_EQUAL(
245
+ std::numeric_limits<unsigned long long>::max(),
246
+ from_ruby<unsigned long long>(ULL2NUM(std::numeric_limits<unsigned long long>::max())));
247
+ }
248
+
148
249
  TESTCASE(bool_to_ruby)
149
250
  {
150
251
  ASSERT_EQUAL(Qfalse, to_ruby(false).value());
@@ -1,4 +1,5 @@
1
1
  #include "unittest.hpp"
2
+ #include "embed_ruby.hpp"
2
3
  #include "rice/global_function.hpp"
3
4
 
4
5
  using namespace Rice;
@@ -7,7 +8,7 @@ TESTSUITE(GlobalFunction);
7
8
 
8
9
  SETUP(GlobalFunction)
9
10
  {
10
- ruby_init();
11
+ embed_ruby();
11
12
  }
12
13
 
13
14
  namespace {
@@ -26,6 +26,10 @@ class RiceTest < Minitest::Test
26
26
  run_external_test("#{RUBY} test_multiple_extensions_same_class.rb")
27
27
  end
28
28
 
29
+ def test_callbacks_sample
30
+ run_external_test("#{RUBY} test_callbacks_sample.rb")
31
+ end
32
+
29
33
  def run_external_test(executable)
30
34
  if VERBOSE then
31
35
  system(executable)
@@ -1,3 +1,4 @@
1
+ #include <algorithm>
1
2
  #include <iostream>
2
3
  #include <map>
3
4
  #include "unittest.hpp"
@@ -85,18 +86,43 @@ run(Test_Result & result)
85
86
  }
86
87
  }
87
88
 
88
- int main()
89
+ char* findOption(char** begin, char** end, const std::string& option)
89
90
  {
91
+ char** itr = std::find(begin, end, option);
92
+ if (itr != end && ++itr != end)
93
+ {
94
+ return *itr;
95
+ }
96
+ return nullptr;
97
+ }
98
+
99
+ int main(int argc, char** argv)
100
+ {
101
+ std::vector<Test_Suite> suites;
102
+
103
+ char* moduleName = findOption(argv, argv + argc, "--suite");
104
+ if (moduleName)
105
+ {
106
+ Test_Suite suite = test_suites()[moduleName];
107
+ suites.push_back(suite);
108
+ }
109
+ else
110
+ {
111
+ std::transform(test_suites().begin(), test_suites().end(),
112
+ std::back_inserter(suites),
113
+ [](auto& pair)
114
+ {
115
+ return pair.second;
116
+ });
117
+ }
118
+
90
119
  Test_Result result;
91
120
  size_t num_tests = 0;
92
-
93
- for(Test_Suites::iterator it = test_suites().begin(),
94
- end = test_suites().end();
95
- it != end;
96
- ++it)
121
+
122
+ for (Test_Suite& suite : suites)
97
123
  {
98
- it->second.run(result);
99
- num_tests += it->second.size();
124
+ suite.run(result);
125
+ num_tests += suite.size();
100
126
  }
101
127
 
102
128
  std::cout << std::endl;
@@ -131,6 +157,6 @@ int main()
131
157
  }
132
158
  }
133
159
 
134
- return result.errors().size() + result.failures().size();
160
+ return (int)result.errors().size() + (int)result.failures().size();
135
161
  }
136
162