Skip to content

[FFI] FFI::Pointer#slice is not defined #608

@Burgestrand

Description

@Burgestrand

Ruby FFI gem has Pointer#slice, JRuby does not: https://github.com/ffi/ffi/blob/d42fe3e5abea6fce3f79f4b8db4728ba454d0f51/ext/ffi_c/Pointer.c#L237

Personally I use slice to slice any arbitrary pointer from the beginning of the pointer, in order to give it size information (to ensure I do not go out of bounds when reading or writing).

pointer = FFI::Pointer.new(arbitrary_address).slice(0, length)
# any attempts to manipulate beyond pointer arbitrary_address + length fails with an error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions