rice 4.9.1 → 4.10.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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -0
  3. data/FindRuby.cmake +21 -45
  4. data/include/rice/rice.hpp +1153 -994
  5. data/include/rice/stl.hpp +524 -71
  6. data/lib/rice/version.rb +1 -1
  7. data/rice/Arg.hpp +1 -7
  8. data/rice/Arg.ipp +0 -12
  9. data/rice/Buffer.hpp +27 -2
  10. data/rice/Buffer.ipp +111 -49
  11. data/rice/Data_Object.ipp +9 -16
  12. data/rice/Data_Type.hpp +7 -28
  13. data/rice/Data_Type.ipp +53 -67
  14. data/rice/Pin.hpp +40 -0
  15. data/rice/Pin.ipp +12 -0
  16. data/rice/Pointer.ipp +2 -2
  17. data/rice/Reference.ipp +2 -2
  18. data/rice/cpp_api/Module.hpp +1 -1
  19. data/rice/cpp_api/Module.ipp +1 -1
  20. data/rice/cpp_api/Object.hpp +6 -8
  21. data/rice/cpp_api/Object.ipp +29 -4
  22. data/rice/detail/Anchor.hpp +58 -0
  23. data/rice/detail/Anchor.ipp +49 -0
  24. data/rice/detail/Native.ipp +8 -5
  25. data/rice/detail/NativeAttributeGet.hpp +8 -4
  26. data/rice/detail/NativeAttributeGet.ipp +4 -4
  27. data/rice/detail/NativeAttributeSet.ipp +2 -2
  28. data/rice/detail/NativeCallback.hpp +6 -3
  29. data/rice/detail/NativeCallback.ipp +5 -19
  30. data/rice/detail/NativeFunction.ipp +6 -6
  31. data/rice/detail/NativeIterator.ipp +10 -5
  32. data/rice/detail/NativeMethod.ipp +9 -9
  33. data/rice/detail/NativeProc.ipp +4 -4
  34. data/rice/detail/Parameter.ipp +59 -28
  35. data/rice/detail/Proc.ipp +1 -1
  36. data/rice/detail/Type.hpp +5 -37
  37. data/rice/detail/Type.ipp +14 -317
  38. data/rice/detail/TypeIndexParser.hpp +52 -0
  39. data/rice/detail/TypeIndexParser.ipp +368 -0
  40. data/rice/detail/TypeRegistry.hpp +4 -1
  41. data/rice/detail/TypeRegistry.ipp +35 -25
  42. data/rice/detail/Wrapper.ipp +27 -8
  43. data/rice/detail/from_ruby.ipp +20 -8
  44. data/rice/detail/ruby.hpp +1 -17
  45. data/rice/detail/to_ruby.ipp +8 -6
  46. data/rice/forward_declares.ipp +1 -1
  47. data/rice/rice.hpp +12 -9
  48. data/rice/stl/function.hpp +12 -0
  49. data/rice/stl/function.ipp +96 -0
  50. data/rice/stl/ios_base.hpp +13 -0
  51. data/rice/stl/ios_base.ipp +38 -0
  52. data/rice/stl/map.ipp +2 -2
  53. data/rice/stl/multimap.ipp +4 -4
  54. data/rice/stl/optional.ipp +2 -2
  55. data/rice/stl/ostream.hpp +13 -0
  56. data/rice/stl/ostream.ipp +200 -0
  57. data/rice/stl/pair.ipp +2 -2
  58. data/rice/stl/reference_wrapper.ipp +2 -2
  59. data/rice/stl/set.ipp +79 -10
  60. data/rice/stl/shared_ptr.ipp +16 -10
  61. data/rice/stl/unique_ptr.ipp +14 -8
  62. data/rice/stl/unordered_map.ipp +2 -2
  63. data/rice/stl/vector.ipp +2 -2
  64. data/rice/stl.hpp +4 -1
  65. data/rice/traits/function_traits.hpp +15 -2
  66. data/rice/traits/rice_traits.hpp +21 -0
  67. data/test/embed_ruby.cpp +9 -5
  68. data/test/extconf.rb +3 -0
  69. data/test/test_Attribute.cpp +85 -63
  70. data/test/test_Buffer.cpp +103 -0
  71. data/test/test_Callback.cpp +11 -6
  72. data/test/test_Data_Type.cpp +147 -6
  73. data/test/test_Incomplete.cpp +739 -0
  74. data/test/test_Iterator.cpp +193 -38
  75. data/test/test_Overloads.cpp +142 -35
  76. data/test/test_Pin.cpp +79 -0
  77. data/test/test_Proc.cpp +8 -6
  78. data/test/test_Stl_Function.cpp +261 -0
  79. data/test/test_Stl_Map.cpp +2 -3
  80. data/test/test_Stl_Multimap.cpp +2 -3
  81. data/test/test_Stl_OStream.cpp +333 -0
  82. data/test/test_Stl_SharedPtr.cpp +60 -6
  83. data/test/test_Stl_UniquePtr.cpp +2 -2
  84. data/test/test_Stl_Variant.cpp +2 -2
  85. data/test/test_Template.cpp +19 -23
  86. data/test/test_Type.cpp +204 -128
  87. data/test/test_global_functions.cpp +17 -1
  88. data/test/unittest.hpp +29 -2
  89. metadata +18 -7
  90. data/rice/Address_Registration_Guard.hpp +0 -76
  91. data/rice/Address_Registration_Guard.ipp +0 -80
  92. data/rice/detail/Forwards.hpp +0 -18
  93. data/rice/detail/Forwards.ipp +0 -60
  94. data/test/test_Address_Registration_Guard.cpp +0 -62
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6482695048d122782acef1d7ee310c47c85cff57eb39c8740db46013a4af0e87
4
- data.tar.gz: a4b3c772ac9d5baff75ad80dbc404dde8a3fc67c821836203dfdcef948877091
3
+ metadata.gz: bfec1a3dda6cae1e2a2e4ead3b3d6d856487a6d214ec89a2aa7c32cab9debf24
4
+ data.tar.gz: 2bb3f7480a0ffcaee70ccc15ea7410c764a67b0b6d229300264570b1e58f8b59
5
5
  SHA512:
6
- metadata.gz: 553618d580f7734d23a0c0278636fe725f48cacd68572fa9d6cee828fed68b2af84cda1fecdad4bb65633ada077bf4b34a703e2bd25173bd4f3ae0de91c54c26
7
- data.tar.gz: '0368ac5a1d1d957ab8a94dcec8a25c6e5cc539930848db9f78077c6006b86a6d81299af839ab1daed52fab9ce743496cebcff6e3698483961c0fc6cc2bef82b4'
6
+ metadata.gz: a6e7edb4a1332104c7e2a0bf616919ceef92fb4d87bbca650898c1a8e705df20f54a02a78372a1a9b66b499c6d1e4a47ed75e8a2e20ebbe57cbfa0c6cd9a953d
7
+ data.tar.gz: 9ea2f5c76ccbb2d4a8e62ead7a796ad700ef77d07cf0c2fbc59b8c7626068225900009a861a654b95dd8476c80ba1e041c46b43f2969318479a28b12f7dc8678
data/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.10.0 (2026-02-07)
4
+
5
+ Enhancements:
6
+ * Ruby 4.0 support
7
+ * Support incomplete types (PIMPL/opaque handle patterns). Rice now uses `typeid(T*)` for forward-declared types that are never fully defined.
8
+ * Support `noexcept` functions, static members, and static member functions
9
+ * Support for `Buffer<void*>` and `Pointer<void*>`
10
+ * Add `std::function`. Ruby procs, lambdas, and blocks can be wrapped in `std::function` objects and passed to C++ methods. C++ functions returning `std::function` are automatically wrapped.
11
+ * Add `std::ostream`, `std::ostringstream`, and `std::ofstream`. Ruby can write to C++ streams and pass them to C++ functions. Standard streams are exposed as `Std::COUT` and `Std::CERR`.
12
+ * Support verifying arrays of non-fundamental types (e.g., `MyClass[2]`)
13
+ * Delegate method calls for smart pointers to their wrapped objects via method_missing?
14
+
15
+ Internal:
16
+ * Refactor type handling by merging `TypeMapper` into `TypeDetail` and simplifying class hierarchy
17
+ * Greatly simplify define_attr
18
+
19
+ Incompatible Changes:
20
+ * `Address_Registration_Guard` has been replaced by `Pin`. If you are using `Address_Registration_Guard`
21
+ to protect Ruby VALUEs from garbage collection, update your code to use `Pin` instead:
22
+
23
+ Before:
24
+ ```cpp
25
+ VALUE value_;
26
+ Address_Registration_Guard guard_;
27
+ MyClass() : value_(rb_str_new2("test")), guard_(&value_) {}
28
+ ```
29
+
30
+ After:
31
+ ```cpp
32
+ Pin pin_;
33
+ MyClass() : pin_(rb_str_new2("test")) {}
34
+ VALUE getValue() { return pin_.get(); }
35
+ ```
36
+
37
+ `Pin` is self-contained and provides `get()` and `set()` methods to access the pinned VALUE.
38
+
39
+ * Rice converts Ruby blocks to procs. Thus if you have a method that expects a block, you must add
40
+ a VALUE parameter and tell Rice it is a value. For example:
41
+
42
+ ```cpp
43
+ define_method("my_method", [](VALUE self, VALUE proc)
44
+ {
45
+ }, Arg("proc").setValue())
46
+ ```
47
+
48
+ Think of this as similar to how you would capture a block in Ruby using the &block syntax.
49
+
50
+ * The `Data_Type<T>::define()` method has been removed. See the [Class Templates](bindings/class_templates.md) documentation for the recommended approach.
51
+
3
52
  ## 4.9.1 (2026-01-04)
4
53
  This release focuses on improving memory management for STL containers and attribute setters.
5
54
 
data/FindRuby.cmake CHANGED
@@ -12,12 +12,14 @@ Finds Ruby installation and the locations of its include files and libraries:
12
12
  find_package(Ruby [<version>] [COMPONENTS <components>...] [...])
13
13
 
14
14
  Ruby is a general-purpose programming language. This module supports Ruby
15
- 1.8 through 3.4. Virtual environments, such as RVM or RBENV, are also
15
+ 2.0 through 4.0. Virtual environments, such as RVM or RBENV, are also
16
16
  supported.
17
17
 
18
18
  Components
19
19
  ^^^^^^^^^^
20
20
 
21
+ .. versionadded:: 4.3
22
+
21
23
  This module supports the following components:
22
24
 
23
25
  ``Interpreter``
@@ -32,6 +34,8 @@ are searched for.
32
34
  Imported Targets
33
35
  ^^^^^^^^^^^^^^^^
34
36
 
37
+ .. versionadded:: 4.3
38
+
35
39
  This module defines the following :prop_tgt:`IMPORTED` targets:
36
40
 
37
41
  ``Ruby::Interpreter``
@@ -171,14 +175,16 @@ endif()
171
175
  set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby)
172
176
 
173
177
  # If the user has not specified a Ruby version, create a list of Ruby versions
174
- # to check going from 1.8 to 4.0
178
+ # to search (newest to oldest). Based on https://www.ruby-lang.org/en/downloads/releases/
175
179
  if (NOT Ruby_FIND_VERSION_EXACT)
176
- foreach (_ruby_version RANGE 40 18 -1)
180
+ set(_Ruby_SUPPORTED_VERSIONS 40 34 33 32)
181
+ set(_Ruby_UNSUPPORTED_VERSIONS 31 30 27 26 25 24 23 22 21 20)
182
+ foreach (_ruby_version IN LISTS _Ruby_SUPPORTED_VERSIONS _Ruby_UNSUPPORTED_VERSIONS)
177
183
  string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version)
178
184
  string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version)
179
185
  # Append both rubyX.Y and rubyXY (eg: ruby3.4 ruby34)
180
- list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES
181
- ruby${_ruby_major_version}.${_ruby_minor_version}
186
+ list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES
187
+ ruby${_ruby_major_version}.${_ruby_minor_version}
182
188
  ruby${_ruby_major_version}${_ruby_minor_version})
183
189
  endforeach ()
184
190
  endif ()
@@ -231,14 +237,6 @@ function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
231
237
  OUTPUT_VARIABLE _Ruby_OUTPUT
232
238
  ERROR_QUIET)
233
239
 
234
- # Config was deprecated in Ruby 1.9 and then removed in Ruby 2 - so this is for ancient code
235
- if (_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "")
236
- execute_process(COMMAND "${Ruby_EXECUTABLE}" -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
237
- RESULT_VARIABLE _Ruby_SUCCESS
238
- OUTPUT_VARIABLE _Ruby_OUTPUT
239
- ERROR_QUIET)
240
- endif ()
241
-
242
240
  set(${OUTVAR} "${_Ruby_OUTPUT}" PARENT_SCOPE)
243
241
  endfunction()
244
242
 
@@ -315,7 +313,7 @@ function(_RUBY_CHECK_BREW)
315
313
  return()
316
314
  endif ()
317
315
 
318
- MESSAGE(DEBUG "Found brew at: ${_BREW_EXECUTABLE}")
316
+ message(DEBUG "Found brew at: ${_BREW_EXECUTABLE}")
319
317
 
320
318
  # Query Homebrew for the prefix of the 'ruby' formula.
321
319
  # If Ruby is not installed via Homebrew, this will fail.
@@ -326,7 +324,7 @@ function(_RUBY_CHECK_BREW)
326
324
  ERROR_QUIET
327
325
  OUTPUT_STRIP_TRAILING_WHITESPACE
328
326
  )
329
- MESSAGE(DEBUG "Ruby BREW is: ${_Ruby_BREW_DIR}")
327
+ message(DEBUG "Ruby BREW is: ${_Ruby_BREW_DIR}")
330
328
 
331
329
  if (NOT _Ruby_BREW_RESULT EQUAL 0 OR _Ruby_BREW_DIR STREQUAL "")
332
330
  # No 'ruby' formula installed in Homebrew
@@ -427,7 +425,7 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
427
425
  set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE INTERNAL "The Ruby arch header dir (2.0+)" FORCE)
428
426
  set(_Ruby_POSSIBLE_LIB_DIR ${_Ruby_POSSIBLE_LIB_DIR} CACHE INTERNAL "The Ruby lib dir" FORCE)
429
427
  set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE INTERNAL "The Ruby ruby-lib dir" FORCE)
430
- set(_Ruby_SO_NAME ${_Ruby_SO_NAME} CACHE PATH "The Ruby shared library name" FORCE)
428
+ set(_Ruby_SO_NAME ${_Ruby_SO_NAME} CACHE STRING "The Ruby shared library name" FORCE)
431
429
  set(_Ruby_DLEXT ${_Ruby_DLEXT} CACHE STRING "Ruby extensions extension" FORCE)
432
430
  set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE INTERNAL "The Ruby site arch dir" FORCE)
433
431
  set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE INTERNAL "The Ruby site lib dir" FORCE)
@@ -455,30 +453,6 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
455
453
  )
456
454
  endif ()
457
455
 
458
- # In case Ruby_EXECUTABLE could not be executed (e.g. cross compiling)
459
- # try to detect which version we found. This is not too good.
460
- if (Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR)
461
- # by default assume 1.8.0
462
- set(Ruby_VERSION_MAJOR 1)
463
- set(Ruby_VERSION_MINOR 8)
464
- set(Ruby_VERSION_PATCH 0)
465
- # check whether we found 1.9.x
466
- if (${Ruby_EXECUTABLE} MATCHES "ruby1\\.?9")
467
- set(Ruby_VERSION_MAJOR 1)
468
- set(Ruby_VERSION_MINOR 9)
469
- endif ()
470
- # check whether we found 2.[0-7].x
471
- if (${Ruby_EXECUTABLE} MATCHES "ruby2")
472
- set(Ruby_VERSION_MAJOR 2)
473
- string(REGEX REPLACE ${Ruby_EXECUTABLE} "ruby2\\.?([0-7])" "\\1" Ruby_VERSION_MINOR)
474
- endif ()
475
- # check whether we found 3.[0-1].x
476
- if (${Ruby_EXECUTABLE} MATCHES "ruby3")
477
- set(Ruby_VERSION_MAJOR 3)
478
- string(REGEX REPLACE ${Ruby_EXECUTABLE} "ruby3\\.?([0-4])" "\\1" Ruby_VERSION_MINOR)
479
- endif ()
480
- endif ()
481
-
482
456
  if (Ruby_VERSION_MAJOR)
483
457
  set(Ruby_VERSION "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}.${Ruby_VERSION_PATCH}")
484
458
  set(_Ruby_VERSION_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}")
@@ -487,9 +461,6 @@ if (Ruby_VERSION_MAJOR)
487
461
  set(_Ruby_VERSION_SHORT_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}")
488
462
  endif ()
489
463
 
490
- # FIXME: Currently we require both the interpreter and development components to be found
491
- # in order to use either. See issue #20474.
492
-
493
464
  # Save CMAKE_FIND_FRAMEWORK
494
465
  set(_Ruby_CMAKE_FIND_FRAMEWORK_ORIGINAL ${CMAKE_FIND_FRAMEWORK})
495
466
 
@@ -516,7 +487,7 @@ set(CMAKE_FIND_FRAMEWORK ${_Ruby_CMAKE_FIND_FRAMEWORK_ORIGINAL})
516
487
  message(DEBUG "--------FindRuby.cmake debug------------")
517
488
  message(DEBUG "_Ruby_POSSIBLE_EXECUTABLE_NAMES: ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
518
489
  message(DEBUG "_Ruby_POSSIBLE_LIB_DIR: ${_Ruby_POSSIBLE_LIB_DIR}")
519
- message(DEBUG "Ruby_LIBRUBY_SO: ${_Ruby_SO_NAME}")
490
+ message(DEBUG "_Ruby_SO_NAME: ${_Ruby_SO_NAME}")
520
491
  message(DEBUG "_Ruby_DLEXT: ${_Ruby_DLEXT}")
521
492
  message(DEBUG "Ruby_FIND_VIRTUALENV=${Ruby_FIND_VIRTUALENV}")
522
493
  message(DEBUG "Ruby_ENV: ${Ruby_ENV}")
@@ -558,7 +529,12 @@ foreach (component IN LISTS Ruby_FIND_COMPONENTS)
558
529
  endforeach ()
559
530
 
560
531
  # Set component found flags
561
- set(Ruby_Interpreter_FOUND ${Ruby_EXECUTABLE})
532
+ if (Ruby_EXECUTABLE)
533
+ set(Ruby_Interpreter_FOUND TRUE)
534
+ else ()
535
+ set(Ruby_Interpreter_FOUND FALSE)
536
+ endif ()
537
+
562
538
  if (Ruby_INCLUDE_DIR AND Ruby_CONFIG_INCLUDE_DIR AND (Ruby_LIBRARY OR NOT WIN32))
563
539
  set(Ruby_Development_FOUND TRUE)
564
540
  else ()