Skip to content

Commit

Permalink
Resolve Ruby 3.2 "undefining the allocator of T_DATA class" warnings (#…
Browse files Browse the repository at this point in the history
…299)

* Resolve warnings:

warning: undefining the allocator of T_DATA class Ox::Cache
warning: undefining the allocator of T_DATA class Ox::Sax::Value

See: https://bugs.ruby-lang.org/issues/18007

Order of dumped XML elements changed in a test, but I believe the
change is not significant.

* Split the assert into two asserts that verify both elements are
exported, but not requiring them be in a particular order.

* Protect calls to rb_undef_alloc_func against old Ruby API versions.
  • Loading branch information
BoboFraggins authored Dec 19, 2022
1 parent 9b54734 commit 1572779
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ext/ox/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "ruby.h"
#include "ruby/encoding.h"
#include "ruby/version.h"
#include "ox.h"
#include "buf.h"
#include "err.h"
Expand Down Expand Up @@ -952,6 +953,9 @@ ox_init_builder(VALUE ox) {
ox = rb_define_module("Ox");
#endif
builder_class = rb_define_class_under(ox, "Builder", rb_cObject);
#if RUBY_API_VERSION_CODE >= 30200
rb_undef_alloc_func(builder_class);
#endif
rb_define_module_function(builder_class, "new", builder_new, -1);
rb_define_module_function(builder_class, "file", builder_file, -1);
rb_define_module_function(builder_class, "io", builder_io, -1);
Expand Down
5 changes: 5 additions & 0 deletions ext/ox/intern.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <stdint.h>

#include "ruby/version.h"

#include "cache.h"
#include "ox.h"

Expand Down Expand Up @@ -68,6 +70,9 @@ static VALUE form_id(const char *str, size_t len) {

void ox_hash_init() {
VALUE cache_class = rb_define_class_under(Ox, "Cache", rb_cObject);
#if RUBY_API_VERSION_CODE >= 30200
rb_undef_alloc_func(cache_class);
#endif

ox_str_cache = ox_cache_create(0, form_str, true, false);
ox_str_cache_obj = Data_Wrap_Struct(cache_class, ox_cache_mark, ox_cache_free, ox_str_cache);
Expand Down
6 changes: 6 additions & 0 deletions ext/ox/sax_as.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <time.h>

#include "ruby.h"
#include "ruby/version.h"
#include "ox.h"
#include "sax.h"

Expand Down Expand Up @@ -254,11 +255,16 @@ void
ox_sax_define() {
#if 0
ox = rb_define_module("Ox");
#if RUBY_API_VERSION_CODE >= 30200
sax_module = rb_define_class_under(ox, "Sax", rb_cObject);
#endif
#endif
VALUE sax_module = rb_const_get_at(Ox, rb_intern("Sax"));

ox_sax_value_class = rb_define_class_under(sax_module, "Value", rb_cObject);
#if RUBY_API_VERSION_CODE >= 30200
rb_undef_alloc_func(ox_sax_value_class);
#endif

rb_define_method(ox_sax_value_class, "as_s", sax_value_as_s, 0);
rb_define_method(ox_sax_value_class, "as_sym", sax_value_as_sym, 0);
Expand Down
17 changes: 8 additions & 9 deletions test/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,13 @@ def test_dump_margin
Ox::default_options = $ox_object_options
x = Ox.dump(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, {:b => 3, :a => [5], :c => Bag.new(:@x => 7)}]), :indent => 1, :margin => '##')

assert_equal('##<o c="Bag">
## <a a="@a">
assert(x.include?('## <o a="@o" c="Bag">
## <a a="@a">
## <i>2</i>
## </a>
## </o>
'))
assert(x.include?('## <a a="@a">
## <i>1</i>
## <h>
## <m>b</m>
Expand All @@ -810,13 +815,7 @@ def test_dump_margin
## </o>
## </h>
## </a>
## <o a="@o" c="Bag">
## <a a="@a">
## <i>2</i>
## </a>
## </o>
##</o>
', x)
'))
end

# Create an Object and an Array with the same Objects in them. Dump and load
Expand Down

0 comments on commit 1572779

Please sign in to comment.