pyo3/src/lib.rs

59 lines
1.5 KiB
Rust
Raw Normal View History

2015-01-12 02:17:29 +00:00
#![feature(core)]
#![feature(libc)]
2015-01-05 16:05:53 +00:00
#![feature(unsafe_destructor)]
2015-03-08 14:29:44 +00:00
#![feature(unsafe_no_drop_flag)]
2015-01-11 03:21:05 +00:00
#![feature(optin_builtin_traits)]
2015-01-05 16:05:53 +00:00
#![allow(unused_imports, dead_code, unused_variables)]
2015-01-12 02:17:29 +00:00
extern crate core; // NonZero is not exposed in std?
2015-01-05 16:05:53 +00:00
extern crate libc;
extern crate "python27-sys" as ffi;
2015-01-05 16:05:53 +00:00
pub use ffi::Py_ssize_t;
pub use err::{PyErr, PyResult};
2015-01-05 16:02:30 +00:00
pub use objects::*;
2015-01-05 15:34:12 +00:00
pub use python::{Python, PythonObject, PythonObjectWithCheckedDowncast, PythonObjectWithTypeObject};
2015-01-05 16:05:53 +00:00
pub use conversion::{FromPyObject, ToPyObject};
2015-01-04 20:37:43 +00:00
pub use objectprotocol::{ObjectProtocol};
2015-03-08 14:29:44 +00:00
pub use std::ffi::CStr;
#[macro_export]
macro_rules! cstr(
($s: tt) => (
// TODO: verify that $s is a string literal without nuls
unsafe {
::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _)
}
);
);
2015-01-05 16:05:53 +00:00
mod python;
mod err;
mod conversion;
2015-01-05 16:02:30 +00:00
mod objects;
2015-01-04 20:37:43 +00:00
mod objectprotocol;
2015-01-05 16:05:53 +00:00
mod pythonrun;
2015-01-12 02:00:34 +00:00
#[macro_export]
macro_rules! py_module_initializer {
($name: tt, $init_funcname: ident, $init: expr) => {
#[no_mangle]
pub extern "C" fn $init_funcname() {
let py = unsafe { $crate::Python::assume_gil_acquired() };
match $crate::PyModule::init(py, cstr!($name), $init) {
Ok(()) => (),
Err(e) => e.restore()
}
}
}
}
2015-01-05 16:05:53 +00:00
#[test]
fn it_works() {
2015-01-04 04:50:28 +00:00
let gil = Python::acquire_gil();
let py = gil.python();
2015-01-11 04:52:11 +00:00
let sys = PyModule::import(py, cstr!("sys")).unwrap();
2015-01-05 16:05:53 +00:00
let path = sys.as_object().getattr("path").unwrap();
println!("{0}", path);
}