Use `::std` to fix #233
This commit is contained in:
parent
af68396c31
commit
c1cb5ca74f
|
@ -3,6 +3,8 @@
|
|||
#[macro_use]
|
||||
extern crate pyo3;
|
||||
|
||||
pub mod othermod;
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{
|
||||
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyDict, PyTime, PyTimeAccess,
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//! https://github.com/PyO3/pyo3/issues/233
|
||||
//!
|
||||
//! The code below just tries to use the most important code generation paths
|
||||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[pyclass]
|
||||
pub struct ModClass {
|
||||
_somefield: String,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl ModClass {
|
||||
fn noop(&self, x: usize) -> usize {
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn double(x: i32) -> i32 {
|
||||
x*2
|
||||
}
|
||||
|
||||
#[pymodinit]
|
||||
fn datetime(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_function!(double))?;
|
||||
m.add_class::<ModClass>()?;
|
||||
Ok(())
|
||||
}
|
|
@ -90,23 +90,23 @@ fn impl_class(
|
|||
self.#token.py()
|
||||
}
|
||||
}
|
||||
impl<'a> std::convert::From<&'a mut #cls> for &'a #cls
|
||||
impl<'a> ::std::convert::From<&'a mut #cls> for &'a #cls
|
||||
{
|
||||
fn from(ob: &'a mut #cls) -> Self {
|
||||
unsafe{std::mem::transmute(ob)}
|
||||
}
|
||||
}
|
||||
impl std::fmt::Debug for #cls {
|
||||
fn fmt(&self, f : &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
impl ::std::fmt::Debug for #cls {
|
||||
fn fmt(&self, f : &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
use ::pyo3::ObjectProtocol;
|
||||
let s = self.repr().map_err(|_| std::fmt::Error)?;
|
||||
let s = self.repr().map_err(|_| ::std::fmt::Error)?;
|
||||
f.write_str(&s.to_string_lossy())
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for #cls {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
impl ::std::fmt::Display for #cls {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
|
||||
use ::pyo3::ObjectProtocol;
|
||||
let s = self.str().map_err(|_| std::fmt::Error)?;
|
||||
let s = self.str().map_err(|_| ::std::fmt::Error)?;
|
||||
f.write_str(&s.to_string_lossy())
|
||||
}
|
||||
}
|
||||
|
@ -186,14 +186,14 @@ fn impl_class(
|
|||
|
||||
const SIZE: usize = {
|
||||
Self::OFFSET as usize +
|
||||
std::mem::size_of::<#cls>() + #weakref + #dict
|
||||
::std::mem::size_of::<#cls>() + #weakref + #dict
|
||||
};
|
||||
const OFFSET: isize = {
|
||||
// round base_size up to next multiple of align
|
||||
(
|
||||
(<#base as ::pyo3::typeob::PyTypeInfo>::SIZE +
|
||||
std::mem::align_of::<#cls>() - 1) /
|
||||
std::mem::align_of::<#cls>() * std::mem::align_of::<#cls>()
|
||||
::std::mem::align_of::<#cls>() - 1) /
|
||||
::std::mem::align_of::<#cls>() * ::std::mem::align_of::<#cls>()
|
||||
) as isize
|
||||
};
|
||||
|
||||
|
@ -207,7 +207,7 @@ fn impl_class(
|
|||
impl ::pyo3::typeob::PyTypeObject for #cls {
|
||||
#[inline]
|
||||
fn init_type() {
|
||||
static START: std::sync::Once = std::sync::ONCE_INIT;
|
||||
static START: ::std::sync::Once = ::std::sync::ONCE_INIT;
|
||||
START.call_once(|| {
|
||||
let ty = unsafe{<#cls as ::pyo3::typeob::PyTypeInfo>::type_object()};
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ pub fn impl_wrap_new(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> Token
|
|||
_args: *mut ::pyo3::ffi::PyObject,
|
||||
_kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject
|
||||
{
|
||||
use pyo3::typeob::PyTypeInfo;
|
||||
use ::pyo3::typeob::PyTypeInfo;
|
||||
|
||||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
let _pool = ::pyo3::GILPool::new();
|
||||
|
@ -307,7 +307,7 @@ pub fn impl_wrap_static(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> To
|
|||
pub(crate) fn impl_wrap_getter(cls: &syn::Type, name: &syn::Ident) -> TokenStream {
|
||||
quote! {
|
||||
unsafe extern "C" fn __wrap(
|
||||
_slf: *mut ::pyo3::ffi::PyObject, _: *mut std::os::raw::c_void) -> *mut ::pyo3::ffi::PyObject
|
||||
_slf: *mut ::pyo3::ffi::PyObject, _: *mut ::std::os::raw::c_void) -> *mut ::pyo3::ffi::PyObject
|
||||
{
|
||||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
|
||||
|
@ -339,7 +339,7 @@ pub(crate) fn impl_wrap_setter(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec
|
|||
#[allow(unused_mut)]
|
||||
unsafe extern "C" fn __wrap(
|
||||
_slf: *mut ::pyo3::ffi::PyObject,
|
||||
_value: *mut ::pyo3::ffi::PyObject, _: *mut std::os::raw::c_void) -> ::pyo3::libc::c_int
|
||||
_value: *mut ::pyo3::ffi::PyObject, _: *mut ::std::os::raw::c_void) -> ::pyo3::libc::c_int
|
||||
{
|
||||
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
|
||||
let _pool = ::pyo3::GILPool::new();
|
||||
|
|
Loading…
Reference in New Issue