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
@@ -1,8 +1,6 @@
1
1
  #ifndef Rice__global_function__hpp_
2
2
  #define Rice__global_function__hpp_
3
3
 
4
- #include "Arg.hpp"
5
-
6
4
  namespace Rice
7
5
  {
8
6
  //! Define an global function
@@ -20,6 +18,4 @@ namespace Rice
20
18
  void define_global_function(char const * name, Function_T&& func, Arg_Ts const& ...args);
21
19
  } // Rice
22
20
 
23
- #include "global_function.ipp"
24
-
25
21
  #endif // Rice__global_function__hpp_
@@ -1,7 +1,6 @@
1
- #include "cpp_api/Module.hpp"
2
1
 
3
2
  template<typename Function_T, typename...Arg_Ts>
4
3
  void Rice::define_global_function(char const * name, Function_T&& func, Arg_Ts const& ...args)
5
4
  {
6
- Module(rb_mKernel).define_module_function(name, std::forward<Function_T>(func), args...);
5
+ Module(rb_mKernel).define_module_function(name, std::forward<Function_T>(func), args...);
7
6
  }
data/rice/rice.hpp CHANGED
@@ -1,64 +1,147 @@
1
1
  #ifndef Rice__hpp_
2
2
  #define Rice__hpp_
3
3
 
4
- // Traits
4
+ // Ruby
5
5
  #include "detail/ruby.hpp"
6
+
7
+ // C++ headers -h has to come after Ruby on MacOS for reasons I do not understand
8
+ #include <cstdio>
9
+ #include <string>
10
+ #include <typeinfo>
11
+ #include <typeindex>
12
+
13
+ #ifdef _MSC_VER
14
+ // Prevent _strdup deprecated message on MSVC
15
+ #define strdup _strdup
16
+ #endif
17
+
18
+ // Traits
6
19
  #include "traits/rice_traits.hpp"
7
20
  #include "traits/function_traits.hpp"
8
21
  #include "traits/method_traits.hpp"
9
22
  #include "traits/attribute_traits.hpp"
10
23
 
24
+ // Helpers
25
+ #include "detail/TupleIterator.hpp"
26
+
11
27
  // Code for C++ to call Ruby
12
- #include "Exception_defn.hpp"
13
- #include "detail/Jump_Tag.hpp"
28
+ #include "Exception.hpp"
29
+ #include "JumpException.hpp"
30
+ #include "JumpException.ipp"
14
31
  #include "detail/RubyFunction.hpp"
32
+ #include "detail/RubyFunction.ipp"
15
33
 
16
- // Code for Ruby to call C++
17
- #include "detail/ExceptionHandler.hpp"
34
+ // C++ API declarations
18
35
  #include "detail/Type.hpp"
36
+ #include "cpp_api/Encoding.hpp"
37
+ #include "cpp_api/Identifier.hpp"
38
+ #include "cpp_api/Identifier.ipp"
39
+ #include "cpp_api/Object.hpp"
40
+ #include "cpp_api/Builtin_Object.hpp"
41
+ #include "cpp_api/String.hpp"
42
+ #include "cpp_api/Symbol.hpp"
43
+ #include "cpp_api/Array.hpp"
44
+ #include "cpp_api/Hash.hpp"
45
+
46
+ // Type Conversion declarations
47
+ #include "detail/RubyType.hpp"
48
+ #include "detail/RubyType.ipp"
49
+ #include "detail/Wrapper.hpp"
50
+ #include "detail/to_ruby.hpp"
51
+ #include "detail/from_ruby.hpp"
52
+ #include "detail/Native.hpp"
53
+
54
+ // Registries
19
55
  #include "detail/TypeRegistry.hpp"
20
56
  #include "detail/InstanceRegistry.hpp"
57
+ #include "detail/DefaultHandler.hpp"
21
58
  #include "detail/HandlerRegistry.hpp"
22
59
  #include "detail/NativeRegistry.hpp"
23
60
  #include "detail/Registries.hpp"
24
- #include "detail/cpp_protect.hpp"
25
- #include "detail/Wrapper.hpp"
26
- #include "Return.hpp"
61
+
62
+ // To / From Ruby
27
63
  #include "Arg.hpp"
28
- #include "detail/MethodInfo.hpp"
29
- #include "detail/from_ruby.hpp"
30
- #include "detail/to_ruby.hpp"
31
- #include "Identifier.hpp"
64
+ #include "Arg.ipp"
65
+ #include "Return.hpp"
66
+ #include "Return.ipp"
67
+ #include "detail/to_ruby.ipp"
68
+ #include "detail/from_ruby.ipp"
69
+ #include "detail/Proc.hpp"
70
+
71
+ // Registries
72
+ #include "detail/TypeRegistry.ipp"
73
+ #include "detail/InstanceRegistry.ipp"
74
+ #include "detail/DefaultHandler.ipp"
75
+ #include "detail/HandlerRegistry.ipp"
76
+ #include "detail/NativeRegistry.ipp"
77
+ #include "detail/Registries.ipp"
78
+
79
+ #include "detail/Type.ipp"
80
+
81
+ // Code for Ruby to call C++
32
82
  #include "Exception.ipp"
33
- #include "detail/NativeAttribute.hpp"
83
+ #include "detail/cpp_protect.hpp"
84
+ #include "detail/Wrapper.ipp"
85
+ #include "detail/MethodInfo.hpp"
86
+ #include "detail/MethodInfo.ipp"
87
+ #include "detail/Native.ipp"
88
+ #include "detail/NativeAttributeGet.hpp"
89
+ #include "detail/NativeAttributeGet.ipp"
90
+ #include "detail/NativeAttributeSet.hpp"
91
+ #include "detail/NativeAttributeSet.ipp"
34
92
  #include "detail/NativeFunction.hpp"
93
+ #include "detail/NativeFunction.ipp"
35
94
  #include "detail/NativeIterator.hpp"
36
- #include "HandlerRegistration.hpp"
95
+ #include "detail/NativeIterator.ipp"
96
+ #include "detail/NativeCallbackFFI.hpp"
97
+ #include "detail/NativeCallbackFFI.ipp"
98
+ #include "detail/NativeCallbackSimple.hpp"
99
+ #include "detail/NativeCallbackSimple.ipp"
100
+ #include "detail/Proc.ipp"
101
+
102
+ // C++ API definitions
103
+ #include "cpp_api/Encoding.ipp"
104
+ #include "cpp_api/Object.ipp"
105
+ #include "cpp_api/Builtin_Object.ipp"
106
+ #include "cpp_api/String.ipp"
107
+ #include "cpp_api/Array.ipp"
108
+ #include "cpp_api/Hash.ipp"
109
+ #include "cpp_api/Symbol.ipp"
37
110
 
38
- // C++ classes for using the Ruby API
39
- #include "cpp_api/Object.hpp"
40
- #include "cpp_api/Builtin_Object.hpp"
41
- #include "cpp_api/String.hpp"
42
- #include "cpp_api/Array.hpp"
43
- #include "cpp_api/Hash.hpp"
44
- #include "cpp_api/Symbol.hpp"
45
111
  #include "cpp_api/Module.hpp"
112
+ #include "cpp_api/Module.ipp"
46
113
  #include "cpp_api/Class.hpp"
114
+ #include "cpp_api/Class.ipp"
47
115
  #include "cpp_api/Struct.hpp"
116
+ #include "cpp_api/Struct.ipp"
117
+
48
118
  #include "Address_Registration_Guard.hpp"
119
+ #include "Address_Registration_Guard.ipp"
49
120
  #include "global_function.hpp"
121
+ #include "global_function.ipp"
50
122
 
51
- // Code involed in creating custom DataTypes (ie, Ruby classes that wrap C++ classes)
123
+ // Code involved in creating custom DataTypes (ie, Ruby classes that wrap C++ classes)
52
124
  #include "ruby_mark.hpp"
53
125
  #include "detail/default_allocation_func.hpp"
54
126
  #include "Director.hpp"
55
127
  #include "Data_Type.hpp"
128
+ #include "Data_Type.ipp"
56
129
  #include "detail/default_allocation_func.ipp"
57
130
  #include "Constructor.hpp"
131
+ #include "Constructor.ipp"
132
+ #include "Callback.hpp"
133
+ #include "Callback.ipp"
58
134
  #include "Data_Object.hpp"
135
+ #include "Data_Object.ipp"
59
136
  #include "Enum.hpp"
137
+ #include "Enum.ipp"
138
+ #include "MemoryView.hpp"
139
+ #include "MemoryView.ipp"
60
140
 
61
141
  // Dependent on Module, Class, Array and String
62
142
  #include "forward_declares.ipp"
63
143
 
144
+ // For now include libc support - maybe should be separate header file someday
145
+ #include "libc/file.hpp"
146
+
64
147
  #endif // Rice__hpp_
data/rice/ruby_mark.hpp CHANGED
@@ -1,5 +1,5 @@
1
- #ifndef ruby_mark__hpp
2
- #define ruby_mark__hpp
1
+ #ifndef Rice__ruby_mark__hpp_
2
+ #define Rice__ruby_mark__hpp_
3
3
 
4
4
  //! Default function to call to mark a data object.
5
5
  /*! This function can be specialized for a particular type to override
@@ -12,4 +12,5 @@ namespace Rice
12
12
  {
13
13
  }
14
14
  }
15
- #endif // ruby_mark__hpp
15
+ #endif // Rice__ruby_mark__hpp_
16
+
data/rice/stl.hpp CHANGED
@@ -1,6 +1,8 @@
1
1
  #ifndef Rice__stl__hpp_
2
2
  #define Rice__stl__hpp_
3
3
 
4
+ #include "stl/exception.hpp"
5
+ #include "stl/exception_ptr.hpp"
4
6
  #include "stl/string.hpp"
5
7
  #include "stl/string_view.hpp"
6
8
  #include "stl/complex.hpp"
@@ -8,6 +10,8 @@
8
10
  #include "stl/reference_wrapper.hpp"
9
11
  #include "stl/smart_ptr.hpp"
10
12
  #include "stl/monostate.hpp"
13
+ #include "stl/type_index.hpp"
14
+ #include "stl/type_info.hpp"
11
15
  #include "stl/variant.hpp"
12
16
  #include "stl/pair.hpp"
13
17
  #include "stl/map.hpp"
data/test/embed_ruby.cpp CHANGED
@@ -7,15 +7,18 @@ void embed_ruby()
7
7
 
8
8
  if (!initialized__)
9
9
  {
10
+ RUBY_INIT_STACK;
11
+
10
12
  int argc = 0;
11
13
  char* argv = nullptr;
12
14
  char** pArgv = &argv;
13
15
 
14
16
  ruby_sysinit(&argc, &pArgv);
17
+
15
18
  ruby_init();
16
19
  ruby_init_loadpath();
17
20
 
18
- #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 3
21
+ #if RUBY_API_VERSION_MAJOR == 3 && RUBY_API_VERSION_MINOR >= 1
19
22
  // Force the prelude / builtins
20
23
  const char* opts[] = { "ruby", "-e;" };
21
24
  ruby_options(2, (char**)opts);
data/test/extconf.rb CHANGED
@@ -2,6 +2,8 @@ require 'bundler/setup'
2
2
  require 'mkmf-rice'
3
3
  require 'rbconfig'
4
4
 
5
+ abort "libffi not found" unless have_libffi
6
+
5
7
  # Totally hack mkmf to make a unittest executable instead of a shared library
6
8
  target_exe = "unittest#{RbConfig::CONFIG['EXEEXT']}"
7
9
  $cleanfiles << target_exe
@@ -1,14 +1,14 @@
1
- $: << File.join(__dir__, '..', 'ext')
2
-
3
- require 'minitest'
4
- require 'minitest/autorun'
5
-
6
- class MultipleExtensionsSameClassTest < Minitest::Test
7
- def test_multiple_extensions_same_class
8
- require 't1/t1'
9
- require 't2/t2'
10
-
11
- foo = Foo.new
12
- assert_equal 42, foo.foo
13
- end
14
- end
1
+ $: << File.join(__dir__, '..', 'ext')
2
+
3
+ require 'minitest'
4
+ require 'minitest/autorun'
5
+
6
+ class MultipleExtensionsSameClassTest < Minitest::Test
7
+ def test_multiple_extensions_same_class
8
+ require 't1/t1'
9
+ require 't2/t2'
10
+
11
+ foo = Foo.new
12
+ assert_equal 42, foo.foo
13
+ end
14
+ end
@@ -11,6 +11,11 @@ SETUP(Address_Registration_Guard)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Address_Registration_Guard)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  TESTCASE(register_address)
15
20
  {
16
21
  VALUE v = Qnil;
data/test/test_Array.cpp CHANGED
@@ -24,13 +24,24 @@ SETUP(Array)
24
24
  embed_ruby();
25
25
  }
26
26
 
27
- TESTCASE(default_construct)
27
+ TEARDOWN(Array)
28
+ {
29
+ rb_gc_start();
30
+ }
31
+
32
+ TESTCASE(construct_default)
28
33
  {
29
34
  Array a;
30
35
  ASSERT_EQUAL(T_ARRAY, rb_type(a));
31
36
  ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
32
37
  }
33
38
 
39
+ TESTCASE(construct_capacity)
40
+ {
41
+ Array a((long)10);
42
+ ASSERT_EQUAL(0, RARRAY_LEN(a.value()));
43
+ }
44
+
34
45
  TESTCASE(construct_from_vector_of_int)
35
46
  {
36
47
  std::vector<int> v;
@@ -14,12 +14,23 @@ SETUP(Attribute)
14
14
  embed_ruby();
15
15
  }
16
16
 
17
+ TEARDOWN(Attribute)
18
+ {
19
+ Rice::detail::Registries::instance.types.clearUnverifiedTypes();
20
+ rb_gc_start();
21
+ }
22
+
17
23
  namespace
18
24
  {
19
25
  class SomeClass
20
26
  {
21
27
  };
22
28
 
29
+ class NotAssignable
30
+ {
31
+ NotAssignable& operator=(const NotAssignable&) = delete;
32
+ };
33
+
23
34
  struct DataStruct
24
35
  {
25
36
  static inline float staticFloat = 1.0;
@@ -29,7 +40,9 @@ namespace
29
40
  std::string readWriteString = "Read Write";
30
41
  int writeInt = 0;
31
42
  const char* readChars = "Read some chars!";
43
+ const int constInt = 5;
32
44
  SomeClass someClass;
45
+ NotAssignable notAssignable;
33
46
 
34
47
  std::string inspect()
35
48
  {
@@ -57,21 +70,28 @@ TESTCASE(attributes)
57
70
  // Test readonly attribute
58
71
  Object result = o.call("read_chars");
59
72
  ASSERT_EQUAL("Read some chars!", detail::From_Ruby<char*>().convert(result));
60
- ASSERT_EXCEPTION_CHECK(
61
- Exception,
62
- o.call("read_char=", "some text"),
63
- ASSERT(std::string(ex.what()).find("undefined method `read_char='") == 0)
64
- );
65
73
 
74
+ if constexpr (!oldRuby)
75
+ {
76
+ ASSERT_EXCEPTION_CHECK(
77
+ Exception,
78
+ o.call("read_char=", "some text"),
79
+ ASSERT(std::string(ex.what()).find("undefined method `read_char='") == 0)
80
+ );
81
+ }
66
82
  // Test writeonly attribute
67
83
  result = o.call("write_int=", 5);
68
84
  ASSERT_EQUAL(5, detail::From_Ruby<int>().convert(result.value()));
69
85
  ASSERT_EQUAL(5, dataStruct->writeInt);
70
- ASSERT_EXCEPTION_CHECK(
71
- Exception,
72
- o.call("write_int", 3),
73
- ASSERT(std::string(ex.what()).find("undefined method `write_int'") == 0)
74
- );
86
+
87
+ if constexpr (!oldRuby)
88
+ {
89
+ ASSERT_EXCEPTION_CHECK(
90
+ Exception,
91
+ o.call("write_int", 3),
92
+ ASSERT(std::string(ex.what()).find("undefined method `write_int'") == 0)
93
+ );
94
+ }
75
95
 
76
96
  // Test readwrite attribute
77
97
  result = o.call("read_write_string=", "Set a string");
@@ -82,6 +102,48 @@ TESTCASE(attributes)
82
102
  ASSERT_EQUAL("Set a string", detail::From_Ruby<std::string>().convert(result.value()));
83
103
  }
84
104
 
105
+ TESTCASE(const_attribute)
106
+ {
107
+ Class c = define_class<DataStruct>("DataStruct")
108
+ .define_constructor(Constructor<DataStruct>())
109
+ .define_attr("const_int", &DataStruct::constInt);
110
+
111
+ Data_Object<DataStruct> o = c.call("new");
112
+ const DataStruct* dataStruct = o.get();
113
+
114
+ if constexpr (!oldRuby)
115
+ {
116
+ ASSERT_EXCEPTION_CHECK(
117
+ Exception,
118
+ o.call("const_int=", 5),
119
+ ASSERT(std::string(ex.what()).find("undefined method `const_int='") == 0)
120
+ );
121
+ }
122
+ }
123
+
124
+ TESTCASE(not_copyable_attribute)
125
+ {
126
+ Class notAssignableClass = define_class<NotAssignable>("NotAssignable")
127
+ .define_constructor(Constructor<NotAssignable>());
128
+
129
+ Class c = define_class<DataStruct>("DataStruct")
130
+ .define_constructor(Constructor<DataStruct>())
131
+ .define_attr("not_assignable", &DataStruct::notAssignable);
132
+
133
+ Data_Object<NotAssignable> notAssignable = notAssignableClass.call("new");
134
+
135
+ Data_Object<DataStruct> o = c.call("new");
136
+
137
+ if constexpr (!oldRuby)
138
+ {
139
+ ASSERT_EXCEPTION_CHECK(
140
+ Exception,
141
+ o.call("not_assignable=", notAssignable),
142
+ ASSERT(std::string(ex.what()).find("undefined method `not_assignable='") == 0)
143
+ );
144
+ }
145
+ }
146
+
85
147
  TESTCASE(static_attributes)
86
148
  {
87
149
  Class c = define_class<DataStruct>("DataStruct")
@@ -98,11 +160,15 @@ TESTCASE(static_attributes)
98
160
 
99
161
  result = c.call("static_string");
100
162
  ASSERT_EQUAL("Static string", detail::From_Ruby<std::string>().convert(result.value()));
101
- ASSERT_EXCEPTION_CHECK(
102
- Exception,
103
- c.call("static_string=", true),
104
- ASSERT(std::string(ex.what()).find("undefined method `static_string='") == 0)
105
- );
163
+
164
+ if constexpr (!oldRuby)
165
+ {
166
+ ASSERT_EXCEPTION_CHECK(
167
+ Exception,
168
+ c.call("static_string=", true),
169
+ ASSERT(std::string(ex.what()).find("undefined method `static_string='") == 0)
170
+ );
171
+ }
106
172
  }
107
173
 
108
174
  TESTCASE(global_attributes)
@@ -128,20 +194,36 @@ TESTCASE(not_defined)
128
194
  Data_Type<DataStruct> c = define_class<DataStruct>("DataStruct");
129
195
 
130
196
  #ifdef _MSC_VER
131
- const char* message = "Type is not defined with Rice: class `anonymous namespace'::SomeClass";
197
+ const char* message = "The following types are not registered with Rice:\n class `anonymous namespace'::SomeClass\n";
132
198
  #else
133
- const char* message = "Type is not defined with Rice: (anonymous namespace)::SomeClass";
199
+ const char* message = "The following types are not registered with Rice:\n (anonymous namespace)::SomeClass\n";
134
200
  #endif
135
201
 
202
+ c.define_singleton_attr("some_class_static", &DataStruct::someClassStatic);
203
+
136
204
  ASSERT_EXCEPTION_CHECK(
137
205
  std::invalid_argument,
138
- c.define_singleton_attr("some_class_static", &DataStruct::someClassStatic),
206
+ Rice::detail::Registries::instance.types.validateTypes(),
139
207
  ASSERT_EQUAL(message, ex.what())
140
208
  );
141
209
 
210
+ #ifdef _MSC_VER
211
+ message = "Type is not registered with Rice: class `anonymous namespace'::SomeClass";
212
+ #else
213
+ message = "Type is not registered with Rice: (anonymous namespace)::SomeClass";
214
+ #endif
215
+
142
216
  ASSERT_EXCEPTION_CHECK(
143
- std::invalid_argument,
144
- c.define_attr("some_class", &DataStruct::someClass),
217
+ Rice::Exception,
218
+ c.call("some_class_static"),
145
219
  ASSERT_EQUAL(message, ex.what())
146
220
  );
147
- }
221
+
222
+ c.define_attr("some_class", &DataStruct::someClass);
223
+ Object o = c.call("new");
224
+ ASSERT_EXCEPTION_CHECK(
225
+ Rice::Exception,
226
+ o.call("some_class"),
227
+ ASSERT_EQUAL(message, ex.what())
228
+ );
229
+ }
@@ -11,6 +11,11 @@ SETUP(Builtin_Object)
11
11
  embed_ruby();
12
12
  }
13
13
 
14
+ TEARDOWN(Builtin_Object)
15
+ {
16
+ rb_gc_start();
17
+ }
18
+
14
19
  TESTCASE(construct_with_object)
15
20
  {
16
21
  Class c(rb_cObject);