You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(stable-api): Add FL_TEST, FL_SET, FL_UNSET for flag manipulation #664
Add stable API methods for testing and manipulating Ruby object flags, equivalent to the C macros FL_TEST, FL_SET, FL_UNSET, and related flag operations.
Motivation
Object flags are used extensively in Ruby internals for tracking object state (frozen, tainted, embedded, etc.). Direct flag manipulation is needed for:
Implementing custom Ruby objects with proper GC semantics
Performance-critical code that checks object properties
Advanced use cases like implementing custom containers
Proposed API
/// Test if specific flags are set on an object (akin to `FL_TEST`).////// # Safety/// This function is unsafe because it dereferences a raw pointer to get/// access to underlying RBasic struct. The caller must ensure that the/// VALUE is a valid pointer to a heap object.unsafefnfl_test(&self,obj:VALUE,flags:VALUE) -> VALUE;/// Test if specific flags are set (returns bool) (akin to `FL_TEST_RAW`).////// # Safety/// Same as fl_test.unsafefnfl_test_raw(&self,obj:VALUE,flags:VALUE) -> bool;/// Set specific flags on an object (akin to `FL_SET`).////// # Safety/// This function is unsafe because it modifies internal Ruby object state./// The caller must ensure proper synchronization and that the flags being/// set are appropriate for the object type.unsafefnfl_set(&self,obj:VALUE,flags:VALUE);/// Unset specific flags on an object (akin to `FL_UNSET`).////// # Safety/// Same as fl_set.unsafefnfl_unset(&self,obj:VALUE,flags:VALUE);
Implementation Notes
Flags are stored in RBasic.flags field
Some flags have special meaning and should not be modified directly
Reference: include/ruby/internal/fl_type.h
Common flags: FL_FREEZE, FL_TAINT (deprecated), FL_USER*
Checklist
Add methods to StableApiDefinition trait
Implement for each Ruby version (2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0)
Activity