Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions glib/src/collections/ptr_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,21 @@ impl<T: TransparentPtrType> PtrSlice<T> {
/// This is guaranteed to be `NULL`-terminated.
#[inline]
pub fn into_raw(mut self) -> *mut <T as GlibPtrDefault>::GlibType {
// Make sure to allocate a valid pointer that points to a
// NULL-pointer.
if self.len == 0 {
ptr::null_mut()
} else {
self.len = 0;
self.capacity = 0;
self.ptr.as_ptr()
self.reserve(0);
unsafe {
ptr::write(
self.ptr.as_ptr().add(0),
Ptr::from(ptr::null_mut::<<T as GlibPtrDefault>::GlibType>()),
);
}
}

self.len = 0;
self.capacity = 0;
self.ptr.as_ptr()
}

// rustdoc-stripper-ignore-next
Expand Down
6 changes: 0 additions & 6 deletions glib/src/collections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,6 @@ impl<T: TransparentType> Slice<T> {

// rustdoc-stripper-ignore-next
/// Returns the underlying pointer.
///
/// This is guaranteed to be `NULL`-terminated.
#[inline]
pub fn as_ptr(&self) -> *const T::GlibType {
if self.len == 0 {
Expand All @@ -559,8 +557,6 @@ impl<T: TransparentType> Slice<T> {

// rustdoc-stripper-ignore-next
/// Returns the underlying pointer.
///
/// This is guaranteed to be `NULL`-terminated.
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut T::GlibType {
if self.len == 0 {
Expand All @@ -572,8 +568,6 @@ impl<T: TransparentType> Slice<T> {

// rustdoc-stripper-ignore-next
/// Consumes the slice and returns the underlying pointer.
///
/// This is guaranteed to be `NULL`-terminated.
#[inline]
pub fn into_raw(mut self) -> *mut T::GlibType {
if self.len == 0 {
Expand Down
15 changes: 10 additions & 5 deletions glib/src/collections/strv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,18 @@ impl StrV {
/// This is guaranteed to be `NULL`-terminated.
#[inline]
pub fn into_raw(mut self) -> *mut *mut c_char {
// Make sure to allocate a valid pointer that points to a
// NULL-pointer.
if self.len == 0 {
ptr::null_mut()
} else {
self.len = 0;
self.capacity = 0;
self.ptr.as_ptr()
self.reserve(0);
unsafe {
*self.ptr.as_ptr().add(0) = ptr::null_mut();
}
}

self.len = 0;
self.capacity = 0;
self.ptr.as_ptr()
}

// rustdoc-stripper-ignore-next
Expand Down
Loading