[librsvg/librsvg-2.48] Do all the GType checks for the C API in the Rust code



commit 6c99808411df568d10679e104e78cde3405959fb
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Apr 8 21:35:06 2020 -0500

    Do all the GType checks for the C API in the Rust code

 librsvg/c_api.rs      | 140 +++++++++++++++++++++++++++++++++++++++++++-------
 librsvg/rsvg-handle.c |  54 -------------------
 tests/api.c           |  33 ++++++++++++
 3 files changed, 154 insertions(+), 73 deletions(-)
---
diff --git a/librsvg/c_api.rs b/librsvg/c_api.rs
index 0e6b3844..41a23080 100644
--- a/librsvg/c_api.rs
+++ b/librsvg/c_api.rs
@@ -28,6 +28,8 @@ use glib::{
     ToValue, Type, Value,
 };
 
+use glib::types::instance_of;
+
 use gobject_sys::{GEnumValue, GFlagsValue};
 
 use rsvg_internals::{
@@ -384,6 +386,12 @@ impl ObjectSubclass for CHandle {
     }
 }
 
+impl StaticType for CHandle {
+    fn static_type() -> Type {
+        CHandle::get_type()
+    }
+}
+
 impl ObjectImpl for CHandle {
     glib_object_impl!();
 
@@ -830,6 +838,22 @@ impl CHandle {
     }
 }
 
+fn is_rsvg_handle(obj: *const RsvgHandle) -> bool {
+    unsafe { instance_of::<CHandle>(obj as *const _) }
+}
+
+fn is_input_stream(obj: *mut gio_sys::GInputStream) -> bool {
+    unsafe { instance_of::<gio::InputStream>(obj as *const _) }
+}
+
+fn is_gfile(obj: *const gio_sys::GFile) -> bool {
+    unsafe { instance_of::<gio::File>(obj as *const _) }
+}
+
+fn is_cancellable(obj: *mut gio_sys::GCancellable) -> bool {
+    unsafe { instance_of::<gio::Cancellable>(obj as *const _) }
+}
+
 fn get_rust_handle<'a>(handle: *const RsvgHandle) -> &'a CHandle {
     let handle = unsafe { &*handle };
     handle.get_impl()
@@ -924,15 +948,17 @@ pub unsafe extern "C" fn rsvg_rust_handle_flags_get_type() -> glib_sys::GType {
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_set_base_url(
-    raw_handle: *const RsvgHandle,
+    handle: *const RsvgHandle,
     uri: *const libc::c_char,
 ) {
     rsvg_return_if_fail! {
         rsvg_handle_set_base_uri;
+
+        is_rsvg_handle(handle),
         !uri.is_null(),
     }
 
-    let rhandle = get_rust_handle(raw_handle);
+    let rhandle = get_rust_handle(handle);
 
     assert!(!uri.is_null());
     let uri: String = from_glib_none(uri);
@@ -942,10 +968,17 @@ pub unsafe extern "C" fn rsvg_rust_handle_set_base_url(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_set_base_gfile(
-    raw_handle: *const RsvgHandle,
+    handle: *const RsvgHandle,
     raw_gfile: *mut gio_sys::GFile,
 ) {
-    let rhandle = get_rust_handle(raw_handle);
+    rsvg_return_if_fail! {
+        rsvg_handle_set_base_gfile;
+
+        is_rsvg_handle(handle),
+        is_gfile(raw_gfile),
+    }
+
+    let rhandle = get_rust_handle(handle);
 
     assert!(!raw_gfile.is_null());
 
@@ -956,16 +989,28 @@ pub unsafe extern "C" fn rsvg_rust_handle_set_base_gfile(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_get_base_url(
-    raw_handle: *const RsvgHandle,
+    handle: *const RsvgHandle,
 ) -> *const libc::c_char {
-    let rhandle = get_rust_handle(raw_handle);
+    rsvg_return_val_if_fail! {
+        rsvg_handle_get_base_uri => ptr::null();
+
+        is_rsvg_handle(handle),
+    }
+
+    let rhandle = get_rust_handle(handle);
 
     rhandle.get_base_url_as_ptr()
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn rsvg_rust_handle_set_dpi_x(raw_handle: *const RsvgHandle, dpi_x: f64) {
-    let rhandle = get_rust_handle(raw_handle);
+pub unsafe extern "C" fn rsvg_rust_handle_set_dpi_x(handle: *const RsvgHandle, dpi_x: f64) {
+    rsvg_return_if_fail! {
+        rsvg_handle_set_dpi_x_y;
+
+        is_rsvg_handle(handle),
+    }
+
+    let rhandle = get_rust_handle(handle);
     rhandle.set_dpi_x(dpi_x);
 }
 
@@ -976,8 +1021,14 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_dpi_x(raw_handle: *const RsvgHandl
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn rsvg_rust_handle_set_dpi_y(raw_handle: *const RsvgHandle, dpi_y: f64) {
-    let rhandle = get_rust_handle(raw_handle);
+pub unsafe extern "C" fn rsvg_rust_handle_set_dpi_y(handle: *const RsvgHandle, dpi_y: f64) {
+    rsvg_return_if_fail! {
+        rsvg_handle_set_dpi_x_y;
+
+        is_rsvg_handle(handle),
+    }
+
+    let rhandle = get_rust_handle(handle);
     rhandle.set_dpi_y(dpi_y);
 }
 
@@ -989,22 +1040,34 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_dpi_y(raw_handle: *const RsvgHandl
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_set_size_callback(
-    raw_handle: *const RsvgHandle,
+    handle: *const RsvgHandle,
     size_func: RsvgSizeFunc,
     user_data: glib_sys::gpointer,
     destroy_notify: glib_sys::GDestroyNotify,
 ) {
-    let rhandle = get_rust_handle(raw_handle);
+    rsvg_return_if_fail! {
+        rsvg_handle_set_size_callback;
+
+        is_rsvg_handle(handle),
+    }
+
+    let rhandle = get_rust_handle(handle);
 
     rhandle.set_size_callback(size_func, user_data, destroy_notify);
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_set_testing(
-    raw_handle: *const RsvgHandle,
+    handle: *const RsvgHandle,
     testing: glib_sys::gboolean,
 ) {
-    let rhandle = get_rust_handle(raw_handle);
+    rsvg_return_if_fail! {
+        rsvg_handle_internal_set_testing;
+
+        is_rsvg_handle(handle),
+    }
+
+    let rhandle = get_rust_handle(handle);
 
     rhandle.set_testing(from_glib(testing));
 }
@@ -1019,6 +1082,9 @@ pub unsafe extern "C" fn rsvg_rust_handle_read_stream_sync(
     rsvg_return_val_if_fail! {
         rsvg_handle_read_stream_sync => false.to_glib();
 
+        is_rsvg_handle(handle),
+        is_input_stream(stream),
+        cancellable.is_null() || is_cancellable(cancellable),
         error.is_null() || (*error).is_null(),
     }
 
@@ -1047,6 +1113,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_write(
     rsvg_return_val_if_fail! {
         rsvg_handle_write => false.to_glib();
 
+        is_rsvg_handle(handle),
         error.is_null() || (*error).is_null(),
         (!buf.is_null() && count != 0) || (count == 0),
     }
@@ -1066,6 +1133,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_close(
     rsvg_return_val_if_fail! {
         rsvg_handle_close => false.to_glib();
 
+        is_rsvg_handle(handle),
         error.is_null() || (*error).is_null(),
     }
 
@@ -1085,6 +1153,12 @@ pub unsafe extern "C" fn rsvg_rust_handle_has_sub(
     handle: *const RsvgHandle,
     id: *const libc::c_char,
 ) -> glib_sys::gboolean {
+    rsvg_return_val_if_fail! {
+        rsvg_handle_has_sub => false.to_glib();
+
+        is_rsvg_handle(handle),
+    }
+
     let rhandle = get_rust_handle(handle);
 
     if id.is_null() {
@@ -1104,6 +1178,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_cairo_sub(
     rsvg_return_val_if_fail! {
         rsvg_handle_render_cairo_sub => false.to_glib();
 
+        is_rsvg_handle(handle),
         !cr.is_null(),
     }
 
@@ -1126,6 +1201,12 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_pixbuf_sub(
     handle: *const RsvgHandle,
     id: *const libc::c_char,
 ) -> *mut gdk_pixbuf_sys::GdkPixbuf {
+    rsvg_return_val_if_fail! {
+        rsvg_handle_get_pixbuf_sub => ptr::null_mut();
+
+        is_rsvg_handle(handle),
+    }
+
     let rhandle = get_rust_handle(handle);
     let id: Option<String> = from_glib_none(id);
 
@@ -1145,6 +1226,8 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_dimensions(
 ) {
     rsvg_return_if_fail! {
         rsvg_handle_get_dimensions;
+
+        is_rsvg_handle(handle),
         !dimension_data.is_null(),
     }
 
@@ -1163,6 +1246,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_dimensions_sub(
     rsvg_return_val_if_fail! {
         rsvg_handle_get_dimensions_sub => false.to_glib();
 
+        is_rsvg_handle(handle),
         !dimension_data.is_null(),
     }
 
@@ -1193,6 +1277,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_position_sub(
     rsvg_return_val_if_fail! {
         rsvg_handle_get_position_sub => false.to_glib();
 
+        is_rsvg_handle(handle),
         !position_data.is_null(),
     }
 
@@ -1264,6 +1349,8 @@ pub unsafe extern "C" fn rsvg_rust_handle_new_from_gfile_sync(
     rsvg_return_val_if_fail! {
         rsvg_handle_new_from_gfile_sync => ptr::null();
 
+        is_gfile(file),
+        cancellable.is_null() || is_cancellable(cancellable),
         error.is_null() || (*error).is_null(),
     }
 
@@ -1303,6 +1390,9 @@ pub unsafe extern "C" fn rsvg_rust_handle_new_from_stream_sync(
     rsvg_return_val_if_fail! {
         rsvg_handle_new_from_stream_sync => ptr::null();
 
+        is_input_stream(input_stream),
+        base_file.is_null() || is_gfile(base_file),
+        cancellable.is_null() || is_cancellable(cancellable),
         error.is_null() || (*error).is_null(),
     }
 
@@ -1400,6 +1490,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_set_stylesheet(
     rsvg_return_val_if_fail! {
         rsvg_handle_set_stylesheet => false.to_glib();
 
+        is_rsvg_handle(handle),
         !css.is_null() || (css.is_null() && css_len == 0),
         error.is_null() || (*error).is_null(),
     }
@@ -1431,7 +1522,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_set_stylesheet(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_get_intrinsic_dimensions(
-    handle: *mut RsvgHandle,
+    handle: *const RsvgHandle,
     out_has_width: *mut glib_sys::gboolean,
     out_width: *mut RsvgLength,
     out_has_height: *mut glib_sys::gboolean,
@@ -1439,6 +1530,12 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_intrinsic_dimensions(
     out_has_viewbox: *mut glib_sys::gboolean,
     out_viewbox: *mut RsvgRectangle,
 ) {
+    rsvg_return_if_fail! {
+        rsvg_handle_get_intrinsic_dimensions;
+
+        is_rsvg_handle(handle),
+    }
+
     let rhandle = get_rust_handle(handle);
 
     let d = rhandle
@@ -1456,7 +1553,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_intrinsic_dimensions(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_render_document(
-    handle: *mut RsvgHandle,
+    handle: *const RsvgHandle,
     cr: *mut cairo_sys::cairo_t,
     viewport: *const RsvgRectangle,
     error: *mut *mut glib_sys::GError,
@@ -1464,6 +1561,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_document(
     rsvg_return_val_if_fail! {
         rsvg_handle_render_document => false.to_glib();
 
+        is_rsvg_handle(handle),
         !cr.is_null(),
         !viewport.is_null(),
         error.is_null() || (*error).is_null(),
@@ -1494,6 +1592,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_layer(
     rsvg_return_val_if_fail! {
         rsvg_handle_get_geometry_for_layer => false.to_glib();
 
+        is_rsvg_handle(handle),
         !viewport.is_null(),
         error.is_null() || (*error).is_null(),
     }
@@ -1524,7 +1623,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_layer(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_render_layer(
-    handle: *mut RsvgHandle,
+    handle: *const RsvgHandle,
     cr: *mut cairo_sys::cairo_t,
     id: *const libc::c_char,
     viewport: *const RsvgRectangle,
@@ -1533,6 +1632,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_layer(
     rsvg_return_val_if_fail! {
         rsvg_handle_render_layer => false.to_glib();
 
+        is_rsvg_handle(handle),
         !cr.is_null(),
         !viewport.is_null(),
         error.is_null() || (*error).is_null(),
@@ -1554,7 +1654,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_layer(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_element(
-    handle: *mut RsvgHandle,
+    handle: *const RsvgHandle,
     id: *const libc::c_char,
     out_ink_rect: *mut RsvgRectangle,
     out_logical_rect: *mut RsvgRectangle,
@@ -1563,6 +1663,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_element(
     rsvg_return_val_if_fail! {
         rsvg_handle_get_geometry_for_element => false.to_glib();
 
+        is_rsvg_handle(handle),
         error.is_null() || (*error).is_null(),
     }
 
@@ -1592,7 +1693,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_element(
 
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_rust_handle_render_element(
-    handle: *mut RsvgHandle,
+    handle: *const RsvgHandle,
     cr: *mut cairo_sys::cairo_t,
     id: *const libc::c_char,
     element_viewport: *const RsvgRectangle,
@@ -1601,6 +1702,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_render_element(
     rsvg_return_val_if_fail! {
         rsvg_handle_render_element => false.to_glib();
 
+        is_rsvg_handle(handle),
         !cr.is_null(),
         !element_viewport.is_null(),
         error.is_null() || (*error).is_null(),
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index f0fe345a..1dd112c6 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -552,9 +552,6 @@ rsvg_handle_new_from_gfile_sync (GFile          *file,
                                  GCancellable   *cancellable,
                                  GError        **error)
 {
-    g_return_val_if_fail (G_IS_FILE (file), NULL);
-    g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
-
     return rsvg_rust_handle_new_from_gfile_sync (file, flags, cancellable, error);
 }
 
@@ -588,10 +585,6 @@ rsvg_handle_new_from_stream_sync (GInputStream    *input_stream,
                                   GCancellable    *cancellable,
                                   GError         **error)
 {
-    g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL);
-    g_return_val_if_fail (base_file == NULL || G_IS_FILE (base_file), NULL);
-    g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
-
     return rsvg_rust_handle_new_from_stream_sync (input_stream,
                                                   base_file,
                                                   flags,
@@ -626,8 +619,6 @@ rsvg_handle_new_from_stream_sync (GInputStream    *input_stream,
 gboolean
 rsvg_handle_write (RsvgHandle *handle, const guchar *buf, gsize count, GError **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_write (handle, buf, count, error);
 }
 
@@ -650,8 +641,6 @@ rsvg_handle_write (RsvgHandle *handle, const guchar *buf, gsize count, GError **
 gboolean
 rsvg_handle_close (RsvgHandle *handle, GError **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_close(handle, error);
 }
 
@@ -686,10 +675,6 @@ rsvg_handle_read_stream_sync (RsvgHandle   *handle,
                               GCancellable *cancellable,
                               GError      **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-    g_return_val_if_fail (G_IS_INPUT_STREAM (stream), FALSE);
-    g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
-
     return rsvg_rust_handle_read_stream_sync (handle,
                                               stream,
                                               cancellable,
@@ -711,8 +696,6 @@ rsvg_handle_read_stream_sync (RsvgHandle   *handle,
 void
 rsvg_handle_set_base_uri (RsvgHandle *handle, const char *base_uri)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-
     rsvg_rust_handle_set_base_url (handle, base_uri);
 }
 
@@ -732,9 +715,6 @@ void
 rsvg_handle_set_base_gfile (RsvgHandle *handle,
                             GFile      *base_file)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-    g_return_if_fail (G_IS_FILE (base_file));
-
     rsvg_rust_handle_set_base_gfile (handle, base_file);
 }
 
@@ -750,8 +730,6 @@ rsvg_handle_set_base_gfile (RsvgHandle *handle,
 const char *
 rsvg_handle_get_base_uri (RsvgHandle *handle)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), NULL);
-
     return rsvg_rust_handle_get_base_url (handle);
 }
 
@@ -782,8 +760,6 @@ rsvg_handle_set_stylesheet (RsvgHandle  *handle,
                             gsize        css_len,
                             GError     **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_set_stylesheet (handle, css, css_len, error);
 }
 
@@ -875,8 +851,6 @@ rsvg_handle_get_desc (RsvgHandle *handle)
 gboolean
 rsvg_handle_render_cairo_sub (RsvgHandle *handle, cairo_t *cr, const char *id)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_render_cairo_sub (handle, cr, id);
 }
 
@@ -923,8 +897,6 @@ rsvg_handle_render_cairo (RsvgHandle *handle, cairo_t *cr)
 void
 rsvg_handle_get_dimensions (RsvgHandle *handle, RsvgDimensionData *dimension_data)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-
     rsvg_rust_handle_get_dimensions (handle, dimension_data);
 }
 
@@ -955,8 +927,6 @@ rsvg_handle_get_dimensions_sub (RsvgHandle *handle,
                                 RsvgDimensionData *dimension_data,
                                 const char *id)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_get_dimensions_sub (handle, dimension_data, id);
 }
 
@@ -987,8 +957,6 @@ rsvg_handle_get_position_sub (RsvgHandle *handle,
                               RsvgPositionData *position_data,
                               const char *id)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_get_position_sub (handle, position_data, id);
 }
 
@@ -1012,8 +980,6 @@ rsvg_handle_get_position_sub (RsvgHandle *handle,
 gboolean
 rsvg_handle_has_sub (RsvgHandle *handle, const char *id)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_has_sub (handle, id);
 }
 
@@ -1050,8 +1016,6 @@ rsvg_handle_has_sub (RsvgHandle *handle, const char *id)
 GdkPixbuf *
 rsvg_handle_get_pixbuf_sub (RsvgHandle *handle, const char *id)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), NULL);
-
     return rsvg_rust_handle_get_pixbuf_sub (handle, id);
 }
 
@@ -1114,8 +1078,6 @@ rsvg_handle_set_dpi (RsvgHandle *handle, double dpi)
 void
 rsvg_handle_set_dpi_x_y (RsvgHandle *handle, double dpi_x, double dpi_y)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-
     rsvg_rust_handle_set_dpi_x (handle, dpi_x);
     rsvg_rust_handle_set_dpi_y (handle, dpi_y);
 }
@@ -1183,8 +1145,6 @@ rsvg_handle_set_size_callback (RsvgHandle *handle,
                                gpointer user_data,
                                GDestroyNotify user_data_destroy)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-
     rsvg_rust_handle_set_size_callback (handle,
                                         size_func,
                                         user_data,
@@ -1244,8 +1204,6 @@ rsvg_handle_get_intrinsic_dimensions (RsvgHandle *handle,
                                       gboolean   *out_has_viewbox,
                                       RsvgRectangle *out_viewbox)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-
     rsvg_rust_handle_get_intrinsic_dimensions (handle,
                                                out_has_width,
                                                out_width,
@@ -1283,8 +1241,6 @@ rsvg_handle_render_document (RsvgHandle           *handle,
                              const RsvgRectangle  *viewport,
                              GError              **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_render_document (handle, cr, viewport, error);
 }
 
@@ -1338,8 +1294,6 @@ rsvg_handle_get_geometry_for_layer (RsvgHandle     *handle,
                                     RsvgRectangle  *out_logical_rect,
                                     GError        **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_get_geometry_for_layer (handle,
                                                     id,
                                                     viewport,
@@ -1389,8 +1343,6 @@ rsvg_handle_render_layer (RsvgHandle           *handle,
                           const RsvgRectangle  *viewport,
                           GError              **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_render_layer (handle, cr, id, viewport, error);
 }
 
@@ -1448,8 +1400,6 @@ rsvg_handle_get_geometry_for_element (RsvgHandle     *handle,
                                       RsvgRectangle  *out_logical_rect,
                                       GError        **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_get_geometry_for_element (handle,
                                                       id,
                                                       out_ink_rect,
@@ -1499,8 +1449,6 @@ rsvg_handle_render_element (RsvgHandle           *handle,
                             const RsvgRectangle  *element_viewport,
                             GError              **error)
 {
-    g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
-
     return rsvg_rust_handle_render_element (handle, cr, id, element_viewport, error);
 }
 
@@ -1515,8 +1463,6 @@ rsvg_handle_render_element (RsvgHandle           *handle,
 void
 rsvg_handle_internal_set_testing (RsvgHandle *handle, gboolean testing)
 {
-    g_return_if_fail (RSVG_IS_HANDLE (handle));
-
     rsvg_rust_handle_set_testing (handle, testing);
 }
 
diff --git a/tests/api.c b/tests/api.c
index cd043350..783f9309 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -1355,6 +1355,37 @@ return_if_fail (void)
     g_test_trap_assert_stderr ("*rsvg_handle_set_base_uri*assertion*failed*");
 }
 
+static void
+return_if_fail_null_check (void)
+{
+    if (g_test_subprocess ()) {
+        /* Pass NULL as an argument, incorrectly... */
+        g_assert_null (rsvg_handle_get_base_uri (NULL));
+    }
+
+    g_test_trap_subprocess (NULL, 0, 0);
+    /* ... and here we catch that it was validated */
+    g_test_trap_assert_stderr ("*rsvg_handle_get_base_uri*assertion*handle*failed*");
+}
+
+static void
+return_if_fail_type_check (void)
+{
+    if (g_test_subprocess ()) {
+        /* Create a random GObject that is not an RsvgHandle... */
+        GInputStream *stream = g_memory_input_stream_new();
+
+        /* Feed it to an RsvgHandle function so it will bail out */
+        g_assert_null (rsvg_handle_get_base_uri ((RsvgHandle *) stream));
+
+        g_object_unref (stream);
+    }
+
+    g_test_trap_subprocess (NULL, 0, 0);
+    /* ... and here we catch that it was validated */
+    g_test_trap_assert_stderr ("*rsvg_handle_get_base_uri*assertion*handle*failed*");
+}
+
 int
 main (int argc, char **argv)
 {
@@ -1404,6 +1435,8 @@ main (int argc, char **argv)
     g_test_add_func ("/api/property_dimensions", property_dimensions);
     g_test_add_func ("/api/property_deprecated", property_deprecated);
     g_test_add_func ("/api/return_if_fail", return_if_fail);
+    g_test_add_func ("/api/return_if_fail_null_check", return_if_fail_null_check);
+    g_test_add_func ("/api/return_if_fail_type_check", return_if_fail_type_check);
 
     return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]