pyo3/testmodule.rs

38 lines
900 B
Rust
Raw Normal View History

2015-01-05 16:05:53 +00:00
#![crate_type = "dylib"]
2015-01-12 02:00:34 +00:00
#[macro_use] extern crate cpython;
extern crate "python27-sys" as py27;
//extern crate libc;
2015-01-05 16:05:53 +00:00
use cpython::{PyModule, PyResult, Python};
2015-01-12 02:00:34 +00:00
py_module_initializer!("testmodule", inittestmodule, |py, m| {
println!("in initializer");
//try!(m.add(cstr!("__doc__"), "Module documentation string"));
//try!(m.add(cstr!("__author__"), "Daniel Grunwald"));
//try!(m.add(cstr!("__version__"), "0.0.1"));
Ok(())
});
/*
2015-01-05 16:05:53 +00:00
#[no_mangle]
pub extern "C" fn inittestmodule() {
//abort_on_panic!({
let py = unsafe { Python::assume_gil_acquired() };
if let Err(e) = init(py) {
2015-01-12 02:00:34 +00:00
println!("Restore error");
2015-01-05 16:05:53 +00:00
e.restore()
}
//})
}
fn init(py : Python) -> PyResult<()> {
2015-01-12 02:00:34 +00:00
//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(())
2015-01-05 16:05:53 +00:00
}
2015-01-12 02:00:34 +00:00
*/
2015-01-05 16:05:53 +00:00