Merge pull request #2062 from davidhewitt/more-pointer-casts

misc: remove some more *const -> *mut pointer casts
This commit is contained in:
David Hewitt 2021-12-20 21:14:45 +00:00 committed by GitHub
commit 8a989eeb6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 7 deletions

View File

@ -41,7 +41,11 @@ impl<T: PyTypeInfo> PyObjectInit<T> for PyNativeTypeInitializer<T> {
let type_object = T::type_object_raw(py);
// HACK (due to FIXME below): PyBaseObject_Type's tp_new isn't happy with NULL arguments
if type_object == (&ffi::PyBaseObject_Type as *const _ as *mut _) {
#[cfg(addr_of)]
let is_base_object = type_object == std::ptr::addr_of_mut!(ffi::PyBaseObject_Type);
#[cfg(not(addr_of))]
let is_base_object = type_object == &mut ffi::PyBaseObject_Type as _;
if is_base_object {
let alloc = get_tp_alloc(subtype).unwrap_or(ffi::PyType_GenericAlloc);
let obj = alloc(subtype, 0);
return if obj.is_null() {

View File

@ -9,7 +9,7 @@ use crate::types::{PyAny, PyDict, PyModule, PyType};
use crate::{ffi, AsPyPointer, FromPyPointer, IntoPyPointer, PyNativeType, PyObject, PyTryFrom};
use std::ffi::{CStr, CString};
use std::marker::PhantomData;
use std::os::raw::{c_char, c_int};
use std::os::raw::c_int;
/// Represents the major, minor, and patch (if any) versions of this interpreter.
///
@ -537,7 +537,7 @@ impl<'py> Python<'py> {
/// ```
pub fn version(self) -> &'py str {
unsafe {
CStr::from_ptr(ffi::Py_GetVersion() as *const c_char)
CStr::from_ptr(ffi::Py_GetVersion())
.to_str()
.expect("Python version string not UTF-8")
}

View File

@ -55,9 +55,9 @@ impl PyBufferProtocol for TestBufferErrors {
(*view).format = msg.as_ptr() as *mut _;
(*view).ndim = 1;
(*view).shape = (&((*view).len)) as *const _ as *mut _;
(*view).shape = &mut (*view).len;
(*view).strides = &((*view).itemsize) as *const _ as *mut _;
(*view).strides = &mut (*view).itemsize;
(*view).suboffsets = ptr::null_mut();
(*view).internal = ptr::null_mut();

View File

@ -54,12 +54,12 @@ impl PyBufferProtocol for TestBufferClass {
(*view).ndim = 1;
(*view).shape = ptr::null_mut();
if (flags & ffi::PyBUF_ND) == ffi::PyBUF_ND {
(*view).shape = (&((*view).len)) as *const _ as *mut _;
(*view).shape = &mut (*view).len;
}
(*view).strides = ptr::null_mut();
if (flags & ffi::PyBUF_STRIDES) == ffi::PyBUF_STRIDES {
(*view).strides = &((*view).itemsize) as *const _ as *mut _;
(*view).strides = &mut (*view).itemsize;
}
(*view).suboffsets = ptr::null_mut();