-
-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add stable API method for accessing wrapped data from legacy RData objects, equivalent to the C macro RDATA_PTR / DATA_PTR.
Motivation
While RTypedData is the modern recommended approach, many existing C extensions still use the legacy RData / Data_Wrap_Struct API. Rust extensions that need to interoperate with these existing objects need a stable way to access the wrapped pointer.
Proposed API
/// Get the data pointer from an RData object (akin to `DATA_PTR` / `RDATA_PTR`).
///
/// This is for legacy Data objects created with `Data_Wrap_Struct`.
/// For modern typed data, use `rtypeddata_get_data` instead.
///
/// # Safety
/// This function is unsafe because it dereferences a raw pointer to get
/// access to underlying Ruby data. The caller must ensure that the pointer
/// is valid and points to a T_DATA object.
unsafe fn rdata_ptr(&self, obj: VALUE) -> *mut c_void;Implementation Notes
- The
RDatastruct has adatafield containing the wrapped pointer - Need to verify object is actually T_DATA (not T_TYPEDDATA)
- Reference:
include/ruby/internal/core/rdata.h
Checklist
- Add method to
StableApiDefinitiontrait - Implement for each Ruby version
- Add C fallback in
compiled.c - Add public macro wrapper in
macros.rs - Add tests
- Document that RTypedData should be preferred for new code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request