@@ -36,7 +36,7 @@ use std::os::raw::{c_char, c_long};
3636/// ```
3737#[ inline( always) ]
3838pub fn TEST ( obj : VALUE ) -> bool {
39- api ( ) . rb_test ( obj. into ( ) )
39+ api ( ) . rb_test ( obj)
4040}
4141
4242/// Checks if the given object is nil.
@@ -55,7 +55,7 @@ pub fn TEST(obj: VALUE) -> bool {
5555/// ```
5656#[ inline( always) ]
5757pub fn NIL_P ( obj : VALUE ) -> bool {
58- api ( ) . nil_p ( obj. into ( ) )
58+ api ( ) . nil_p ( obj)
5959}
6060
6161/// Checks if the given object is a so-called Fixnum.
@@ -66,7 +66,7 @@ pub fn NIL_P(obj: VALUE) -> bool {
6666/// - @note Fixnum was a thing in the 20th century, but it is rather an implementation detail today.
6767#[ inline( always) ]
6868pub fn FIXNUM_P ( obj : VALUE ) -> bool {
69- api ( ) . fixnum_p ( obj. into ( ) )
69+ api ( ) . fixnum_p ( obj)
7070}
7171
7272/// Checks if the given object is a static symbol.
@@ -79,7 +79,7 @@ pub fn FIXNUM_P(obj: VALUE) -> bool {
7979/// - @note These days there are static and dynamic symbols, just like we once had Fixnum/Bignum back in the old days.
8080#[ inline( always) ]
8181pub fn STATIC_SYM_P ( obj : VALUE ) -> bool {
82- api ( ) . static_sym_p ( obj. into ( ) )
82+ api ( ) . static_sym_p ( obj)
8383}
8484
8585/// Get the backend storage of a Ruby array.
@@ -95,7 +95,7 @@ pub fn STATIC_SYM_P(obj: VALUE) -> bool {
9595/// - @return Its backend storage.
9696#[ inline( always) ]
9797pub unsafe fn RARRAY_CONST_PTR ( obj : VALUE ) -> * const VALUE {
98- api ( ) . rarray_const_ptr ( obj. into ( ) )
98+ api ( ) . rarray_const_ptr ( obj)
9999}
100100
101101/// Get the length of a Ruby array.
@@ -109,7 +109,7 @@ pub unsafe fn RARRAY_CONST_PTR(obj: VALUE) -> *const VALUE {
109109/// - @return Its length.
110110#[ inline( always) ]
111111pub unsafe fn RARRAY_LEN ( obj : VALUE ) -> c_long {
112- api ( ) . rarray_len ( obj. into ( ) )
112+ api ( ) . rarray_len ( obj)
113113}
114114
115115/// Get the length of a Ruby string.
@@ -123,21 +123,23 @@ pub unsafe fn RARRAY_LEN(obj: VALUE) -> c_long {
123123/// - @return Its length.
124124#[ inline( always) ]
125125pub unsafe fn RSTRING_LEN ( obj : VALUE ) -> c_long {
126- api ( ) . rstring_len ( obj. into ( ) )
126+ api ( ) . rstring_len ( obj)
127127}
128128
129129/// Get the backend storage of a Ruby string.
130130///
131131/// ### Safety
132132///
133133/// This function is unsafe because it dereferences a raw pointer and returns
134- /// raw pointers to Ruby memory.
134+ /// raw pointers to Ruby memory. The caller must ensure that the pointer stays live
135+ /// for the duration of usage the the underlying array (by either GC marking or
136+ /// keeping the RArray on the stack).
135137///
136138/// - @param[in] a An object of ::RString.
137139/// - @return Its backend storage
138140#[ inline( always) ]
139141pub unsafe fn RSTRING_PTR ( obj : VALUE ) -> * const c_char {
140- api ( ) . rstring_ptr ( obj. into ( ) )
142+ api ( ) . rstring_ptr ( obj)
141143}
142144
143145/// Checks if the given object is a so-called Flonum.
@@ -150,7 +152,7 @@ pub unsafe fn RSTRING_PTR(obj: VALUE) -> *const c_char {
150152/// once had Fixnum/Bignum back in the old days.
151153#[ inline( always) ]
152154pub fn FLONUM_P ( obj : VALUE ) -> bool {
153- api ( ) . flonum_p ( obj. into ( ) )
155+ api ( ) . flonum_p ( obj)
154156}
155157
156158/// Checks if the given object is an immediate i.e. an object which has no
@@ -163,7 +165,7 @@ pub fn FLONUM_P(obj: VALUE) -> bool {
163165/// @note The concept of "immediate" is purely C specific.
164166#[ inline( always) ]
165167pub fn IMMEDIATE_P ( obj : VALUE ) -> bool {
166- api ( ) . immediate_p ( obj. into ( ) )
168+ api ( ) . immediate_p ( obj)
167169}
168170
169171/// Checks if the given object is of enum ::ruby_special_consts.
@@ -183,7 +185,7 @@ pub fn IMMEDIATE_P(obj: VALUE) -> bool {
183185/// ```
184186#[ inline( always) ]
185187pub fn SPECIAL_CONST_P ( obj : VALUE ) -> bool {
186- api ( ) . special_const_p ( obj. into ( ) )
188+ api ( ) . special_const_p ( obj)
187189}
188190
189191/// Queries the type of the object.
@@ -404,6 +406,10 @@ pub unsafe fn SYM2ID(obj: VALUE) -> crate::ID {
404406}
405407
406408/// Alias for SYM2ID for compatibility with Ruby naming conventions.
409+ ///
410+ /// # Safety
411+ /// - `obj` must be a valid Symbol VALUE
412+ /// - For dynamic symbols, this may access the heap
407413#[ inline( always) ]
408414pub unsafe fn RB_SYM2ID ( obj : VALUE ) -> crate :: ID {
409415 api ( ) . sym2id ( obj)
0 commit comments