Skip to content

Commit 2de367d

Browse files
committed
Update the compatibility document for C extensions.
1 parent b5e583a commit 2de367d

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

doc/user/compatibility.md

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -165,28 +165,11 @@ disabled where we dynamically detect that they probably won't be used. See the
165165

166166
## C Extension Compatibility
167167

168-
#### Storing Ruby objects in native structures and arrays
168+
#### `VALUE` is a pointer
169169

170-
You cannot store a Ruby object in a structure or array that has been natively
171-
allocated, such as on the stack, or in a heap-allocated structure or array.
172-
173-
Simple local variables of type `VALUE`, and locals arrays that are defined such
174-
as `VALUE array[n]` are an exception and are supported, provided their address
175-
is not taken and passed to a function that is not inlined.
176-
177-
`void *rb_tr_handle_for_managed(VALUE managed)` and `VALUE
178-
rb_tr_managed_from_handle(void *native)` may help you work around this
179-
limitation. Use `void* rb_tr_handle_for_managed_leaking(VALUE managed)` if you
180-
don't yet know where to put a corresponding call to `void
181-
*rb_tr_release_handle(void *native)`. Use `VALUE
182-
rb_tr_managed_from_handle_or_null(void *native)` if the handle may be `NULL`.
183-
184-
#### Mixing native and managed in C global variables
185-
186-
C global variables can contain native data or they can contain managed data,
187-
but they cannot contain both in the same program run. If you have a global you
188-
assign `NULL` to (`NULL` being just `0` and so a native address) you cannot
189-
then assign managed data to this variable.
170+
In TruffleRuby `VALUE` is a pointer rather than a 64 bit integer
171+
type. This means that `switch` statements cannot be done using a raw
172+
`VALUE` as they can with MRI
190173

191174
#### Identifiers may be macros or functions
192175

@@ -197,34 +180,18 @@ address of it, assigning to a function pointer variable and using defined() to
197180
check if a macro exists). These issues should all be considered bugs and be
198181
fixed, please report these cases.
199182

200-
#### Variadic functions
201-
202-
Variadic arguments of type `VALUE` that hold Ruby objects can be used, but they
203-
cannot be accessed with `va_start` etc. You can use
204-
`void *polyglot_get_arg(int i)` instead.
205-
206-
#### Pointers to `VALUE` locals and variadic functions
207-
208-
Pointers to local variables that have the type `VALUE` and hold Ruby objects can
209-
only be passed as function arguments if the function is inlined. LLVM will never
210-
inline variadic functions so pointers to local variables that hold Ruby objects
211-
cannot be passed as variadic arguments.
212-
213-
`rb_scan_args` is an exception and is supported.
214-
215183
#### `rb_scan_args`
216184

217185
`rb_scan_args` only supports up to ten pointers.
218186

219187
#### `RDATA`
220188

221-
The `mark` function of `RDATA` and `RTYPEDDATA` is never called.
222-
223-
#### Ruby objects and truthiness in C
224-
225-
All Ruby objects are truthy in C, except for `Qfalse`, the `Integer` value `0`,
226-
and the `Float` value `0.0`. The last two are incompatible with MRI, which would
227-
also see these values as truthy.
189+
The `mark` function of `RDATA` and `RTYPEDDATA` is not called during
190+
garbage collection. Instead we simulate this by caching information
191+
about objects as they are assigned to structs, and periodically
192+
running all mark functions when the cache has become full to represent
193+
those object relationships in a way that the our garbage collector
194+
will understand.
228195

229196
## Compatibility with JRuby
230197

0 commit comments

Comments
 (0)