Created
March 28, 2019 19:37
-
-
Save konstin/ee00d9aaae44117dbae6f4f5eb2998eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs | |
index 1e522989..3cb04f5d 100644 | |
--- a/src/ffi/datetime.rs | |
+++ b/src/ffi/datetime.rs | |
@@ -6,15 +6,15 @@ | |
//! and covers the various date and time related objects in the Python `datetime` | |
//! standard library module. | |
-use crate::ffi::PyCapsule_Import; | |
use crate::ffi::Py_hash_t; | |
use crate::ffi::{PyObject, PyTypeObject}; | |
use crate::ffi::{PyObject_TypeCheck, Py_TYPE}; | |
-use std::ffi::CString; | |
use std::ops::Deref; | |
use std::os::raw::{c_char, c_int, c_uchar}; | |
use std::ptr; | |
use std::sync::Once; | |
+#[cfg(not(PyPy))] | |
+use {crate::ffi::PyCapsule_Import, std::ffi::CString}; | |
// A note regarding cpyext support: | |
// Some macros, like `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as separate symbols. | |
@@ -338,7 +338,7 @@ pub unsafe fn PyTZInfo_CheckExact(op: *mut PyObject) -> c_int { | |
} | |
/// Accessor functions | |
-/// | |
+#[cfg(not(PyPy))] | |
macro_rules! _access_field { | |
($obj:expr, $type: ident, $field:tt) => { | |
(*($obj as *mut $type)).$field | |
@@ -375,24 +375,28 @@ pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int { | |
} | |
// Accessor macros for times | |
+#[cfg(not(PyPy))] | |
macro_rules! _PyDateTime_GET_HOUR { | |
($o: expr, $offset:expr) => { | |
c_int::from((*$o).data[$offset + 0]) | |
}; | |
} | |
+#[cfg(not(PyPy))] | |
macro_rules! _PyDateTime_GET_MINUTE { | |
($o: expr, $offset:expr) => { | |
c_int::from((*$o).data[$offset + 1]) | |
}; | |
} | |
+#[cfg(not(PyPy))] | |
macro_rules! _PyDateTime_GET_SECOND { | |
($o: expr, $offset:expr) => { | |
c_int::from((*$o).data[$offset + 2]) | |
}; | |
} | |
+#[cfg(not(PyPy))] | |
macro_rules! _PyDateTime_GET_MICROSECOND { | |
($o: expr, $offset:expr) => { | |
(c_int::from((*$o).data[$offset + 3]) << 16) | |
@@ -402,12 +406,14 @@ macro_rules! _PyDateTime_GET_MICROSECOND { | |
} | |
#[cfg(Py_3_6)] | |
+#[cfg(not(PyPy))] | |
macro_rules! _PyDateTime_GET_FOLD { | |
($o: expr) => { | |
(*$o).fold | |
}; | |
} | |
+#[cfg(not(PyPy))] | |
macro_rules! _PyDateTime_GET_TZINFO { | |
($o: expr) => { | |
(*$o).tzinfo | |
@@ -500,7 +506,7 @@ pub unsafe fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int { | |
_PyDateTime_GET_MICROSECOND!((o as *mut PyDateTime_Time), 0) | |
} | |
-#[cfg(Py_3_6)] | |
+#[cfg(all(Py_3_6, not(PyPy)))] | |
#[inline] | |
/// Retrieve the fold component of a `PyDateTime_Time`. | |
/// Returns a signed integer in the interval `[0, 1]` | |
@@ -520,6 +526,7 @@ pub unsafe fn PyDateTime_TIME_GET_TZINFO(o: *mut PyObject) -> *mut PyObject { | |
} | |
// Accessor functions for PyDateTime_Delta | |
+#[cfg(not(PyPy))] | |
macro_rules! _access_delta_field { | |
($obj:expr, $field:tt) => { | |
_access_field!($obj, PyDateTime_Delta, $field) | |
diff --git a/src/ffi3/descrobject.rs b/src/ffi3/descrobject.rs | |
index ce8f9d9e..05af23b0 100644 | |
--- a/src/ffi3/descrobject.rs | |
+++ b/src/ffi3/descrobject.rs | |
@@ -1,7 +1,7 @@ | |
use crate::ffi3::methodobject::PyMethodDef; | |
-use crate::ffi3::object::{ | |
- PyObject, PyObject_GenericGetDict, PyObject_GenericSetDict, PyTypeObject, | |
-}; | |
+use crate::ffi3::object::{PyObject, PyTypeObject}; | |
+#[cfg(not(PyPy))] | |
+use crate::ffi3::object::{PyObject_GenericGetDict, PyObject_GenericSetDict}; | |
use crate::ffi3::structmember::PyMemberDef; | |
use std::os::raw::{c_char, c_int, c_void}; | |
use std::ptr; | |
diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs | |
index cba419ce..9c90bf91 100644 | |
--- a/src/ffi3/object.rs | |
+++ b/src/ffi3/object.rs | |
@@ -1,4 +1,5 @@ | |
use crate::ffi3::pyport::{Py_hash_t, Py_ssize_t}; | |
+#[cfg(PyPy)] | |
use std::ffi::CStr; | |
use std::mem; | |
use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; | |
diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs | |
index d2a52062..bc12572e 100644 | |
--- a/src/ffi3/pyerrors.rs | |
+++ b/src/ffi3/pyerrors.rs | |
@@ -1,6 +1,8 @@ | |
use crate::ffi3::object::*; | |
+#[cfg(PyPy)] | |
use crate::ffi3::objectabstract::PyObject_CallFunction; | |
use crate::ffi3::pyport::Py_ssize_t; | |
+#[cfg(PyPy)] | |
use std::ffi::CStr; | |
use std::os::raw::{c_char, c_int}; | |
@@ -84,7 +86,7 @@ pub unsafe fn PyUnicodeDecodeError_Create( | |
length: Py_ssize_t, | |
start: Py_ssize_t, | |
end: Py_ssize_t, | |
- reason: *const c_char, | |
+ _reason: *const c_char, | |
) -> *mut PyObject { | |
return PyObject_CallFunction( | |
PyExc_UnicodeDecodeError, | |
diff --git a/src/types/datetime.rs b/src/types/datetime.rs | |
index 8a6e504c..207c4c5a 100644 | |
--- a/src/types/datetime.rs | |
+++ b/src/types/datetime.rs | |
@@ -9,10 +9,9 @@ use crate::err::PyResult; | |
use crate::ffi; | |
#[cfg(PyPy)] | |
use crate::ffi::datetime::{PyDateTime_FromTimestamp, PyDate_FromTimestamp}; | |
- | |
use crate::ffi::PyDateTimeAPI; | |
use crate::ffi::{PyDateTime_Check, PyDate_Check, PyDelta_Check, PyTZInfo_Check, PyTime_Check}; | |
-#[cfg(Py_3_6)] | |
+#[cfg(all(Py_3_6, not(PyPy)))] | |
use crate::ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; | |
use crate::ffi::{ | |
PyDateTime_DATE_GET_HOUR, PyDateTime_DATE_GET_MICROSECOND, PyDateTime_DATE_GET_MINUTE, | |
@@ -33,6 +32,7 @@ use crate::AsPyPointer; | |
use crate::Python; | |
use crate::ToPyObject; | |
use std::os::raw::c_int; | |
+#[cfg(not(PyPy))] | |
use std::ptr; | |
/// Access traits | |
@@ -61,7 +61,7 @@ pub trait PyTimeAccess { | |
fn get_minute(&self) -> u8; | |
fn get_second(&self) -> u8; | |
fn get_microsecond(&self) -> u32; | |
- #[cfg(Py_3_6)] | |
+ #[cfg(all(Py_3_6, not(PyPy)))] | |
fn get_fold(&self) -> u8; | |
} | |
@@ -213,7 +213,7 @@ impl PyTimeAccess for PyDateTime { | |
unsafe { PyDateTime_DATE_GET_MICROSECOND(self.as_ptr()) as u32 } | |
} | |
- #[cfg(Py_3_6)] | |
+ #[cfg(all(Py_3_6, not(PyPy)))] | |
fn get_fold(&self) -> u8 { | |
unsafe { PyDateTime_DATE_GET_FOLD(self.as_ptr()) as u8 } | |
} | |
@@ -290,7 +290,7 @@ impl PyTimeAccess for PyTime { | |
unsafe { PyDateTime_TIME_GET_MICROSECOND(self.as_ptr()) as u32 } | |
} | |
- #[cfg(Py_3_6)] | |
+ #[cfg(all(Py_3_6, not(PyPy)))] | |
fn get_fold(&self) -> u8 { | |
unsafe { PyDateTime_TIME_GET_FOLD(self.as_ptr()) as u8 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment