Skip to content

Commit 0d16923

Browse files
committed
Change some assertions to debug assertions
These assertions can only trigger because of bugs in the bindings implementation or in the C code and not because of bugs in calling code, so using debug assertions is perfectly fine for them and reduces the number of assertions inlined everywhere in release builds.
1 parent d9b569c commit 0d16923

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+201
-200
lines changed

cairo/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,20 @@ impl Drop for Context {
136136
impl Context {
137137
#[inline]
138138
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_t) -> Context {
139-
assert!(!ptr.is_null());
139+
debug_assert!(!ptr.is_null());
140140
ffi::cairo_reference(ptr);
141141
Context(ptr::NonNull::new_unchecked(ptr))
142142
}
143143

144144
#[inline]
145145
pub unsafe fn from_raw_borrow(ptr: *mut ffi::cairo_t) -> crate::Borrowed<Context> {
146-
assert!(!ptr.is_null());
146+
debug_assert!(!ptr.is_null());
147147
crate::Borrowed::new(Context(ptr::NonNull::new_unchecked(ptr)))
148148
}
149149

150150
#[inline]
151151
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_t) -> Context {
152-
assert!(!ptr.is_null());
152+
debug_assert!(!ptr.is_null());
153153
Context(ptr::NonNull::new_unchecked(ptr))
154154
}
155155

cairo/src/device.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ pub struct Device(ptr::NonNull<ffi::cairo_device_t>);
3434
impl Device {
3535
#[inline]
3636
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_device_t) -> Device {
37-
assert!(!ptr.is_null());
37+
debug_assert!(!ptr.is_null());
3838
ffi::cairo_device_reference(ptr);
3939
Device(ptr::NonNull::new_unchecked(ptr))
4040
}
4141

4242
#[inline]
4343
pub unsafe fn from_raw_borrow(ptr: *mut ffi::cairo_device_t) -> crate::Borrowed<Device> {
44-
assert!(!ptr.is_null());
44+
debug_assert!(!ptr.is_null());
4545
crate::Borrowed::new(Device(ptr::NonNull::new_unchecked(ptr)))
4646
}
4747

4848
#[inline]
4949
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_device_t) -> Device {
50-
assert!(!ptr.is_null());
50+
debug_assert!(!ptr.is_null());
5151
Device(ptr::NonNull::new_unchecked(ptr))
5252
}
5353

cairo/src/font/font_face.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl FontFace {
114114
#[cfg(not(feature = "use_glib"))]
115115
#[inline]
116116
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_font_face_t) -> FontFace {
117-
assert!(!ptr.is_null());
117+
debug_assert!(!ptr.is_null());
118118
FontFace(ptr::NonNull::new_unchecked(ptr))
119119
}
120120

@@ -127,7 +127,7 @@ impl FontFace {
127127
#[cfg(not(feature = "use_glib"))]
128128
#[inline]
129129
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_font_face_t) -> FontFace {
130-
assert!(!ptr.is_null());
130+
debug_assert!(!ptr.is_null());
131131
FontFace(ptr::NonNull::new_unchecked(ptr))
132132
}
133133

cairo/src/font/font_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl FontOptions {
6060
#[cfg(not(feature = "use_glib"))]
6161
#[inline]
6262
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_font_options_t) -> Self {
63-
assert!(!ptr.is_null());
63+
debug_assert!(!ptr.is_null());
6464
Self(ptr::NonNull::new_unchecked(ptr))
6565
}
6666

cairo/src/font/scaled_font.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl ScaledFont {
6565
#[cfg(not(feature = "use_glib"))]
6666
#[inline]
6767
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_scaled_font_t) -> ScaledFont {
68-
assert!(!ptr.is_null());
68+
debug_assert!(!ptr.is_null());
6969
ScaledFont(ptr::NonNull::new_unchecked(ptr))
7070
}
7171

@@ -84,7 +84,7 @@ impl ScaledFont {
8484
#[cfg(not(feature = "use_glib"))]
8585
#[inline]
8686
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_scaled_font_t) -> ScaledFont {
87-
assert!(!ptr.is_null());
87+
debug_assert!(!ptr.is_null());
8888
ffi::cairo_scaled_font_reference(ptr);
8989
ScaledFont(ptr::NonNull::new_unchecked(ptr))
9090
}

cairo/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ macro_rules! gvalue_impl {
4646
let ptr = glib::gobject_ffi::g_value_dup_boxed(
4747
glib::translate::ToGlibPtr::to_glib_none(value).0,
4848
);
49-
assert!(!ptr.is_null());
49+
debug_assert!(!ptr.is_null());
5050
<$name as glib::translate::FromGlibPtrFull<*mut $ffi_name>>::from_glib_full(
5151
ptr as *mut $ffi_name,
5252
)
@@ -57,14 +57,14 @@ macro_rules! gvalue_impl {
5757
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
5858

5959
unsafe fn from_value(value: &'a glib::Value) -> Self {
60-
assert_eq!(
60+
debug_assert_eq!(
6161
std::mem::size_of::<Self>(),
6262
std::mem::size_of::<glib::ffi::gpointer>()
6363
);
6464
let value = &*(value as *const glib::Value as *const glib::gobject_ffi::GValue);
6565
let ptr = &value.data[0].v_pointer as *const glib::ffi::gpointer
6666
as *const *const $ffi_name;
67-
assert!(!(*ptr).is_null());
67+
debug_assert!(!(*ptr).is_null());
6868
&*(ptr as *const $name)
6969
}
7070
}
@@ -129,7 +129,7 @@ macro_rules! gvalue_impl_inline {
129129
let ptr = glib::gobject_ffi::g_value_get_boxed(
130130
glib::translate::ToGlibPtr::to_glib_none(value).0,
131131
);
132-
assert!(!ptr.is_null());
132+
debug_assert!(!ptr.is_null());
133133
<$name as glib::translate::FromGlibPtrNone<*mut $ffi_name>>::from_glib_none(
134134
ptr as *mut $ffi_name,
135135
)
@@ -143,7 +143,7 @@ macro_rules! gvalue_impl_inline {
143143
let ptr = glib::gobject_ffi::g_value_get_boxed(
144144
glib::translate::ToGlibPtr::to_glib_none(value).0,
145145
);
146-
assert!(!ptr.is_null());
146+
debug_assert!(!ptr.is_null());
147147
&*(ptr as *mut $name)
148148
}
149149
}

cairo/src/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Path {
1515

1616
#[inline]
1717
pub unsafe fn from_raw_full(pointer: *mut cairo_path_t) -> Path {
18-
assert!(!pointer.is_null());
18+
debug_assert!(!pointer.is_null());
1919
Path(ptr::NonNull::new_unchecked(pointer))
2020
}
2121

cairo/src/region.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,20 @@ impl Eq for Region {}
113113
impl Region {
114114
#[inline]
115115
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_region_t) -> Region {
116-
assert!(!ptr.is_null());
116+
debug_assert!(!ptr.is_null());
117117
ffi::cairo_region_reference(ptr);
118118
Region(ptr::NonNull::new_unchecked(ptr))
119119
}
120120

121121
#[inline]
122122
pub unsafe fn from_raw_borrow(ptr: *mut ffi::cairo_region_t) -> crate::Borrowed<Region> {
123-
assert!(!ptr.is_null());
123+
debug_assert!(!ptr.is_null());
124124
crate::Borrowed::new(Region(ptr::NonNull::new_unchecked(ptr)))
125125
}
126126

127127
#[inline]
128128
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_region_t) -> Region {
129-
assert!(!ptr.is_null());
129+
debug_assert!(!ptr.is_null());
130130
Region(ptr::NonNull::new_unchecked(ptr))
131131
}
132132

cairo/src/surface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ pub struct Surface(ptr::NonNull<ffi::cairo_surface_t>);
2121
impl Surface {
2222
#[inline]
2323
pub unsafe fn from_raw_none(ptr: *mut ffi::cairo_surface_t) -> Surface {
24-
assert!(!ptr.is_null());
24+
debug_assert!(!ptr.is_null());
2525
ffi::cairo_surface_reference(ptr);
2626
Surface(ptr::NonNull::new_unchecked(ptr))
2727
}
2828

2929
#[inline]
3030
pub unsafe fn from_raw_borrow(ptr: *mut ffi::cairo_surface_t) -> crate::Borrowed<Surface> {
31-
assert!(!ptr.is_null());
31+
debug_assert!(!ptr.is_null());
3232
crate::Borrowed::new(Surface(ptr::NonNull::new_unchecked(ptr)))
3333
}
3434

3535
#[inline]
3636
pub unsafe fn from_raw_full(ptr: *mut ffi::cairo_surface_t) -> Result<Surface, Error> {
37-
assert!(!ptr.is_null());
37+
debug_assert!(!ptr.is_null());
3838
let status = ffi::cairo_surface_status(ptr);
3939
status_to_result(status)?;
4040
Ok(Surface(ptr::NonNull::new_unchecked(ptr)))

cairo/src/xcb.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ impl XCBConnection {
5353

5454
#[inline]
5555
pub unsafe fn from_raw_none(ptr: *mut ffi::xcb_connection_t) -> XCBConnection {
56-
assert!(!ptr.is_null());
56+
debug_assert!(!ptr.is_null());
5757
XCBConnection(ptr::NonNull::new_unchecked(ptr))
5858
}
5959

6060
#[inline]
6161
pub unsafe fn from_raw_borrow(ptr: *mut ffi::xcb_connection_t) -> Borrowed<XCBConnection> {
62-
assert!(!ptr.is_null());
62+
debug_assert!(!ptr.is_null());
6363
Borrowed::new(XCBConnection(ptr::NonNull::new_unchecked(ptr)))
6464
}
6565

6666
#[inline]
6767
pub unsafe fn from_raw_full(ptr: *mut ffi::xcb_connection_t) -> XCBConnection {
68-
assert!(!ptr.is_null());
68+
debug_assert!(!ptr.is_null());
6969
XCBConnection(ptr::NonNull::new_unchecked(ptr))
7070
}
7171
}
@@ -129,21 +129,21 @@ impl XCBRenderPictFormInfo {
129129

130130
#[inline]
131131
pub unsafe fn from_raw_none(ptr: *mut ffi::xcb_render_pictforminfo_t) -> XCBRenderPictFormInfo {
132-
assert!(!ptr.is_null());
132+
debug_assert!(!ptr.is_null());
133133
XCBRenderPictFormInfo(ptr::NonNull::new_unchecked(ptr))
134134
}
135135

136136
#[inline]
137137
pub unsafe fn from_raw_borrow(
138138
ptr: *mut ffi::xcb_render_pictforminfo_t,
139139
) -> Borrowed<XCBRenderPictFormInfo> {
140-
assert!(!ptr.is_null());
140+
debug_assert!(!ptr.is_null());
141141
Borrowed::new(XCBRenderPictFormInfo(ptr::NonNull::new_unchecked(ptr)))
142142
}
143143

144144
#[inline]
145145
pub unsafe fn from_raw_full(ptr: *mut ffi::xcb_render_pictforminfo_t) -> XCBRenderPictFormInfo {
146-
assert!(!ptr.is_null());
146+
debug_assert!(!ptr.is_null());
147147
XCBRenderPictFormInfo(ptr::NonNull::new_unchecked(ptr))
148148
}
149149
}
@@ -211,19 +211,19 @@ impl XCBScreen {
211211

212212
#[inline]
213213
pub unsafe fn from_raw_none(ptr: *mut ffi::xcb_screen_t) -> XCBScreen {
214-
assert!(!ptr.is_null());
214+
debug_assert!(!ptr.is_null());
215215
XCBScreen(ptr::NonNull::new_unchecked(ptr))
216216
}
217217

218218
#[inline]
219219
pub unsafe fn from_raw_borrow(ptr: *mut ffi::xcb_screen_t) -> Borrowed<XCBScreen> {
220-
assert!(!ptr.is_null());
220+
debug_assert!(!ptr.is_null());
221221
Borrowed::new(XCBScreen(ptr::NonNull::new_unchecked(ptr)))
222222
}
223223

224224
#[inline]
225225
pub unsafe fn from_raw_full(ptr: *mut ffi::xcb_screen_t) -> XCBScreen {
226-
assert!(!ptr.is_null());
226+
debug_assert!(!ptr.is_null());
227227
XCBScreen(ptr::NonNull::new_unchecked(ptr))
228228
}
229229
}
@@ -378,19 +378,19 @@ impl XCBVisualType {
378378

379379
#[inline]
380380
pub unsafe fn from_raw_none(ptr: *mut ffi::xcb_visualtype_t) -> XCBVisualType {
381-
assert!(!ptr.is_null());
381+
debug_assert!(!ptr.is_null());
382382
XCBVisualType(ptr::NonNull::new_unchecked(ptr))
383383
}
384384

385385
#[inline]
386386
pub unsafe fn from_raw_borrow(ptr: *mut ffi::xcb_visualtype_t) -> Borrowed<XCBVisualType> {
387-
assert!(!ptr.is_null());
387+
debug_assert!(!ptr.is_null());
388388
Borrowed::new(XCBVisualType(ptr::NonNull::new_unchecked(ptr)))
389389
}
390390

391391
#[inline]
392392
pub unsafe fn from_raw_full(ptr: *mut ffi::xcb_visualtype_t) -> XCBVisualType {
393-
assert!(!ptr.is_null());
393+
debug_assert!(!ptr.is_null());
394394
XCBVisualType(ptr::NonNull::new_unchecked(ptr))
395395
}
396396
}

0 commit comments

Comments
 (0)