ext/cairo/rb_cairo_device.c in cairo-1.17.6 vs ext/cairo/rb_cairo_device.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-2019 Kouhei Sutou <kou@cozmixng.org>
+ * Copyright 2010-2022 Sutou Kouhei <kou@cozmixng.org>
*
* This file is made available under the same terms as Ruby
*
*/
@@ -115,19 +115,37 @@
return Qfalse;
#endif
}
/* constructor/de-constructor */
+static void
+cr_device_free (void *ptr)
+{
+ cairo_device_t *device = ptr;
+ cairo_device_destroy (device);
+}
+
+static const rb_data_type_t cr_device_type = {
+ "Cairo::Device",
+ {
+ NULL,
+ cr_device_free,
+ },
+ NULL,
+ NULL,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
cairo_device_t *
rb_cairo_device_from_ruby_object (VALUE obj)
{
cairo_device_t *device;
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Device))
{
rb_raise (rb_eTypeError, "not a cairo device");
}
- Data_Get_Struct (obj, cairo_device_t, device);
+ TypedData_Get_Struct (obj, cairo_device_t, &cr_device_type, device);
if (!device)
rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
return device;
}
@@ -143,28 +161,19 @@
{
rb_cairo__object_holder_free (rb_cCairo_Device, ptr);
}
#endif
-static void
-cr_device_free (void *ptr)
-{
- cairo_device_t *device = ptr;
-
- if (device)
- cairo_device_destroy (device);
-}
-
VALUE
rb_cairo_device_to_ruby_object (cairo_device_t *device)
{
if (device)
{
VALUE klass;
klass = cr_device_get_klass (device);
cairo_device_reference (device);
- return Data_Wrap_Struct (klass, NULL, cr_device_free, device);
+ return TypedData_Wrap_Struct (klass, &cr_device_type, device);
}
else
{
return Qnil;
}
@@ -183,10 +192,10 @@
}
static VALUE
cr_device_allocate (VALUE klass)
{
- return Data_Wrap_Struct (klass, NULL, cr_device_free, NULL);
+ return TypedData_Wrap_Struct (klass, &cr_device_type, NULL);
}
static VALUE
cr_device_initialize (int argc, VALUE *argv, VALUE self)
{