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

Revise pyobject_* macro exports #158

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(specialization, proc_macro)]
#![feature(specialization, proc_macro, fn_must_use)]
Copy link
Member

Choose a reason for hiding this comment

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

This might be because you're nightly is an older one. Re-adding this gives a warning on recent nightlies:

warning: this feature has been stable since 1.27.0. Attribute no longer needed
 --> src/lib.rs:1:40
  |
1 | #![feature(specialization, proc_macro, fn_must_use)]
  |                                        ^^^^^^^^^^^
  |
  = note: #[warn(stable_features)] on by default

I've just increased the minimum required version to 1.27.0, so this should be caught by the build script in the future.


//! Rust bindings to the Python interpreter.
//!
Expand Down
2 changes: 1 addition & 1 deletion src/objects/boolobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use conversion::{ToPyObject, IntoPyObject, ToBorrowedObject, PyTryFrom};
/// Represents a Python `bool`.
pub struct PyBool(PyObject);

pyobject_native_type!(PyBool, PyBool_Type, PyBool_Check);
pyobject_native_type!(PyBool, ffi::PyBool_Type, ffi::PyBool_Check);


impl PyBool {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/bytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use err::{PyResult, PyErr};
/// Represents a Python `bytearray`.
pub struct PyByteArray(PyObject);

pyobject_native_type!(PyByteArray, PyByteArray_Type, PyByteArray_Check);
pyobject_native_type!(PyByteArray, ffi::PyByteArray_Type, ffi::PyByteArray_Check);

impl PyByteArray {
/// Creates a new Python bytearray object.
Expand Down
2 changes: 1 addition & 1 deletion src/objects/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use err::{self, PyResult, PyErr};
/// Represents a Python `dict`.
pub struct PyDict(PyObject);

pyobject_native_type!(PyDict, PyDict_Type, PyDict_Check);
pyobject_native_type!(PyDict, ffi::PyDict_Type, ffi::PyDict_Check);


impl PyDict {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/floatob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use conversion::{ToPyObject, IntoPyObject};
/// with `f32`/`f64`.
pub struct PyFloat(PyObject);

pyobject_native_type!(PyFloat, PyFloat_Type, PyFloat_Check);
pyobject_native_type!(PyFloat, ffi::PyFloat_Type, ffi::PyFloat_Check);


impl PyFloat {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use conversion::{ToPyObject, IntoPyObject, ToBorrowedObject};
/// Represents a Python `list`.
pub struct PyList(PyObject);

pyobject_native_type!(PyList, PyList_Type, PyList_Check);
pyobject_native_type!(PyList, ffi::PyList_Type, ffi::PyList_Check);

impl PyList {
/// Construct a new list with the given elements.
Expand Down
50 changes: 25 additions & 25 deletions src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ pub use self::num2::{PyInt, PyLong};
/// parameter
#[macro_export]
macro_rules! pyobject_downcast(
($name: ident, $checkfunction: ident) => (
($name: ident, $checkfunction: path) => (
impl<'a> $crate::FromPyObject<'a> for &'a $name
{
/// Extracts `Self` from the source `PyObject`.
#[cfg_attr(feature = "cargo-clippy", allow(useless_transmute))]
fn extract(ob: &'a $crate::PyObjectRef) -> $crate::PyResult<Self>
{
unsafe {
if $crate::ffi::$checkfunction(ob.as_ptr()) != 0 {
Ok($crate::std::mem::transmute(ob))
if $checkfunction(ob.as_ptr()) != 0 {
Ok(::std::mem::transmute(ob))
} else {
Err($crate::PyDowncastError.into())
}
Expand All @@ -59,10 +59,10 @@ macro_rules! pyobject_native_type_named(
($name: ident) => {
impl $crate::PyNativeType for $name {}

impl $crate::std::convert::AsRef<$crate::PyObjectRef> for $name {
impl ::std::convert::AsRef<$crate::PyObjectRef> for $name {
Copy link
Member

Choose a reason for hiding this comment

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

Does ::std have an advantage over $crate::std?

#[cfg_attr(feature = "cargo-clippy", allow(useless_transmute))]
fn as_ref(&self) -> &$crate::PyObjectRef {
unsafe{$crate::std::mem::transmute(self)}
unsafe{::std::mem::transmute(self)}
}
}

Expand All @@ -73,7 +73,7 @@ macro_rules! pyobject_native_type_named(
}
}

impl $crate::python::ToPyPointer for $name {
impl $crate::ToPyPointer for $name {
/// Gets the underlying FFI pointer, returns a borrowed pointer.
#[inline]
fn as_ptr(&self) -> *mut $crate::ffi::PyObject {
Expand All @@ -92,39 +92,39 @@ macro_rules! pyobject_native_type_named(

#[macro_export]
macro_rules! pyobject_native_type(
($name: ident, $typeobject: ident, $checkfunction: ident) => {
($name: ident, $typeobject: expr, $checkfunction: path) => {
pyobject_native_type_named!($name);
pyobject_native_type_convert!($name, $typeobject, $checkfunction);
pyobject_downcast!($name, $checkfunction);

impl<'a> $crate::std::convert::From<&'a $name> for &'a $crate::PyObjectRef {
impl<'a> ::std::convert::From<&'a $name> for &'a $crate::PyObjectRef {
fn from(ob: &'a $name) -> Self {
unsafe{$crate::std::mem::transmute(ob)}
unsafe{::std::mem::transmute(ob)}
}
}
};
);

#[macro_export]
macro_rules! pyobject_native_type_convert(
($name: ident, $typeobject: ident, $checkfunction: ident) => {
($name: ident, $typeobject: expr, $checkfunction: path) => {
impl $crate::typeob::PyTypeInfo for $name {
type Type = ();
type BaseType = $crate::PyObjectRef;

const NAME: &'static str = stringify!($name);
const SIZE: usize = $crate::std::mem::size_of::<$crate::ffi::PyObject>();
const SIZE: usize = ::std::mem::size_of::<$crate::ffi::PyObject>();
const OFFSET: isize = 0;

#[inline]
unsafe fn type_object() -> &'static mut $crate::ffi::PyTypeObject {
&mut $crate::ffi::$typeobject
&mut $typeobject
}

#[cfg_attr(feature = "cargo-clippy", allow(not_unsafe_ptr_arg_deref))]
fn is_instance(ptr: *mut $crate::ffi::PyObject) -> bool {
#[allow(unused_unsafe)]
unsafe { $crate::ffi::$checkfunction(ptr) > 0 }
unsafe { $checkfunction(ptr) > 0 }
}
}

Expand Down Expand Up @@ -156,22 +156,22 @@ macro_rules! pyobject_native_type_convert(
}
}

impl $crate::std::fmt::Debug for $name {
fn fmt(&self, f: &mut $crate::std::fmt::Formatter)
-> Result<(), $crate::std::fmt::Error>
impl ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error>
{
use $crate::ObjectProtocol;
let s = try!(self.repr().map_err(|_| $crate::std::fmt::Error));
let s = try!(self.repr().map_err(|_| ::std::fmt::Error));
f.write_str(&s.to_string_lossy())
}
}

impl $crate::std::fmt::Display for $name {
fn fmt(&self, f: &mut $crate::std::fmt::Formatter)
-> Result<(), $crate::std::fmt::Error>
impl ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error>
{
use $crate::ObjectProtocol;
let s = try!(self.str().map_err(|_| $crate::std::fmt::Error));
let s = try!(self.str().map_err(|_| ::std::fmt::Error));
f.write_str(&s.to_string_lossy())
}
}
Expand All @@ -193,7 +193,7 @@ macro_rules! pyobject_extract(
}

#[cfg(feature = "try_from")]
impl<'source> $crate::std::convert::TryFrom<&'source $crate::PyObjectRef> for $t
impl<'source> ::std::convert::TryFrom<&'source $crate::PyObjectRef> for $t
{
type Error = $crate::PyErr;

Expand All @@ -208,14 +208,14 @@ macro_rules! pyobject_extract(
}
);


use ffi;
use python::ToPyPointer;

/// Represents general python instance.
pub struct PyObjectRef(::PyObject);
pyobject_native_type_named!(PyObjectRef);
pyobject_native_type_convert!(PyObjectRef, PyBaseObject_Type, PyObject_Check);
pyobject_downcast!(PyObjectRef, PyObject_Check);
pyobject_native_type_convert!(PyObjectRef, ffi::PyBaseObject_Type, ffi::PyObject_Check);
pyobject_downcast!(PyObjectRef, ffi::PyObject_Check);

mod typeobject;
mod module;
Expand Down
2 changes: 1 addition & 1 deletion src/objects/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use err::{PyResult, PyErr};
/// Represents a Python `module` object.
pub struct PyModule(PyObject);

pyobject_native_type!(PyModule, PyModule_Type, PyModule_Check);
pyobject_native_type!(PyModule, ffi::PyModule_Type, ffi::PyModule_Check);


impl PyModule {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/num3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use conversion::{ToPyObject, IntoPyObject, FromPyObject};
/// with the primitive Rust integer types.
pub struct PyLong(PyObject);

pyobject_native_type!(PyLong, PyLong_Type, PyLong_Check);
pyobject_native_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check);


macro_rules! int_fits_c_long(
Expand Down
2 changes: 1 addition & 1 deletion src/objects/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use objectprotocol::ObjectProtocol;
/// Represents a reference to a python object supporting the sequence protocol.
pub struct PySequence(PyObject);
pyobject_native_type_named!(PySequence);
pyobject_downcast!(PySequence, PySequence_Check);
pyobject_downcast!(PySequence, ffi::PySequence_Check);


#[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))]
Expand Down
4 changes: 2 additions & 2 deletions src/objects/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub struct PySet(PyObject);
/// Represents a Python `frozenset`
pub struct PyFrozenSet(PyObject);


pyobject_native_type!(PySet, PySet_Type, PySet_Check);pyobject_native_type!(PyFrozenSet, PyFrozenSet_Type, PyFrozenSet_Check);
pyobject_native_type!(PySet, ffi::PySet_Type, ffi::PySet_Check);
pyobject_native_type!(PyFrozenSet, ffi::PyFrozenSet_Type, ffi::PyFrozenSet_Check);

impl PySet {
/// Creates a new set.
Expand Down
2 changes: 1 addition & 1 deletion src/objects/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use conversion::ToPyObject;
/// Only `c_long` indeces supprted at the moment by `PySlice` object.
pub struct PySlice(PyObject);

pyobject_native_type!(PySlice, PySlice_Type, PySlice_Check);
pyobject_native_type!(PySlice, ffi::PySlice_Type, ffi::PySlice_Check);


/// Represents a Python `slice` indices
Expand Down
4 changes: 2 additions & 2 deletions src/objects/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::PyStringData;
/// Represents a Python `string`.
pub struct PyString(PyObject);

pyobject_native_type!(PyString, PyUnicode_Type, PyUnicode_Check);
pyobject_native_type!(PyString, ffi::PyUnicode_Type, ffi::PyUnicode_Check);

/// Represents a Python `unicode string`.
/// Corresponds to `unicode` in Python 2, and `str` in Python 3.
Expand All @@ -25,7 +25,7 @@ pub use PyString as PyUnicode;
/// Represents a Python `byte` string.
pub struct PyBytes(PyObject);

pyobject_native_type!(PyBytes, PyBytes_Type, PyBytes_Check);
pyobject_native_type!(PyBytes, ffi::PyBytes_Type, ffi::PyBytes_Check);


impl PyString {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::exc;
/// Represents a Python `tuple` object.
pub struct PyTuple(PyObject);

pyobject_native_type!(PyTuple, PyTuple_Type, PyTuple_Check);
pyobject_native_type!(PyTuple, ffi::PyTuple_Type, ffi::PyTuple_Check);


impl PyTuple {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/typeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use typeob::{PyTypeInfo, PyTypeObject};
/// Represents a reference to a Python `type object`.
pub struct PyType(PyObject);

pyobject_native_type!(PyType, PyType_Type, PyType_Check);
pyobject_native_type!(PyType, ffi::PyType_Type, ffi::PyType_Check);


impl PyType {
Expand Down