From dd20e00c778cd76a12d7dfd0334e73dbc4b88634 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 9 Mar 2015 14:31:20 +0100 Subject: [PATCH] Update for rust beta. --- Cargo.toml | 6 ++---- src/conversion.rs | 3 ++- src/err.rs | 4 ++-- src/lib.rs | 4 ++-- src/objects/object.rs | 5 +++-- src/objects/tuple.rs | 4 ++-- test.sh | 2 +- testmodule.rs | 8 ++++---- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4065c53b..5f0fd364 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,6 @@ description = "Bindings to Python 2.7" authors = ["Daniel Grunwald "] [dependencies] -python27-sys="0.0.3" - -#[dependencies.python27-sys] -#path = "../python27-sys" +python27-sys="*" +libc="*" diff --git a/src/conversion.rs b/src/conversion.rs index d5c52610..d036de37 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -101,7 +101,7 @@ impl <'p, 's, T> FromPyObject<'p, 's> for T where T: PythonObjectWithCheckedDown // We support FromPyObject and ToPyObject for borrowed python references. // This allows using existing python objects in code that generically expects a value // convertible to a python object. - +/* impl <'p, 's, T> ToPyObject<'p> for &'s T where T : ToPyObject<'p> { type ObjectType = >::ObjectType; @@ -121,4 +121,5 @@ impl <'p, 's, T> ToPyObject<'p> for &'s T where T : ToPyObject<'p> { (**self).with_borrowed_ptr(py, f) } } +*/ diff --git a/src/err.rs b/src/err.rs index 46e16b4b..937f1497 100644 --- a/src/err.rs +++ b/src/err.rs @@ -189,8 +189,8 @@ impl <'p> PyErr<'p> { } } -impl <'p> std::error::FromError> for PyErr<'p> { - fn from_error(err: PythonObjectDowncastError<'p>) -> PyErr<'p> { +impl <'p> std::convert::From> for PyErr<'p> { + fn from(err: PythonObjectDowncastError<'p>) -> PyErr<'p> { PyErr::new_lazy_init(err.0.get_type::(), None) } } diff --git a/src/lib.rs b/src/lib.rs index 1b375adf..c6137711 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,13 @@ #![feature(core)] -#![feature(libc)] #![feature(unsafe_destructor)] #![feature(unsafe_no_drop_flag)] #![feature(optin_builtin_traits)] +#![feature(slice_patterns)] #![allow(unused_imports, dead_code, unused_variables)] extern crate core; // NonZero is not exposed in std? extern crate libc; -extern crate "python27-sys" as ffi; +extern crate python27_sys as ffi; pub use ffi::Py_ssize_t; pub use err::{PyErr, PyResult}; pub use objects::*; diff --git a/src/objects/object.rs b/src/objects/object.rs index 88894d93..5644d129 100644 --- a/src/objects/object.rs +++ b/src/objects/object.rs @@ -16,6 +16,7 @@ pub struct PyObject<'p> { #[unsafe_destructor] impl <'p> Drop for PyObject<'p> { + #[inline] fn drop(&mut self) { // TODO: change from Py_XDECREF to Py_DECREF when #[unsafe_no_drop_flag] disappears unsafe { ffi::Py_XDECREF(*self.ptr); } @@ -42,12 +43,12 @@ impl <'p> PythonObject<'p> for PyObject<'p> { } #[inline] - fn unchecked_downcast_from(o: PyObject<'p>) -> PyObject<'p> { + unsafe fn unchecked_downcast_from(o: PyObject<'p>) -> PyObject<'p> { o } #[inline] - fn unchecked_downcast_borrow_from<'a>(o: &'a PyObject<'p>) -> &'a PyObject<'p> { + unsafe fn unchecked_downcast_borrow_from<'a>(o: &'a PyObject<'p>) -> &'a PyObject<'p> { o } diff --git a/src/objects/tuple.rs b/src/objects/tuple.rs index dda1dbba..88661347 100644 --- a/src/objects/tuple.rs +++ b/src/objects/tuple.rs @@ -59,9 +59,9 @@ impl<'p> std::ops::Index for PyTuple<'p> { type Output = PyObject<'p>; #[inline] - fn index<'a>(&'a self, index: &usize) -> &'a PyObject<'p> { + fn index<'a>(&'a self, index: usize) -> &'a PyObject<'p> { // use as_slice() to use the normal Rust bounds checking when indexing - &self.as_slice()[*index] + &self.as_slice()[index] } } diff --git a/test.sh b/test.sh index 86c5c0dc..19cef42a 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash set -xeu cargo build -rustc testmodule.rs -L target -L target/deps -o testmodule.so +rustc testmodule.rs -L target/debug -L target/debug/deps -o testmodule.so python -c "import testmodule; print(repr(testmodule.__author__))" diff --git a/testmodule.rs b/testmodule.rs index 69c9b737..1a87b2e3 100644 --- a/testmodule.rs +++ b/testmodule.rs @@ -7,6 +7,7 @@ extern crate "python27-sys" as py27; use cpython::{PyModule, PyResult, Python}; +/* py_module_initializer!("testmodule", inittestmodule, |py, m| { println!("in initializer"); //try!(m.add(cstr!("__doc__"), "Module documentation string")); @@ -14,8 +15,8 @@ py_module_initializer!("testmodule", inittestmodule, |py, m| { //try!(m.add(cstr!("__version__"), "0.0.1")); Ok(()) }); +*/ -/* #[no_mangle] pub extern "C" fn inittestmodule() { //abort_on_panic!({ @@ -28,10 +29,9 @@ pub extern "C" fn inittestmodule() { } fn init(py : Python) -> PyResult<()> { - //let m : &PyModule = try!(py.init_module("testmodule", None)); - unsafe { py27::Py_InitModule(cstr!("testmodule").as_ptr(), std::ptr::null_mut()) }; + let m : &PyModule = try!(py.init_module("testmodule", None)); + //unsafe { py27::Py_InitModule(cstr!("testmodule").as_ptr(), std::ptr::null_mut()) }; println!("init_module done"); Ok(()) } -*/