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

ruby: Fix build failures with Ruby 3.4 #1544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ac000
Copy link
Member

@ac000 ac000 commented Jan 21, 2025

    ruby: Fix build failures with Ruby 3.4
    
    Ruby 3.4 started to actually mark some deprecated functions as
    *deprecated* now resulting in compiler warnings (which due to -Werror we
    treat as errors and thus the build fails).
    
    The *new* functions were actually introduced back in Ruby 1.9.2, so have
    been around for quite some time. We claim support for Ruby 2.0 onwards
    so this is more than fine.
    
    The new API replaces the old 'mark' and 'free' parameters with a struct
    that allows for more fine tuning/configuration. We never made use of
    either of those parameters and so the only members of this struct we
    *need* to set is the structure wrapper name and the dsize function
    pointer which is passed a pointer to the underlying wrapped structure to
    calculate its memory usage. While this is *not* required the
    documentation *recommends* setting it (though it doesn't say how it's
    used).
    
    Ruby pytests still pass after this change...
    
    Closes: https://github.com/nginx/unit/issues/1525
    Link: <https://bugs.ruby-lang.org/issues/19998>
    Link: <https://docs.ruby-lang.org/en/3.4/extension_rdoc.html#label-C+struct+to+Ruby+object>
    Signed-off-by: Andrew Clayton <[email protected]>

@ac000 ac000 linked an issue Jan 21, 2025 that may be closed by this pull request
@ac000 ac000 marked this pull request as ready for review January 21, 2025 19:36
@ac000 ac000 requested review from hongzhidao and avahahn January 21, 2025 19:38
Ruby 3.4 started to actually mark some deprecated functions as
*deprecated* now resulting in compiler warnings (which due to -Werror we
treat as errors and thus the build fails).

The *new* functions were actually introduced back in Ruby 1.9.2, so have
been around for quite some time. We claim support for Ruby 2.0 onwards
so this is more than fine.

The new API replaces the old 'mark' and 'free' parameters with a struct
that allows for more fine tuning/configuration. We never made use of
either of those parameters and so the only members of this struct we
*need* to set is the structure wrapper name and the dsize function
pointer which is passed a pointer to the underlying wrapped structure to
calculate its memory usage. While this is *not* required the
documentation *recommends* setting it (though it doesn't say how it's
used).

Ruby pytests still pass after this change...

Closes: nginx#1525
Link: <https://bugs.ruby-lang.org/issues/19998>
Link: <https://docs.ruby-lang.org/en/3.4/extension_rdoc.html#label-C+struct+to+Ruby+object>
Signed-off-by: Andrew Clayton <[email protected]>
@ac000
Copy link
Member Author

ac000 commented Jan 22, 2025

  • Set the dsize function pointer in the rb_data_type_struct as recommended by the docs.
$ git range-diff 60fc2559...7b7b29fc
1:  60fc2559 ! 1:  7b7b29fc ruby: Fix build failures with Ruby 3.4
    @@ Commit message
     
         The new API replaces the old 'mark' and 'free' parameters with a struct
         that allows for more fine tuning/configuration. We never made use of
    -    either of those parameters and so the only member of this struct we
    -    *need* to set is the structure wrapper name.
    +    either of those parameters and so the only members of this struct we
    +    *need* to set is the structure wrapper name and the dsize function
    +    pointer which is passed a pointer to the underlying wrapped structure to
    +    calculate its memory usage. While this is *not* required the
    +    documentation *recommends* setting it (though it doesn't say how it's
    +    used).
     
         Ruby pytests still pass after this change...
     
         Closes: https://github.com/nginx/unit/issues/1525
         Link: <https://bugs.ruby-lang.org/issues/19998>
    +    Link: <https://docs.ruby-lang.org/en/3.4/extension_rdoc.html#label-C+struct+to+Ruby+object>
         Signed-off-by: Andrew Clayton <[email protected]>
     
      ## src/ruby/nxt_ruby_stream_io.c ##
    -@@ src/ruby/nxt_ruby_stream_io.c: static VALUE nxt_ruby_stream_io_flush(VALUE obj);
    +@@ src/ruby/nxt_ruby_stream_io.c: static VALUE nxt_ruby_stream_io_write(VALUE obj, VALUE args);
    + nxt_inline long nxt_ruby_stream_io_s_write(nxt_ruby_ctx_t *rctx, VALUE val);
    + static VALUE nxt_ruby_stream_io_flush(VALUE obj);
      static VALUE nxt_ruby_stream_io_close(VALUE obj);
    - 
    - 
    -+static const rb_data_type_t  nxt_rctx_dt = { .wrap_struct_name = "rctx" };
    ++nxt_inline size_t nxt_ruby_dt_dsize_rctx(const void *arg);
     +
     +
    ++static const rb_data_type_t  nxt_rctx_dt = {
    ++    .wrap_struct_name  = "rctx",
    ++    .function  = {
    ++        .dsize         = nxt_ruby_dt_dsize_rctx,
    ++    },
    ++};
    ++
    ++
    ++nxt_inline size_t
    ++nxt_ruby_dt_dsize_rctx(const void *arg)
    ++{
    ++    const nxt_ruby_ctx_t  *rctx = arg;
    ++
    ++    return sizeof(*rctx);
    ++}
    + 
    + 
      VALUE
    - nxt_ruby_stream_io_input_init(void)
    - {
     @@ src/ruby/nxt_ruby_stream_io.c: nxt_ruby_stream_io_new(VALUE class, VALUE arg)
      {
          VALUE  self;

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

Successfully merging this pull request may close these issues.

Emits deprecation warnings when building with Ruby 3.4
1 participant