Skip to content

Commit f4c7003

Browse files
committed
replace std:: with core:: in ffi crate
1 parent 65d6a36 commit f4c7003

89 files changed

Lines changed: 233 additions & 233 deletions

Some content is hidden

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

pyo3-ffi/src/abstract_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use crate::object::*;
22
use crate::pyport::Py_ssize_t;
3+
use core::ffi::{c_char, c_int};
34
#[cfg(any(Py_3_12, not(Py_LIMITED_API)))]
45
use libc::size_t;
5-
use std::ffi::{c_char, c_int};
66

77
#[inline]
88
#[cfg(all(
99
not(Py_3_13), // CPython exposed as a function in 3.13, in object.h
1010
not(all(PyPy, not(Py_3_11))) // PyPy exposed as a function until PyPy 3.10, macro in 3.11+
1111
))]
1212
pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int {
13-
PyObject_SetAttrString(o, attr_name, std::ptr::null_mut())
13+
PyObject_SetAttrString(o, attr_name, core::ptr::null_mut())
1414
}
1515

1616
#[inline]
@@ -19,7 +19,7 @@ pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char)
1919
not(all(PyPy, not(Py_3_11))) // PyPy exposed as a function until PyPy 3.10, macro in 3.11+
2020
))]
2121
pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_int {
22-
PyObject_SetAttr(o, attr_name, std::ptr::null_mut())
22+
PyObject_SetAttr(o, attr_name, core::ptr::null_mut())
2323
}
2424

2525
extern_libpython! {
@@ -86,7 +86,7 @@ extern_libpython! {
8686

8787
#[cfg(any(Py_3_12, not(Py_LIMITED_API)))]
8888
pub const PY_VECTORCALL_ARGUMENTS_OFFSET: size_t = (1 as size_t)
89-
.checked_shl((8 * std::mem::size_of::<size_t>() - 1) as u32)
89+
.checked_shl((8 * core::mem::size_of::<size_t>() - 1) as u32)
9090
.expect("size_t should fit the flag bits");
9191

9292
extern_libpython! {

pyo3-ffi/src/boolobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(all(not(GraalPy), not(all(Py_3_13, Py_LIMITED_API))))]
22
use crate::longobject::PyLongObject;
33
use crate::object::*;
4-
use std::ffi::{c_int, c_long};
4+
use core::ffi::{c_int, c_long};
55

66
#[inline]
77
#[cfg(not(RustPython))]

pyo3-ffi/src/bytearrayobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::object::*;
22
use crate::pyport::Py_ssize_t;
3-
use std::ffi::{c_char, c_int};
3+
use core::ffi::{c_char, c_int};
44

55
#[cfg(not(RustPython))]
66
extern_libpython! {

pyo3-ffi/src/bytesobject.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::object::*;
22
use crate::pyport::Py_ssize_t;
3-
use std::ffi::{c_char, c_int};
3+
use core::ffi::{c_char, c_int};
44

55
#[cfg(not(RustPython))]
66
extern_libpython! {

pyo3-ffi/src/ceval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::object::PyObject;
22
use crate::pytypedefs::PyThreadState;
3-
use std::ffi::{c_char, c_int, c_void};
3+
use core::ffi::{c_char, c_int, c_void};
44

55
extern_libpython! {
66
#[cfg_attr(PyPy, link_name = "PyPyEval_EvalCode")]
@@ -39,7 +39,7 @@ extern_libpython! {
3939
#[inline]
4040
pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut PyObject {
4141
#[allow(deprecated)]
42-
PyEval_CallObjectWithKeywords(func, arg, std::ptr::null_mut())
42+
PyEval_CallObjectWithKeywords(func, arg, core::ptr::null_mut())
4343
}
4444

4545
extern_libpython! {

pyo3-ffi/src/codecs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::object::PyObject;
2-
use std::ffi::{c_char, c_int};
2+
use core::ffi::{c_char, c_int};
33

44
extern_libpython! {
55
pub fn PyCodec_Register(search_function: *mut PyObject) -> c_int;

pyo3-ffi/src/compat/py_3_10.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ compat_function!(
2424
#[inline]
2525
pub unsafe fn PyModule_AddObjectRef(
2626
module: *mut crate::PyObject,
27-
name: *const std::ffi::c_char,
27+
name: *const core::ffi::c_char,
2828
value: *mut crate::PyObject,
29-
) -> std::ffi::c_int {
29+
) -> core::ffi::c_int {
3030
if value.is_null() && crate::PyErr_Occurred().is_null() {
3131
crate::PyErr_SetString(
3232
crate::PyExc_SystemError,

pyo3-ffi/src/compat/py_3_13.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ compat_function!(
66
dp: *mut crate::PyObject,
77
key: *mut crate::PyObject,
88
result: *mut *mut crate::PyObject,
9-
) -> std::ffi::c_int {
9+
) -> core::ffi::c_int {
1010
use crate::{compat::Py_NewRef, PyDict_GetItemWithError, PyErr_Occurred};
1111

1212
let item = PyDict_GetItemWithError(dp, key);
1313
if !item.is_null() {
1414
*result = Py_NewRef(item);
1515
return 1; // found
1616
}
17-
*result = std::ptr::null_mut();
17+
*result = core::ptr::null_mut();
1818
if PyErr_Occurred().is_null() {
1919
return 0; // not found
2020
}
@@ -43,7 +43,7 @@ compat_function!(
4343

4444
#[inline]
4545
pub unsafe fn PyImport_AddModuleRef(
46-
name: *const std::ffi::c_char,
46+
name: *const core::ffi::c_char,
4747
) -> *mut crate::PyObject {
4848
use crate::{compat::Py_XNewRef, PyImport_AddModule};
4949

@@ -58,25 +58,25 @@ compat_function!(
5858
pub unsafe fn PyWeakref_GetRef(
5959
reference: *mut crate::PyObject,
6060
pobj: *mut *mut crate::PyObject,
61-
) -> std::ffi::c_int {
61+
) -> core::ffi::c_int {
6262
use crate::{
6363
compat::Py_NewRef, PyErr_SetString, PyExc_TypeError, PyWeakref_Check,
6464
PyWeakref_GetObject, Py_None,
6565
};
6666

6767
if !reference.is_null() && PyWeakref_Check(reference) == 0 {
68-
*pobj = std::ptr::null_mut();
68+
*pobj = core::ptr::null_mut();
6969
PyErr_SetString(PyExc_TypeError, c"expected a weakref".as_ptr());
7070
return -1;
7171
}
7272
let obj = PyWeakref_GetObject(reference);
7373
if obj.is_null() {
7474
// SystemError if reference is NULL
75-
*pobj = std::ptr::null_mut();
75+
*pobj = core::ptr::null_mut();
7676
return -1;
7777
}
7878
if obj == Py_None() {
79-
*pobj = std::ptr::null_mut();
79+
*pobj = core::ptr::null_mut();
8080
return 0;
8181
}
8282
*pobj = Py_NewRef(obj);
@@ -91,7 +91,7 @@ compat_function!(
9191
pub unsafe fn PyList_Extend(
9292
list: *mut crate::PyObject,
9393
iterable: *mut crate::PyObject,
94-
) -> std::ffi::c_int {
94+
) -> core::ffi::c_int {
9595
crate::PyList_SetSlice(list, crate::PY_SSIZE_T_MAX, crate::PY_SSIZE_T_MAX, iterable)
9696
}
9797
);
@@ -100,8 +100,8 @@ compat_function!(
100100
originally_defined_for(Py_3_13);
101101

102102
#[inline]
103-
pub unsafe fn PyList_Clear(list: *mut crate::PyObject) -> std::ffi::c_int {
104-
crate::PyList_SetSlice(list, 0, crate::PY_SSIZE_T_MAX, std::ptr::null_mut())
103+
pub unsafe fn PyList_Clear(list: *mut crate::PyObject) -> core::ffi::c_int {
104+
crate::PyList_SetSlice(list, 0, crate::PY_SSIZE_T_MAX, core::ptr::null_mut())
105105
}
106106
);
107107

@@ -111,9 +111,9 @@ compat_function!(
111111
#[inline]
112112
pub unsafe fn PyModule_Add(
113113
module: *mut crate::PyObject,
114-
name: *const std::ffi::c_char,
114+
name: *const core::ffi::c_char,
115115
value: *mut crate::PyObject,
116-
) -> std::ffi::c_int {
116+
) -> core::ffi::c_int {
117117
let result = crate::compat::PyModule_AddObjectRef(module, name, value);
118118
crate::Py_XDECREF(value);
119119
result
@@ -140,16 +140,16 @@ compat_function!(
140140
key: *mut crate::PyObject,
141141
default_value: *mut crate::PyObject,
142142
result: *mut *mut crate::PyObject,
143-
) -> std::ffi::c_int {
143+
) -> core::ffi::c_int {
144144
use crate::{
145145
compat::{PyDict_GetItemRef, Py_NewRef},
146146
PyDict_SetItem, PyObject, Py_DECREF,
147147
};
148-
let mut value: *mut PyObject = std::ptr::null_mut();
148+
let mut value: *mut PyObject = core::ptr::null_mut();
149149
if PyDict_GetItemRef(mp, key, &mut value) < 0 {
150150
// get error
151151
if !result.is_null() {
152-
*result = std::ptr::null_mut();
152+
*result = core::ptr::null_mut();
153153
}
154154
return -1;
155155
}
@@ -167,7 +167,7 @@ compat_function!(
167167
if PyDict_SetItem(mp, key, default_value) < 0 {
168168
// set error
169169
if !result.is_null() {
170-
*result = std::ptr::null_mut();
170+
*result = core::ptr::null_mut();
171171
}
172172
return -1;
173173
}
@@ -186,15 +186,15 @@ compat_function!(
186186
obj: *mut crate::PyObject,
187187
name: *mut crate::PyObject,
188188
result: *mut *mut crate::PyObject,
189-
) -> std::ffi::c_int {
189+
) -> core::ffi::c_int {
190190
use crate::{PyErr_Clear, PyErr_ExceptionMatches, PyExc_AttributeError, PyObject_GetAttr};
191191

192192
let attr = PyObject_GetAttr(obj, name);
193193
if !attr.is_null() {
194194
*result = attr;
195195
return 1; // found
196196
}
197-
*result = std::ptr::null_mut();
197+
*result = core::ptr::null_mut();
198198
if PyErr_ExceptionMatches(PyExc_AttributeError) != 0 {
199199
PyErr_Clear();
200200
return 0; // not found
@@ -207,8 +207,8 @@ compat_function!(
207207
originally_defined_for(Py_3_13);
208208

209209
#[inline]
210-
pub unsafe fn PyObject_HasAttrWithError(obj: *mut crate::PyObject, attr_name: *mut crate::PyObject) -> std::ffi::c_int {
211-
let mut res: *mut crate::PyObject = std::ptr::null_mut();
210+
pub unsafe fn PyObject_HasAttrWithError(obj: *mut crate::PyObject, attr_name: *mut crate::PyObject) -> core::ffi::c_int {
211+
let mut res: *mut crate::PyObject = core::ptr::null_mut();
212212
let rc = crate::compat::PyObject_GetOptionalAttr(obj, attr_name, &mut res);
213213
crate::Py_XDECREF(res);
214214
rc

pyo3-ffi/src/compat/py_3_14.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ compat_function!(
33

44
#[inline]
55
pub unsafe fn Py_HashBuffer(
6-
ptr: *const std::ffi::c_void,
6+
ptr: *const core::ffi::c_void,
77
len: crate::Py_ssize_t,
88
) -> crate::Py_hash_t {
99
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
@@ -13,7 +13,7 @@ compat_function!(
1313

1414
#[cfg(any(Py_LIMITED_API, PyPy))]
1515
{
16-
let bytes = crate::PyBytes_FromStringAndSize(ptr as *const std::ffi::c_char, len);
16+
let bytes = crate::PyBytes_FromStringAndSize(ptr as *const core::ffi::c_char, len);
1717
if bytes.is_null() {
1818
-1
1919
} else {
@@ -32,7 +32,7 @@ compat_function!(
3232
pub unsafe fn PyIter_NextItem(
3333
iter: *mut crate::PyObject,
3434
item: *mut *mut crate::PyObject,
35-
) -> std::ffi::c_int {
35+
) -> core::ffi::c_int {
3636
*item = crate::PyIter_Next(iter);
3737
if !(*item).is_null() {
3838
1

pyo3-ffi/src/compat/py_3_15.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ compat_function!(
1212

1313
if size < 0 {
1414
crate::PyErr_SetString(crate::PyExc_ValueError, c"size must be >= 0".as_ptr() as *const _);
15-
return std::ptr::null_mut();
15+
return core::ptr::null_mut();
1616
}
1717

18-
let writer: *mut PyBytesWriter = crate::PyMem_Malloc(std::mem::size_of::<PyBytesWriter>()).cast();
18+
let writer: *mut PyBytesWriter = crate::PyMem_Malloc(core::mem::size_of::<PyBytesWriter>()).cast();
1919
if writer.is_null() {
2020
crate::PyErr_NoMemory();
21-
return std::ptr::null_mut();
21+
return core::ptr::null_mut();
2222
}
2323

24-
(*writer).obj = std::ptr::null_mut();
24+
(*writer).obj = core::ptr::null_mut();
2525
(*writer).size = 0;
2626

2727
if size >=1 {
2828
if _PyBytesWriter_Resize_impl(writer, size, 0) < 0 {
2929
PyBytesWriter_Discard(writer);
30-
return std::ptr::null_mut();
30+
return core::ptr::null_mut();
3131
}
3232

3333
(*writer).size = size;
@@ -75,9 +75,9 @@ compat_function!(
7575
} else {
7676
if size != crate::PyBytes_Size((*writer).obj) && crate::_PyBytes_Resize(&mut (*writer).obj, size) < 0 {
7777
PyBytesWriter_Discard(writer);
78-
return std::ptr::null_mut();
78+
return core::ptr::null_mut();
7979
}
80-
std::mem::replace(&mut (*writer).obj, std::ptr::null_mut())
80+
core::mem::replace(&mut (*writer).obj, core::ptr::null_mut())
8181
};
8282

8383
PyBytesWriter_Discard(writer);
@@ -90,7 +90,7 @@ compat_function!(
9090
originally_defined_for(all(Py_3_15, not(Py_LIMITED_API)));
9191

9292
#[inline]
93-
pub unsafe fn PyBytesWriter_GetData(writer: *mut PyBytesWriter) -> *mut std::ffi::c_void {
93+
pub unsafe fn PyBytesWriter_GetData(writer: *mut PyBytesWriter) -> *mut core::ffi::c_void {
9494
if (*writer).obj.is_null() {
9595
(*writer).small_buffer.as_ptr() as *mut _
9696
} else {
@@ -114,7 +114,7 @@ compat_function!(
114114
originally_defined_for(all(Py_3_15, not(Py_LIMITED_API)));
115115

116116
#[inline]
117-
pub unsafe fn PyBytesWriter_Resize(writer: *mut PyBytesWriter, size: crate::Py_ssize_t) -> std::ffi::c_int {
117+
pub unsafe fn PyBytesWriter_Resize(writer: *mut PyBytesWriter, size: crate::Py_ssize_t) -> core::ffi::c_int {
118118
if size < 0 {
119119
crate::PyErr_SetString(crate::PyExc_ValueError, c"size must be >= 0".as_ptr());
120120
return -1;
@@ -130,7 +130,7 @@ compat_function!(
130130
#[repr(C)]
131131
#[cfg(not(any(Py_3_15, Py_LIMITED_API)))]
132132
pub struct PyBytesWriter {
133-
small_buffer: [std::ffi::c_char; 256],
133+
small_buffer: [core::ffi::c_char; 256],
134134
obj: *mut crate::PyObject,
135135
size: crate::Py_ssize_t,
136136
}
@@ -140,13 +140,13 @@ pub struct PyBytesWriter {
140140
unsafe fn _PyBytesWriter_Resize_impl(
141141
writer: *mut PyBytesWriter,
142142
mut size: crate::Py_ssize_t,
143-
resize: std::ffi::c_int,
144-
) -> std::ffi::c_int {
143+
resize: core::ffi::c_int,
144+
) -> core::ffi::c_int {
145145
let overallocate = resize;
146146
assert!(size >= 0);
147147

148148
let allocated = if (*writer).obj.is_null() {
149-
std::mem::size_of_val(&(*writer).small_buffer) as _
149+
core::mem::size_of_val(&(*writer).small_buffer) as _
150150
} else {
151151
crate::PyBytes_Size((*writer).obj)
152152
};
@@ -173,18 +173,18 @@ unsafe fn _PyBytesWriter_Resize_impl(
173173
}
174174
assert!(!(*writer).obj.is_null())
175175
} else {
176-
(*writer).obj = crate::PyBytes_FromStringAndSize(std::ptr::null_mut(), size);
176+
(*writer).obj = crate::PyBytes_FromStringAndSize(core::ptr::null_mut(), size);
177177
if (*writer).obj.is_null() {
178178
return -1;
179179
}
180180

181181
if resize > 0 {
182-
assert!((size as usize) > std::mem::size_of_val(&(*writer).small_buffer));
182+
assert!((size as usize) > core::mem::size_of_val(&(*writer).small_buffer));
183183

184-
std::ptr::copy_nonoverlapping(
184+
core::ptr::copy_nonoverlapping(
185185
(*writer).small_buffer.as_ptr(),
186186
crate::PyBytes_AS_STRING((*writer).obj) as *mut _,
187-
std::mem::size_of_val(&(*writer).small_buffer),
187+
core::mem::size_of_val(&(*writer).small_buffer),
188188
);
189189
}
190190
}

0 commit comments

Comments
 (0)