Update for rust beta.
This commit is contained in:
parent
913f3ea2e5
commit
dd20e00c77
|
@ -6,8 +6,6 @@ description = "Bindings to Python 2.7"
|
|||
authors = ["Daniel Grunwald <daniel@danielgrunwald.de>"]
|
||||
|
||||
[dependencies]
|
||||
python27-sys="0.0.3"
|
||||
|
||||
#[dependencies.python27-sys]
|
||||
#path = "../python27-sys"
|
||||
python27-sys="*"
|
||||
libc="*"
|
||||
|
||||
|
|
|
@ -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 = <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)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -189,8 +189,8 @@ impl <'p> PyErr<'p> {
|
|||
}
|
||||
}
|
||||
|
||||
impl <'p> std::error::FromError<PythonObjectDowncastError<'p>> for PyErr<'p> {
|
||||
fn from_error(err: PythonObjectDowncastError<'p>) -> PyErr<'p> {
|
||||
impl <'p> std::convert::From<PythonObjectDowncastError<'p>> for PyErr<'p> {
|
||||
fn from(err: PythonObjectDowncastError<'p>) -> PyErr<'p> {
|
||||
PyErr::new_lazy_init(err.0.get_type::<exc::TypeError>(), None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -59,9 +59,9 @@ impl<'p> std::ops::Index<usize> 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]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
test.sh
2
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__))"
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue