rice 4.3.3 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -26
  3. data/README.md +7 -2
  4. data/Rakefile +7 -1
  5. data/include/rice/rice.hpp +7291 -4430
  6. data/include/rice/stl.hpp +769 -222
  7. data/lib/mkmf-rice.rb +37 -95
  8. data/rice/Address_Registration_Guard.hpp +72 -3
  9. data/rice/Arg.hpp +19 -5
  10. data/rice/Arg.ipp +24 -0
  11. data/rice/Callback.hpp +21 -0
  12. data/rice/Callback.ipp +13 -0
  13. data/rice/Constructor.hpp +4 -27
  14. data/rice/Constructor.ipp +79 -0
  15. data/rice/Data_Object.hpp +74 -3
  16. data/rice/Data_Object.ipp +324 -32
  17. data/rice/Data_Type.hpp +215 -3
  18. data/rice/Data_Type.ipp +125 -64
  19. data/rice/Director.hpp +0 -2
  20. data/rice/Enum.hpp +4 -6
  21. data/rice/Enum.ipp +101 -57
  22. data/rice/Exception.hpp +62 -2
  23. data/rice/Exception.ipp +7 -12
  24. data/rice/JumpException.hpp +44 -0
  25. data/rice/JumpException.ipp +48 -0
  26. data/rice/MemoryView.hpp +11 -0
  27. data/rice/MemoryView.ipp +43 -0
  28. data/rice/Return.hpp +6 -26
  29. data/rice/Return.ipp +10 -16
  30. data/rice/detail/DefaultHandler.hpp +12 -0
  31. data/rice/detail/DefaultHandler.ipp +8 -0
  32. data/rice/detail/HandlerRegistry.hpp +5 -35
  33. data/rice/detail/HandlerRegistry.ipp +7 -11
  34. data/rice/detail/InstanceRegistry.hpp +1 -4
  35. data/rice/detail/MethodInfo.hpp +15 -5
  36. data/rice/detail/MethodInfo.ipp +78 -6
  37. data/rice/detail/Native.hpp +32 -0
  38. data/rice/detail/Native.ipp +129 -0
  39. data/rice/detail/NativeAttributeGet.hpp +51 -0
  40. data/rice/detail/NativeAttributeGet.ipp +51 -0
  41. data/rice/detail/NativeAttributeSet.hpp +43 -0
  42. data/rice/detail/NativeAttributeSet.ipp +82 -0
  43. data/rice/detail/NativeCallbackFFI.hpp +55 -0
  44. data/rice/detail/NativeCallbackFFI.ipp +151 -0
  45. data/rice/detail/NativeCallbackSimple.hpp +30 -0
  46. data/rice/detail/NativeCallbackSimple.ipp +29 -0
  47. data/rice/detail/NativeFunction.hpp +20 -21
  48. data/rice/detail/NativeFunction.ipp +199 -64
  49. data/rice/detail/NativeIterator.hpp +8 -11
  50. data/rice/detail/NativeIterator.ipp +27 -31
  51. data/rice/detail/NativeRegistry.hpp +24 -15
  52. data/rice/detail/NativeRegistry.ipp +23 -48
  53. data/rice/detail/Proc.hpp +4 -0
  54. data/rice/detail/Proc.ipp +85 -0
  55. data/rice/detail/Registries.hpp +0 -7
  56. data/rice/detail/Registries.ipp +0 -18
  57. data/rice/detail/RubyFunction.hpp +0 -3
  58. data/rice/detail/RubyFunction.ipp +4 -8
  59. data/rice/detail/RubyType.hpp +19 -0
  60. data/rice/detail/RubyType.ipp +187 -0
  61. data/rice/detail/TupleIterator.hpp +14 -0
  62. data/rice/detail/Type.hpp +5 -6
  63. data/rice/detail/Type.ipp +150 -33
  64. data/rice/detail/TypeRegistry.hpp +15 -7
  65. data/rice/detail/TypeRegistry.ipp +105 -12
  66. data/rice/detail/Wrapper.hpp +6 -5
  67. data/rice/detail/Wrapper.ipp +45 -23
  68. data/rice/detail/cpp_protect.hpp +5 -6
  69. data/rice/detail/default_allocation_func.ipp +0 -2
  70. data/rice/detail/from_ruby.hpp +37 -3
  71. data/rice/detail/from_ruby.ipp +911 -454
  72. data/rice/detail/ruby.hpp +18 -0
  73. data/rice/detail/to_ruby.hpp +41 -3
  74. data/rice/detail/to_ruby.ipp +437 -113
  75. data/rice/global_function.hpp +0 -4
  76. data/rice/global_function.ipp +1 -2
  77. data/rice/rice.hpp +105 -22
  78. data/rice/ruby_mark.hpp +4 -3
  79. data/rice/stl.hpp +4 -0
  80. data/test/embed_ruby.cpp +4 -1
  81. data/test/extconf.rb +2 -0
  82. data/test/ruby/test_multiple_extensions_same_class.rb +14 -14
  83. data/test/test_Address_Registration_Guard.cpp +5 -0
  84. data/test/test_Array.cpp +12 -1
  85. data/test/test_Attribute.cpp +103 -21
  86. data/test/test_Builtin_Object.cpp +5 -0
  87. data/test/test_Callback.cpp +231 -0
  88. data/test/test_Class.cpp +5 -31
  89. data/test/test_Constructor.cpp +69 -6
  90. data/test/test_Data_Object.cpp +9 -4
  91. data/test/test_Data_Type.cpp +428 -64
  92. data/test/test_Director.cpp +10 -5
  93. data/test/test_Enum.cpp +152 -40
  94. data/test/test_Exception.cpp +235 -0
  95. data/test/test_File.cpp +70 -0
  96. data/test/test_From_Ruby.cpp +542 -0
  97. data/test/test_Hash.cpp +5 -0
  98. data/test/test_Identifier.cpp +5 -0
  99. data/test/test_Inheritance.cpp +6 -1
  100. data/test/test_Iterator.cpp +5 -0
  101. data/test/test_JumpException.cpp +22 -0
  102. data/test/test_Keep_Alive.cpp +6 -1
  103. data/test/test_Keep_Alive_No_Wrapper.cpp +5 -0
  104. data/test/test_Memory_Management.cpp +5 -0
  105. data/test/test_Module.cpp +118 -64
  106. data/test/test_Native_Registry.cpp +2 -33
  107. data/test/test_Object.cpp +5 -0
  108. data/test/test_Overloads.cpp +631 -0
  109. data/test/test_Ownership.cpp +67 -4
  110. data/test/test_Proc.cpp +45 -0
  111. data/test/test_Self.cpp +5 -0
  112. data/test/test_Stl_Exception.cpp +109 -0
  113. data/test/test_Stl_Map.cpp +22 -8
  114. data/test/test_Stl_Optional.cpp +5 -0
  115. data/test/test_Stl_Pair.cpp +7 -2
  116. data/test/test_Stl_Reference_Wrapper.cpp +5 -0
  117. data/test/test_Stl_SmartPointer.cpp +210 -5
  118. data/test/test_Stl_String.cpp +5 -0
  119. data/test/test_Stl_String_View.cpp +5 -0
  120. data/test/test_Stl_Type.cpp +147 -0
  121. data/test/test_Stl_Unordered_Map.cpp +18 -7
  122. data/test/test_Stl_Variant.cpp +5 -0
  123. data/test/test_Stl_Vector.cpp +130 -8
  124. data/test/test_String.cpp +5 -0
  125. data/test/test_Struct.cpp +5 -0
  126. data/test/test_Symbol.cpp +5 -0
  127. data/test/test_Template.cpp +192 -0
  128. data/test/test_To_Ruby.cpp +152 -0
  129. data/test/test_Tracking.cpp +1 -0
  130. data/test/test_Type.cpp +100 -0
  131. data/test/test_global_functions.cpp +53 -6
  132. data/test/unittest.cpp +8 -0
  133. metadata +37 -20
  134. data/lib/version.rb +0 -3
  135. data/rice/Address_Registration_Guard_defn.hpp +0 -79
  136. data/rice/Data_Object_defn.hpp +0 -84
  137. data/rice/Data_Type_defn.hpp +0 -190
  138. data/rice/Exception_defn.hpp +0 -68
  139. data/rice/HandlerRegistration.hpp +0 -15
  140. data/rice/Identifier.hpp +0 -50
  141. data/rice/Identifier.ipp +0 -29
  142. data/rice/detail/ExceptionHandler.hpp +0 -8
  143. data/rice/detail/ExceptionHandler.ipp +0 -28
  144. data/rice/detail/ExceptionHandler_defn.hpp +0 -77
  145. data/rice/detail/Jump_Tag.hpp +0 -21
  146. data/rice/detail/NativeAttribute.hpp +0 -64
  147. data/rice/detail/NativeAttribute.ipp +0 -112
  148. data/rice/detail/from_ruby_defn.hpp +0 -38
  149. data/rice/detail/to_ruby_defn.hpp +0 -48
  150. data/test/test_Jump_Tag.cpp +0 -17
  151. data/test/test_To_From_Ruby.cpp +0 -399
data/test/test_Module.cpp CHANGED
@@ -13,6 +13,11 @@ SETUP(Module)
13
13
  embed_ruby();
14
14
  }
15
15
 
16
+ TEARDOWN(Module)
17
+ {
18
+ rb_gc_start();
19
+ }
20
+
16
21
  TESTCASE(FromConstant)
17
22
  {
18
23
  Module m(rb_mEnumerable);
@@ -27,59 +32,51 @@ TESTCASE(FromName)
27
32
 
28
33
  namespace
29
34
  {
35
+ class MyClass
36
+ {
37
+ public:
38
+ MyClass() = default;
39
+ };
30
40
 
31
- class Quite_Silly_Exception
32
- : public std::exception
33
- {
34
- };
35
-
36
- void handle_silly_exception(Quite_Silly_Exception const & ex)
37
- {
38
- throw Exception(rb_eRuntimeError, "SILLY");
39
- }
40
-
41
- void throw_silly_exception(Object self)
42
- {
43
- throw Quite_Silly_Exception();
44
- }
45
-
46
- } // namespace
47
-
48
- TESTCASE(add_handler)
49
- {
50
- register_handler<Quite_Silly_Exception>(handle_silly_exception);
41
+ bool some_function()
42
+ {
43
+ return true;
44
+ }
51
45
 
52
- Module m(anonymous_module());
53
- m.define_singleton_method("foo", throw_silly_exception);
54
- Object exc = m.module_eval("begin; foo; rescue Exception; $!; end");
55
- ASSERT_EQUAL(rb_eRuntimeError, CLASS_OF(exc));
56
- Exception ex(exc);
57
- ASSERT_EQUAL(String("SILLY"), String(ex.what()));
58
- }
46
+ Object some_method(Object o)
47
+ {
48
+ return o;
49
+ }
59
50
 
60
- namespace
61
- {
51
+ int function_int(int i)
52
+ {
53
+ return i;
54
+ }
62
55
 
63
- bool some_function()
64
- {
65
- return true;
66
- }
56
+ int method_int(Object object, int i)
57
+ {
58
+ return i;
59
+ }
67
60
 
68
- Object some_method(Object o)
69
- {
70
- return o;
71
- }
61
+ bool method_lvalue(MyClass& myClass)
62
+ {
63
+ return true;
64
+ }
72
65
 
73
- int function_int(int i)
74
- {
75
- return i;
76
- }
66
+ bool method_rvalue(MyClass&& myClass)
67
+ {
68
+ return true;
69
+ }
77
70
 
78
- int method_int(Object object, int i)
79
- {
80
- return i;
81
- }
71
+ void method_lvalue_return_void(int a, MyClass& myClass)
72
+ {
73
+ // Do nothing
74
+ }
82
75
 
76
+ void method_rvalue_return_void(int b, MyClass&& myClass)
77
+ {
78
+ // Do nothing
79
+ }
83
80
  } // namespace
84
81
 
85
82
  TESTCASE(define_method)
@@ -180,14 +177,18 @@ TESTCASE(method_int_passed_no_args)
180
177
  {
181
178
  Module m(anonymous_module());
182
179
  m.define_method("foo", method_int);
180
+
183
181
  ASSERT_EXCEPTION_CHECK(
184
182
  Exception,
185
183
  m.module_eval("o = Object.new; o.extend(self); o.foo"),
186
- ASSERT_EQUAL(
187
- Object(rb_eArgError),
188
- Object(CLASS_OF(ex.value()))
189
- )
184
+ ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
190
185
  );
186
+
187
+ ASSERT_EXCEPTION_CHECK(
188
+ Exception,
189
+ m.module_eval("o = Object.new; o.extend(self); o.foo"),
190
+ ASSERT_EQUAL("wrong number of arguments (given 0, expected 1)", ex.what())
191
+ );
191
192
  }
192
193
 
193
194
  TESTCASE(define_singleton_method_int_foo)
@@ -263,22 +264,28 @@ TESTCASE(default_arguments_still_throws_argument_error)
263
264
  m.define_function("foo", &defaults_method_one, Arg("arg1"), Arg("arg2") = 3, Arg("arg3") = true);
264
265
 
265
266
  ASSERT_EXCEPTION_CHECK(
266
- Exception,
267
- m.module_eval("o = Object.new; o.extend(self); o.foo()"),
268
- ASSERT_EQUAL(
269
- Object(rb_eArgError),
270
- Object(CLASS_OF(ex.value()))
271
- )
272
- );
267
+ Exception,
268
+ m.module_eval("o = Object.new; o.extend(self); o.foo()"),
269
+ ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
270
+ );
273
271
 
274
272
  ASSERT_EXCEPTION_CHECK(
275
- Exception,
276
- m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
277
- ASSERT_EQUAL(
278
- Object(rb_eArgError),
279
- Object(CLASS_OF(ex.value()))
280
- )
281
- );
273
+ Exception,
274
+ m.module_eval("o = Object.new; o.extend(self); o.foo()"),
275
+ ASSERT_EQUAL("wrong number of arguments (given 0, expected 1..3)", ex.what())
276
+ );
277
+
278
+ ASSERT_EXCEPTION_CHECK(
279
+ Exception,
280
+ m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
281
+ ASSERT_EQUAL(Object(rb_eArgError), Object(CLASS_OF(ex.value())))
282
+ );
283
+
284
+ ASSERT_EXCEPTION_CHECK(
285
+ Exception,
286
+ m.module_eval("o = Object.new; o.extend(self); o.foo(3, 4, false, 17)"),
287
+ ASSERT_EQUAL("wrong number of arguments (given 4, expected 1..3)", ex.what())
288
+ );
282
289
  }
283
290
 
284
291
  namespace {
@@ -515,4 +522,51 @@ TESTCASE(references)
515
522
  ASSERT_EQUAL(boolValue, true);
516
523
  ASSERT_EQUAL(floatValue, 43.0);
517
524
  ASSERT_EQUAL(doubleValue, 44.0);
518
- }
525
+ }
526
+
527
+ TESTCASE(lvalue_function)
528
+ {
529
+ Module m(anonymous_module());
530
+ Class c = define_class<MyClass>("MyClass").
531
+ define_constructor(Constructor<MyClass>());
532
+
533
+ m.define_module_function("method_lvalue", &method_lvalue);
534
+ m.define_module_function("method_lvalue_return_void", &method_lvalue_return_void);
535
+
536
+ Object result = m.module_eval(R"(o = MyClass.new
537
+ method_lvalue_return_void(1, o)
538
+ method_lvalue(o))");
539
+
540
+ ASSERT_EQUAL(Qtrue, result.value());
541
+ }
542
+
543
+ TESTCASE(rvalue_function)
544
+ {
545
+ Module m(anonymous_module());
546
+ Class c = define_class<MyClass>("MyClass").
547
+ define_constructor(Constructor<MyClass>());
548
+
549
+ m.define_module_function("method_rvalue", &method_rvalue);
550
+ m.define_module_function("method_rvalue_return_void", &method_rvalue_return_void);
551
+
552
+ Object result = m.module_eval(R"(o = MyClass.new
553
+ method_rvalue_return_void(1, o)
554
+ method_rvalue(o))");
555
+
556
+ ASSERT_EQUAL(Qtrue, result.value());
557
+ }
558
+
559
+ namespace {
560
+ namespace Constants {
561
+ #define MY_PI 314
562
+ }
563
+ }
564
+
565
+ TESTCASE(constants)
566
+ {
567
+ Module m = anonymous_module().
568
+ define_constant("MY_PI", MY_PI);
569
+
570
+ Object result = m.module_eval(R"(MY_PI)");
571
+ ASSERT_EQUAL(314, detail::From_Ruby<int>().convert(result.value()));
572
+ }
@@ -13,38 +13,7 @@ SETUP(NativeRegistry)
13
13
  embed_ruby();
14
14
  }
15
15
 
16
- TESTCASE(collisions)
16
+ TEARDOWN(NativeRegistry)
17
17
  {
18
- std::array<Class, 100> classes;
19
- int scale = 1000;
20
-
21
- for (int i = 0; i < std::size(classes); i++)
22
- {
23
- Class cls(anonymous_class());
24
-
25
- for (int j = 0; j < scale; j++)
26
- {
27
- cls.define_function("int" + std::to_string(j), []() { return 1; });
28
- cls.define_function("long" + std::to_string(j), []() { return 1L; });
29
- cls.define_function("double" + std::to_string(j), []() { return 1.0; });
30
- cls.define_function("float" + std::to_string(j), []() { return 1.0f; });
31
- cls.define_function("bool" + std::to_string(j), []() { return true; });
32
- }
33
-
34
- classes[i] = cls;
35
- }
36
-
37
- for (auto& cls : classes)
38
- {
39
- auto obj = cls.call("new");
40
-
41
- for (int j = 0; j < scale; j++)
42
- {
43
- obj.call("int" + std::to_string(j));
44
- obj.call("long" + std::to_string(j));
45
- obj.call("double" + std::to_string(j));
46
- obj.call("float" + std::to_string(j));
47
- obj.call("bool" + std::to_string(j));
48
- }
49
- }
18
+ rb_gc_start();
50
19
  }
data/test/test_Object.cpp CHANGED
@@ -11,6 +11,11 @@ SETUP(Object)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Object)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  TESTCASE(default_construct)
15
20
  {
16
21
  Object o;