Update for rust beta.

This commit is contained in:
Daniel Grunwald 2015-03-09 14:31:20 +01:00
parent 913f3ea2e5
commit dd20e00c77
8 changed files with 18 additions and 18 deletions

View File

@ -6,8 +6,6 @@ description = "Bindings to Python 2.7"
authors = ["Daniel Grunwald <daniel@danielgrunwald.de>"] authors = ["Daniel Grunwald <daniel@danielgrunwald.de>"]
[dependencies] [dependencies]
python27-sys="0.0.3" python27-sys="*"
libc="*"
#[dependencies.python27-sys]
#path = "../python27-sys"

View File

@ -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. // We support FromPyObject and ToPyObject for borrowed python references.
// This allows using existing python objects in code that generically expects a value // This allows using existing python objects in code that generically expects a value
// convertible to a python object. // convertible to a python object.
/*
impl <'p, 's, T> ToPyObject<'p> for &'s T where T : ToPyObject<'p> { impl <'p, 's, T> ToPyObject<'p> for &'s T where T : ToPyObject<'p> {
type ObjectType = <T as ToPyObject<'p>>::ObjectType; type ObjectType = <T as ToPyObject<'p>>::ObjectType;
@ -121,4 +121,5 @@ impl <'p, 's, T> ToPyObject<'p> for &'s T where T : ToPyObject<'p> {
(**self).with_borrowed_ptr(py, f) (**self).with_borrowed_ptr(py, f)
} }
} }
*/

View File

@ -189,8 +189,8 @@ impl <'p> PyErr<'p> {
} }
} }
impl <'p> std::error::FromError<PythonObjectDowncastError<'p>> for PyErr<'p> { impl <'p> std::convert::From<PythonObjectDowncastError<'p>> for PyErr<'p> {
fn from_error(err: PythonObjectDowncastError<'p>) -> PyErr<'p> { fn from(err: PythonObjectDowncastError<'p>) -> PyErr<'p> {
PyErr::new_lazy_init(err.0.get_type::<exc::TypeError>(), None) PyErr::new_lazy_init(err.0.get_type::<exc::TypeError>(), None)
} }
} }

View File

@ -1,13 +1,13 @@
#![feature(core)] #![feature(core)]
#![feature(libc)]
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
#![feature(unsafe_no_drop_flag)] #![feature(unsafe_no_drop_flag)]
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(slice_patterns)]
#![allow(unused_imports, dead_code, unused_variables)] #![allow(unused_imports, dead_code, unused_variables)]
extern crate core; // NonZero is not exposed in std? extern crate core; // NonZero is not exposed in std?
extern crate libc; extern crate libc;
extern crate "python27-sys" as ffi; extern crate python27_sys as ffi;
pub use ffi::Py_ssize_t; pub use ffi::Py_ssize_t;
pub use err::{PyErr, PyResult}; pub use err::{PyErr, PyResult};
pub use objects::*; pub use objects::*;

View File

@ -16,6 +16,7 @@ pub struct PyObject<'p> {
#[unsafe_destructor] #[unsafe_destructor]
impl <'p> Drop for PyObject<'p> { impl <'p> Drop for PyObject<'p> {
#[inline]
fn drop(&mut self) { fn drop(&mut self) {
// TODO: change from Py_XDECREF to Py_DECREF when #[unsafe_no_drop_flag] disappears // TODO: change from Py_XDECREF to Py_DECREF when #[unsafe_no_drop_flag] disappears
unsafe { ffi::Py_XDECREF(*self.ptr); } unsafe { ffi::Py_XDECREF(*self.ptr); }
@ -42,12 +43,12 @@ impl <'p> PythonObject<'p> for PyObject<'p> {
} }
#[inline] #[inline]
fn unchecked_downcast_from(o: PyObject<'p>) -> PyObject<'p> { unsafe fn unchecked_downcast_from(o: PyObject<'p>) -> PyObject<'p> {
o o
} }
#[inline] #[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 o
} }

View File

@ -59,9 +59,9 @@ impl<'p> std::ops::Index<usize> for PyTuple<'p> {
type Output = PyObject<'p>; type Output = PyObject<'p>;
#[inline] #[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 // use as_slice() to use the normal Rust bounds checking when indexing
&self.as_slice()[*index] &self.as_slice()[index]
} }
} }

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -xeu set -xeu
cargo build 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__))" python -c "import testmodule; print(repr(testmodule.__author__))"

View File

@ -7,6 +7,7 @@ extern crate "python27-sys" as py27;
use cpython::{PyModule, PyResult, Python}; use cpython::{PyModule, PyResult, Python};
/*
py_module_initializer!("testmodule", inittestmodule, |py, m| { py_module_initializer!("testmodule", inittestmodule, |py, m| {
println!("in initializer"); println!("in initializer");
//try!(m.add(cstr!("__doc__"), "Module documentation string")); //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")); //try!(m.add(cstr!("__version__"), "0.0.1"));
Ok(()) Ok(())
}); });
*/
/*
#[no_mangle] #[no_mangle]
pub extern "C" fn inittestmodule() { pub extern "C" fn inittestmodule() {
//abort_on_panic!({ //abort_on_panic!({
@ -28,10 +29,9 @@ pub extern "C" fn inittestmodule() {
} }
fn init(py : Python) -> PyResult<()> { fn init(py : Python) -> PyResult<()> {
//let m : &PyModule = try!(py.init_module("testmodule", None)); let m : &PyModule = try!(py.init_module("testmodule", None));
unsafe { py27::Py_InitModule(cstr!("testmodule").as_ptr(), std::ptr::null_mut()) }; //unsafe { py27::Py_InitModule(cstr!("testmodule").as_ptr(), std::ptr::null_mut()) };
println!("init_module done"); println!("init_module done");
Ok(()) Ok(())
} }
*/