ext/cairo/rb_cairo_region.c in cairo-1.17.6 vs ext/cairo/rb_cairo_region.c in cairo-1.17.7

- old
+ new

@@ -1,10 +1,10 @@ /* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */ /* * Ruby Cairo Binding * - * Copyright 2010 Kouhei Sutou <kou@cozmixng.org> + * Copyright 2010-2022 Sutou Kouhei <kou@cozmixng.org> * * This file is made available under the same terms as Ruby * */ @@ -16,10 +16,27 @@ #if CAIRO_CHECK_VERSION(1, 10, 0) #define _SELF (RVAL2CRREGION(self)) +static void +cr_region_free (void *ptr) +{ + cairo_region_destroy ((cairo_region_t *) ptr); +} + +static const rb_data_type_t cr_region_type = { + "Cairo::Region", + { + NULL, + cr_region_free, + }, + NULL, + NULL, + RUBY_TYPED_FREE_IMMEDIATELY, +}; + static inline void cr_region_check_status (cairo_region_t *region) { rb_cairo_check_status (cairo_region_status (region)); } @@ -30,40 +47,31 @@ cairo_region_t *region; if (!rb_cairo__is_kind_of (obj, rb_cCairo_Region)) { rb_raise (rb_eTypeError, "not a cairo region"); } - Data_Get_Struct (obj, cairo_region_t, region); + TypedData_Get_Struct (obj, cairo_region_t, &cr_region_type, region); return region; } -static void -cr_region_free (void *ptr) -{ - if (ptr) - { - cairo_region_destroy ((cairo_region_t *) ptr); - } -} - VALUE rb_cairo_region_to_ruby_object (cairo_region_t *region) { if (region) { cairo_region_reference (region); - return Data_Wrap_Struct (rb_cCairo_Region, NULL, cr_region_free, region); + return TypedData_Wrap_Struct (rb_cCairo_Region, &cr_region_type, region); } else { return Qnil; } } static VALUE cr_region_allocate (VALUE klass) { - return Data_Wrap_Struct (klass, NULL, cr_region_free, NULL); + return TypedData_Wrap_Struct (klass, &cr_region_type, NULL); } static VALUE cr_region_initialize (int argc, VALUE *argv, VALUE self) {