Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There isn’t actually a distinction between in, out, and inout. Is this intended for backward-compatibility or future-proofing? #1073

Open
ParadoxV5 opened this issue Dec 31, 2023 · 2 comments

Comments

@ParadoxV5
Copy link
Contributor

  • Struct.ptr does not utilize the optional argument flags (not even checking if it’s a valid choice).

    ffi/lib/ffi/struct.rb

    Lines 131 to 133 in f2d3846

    def self.ptr(flags = :inout)
    @ref_data_type ||= Type::Mapped.new(StructByReference.new(self))
    end
  • Struct and Buffer’s . alloc/new _ inout/in/out are all either an alias of, or is nothing more than a delegate to, .new.

    ffi/ext/ffi_c/Struct.c

    Lines 859 to 864 in f2d3846

    rb_define_alias(rb_singleton_class(StructClass), "alloc_in", "new");
    rb_define_alias(rb_singleton_class(StructClass), "alloc_out", "new");
    rb_define_alias(rb_singleton_class(StructClass), "alloc_inout", "new");
    rb_define_alias(rb_singleton_class(StructClass), "new_in", "new");
    rb_define_alias(rb_singleton_class(StructClass), "new_out", "new");
    rb_define_alias(rb_singleton_class(StructClass), "new_inout", "new");

    ffi/ext/ffi_c/Buffer.c

    Lines 194 to 198 in f2d3846

    static VALUE
    buffer_alloc_inout(int argc, VALUE* argv, VALUE klass)
    {
    return buffer_initialize(argc, argv, buffer_allocate(klass));
    }

    ffi/ext/ffi_c/Buffer.c

    Lines 387 to 407 in f2d3846

    /*
    * Document-method: alloc_inout
    * call-seq: alloc_inout(*args)
    * Create a new Buffer for in and out arguments (alias : <i>new_inout</i>).
    */
    rb_define_singleton_method(BufferClass, "alloc_inout", buffer_alloc_inout, -1);
    /*
    * Document-method: alloc_out
    * call-seq: alloc_out(*args)
    * Create a new Buffer for out arguments (alias : <i>new_out</i>).
    */
    rb_define_singleton_method(BufferClass, "alloc_out", buffer_alloc_inout, -1);
    /*
    * Document-method: alloc_in
    * call-seq: alloc_in(*args)
    * Create a new Buffer for in arguments (alias : <i>new_in</i>).
    */
    rb_define_singleton_method(BufferClass, "alloc_in", buffer_alloc_inout, -1);
    rb_define_alias(rb_singleton_class(BufferClass), "new_in", "alloc_in");
    rb_define_alias(rb_singleton_class(BufferClass), "new_out", "alloc_out");
    rb_define_alias(rb_singleton_class(BufferClass), "new_inout", "alloc_inout");
ParadoxV5 added a commit to ParadoxV5/ruby-ffi that referenced this issue Dec 31, 2023
* add `Struct#layout`; see ffi#1072 regarding incomplete docs
* (temporarily?) un-type `Struct.ptr` `flags` arg: ffi#1073
@larskanis
Copy link
Member

I think it is future-proofing. I know the declaration of the direction of buffer usage from OpenGL, where the memory location can be different according to this information.

Also our Wiki describes them as a performance optimization: https://github.com/ffi/ffi/wiki/Types

@larskanis
Copy link
Member

The very first commit with in/out buffers is 2592f27 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants