Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect documentation and assume pointer is not null in GlobalAlloc::dealloc #144

Merged
merged 3 commits into from
Dec 11, 2019
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
6 changes: 2 additions & 4 deletions jemalloc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,13 @@ extern "C" {
///
/// This makes the space available for future allocations.
///
/// If `ptr` is null, no action occurs.
///
/// # Safety
///
/// The behavior is _undefined_ if:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to add to these lists that the behavior is undefined if the pointer is null in both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ffdcf7

///
/// * `ptr` does not match a pointer earlier returned by the memory
/// allocation functions of this crate, or
/// * `ptr` is null, or
/// * the memory region referenced by `ptr` has been deallocated.
#[cfg_attr(prefixed, link_name = "_rjem_dallocx")]
pub fn dallocx(ptr: *mut c_void, flags: c_int);
Expand All @@ -383,8 +382,6 @@ extern "C" {
///
/// This makes the space available for future allocations.
///
/// If `ptr` is null, no action occurs.
///
/// # Safety
///
/// The behavior is _undefined_ if:
Expand All @@ -395,6 +392,7 @@ extern "C" {
/// [`xallocx`],
/// * `ptr` does not match a pointer earlier returned by the memory
/// allocation functions of this crate, or
/// * `ptr` is null, or
/// * the memory region referenced by `ptr` has been deallocated.
#[cfg_attr(prefixed, link_name = "_rjem_sdallocx")]
pub fn sdallocx(ptr: *mut c_void, size: size_t, flags: c_int);
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ unsafe impl GlobalAlloc for Jemalloc {

#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
assume!(!ptr.is_null())
assume!(layout.size() != 0);
let flags = layout_to_flags(layout.align(), layout.size());
ffi::sdallocx(ptr as *mut c_void, layout.size(), flags)
Expand Down