Add fileobject, cobject and pycapsule headers

This commit is contained in:
Daniel Grunwald 2015-05-07 23:18:48 +02:00
parent bab3214595
commit b9b67ee932
5 changed files with 163 additions and 3 deletions

View File

@ -0,0 +1,15 @@
extern crate libc;
extern crate python27_sys;
unsafe fn get_str<'a>(s: *const libc::c_char) -> &'a str {
let bytes = std::ffi::CStr::from_ptr(s).to_bytes();
std::str::from_utf8(bytes).unwrap()
}
fn main() {
unsafe {
python27_sys::Py_Initialize();
println!("{}", get_str(python27_sys::Py_GetVersion()));
}
}

View File

@ -0,0 +1,37 @@
use libc::{c_void, c_char, c_int};
use object::*;
extern "C" {
pub static mut PyCObject_Type: PyTypeObject;
}
#[inline(always)]
pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyCObject_Type) as c_int
}
extern "C" {
pub fn PyCObject_FromVoidPtr(cobj: *mut c_void,
destruct:
Option<unsafe extern "C" fn
(arg1:
*mut c_void)>)
-> *mut PyObject;
pub fn PyCObject_FromVoidPtrAndDesc(cobj: *mut c_void,
desc: *mut c_void,
destruct:
Option<unsafe extern "C" fn
(arg1:
*mut c_void,
arg2:
*mut c_void)>)
-> *mut PyObject;
pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void;
pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void;
pub fn PyCObject_Import(module_name: *mut c_char,
cobject_name: *mut c_char)
-> *mut c_void;
pub fn PyCObject_SetVoidPtr(_self: *mut PyObject,
cobj: *mut c_void) -> c_int;
}

View File

@ -0,0 +1,61 @@
use libc::{c_char, c_int, size_t, FILE};
use object::*;
extern "C" {
pub static mut PyFile_Type: PyTypeObject;
}
#[inline(always)]
pub unsafe fn PyFile_Check(op : *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &mut PyFile_Type)
}
#[inline(always)]
pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyFile_Type) as c_int
}
pub const PY_STDIOTEXTMODE : &'static str = "b";
extern "C" {
pub fn PyFile_FromString(arg1: *mut c_char,
arg2: *mut c_char) -> *mut PyObject;
pub fn PyFile_SetBufSize(arg1: *mut PyObject, arg2: c_int);
pub fn PyFile_SetEncoding(arg1: *mut PyObject,
arg2: *const c_char) -> c_int;
pub fn PyFile_SetEncodingAndErrors(arg1: *mut PyObject,
arg2: *const c_char,
errors: *mut c_char)
-> c_int;
pub fn PyFile_FromFile(arg1: *mut FILE, arg2: *mut c_char,
arg3: *mut c_char,
arg4:
Option<unsafe extern "C" fn
(arg1: *mut FILE)
-> c_int>)
-> *mut PyObject;
pub fn PyFile_AsFile(arg1: *mut PyObject) -> *mut FILE;
//pub fn PyFile_IncUseCount(arg1: *mut PyFileObject);
//pub fn PyFile_DecUseCount(arg1: *mut PyFileObject);
pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int)
-> *mut PyObject;
pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: c_int) -> c_int;
pub fn PyFile_SoftSpace(arg1: *mut PyObject, arg2: c_int)
-> c_int;
pub fn PyFile_WriteString(arg1: *const c_char,
arg2: *mut PyObject) -> c_int;
pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int;
pub fn Py_UniversalNewlineFgets(arg1: *mut c_char,
arg2: c_int, arg3: *mut FILE,
arg4: *mut PyObject)
-> *mut c_char;
pub fn Py_UniversalNewlineFread(arg1: *mut c_char, arg2: size_t,
arg3: *mut FILE, arg4: *mut PyObject)
-> size_t;
pub static mut Py_FileSystemDefaultEncoding: *const c_char;
}

View File

@ -32,6 +32,10 @@ pub use methodobject::*;
pub use moduleobject::*; pub use moduleobject::*;
pub use funcobject::*; pub use funcobject::*;
pub use classobject::*; pub use classobject::*;
pub use fileobject::*;
pub use cobject::*;
pub use pycapsule::*;
pub use descrobject::*; pub use descrobject::*;
pub use warnings::*; pub use warnings::*;
pub use pyarena::*; pub use pyarena::*;
@ -71,9 +75,9 @@ mod methodobject;
mod moduleobject; mod moduleobject;
mod funcobject; mod funcobject;
mod classobject; mod classobject;
// mod fileobject; // TODO: incomplete mod fileobject;
// mod cobject; // TODO: incomplete mod cobject;
// mod pycapsule; // TODO: incomplete mod pycapsule;
// mod traceback; // TODO: incomplete // mod traceback; // TODO: incomplete
// mod sliceobject; // TODO: incomplete // mod sliceobject; // TODO: incomplete
// mod cellobject; // TODO: incomplete // mod cellobject; // TODO: incomplete

View File

@ -0,0 +1,43 @@
use libc::{c_void, c_char, c_int};
use object::*;
extern "C" {
pub static mut PyCapsule_Type: PyTypeObject;
}
pub type PyCapsule_Destructor = unsafe extern "C" fn(o: *mut PyObject);
#[inline]
pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == &mut PyCapsule_Type) as c_int
}
extern "C" {
pub fn PyCapsule_New(pointer: *mut c_void,
name: *const c_char,
destructor: Option<PyCapsule_Destructor>) -> *mut PyObject;
pub fn PyCapsule_GetPointer(capsule: *mut PyObject,
name: *const c_char)
-> *mut c_void;
pub fn PyCapsule_GetDestructor(capsule: *mut PyObject)
-> Option<PyCapsule_Destructor>;
pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char;
pub fn PyCapsule_GetContext(capsule: *mut PyObject)
-> *mut c_void;
pub fn PyCapsule_IsValid(capsule: *mut PyObject,
name: *const c_char) -> c_int;
pub fn PyCapsule_SetPointer(capsule: *mut PyObject,
pointer: *mut c_void)
-> c_int;
pub fn PyCapsule_SetDestructor(capsule: *mut PyObject,
destructor: Option<PyCapsule_Destructor>)
-> c_int;
pub fn PyCapsule_SetName(capsule: *mut PyObject,
name: *const c_char) -> c_int;
pub fn PyCapsule_SetContext(capsule: *mut PyObject,
context: *mut c_void)
-> c_int;
pub fn PyCapsule_Import(name: *const c_char,
no_block: c_int) -> *mut c_void;
}