Rustfmt all the things ✔️

This commit is contained in:
konstin 2018-07-30 23:01:46 +02:00
parent 83db765889
commit fe8a719ee1
168 changed files with 7802 additions and 5622 deletions

View File

@ -8,11 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Removed
* Conversions from tuples to PyDict.
* Conversions from tuples to PyDict due to [rust-lang/rust#52050](https://github.com/rust-lang/rust/issues/52050)
### Changed
* Merged both examples into one
* Rustfmt all the things :heavy_check_mark:
## [0.3.2] - 2018-07-22

View File

@ -21,7 +21,9 @@ struct WordCounter {
impl WordCounter {
#[new]
fn __new__(obj: &PyRawObject, path: String) -> PyResult<()> {
obj.init(|_| WordCounter { path: PathBuf::from(path) })
obj.init(|_| WordCounter {
path: PathBuf::from(path),
})
}
/// Searches for the word, parallelized by rayon
@ -41,10 +43,7 @@ impl WordCounter {
fn search_sequential(&self, needle: String) -> PyResult<usize> {
let contents = fs::read_to_string(&self.path)?;
let result = contents
.lines()
.map(|line| count_line(line, &needle))
.sum();
let result = contents.lines().map(|line| count_line(line, &needle)).sum();
Ok(result)
}

View File

@ -179,8 +179,8 @@ pub fn parse_arguments(items: &[syn::NestedMeta]) -> Vec<Argument> {
mod test {
use args::{parse_arguments, Argument};
use syn;
use proc_macro2::TokenStream;
use syn;
fn items(s: TokenStream) -> Vec<syn::NestedMeta> {
let dummy: syn::ItemFn = parse_quote!{#s fn dummy() {}};

View File

@ -272,8 +272,7 @@ fn function_c_wrapper(name: &syn::Ident, spec: &method::FnSpec) -> TokenStream {
} else {
syn::Ident::new(&format!("arg{}", item.0), Span::call_site())
}
})
.collect();
}).collect();
let cb = quote! {
::pyo3::ReturnTypeIntoPyResult::return_type_into_py_result(#name(#(#names),*))
};

View File

@ -345,10 +345,8 @@ fn impl_descriptors(cls: &syn::Type, descriptors: Vec<(syn::Field, Vec<FnType>)>
}
_ => unreachable!(),
}
})
.collect::<Vec<TokenStream>>()
})
.collect();
}).collect::<Vec<TokenStream>>()
}).collect();
quote! {
#(#methods)*

View File

@ -139,8 +139,7 @@ pub fn impl_wrap_new(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> Token
} else {
syn::Ident::new(&format!("arg{}", item.0), Span::call_site())
}
})
.collect();
}).collect();
let cb = quote! {
::pyo3::ReturnTypeIntoPyResult::return_type_into_py_result(#cls::#name(&_obj, #(#names),*))
};
@ -235,8 +234,7 @@ pub fn impl_wrap_class(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> Tok
} else {
syn::Ident::new(&format!("arg{}", item.0), Span::call_site())
}
})
.collect();
}).collect();
let cb = quote! {
::pyo3::ReturnTypeIntoPyResult::return_type_into_py_result(#cls::#name(&_cls, #(#names),*))
};
@ -277,8 +275,7 @@ pub fn impl_wrap_static(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec) -> To
} else {
syn::Ident::new(&format!("arg{}", item.0), Span::call_site())
}
})
.collect();
}).collect();
let cb = quote! {
::pyo3::ReturnTypeIntoPyResult::return_type_into_py_result(#cls::#name(#(#names),*))
};
@ -376,8 +373,7 @@ fn impl_call(_cls: &syn::Type, fname: &syn::Ident, spec: &FnSpec) -> TokenStream
} else {
syn::Ident::new(&format!("arg{}", item.0), Span::call_site())
}
})
.collect();
}).collect();
quote! {
::pyo3::ReturnTypeIntoPyResult::return_type_into_py_result(_slf.#fname(#(#names),*))
}

View File

@ -50,7 +50,8 @@ pub fn mod3init(
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
// Parse the token stream into a syntax tree
let mut ast: syn::ItemFn = syn::parse(input).expect("#[pymodinit] must be used on a `fn` block");
let mut ast: syn::ItemFn =
syn::parse(input).expect("#[pymodinit] must be used on a `fn` block");
let modname: syn::Ident;
if attr.is_empty() {
@ -95,7 +96,8 @@ pub fn pyclass(
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
// Parse the token stream into a syntax tree
let mut ast: syn::ItemStruct = syn::parse(input).expect("#[pyclass] must be used on a `struct`");
let mut ast: syn::ItemStruct =
syn::parse(input).expect("#[pyclass] must be used on a `struct`");
// Parse the macro arguments into a list of expressions
let args: Vec<syn::Expr> = {

View File

@ -3,11 +3,11 @@
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
//! Python argument parsing
use ffi;
use err::PyResult;
use python::Python;
use conversion::PyTryFrom;
use objects::{PyObjectRef, PyTuple, PyDict, PyString, exc};
use err::PyResult;
use ffi;
use objects::{exc, PyDict, PyObjectRef, PyString, PyTuple};
use python::Python;
#[derive(Debug)]
/// Description of a python parameter; used for `parse_args()`.
@ -28,16 +28,20 @@ pub struct ParamDescription<'a> {
/// * kwargs: Keyword arguments
/// * output: Output array that receives the arguments.
/// Must have same length as `params` and must be initialized to `None`.
pub fn parse_args<'p>(fname: Option<&str>, params: &[ParamDescription],
args: &'p PyTuple, kwargs: Option<&'p PyDict>,
accept_args: bool, accept_kwargs: bool,
output: &mut[Option<&'p PyObjectRef>]) -> PyResult<()>
{
pub fn parse_args<'p>(
fname: Option<&str>,
params: &[ParamDescription],
args: &'p PyTuple,
kwargs: Option<&'p PyDict>,
accept_args: bool,
accept_kwargs: bool,
output: &mut [Option<&'p PyObjectRef>],
) -> PyResult<()> {
let nargs = args.len();
let nkeywords = kwargs.map_or(0, |d| d.len());
if !accept_args && (nargs + nkeywords > params.len()) {
return Err(exc::TypeError::new(
format!("{}{} takes at most {} argument{} ({} given)",
return Err(exc::TypeError::new(format!(
"{}{} takes at most {} argument{} ({} given)",
fname.unwrap_or("function"),
if fname.is_some() { "()" } else { "" },
params.len(),
@ -53,25 +57,32 @@ pub fn parse_args<'p>(fname: Option<&str>, params: &[ParamDescription],
*out = Some(kwarg);
used_keywords += 1;
if i < nargs {
return Err(exc::TypeError::new(
format!("Argument given by name ('{}') and position ({})", p.name, i+1)));
return Err(exc::TypeError::new(format!(
"Argument given by name ('{}') and position ({})",
p.name,
i + 1
)));
}
}
},
None => {
if p.kw_only {
if !p.is_optional {
return Err(exc::TypeError::new(
format!("Required argument ('{}') is keyword only argument", p.name)));
return Err(exc::TypeError::new(format!(
"Required argument ('{}') is keyword only argument",
p.name
)));
}
*out = None;
}
else if i < nargs {
} else if i < nargs {
*out = Some(args.get_item(i));
} else {
*out = None;
if !p.is_optional {
return Err(exc::TypeError::new(
format!("Required argument ('{}') (pos {}) not found", p.name, i+1)));
return Err(exc::TypeError::new(format!(
"Required argument ('{}') (pos {}) not found",
p.name,
i + 1
)));
}
}
}
@ -83,8 +94,10 @@ pub fn parse_args<'p>(fname: Option<&str>, params: &[ParamDescription],
let item = <PyTuple as PyTryFrom>::try_from(item)?;
let key = <PyString as PyTryFrom>::try_from(item.get_item(0))?.to_string()?;
if !params.iter().any(|p| p.name == key) {
return Err(exc::TypeError::new(
format!("'{}' is an invalid keyword argument for this function", key)));
return Err(exc::TypeError::new(format!(
"'{}' is an invalid keyword argument for this function",
key
)));
}
}
}

View File

@ -17,16 +17,16 @@
// DEALINGS IN THE SOFTWARE.
//! `PyBuffer` implementation
use std::os::raw;
use std::{mem, slice, cell};
use std::ffi::CStr;
use libc;
use std::ffi::CStr;
use std::os::raw;
use std::{cell, mem, slice};
use ffi;
use exc;
use err::{self, PyResult};
use python::{Python, ToPyPointer};
use exc;
use ffi;
use objects::PyObjectRef;
use python::{Python, ToPyPointer};
/// Allows access to the underlying buffer used by a python object such as `bytes`, `bytearray` or `array.array`.
#[repr(transparent)]
@ -43,7 +43,7 @@ pub enum ElementType {
UnsignedInteger { bytes: usize },
Bool,
Float { bytes: usize },
Unknown
Unknown,
}
impl ElementType {
@ -55,7 +55,7 @@ impl ElementType {
match slice[0] {
b'@' => native_element_type_from_type_char(slice[1]),
b'=' | b'<' | b'>' | b'!' => standard_element_type_from_type_char(slice[1]),
_ => ElementType::Unknown
_ => ElementType::Unknown,
}
} else {
ElementType::Unknown
@ -66,24 +66,50 @@ impl ElementType {
fn native_element_type_from_type_char(type_char: u8) -> ElementType {
use self::ElementType::*;
match type_char {
b'c' => UnsignedInteger { bytes: mem::size_of::<raw::c_char>() },
b'b' => SignedInteger { bytes: mem::size_of::<raw::c_schar>() },
b'B' => UnsignedInteger { bytes: mem::size_of::<raw::c_uchar>() },
b'c' => UnsignedInteger {
bytes: mem::size_of::<raw::c_char>(),
},
b'b' => SignedInteger {
bytes: mem::size_of::<raw::c_schar>(),
},
b'B' => UnsignedInteger {
bytes: mem::size_of::<raw::c_uchar>(),
},
b'?' => Bool,
b'h' => SignedInteger { bytes: mem::size_of::<raw::c_short>() },
b'H' => UnsignedInteger { bytes: mem::size_of::<raw::c_ushort>() },
b'i' => SignedInteger { bytes: mem::size_of::<raw::c_int>() },
b'I' => UnsignedInteger { bytes: mem::size_of::<raw::c_uint>() },
b'l' => SignedInteger { bytes: mem::size_of::<raw::c_long>() },
b'L' => UnsignedInteger { bytes: mem::size_of::<raw::c_ulong>() },
b'q' => SignedInteger { bytes: mem::size_of::<raw::c_longlong>() },
b'Q' => UnsignedInteger { bytes: mem::size_of::<raw::c_ulonglong>() },
b'n' => SignedInteger { bytes: mem::size_of::<libc::ssize_t>() },
b'N' => UnsignedInteger { bytes: mem::size_of::<libc::size_t>() },
b'h' => SignedInteger {
bytes: mem::size_of::<raw::c_short>(),
},
b'H' => UnsignedInteger {
bytes: mem::size_of::<raw::c_ushort>(),
},
b'i' => SignedInteger {
bytes: mem::size_of::<raw::c_int>(),
},
b'I' => UnsignedInteger {
bytes: mem::size_of::<raw::c_uint>(),
},
b'l' => SignedInteger {
bytes: mem::size_of::<raw::c_long>(),
},
b'L' => UnsignedInteger {
bytes: mem::size_of::<raw::c_ulong>(),
},
b'q' => SignedInteger {
bytes: mem::size_of::<raw::c_longlong>(),
},
b'Q' => UnsignedInteger {
bytes: mem::size_of::<raw::c_ulonglong>(),
},
b'n' => SignedInteger {
bytes: mem::size_of::<libc::ssize_t>(),
},
b'N' => UnsignedInteger {
bytes: mem::size_of::<libc::size_t>(),
},
b'e' => Float { bytes: 2 },
b'f' => Float { bytes: 4 },
b'd' => Float { bytes: 8 },
_ => Unknown
_ => Unknown,
}
}
@ -102,7 +128,7 @@ fn standard_element_type_from_type_char(type_char: u8) -> ElementType {
b'e' => Float { bytes: 2 },
b'f' => Float { bytes: 4 },
b'd' => Float { bytes: 8 },
_ => Unknown
_ => Unknown,
}
}
@ -110,7 +136,7 @@ fn standard_element_type_from_type_char(type_char: u8) -> ElementType {
fn is_matching_endian(c: u8) -> bool {
match c {
b'@' | b'=' | b'<' => true,
_ => false
_ => false,
}
}
@ -118,7 +144,7 @@ fn is_matching_endian(c: u8) -> bool {
fn is_matching_endian(c: u8) -> bool {
match c {
b'@' | b'=' | b'>' | b'!' => true,
_ => false
_ => false,
}
}
@ -141,7 +167,9 @@ impl PyBuffer {
unsafe {
let mut buf = Box::new(mem::zeroed::<ffi::Py_buffer>());
err::error_on_minusone(
py, ffi::PyObject_GetBuffer(obj.as_ptr(), &mut *buf, ffi::PyBUF_FULL_RO))?;
py,
ffi::PyObject_GetBuffer(obj.as_ptr(), &mut *buf, ffi::PyBUF_FULL_RO),
)?;
validate(&buf);
Ok(PyBuffer(buf))
}
@ -167,7 +195,7 @@ impl PyBuffer {
unsafe {
ffi::PyBuffer_GetPointer(
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
indices.as_ptr() as *mut usize as *mut ffi::Py_ssize_t
indices.as_ptr() as *mut usize as *mut ffi::Py_ssize_t,
)
}
}
@ -216,9 +244,7 @@ impl PyBuffer {
/// However, dimensions of length 0 are possible and might need special attention.
#[inline]
pub fn shape(&self) -> &[usize] {
unsafe {
slice::from_raw_parts(self.0.shape as *const usize, self.0.ndim as usize)
}
unsafe { slice::from_raw_parts(self.0.shape as *const usize, self.0.ndim as usize) }
}
/// Returns an array that holds, for each dimension, the number of bytes to skip to get to the next element in the dimension.
@ -227,9 +253,7 @@ impl PyBuffer {
/// but a consumer MUST be able to handle the case `strides[n] <= 0`.
#[inline]
pub fn strides(&self) -> &[isize] {
unsafe {
slice::from_raw_parts(self.0.strides, self.0.ndim as usize)
}
unsafe { slice::from_raw_parts(self.0.strides, self.0.ndim as usize) }
}
/// An array of length ndim.
@ -243,7 +267,10 @@ impl PyBuffer {
if self.0.suboffsets.is_null() {
None
} else {
Some(slice::from_raw_parts(self.0.suboffsets, self.0.ndim as usize))
Some(slice::from_raw_parts(
self.0.suboffsets,
self.0.ndim as usize,
))
}
}
}
@ -263,7 +290,10 @@ impl PyBuffer {
pub fn is_c_contiguous(&self) -> bool {
unsafe {
// Python 2.7 is not const-correct, so we need the cast to *mut
ffi::PyBuffer_IsContiguous(&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, b'C' as libc::c_char) != 0
ffi::PyBuffer_IsContiguous(
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
b'C' as libc::c_char,
) != 0
}
}
@ -272,7 +302,10 @@ impl PyBuffer {
pub fn is_fortran_contiguous(&self) -> bool {
unsafe {
// Python 2.7 is not const-correct, so we need the cast to *mut
ffi::PyBuffer_IsContiguous(&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, b'F' as libc::c_char) != 0
ffi::PyBuffer_IsContiguous(
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
b'F' as libc::c_char,
) != 0
}
}
@ -291,7 +324,12 @@ impl PyBuffer {
&& self.is_c_contiguous()
&& T::is_compatible_format(self.format())
{
unsafe { Some(slice::from_raw_parts(self.0.buf as *mut ReadOnlyCell<T>, self.item_count())) }
unsafe {
Some(slice::from_raw_parts(
self.0.buf as *mut ReadOnlyCell<T>,
self.item_count(),
))
}
} else {
None
}
@ -314,7 +352,12 @@ impl PyBuffer {
&& self.is_c_contiguous()
&& T::is_compatible_format(self.format())
{
unsafe { Some(slice::from_raw_parts(self.0.buf as *mut cell::Cell<T>, self.item_count())) }
unsafe {
Some(slice::from_raw_parts(
self.0.buf as *mut cell::Cell<T>,
self.item_count(),
))
}
} else {
None
}
@ -329,13 +372,21 @@ impl PyBuffer {
///
/// The returned slice uses type `Cell<T>` because it's theoretically possible for any call into the Python runtime
/// to modify the values in the slice.
pub fn as_fortran_slice<'a, T: Element>(&'a self, _py: Python<'a>) -> Option<&'a [ReadOnlyCell<T>]> {
pub fn as_fortran_slice<'a, T: Element>(
&'a self,
_py: Python<'a>,
) -> Option<&'a [ReadOnlyCell<T>]> {
if mem::size_of::<T>() == self.item_size()
&& (self.0.buf as usize) % mem::align_of::<T>() == 0
&& self.is_fortran_contiguous()
&& T::is_compatible_format(self.format())
{
unsafe { Some(slice::from_raw_parts(self.0.buf as *mut ReadOnlyCell<T>, self.item_count())) }
unsafe {
Some(slice::from_raw_parts(
self.0.buf as *mut ReadOnlyCell<T>,
self.item_count(),
))
}
} else {
None
}
@ -351,14 +402,22 @@ impl PyBuffer {
///
/// The returned slice uses type `Cell<T>` because it's theoretically possible for any call into the Python runtime
/// to modify the values in the slice.
pub fn as_fortran_mut_slice<'a, T: Element>(&'a self, _py: Python<'a>) -> Option<&'a [cell::Cell<T>]> {
pub fn as_fortran_mut_slice<'a, T: Element>(
&'a self,
_py: Python<'a>,
) -> Option<&'a [cell::Cell<T>]> {
if !self.readonly()
&& mem::size_of::<T>() == self.item_size()
&& (self.0.buf as usize) % mem::align_of::<T>() == 0
&& self.is_fortran_contiguous()
&& T::is_compatible_format(self.format())
{
unsafe { Some(slice::from_raw_parts(self.0.buf as *mut cell::Cell<T>, self.item_count())) }
unsafe {
Some(slice::from_raw_parts(
self.0.buf as *mut cell::Cell<T>,
self.item_count(),
))
}
} else {
None
}
@ -386,24 +445,38 @@ impl PyBuffer {
/// To check whether the buffer format is compatible before calling this method,
/// you can use `<T as buffer::Element>::is_compatible_format(buf.format())`.
/// Alternatively, `match buffer::ElementType::from_format(buf.format())`.
pub fn copy_to_fortran_slice<T: Element+Copy>(&self, py: Python, target: &mut [T]) -> PyResult<()> {
pub fn copy_to_fortran_slice<T: Element + Copy>(
&self,
py: Python,
target: &mut [T],
) -> PyResult<()> {
self.copy_to_slice_impl(py, target, b'F')
}
fn copy_to_slice_impl<T: Element+Copy>(&self, py: Python, target: &mut [T], fort: u8) -> PyResult<()> {
fn copy_to_slice_impl<T: Element + Copy>(
&self,
py: Python,
target: &mut [T],
fort: u8,
) -> PyResult<()> {
if mem::size_of_val(target) != self.len_bytes() {
return Err(exc::BufferError::new("Slice length does not match buffer length."));
return Err(exc::BufferError::new(
"Slice length does not match buffer length.",
));
}
if !T::is_compatible_format(self.format()) || mem::size_of::<T>() != self.item_size() {
return incompatible_format_error();
}
unsafe {
err::error_on_minusone(py, ffi::PyBuffer_ToContiguous(
err::error_on_minusone(
py,
ffi::PyBuffer_ToContiguous(
target.as_ptr() as *mut raw::c_void,
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
self.0.len,
fort as libc::c_char
))
fort as libc::c_char,
),
)
}
}
@ -433,12 +506,15 @@ impl PyBuffer {
unsafe {
// Copy the buffer into the uninitialized space in the vector.
// Due to T:Copy, we don't need to be concerned with Drop impls.
err::error_on_minusone(py, ffi::PyBuffer_ToContiguous(
err::error_on_minusone(
py,
ffi::PyBuffer_ToContiguous(
vec.as_mut_ptr() as *mut raw::c_void,
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
self.0.len,
fort as libc::c_char
))?;
fort as libc::c_char,
),
)?;
// set vector length to mark the now-initialized space as usable
vec.set_len(item_count);
}
@ -469,27 +545,41 @@ impl PyBuffer {
/// To check whether the buffer format is compatible before calling this method,
/// use `<T as buffer::Element>::is_compatible_format(buf.format())`.
/// Alternatively, `match buffer::ElementType::from_format(buf.format())`.
pub fn copy_from_fortran_slice<T: Element+Copy>(&self, py: Python, source: &[T]) -> PyResult<()> {
pub fn copy_from_fortran_slice<T: Element + Copy>(
&self,
py: Python,
source: &[T],
) -> PyResult<()> {
self.copy_from_slice_impl(py, source, b'F')
}
fn copy_from_slice_impl<T: Element+Copy>(&self, py: Python, source: &[T], fort: u8) -> PyResult<()> {
fn copy_from_slice_impl<T: Element + Copy>(
&self,
py: Python,
source: &[T],
fort: u8,
) -> PyResult<()> {
if self.readonly() {
return buffer_readonly_error();
}
if mem::size_of_val(source) != self.len_bytes() {
return Err(exc::BufferError::new("Slice length does not match buffer length."));
return Err(exc::BufferError::new(
"Slice length does not match buffer length.",
));
}
if !T::is_compatible_format(self.format()) || mem::size_of::<T>() != self.item_size() {
return incompatible_format_error();
}
unsafe {
err::error_on_minusone(py, ffi::PyBuffer_FromContiguous(
err::error_on_minusone(
py,
ffi::PyBuffer_FromContiguous(
&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
source.as_ptr() as *mut raw::c_void,
self.0.len,
fort as libc::c_char
))
fort as libc::c_char,
),
)
}
}
@ -503,7 +593,9 @@ impl PyBuffer {
}
fn incompatible_format_error() -> PyResult<()> {
Err(exc::BufferError::new("Slice type is incompatible with buffer format."))
Err(exc::BufferError::new(
"Slice type is incompatible with buffer format.",
))
}
fn buffer_readonly_error() -> PyResult<()> {
@ -564,12 +656,11 @@ impl_element!(isize, SignedInteger);
impl_element!(f32, Float);
impl_element!(f64, Float);
#[cfg(test)]
mod test {
use std;
use python::{Python};
use super::PyBuffer;
use python::Python;
use std;
#[allow(unused_imports)]
use objectprotocol::ObjectProtocol;
@ -577,7 +668,10 @@ mod test {
#[test]
fn test_compatible_size() {
// for the cast in PyBuffer::shape()
assert_eq!(std::mem::size_of::<::ffi::Py_ssize_t>(), std::mem::size_of::<usize>());
assert_eq!(
std::mem::size_of::<::ffi::Py_ssize_t>(),
std::mem::size_of::<usize>()
);
}
#[test]
@ -621,8 +715,11 @@ mod test {
fn test_array_buffer() {
let gil = Python::acquire_gil();
let py = gil.python();
let array = py.import("array").unwrap().call_method(
"array", ("f", (1.0, 1.5, 2.0, 2.5)), ::NoArgs).unwrap();
let array = py
.import("array")
.unwrap()
.call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), ::NoArgs)
.unwrap();
let buffer = PyBuffer::get(py, array.into()).unwrap();
assert_eq!(buffer.dimensions(), 1);
assert_eq!(buffer.item_count(), 4);
@ -643,7 +740,9 @@ mod test {
mut_slice[3].set(2.75);
assert_eq!(slice[3].get(), 2.75);
buffer.copy_from_slice(py, &[10.0f32, 11.0, 12.0, 13.0]).unwrap();
buffer
.copy_from_slice(py, &[10.0f32, 11.0, 12.0, 13.0])
.unwrap();
assert_eq!(slice[2].get(), 12.0);
assert_eq!(buffer.to_vec::<f32>(py).unwrap(), [10.0, 11.0, 12.0, 13.0]);

View File

@ -3,14 +3,13 @@
//! Utilities for a Python callable object that invokes a Rust function.
use std::os::raw::c_int;
use std::{ptr, isize};
use std::{isize, ptr};
use conversion::IntoPyObject;
use err::PyResult;
use ffi::{self, Py_hash_t};
use python::{Python, IntoPyPointer};
use objects::exc::OverflowError;
use conversion::IntoPyObject;
use python::{IntoPyPointer, Python};
pub trait CallbackConverter<S> {
type R;
@ -22,7 +21,8 @@ pub trait CallbackConverter<S> {
pub struct PyObjectCallbackConverter;
impl<S> CallbackConverter<S> for PyObjectCallbackConverter
where S: IntoPyObject
where
S: IntoPyObject,
{
type R = *mut ffi::PyObject;
@ -36,7 +36,6 @@ impl<S> CallbackConverter<S> for PyObjectCallbackConverter
}
}
pub struct BoolCallbackConverter;
impl CallbackConverter<bool> for BoolCallbackConverter {
@ -73,7 +72,6 @@ impl CallbackConverter<usize> for LenResultConverter {
}
}
pub struct UnitCallbackConverter;
impl CallbackConverter<()> for UnitCallbackConverter {
@ -102,7 +100,7 @@ macro_rules! wrapping_cast {
self as $to
}
}
}
};
}
wrapping_cast!(u8, Py_hash_t);
wrapping_cast!(u16, Py_hash_t);
@ -118,7 +116,8 @@ wrapping_cast!(i64, Py_hash_t);
pub struct HashConverter;
impl<T> CallbackConverter<T> for HashConverter
where T: WrappingCastTo<Py_hash_t>
where
T: WrappingCastTo<Py_hash_t>,
{
type R = Py_hash_t;
@ -141,7 +140,8 @@ impl <T> CallbackConverter<T> for HashConverter
#[inline]
pub unsafe fn cb_convert<C, T>(_c: C, py: Python, value: PyResult<T>) -> C::R
where C: CallbackConverter<T>
where
C: CallbackConverter<T>,
{
match value {
Ok(val) => C::convert(val, py),

View File

@ -8,36 +8,56 @@
//! [PEP-0492](https://www.python.org/dev/peps/pep-0492/)
//!
use ffi;
use err::PyResult;
use callback::PyObjectCallbackConverter;
use typeob::PyTypeInfo;
use class::methods::PyMethodDef;
use err::PyResult;
use ffi;
use typeob::PyTypeInfo;
/// Python Async/Await support interface.
///
/// Each method in this trait corresponds to Python async/await implementation.
#[allow(unused_variables)]
pub trait PyAsyncProtocol<'p>: PyTypeInfo {
fn __await__(&'p self) -> Self::Result
where
Self: PyAsyncAwaitProtocol<'p>,
{
unimplemented!()
}
fn __await__(&'p self)
-> Self::Result where Self: PyAsyncAwaitProtocol<'p> { unimplemented!() }
fn __aiter__(&'p self) -> Self::Result
where
Self: PyAsyncAiterProtocol<'p>,
{
unimplemented!()
}
fn __aiter__(&'p self)
-> Self::Result where Self: PyAsyncAiterProtocol<'p> { unimplemented!() }
fn __anext__(&'p mut self) -> Self::Result
where
Self: PyAsyncAnextProtocol<'p>,
{
unimplemented!()
}
fn __anext__(&'p mut self)
-> Self::Result where Self: PyAsyncAnextProtocol<'p> { unimplemented!() }
fn __aenter__(&'p mut self) -> Self::Result
where
Self: PyAsyncAenterProtocol<'p>,
{
unimplemented!()
}
fn __aenter__(&'p mut self)
-> Self::Result where Self: PyAsyncAenterProtocol<'p> { unimplemented!() }
fn __aexit__(&'p mut self,
fn __aexit__(
&'p mut self,
exc_type: Option<Self::ExcType>,
exc_value: Option<Self::ExcValue>,
traceback: Option<Self::Traceback>)
-> Self::Result where Self: PyAsyncAexitProtocol<'p> { unimplemented!() }
traceback: Option<Self::Traceback>,
) -> Self::Result
where
Self: PyAsyncAexitProtocol<'p>,
{
unimplemented!()
}
}
pub trait PyAsyncAwaitProtocol<'p>: PyAsyncProtocol<'p> {
@ -68,7 +88,6 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> {
type Result: Into<PyResult<Self::Success>>;
}
#[cfg(Py_3)]
#[doc(hidden)]
pub trait PyAsyncProtocolImpl {
@ -91,7 +110,10 @@ impl<T> PyAsyncProtocolImpl for T {
}
#[cfg(Py_3)]
impl<'p, T> PyAsyncProtocolImpl for T where T: PyAsyncProtocol<'p> {
impl<'p, T> PyAsyncProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
#[inline]
fn tp_as_async() -> Option<ffi::PyAsyncMethods> {
Some(ffi::PyAsyncMethods {
@ -116,12 +138,13 @@ impl<'p, T> PyAsyncProtocolImpl for T where T: PyAsyncProtocol<'p> {
}
}
trait PyAsyncAwaitProtocolImpl {
fn am_await() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p>
impl<'p, T> PyAsyncAwaitProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
#[inline]
default fn am_await() -> Option<ffi::unaryfunc> {
@ -129,12 +152,18 @@ impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p>
}
}
impl<T> PyAsyncAwaitProtocolImpl for T where T: for<'p> PyAsyncAwaitProtocol<'p>
impl<T> PyAsyncAwaitProtocolImpl for T
where
T: for<'p> PyAsyncAwaitProtocol<'p>,
{
#[inline]
fn am_await() -> Option<ffi::unaryfunc> {
py_unary_func!(PyAsyncAwaitProtocol, T::__await__,
<T as PyAsyncAwaitProtocol>::Success, PyObjectCallbackConverter)
py_unary_func!(
PyAsyncAwaitProtocol,
T::__await__,
<T as PyAsyncAwaitProtocol>::Success,
PyObjectCallbackConverter
)
}
}
@ -142,7 +171,9 @@ trait PyAsyncAiterProtocolImpl {
fn am_aiter() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p>
impl<'p, T> PyAsyncAiterProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
#[inline]
default fn am_aiter() -> Option<ffi::unaryfunc> {
@ -150,12 +181,18 @@ impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p>
}
}
impl<T> PyAsyncAiterProtocolImpl for T where T: for<'p> PyAsyncAiterProtocol<'p>
impl<T> PyAsyncAiterProtocolImpl for T
where
T: for<'p> PyAsyncAiterProtocol<'p>,
{
#[inline]
fn am_aiter() -> Option<ffi::unaryfunc> {
py_unary_func!(PyAsyncAiterProtocol, T::__aiter__,
<T as PyAsyncAiterProtocol>::Success, PyObjectCallbackConverter)
py_unary_func!(
PyAsyncAiterProtocol,
T::__aiter__,
<T as PyAsyncAiterProtocol>::Success,
PyObjectCallbackConverter
)
}
}
@ -163,7 +200,9 @@ trait PyAsyncAnextProtocolImpl {
fn am_anext() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p>
impl<'p, T> PyAsyncAnextProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
#[inline]
default fn am_anext() -> Option<ffi::unaryfunc> {
@ -171,20 +210,20 @@ impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p>
}
}
#[cfg(Py_3)]
mod anext {
use std::ptr;
use ffi;
use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl};
use callback::CallbackConverter;
use conversion::IntoPyObject;
use python::{Python, IntoPyPointer};
use super::{PyAsyncAnextProtocolImpl, PyAsyncAnextProtocol};
use ffi;
use python::{IntoPyPointer, Python};
use std::ptr;
pub struct IterANextResultConverter;
impl<T> CallbackConverter<Option<T>> for IterANextResultConverter
where T: IntoPyObject
where
T: IntoPyObject,
{
type R = *mut ffi::PyObject;
@ -194,7 +233,7 @@ mod anext {
None => unsafe {
ffi::PyErr_SetNone(ffi::PyExc_StopAsyncIteration);
ptr::null_mut()
}
},
}
}
@ -204,12 +243,18 @@ mod anext {
}
}
impl<T> PyAsyncAnextProtocolImpl for T where T: for<'p> PyAsyncAnextProtocol<'p>
impl<T> PyAsyncAnextProtocolImpl for T
where
T: for<'p> PyAsyncAnextProtocol<'p>,
{
#[inline]
fn am_anext() -> Option<ffi::unaryfunc> {
py_unary_func!(PyAsyncAnextProtocol, T::__anext__,
Option<T::Success>, IterANextResultConverter)
py_unary_func!(
PyAsyncAnextProtocol,
T::__anext__,
Option<T::Success>,
IterANextResultConverter
)
}
}
}
@ -218,7 +263,9 @@ trait PyAsyncAenterProtocolImpl {
fn __aenter__() -> Option<PyMethodDef>;
}
impl<'p, T> PyAsyncAenterProtocolImpl for T where T: PyAsyncProtocol<'p>
impl<'p, T> PyAsyncAenterProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
#[inline]
default fn __aenter__() -> Option<PyMethodDef> {
@ -230,7 +277,9 @@ trait PyAsyncAexitProtocolImpl {
fn __aexit__() -> Option<PyMethodDef>;
}
impl<'p, T> PyAsyncAexitProtocolImpl for T where T: PyAsyncProtocol<'p>
impl<'p, T> PyAsyncAexitProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
#[inline]
default fn __aexit__() -> Option<PyMethodDef> {

View File

@ -8,57 +8,98 @@
use std;
use std::os::raw::c_int;
use ::CompareOp;
use ffi;
use err::{PyErr, PyResult};
use python::{Python, IntoPyPointer};
use objects::{exc, PyObjectRef};
use typeob::PyTypeInfo;
use conversion::{FromPyObject, IntoPyObject};
use objectprotocol::ObjectProtocol;
use callback::{PyObjectCallbackConverter, HashConverter, BoolCallbackConverter};
use callback::{BoolCallbackConverter, HashConverter, PyObjectCallbackConverter};
use class::methods::PyMethodDef;
use conversion::{FromPyObject, IntoPyObject};
use err::{PyErr, PyResult};
use ffi;
use objectprotocol::ObjectProtocol;
use objects::{exc, PyObjectRef};
use python::{IntoPyPointer, Python};
use typeob::PyTypeInfo;
use CompareOp;
/// Basic python class customization
#[allow(unused_variables)]
pub trait PyObjectProtocol<'p>: PyTypeInfo {
fn __getattr__(&'p self, name: Self::Name)
-> Self::Result where Self: PyObjectGetAttrProtocol<'p> {unimplemented!()}
fn __setattr__(&'p mut self, name: Self::Name, value: Self::Value)
-> Self::Result where Self: PyObjectSetAttrProtocol<'p> {unimplemented!()}
fn __delattr__(&'p mut self, name: Self::Name)
-> Self::Result where Self: PyObjectDelAttrProtocol<'p> {unimplemented!()}
fn __str__(&'p self)
-> Self::Result where Self: PyObjectStrProtocol<'p> {unimplemented!()}
fn __repr__(&'p self)
-> Self::Result where Self: PyObjectReprProtocol<'p> {unimplemented!()}
fn __format__(&'p self, format_spec: Self::Format)
-> Self::Result where Self: PyObjectFormatProtocol<'p> {unimplemented!()}
fn __hash__(&'p self)
-> Self::Result where Self: PyObjectHashProtocol<'p> {unimplemented!()}
fn __bool__(&'p self)
-> Self::Result where Self: PyObjectBoolProtocol<'p> {unimplemented!()}
fn __bytes__(&'p self)
-> Self::Result where Self: PyObjectBytesProtocol<'p> {unimplemented!()}
/// This method is used by Python2 only.
fn __unicode__(&'p self)
-> Self::Result where Self: PyObjectUnicodeProtocol<'p> {unimplemented!()}
fn __richcmp__(&'p self, other: Self::Other, op: CompareOp)
-> Self::Result where Self: PyObjectRichcmpProtocol<'p> {unimplemented!()}
fn __getattr__(&'p self, name: Self::Name) -> Self::Result
where
Self: PyObjectGetAttrProtocol<'p>,
{
unimplemented!()
}
fn __setattr__(&'p mut self, name: Self::Name, value: Self::Value) -> Self::Result
where
Self: PyObjectSetAttrProtocol<'p>,
{
unimplemented!()
}
fn __delattr__(&'p mut self, name: Self::Name) -> Self::Result
where
Self: PyObjectDelAttrProtocol<'p>,
{
unimplemented!()
}
fn __str__(&'p self) -> Self::Result
where
Self: PyObjectStrProtocol<'p>,
{
unimplemented!()
}
fn __repr__(&'p self) -> Self::Result
where
Self: PyObjectReprProtocol<'p>,
{
unimplemented!()
}
fn __format__(&'p self, format_spec: Self::Format) -> Self::Result
where
Self: PyObjectFormatProtocol<'p>,
{
unimplemented!()
}
fn __hash__(&'p self) -> Self::Result
where
Self: PyObjectHashProtocol<'p>,
{
unimplemented!()
}
fn __bool__(&'p self) -> Self::Result
where
Self: PyObjectBoolProtocol<'p>,
{
unimplemented!()
}
fn __bytes__(&'p self) -> Self::Result
where
Self: PyObjectBytesProtocol<'p>,
{
unimplemented!()
}
/// This method is used by Python2 only.
fn __unicode__(&'p self) -> Self::Result
where
Self: PyObjectUnicodeProtocol<'p>,
{
unimplemented!()
}
fn __richcmp__(&'p self, other: Self::Other, op: CompareOp) -> Self::Result
where
Self: PyObjectRichcmpProtocol<'p>,
{
unimplemented!()
}
}
pub trait PyObjectGetAttrProtocol<'p>: PyObjectProtocol<'p> {
type Name: FromPyObject<'p>;
@ -107,7 +148,6 @@ pub trait PyObjectRichcmpProtocol<'p>: PyObjectProtocol<'p> {
type Result: Into<PyResult<Self::Success>>;
}
#[doc(hidden)]
pub trait PyObjectProtocolImpl {
fn methods() -> Vec<PyMethodDef>;
@ -119,14 +159,16 @@ impl<T> PyObjectProtocolImpl for T {
default fn methods() -> Vec<PyMethodDef> {
Vec::new()
}
default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {
}
default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {}
default fn nb_bool_fn() -> Option<ffi::inquiry> {
None
}
}
impl<'p, T> PyObjectProtocolImpl for T where T: PyObjectProtocol<'p> {
impl<'p, T> PyObjectProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
fn methods() -> Vec<PyMethodDef> {
let mut methods = Vec::new();
@ -163,35 +205,46 @@ impl<'p, T> PyObjectProtocolImpl for T where T: PyObjectProtocol<'p> {
trait PyObjectGetAttrProtocolImpl {
fn tp_getattro() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyObjectGetAttrProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectGetAttrProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_getattro() -> Option<ffi::binaryfunc> {
None
}
}
impl<T> PyObjectGetAttrProtocolImpl for T where T: for<'p> PyObjectGetAttrProtocol<'p>
impl<T> PyObjectGetAttrProtocolImpl for T
where
T: for<'p> PyObjectGetAttrProtocol<'p>,
{
#[inline]
fn tp_getattro() -> Option<ffi::binaryfunc> {
py_binary_func!(PyObjectGetAttrProtocol,
T::__getattr__, T::Success, PyObjectCallbackConverter)
py_binary_func!(
PyObjectGetAttrProtocol,
T::__getattr__,
T::Success,
PyObjectCallbackConverter
)
}
}
trait PyObjectSetAttrProtocolImpl {
fn tp_setattro() -> Option<ffi::setattrofunc>;
}
impl<'p, T> PyObjectSetAttrProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectSetAttrProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_setattro() -> Option<ffi::setattrofunc> {
None
}
}
impl<T> PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtocol<'p>
impl<T> PyObjectSetAttrProtocolImpl for T
where
T: for<'p> PyObjectSetAttrProtocol<'p>,
{
#[inline]
fn tp_setattro() -> Option<ffi::setattrofunc> {
@ -199,18 +252,21 @@ impl<T> PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtoc
}
}
trait PyObjectDelAttrProtocolImpl {
fn tp_delattro() -> Option<ffi::setattrofunc>;
}
impl<'p, T> PyObjectDelAttrProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectDelAttrProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_delattro() -> Option<ffi::setattrofunc> {
None
}
}
impl<T> PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtocol<'p>
impl<T> PyObjectDelAttrProtocolImpl for T
where
T: for<'p> PyObjectDelAttrProtocol<'p>,
{
#[inline]
default fn tp_delattro() -> Option<ffi::setattrofunc> {
@ -218,51 +274,70 @@ impl<T> PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtoc
}
}
impl<T> PyObjectDelAttrProtocolImpl for T
where T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>
where
T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>,
{
#[inline]
fn tp_delattro() -> Option<ffi::setattrofunc> {
py_func_set_del!(PyObjectSetAttrProtocol, PyObjectDelAttrProtocol,
T::__setattr__/__delattr__)
py_func_set_del!(
PyObjectSetAttrProtocol,
PyObjectDelAttrProtocol,
T::__setattr__ / __delattr__
)
}
}
trait PyObjectStrProtocolImpl {
fn tp_str() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyObjectStrProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectStrProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_str() -> Option<ffi::unaryfunc> {
None
}
}
impl<T> PyObjectStrProtocolImpl for T where T: for<'p> PyObjectStrProtocol<'p>
impl<T> PyObjectStrProtocolImpl for T
where
T: for<'p> PyObjectStrProtocol<'p>,
{
#[inline]
fn tp_str() -> Option<ffi::unaryfunc> {
py_unary_func!(PyObjectStrProtocol, T::__str__,
<T as PyObjectStrProtocol>::Success, PyObjectCallbackConverter)
py_unary_func!(
PyObjectStrProtocol,
T::__str__,
<T as PyObjectStrProtocol>::Success,
PyObjectCallbackConverter
)
}
}
trait PyObjectReprProtocolImpl {
fn tp_repr() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyObjectReprProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectReprProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_repr() -> Option<ffi::unaryfunc> {
None
}
}
impl<T> PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p>
impl<T> PyObjectReprProtocolImpl for T
where
T: for<'p> PyObjectReprProtocol<'p>,
{
#[inline]
fn tp_repr() -> Option<ffi::unaryfunc> {
py_unary_func!(PyObjectReprProtocol,
T::__repr__, T::Success, PyObjectCallbackConverter)
py_unary_func!(
PyObjectReprProtocol,
T::__repr__,
T::Success,
PyObjectCallbackConverter
)
}
}
@ -270,7 +345,9 @@ impl<T> PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p>
pub trait PyObjectFormatProtocolImpl {
fn __format__() -> Option<PyMethodDef>;
}
impl<'p, T> PyObjectFormatProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectFormatProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn __format__() -> Option<PyMethodDef> {
@ -282,7 +359,9 @@ impl<'p, T> PyObjectFormatProtocolImpl for T where T: PyObjectProtocol<'p>
pub trait PyObjectBytesProtocolImpl {
fn __bytes__() -> Option<PyMethodDef>;
}
impl<'p, T> PyObjectBytesProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectBytesProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn __bytes__() -> Option<PyMethodDef> {
@ -294,7 +373,9 @@ impl<'p, T> PyObjectBytesProtocolImpl for T where T: PyObjectProtocol<'p>
pub trait PyObjectUnicodeProtocolImpl {
fn __unicode__() -> Option<PyMethodDef>;
}
impl<'p, T> PyObjectUnicodeProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectUnicodeProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn __unicode__() -> Option<PyMethodDef> {
@ -305,7 +386,9 @@ impl<'p, T> PyObjectUnicodeProtocolImpl for T where T: PyObjectProtocol<'p>
trait PyObjectHashProtocolImpl {
fn tp_hash() -> Option<ffi::hashfunc>;
}
impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectHashProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_hash() -> Option<ffi::hashfunc> {
@ -313,36 +396,55 @@ impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p>
}
}
impl<T> PyObjectHashProtocolImpl for T
where T: for<'p> PyObjectHashProtocol<'p>
where
T: for<'p> PyObjectHashProtocol<'p>,
{
#[inline]
fn tp_hash() -> Option<ffi::hashfunc> {
py_unary_func!(PyObjectHashProtocol, T::__hash__, isize, HashConverter, ffi::Py_hash_t)
py_unary_func!(
PyObjectHashProtocol,
T::__hash__,
isize,
HashConverter,
ffi::Py_hash_t
)
}
}
trait PyObjectBoolProtocolImpl {
fn nb_bool() -> Option<ffi::inquiry>;
}
impl<'p, T> PyObjectBoolProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectBoolProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn nb_bool() -> Option<ffi::inquiry> {
None
}
}
impl<T> PyObjectBoolProtocolImpl for T where T: for<'p> PyObjectBoolProtocol<'p>
impl<T> PyObjectBoolProtocolImpl for T
where
T: for<'p> PyObjectBoolProtocol<'p>,
{
#[inline]
fn nb_bool() -> Option<ffi::inquiry> {
py_unary_func!(PyObjectBoolProtocol, T::__bool__, bool, BoolCallbackConverter, c_int)
py_unary_func!(
PyObjectBoolProtocol,
T::__bool__,
bool,
BoolCallbackConverter,
c_int
)
}
}
trait PyObjectRichcmpProtocolImpl {
fn tp_richcompare() -> Option<ffi::richcmpfunc>;
}
impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p>
impl<'p, T> PyObjectRichcmpProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
#[inline]
default fn tp_richcompare() -> Option<ffi::richcmpfunc> {
@ -350,14 +452,18 @@ impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p>
}
}
impl<T> PyObjectRichcmpProtocolImpl for T
where T: for<'p> PyObjectRichcmpProtocol<'p>
where
T: for<'p> PyObjectRichcmpProtocol<'p>,
{
#[inline]
fn tp_richcompare() -> Option<ffi::richcmpfunc> {
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
arg: *mut ffi::PyObject,
op: c_int) -> *mut ffi::PyObject
where T: for<'p> PyObjectRichcmpProtocol<'p>
op: c_int,
) -> *mut ffi::PyObject
where
T: for<'p> PyObjectRichcmpProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = Python::assume_gil_acquired();
@ -366,16 +472,13 @@ impl<T> PyObjectRichcmpProtocolImpl for T
let res = match extract_op(op) {
Ok(op) => match arg.extract() {
Ok(arg) =>
slf.__richcmp__(arg, op).into(),
Ok(arg) => slf.__richcmp__(arg, op).into(),
Err(e) => Err(e),
},
Err(e) => Err(e)
Err(e) => Err(e),
};
match res {
Ok(val) => {
val.into_object(py).into_ptr()
}
Ok(val) => val.into_object(py).into_ptr(),
Err(e) => {
e.restore(py);
std::ptr::null_mut()
@ -386,7 +489,6 @@ impl<T> PyObjectRichcmpProtocolImpl for T
}
}
fn extract_op(op: c_int) -> PyResult<CompareOp> {
match op {
ffi::Py_LT => Ok(CompareOp::Lt),
@ -396,6 +498,7 @@ fn extract_op(op: c_int) -> PyResult<CompareOp> {
ffi::Py_GT => Ok(CompareOp::Gt),
ffi::Py_GE => Ok(CompareOp::Ge),
_ => Err(PyErr::new::<exc::ValueError, _>(
"tp_richcompare called with invalid comparison operator"))
"tp_richcompare called with invalid comparison operator",
)),
}
}

View File

@ -6,25 +6,30 @@
//! c-api
use std::os::raw::c_int;
use ffi;
use err::PyResult;
use typeob::PyTypeInfo;
use callback::UnitCallbackConverter;
use err::PyResult;
use ffi;
use typeob::PyTypeInfo;
/// Buffer protocol interface
///
/// For more information check [buffer protocol](https://docs.python.org/3/c-api/buffer.html)
/// c-api
#[allow(unused_variables)]
pub trait PyBufferProtocol<'p> : PyTypeInfo
pub trait PyBufferProtocol<'p>: PyTypeInfo {
fn bf_getbuffer(&'p self, view: *mut ffi::Py_buffer, flags: c_int) -> Self::Result
where
Self: PyBufferGetBufferProtocol<'p>,
{
fn bf_getbuffer(&'p self,
view: *mut ffi::Py_buffer, flags: c_int) -> Self::Result
where Self: PyBufferGetBufferProtocol<'p> { unimplemented!() }
unimplemented!()
}
fn bf_releasebuffer(&'p self, view: *mut ffi::Py_buffer) -> Self::Result
where Self: PyBufferReleaseBufferProtocol<'p> { unimplemented!() }
where
Self: PyBufferReleaseBufferProtocol<'p>,
{
unimplemented!()
}
}
pub trait PyBufferGetBufferProtocol<'p>: PyBufferProtocol<'p> {
@ -35,17 +40,20 @@ pub trait PyBufferReleaseBufferProtocol<'p>: PyBufferProtocol<'p> {
type Result: Into<PyResult<()>>;
}
#[doc(hidden)]
pub trait PyBufferProtocolImpl {
fn tp_as_buffer() -> Option<ffi::PyBufferProcs>;
}
impl<T> PyBufferProtocolImpl for T {
default fn tp_as_buffer() -> Option<ffi::PyBufferProcs> { None }
default fn tp_as_buffer() -> Option<ffi::PyBufferProcs> {
None
}
}
impl<'p, T> PyBufferProtocolImpl for T where T: PyBufferProtocol<'p>
impl<'p, T> PyBufferProtocolImpl for T
where
T: PyBufferProtocol<'p>,
{
#[inline]
@ -62,7 +70,9 @@ trait PyBufferGetBufferProtocolImpl {
fn cb_bf_getbuffer() -> Option<ffi::getbufferproc>;
}
impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p>
impl<'p, T> PyBufferGetBufferProtocolImpl for T
where
T: PyBufferProtocol<'p>,
{
#[inline]
default fn cb_bf_getbuffer() -> Option<ffi::getbufferproc> {
@ -71,14 +81,18 @@ impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p>
}
impl<T> PyBufferGetBufferProtocolImpl for T
where T: for<'p> PyBufferGetBufferProtocol<'p>
where
T: for<'p> PyBufferGetBufferProtocol<'p>,
{
#[inline]
fn cb_bf_getbuffer() -> Option<ffi::getbufferproc> {
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
arg1: *mut ffi::Py_buffer,
arg2: c_int) -> c_int
where T: for<'p> PyBufferGetBufferProtocol<'p>
arg2: c_int,
) -> c_int
where
T: for<'p> PyBufferGetBufferProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = ::Python::assume_gil_acquired();

View File

@ -4,23 +4,31 @@
//! Trait and support implementation for context manager api
//!
use class::methods::PyMethodDef;
use err::PyResult;
use typeob::PyTypeInfo;
use class::methods::PyMethodDef;
/// Context manager interface
#[allow(unused_variables)]
pub trait PyContextProtocol<'p>: PyTypeInfo {
fn __enter__(&'p mut self) -> Self::Result
where
Self: PyContextEnterProtocol<'p>,
{
unimplemented!()
}
fn __enter__(&'p mut self)
-> Self::Result where Self: PyContextEnterProtocol<'p> {unimplemented!()}
fn __exit__(&'p mut self,
fn __exit__(
&'p mut self,
exc_type: Option<Self::ExcType>,
exc_value: Option<Self::ExcValue>,
traceback: Option<Self::Traceback>)
-> Self::Result where Self: PyContextExitProtocol<'p> { unimplemented!() }
traceback: Option<Self::Traceback>,
) -> Self::Result
where
Self: PyContextExitProtocol<'p>,
{
unimplemented!()
}
}
pub trait PyContextEnterProtocol<'p>: PyContextProtocol<'p> {
@ -48,7 +56,10 @@ impl<T> PyContextProtocolImpl for T {
}
}
impl<'p, T> PyContextProtocolImpl for T where T: PyContextProtocol<'p> {
impl<'p, T> PyContextProtocolImpl for T
where
T: PyContextProtocol<'p>,
{
#[inline]
fn methods() -> Vec<PyMethodDef> {
let mut methods = Vec::new();
@ -69,7 +80,9 @@ pub trait PyContextEnterProtocolImpl {
fn __enter__() -> Option<PyMethodDef>;
}
impl<'p, T> PyContextEnterProtocolImpl for T where T: PyContextProtocol<'p>
impl<'p, T> PyContextEnterProtocolImpl for T
where
T: PyContextProtocol<'p>,
{
#[inline]
default fn __enter__() -> Option<PyMethodDef> {
@ -82,7 +95,9 @@ pub trait PyContextExitProtocolImpl {
fn __exit__() -> Option<PyMethodDef>;
}
impl<'p, T> PyContextExitProtocolImpl for T where T: PyContextProtocol<'p>
impl<'p, T> PyContextExitProtocolImpl for T
where
T: PyContextProtocol<'p>,
{
#[inline]
default fn __exit__() -> Option<PyMethodDef> {

View File

@ -7,30 +7,44 @@
use std::os::raw::c_int;
use ffi;
use err::PyResult;
use objects::{PyType, PyObjectRef};
use callback::{PyObjectCallbackConverter, UnitCallbackConverter};
use typeob::PyTypeInfo;
use class::methods::PyMethodDef;
use conversion::{IntoPyObject, FromPyObject};
use conversion::{FromPyObject, IntoPyObject};
use err::PyResult;
use ffi;
use objects::{PyObjectRef, PyType};
use typeob::PyTypeInfo;
/// Descriptor interface
#[allow(unused_variables)]
pub trait PyDescrProtocol<'p>: PyTypeInfo {
fn __get__(&'p self, instance: &'p PyObjectRef, owner: Option<&'p PyType>) -> Self::Result
where
Self: PyDescrGetProtocol<'p>,
{
unimplemented!()
}
fn __get__(&'p self, instance: &'p PyObjectRef, owner: Option<&'p PyType>)
-> Self::Result where Self: PyDescrGetProtocol<'p> { unimplemented!() }
fn __set__(&'p self, instance: &'p PyObjectRef, value: &'p PyObjectRef) -> Self::Result
where
Self: PyDescrSetProtocol<'p>,
{
unimplemented!()
}
fn __set__(&'p self, instance: &'p PyObjectRef, value: &'p PyObjectRef)
-> Self::Result where Self: PyDescrSetProtocol<'p> { unimplemented!() }
fn __delete__(&'p self, instance: &'p PyObjectRef) -> Self::Result
where
Self: PyDescrDeleteProtocol<'p>,
{
unimplemented!()
}
fn __delete__(&'p self, instance: &'p PyObjectRef)
-> Self::Result where Self: PyDescrDeleteProtocol<'p> { unimplemented!() }
fn __set_name__(&'p self, instance: &'p PyObjectRef)
-> Self::Result where Self: PyDescrSetNameProtocol<'p> { unimplemented!() }
fn __set_name__(&'p self, instance: &'p PyObjectRef) -> Self::Result
where
Self: PyDescrSetNameProtocol<'p>,
{
unimplemented!()
}
}
pub trait PyDescrGetProtocol<'p>: PyDescrProtocol<'p> {
@ -56,40 +70,63 @@ pub trait PyDescrSetNameProtocol<'p>: PyDescrProtocol<'p> {
type Result: Into<PyResult<()>>;
}
trait PyDescrGetProtocolImpl {
fn tp_descr_get() -> Option<ffi::descrgetfunc>;
}
impl<'p, T> PyDescrGetProtocolImpl for T where T: PyDescrProtocol<'p> {
impl<'p, T> PyDescrGetProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
default fn tp_descr_get() -> Option<ffi::descrgetfunc> {
None
}
}
impl<T> PyDescrGetProtocolImpl for T where T: for<'p> PyDescrGetProtocol<'p>
impl<T> PyDescrGetProtocolImpl for T
where
T: for<'p> PyDescrGetProtocol<'p>,
{
fn tp_descr_get() -> Option<ffi::descrgetfunc> {
py_ternary_func!(PyDescrGetProtocol, T::__get__, T::Success, PyObjectCallbackConverter)
py_ternary_func!(
PyDescrGetProtocol,
T::__get__,
T::Success,
PyObjectCallbackConverter
)
}
}
trait PyDescrSetProtocolImpl {
fn tp_descr_set() -> Option<ffi::descrsetfunc>;
}
impl<'p, T> PyDescrSetProtocolImpl for T where T: PyDescrProtocol<'p> {
impl<'p, T> PyDescrSetProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
default fn tp_descr_set() -> Option<ffi::descrsetfunc> {
None
}
}
impl<T> PyDescrSetProtocolImpl for T where T: for<'p> PyDescrSetProtocol<'p>
impl<T> PyDescrSetProtocolImpl for T
where
T: for<'p> PyDescrSetProtocol<'p>,
{
fn tp_descr_set() -> Option<ffi::descrsetfunc> {
py_ternary_func!(PyDescrSetProtocol, T::__set__, (), UnitCallbackConverter, c_int)
py_ternary_func!(
PyDescrSetProtocol,
T::__set__,
(),
UnitCallbackConverter,
c_int
)
}
}
trait PyDescrDelProtocolImpl {
fn __del__() -> Option<PyMethodDef>;
}
impl<'p, T> PyDescrDelProtocolImpl for T where T: PyDescrProtocol<'p> {
impl<'p, T> PyDescrDelProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
default fn __del__() -> Option<PyMethodDef> {
None
}
@ -98,7 +135,10 @@ impl<'p, T> PyDescrDelProtocolImpl for T where T: PyDescrProtocol<'p> {
trait PyDescrSetNameProtocolImpl {
fn __set_name__() -> Option<PyMethodDef>;
}
impl<'p, T> PyDescrSetNameProtocolImpl for T where T: PyDescrProtocol<'p> {
impl<'p, T> PyDescrSetNameProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
default fn __set_name__() -> Option<PyMethodDef> {
None
}
@ -114,11 +154,13 @@ impl<T> PyDescrProtocolImpl for T {
default fn methods() -> Vec<PyMethodDef> {
Vec::new()
}
default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {
}
default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {}
}
impl<'p, T> PyDescrProtocolImpl for T where T: PyDescrProtocol<'p> {
impl<'p, T> PyDescrProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
fn methods() -> Vec<PyMethodDef> {
Vec::new()
}

View File

@ -15,12 +15,13 @@ pub struct PyTraverseError(c_int);
/// GC support
#[allow(unused_variables)]
pub trait PyGCProtocol<'p>: PyTypeInfo {
fn __traverse__(&'p self, visit: PyVisit) -> Result<(), PyTraverseError> {
unimplemented!()
}
fn __traverse__(&'p self, visit: PyVisit)
-> Result<(), PyTraverseError> { unimplemented!() }
fn __clear__(&'p mut self) { unimplemented!() }
fn __clear__(&'p mut self) {
unimplemented!()
}
}
pub trait PyGCTraverseProtocol<'p>: PyGCProtocol<'p> {}
@ -35,7 +36,9 @@ impl<'p, T> PyGCProtocolImpl for T {
default fn update_type_object(_type_object: &mut ffi::PyTypeObject) {}
}
impl<'p, T> PyGCProtocolImpl for T where T: PyGCProtocol<'p>
impl<'p, T> PyGCProtocolImpl for T
where
T: PyGCProtocol<'p>,
{
fn update_type_object(type_object: &mut ffi::PyTypeObject) {
type_object.tp_traverse = Self::tp_traverse();
@ -50,12 +53,13 @@ pub struct PyVisit<'p> {
/// VisitProc contains a Python instance to ensure that
/// 1) it is cannot be moved out of the traverse() call
/// 2) it cannot be sent to other threads
_py: Python<'p>
_py: Python<'p>,
}
impl<'p> PyVisit<'p> {
pub fn call<T>(&self, obj: &T) -> Result<(), PyTraverseError>
where T: ToPyPointer
where
T: ToPyPointer,
{
let r = unsafe { (self.visit)(obj.as_ptr(), self.arg) };
if r == 0 {
@ -70,7 +74,9 @@ trait PyGCTraverseProtocolImpl {
fn tp_traverse() -> Option<ffi::traverseproc>;
}
impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p>
impl<'p, T> PyGCTraverseProtocolImpl for T
where
T: PyGCProtocol<'p>,
{
#[inline]
default fn tp_traverse() -> Option<ffi::traverseproc> {
@ -79,23 +85,32 @@ impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p>
}
#[doc(hidden)]
impl<T> PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p>
impl<T> PyGCTraverseProtocolImpl for T
where
T: for<'p> PyGCTraverseProtocol<'p>,
{
#[inline]
fn tp_traverse() -> Option<ffi::traverseproc> {
unsafe extern "C" fn tp_traverse<T>(slf: *mut ffi::PyObject,
unsafe extern "C" fn tp_traverse<T>(
slf: *mut ffi::PyObject,
visit: ffi::visitproc,
arg: *mut c_void) -> c_int
where T: for<'p> PyGCTraverseProtocol<'p>
arg: *mut c_void,
) -> c_int
where
T: for<'p> PyGCTraverseProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = Python::assume_gil_acquired();
let slf = py.mut_from_borrowed_ptr::<T>(slf);
let visit = PyVisit { visit, arg, _py: py };
let visit = PyVisit {
visit,
arg,
_py: py,
};
match slf.__traverse__(visit) {
Ok(()) => 0,
Err(PyTraverseError(code)) => code
Err(PyTraverseError(code)) => code,
}
}
@ -103,12 +118,13 @@ impl<T> PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p>
}
}
trait PyGCClearProtocolImpl {
fn tp_clear() -> Option<ffi::inquiry>;
}
impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p>
impl<'p, T> PyGCClearProtocolImpl for T
where
T: PyGCProtocol<'p>,
{
#[inline]
default fn tp_clear() -> Option<ffi::inquiry> {
@ -116,12 +132,15 @@ impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p>
}
}
impl<T> PyGCClearProtocolImpl for T where T: for<'p> PyGCClearProtocol<'p>
impl<T> PyGCClearProtocolImpl for T
where
T: for<'p> PyGCClearProtocol<'p>,
{
#[inline]
fn tp_clear() -> Option<ffi::inquiry> {
unsafe extern "C" fn tp_clear<T>(slf: *mut ffi::PyObject) -> c_int
where T: for<'p> PyGCClearProtocol<'p>
where
T: for<'p> PyGCClearProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = Python::assume_gil_acquired();

View File

@ -4,13 +4,12 @@
use std::ptr;
use ffi;
use err::PyResult;
use python::{Python, IntoPyPointer};
use typeob::PyTypeInfo;
use conversion::IntoPyObject;
use callback::{CallbackConverter, PyObjectCallbackConverter};
use conversion::IntoPyObject;
use err::PyResult;
use ffi;
use python::{IntoPyPointer, Python};
use typeob::PyTypeInfo;
/// Python Iterator Interface.
///
@ -18,12 +17,19 @@ use callback::{CallbackConverter, PyObjectCallbackConverter};
/// `https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_iter`
#[allow(unused_variables)]
pub trait PyIterProtocol<'p>: PyTypeInfo {
fn __iter__(&'p mut self)
-> Self::Result where Self: PyIterIterProtocol<'p> { unimplemented!() }
fn __next__(&'p mut self)
-> Self::Result where Self: PyIterNextProtocol<'p> { unimplemented!() }
fn __iter__(&'p mut self) -> Self::Result
where
Self: PyIterIterProtocol<'p>,
{
unimplemented!()
}
fn __next__(&'p mut self) -> Self::Result
where
Self: PyIterNextProtocol<'p>,
{
unimplemented!()
}
}
pub trait PyIterIterProtocol<'p>: PyIterProtocol<'p> {
@ -36,7 +42,6 @@ pub trait PyIterNextProtocol<'p>: PyIterProtocol<'p> {
type Result: Into<PyResult<Option<Self::Success>>>;
}
#[doc(hidden)]
pub trait PyIterProtocolImpl {
fn tp_as_iter(typeob: &mut ffi::PyTypeObject);
@ -47,7 +52,10 @@ impl<T> PyIterProtocolImpl for T {
default fn tp_as_iter(_: &mut ffi::PyTypeObject) {}
}
impl<'p, T> PyIterProtocolImpl for T where T: PyIterProtocol<'p> {
impl<'p, T> PyIterProtocolImpl for T
where
T: PyIterProtocol<'p>,
{
#[inline]
fn tp_as_iter(typeob: &mut ffi::PyTypeObject) {
typeob.tp_iter = Self::tp_iter();
@ -59,7 +67,9 @@ trait PyIterIterProtocolImpl {
fn tp_iter() -> Option<ffi::getiterfunc>;
}
impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p>
impl<'p, T> PyIterIterProtocolImpl for T
where
T: PyIterProtocol<'p>,
{
#[inline]
default fn tp_iter() -> Option<ffi::getiterfunc> {
@ -67,11 +77,18 @@ impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p>
}
}
impl<T> PyIterIterProtocolImpl for T where T: for<'p> PyIterIterProtocol<'p>
impl<T> PyIterIterProtocolImpl for T
where
T: for<'p> PyIterIterProtocol<'p>,
{
#[inline]
fn tp_iter() -> Option<ffi::getiterfunc> {
py_unary_func!(PyIterIterProtocol, T::__iter__, T::Success, PyObjectCallbackConverter)
py_unary_func!(
PyIterIterProtocol,
T::__iter__,
T::Success,
PyObjectCallbackConverter
)
}
}
@ -80,7 +97,8 @@ trait PyIterNextProtocolImpl {
}
impl<'p, T> PyIterNextProtocolImpl for T
where T: PyIterProtocol<'p>
where
T: PyIterProtocol<'p>,
{
#[inline]
default fn tp_iternext() -> Option<ffi::iternextfunc> {
@ -88,20 +106,26 @@ impl<'p, T> PyIterNextProtocolImpl for T
}
}
impl<T> PyIterNextProtocolImpl for T where T: for<'p> PyIterNextProtocol<'p>
impl<T> PyIterNextProtocolImpl for T
where
T: for<'p> PyIterNextProtocol<'p>,
{
#[inline]
fn tp_iternext() -> Option<ffi::iternextfunc> {
py_unary_func!(PyIterNextProtocol, T::__next__,
Option<T::Success>, IterNextConverter)
py_unary_func!(
PyIterNextProtocol,
T::__next__,
Option<T::Success>,
IterNextConverter
)
}
}
struct IterNextConverter;
impl<T> CallbackConverter<Option<T>> for IterNextConverter
where T: IntoPyObject
where
T: IntoPyObject,
{
type R = *mut ffi::PyObject;
@ -111,7 +135,7 @@ impl <T> CallbackConverter<Option<T>> for IterNextConverter
None => unsafe {
ffi::PyErr_SetNone(ffi::PyExc_StopIteration);
ptr::null_mut()
}
},
}
}

View File

@ -4,11 +4,18 @@
#[doc(hidden)]
macro_rules! py_unary_func {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {
py_unary_func!($trait, $class::$f, $res_type, $conv, *mut $crate::ffi::PyObject);
py_unary_func!(
$trait,
$class::$f,
$res_type,
$conv,
*mut $crate::ffi::PyObject
);
};
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr, $ret_type:ty) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject) -> $ret_type
where T: for<'p> $trait<'p>
where
T: for<'p> $trait<'p>,
{
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
@ -17,16 +24,16 @@ macro_rules! py_unary_func {
$crate::callback::cb_convert($conv, py, res)
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_unary_func_self {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:ty) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject)
-> *mut $crate::ffi::PyObject
where T: for<'p> $trait<'p>
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject) -> *mut $crate::ffi::PyObject
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
let _pool = $crate::GILPool::new();
@ -36,17 +43,16 @@ macro_rules! py_unary_func {
$crate::callback::cb_convert($conv, py, res)
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_len_func {
($trait:ident, $class:ident :: $f:ident, $conv:expr) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject)
-> $crate::ffi::Py_ssize_t
where T: for<'p> $trait<'p>
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject) -> $crate::ffi::Py_ssize_t
where
T: for<'p> $trait<'p>,
{
let _pool = $crate::GILPool::new();
let py = Python::assume_gil_acquired();
@ -56,20 +62,26 @@ macro_rules! py_len_func {
$crate::callback::cb_convert($conv, py, result)
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_binary_func {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {
py_binary_func!($trait, $class::$f, $res_type, $conv, *mut $crate::ffi::PyObject)
py_binary_func!(
$trait,
$class::$f,
$res_type,
$conv,
*mut $crate::ffi::PyObject
)
};
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr, $return:ty) => {{
#[allow(unused_mut)]
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
arg: *mut ffi::PyObject) -> $return
where T: for<'p> $trait<'p>
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject, arg: *mut ffi::PyObject) -> $return
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
let _pool = $crate::GILPool::new();
@ -84,7 +96,7 @@ macro_rules! py_binary_func{
$crate::callback::cb_convert($conv, py, result)
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
@ -92,9 +104,12 @@ macro_rules! py_binary_func{
macro_rules! py_binary_num_func {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {{
#[allow(unused_mut)]
unsafe extern "C" fn wrap<T>(lhs: *mut ffi::PyObject,
rhs: *mut ffi::PyObject) -> *mut $crate::ffi::PyObject
where T: for<'p> $trait<'p>
unsafe extern "C" fn wrap<T>(
lhs: *mut ffi::PyObject,
rhs: *mut ffi::PyObject,
) -> *mut $crate::ffi::PyObject
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
let _pool = $crate::GILPool::new();
@ -112,7 +127,7 @@ macro_rules! py_binary_num_func{
$crate::callback::cb_convert($conv, py, result)
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
@ -120,9 +135,12 @@ macro_rules! py_binary_num_func{
macro_rules! py_binary_self_func {
($trait:ident, $class:ident :: $f:ident) => {{
#[allow(unused_mut)]
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
arg: *mut ffi::PyObject) -> *mut $crate::ffi::PyObject
where T: for<'p> $trait<'p>
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
arg: *mut ffi::PyObject,
) -> *mut $crate::ffi::PyObject
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
@ -147,18 +165,20 @@ macro_rules! py_binary_self_func{
}
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_ssizearg_func {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {{
#[allow(unused_mut)]
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
arg: $crate::ffi::Py_ssize_t) -> *mut $crate::ffi::PyObject
where T: for<'p> $trait<'p>
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
arg: $crate::ffi::Py_ssize_t,
) -> *mut $crate::ffi::PyObject
where
T: for<'p> $trait<'p>,
{
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
@ -167,20 +187,29 @@ macro_rules! py_ssizearg_func {
$crate::callback::cb_convert($conv, py, result)
}
Some(wrap::<$class>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_ternary_func {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {
py_ternary_func!($trait, $class::$f, $res_type, $conv, *mut $crate::ffi::PyObject);
py_ternary_func!(
$trait,
$class::$f,
$res_type,
$conv,
*mut $crate::ffi::PyObject
);
};
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr, $return_type:ty) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut $crate::ffi::PyObject,
arg1: *mut $crate::ffi::PyObject,
arg2: *mut $crate::ffi::PyObject) -> $return_type
where T: for<'p> $trait<'p>
arg2: *mut $crate::ffi::PyObject,
) -> $return_type
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
@ -193,7 +222,7 @@ macro_rules! py_ternary_func{
let result = match arg1.extract() {
Ok(arg1) => match arg2.extract() {
Ok(arg2) => slf.$f(arg1, arg2).into(),
Err(e) => Err(e.into())
Err(e) => Err(e.into()),
},
Err(e) => Err(e.into()),
};
@ -201,17 +230,20 @@ macro_rules! py_ternary_func{
}
Some(wrap::<T>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_ternary_num_func {
($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {{
unsafe extern "C" fn wrap<T>(arg1: *mut $crate::ffi::PyObject,
unsafe extern "C" fn wrap<T>(
arg1: *mut $crate::ffi::PyObject,
arg2: *mut $crate::ffi::PyObject,
arg3: *mut $crate::ffi::PyObject) -> *mut $crate::ffi::PyObject
where T: for<'p> $trait<'p>
arg3: *mut $crate::ffi::PyObject,
) -> *mut $crate::ffi::PyObject
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
@ -225,9 +257,9 @@ macro_rules! py_ternary_num_func{
Ok(arg1) => match arg2.extract() {
Ok(arg2) => match arg3.extract() {
Ok(arg3) => $class::$f(arg1, arg2, arg3).into(),
Err(e) => Err(e.into())
Err(e) => Err(e.into()),
},
Err(e) => Err(e.into())
Err(e) => Err(e.into()),
},
Err(e) => Err(e.into()),
};
@ -235,18 +267,20 @@ macro_rules! py_ternary_num_func{
}
Some(wrap::<T>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_ternary_self_func {
($trait:ident, $class:ident :: $f:ident) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut $crate::ffi::PyObject,
arg1: *mut $crate::ffi::PyObject,
arg2: *mut $crate::ffi::PyObject)
-> *mut $crate::ffi::PyObject
where T: for<'p> $trait<'p>
arg2: *mut $crate::ffi::PyObject,
) -> *mut $crate::ffi::PyObject
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
@ -259,7 +293,7 @@ macro_rules! py_ternary_self_func{
let result = match arg1.extract() {
Ok(arg1) => match arg2.extract() {
Ok(arg2) => slf1.$f(arg1, arg2).into(),
Err(e) => Err(e.into())
Err(e) => Err(e.into()),
},
Err(e) => Err(e.into()),
};
@ -273,18 +307,20 @@ macro_rules! py_ternary_self_func{
}
}
Some(wrap::<T>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_func_set {
($trait:ident, $class:ident :: $f:ident) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut $crate::ffi::PyObject,
name: *mut $crate::ffi::PyObject,
value: *mut $crate::ffi::PyObject) -> $crate::c_int
where T: for<'p> $trait<'p>
value: *mut $crate::ffi::PyObject,
) -> $crate::c_int
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
@ -293,8 +329,10 @@ macro_rules! py_func_set{
let slf = py.mut_from_borrowed_ptr::<T>(slf);
if value.is_null() {
let e = $crate::PyErr::new::<exc::NotImplementedError, _>(
format!("Subscript deletion not supported by {:?}", stringify!(T)));
let e = $crate::PyErr::new::<exc::NotImplementedError, _>(format!(
"Subscript deletion not supported by {:?}",
stringify!(T)
));
e.restore(py);
-1
} else {
@ -302,15 +340,13 @@ macro_rules! py_func_set{
let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value);
let result = match name.extract() {
Ok(name) => match value.extract() {
Ok(value) =>
slf.$f(name, value).into(),
Ok(value) => slf.$f(name, value).into(),
Err(e) => Err(e.into()),
},
Err(e) => Err(e.into()),
};
match result {
Ok(_) =>
0,
Ok(_) => 0,
Err(e) => {
e.restore(py);
-1
@ -320,19 +356,21 @@ macro_rules! py_func_set{
}
Some(wrap::<T>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_func_del {
($trait:ident, $class:ident :: $f:ident) => {{
#[allow(unused_mut)]
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut $crate::ffi::PyObject,
name: *mut $crate::ffi::PyObject,
value: *mut $crate::ffi::PyObject) -> $crate::c_int
where T: for<'p> $trait<'p>
value: *mut $crate::ffi::PyObject,
) -> $crate::c_int
where
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
@ -355,26 +393,30 @@ macro_rules! py_func_del{
}
}
} else {
let e = PyErr::new::<exc::NotImplementedError, _>(
format!("Subscript assignment not supported by {:?}", stringify!(T)));
let e = PyErr::new::<exc::NotImplementedError, _>(format!(
"Subscript assignment not supported by {:?}",
stringify!(T)
));
e.restore(py);
-1
}
}
Some(wrap::<T>)
}}
}};
}
#[macro_export]
#[doc(hidden)]
macro_rules! py_func_set_del {
($trait:ident, $trait2:ident, $class:ident :: $f:ident/$f2:ident) => {{
unsafe extern "C" fn wrap<T>(slf: *mut $crate::ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut $crate::ffi::PyObject,
name: *mut $crate::ffi::PyObject,
value: *mut $crate::ffi::PyObject) -> $crate::c_int
where T: for<'p> $trait<'p> + for<'p> $trait2<'p>
value: *mut $crate::ffi::PyObject,
) -> $crate::c_int
where
T: for<'p> $trait<'p> + for<'p> $trait2<'p>,
{
use $crate::ObjectProtocol;
@ -399,9 +441,7 @@ macro_rules! py_func_set_del{
let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value);
let result = match name.extract() {
Ok(name) => match value.extract() {
Ok(value) => {
slf.$f(name, value).into()
},
Ok(value) => slf.$f(name, value).into(),
Err(e) => Err(e.into()),
},
Err(e) => Err(e.into()),
@ -416,5 +456,5 @@ macro_rules! py_func_set_del{
}
}
Some(wrap::<T>)
}}
}};
}

View File

@ -3,43 +3,67 @@
//! Python Mapping Interface
//! Trait and support implementation for implementing mapping support
use ffi;
use err::{PyErr, PyResult};
use python::Python;
use objects::exc;
use callback::{PyObjectCallbackConverter, LenResultConverter};
use conversion::{IntoPyObject, FromPyObject};
use typeob::PyTypeInfo;
use callback::{LenResultConverter, PyObjectCallbackConverter};
use class::methods::PyMethodDef;
use conversion::{FromPyObject, IntoPyObject};
use err::{PyErr, PyResult};
use ffi;
use objects::exc;
use python::Python;
use typeob::PyTypeInfo;
/// Mapping interface
#[allow(unused_variables)]
pub trait PyMappingProtocol<'p>: PyTypeInfo {
fn __len__(&'p self)
-> Self::Result where Self: PyMappingLenProtocol<'p> {unimplemented!()}
fn __getitem__(&'p self, key: Self::Key)
-> Self::Result where Self: PyMappingGetItemProtocol<'p> {unimplemented!()}
fn __setitem__(&'p mut self, key: Self::Key, value: Self::Value)
-> Self::Result where Self: PyMappingSetItemProtocol<'p> {unimplemented!()}
fn __delitem__(&'p mut self, key: Self::Key)
-> Self::Result where Self: PyMappingDelItemProtocol<'p> {unimplemented!()}
fn __iter__(&'p self, py: Python<'p>)
-> Self::Result where Self: PyMappingIterProtocol<'p> {unimplemented!()}
fn __contains__(&'p self, value: Self::Value)
-> Self::Result where Self: PyMappingContainsProtocol<'p> {unimplemented!()}
fn __reversed__(&'p self)
-> Self::Result where Self: PyMappingReversedProtocol<'p> {unimplemented!()}
fn __len__(&'p self) -> Self::Result
where
Self: PyMappingLenProtocol<'p>,
{
unimplemented!()
}
fn __getitem__(&'p self, key: Self::Key) -> Self::Result
where
Self: PyMappingGetItemProtocol<'p>,
{
unimplemented!()
}
fn __setitem__(&'p mut self, key: Self::Key, value: Self::Value) -> Self::Result
where
Self: PyMappingSetItemProtocol<'p>,
{
unimplemented!()
}
fn __delitem__(&'p mut self, key: Self::Key) -> Self::Result
where
Self: PyMappingDelItemProtocol<'p>,
{
unimplemented!()
}
fn __iter__(&'p self, py: Python<'p>) -> Self::Result
where
Self: PyMappingIterProtocol<'p>,
{
unimplemented!()
}
fn __contains__(&'p self, value: Self::Value) -> Self::Result
where
Self: PyMappingContainsProtocol<'p>,
{
unimplemented!()
}
fn __reversed__(&'p self) -> Self::Result
where
Self: PyMappingReversedProtocol<'p>,
{
unimplemented!()
}
}
// The following are a bunch of marker traits used to detect
// the existance of a slotted method.
@ -97,7 +121,10 @@ impl<T> PyMappingProtocolImpl for T {
}
}
impl<'p, T> PyMappingProtocolImpl for T where T: PyMappingProtocol<'p> {
impl<'p, T> PyMappingProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
fn tp_as_mapping() -> Option<ffi::PyMappingMethods> {
let f = if let Some(df) = Self::mp_del_subscript() {
@ -135,7 +162,9 @@ trait PyMappingLenProtocolImpl {
fn mp_length() -> Option<ffi::lenfunc>;
}
impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingLenProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn mp_length() -> Option<ffi::lenfunc> {
@ -143,7 +172,9 @@ impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p>
}
}
impl<T> PyMappingLenProtocolImpl for T where T: for<'p> PyMappingLenProtocol<'p>
impl<T> PyMappingLenProtocolImpl for T
where
T: for<'p> PyMappingLenProtocol<'p>,
{
#[inline]
fn mp_length() -> Option<ffi::lenfunc> {
@ -155,7 +186,9 @@ trait PyMappingGetItemProtocolImpl {
fn mp_subscript() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingGetItemProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn mp_subscript() -> Option<ffi::binaryfunc> {
@ -163,12 +196,18 @@ impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p>
}
}
impl<T> PyMappingGetItemProtocolImpl for T where T: for<'p> PyMappingGetItemProtocol<'p>
impl<T> PyMappingGetItemProtocolImpl for T
where
T: for<'p> PyMappingGetItemProtocol<'p>,
{
#[inline]
fn mp_subscript() -> Option<ffi::binaryfunc> {
py_binary_func!(PyMappingGetItemProtocol,
T::__getitem__, T::Success, PyObjectCallbackConverter)
py_binary_func!(
PyMappingGetItemProtocol,
T::__getitem__,
T::Success,
PyObjectCallbackConverter
)
}
}
@ -176,7 +215,9 @@ trait PyMappingSetItemProtocolImpl {
fn mp_ass_subscript() -> Option<ffi::objobjargproc>;
}
impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingSetItemProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn mp_ass_subscript() -> Option<ffi::objobjargproc> {
@ -184,7 +225,9 @@ impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p>
}
}
impl<T> PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProtocol<'p>
impl<T> PyMappingSetItemProtocolImpl for T
where
T: for<'p> PyMappingSetItemProtocol<'p>,
{
#[inline]
fn mp_ass_subscript() -> Option<ffi::objobjargproc> {
@ -192,12 +235,13 @@ impl<T> PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProt
}
}
trait PyMappingDelItemProtocolImpl {
fn mp_del_subscript() -> Option<ffi::objobjargproc>;
}
impl<'p, T> PyMappingDelItemProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingDelItemProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn mp_del_subscript() -> Option<ffi::objobjargproc> {
@ -205,7 +249,9 @@ impl<'p, T> PyMappingDelItemProtocolImpl for T where T: PyMappingProtocol<'p>
}
}
impl<T> PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProtocol<'p>
impl<T> PyMappingDelItemProtocolImpl for T
where
T: for<'p> PyMappingDelItemProtocol<'p>,
{
#[inline]
default fn mp_del_subscript() -> Option<ffi::objobjargproc> {
@ -213,24 +259,28 @@ impl<T> PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProt
}
}
impl<T> PyMappingDelItemProtocolImpl for T
where T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p>
where
T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p>,
{
#[inline]
fn mp_del_subscript() -> Option<ffi::objobjargproc> {
py_func_set_del!(PyMappingSetItemProtocol, PyMappingDelItemProtocol,
T::__setitem__/__delitem__)
py_func_set_del!(
PyMappingSetItemProtocol,
PyMappingDelItemProtocol,
T::__setitem__ / __delitem__
)
}
}
#[doc(hidden)]
pub trait PyMappingContainsProtocolImpl {
fn __contains__() -> Option<PyMethodDef>;
}
impl<'p, T> PyMappingContainsProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingContainsProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn __contains__() -> Option<PyMethodDef> {
@ -243,7 +293,9 @@ pub trait PyMappingReversedProtocolImpl {
fn __reversed__() -> Option<PyMethodDef>;
}
impl<'p, T> PyMappingReversedProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingReversedProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn __reversed__() -> Option<PyMethodDef> {
@ -256,7 +308,9 @@ pub trait PyMappingIterProtocolImpl {
fn __iter__() -> Option<PyMethodDef>;
}
impl<'p, T> PyMappingIterProtocolImpl for T where T: PyMappingProtocol<'p>
impl<'p, T> PyMappingIterProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
#[inline]
default fn __iter__() -> Option<PyMethodDef> {

View File

@ -67,34 +67,29 @@ unsafe impl Sync for PyGetterDef {}
unsafe impl Sync for PySetterDef {}
unsafe impl Sync for ffi::PyGetSetDef {}
impl PyMethodDef {
/// Convert `PyMethodDef` to Python method definition struct `ffi::PyMethodDef`
pub fn as_method_def(&self) -> ffi::PyMethodDef {
let meth = match self.ml_meth {
PyMethodType::PyCFunction(meth) => meth,
PyMethodType::PyCFunctionWithKeywords(meth) =>
unsafe {
PyMethodType::PyCFunctionWithKeywords(meth) => unsafe {
std::mem::transmute::<ffi::PyCFunctionWithKeywords, ffi::PyCFunction>(meth)
},
PyMethodType::PyNoArgsFunction(meth) =>
unsafe {
PyMethodType::PyNoArgsFunction(meth) => unsafe {
std::mem::transmute::<ffi::PyNoArgsFunction, ffi::PyCFunction>(meth)
},
PyMethodType::PyNewFunc(meth) =>
unsafe {
PyMethodType::PyNewFunc(meth) => unsafe {
std::mem::transmute::<ffi::newfunc, ffi::PyCFunction>(meth)
},
PyMethodType::PyInitFunc(meth) =>
unsafe {
PyMethodType::PyInitFunc(meth) => unsafe {
std::mem::transmute::<ffi::initproc, ffi::PyCFunction>(meth)
},
};
ffi::PyMethodDef {
ml_name: CString::new(self.ml_name).expect(
"Method name must not contain NULL byte").into_raw(),
ml_name: CString::new(self.ml_name)
.expect("Method name must not contain NULL byte")
.into_raw(),
ml_meth: Some(meth),
ml_flags: self.ml_flags,
ml_doc: self.ml_doc.as_ptr() as *const _,
@ -106,8 +101,9 @@ impl PyGetterDef {
/// Copy descriptor information to `ffi::PyGetSetDef`
pub fn copy_to(&self, dst: &mut ffi::PyGetSetDef) {
if dst.name.is_null() {
dst.name = CString::new(self.name).expect(
"Method name must not contain NULL byte").into_raw();
dst.name = CString::new(self.name)
.expect("Method name must not contain NULL byte")
.into_raw();
}
dst.get = Some(self.meth);
}
@ -117,8 +113,9 @@ impl PySetterDef {
/// Copy descriptor information to `ffi::PyGetSetDef`
pub fn copy_to(&self, dst: &mut ffi::PyGetSetDef) {
if dst.name.is_null() {
dst.name = CString::new(self.name).expect(
"Method name must not contain NULL byte").into_raw();
dst.name = CString::new(self.name)
.expect("Method name must not contain NULL byte")
.into_raw();
}
dst.set = Some(self.meth);
}

View File

@ -2,33 +2,33 @@
//! Python object protocols
#[macro_use] mod macros;
#[macro_use]
mod macros;
pub mod async;
pub mod basic;
pub mod buffer;
pub mod context;
pub mod descr;
pub mod gc;
pub mod iter;
pub mod mapping;
pub mod methods;
pub mod number;
pub mod iter;
pub mod gc;
pub mod sequence;
pub use self::basic::PyObjectProtocol;
pub use self::async::PyAsyncProtocol;
pub use self::iter::PyIterProtocol;
pub use self::basic::PyObjectProtocol;
pub use self::buffer::PyBufferProtocol;
pub use self::context::PyContextProtocol;
pub use self::descr::PyDescrProtocol;
pub use self::number::PyNumberProtocol;
pub use self::iter::PyIterProtocol;
pub use self::mapping::PyMappingProtocol;
pub use self::number::PyNumberProtocol;
pub use self::sequence::PySequenceProtocol;
pub use self::gc::{PyVisit, PyGCProtocol, PyTraverseError};
pub use self::methods::{PyMethodDef, PyMethodDefType, PyMethodType,
PyGetterDef, PySetterDef};
pub use self::gc::{PyGCProtocol, PyTraverseError, PyVisit};
pub use self::methods::{PyGetterDef, PyMethodDef, PyMethodDefType, PyMethodType, PySetterDef};
use ffi;
@ -40,5 +40,5 @@ pub enum CompareOp {
Eq = ffi::Py_EQ as isize,
Ne = ffi::Py_NE as isize,
Gt = ffi::Py_GT as isize,
Ge = ffi::Py_GE as isize
Ge = ffi::Py_GE as isize,
}

File diff suppressed because it is too large Load Diff

View File

@ -5,46 +5,80 @@
use std::os::raw::c_int;
use ffi;
use python::Python;
use callback::{BoolCallbackConverter, LenResultConverter, PyObjectCallbackConverter};
use conversion::{FromPyObject, IntoPyObject};
use err::{PyErr, PyResult};
use objects::{exc, PyObjectRef};
use ffi;
use objectprotocol::ObjectProtocol;
use callback::{PyObjectCallbackConverter, LenResultConverter, BoolCallbackConverter};
use objects::{exc, PyObjectRef};
use python::Python;
use typeob::PyTypeInfo;
use conversion::{IntoPyObject, FromPyObject};
/// Sequece interface
#[allow(unused_variables)]
pub trait PySequenceProtocol<'p>: PyTypeInfo + Sized
{
pub trait PySequenceProtocol<'p>: PyTypeInfo + Sized {
fn __len__(&'p self) -> Self::Result
where Self: PySequenceLenProtocol<'p> { unimplemented!() }
where
Self: PySequenceLenProtocol<'p>,
{
unimplemented!()
}
fn __getitem__(&'p self, key: isize) -> Self::Result
where Self: PySequenceGetItemProtocol<'p> { unimplemented!() }
where
Self: PySequenceGetItemProtocol<'p>,
{
unimplemented!()
}
fn __setitem__(&'p mut self, key: isize, value: Self::Value) -> Self::Result
where Self: PySequenceSetItemProtocol<'p> { unimplemented!() }
where
Self: PySequenceSetItemProtocol<'p>,
{
unimplemented!()
}
fn __delitem__(&'p mut self, key: isize) -> Self::Result
where Self: PySequenceDelItemProtocol<'p> { unimplemented!() }
where
Self: PySequenceDelItemProtocol<'p>,
{
unimplemented!()
}
fn __contains__(&'p self, item: Self::Item) -> Self::Result
where Self: PySequenceContainsProtocol<'p> { unimplemented!() }
where
Self: PySequenceContainsProtocol<'p>,
{
unimplemented!()
}
fn __concat__(&'p self, other: Self::Other) -> Self::Result
where Self: PySequenceConcatProtocol<'p> { unimplemented!() }
where
Self: PySequenceConcatProtocol<'p>,
{
unimplemented!()
}
fn __repeat__(&'p self, count: isize) -> Self::Result
where Self: PySequenceRepeatProtocol<'p> { unimplemented!() }
where
Self: PySequenceRepeatProtocol<'p>,
{
unimplemented!()
}
fn __inplace_concat__(&'p mut self, other: Self::Other) -> Self::Result
where Self: PySequenceInplaceConcatProtocol<'p> { unimplemented!() }
where
Self: PySequenceInplaceConcatProtocol<'p>,
{
unimplemented!()
}
fn __inplace_repeat__(&'p mut self, count: isize) -> Self::Result
where Self: PySequenceInplaceRepeatProtocol<'p> { unimplemented!() }
where
Self: PySequenceInplaceRepeatProtocol<'p>,
{
unimplemented!()
}
}
// The following are a bunch of marker traits used to detect
@ -105,7 +139,10 @@ impl<T> PySequenceProtocolImpl for T {
}
}
impl<'p, T> PySequenceProtocolImpl for T where T: PySequenceProtocol<'p> {
impl<'p, T> PySequenceProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[cfg(Py_3)]
#[inline]
fn tp_as_sequence() -> Option<ffi::PySequenceMethods> {
@ -156,7 +193,9 @@ trait PySequenceLenProtocolImpl {
fn sq_length() -> Option<ffi::lenfunc>;
}
impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceLenProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_length() -> Option<ffi::lenfunc> {
@ -164,7 +203,9 @@ impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p>
}
}
impl<T> PySequenceLenProtocolImpl for T where T: for<'p> PySequenceLenProtocol<'p>
impl<T> PySequenceLenProtocolImpl for T
where
T: for<'p> PySequenceLenProtocol<'p>,
{
#[inline]
fn sq_length() -> Option<ffi::lenfunc> {
@ -176,7 +217,9 @@ trait PySequenceGetItemProtocolImpl {
fn sq_item() -> Option<ffi::ssizeargfunc>;
}
impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceGetItemProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_item() -> Option<ffi::ssizeargfunc> {
@ -185,12 +228,17 @@ impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p>
}
impl<T> PySequenceGetItemProtocolImpl for T
where T: for<'p> PySequenceGetItemProtocol<'p>
where
T: for<'p> PySequenceGetItemProtocol<'p>,
{
#[inline]
fn sq_item() -> Option<ffi::ssizeargfunc> {
py_ssizearg_func!(
PySequenceGetItemProtocol, T::__getitem__, T::Success, PyObjectCallbackConverter)
PySequenceGetItemProtocol,
T::__getitem__,
T::Success,
PyObjectCallbackConverter
)
}
}
@ -198,7 +246,9 @@ trait PySequenceSetItemProtocolImpl {
fn sq_ass_item() -> Option<ffi::ssizeobjargproc>;
}
impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceSetItemProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_ass_item() -> Option<ffi::ssizeobjargproc> {
@ -207,30 +257,34 @@ impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p>
}
impl<T> PySequenceSetItemProtocolImpl for T
where T: for<'p> PySequenceSetItemProtocol<'p>
where
T: for<'p> PySequenceSetItemProtocol<'p>,
{
#[inline]
fn sq_ass_item() -> Option<ffi::ssizeobjargproc> {
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
key: ffi::Py_ssize_t,
value: *mut ffi::PyObject) -> c_int
where T: for<'p> PySequenceSetItemProtocol<'p>
value: *mut ffi::PyObject,
) -> c_int
where
T: for<'p> PySequenceSetItemProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = Python::assume_gil_acquired();
let slf = py.mut_from_borrowed_ptr::<T>(slf);
if value.is_null() {
let e = PyErr::new::<exc::NotImplementedError, _>(
format!("Item deletion not supported by {:?}", stringify!(T)));
let e = PyErr::new::<exc::NotImplementedError, _>(format!(
"Item deletion not supported by {:?}",
stringify!(T)
));
e.restore(py);
-1
} else {
let value = py.from_borrowed_ptr::<PyObjectRef>(value);
let result = match value.extract() {
Ok(value) => {
slf.__setitem__(key as isize, value).into()
},
Ok(value) => slf.__setitem__(key as isize, value).into(),
Err(e) => Err(e),
};
match result {
@ -249,7 +303,9 @@ impl<T> PySequenceSetItemProtocolImpl for T
trait PySequenceDelItemProtocolImpl {
fn sq_del_item() -> Option<ffi::ssizeobjargproc>;
}
impl<'p, T> PySequenceDelItemProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceDelItemProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_del_item() -> Option<ffi::ssizeobjargproc> {
@ -258,14 +314,18 @@ impl<'p, T> PySequenceDelItemProtocolImpl for T where T: PySequenceProtocol<'p>
}
impl<T> PySequenceDelItemProtocolImpl for T
where T: for<'p> PySequenceDelItemProtocol<'p>
where
T: for<'p> PySequenceDelItemProtocol<'p>,
{
#[inline]
default fn sq_del_item() -> Option<ffi::ssizeobjargproc> {
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
key: ffi::Py_ssize_t,
value: *mut ffi::PyObject) -> c_int
where T: for<'p> PySequenceDelItemProtocol<'p>
value: *mut ffi::PyObject,
) -> c_int
where
T: for<'p> PySequenceDelItemProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = Python::assume_gil_acquired();
@ -281,8 +341,10 @@ impl<T> PySequenceDelItemProtocolImpl for T
}
}
} else {
let e = PyErr::new::<exc::NotImplementedError, _>(
format!("Item assignment not supported by {:?}", stringify!(T)));
let e = PyErr::new::<exc::NotImplementedError, _>(format!(
"Item assignment not supported by {:?}",
stringify!(T)
));
e.restore(py);
-1
}
@ -292,15 +354,18 @@ impl<T> PySequenceDelItemProtocolImpl for T
}
impl<T> PySequenceDelItemProtocolImpl for T
where T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>
where
T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>,
{
#[inline]
fn sq_del_item() -> Option<ffi::ssizeobjargproc> {
unsafe extern "C" fn wrap<T>(slf: *mut ffi::PyObject,
unsafe extern "C" fn wrap<T>(
slf: *mut ffi::PyObject,
key: ffi::Py_ssize_t,
value: *mut ffi::PyObject) -> c_int
where T: for<'p> PySequenceSetItemProtocol<'p> +
for<'p> PySequenceDelItemProtocol<'p>
value: *mut ffi::PyObject,
) -> c_int
where
T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>,
{
let _pool = ::GILPool::new();
let py = Python::assume_gil_acquired();
@ -318,9 +383,7 @@ impl<T> PySequenceDelItemProtocolImpl for T
} else {
let value = py.from_borrowed_ptr::<PyObjectRef>(value);
let result = match value.extract() {
Ok(value) => {
slf.__setitem__(key as isize, value).into()
},
Ok(value) => slf.__setitem__(key as isize, value).into(),
Err(e) => Err(e),
};
match result {
@ -336,12 +399,13 @@ impl<T> PySequenceDelItemProtocolImpl for T
}
}
trait PySequenceContainsProtocolImpl {
fn sq_contains() -> Option<ffi::objobjproc>;
}
impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceContainsProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_contains() -> Option<ffi::objobjproc> {
@ -350,12 +414,18 @@ impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p>
}
impl<T> PySequenceContainsProtocolImpl for T
where T: for<'p> PySequenceContainsProtocol<'p>
where
T: for<'p> PySequenceContainsProtocol<'p>,
{
#[inline]
fn sq_contains() -> Option<ffi::objobjproc> {
py_binary_func!(PySequenceContainsProtocol,
T::__contains__, bool, BoolCallbackConverter, c_int)
py_binary_func!(
PySequenceContainsProtocol,
T::__contains__,
bool,
BoolCallbackConverter,
c_int
)
}
}
@ -363,7 +433,9 @@ trait PySequenceConcatProtocolImpl {
fn sq_concat() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceConcatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_concat() -> Option<ffi::binaryfunc> {
@ -372,12 +444,17 @@ impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p>
}
impl<T> PySequenceConcatProtocolImpl for T
where T: for<'p> PySequenceConcatProtocol<'p>
where
T: for<'p> PySequenceConcatProtocol<'p>,
{
#[inline]
fn sq_concat() -> Option<ffi::binaryfunc> {
py_binary_func!(PySequenceConcatProtocol,
T::__concat__, T::Success, PyObjectCallbackConverter)
py_binary_func!(
PySequenceConcatProtocol,
T::__concat__,
T::Success,
PyObjectCallbackConverter
)
}
}
@ -386,7 +463,8 @@ trait PySequenceRepeatProtocolImpl {
}
impl<'p, T> PySequenceRepeatProtocolImpl for T
where T: PySequenceProtocol<'p>
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_repeat() -> Option<ffi::ssizeargfunc> {
@ -394,12 +472,18 @@ impl<'p, T> PySequenceRepeatProtocolImpl for T
}
}
impl<T> PySequenceRepeatProtocolImpl for T where T: for<'p> PySequenceRepeatProtocol<'p>
impl<T> PySequenceRepeatProtocolImpl for T
where
T: for<'p> PySequenceRepeatProtocol<'p>,
{
#[inline]
fn sq_repeat() -> Option<ffi::ssizeargfunc> {
py_ssizearg_func!(
PySequenceRepeatProtocol, T::__repeat__, T::Success, PyObjectCallbackConverter)
PySequenceRepeatProtocol,
T::__repeat__,
T::Success,
PyObjectCallbackConverter
)
}
}
@ -407,7 +491,9 @@ trait PySequenceInplaceConcatProtocolImpl {
fn sq_inplace_concat() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceInplaceConcatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_inplace_concat() -> Option<ffi::binaryfunc> {
@ -416,12 +502,17 @@ impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtoco
}
impl<T> PySequenceInplaceConcatProtocolImpl for T
where T: for<'p> PySequenceInplaceConcatProtocol<'p>
where
T: for<'p> PySequenceInplaceConcatProtocol<'p>,
{
#[inline]
fn sq_inplace_concat() -> Option<ffi::binaryfunc> {
py_binary_func!(PySequenceInplaceConcatProtocol,
T::__inplace_concat__, T, PyObjectCallbackConverter)
py_binary_func!(
PySequenceInplaceConcatProtocol,
T::__inplace_concat__,
T,
PyObjectCallbackConverter
)
}
}
@ -429,7 +520,9 @@ trait PySequenceInplaceRepeatProtocolImpl {
fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc>;
}
impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtocol<'p>
impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
#[inline]
default fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc> {
@ -438,11 +531,16 @@ impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtoco
}
impl<T> PySequenceInplaceRepeatProtocolImpl for T
where T: for<'p> PySequenceInplaceRepeatProtocol<'p>
where
T: for<'p> PySequenceInplaceRepeatProtocol<'p>,
{
#[inline]
fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc> {
py_ssizearg_func!(PySequenceInplaceRepeatProtocol,
T::__inplace_repeat__, T, PyObjectCallbackConverter)
py_ssizearg_func!(
PySequenceInplaceRepeatProtocol,
T::__inplace_repeat__,
T,
PyObjectCallbackConverter
)
}
}

View File

@ -2,38 +2,39 @@
//! This module contains some conversion traits
use err::{PyDowncastError, PyResult};
use ffi;
use err::{PyResult, PyDowncastError};
use python::{Python, ToPyPointer, IntoPyPointer};
use instance::Py;
use object::PyObject;
use objects::{PyObjectRef, PyTuple};
use python::{IntoPyPointer, Python, ToPyPointer};
use typeob::PyTypeInfo;
use instance::Py;
/// Conversion trait that allows various objects to be converted into `PyObject`
pub trait ToPyObject {
/// Converts self into a Python object.
fn to_object(&self, py: Python) -> PyObject;
}
pub trait ToBorrowedObject: ToPyObject {
/// Converts self into a Python object and calls the specified closure
/// on the native FFI pointer underlying the Python object.
///
/// May be more efficient than `to_object` because it does not need
/// to touch any reference counts when the input object already is a Python object.
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
where F: FnOnce(*mut ffi::PyObject) -> R;
where
F: FnOnce(*mut ffi::PyObject) -> R;
}
impl<T> ToBorrowedObject for T where T: ToPyObject {
impl<T> ToBorrowedObject for T
where
T: ToPyObject,
{
#[inline]
default fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
where F: FnOnce(*mut ffi::PyObject) -> R
where
F: FnOnce(*mut ffi::PyObject) -> R,
{
let ptr = self.to_object(py).into_ptr();
let result = f(ptr);
@ -45,18 +46,14 @@ impl<T> ToBorrowedObject for T where T: ToPyObject {
/// Conversion trait that allows various objects to be converted into `PyObject`
/// by consuming original object.
pub trait IntoPyObject {
/// Converts self into a Python object. (Consumes self)
fn into_object(self, py: Python) -> PyObject;
}
/// Conversion trait that allows various objects to be converted into `PyTuple` object.
pub trait IntoPyTuple {
/// Converts self into a PyTuple object.
fn into_tuple(self, py: Python) -> Py<PyTuple>;
}
/// `FromPyObject` is implemented by various types that can be extracted from
@ -86,8 +83,10 @@ pub trait FromPyObject<'source> : Sized {
/// Identity conversion: allows using existing `PyObject` instances where
/// `T: ToPyObject` is expected.
impl <'a, T: ?Sized> ToPyObject for &'a T where T: ToPyObject {
impl<'a, T: ?Sized> ToPyObject for &'a T
where
T: ToPyObject,
{
#[inline]
fn to_object(&self, py: Python) -> PyObject {
<T as ToPyObject>::to_object(*self, py)
@ -96,8 +95,10 @@ impl <'a, T: ?Sized> ToPyObject for &'a T where T: ToPyObject {
/// `Option::Some<T>` is converted like `T`.
/// `Option::None` is converted to Python `None`.
impl <T> ToPyObject for Option<T> where T: ToPyObject {
impl<T> ToPyObject for Option<T>
where
T: ToPyObject,
{
fn to_object(&self, py: Python) -> PyObject {
match *self {
Some(ref val) => val.to_object(py),
@ -106,8 +107,10 @@ impl <T> ToPyObject for Option<T> where T: ToPyObject {
}
}
impl<T> IntoPyObject for Option<T> where T: IntoPyObject {
impl<T> IntoPyObject for Option<T>
where
T: IntoPyObject,
{
fn into_object(self, py: Python) -> PyObject {
match self {
Some(val) => val.into_object(py),
@ -129,7 +132,9 @@ impl IntoPyObject for () {
}
}
impl<'a, T> IntoPyObject for &'a T where T: ToPyPointer
impl<'a, T> IntoPyObject for &'a T
where
T: ToPyPointer,
{
#[inline]
fn into_object(self, py: Python) -> PyObject {
@ -137,7 +142,10 @@ impl<'a, T> IntoPyObject for &'a T where T: ToPyPointer
}
}
impl<'a, T> IntoPyObject for &'a mut T where T: ToPyPointer {
impl<'a, T> IntoPyObject for &'a mut T
where
T: ToPyPointer,
{
#[inline]
fn into_object(self, py: Python) -> PyObject {
unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) }
@ -146,7 +154,8 @@ impl<'a, T> IntoPyObject for &'a mut T where T: ToPyPointer {
/// Extract reference to instance from `PyObject`
impl<'a, T> FromPyObject<'a> for &'a T
where T: PyTypeInfo
where
T: PyTypeInfo,
{
#[inline]
default fn extract(ob: &'a PyObjectRef) -> PyResult<&'a T> {
@ -156,7 +165,8 @@ impl<'a, T> FromPyObject<'a> for &'a T
/// Extract mutable reference to instance from `PyObject`
impl<'a, T> FromPyObject<'a> for &'a mut T
where T: PyTypeInfo
where
T: PyTypeInfo,
{
#[inline]
default fn extract(ob: &'a PyObjectRef) -> PyResult<&'a mut T> {
@ -164,7 +174,9 @@ impl<'a, T> FromPyObject<'a> for &'a mut T
}
}
impl<'a, T> FromPyObject<'a> for Option<T> where T: FromPyObject<'a>
impl<'a, T> FromPyObject<'a> for Option<T>
where
T: FromPyObject<'a>,
{
fn extract(obj: &'a PyObjectRef) -> PyResult<Self> {
if obj.as_ptr() == unsafe { ffi::Py_None() } {
@ -172,7 +184,7 @@ impl<'a, T> FromPyObject<'a> for Option<T> where T: FromPyObject<'a>
} else {
match T::extract(obj) {
Ok(v) => Ok(Some(v)),
Err(e) => Err(e)
Err(e) => Err(e),
}
}
}
@ -217,8 +229,10 @@ pub trait PyTryFrom: Sized {
}
// TryFrom implies TryInto
impl<U> PyTryInto<U> for PyObjectRef where U: PyTryFrom {
impl<U> PyTryInto<U> for PyObjectRef
where
U: PyTryFrom,
{
type Error = U::Error;
fn try_into(&self) -> Result<&U, U::Error> {
@ -235,9 +249,10 @@ impl<U> PyTryInto<U> for PyObjectRef where U: PyTryFrom {
}
}
impl<T> PyTryFrom for T where T: PyTypeInfo {
impl<T> PyTryFrom for T
where
T: PyTypeInfo,
{
type Error = PyDowncastError;
fn try_from(value: &PyObjectRef) -> Result<&T, Self::Error> {
@ -301,7 +316,6 @@ impl<T> PyTryFrom for T where T: PyTypeInfo {
}
}
/// This trait wraps a T: IntoPyObject into PyResult<T> while PyResult<T> remains PyResult<T>.
///
/// This is necessaty because proc macros run before typechecking and can't decide

View File

@ -1,18 +1,18 @@
// Copyright (c) 2017-present PyO3 Project and Contributors
use std;
use std::io;
use std::ffi::CString;
use std::os::raw::c_char;
use std::error::Error;
use libc;
use std;
use std::error::Error;
use std::ffi::CString;
use std::io;
use std::os::raw::c_char;
use conversion::{IntoPyObject, ToBorrowedObject, ToPyObject};
use ffi;
use python::{ToPyPointer, IntoPyPointer, Python};
use object::PyObject;
use objects::{PyObjectRef, PyType, exc};
use instance::Py;
use object::PyObject;
use objects::{exc, PyObjectRef, PyType};
use python::{IntoPyPointer, Python, ToPyPointer};
use typeob::PyTypeObject;
use conversion::{ToPyObject, IntoPyObject, ToBorrowedObject};
/// Defines a new exception type.
///
@ -78,8 +78,11 @@ macro_rules! py_exception {
let py = gil.python();
TYPE_OBJECT = $crate::PyErr::new_type(
py, concat!(stringify!($module), ".", stringify!($name)),
Some(py.get_type::<$base>()), None);
py,
concat!(stringify!($module), ".", stringify!($name)),
Some(py.get_type::<$base>()),
None,
);
}
TYPE_OBJECT
}
@ -96,14 +99,15 @@ macro_rules! py_exception {
fn type_object() -> $crate::Py<$crate::PyType> {
unsafe {
$crate::Py::from_borrowed_ptr(
$name::type_object() as *const _ as *mut $crate::ffi::PyObject)
$name::type_object() as *const _ as *mut $crate::ffi::PyObject
)
}
}
}
};
($module: ident, $name: ident) => {
py_exception!($module, $name, $crate::exc::Exception);
}
};
}
/// Represents a `PyErr` value
@ -156,7 +160,9 @@ impl PyErr {
/// Example:
/// `return Err(PyErr::new::<exc::TypeError, _>("Error message"));`
pub fn new<T, V>(value: V) -> PyErr
where T: PyTypeObject, V: ToPyObject + 'static
where
T: PyTypeObject,
V: ToPyObject + 'static,
{
let ty = T::type_object();
assert_ne!(unsafe { ffi::PyExceptionClass_Check(ty.as_ptr()) }, 0);
@ -173,7 +179,8 @@ impl PyErr {
/// like `exc::RuntimeError`.
/// `args` is the a tuple of arguments to pass to the exception constructor.
pub fn from_type<A>(exc: Py<PyType>, args: A) -> PyErr
where A: ToPyObject + 'static
where
A: ToPyObject + 'static,
{
PyErr {
ptype: exc,
@ -184,7 +191,8 @@ impl PyErr {
/// Creates a new PyErr of type `T`.
pub fn from_value<T>(value: PyErrValue) -> PyErr
where T: PyTypeObject
where
T: PyTypeObject,
{
let ty = T::type_object();
assert_ne!(unsafe { ffi::PyExceptionClass_Check(ty.as_ptr()) }, 0);
@ -220,8 +228,7 @@ impl PyErr {
} else {
PyErr {
ptype: exc::TypeError::type_object(),
pvalue: PyErrValue::ToObject(
Box::new("exceptions must derive from BaseException")),
pvalue: PyErrValue::ToObject(Box::new("exceptions must derive from BaseException")),
ptraceback: None,
}
}
@ -251,12 +258,15 @@ impl PyErr {
///
/// `base` can be an existing exception type to subclass, or a tuple of classes
/// `dict` specifies an optional dictionary of class variables and methods
pub fn new_type<'p>(_: Python<'p>, name: &str, base: Option<&PyType>, dict: Option<PyObject>)
-> *mut ffi::PyTypeObject
{
pub fn new_type<'p>(
_: Python<'p>,
name: &str,
base: Option<&PyType>,
dict: Option<PyObject>,
) -> *mut ffi::PyTypeObject {
let base: *mut ffi::PyObject = match base {
None => std::ptr::null_mut(),
Some(obj) => obj.as_ptr()
Some(obj) => obj.as_ptr(),
};
let dict: *mut ffi::PyObject = match dict {
@ -265,16 +275,18 @@ impl PyErr {
};
unsafe {
let null_terminated_name = CString::new(name)
.expect("Failed to initialize nul terminated exception name");
ffi::PyErr_NewException(
null_terminated_name.as_ptr() as *mut c_char, base, dict) as *mut ffi::PyTypeObject
let null_terminated_name =
CString::new(name).expect("Failed to initialize nul terminated exception name");
ffi::PyErr_NewException(null_terminated_name.as_ptr() as *mut c_char, base, dict)
as *mut ffi::PyTypeObject
}
}
unsafe fn new_from_ffi_tuple(ptype: *mut ffi::PyObject,
unsafe fn new_from_ffi_tuple(
ptype: *mut ffi::PyObject,
pvalue: *mut ffi::PyObject,
ptraceback: *mut ffi::PyObject) -> PyErr {
ptraceback: *mut ffi::PyObject,
) -> PyErr {
// Note: must not panic to ensure all owned pointers get acquired correctly,
// and because we mustn't panic in normalize().
@ -315,7 +327,8 @@ impl PyErr {
/// If `exc` is a class object, this also returns `true` when `self` is an instance of a subclass.
/// If `exc` is a tuple, all exceptions in the tuple (and recursively in subtuples) are searched for a match.
pub fn matches<T>(&self, py: Python, exc: T) -> bool
where T: ToBorrowedObject
where
T: ToBorrowedObject,
{
exc.with_borrowed_ptr(py, |exc| unsafe {
ffi::PyErr_GivenExceptionMatches(self.ptype.as_ptr(), exc) != 0
@ -324,11 +337,11 @@ impl PyErr {
/// Return true if the current exception is instance of `T`
pub fn is_instance<T>(&self, _py: Python) -> bool
where T: PyTypeObject
where
T: PyTypeObject,
{
unsafe {
ffi::PyErr_GivenExceptionMatches(
self.ptype.as_ptr(), T::type_object().as_ptr()) != 0
ffi::PyErr_GivenExceptionMatches(self.ptype.as_ptr(), T::type_object().as_ptr()) != 0
}
}
@ -346,7 +359,11 @@ impl PyErr {
/// Helper function for normalizing the error by deconstructing and reconstructing the PyErr.
/// Must not panic for safety in normalize()
fn into_normalized(self, py: Python) -> PyErr {
let PyErr { ptype, pvalue, ptraceback } = self;
let PyErr {
ptype,
pvalue,
ptraceback,
} = self;
let mut pvalue = match pvalue {
PyErrValue::None => std::ptr::null_mut(),
@ -378,7 +395,11 @@ impl PyErr {
/// This is the opposite of `PyErr::fetch()`.
#[inline]
pub fn restore(self, py: Python) {
let PyErr { ptype, pvalue, ptraceback } = self;
let PyErr {
ptype,
pvalue,
ptraceback,
} = self;
let pvalue = match pvalue {
PyErrValue::None => std::ptr::null_mut(),
@ -386,18 +407,27 @@ impl PyErr {
PyErrValue::ToArgs(ob) => ob.arguments(py).into_ptr(),
PyErrValue::ToObject(ob) => ob.to_object(py).into_ptr(),
};
unsafe {
ffi::PyErr_Restore(ptype.into_ptr(), pvalue, ptraceback.into_ptr())
}
unsafe { ffi::PyErr_Restore(ptype.into_ptr(), pvalue, ptraceback.into_ptr()) }
}
/// Issue a warning message.
/// May return a PyErr if warnings-as-errors is enabled.
pub fn warn(py: Python, category: &PyObjectRef, message: &str, stacklevel: i32) -> PyResult<()> {
pub fn warn(
py: Python,
category: &PyObjectRef,
message: &str,
stacklevel: i32,
) -> PyResult<()> {
let message = CString::new(message)?;
unsafe {
error_on_minusone(py, ffi::PyErr_WarnEx(
category.as_ptr(), message.as_ptr(), stacklevel as ffi::Py_ssize_t))
error_on_minusone(
py,
ffi::PyErr_WarnEx(
category.as_ptr(),
message.as_ptr(),
stacklevel as ffi::Py_ssize_t,
),
)
}
}
@ -409,7 +439,11 @@ impl PyErr {
PyErrValue::ToObject(ref ob) => PyErrValue::Value(ob.to_object(py)),
};
let t = if let Some(ref val) = self.ptraceback { Some(val.clone_ref(py))} else { None };
let t = if let Some(ref val) = self.ptraceback {
Some(val.clone_ref(py))
} else {
None
};
PyErr {
ptype: self.ptype.clone_ref(py),
pvalue: v,
@ -425,14 +459,12 @@ impl std::fmt::Debug for PyErr {
}
impl IntoPyObject for PyErr {
fn into_object(self, py: Python) -> PyObject {
self.instance(py)
}
}
impl ToPyObject for PyErr {
fn to_object(&self, py: Python) -> PyObject {
let err = self.clone_ref(py);
err.instance(py)
@ -440,7 +472,6 @@ impl ToPyObject for PyErr {
}
impl<'a> IntoPyObject for &'a PyErr {
fn into_object(self, py: Python) -> PyObject {
let err = self.clone_ref(py);
err.instance(py)
@ -464,7 +495,9 @@ impl <'p> std::fmt::Debug for PyDowncastError {
impl std::convert::From<PyErr> for std::io::Error {
fn from(err: PyErr) -> Self {
std::io::Error::new(
std::io::ErrorKind::Other, format!("Python exception: {:?}", err))
std::io::ErrorKind::Other,
format!("Python exception: {:?}", err),
)
}
}
@ -488,7 +521,7 @@ macro_rules! impl_to_pyerr {
PyErr::from_value::<$pyexc>(PyErrValue::ToArgs(Box::new(err)))
}
}
}
};
}
#[cfg(Py_3)]
@ -496,27 +529,31 @@ macro_rules! impl_to_pyerr {
impl std::convert::From<io::Error> for PyErr {
fn from(err: io::Error) -> PyErr {
match err.kind() {
io::ErrorKind::BrokenPipe =>
PyErr::from_value::<exc::BrokenPipeError>(PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::ConnectionRefused =>
PyErr::from_value::<exc::ConnectionRefusedError>(
PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::ConnectionAborted =>
PyErr::from_value::<exc::ConnectionAbortedError>(
PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::ConnectionReset =>
PyErr::from_value::<exc::ConnectionResetError>(
PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::Interrupted =>
PyErr::from_value::<exc::InterruptedError>(PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::NotFound =>
PyErr::from_value::<exc::FileNotFoundError>(PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::WouldBlock =>
PyErr::from_value::<exc::BlockingIOError>(PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::TimedOut =>
PyErr::from_value::<exc::TimeoutError>(PyErrValue::ToArgs(Box::new(err))),
_ =>
PyErr::from_value::<exc::OSError>(PyErrValue::ToArgs(Box::new(err))),
io::ErrorKind::BrokenPipe => {
PyErr::from_value::<exc::BrokenPipeError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::ConnectionRefused => {
PyErr::from_value::<exc::ConnectionRefusedError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::ConnectionAborted => {
PyErr::from_value::<exc::ConnectionAbortedError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::ConnectionReset => {
PyErr::from_value::<exc::ConnectionResetError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::Interrupted => {
PyErr::from_value::<exc::InterruptedError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::NotFound => {
PyErr::from_value::<exc::FileNotFoundError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::WouldBlock => {
PyErr::from_value::<exc::BlockingIOError>(PyErrValue::ToArgs(Box::new(err)))
}
io::ErrorKind::TimedOut => {
PyErr::from_value::<exc::TimeoutError>(PyErrValue::ToArgs(Box::new(err)))
}
_ => PyErr::from_value::<exc::OSError>(PyErrValue::ToArgs(Box::new(err))),
}
}
}
@ -529,7 +566,6 @@ impl std::convert::From<io::Error> for PyErr {
}
}
/// Extract `errno` and `errdesc` from from `io::Error`
impl PyErrArguments for io::Error {
fn arguments(&self, py: Python) -> PyObject {
@ -537,8 +573,7 @@ impl PyErrArguments for io::Error {
}
}
impl<W: 'static + Send + std::fmt::Debug> std::convert::From<std::io::IntoInnerError<W>> for PyErr
{
impl<W: 'static + Send + std::fmt::Debug> std::convert::From<std::io::IntoInnerError<W>> for PyErr {
fn from(err: std::io::IntoInnerError<W>) -> PyErr {
PyErr::from_value::<exc::OSError>(PyErrValue::ToArgs(Box::new(err)))
}
@ -563,7 +598,9 @@ impl_to_pyerr!(std::char::DecodeUtf16Error, exc::UnicodeDecodeError);
impl_to_pyerr!(std::net::AddrParseError, exc::ValueError);
pub fn panic_after_error() -> ! {
unsafe { ffi::PyErr_Print(); }
unsafe {
ffi::PyErr_Print();
}
panic!("Python API called failed");
}
@ -579,8 +616,8 @@ pub fn error_on_minusone(py: Python, result: libc::c_int) -> PyResult<()> {
#[cfg(test)]
mod tests {
use ::{Python, PyErr};
use objects::exc;
use {PyErr, Python};
#[test]
fn set_typeerror() {

View File

@ -1,10 +1,11 @@
use std::os::raw::{c_int, c_long};
use ffi2::object::*;
use ffi2::intobject::PyIntObject;
use ffi2::object::*;
use std::os::raw::{c_int, c_long};
pub type PyBoolObject = PyIntObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyBool_Type: PyTypeObject;
static mut _Py_ZeroStruct: PyIntObject;
static mut _Py_TrueStruct: PyIntObject;

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_void, c_int};
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyBuffer_Type: PyTypeObject;
}
@ -14,15 +15,19 @@ pub unsafe fn PyBuffer_Check(op : *mut PyObject) -> c_int {
pub const Py_END_OF_BUFFER: Py_ssize_t = -1;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyBuffer_FromObject(base: *mut PyObject, offset: Py_ssize_t,
size: Py_ssize_t) -> *mut PyObject;
pub fn PyBuffer_FromReadWriteObject(base: *mut PyObject,
offset: Py_ssize_t, size: Py_ssize_t)
-> *mut PyObject;
pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t)
-> *mut PyObject;
pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void,
size: Py_ssize_t) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyBuffer_FromObject(
base: *mut PyObject,
offset: Py_ssize_t,
size: Py_ssize_t,
) -> *mut PyObject;
pub fn PyBuffer_FromReadWriteObject(
base: *mut PyObject,
offset: Py_ssize_t,
size: Py_ssize_t,
) -> *mut PyObject;
pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject;
pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject;
pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject;
}

View File

@ -1,6 +1,6 @@
use std::os::raw::{c_char, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
/*#[repr(C)]
#[deriving(Copy)]
@ -17,7 +17,8 @@ struct PyByteArrayObject {
pub ob_bytes: *mut c_char,
}*/
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyByteArray_Type: PyTypeObject;
pub static mut PyByteArrayIter_Type: PyTypeObject;
}
@ -31,16 +32,14 @@ pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject;
pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject)
-> *mut PyObject;
pub fn PyByteArray_FromStringAndSize(string: *const c_char,
len: Py_ssize_t) -> *mut PyObject;
pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject;
pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject;
pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t;
pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char;
pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t)
-> c_int;
pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int;
}
#[inline(always)]

View File

@ -1,16 +1,16 @@
pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS;
pub use ffi2::stringobject::PyStringObject as PyBytesObject;
pub use ffi2::stringobject::PyString_Type as PyBytes_Type;
pub use ffi2::stringobject::PyString_AS_STRING as PyBytes_AS_STRING;
pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString;
pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize;
pub use ffi2::stringobject::PyString_Check as PyBytes_Check;
pub use ffi2::stringobject::PyString_CheckExact as PyBytes_CheckExact;
pub use ffi2::stringobject::PyString_AS_STRING as PyBytes_AS_STRING;
pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE;
pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS;
pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize;
pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString;
pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat;
pub use ffi2::stringobject::PyString_Size as PyBytes_Size;
pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString;
pub use ffi2::stringobject::PyString_Concat as PyBytes_Concat;
pub use ffi2::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel;
pub use ffi2::stringobject::PyString_Format as PyBytes_Format;
pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize;
pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat;
pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString;
pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize;
pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE;
pub use ffi2::stringobject::PyString_Size as PyBytes_Size;
pub use ffi2::stringobject::PyString_Type as PyBytes_Type;

View File

@ -1,6 +1,6 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -11,10 +11,11 @@ struct PyCellObject {
pub _ob_prev: *mut PyObject,
pub ob_refcnt: Py_ssize_t,
pub ob_type: *mut PyTypeObject,
pub ob_ref: *mut PyObject
pub ob_ref: *mut PyObject,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCell_Type: PyTypeObject;
}
@ -23,7 +24,8 @@ pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyCell_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCell_New(obj: *mut PyObject) -> *mut PyObject;
pub fn PyCell_Get(op: *mut PyObject) -> *mut PyObject;
pub fn PyCell_Set(op: *mut PyObject, obj: *mut PyObject) -> c_int;

View File

@ -1,19 +1,24 @@
use std::os::raw::{c_void, c_char, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::PyObject;
use ffi2::frameobject::PyFrameObject;
use ffi2::object::PyObject;
use ffi2::pyport::Py_ssize_t;
use ffi2::pystate::{PyThreadState, Py_tracefunc};
use ffi2::pythonrun::PyCompilerFlags;
use std::os::raw::{c_char, c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_CallObjectWithKeywords(
callable: *mut PyObject,
args: *mut PyObject,
kwds: *mut PyObject) -> *mut PyObject;
pub fn PyEval_CallFunction(obj: *mut PyObject,
format: *const c_char, ...) -> *mut PyObject;
pub fn PyEval_CallMethod(obj: *mut PyObject,
kwds: *mut PyObject,
) -> *mut PyObject;
pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject;
pub fn PyEval_CallMethod(
obj: *mut PyObject,
methodname: *const c_char,
format: *const c_char, ...) -> *mut PyObject;
format: *const c_char,
...
) -> *mut PyObject;
pub fn PyEval_SetProfile(func: Option<Py_tracefunc>, obj: *mut PyObject);
pub fn PyEval_SetTrace(func: Option<Py_tracefunc>, obj: *mut PyObject);
pub fn PyEval_GetBuiltins() -> *mut PyObject;
@ -23,9 +28,10 @@ use ffi2::pythonrun::PyCompilerFlags;
pub fn PyEval_GetRestricted() -> c_int;
pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int;
pub fn Py_FlushLine() -> c_int;
pub fn Py_AddPendingCall(func: Option<extern "C" fn (arg1: *mut c_void)
-> c_int>,
arg: *mut c_void) -> c_int;
pub fn Py_AddPendingCall(
func: Option<extern "C" fn(arg1: *mut c_void) -> c_int>,
arg: *mut c_void,
) -> c_int;
pub fn Py_MakePendingCalls() -> c_int;
pub fn Py_SetRecursionLimit(arg1: c_int);
pub fn Py_GetRecursionLimit() -> c_int;
@ -43,7 +49,8 @@ use ffi2::pythonrun::PyCompilerFlags;
}
#[cfg(py_sys_config = "WITH_THREAD")]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_ThreadsInitialized() -> c_int;
pub fn PyEval_InitThreads();
pub fn PyEval_AcquireLock();
@ -52,4 +59,3 @@ use ffi2::pythonrun::PyCompilerFlags;
pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState);
pub fn PyEval_ReInitThreads();
}

View File

@ -1,6 +1,6 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -49,7 +49,8 @@ pub struct PyMethodObject {
pub im_weakreflist: *mut PyObject,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyClass_Type: PyTypeObject;
pub static mut PyInstance_Type: PyTypeObject;
pub static mut PyMethod_Type: PyTypeObject;
@ -73,22 +74,29 @@ pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyClass_New(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
pub fn PyInstance_New(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
pub fn PyInstance_NewRaw(arg1: *mut PyObject, arg2: *mut PyObject)
-> *mut PyObject;
pub fn PyMethod_New(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyClass_New(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;
pub fn PyInstance_New(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;
pub fn PyInstance_NewRaw(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
pub fn PyMethod_New(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;
pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyMethod_Self(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyMethod_Class(arg1: *mut PyObject) -> *mut PyObject;
fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject)
-> *mut PyObject;
pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject)
-> c_int;
fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) -> *mut PyObject;
pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub fn PyMethod_ClearFreeList() -> c_int;
}
@ -106,4 +114,3 @@ pub unsafe fn PyMethod_GET_SELF(meth : *mut PyObject) -> *mut PyObject {
pub unsafe fn PyMethod_GET_CLASS(meth: *mut PyObject) -> *mut PyObject {
(*(meth as *mut PyMethodObject)).im_class
}

View File

@ -1,7 +1,8 @@
use std::os::raw::{c_void, c_char, c_int};
use ffi2::object::*;
use std::os::raw::{c_char, c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCObject_Type: PyTypeObject;
}
@ -10,18 +11,19 @@ pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyCObject_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyCObject_FromVoidPtr(cobj: *mut c_void,
destruct: Option<unsafe extern "C" fn (arg1: *mut c_void)>)
-> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
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;
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_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

@ -1,6 +1,6 @@
use std::os::raw::{c_char, c_int, c_void};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_void};
#[repr(C)]
#[derive(Copy, Clone)]
@ -51,28 +51,41 @@ pub const CO_FUTURE_UNICODE_LITERALS : c_int = 0x2_0000;
pub const CO_MAXBLOCKS: usize = 20;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCode_Type: PyTypeObject;
pub fn PyCode_New(arg1: c_int, arg2: c_int,
arg3: c_int, arg4: c_int,
arg5: *mut PyObject, arg6: *mut PyObject,
arg7: *mut PyObject, arg8: *mut PyObject,
arg9: *mut PyObject, arg10: *mut PyObject,
arg11: *mut PyObject, arg12: *mut PyObject,
arg13: c_int, arg14: *mut PyObject)
-> *mut PyCodeObject;
pub fn PyCode_NewEmpty(filename: *const c_char,
pub fn PyCode_New(
arg1: c_int,
arg2: c_int,
arg3: c_int,
arg4: c_int,
arg5: *mut PyObject,
arg6: *mut PyObject,
arg7: *mut PyObject,
arg8: *mut PyObject,
arg9: *mut PyObject,
arg10: *mut PyObject,
arg11: *mut PyObject,
arg12: *mut PyObject,
arg13: c_int,
arg14: *mut PyObject,
) -> *mut PyCodeObject;
pub fn PyCode_NewEmpty(
filename: *const c_char,
funcname: *const c_char,
firstlineno: c_int) -> *mut PyCodeObject;
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int)
-> c_int;
firstlineno: c_int,
) -> *mut PyCodeObject;
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int;
//fn _PyCode_CheckLineNumber(co: *mut PyCodeObject,
// lasti: c_int,
// bounds: *mut PyAddrPair) -> c_int;
pub fn PyCode_Optimize(code: *mut PyObject, consts: *mut PyObject,
names: *mut PyObject, lineno_obj: *mut PyObject)
-> *mut PyObject;
pub fn PyCode_Optimize(
code: *mut PyObject,
consts: *mut PyObject,
names: *mut PyObject,
lineno_obj: *mut PyObject,
) -> *mut PyObject;
}
#[inline(always)]
@ -84,4 +97,3 @@ pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int {
pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t {
::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars)
}

View File

@ -1,7 +1,7 @@
use std::os::raw::{c_char, c_int};
use ffi2::pythonrun::*;
use ffi2::code::*;
use ffi2::pyarena::PyArena;
use ffi2::pythonrun::*;
use std::os::raw::{c_char, c_int};
#[repr(C)]
#[derive(Copy, Clone)]
@ -18,12 +18,14 @@ pub const FUTURE_WITH_STATEMENT : &'static str = "with_statement";
pub const FUTURE_PRINT_FUNCTION: &'static str = "print_function";
pub const FUTURE_UNICODE_LITERALS: &'static str = "unicode_literals";
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyNode_Compile(arg1: *mut Struct__node,
arg2: *const c_char) -> *mut PyCodeObject;
pub fn PyAST_Compile(arg1: *mut Struct__mod, arg2: *const c_char,
arg3: *mut PyCompilerFlags, arg4: *mut PyArena)
-> *mut PyCodeObject;
pub fn PyFuture_FromAST(arg1: *mut Struct__mod,
arg2: *const c_char) -> *mut PyFutureFeatures;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyNode_Compile(arg1: *mut Struct__node, arg2: *const c_char) -> *mut PyCodeObject;
pub fn PyAST_Compile(
arg1: *mut Struct__mod,
arg2: *const c_char,
arg3: *mut PyCompilerFlags,
arg4: *mut PyArena,
) -> *mut PyCodeObject;
pub fn PyFuture_FromAST(arg1: *mut Struct__mod, arg2: *const c_char) -> *mut PyFutureFeatures;
}

View File

@ -1,15 +1,16 @@
use std::os::raw::{c_double, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_double, c_int};
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Py_complex {
pub real: c_double,
pub imag: c_double
pub imag: c_double,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn _Py_c_sum(left: Py_complex, right: Py_complex) -> Py_complex;
pub fn _Py_c_diff(left: Py_complex, right: Py_complex) -> Py_complex;
pub fn _Py_c_neg(complex: Py_complex) -> Py_complex;
@ -28,10 +29,11 @@ pub struct PyComplexObject {
pub _ob_prev: *mut PyObject,
pub ob_refcnt: Py_ssize_t,
pub ob_type: *mut PyTypeObject,
pub cval: Py_complex
pub cval: Py_complex,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyComplex_Type: PyTypeObject;
}
@ -46,18 +48,16 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject;
pub fn PyComplex_FromDoubles(real: c_double,
imag: c_double) -> *mut PyObject;
pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject;
pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double;
pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double;
pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex;
//fn _PyComplex_FormatAdvanced(obj: *mut PyObject,
// format_spec: *mut c_char,
// format_spec_len: Py_ssize_t)
// -> *mut PyObject;
}

View File

@ -1,16 +1,13 @@
use std::ptr;
use std::os::raw::{c_void, c_char, c_int};
use ffi2::methodobject::PyMethodDef;
use ffi2::object::{PyObject, PyTypeObject, Py_TYPE};
use ffi2::structmember::PyMemberDef;
use ffi2::methodobject::PyMethodDef;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
pub type getter =
unsafe extern "C" fn
(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject;
pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject;
pub type setter =
unsafe extern "C" fn (slf: *mut PyObject, value: *mut PyObject,
closure: *mut c_void) -> c_int;
unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int;
#[repr(C)]
#[derive(Copy)]
@ -31,16 +28,22 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef {
};
impl Clone for PyGetSetDef {
#[inline] fn clone(&self) -> PyGetSetDef { *self }
#[inline]
fn clone(&self) -> PyGetSetDef {
*self
}
}
pub type wrapperfunc =
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject,
wrapped: *mut c_void) -> *mut PyObject;
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject, wrapped: *mut c_void)
-> *mut PyObject;
pub type wrapperfunc_kwds =
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject,
wrapped: *mut c_void, kwds: *mut PyObject) -> *mut PyObject;
pub type wrapperfunc_kwds = unsafe extern "C" fn(
slf: *mut PyObject,
args: *mut PyObject,
wrapped: *mut c_void,
kwds: *mut PyObject,
) -> *mut PyObject;
#[repr(C)]
#[derive(Copy)]
@ -51,33 +54,36 @@ pub struct wrapperbase {
pub wrapper: Option<wrapperfunc>,
pub doc: *mut c_char,
pub flags: c_int,
pub name_strobj: *mut PyObject
pub name_strobj: *mut PyObject,
}
impl Clone for wrapperbase {
#[inline] fn clone(&self) -> wrapperbase { *self }
#[inline]
fn clone(&self) -> wrapperbase {
*self
}
}
pub const PyWrapperFlag_KEYWORDS: c_int = 1;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyWrapperDescr_Type: PyTypeObject;
pub static mut PyDictProxy_Type: PyTypeObject;
pub static mut PyGetSetDescr_Type: PyTypeObject;
pub static mut PyMemberDescr_Type: PyTypeObject;
pub static mut PyProperty_Type: PyTypeObject;
pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef)
pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject;
pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef)
-> *mut PyObject;
pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject,
arg2: *mut PyMethodDef) -> *mut PyObject;
pub fn PyDescr_NewMember(arg1: *mut PyTypeObject,
arg2: *mut PyMemberDef) -> *mut PyObject;
pub fn PyDescr_NewGetSet(arg1: *mut PyTypeObject,
arg2: *mut PyGetSetDef) -> *mut PyObject;
pub fn PyDescr_NewWrapper(arg1: *mut PyTypeObject,
pub fn PyDescr_NewMember(arg1: *mut PyTypeObject, arg2: *mut PyMemberDef) -> *mut PyObject;
pub fn PyDescr_NewGetSet(arg1: *mut PyTypeObject, arg2: *mut PyGetSetDef) -> *mut PyObject;
pub fn PyDescr_NewWrapper(
arg1: *mut PyTypeObject,
arg2: *mut wrapperbase,
arg3: *mut c_void) -> *mut PyObject;
arg3: *mut c_void,
) -> *mut PyObject;
}
#[inline(always)]
@ -85,13 +91,9 @@ pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int {
(*Py_TYPE(d)).tp_descr_set.is_some() as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
//pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject;
// PyDictProxy_New is also defined in dictobject.h
pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject)
-> *mut PyObject;
pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
}

View File

@ -1,10 +1,11 @@
use std::os::raw::{c_char, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
//pub enum PyDictObject { /* representation hidden */ }
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyDict_Type: PyTypeObject;
pub static mut PyDictIterKey_Type: PyTypeObject;
pub static mut PyDictIterValue_Type: PyTypeObject;
@ -25,34 +26,35 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyDict_New() -> *mut PyObject;
pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject;
pub fn PyDict_Clear(mp: *mut PyObject);
pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject)
-> c_int;
pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject;
pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject)
-> *mut PyObject;
pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject,
item: *mut PyObject) -> c_int;
pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject)
-> c_int;
pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char)
-> *mut PyObject;
pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char,
item: *mut PyObject) -> c_int;
pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char)
-> c_int;
pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject;
pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int;
pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject;
pub fn PyDict_SetItemString(
dp: *mut PyObject,
key: *const c_char,
item: *mut PyObject,
) -> c_int;
pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int;
pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject;
pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject;
pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject;
pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t;
pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t,
key: *mut *mut PyObject, value: *mut *mut PyObject)
-> c_int;
pub fn PyDict_Next(
mp: *mut PyObject,
pos: *mut Py_ssize_t,
key: *mut *mut PyObject,
value: *mut *mut PyObject,
) -> c_int;
/*pub fn _PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t,
key: *mut *mut PyObject, value: *mut *mut PyObject,
hash: *mut c_long) -> c_int;
@ -60,12 +62,8 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int {
hash: c_long) -> c_int;
pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject;
pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/
pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject)
-> c_int;
pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject,
_override: c_int) -> c_int;
pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject,
_override: c_int) -> c_int;
pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int;
pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject, _override: c_int) -> c_int;
pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject, _override: c_int) -> c_int;
}

View File

@ -1,7 +1,7 @@
use ffi2::object::PyTypeObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyEnum_Type: PyTypeObject;
pub static mut PyReversed_Type: PyTypeObject;
}

View File

@ -1,16 +1,25 @@
use std::os::raw::c_int;
use ffi2::object::PyObject;
use ffi2::code::PyCodeObject;
use ffi2::object::PyObject;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyEval_EvalCode(arg1: *mut PyCodeObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
pub fn PyEval_EvalCodeEx(co: *mut PyCodeObject, globals: *mut PyObject,
locals: *mut PyObject, args: *mut *mut PyObject,
argc: c_int, kwds: *mut *mut PyObject,
kwdc: c_int, defs: *mut *mut PyObject,
defc: c_int, closure: *mut PyObject)
-> *mut PyObject;
fn _PyEval_CallTracing(func: *mut PyObject, args: *mut PyObject)
-> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_EvalCode(
arg1: *mut PyCodeObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;
pub fn PyEval_EvalCodeEx(
co: *mut PyCodeObject,
globals: *mut PyObject,
locals: *mut PyObject,
args: *mut *mut PyObject,
argc: c_int,
kwds: *mut *mut PyObject,
kwdc: c_int,
defs: *mut *mut PyObject,
defc: c_int,
closure: *mut PyObject,
) -> *mut PyObject;
fn _PyEval_CallTracing(func: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
}

View File

@ -1,8 +1,9 @@
use ffi2::object::*;
use libc::{size_t, FILE};
use std::os::raw::{c_char, c_int};
use ffi2::object::*;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFile_Type: PyTypeObject;
}
@ -16,44 +17,45 @@ 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";
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyFile_FromString(arg1: *mut c_char,
arg2: *mut c_char) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
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,
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,
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;
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 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 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

@ -1,6 +1,6 @@
use std::os::raw::{c_char, c_int, c_double};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_double, c_int};
#[repr(C)]
#[derive(Copy, Clone)]
@ -11,10 +11,11 @@ struct PyFloatObject {
pub _ob_prev: *mut PyObject,
pub ob_refcnt: Py_ssize_t,
pub ob_type: *mut PyTypeObject,
pub ob_fval: c_double
pub ob_fval: c_double,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFloat_Type: PyTypeObject;
}
@ -31,10 +32,9 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int {
pub const PyFloat_STR_PRECISION: c_int = 12;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyFloat_FromString(str: *mut PyObject,
pend: *mut *mut c_char)
-> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject;
pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject;
pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double;
pub fn PyFloat_GetInfo() -> *mut PyObject;
@ -47,4 +47,3 @@ pub const PyFloat_STR_PRECISION : c_int = 12;
pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double {
(*(pyfloat as *mut PyFloatObject)).ob_fval
}

View File

@ -1,8 +1,8 @@
use std::os::raw::c_int;
use ffi2::code::{PyCodeObject, CO_MAXBLOCKS};
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use ffi2::code::{PyCodeObject, CO_MAXBLOCKS};
use ffi2::pystate::PyThreadState;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -49,10 +49,11 @@ pub struct PyFrameObject {
pub f_lineno: c_int, /* Current line number */
pub f_iblock: c_int, /* index in f_blockstack */
pub f_blockstack: [PyTryBlock; CO_MAXBLOCKS], /* for try and loop blocks */
pub f_localsplus: [*mut PyObject; 1] /* locals+stack, dynamically sized */
pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFrame_Type: PyTypeObject;
}
@ -66,11 +67,21 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
// ((*f).f_builtins != (*(*(*f).f_tstate).interp).builtins) as c_int
//}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject,
globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFrame_New(
tstate: *mut PyThreadState,
code: *mut PyCodeObject,
globals: *mut PyObject,
locals: *mut PyObject,
) -> *mut PyFrameObject;
pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int) -> ();
pub fn PyFrame_BlockSetup(
f: *mut PyFrameObject,
_type: c_int,
handler: c_int,
level: c_int,
) -> ();
pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;
pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> ();
@ -79,4 +90,3 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
pub fn PyFrame_ClearFreeList() -> c_int;
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
}

View File

@ -1,7 +1,8 @@
use std::os::raw::c_int;
use ffi2::object::*;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFunction_Type: PyTypeObject;
}
@ -11,19 +12,16 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject)
-> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject;
pub fn PyFunction_GetCode(f: *mut PyObject) -> *mut PyObject;
pub fn PyFunction_GetGlobals(f: *mut PyObject) -> *mut PyObject;
pub fn PyFunction_GetModule(f: *mut PyObject) -> *mut PyObject;
pub fn PyFunction_GetDefaults(f: *mut PyObject) -> *mut PyObject;
pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject)
-> c_int;
pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) -> c_int;
pub fn PyFunction_GetClosure(f: *mut PyObject) -> *mut PyObject;
pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject)
-> c_int;
pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) -> c_int;
pub static mut PyClassMethod_Type: PyTypeObject;
pub static mut PyStaticMethod_Type: PyTypeObject;
@ -31,4 +29,3 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int {
pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject;
}

View File

@ -1,7 +1,7 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::frameobject::PyFrameObject;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -15,10 +15,11 @@ pub struct PyGenObject {
pub gi_frame: *mut PyFrameObject,
pub gi_running: c_int,
pub gi_code: *mut PyObject,
pub gi_weakreflist: *mut PyObject
pub gi_weakreflist: *mut PyObject,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyGen_Type: PyTypeObject;
}
@ -32,8 +33,8 @@ pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyGen_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject;
pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
}

View File

@ -1,5 +1,5 @@
use std::os::raw::{c_char, c_uchar, c_int, c_long};
use ffi2::object::*;
use std::os::raw::{c_char, c_int, c_long, c_uchar};
#[repr(C)]
#[derive(Copy)]
@ -9,7 +9,10 @@ pub struct PyImport_Struct_inittab {
}
impl Clone for PyImport_Struct_inittab {
#[inline] fn clone(&self) -> PyImport_Struct_inittab { *self }
#[inline]
fn clone(&self) -> PyImport_Struct_inittab {
*self
}
}
#[repr(C)]
@ -21,45 +24,46 @@ pub struct PyImport_Struct_frozen {
}
#[inline]
pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char,
globals: *mut PyObject,
locals: *mut PyObject,
fromlist: *mut PyObject) -> *mut PyObject {
PyImport_ImportModuleLevel(name, globals, locals, fromlist, -1)
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyImport_ImportModule(name: *const c_char)
-> *mut PyObject;
pub fn PyImport_ImportModuleNoBlock(name: *const c_char)
-> *mut PyObject;
pub fn PyImport_ImportModuleLevel(name: *mut c_char,
pub unsafe fn PyImport_ImportModuleEx(
name: *mut c_char,
globals: *mut PyObject,
locals: *mut PyObject,
fromlist: *mut PyObject,
level: c_int) -> *mut PyObject;
) -> *mut PyObject {
PyImport_ImportModuleLevel(name, globals, locals, fromlist, -1)
}
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject;
pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject;
pub fn PyImport_ImportModuleLevel(
name: *mut c_char,
globals: *mut PyObject,
locals: *mut PyObject,
fromlist: *mut PyObject,
level: c_int,
) -> *mut PyObject;
pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject;
pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject;
pub fn PyImport_ExecCodeModule(name: *mut c_char,
co: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ExecCodeModuleEx(name: *mut c_char,
pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ExecCodeModuleEx(
name: *mut c_char,
co: *mut PyObject,
pathname: *mut c_char)
-> *mut PyObject;
pathname: *mut c_char,
) -> *mut PyObject;
pub fn PyImport_GetMagicNumber() -> c_long;
pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject;
pub fn PyImport_GetModuleDict() -> *mut PyObject;
pub fn PyImport_ImportFrozenModule(name: *mut c_char)
-> c_int;
pub fn PyImport_ImportFrozenModule(name: *mut c_char) -> c_int;
pub fn PyImport_AppendInittab(name: *const c_char,
initfunc:
Option<unsafe extern "C" fn()>)
-> c_int;
pub fn PyImport_ExtendInittab(newtab: *mut PyImport_Struct_inittab)
-> c_int;
pub fn PyImport_AppendInittab(
name: *const c_char,
initfunc: Option<unsafe extern "C" fn()>,
) -> c_int;
pub fn PyImport_ExtendInittab(newtab: *mut PyImport_Struct_inittab) -> c_int;
pub static mut PyImport_Inittab: *mut PyImport_Struct_inittab;
pub static mut PyImport_FrozenModules: *mut PyImport_Struct_frozen;
@ -83,4 +87,3 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char,
arg2: *mut c_char)
-> *mut PyObject;*/
}

View File

@ -1,7 +1,7 @@
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use libc::size_t;
use std::os::raw::{c_char, c_int, c_long, c_ulong, c_ulonglong};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
#[repr(C)]
#[derive(Copy, Clone)]
@ -12,10 +12,11 @@ pub struct PyIntObject {
pub _ob_prev: *mut PyObject,
pub ob_refcnt: Py_ssize_t,
pub ob_type: *mut PyTypeObject,
pub ob_ival: c_long
pub ob_ival: c_long,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyInt_Type: PyTypeObject;
}
@ -30,14 +31,16 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyInt_FromString(str: *mut c_char,
pend: *mut *mut c_char,
base: c_int) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyInt_FromString(str: *mut c_char, pend: *mut *mut c_char, base: c_int)
-> *mut PyObject;
#[cfg(py_sys_config = "Py_USING_UNICODE")]
pub fn PyInt_FromUnicode(u: *mut ::ffi2::unicodeobject::Py_UNICODE,
pub fn PyInt_FromUnicode(
u: *mut ::ffi2::unicodeobject::Py_UNICODE,
length: Py_ssize_t,
base: c_int) -> *mut PyObject;
base: c_int,
) -> *mut PyObject;
pub fn PyInt_FromLong(ival: c_long) -> *mut PyObject;
pub fn PyInt_FromSize_t(ival: size_t) -> *mut PyObject;
pub fn PyInt_FromSsize_t(ival: Py_ssize_t) -> *mut PyObject;
@ -45,8 +48,7 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int {
pub fn PyInt_AsSsize_t(io: *mut PyObject) -> Py_ssize_t;
fn _PyInt_AsInt(io: *mut PyObject) -> c_int;
pub fn PyInt_AsUnsignedLongMask(io: *mut PyObject) -> c_ulong;
pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject)
-> c_ulonglong;
pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) -> c_ulonglong;
pub fn PyInt_GetMax() -> c_long;
//fn PyOS_strtoul(arg1: *mut c_char,
// arg2: *mut *mut c_char, arg3: c_int)
@ -66,4 +68,3 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int {
pub unsafe fn PyInt_AS_LONG(io: *mut PyObject) -> c_long {
(*(io as *mut PyIntObject)).ob_ival
}

View File

@ -1,13 +1,13 @@
use std::os::raw::c_int;
use ffi2::object::*;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PySeqIter_Type: PyTypeObject;
pub static mut PyCallIter_Type: PyTypeObject;
pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject)
-> *mut PyObject;
pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
}
#[inline(always)]

View File

@ -1,6 +1,6 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -16,7 +16,8 @@ pub struct PyListObject {
pub allocated: Py_ssize_t,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyList_Type: PyTypeObject;
}
@ -31,7 +32,6 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
// Macro, trading safety for speed
#[inline(always)]
pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
@ -49,26 +49,25 @@ pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject
*(*(op as *mut PyListObject)).ob_item.offset(i as isize) = v;
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject;
pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t;
pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t)
pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject;
pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int;
pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int;
pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int;
pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t)
-> *mut PyObject;
pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t,
item: *mut PyObject) -> c_int;
pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t,
item: *mut PyObject) -> c_int;
pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject)
-> c_int;
pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t,
high: Py_ssize_t) -> *mut PyObject;
pub fn PyList_SetSlice(list: *mut PyObject, low: Py_ssize_t,
high: Py_ssize_t, itemlist: *mut PyObject)
-> c_int;
pub fn PyList_SetSlice(
list: *mut PyObject,
low: Py_ssize_t,
high: Py_ssize_t,
itemlist: *mut PyObject,
) -> c_int;
pub fn PyList_Sort(list: *mut PyObject) -> c_int;
pub fn PyList_Reverse(list: *mut PyObject) -> c_int;
pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject;
//fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject)
//-> *mut PyObject;
}

View File

@ -1,13 +1,14 @@
use std::os::raw::{
c_void, c_char, c_int, c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_uchar
};
use libc::size_t;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use libc::size_t;
use std::os::raw::{
c_char, c_double, c_int, c_long, c_longlong, c_uchar, c_ulong, c_ulonglong, c_void,
};
pub enum PyLongObject {}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyLong_Type: PyTypeObject;
}
@ -22,38 +23,37 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyLong_FromLong(v: c_long) -> *mut PyObject;
pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject;
pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject;
pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject;
pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject;
pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong)
-> *mut PyObject;
pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject;
pub fn PyLong_FromDouble(v: c_double) -> *mut PyObject;
pub fn PyLong_FromString(str: *mut c_char,
pub fn PyLong_FromString(
str: *mut c_char,
pend: *mut *mut c_char,
base: c_int) -> *mut PyObject;
base: c_int,
) -> *mut PyObject;
#[cfg(py_sys_config = "Py_USING_UNICODE")]
pub fn PyLong_FromUnicode(u: *mut ::ffi2::unicodeobject::Py_UNICODE,
length: Py_ssize_t, base: c_int) -> *mut PyObject;
pub fn PyLong_FromUnicode(
u: *mut ::ffi2::unicodeobject::Py_UNICODE,
length: Py_ssize_t,
base: c_int,
) -> *mut PyObject;
pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject;
pub fn PyLong_AsLong(pylong: *mut PyObject) -> c_long;
pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject,
overflow: *mut c_int)
-> c_long;
pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject,
overflow: *mut c_int)
-> c_longlong;
pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long;
pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong;
pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t;
pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong;
pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong;
pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject)
-> c_ulonglong;
pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong;
pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong;
pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject)
-> c_ulonglong;
pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong;
pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double;
pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void;

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_int, c_char};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyMemoryView_Type: PyTypeObject;
}
@ -22,11 +23,13 @@ pub unsafe fn PyMemoryView_GET_BASE(op : *mut PyObject) -> *mut PyObject {
(*(op as *mut PyMemoryViewObject)).view.obj
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyMemoryView_GetContiguous(base: *mut PyObject,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyMemoryView_GetContiguous(
base: *mut PyObject,
buffertype: c_int,
fort: c_char) -> *mut PyObject;
fort: c_char,
) -> *mut PyObject;
pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject;
pub fn PyMemoryView_FromBuffer(info: *mut Py_buffer) -> *mut PyObject;
}
@ -43,4 +46,3 @@ pub struct PyMemoryViewObject {
pub base: *mut PyObject,
pub view: Py_buffer,
}

View File

@ -1,8 +1,9 @@
use std::ptr;
use std::os::raw::{c_char, c_int};
use ffi2::object::{PyObject, PyTypeObject, Py_TYPE};
use std::os::raw::{c_char, c_int};
use std::ptr;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCFunction_Type: PyTypeObject;
}
@ -13,24 +14,22 @@ pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int {
}
pub type PyCFunction =
unsafe extern "C" fn
(slf: *mut PyObject, args: *mut PyObject)
-> *mut PyObject;
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
pub type PyCFunctionWithKeywords =
unsafe extern "C" fn
(slf: *mut PyObject, args: *mut PyObject,
kwds: *mut PyObject) -> *mut PyObject;
pub type PyNoArgsFunction =
unsafe extern "C" fn(slf: *mut PyObject)
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject)
-> *mut PyObject;
pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option<PyCFunction>;
pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject;
pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int;
pub fn PyCFunction_Call(f: *mut PyObject, args: *mut PyObject,
kwds: *mut PyObject) -> *mut PyObject;
pub fn PyCFunction_Call(
f: *mut PyObject,
args: *mut PyObject,
kwds: *mut PyObject,
) -> *mut PyObject;
}
#[repr(C)]
@ -50,7 +49,10 @@ pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef {
};
impl Clone for PyMethodDef {
#[inline] fn clone(&self) -> PyMethodDef { *self }
#[inline]
fn clone(&self) -> PyMethodDef {
*self
}
}
/* Flag passed to newmethodobject */
@ -74,7 +76,6 @@ pub const METH_STATIC : c_int = 0x0020;
pub const METH_COEXIST: c_int = 0x0040;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyMethodChain {
@ -98,13 +99,23 @@ struct PyCFunctionObject {
}
*/
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn Py_FindMethod(methods: *mut PyMethodDef, slf: *mut PyObject,
name: *const c_char) -> *mut PyObject;
pub fn PyCFunction_NewEx(ml: *mut PyMethodDef, slf: *mut PyObject,
module: *mut PyObject) -> *mut PyObject;
pub fn Py_FindMethodInChain(chain: *mut PyMethodChain, slf: *mut PyObject,
name: *const c_char) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn Py_FindMethod(
methods: *mut PyMethodDef,
slf: *mut PyObject,
name: *const c_char,
) -> *mut PyObject;
pub fn PyCFunction_NewEx(
ml: *mut PyMethodDef,
slf: *mut PyObject,
module: *mut PyObject,
) -> *mut PyObject;
pub fn Py_FindMethodInChain(
chain: *mut PyMethodChain,
slf: *mut PyObject,
name: *const c_char,
) -> *mut PyObject;
pub fn PyCFunction_ClearFreeList() -> c_int;
}
@ -112,4 +123,3 @@ struct PyCFunctionObject {
pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject {
PyCFunction_NewEx(ml, slf, ptr::null_mut())
}

View File

@ -5,95 +5,95 @@
use std::os::raw::c_int;
pub use self::pyport::*;
pub use self::pymem::*;
pub use self::object::*;
pub use self::objimpl::*;
pub use self::pydebug::*;
#[cfg(py_sys_config="Py_USING_UNICODE")]
pub use self::unicodeobject::*;
pub use self::intobject::*;
pub use self::boolobject::*;
pub use self::longobject::*;
pub use self::floatobject::*;
pub use self::complexobject::*;
pub use self::rangeobject::*;
pub use self::memoryobject::*;
pub use self::bufferobject::*;
pub use self::stringobject::*;
pub use self::bytesobject::*;
pub use self::bytearrayobject::*;
pub use self::tupleobject::*;
pub use self::listobject::*;
pub use self::dictobject::*;
pub use self::enumobject::*;
pub use self::setobject::*;
pub use self::pyerrors::*;
pub use self::pystate::*;
pub use self::pystate::PyGILState_STATE::*;
pub use self::methodobject::*;
pub use self::moduleobject::*;
pub use self::funcobject::*;
pub use self::classobject::*;
pub use self::fileobject::*;
pub use self::cobject::*;
pub use self::pycapsule::*;
pub use self::traceback::*;
pub use self::sliceobject::*;
pub use self::bytesobject::*;
pub use self::cellobject::*;
pub use self::iterobject::*;
pub use self::genobject::*;
pub use self::descrobject::*;
pub use self::warnings::*;
pub use self::weakrefobject::*;
pub use self::pyarena::*;
pub use self::modsupport::*;
pub use self::pythonrun::*;
pub use self::ceval::*;
pub use self::import::*;
pub use self::objectabstract::*;
pub use self::classobject::*;
pub use self::cobject::*;
pub use self::code::*;
pub use self::compile::*;
pub use self::complexobject::*;
pub use self::descrobject::*;
pub use self::dictobject::*;
pub use self::enumobject::*;
pub use self::eval::*;
pub use self::structmember::PyMemberDef;
pub use self::fileobject::*;
pub use self::floatobject::*;
pub use self::frameobject::PyFrameObject;
mod pyport;
mod pymem;
mod object;
mod objimpl;
mod pydebug;
pub use self::funcobject::*;
pub use self::genobject::*;
pub use self::import::*;
pub use self::intobject::*;
pub use self::iterobject::*;
pub use self::listobject::*;
pub use self::longobject::*;
pub use self::memoryobject::*;
pub use self::methodobject::*;
pub use self::modsupport::*;
pub use self::moduleobject::*;
pub use self::object::*;
pub use self::objectabstract::*;
pub use self::objimpl::*;
pub use self::pyarena::*;
pub use self::pycapsule::*;
pub use self::pydebug::*;
pub use self::pyerrors::*;
pub use self::pymem::*;
pub use self::pyport::*;
pub use self::pystate::PyGILState_STATE::*;
pub use self::pystate::*;
pub use self::pythonrun::*;
pub use self::rangeobject::*;
pub use self::setobject::*;
pub use self::sliceobject::*;
pub use self::stringobject::*;
pub use self::structmember::PyMemberDef;
pub use self::traceback::*;
pub use self::tupleobject::*;
#[cfg(py_sys_config = "Py_USING_UNICODE")]
mod unicodeobject; // TODO: incomplete
mod intobject;
pub use self::unicodeobject::*;
pub use self::warnings::*;
pub use self::weakrefobject::*;
mod boolobject;
mod longobject;
mod floatobject;
mod complexobject;
mod rangeobject;
mod stringobject;
mod memoryobject;
mod bufferobject;
mod bytesobject;
mod bytearrayobject;
mod tupleobject;
mod listobject;
mod bytesobject;
mod cellobject;
mod classobject;
mod cobject;
mod complexobject;
mod descrobject;
mod dictobject;
mod enumobject;
mod setobject;
mod fileobject;
mod floatobject;
mod funcobject;
mod genobject;
mod intobject;
mod iterobject;
mod listobject;
mod longobject;
mod memoryobject;
mod methodobject;
mod moduleobject;
mod funcobject;
mod classobject;
mod fileobject;
mod cobject;
mod object;
mod objimpl;
mod pycapsule;
mod traceback;
mod pydebug;
mod pymem;
mod pyport;
mod rangeobject;
mod setobject;
mod sliceobject;
mod cellobject;
mod iterobject;
mod genobject;
mod descrobject;
mod stringobject;
mod traceback;
mod tupleobject;
#[cfg(py_sys_config = "Py_USING_UNICODE")]
mod unicodeobject; // TODO: incomplete
mod warnings;
mod weakrefobject;
@ -102,10 +102,10 @@ mod pyerrors;
mod pystate;
mod pyarena;
mod modsupport;
mod pythonrun;
mod ceval;
mod modsupport;
mod pyarena;
mod pythonrun;
// mod sysmodule; // TODO: incomplete
// mod intrcheck; // TODO: incomplete
mod import;
@ -124,8 +124,8 @@ mod eval;
// mod pyfpe; // TODO: incomplete
// Additional headers that are not exported by Python.h
pub mod structmember;
pub mod frameobject;
pub mod structmember;
pub const Py_single_input: c_int = 256;
pub const Py_file_input: c_int = 257;
@ -133,8 +133,12 @@ pub const Py_eval_input: c_int = 258;
#[cfg(not(py_sys_config = "Py_USING_UNICODE"))]
#[inline(always)]
pub fn PyUnicode_Check(op : *mut PyObject) -> libc::c_int { 0 }
pub fn PyUnicode_Check(op: *mut PyObject) -> libc::c_int {
0
}
#[cfg(not(py_sys_config = "Py_USING_UNICODE"))]
#[inline(always)]
pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 }
pub fn PyUnicode_CheckExact(op: *mut PyObject) -> libc::c_int {
0
}

View File

@ -1,94 +1,164 @@
use std::ptr;
use std::os::raw::{c_char, c_int, c_long};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::PyObject;
use ffi2::methodobject::PyMethodDef;
use ffi2::object::PyObject;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_long};
use std::ptr;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int;
pub fn PyArg_ParseTuple(args: *mut PyObject,
format: *const c_char, ...) -> c_int;
pub fn PyArg_ParseTupleAndKeywords(args: *mut PyObject,
pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int;
pub fn PyArg_ParseTupleAndKeywords(
args: *mut PyObject,
kw: *mut PyObject,
format: *const c_char,
keywords: *mut *mut c_char, ...) -> c_int;
pub fn PyArg_UnpackTuple(args: *mut PyObject, name: *const c_char,
min: Py_ssize_t, max: Py_ssize_t, ...) -> c_int;
keywords: *mut *mut c_char,
...
) -> c_int;
pub fn PyArg_UnpackTuple(
args: *mut PyObject,
name: *const c_char,
min: Py_ssize_t,
max: Py_ssize_t,
...
) -> c_int;
pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject;
//fn _Py_BuildValue_SizeT(arg1: *const c_char, ...)
// -> *mut PyObject;
//fn _PyArg_NoKeywords(funcname: *const c_char,
// kw: *mut PyObject) -> c_int;
pub fn PyModule_AddObject(module: *mut PyObject,
pub fn PyModule_AddObject(
module: *mut PyObject,
name: *const c_char,
value: *mut PyObject) -> c_int;
pub fn PyModule_AddIntConstant(module: *mut PyObject,
value: *mut PyObject,
) -> c_int;
pub fn PyModule_AddIntConstant(
module: *mut PyObject,
name: *const c_char,
value: c_long) -> c_int;
pub fn PyModule_AddStringConstant(module: *mut PyObject,
value: c_long,
) -> c_int;
pub fn PyModule_AddStringConstant(
module: *mut PyObject,
name: *const c_char,
value: *const c_char) -> c_int;
value: *const c_char,
) -> c_int;
#[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))]
fn Py_InitModule4_64(name: *const c_char,
#[cfg(
all(
target_pointer_width = "64",
not(py_sys_config = "Py_TRACE_REFS")
)
)]
fn Py_InitModule4_64(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject;
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject;
#[cfg(all(target_pointer_width = "64", py_sys_config = "Py_TRACE_REFS"))]
fn Py_InitModule4TraceRefs_64(name: *const c_char,
fn Py_InitModule4TraceRefs_64(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject;
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject;
#[cfg(all(not(target_pointer_width = "64"), not(py_sys_config = "Py_TRACE_REFS")))]
pub fn Py_InitModule4(name: *const c_char,
#[cfg(
all(
not(target_pointer_width = "64"),
not(py_sys_config = "Py_TRACE_REFS")
)
)]
pub fn Py_InitModule4(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject;
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject;
#[cfg(all(not(target_pointer_width = "64"), py_sys_config = "Py_TRACE_REFS"))]
fn Py_InitModule4TraceRefs(name: *const c_char,
#[cfg(
all(
not(target_pointer_width = "64"),
py_sys_config = "Py_TRACE_REFS"
)
)]
fn Py_InitModule4TraceRefs(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject;
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject;
}
pub const PYTHON_API_VERSION: c_int = 1013;
#[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))]
#[cfg(
all(
target_pointer_width = "64",
not(py_sys_config = "Py_TRACE_REFS")
)
)]
#[inline(always)]
pub unsafe fn Py_InitModule4(name: *const c_char,
pub unsafe fn Py_InitModule4(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject {
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject {
Py_InitModule4_64(name, methods, doc, _self, apiver)
}
#[cfg(all(target_pointer_width = "64", py_sys_config = "Py_TRACE_REFS"))]
#[inline(always)]
pub unsafe fn Py_InitModule4(name: *const c_char,
pub unsafe fn Py_InitModule4(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject {
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject {
Py_InitModule4TraceRefs_64(name, methods, doc, _self, apiver)
}
#[cfg(all(not(target_pointer_width = "64"), py_sys_config = "Py_TRACE_REFS"))]
#[cfg(
all(
not(target_pointer_width = "64"),
py_sys_config = "Py_TRACE_REFS"
)
)]
#[inline(always)]
pub unsafe fn Py_InitModule4(name: *const c_char,
pub unsafe fn Py_InitModule4(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char, _self: *mut PyObject,
apiver: c_int) -> *mut PyObject {
doc: *const c_char,
_self: *mut PyObject,
apiver: c_int,
) -> *mut PyObject {
Py_InitModule4TraceRefs(name, methods, doc, _self, apiver)
}
#[inline(always)]
pub unsafe fn Py_InitModule(name: *const c_char, methods: *mut PyMethodDef) -> *mut PyObject {
Py_InitModule4(name, methods, ptr::null(), ptr::null_mut(), PYTHON_API_VERSION)
Py_InitModule4(
name,
methods,
ptr::null(),
ptr::null_mut(),
PYTHON_API_VERSION,
)
}
#[inline(always)]
pub unsafe fn Py_InitModule3(name: *const c_char, methods: *mut PyMethodDef, doc : *const c_char) -> *mut PyObject {
pub unsafe fn Py_InitModule3(
name: *const c_char,
methods: *mut PyMethodDef,
doc: *const c_char,
) -> *mut PyObject {
Py_InitModule4(name, methods, doc, ptr::null_mut(), PYTHON_API_VERSION)
}

View File

@ -1,9 +1,10 @@
use std::os::raw::{c_char, c_int, c_void};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::methodobject::PyMethodDef;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyModule_Type: PyTypeObject;
}
@ -17,7 +18,8 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyModule_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject;
pub fn PyModule_New(name: *const c_char) -> *mut PyObject;
pub fn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject;
@ -40,14 +42,16 @@ pub struct PyModuleDef_Base {
pub m_copy: *mut PyObject,
}
impl Clone for PyModuleDef_Base {
fn clone(&self) -> PyModuleDef_Base { *self }
fn clone(&self) -> PyModuleDef_Base {
*self
}
}
pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base {
ob_base: PyObject_HEAD_INIT,
m_init: None,
m_index: 0,
m_copy: ::std::ptr::null_mut()
m_copy: ::std::ptr::null_mut(),
};
#[repr(C)]
@ -57,7 +61,9 @@ pub struct PyModuleDef_Slot {
pub value: *mut c_void,
}
impl Clone for PyModuleDef_Slot {
fn clone(&self) -> PyModuleDef_Slot { *self }
fn clone(&self) -> PyModuleDef_Slot {
*self
}
}
pub const Py_mod_create: c_int = 1;
@ -77,7 +83,9 @@ pub struct PyModuleDef {
pub m_free: Option<freefunc>,
}
impl Clone for PyModuleDef {
fn clone(&self) -> PyModuleDef { *self }
fn clone(&self) -> PyModuleDef {
*self
}
}
pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef {
@ -89,5 +97,5 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef {
m_slots: ::std::ptr::null_mut(),
m_traverse: None,
m_clear: None,
m_free: None
m_free: None,
};

View File

@ -1,9 +1,9 @@
use std::ptr;
use std::os::raw::{c_void, c_int, c_uint, c_long, c_char, c_double};
use libc::FILE;
use ffi2;
use ffi2::pyport::{Py_ssize_t, Py_hash_t};
use ffi2::methodobject::PyMethodDef;
use ffi2::pyport::{Py_hash_t, Py_ssize_t};
use libc::FILE;
use std::os::raw::{c_char, c_double, c_int, c_long, c_uint, c_void};
use std::ptr;
#[repr(C)]
#[derive(Copy, Clone)]
@ -21,13 +21,13 @@ pub const PyObject_HEAD_INIT: PyObject = PyObject {
_ob_next: ::std::ptr::null_mut(),
_ob_prev: ::std::ptr::null_mut(),
ob_refcnt: 1,
ob_type: ::std::ptr::null_mut()
ob_type: ::std::ptr::null_mut(),
};
#[cfg(not(py_sys_config = "Py_TRACE_REFS"))]
pub const PyObject_HEAD_INIT: PyObject = PyObject {
ob_refcnt: 1,
ob_type: ::std::ptr::null_mut()
ob_type: ::std::ptr::null_mut(),
};
#[repr(C)]
@ -52,60 +52,53 @@ pub unsafe fn Py_SIZE(ob : *mut PyObject) -> Py_ssize_t {
(*(ob as *mut PyVarObject)).ob_size
}
pub type unaryfunc =
unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type unaryfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type binaryfunc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
pub type ternaryfunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
pub type inquiry =
unsafe extern "C" fn(arg1: *mut PyObject) -> c_int;
pub type lenfunc =
unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject)
-> *mut PyObject;
pub type inquiry = unsafe extern "C" fn(arg1: *mut PyObject) -> c_int;
pub type lenfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t;
pub type coercion =
unsafe extern "C" fn (arg1: *mut *mut PyObject,
arg2: *mut *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int;
pub type ssizeargfunc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
pub type ssizessizeargfunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: Py_ssize_t) -> *mut PyObject;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject;
pub type intobjargproc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut PyObject) -> c_int;
pub type intintobjargproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int,
arg3: c_int, arg4: *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: c_int, arg4: *mut PyObject)
-> c_int;
pub type ssizeobjargproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: *mut PyObject) -> c_int;
pub type ssizessizeobjargproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int;
pub type ssizessizeobjargproc = unsafe extern "C" fn(
arg1: *mut PyObject,
arg2: Py_ssize_t,
arg3: Py_ssize_t,
arg4: *mut PyObject,
) -> c_int;
pub type objobjargproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int;
pub type getreadbufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int,
arg3: *mut *mut c_void) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int;
pub type getwritebufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int,
arg3: *mut *mut c_void) -> c_int;
pub type getsegcountproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_int) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int;
pub type getsegcountproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_int) -> c_int;
pub type getcharbufferproc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_char) -> c_int;
pub type readbufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: *mut *mut c_void) -> Py_ssize_t;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut *mut c_void)
-> Py_ssize_t;
pub type writebufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: *mut *mut c_void) -> Py_ssize_t;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut *mut c_void)
-> Py_ssize_t;
pub type segcountproc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> Py_ssize_t;
pub type charbufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: *mut *mut c_char) -> Py_ssize_t;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut *mut c_char)
-> Py_ssize_t;
#[repr(C)]
#[derive(Copy, Clone)]
@ -125,10 +118,8 @@ pub struct Py_buffer {
}
pub type getbufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer,
arg3: c_int) -> c_int;
pub type releasebufferproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer);
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer, arg3: c_int) -> c_int;
pub type releasebufferproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer);
// flags:
pub const PyBUF_SIMPLE: c_int = 0;
@ -158,15 +149,11 @@ pub const PyBUF_READ : c_int = 0x100;
pub const PyBUF_WRITE: c_int = 0x200;
pub const PyBUF_SHADOW: c_int = 0x400;
pub type objobjproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub type visitproc =
unsafe extern "C" fn (object: *mut PyObject, arg: *mut c_void) -> c_int;
pub type objobjproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub type visitproc = unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int;
pub type traverseproc =
unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int;
#[repr(C)]
#[derive(Copy)]
pub struct PyNumberMethods {
@ -212,7 +199,10 @@ pub struct PyNumberMethods {
}
impl Clone for PyNumberMethods {
#[inline] fn clone(&self) -> PyNumberMethods { *self }
#[inline]
fn clone(&self) -> PyNumberMethods {
*self
}
}
pub const PyNumberMethods_INIT: PyNumberMethods = PyNumberMethods {
@ -273,7 +263,10 @@ pub struct PySequenceMethods {
}
impl Clone for PySequenceMethods {
#[inline] fn clone(&self) -> PySequenceMethods { *self }
#[inline]
fn clone(&self) -> PySequenceMethods {
*self
}
}
pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods {
@ -298,7 +291,10 @@ pub struct PyMappingMethods {
}
impl Clone for PyMappingMethods {
#[inline] fn clone(&self) -> PyMappingMethods { *self }
#[inline]
fn clone(&self) -> PyMappingMethods {
*self
}
}
pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods {
@ -319,7 +315,10 @@ pub struct PyBufferProcs {
}
impl Clone for PyBufferProcs {
#[inline] fn clone(&self) -> PyBufferProcs { *self }
#[inline]
fn clone(&self) -> PyBufferProcs {
*self
}
}
pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs {
@ -331,10 +330,8 @@ pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs {
bf_releasebuffer: None,
};
pub type freefunc =
unsafe extern "C" fn(arg1: *mut c_void);
pub type destructor =
unsafe extern "C" fn(arg1: *mut PyObject);
pub type freefunc = unsafe extern "C" fn(arg1: *mut c_void);
pub type destructor = unsafe extern "C" fn(arg1: *mut PyObject);
pub type printfunc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut FILE, arg3: c_int) -> c_int;
pub type getattrfunc =
@ -342,36 +339,26 @@ pub type getattrfunc =
pub type getattrofunc =
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
pub type setattrfunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_char,
arg3: *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, arg3: *mut PyObject) -> c_int;
pub type setattrofunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> c_int;
pub type cmpfunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub type reprfunc =
unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type hashfunc =
unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int;
pub type cmpfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub type reprfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type hashfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t;
pub type richcmpfunc =
unsafe extern "C" fn (arg1: *mut PyObject,
arg2: *mut PyObject, arg3: c_int) -> *mut PyObject;
pub type getiterfunc =
unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type iternextfunc =
unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> *mut PyObject;
pub type getiterfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type iternextfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject;
pub type descrgetfunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject)
-> *mut PyObject;
pub type descrsetfunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int;
pub type initproc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> c_int;
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int;
pub type newfunc =
unsafe extern "C" fn (arg1: *mut PyTypeObject,
arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject;
unsafe extern "C" fn(arg1: *mut PyTypeObject, arg2: *mut PyObject, arg3: *mut PyObject)
-> *mut PyObject;
pub type allocfunc =
unsafe extern "C" fn(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject;
@ -430,7 +417,10 @@ pub struct PyTypeObject {
}
impl Clone for PyTypeObject {
#[inline] fn clone(&self) -> PyTypeObject { *self }
#[inline]
fn clone(&self) -> PyTypeObject {
*self
}
}
#[cfg(py_sys_config = "Py_TRACE_REFS")]
@ -554,17 +544,23 @@ pub struct PyHeapTypeObject {
}
impl Clone for PyHeapTypeObject {
#[inline] fn clone(&self) -> PyHeapTypeObject { *self }
#[inline]
fn clone(&self) -> PyHeapTypeObject {
*self
}
}
// access macro to the members which are floating "behind" the object
#[inline]
pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2::structmember::PyMemberDef {
pub unsafe fn PyHeapType_GET_MEMBERS(
etype: *mut PyHeapTypeObject,
) -> *mut ffi2::structmember::PyMemberDef {
let basicsize = (*Py_TYPE(etype as *mut PyObject)).tp_basicsize;
(etype as *mut u8).offset(basicsize as isize) as *mut ffi2::structmember::PyMemberDef
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int;
}
@ -573,7 +569,8 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_
(Py_TYPE(ob) == tp || PyType_IsSubtype(Py_TYPE(ob), tp) != 0) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyType_Type: PyTypeObject;
pub static mut PyBaseObject_Type: PyTypeObject;
pub static mut PySuper_Type: PyTypeObject;
@ -589,20 +586,25 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == (&mut PyType_Type as *mut _)) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int;
pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject;
pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject,
kwds: *mut PyObject) -> *mut PyObject;
pub fn PyType_GenericNew(
t: *mut PyTypeObject,
args: *mut PyObject,
kwds: *mut PyObject,
) -> *mut PyObject;
fn _PyType_Lookup(arg1: *mut PyTypeObject, arg2: *mut PyObject) -> *mut PyObject;
fn _PyObject_LookupSpecial(arg1: *mut PyObject,
fn _PyObject_LookupSpecial(
arg1: *mut PyObject,
arg2: *mut c_char,
arg3: *mut *mut PyObject) -> *mut PyObject;
arg3: *mut *mut PyObject,
) -> *mut PyObject;
pub fn PyType_ClearCache() -> c_uint;
pub fn PyType_Modified(t: *mut PyTypeObject);
pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE,
flags: c_int) -> c_int;
pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int;
fn _PyObject_Dump(o: *mut PyObject);
pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject;
fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject;
@ -614,48 +616,58 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject {
PyObject_Str(o)
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[cfg(py_sys_config = "Py_USING_UNICODE")]
pub fn PyObject_Unicode(o: *mut PyObject) -> *mut PyObject;
pub fn PyObject_Compare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: c_int) -> *mut PyObject;
pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: c_int) -> c_int;
pub fn PyObject_GetAttrString(arg1: *mut PyObject,
arg2: *const c_char) -> *mut PyObject;
pub fn PyObject_SetAttrString(arg1: *mut PyObject,
pub fn PyObject_RichCompare(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: c_int,
) -> *mut PyObject;
pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int)
-> c_int;
pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject;
pub fn PyObject_SetAttrString(
arg1: *mut PyObject,
arg2: *const c_char,
arg3: *mut PyObject) -> c_int;
pub fn PyObject_HasAttrString(arg1: *mut PyObject,
arg2: *const c_char) -> c_int;
arg3: *mut PyObject,
) -> c_int;
pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> c_int;
pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject)
-> c_int;
pub fn PyObject_HasAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject;
pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> c_int;
pub fn PyObject_GenericSetAttr(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> c_int;
pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t;
pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t;
pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int;
pub fn PyObject_Not(arg1: *mut PyObject) -> c_int;
pub fn PyCallable_Check(arg1: *mut PyObject) -> c_int;
pub fn PyNumber_Coerce(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int;
pub fn PyNumber_CoerceEx(arg1: *mut *mut PyObject,
arg2: *mut *mut PyObject) -> c_int;
pub fn PyNumber_CoerceEx(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int;
pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject);
fn _PyObject_SlotCompare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
fn _PyObject_GenericGetAttrWithDict(arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
fn _PyObject_GenericSetAttrWithDict(arg1: *mut PyObject,
fn _PyObject_GenericGetAttrWithDict(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
arg4: *mut PyObject) -> c_int;
) -> *mut PyObject;
fn _PyObject_GenericSetAttrWithDict(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
arg4: *mut PyObject,
) -> c_int;
pub fn PyObject_Dir(arg1: *mut PyObject) -> *mut PyObject;
pub fn Py_ReprEnter(arg1: *mut PyObject) -> c_int;
pub fn Py_ReprLeave(arg1: *mut PyObject);
@ -732,17 +744,16 @@ pub const Py_TPFLAGS_DICT_SUBCLASS : c_long = (1<<29);
pub const Py_TPFLAGS_BASE_EXC_SUBCLASS: c_long = (1 << 30);
pub const Py_TPFLAGS_TYPE_SUBCLASS: c_long = (1 << 31);
pub const Py_TPFLAGS_DEFAULT : c_long = (
Py_TPFLAGS_HAVE_GETCHARBUFFER |
Py_TPFLAGS_HAVE_SEQUENCE_IN |
Py_TPFLAGS_HAVE_INPLACEOPS |
Py_TPFLAGS_HAVE_RICHCOMPARE |
Py_TPFLAGS_HAVE_WEAKREFS |
Py_TPFLAGS_HAVE_ITER |
Py_TPFLAGS_HAVE_CLASS |
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION |
Py_TPFLAGS_HAVE_INDEX |
0);
pub const Py_TPFLAGS_DEFAULT: c_long = (Py_TPFLAGS_HAVE_GETCHARBUFFER
| Py_TPFLAGS_HAVE_SEQUENCE_IN
| Py_TPFLAGS_HAVE_INPLACEOPS
| Py_TPFLAGS_HAVE_RICHCOMPARE
| Py_TPFLAGS_HAVE_WEAKREFS
| Py_TPFLAGS_HAVE_ITER
| Py_TPFLAGS_HAVE_CLASS
| Py_TPFLAGS_HAVE_STACKLESS_EXTENSION
| Py_TPFLAGS_HAVE_INDEX
| 0);
#[inline(always)]
pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_long) -> c_int {
@ -799,7 +810,8 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) {
}
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn Py_IncRef(o: *mut PyObject);
pub fn Py_DecRef(o: *mut PyObject);
@ -835,7 +847,8 @@ pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int {
0
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
fn _PyTrash_thread_deposit_object(o: *mut PyObject);
fn _PyTrash_thread_destroy_chain();
}
@ -860,4 +873,3 @@ pub unsafe fn Py_TRASHCAN<F : FnOnce() -> ()>(op: *mut PyObject, body: F) {
_PyTrash_thread_deposit_object(op)
}
}

View File

@ -1,8 +1,8 @@
use std::ptr;
use std::os::raw::{c_void, c_char, c_int};
use ffi2;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
#[inline]
pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int {
@ -14,227 +14,209 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_
PyObject_SetAttr(o, attr_name, ptr::null_mut())
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject,
result: *mut c_int) -> c_int;
pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject,
kw: *mut PyObject) -> *mut PyObject;
pub fn PyObject_CallObject(callable_object: *mut PyObject,
args: *mut PyObject) -> *mut PyObject;
pub fn PyObject_CallFunction(callable_object: *mut PyObject,
format: *mut c_char, ...)
-> *mut PyObject;
pub fn PyObject_CallMethod(o: *mut PyObject, m: *mut c_char,
format: *mut c_char, ...)
-> *mut PyObject;
fn _PyObject_CallFunction_SizeT(callable: *mut PyObject,
format: *mut c_char, ...)
-> *mut PyObject;
fn _PyObject_CallMethod_SizeT(o: *mut PyObject,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject, result: *mut c_int) -> c_int;
pub fn PyObject_Call(
callable_object: *mut PyObject,
args: *mut PyObject,
kw: *mut PyObject,
) -> *mut PyObject;
pub fn PyObject_CallObject(
callable_object: *mut PyObject,
args: *mut PyObject,
) -> *mut PyObject;
pub fn PyObject_CallFunction(
callable_object: *mut PyObject,
format: *mut c_char,
...
) -> *mut PyObject;
pub fn PyObject_CallMethod(
o: *mut PyObject,
m: *mut c_char,
format: *mut c_char,
...
) -> *mut PyObject;
fn _PyObject_CallFunction_SizeT(
callable: *mut PyObject,
format: *mut c_char,
...
) -> *mut PyObject;
fn _PyObject_CallMethod_SizeT(
o: *mut PyObject,
name: *mut c_char,
format: *mut c_char, ...)
-> *mut PyObject;
pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...)
-> *mut PyObject;
pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...)
-> *mut PyObject;
format: *mut c_char,
...
) -> *mut PyObject;
pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject;
pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject;
pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject;
pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t;
pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t)
-> Py_ssize_t;
pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject)
-> *mut PyObject;
pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject,
v: *mut PyObject) -> c_int;
pub fn PyObject_DelItemString(o: *mut PyObject, key: *mut c_char)
-> c_int;
pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject)
-> c_int;
pub fn PyObject_AsCharBuffer(obj: *mut PyObject,
pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t;
pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject;
pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, v: *mut PyObject) -> c_int;
pub fn PyObject_DelItemString(o: *mut PyObject, key: *mut c_char) -> c_int;
pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PyObject_AsCharBuffer(
obj: *mut PyObject,
buffer: *mut *const c_char,
buffer_len: *mut Py_ssize_t)
-> c_int;
buffer_len: *mut Py_ssize_t,
) -> c_int;
pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int;
pub fn PyObject_AsReadBuffer(obj: *mut PyObject,
pub fn PyObject_AsReadBuffer(
obj: *mut PyObject,
buffer: *mut *const c_void,
buffer_len: *mut Py_ssize_t)
-> c_int;
pub fn PyObject_AsWriteBuffer(obj: *mut PyObject,
buffer_len: *mut Py_ssize_t,
) -> c_int;
pub fn PyObject_AsWriteBuffer(
obj: *mut PyObject,
buffer: *mut *mut c_void,
buffer_len: *mut Py_ssize_t)
-> c_int;
buffer_len: *mut Py_ssize_t,
) -> c_int;
pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer,
flags: c_int) -> c_int;
pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int;
pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t)
-> *mut c_void;
pub fn PyBuffer_ToContiguous(buf: *mut c_void,
view: *mut Py_buffer, len: Py_ssize_t,
fort: c_char) -> c_int;
pub fn PyBuffer_FromContiguous(view: *mut Py_buffer,
buf: *mut c_void, len: Py_ssize_t,
fort: c_char) -> c_int;
pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject)
-> c_int;
pub fn PyBuffer_IsContiguous(view: *mut Py_buffer, fort: c_char)
-> c_int;
pub fn PyBuffer_FillContiguousStrides(ndims: c_int,
pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void;
pub fn PyBuffer_ToContiguous(
buf: *mut c_void,
view: *mut Py_buffer,
len: Py_ssize_t,
fort: c_char,
) -> c_int;
pub fn PyBuffer_FromContiguous(
view: *mut Py_buffer,
buf: *mut c_void,
len: Py_ssize_t,
fort: c_char,
) -> c_int;
pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int;
pub fn PyBuffer_IsContiguous(view: *mut Py_buffer, fort: c_char) -> c_int;
pub fn PyBuffer_FillContiguousStrides(
ndims: c_int,
shape: *mut Py_ssize_t,
strides: *mut Py_ssize_t,
itemsize: c_int,
fort: c_char);
pub fn PyBuffer_FillInfo(view: *mut Py_buffer, o: *mut PyObject,
buf: *mut c_void, len: Py_ssize_t,
readonly: c_int, flags: c_int)
-> c_int;
fort: c_char,
);
pub fn PyBuffer_FillInfo(
view: *mut Py_buffer,
o: *mut PyObject,
buf: *mut c_void,
len: Py_ssize_t,
readonly: c_int,
flags: c_int,
) -> c_int;
pub fn PyBuffer_Release(view: *mut Py_buffer);
pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject)
-> *mut PyObject;
pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject;
pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject;
fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Check(o: *mut PyObject) -> c_int;
pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject)
pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject,
o3: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject)
-> Py_ssize_t;
fn _PyNumber_ConvertIntegralToInt(integral: *mut PyObject,
error_format: *const c_char)
-> *mut PyObject;
pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) -> Py_ssize_t;
fn _PyNumber_ConvertIntegralToInt(
integral: *mut PyObject,
error_format: *const c_char,
) -> *mut PyObject;
pub fn PyNumber_Int(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject,
o3: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int)
-> *mut PyObject;
pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlacePower(
o1: *mut PyObject,
o2: *mut PyObject,
o3: *mut PyObject,
) -> *mut PyObject;
pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject;
pub fn PySequence_Check(o: *mut PyObject) -> c_int;
pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t;
pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t;
pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t)
-> *mut PyObject;
pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t)
-> *mut PyObject;
pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t,
i2: Py_ssize_t) -> *mut PyObject;
pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t,
v: *mut PyObject) -> c_int;
pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t)
-> c_int;
pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t,
i2: Py_ssize_t, v: *mut PyObject)
-> c_int;
pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t,
i2: Py_ssize_t) -> c_int;
pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject;
pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject;
pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject;
pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int;
pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int;
pub fn PySequence_SetSlice(
o: *mut PyObject,
i1: Py_ssize_t,
i2: Py_ssize_t,
v: *mut PyObject,
) -> c_int;
pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int;
pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject;
pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject;
pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char)
-> *mut PyObject;
pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject)
-> Py_ssize_t;
pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject)
-> c_int;
pub fn _PySequence_IterSearch(seq: *mut PyObject, obj: *mut PyObject,
operation: c_int) -> Py_ssize_t;
pub fn PySequence_In(o: *mut PyObject, value: *mut PyObject)
-> c_int;
pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject)
-> Py_ssize_t;
pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject)
-> *mut PyObject;
pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t)
-> *mut PyObject;
pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char) -> *mut PyObject;
pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t;
pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) -> c_int;
pub fn _PySequence_IterSearch(
seq: *mut PyObject,
obj: *mut PyObject,
operation: c_int,
) -> Py_ssize_t;
pub fn PySequence_In(o: *mut PyObject, value: *mut PyObject) -> c_int;
pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t;
pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject;
pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject;
pub fn PyMapping_Check(o: *mut PyObject) -> c_int;
pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t;
pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t;
pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char)
-> c_int;
pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject)
-> c_int;
pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char)
-> *mut PyObject;
pub fn PyMapping_SetItemString(o: *mut PyObject, key: *mut c_char,
value: *mut PyObject) -> c_int;
pub fn PyObject_IsInstance(object: *mut PyObject,
typeorclass: *mut PyObject) -> c_int;
pub fn PyObject_IsSubclass(object: *mut PyObject,
typeorclass: *mut PyObject) -> c_int;
pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int;
pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject;
pub fn PyMapping_SetItemString(
o: *mut PyObject,
key: *mut c_char,
value: *mut PyObject,
) -> c_int;
pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int;
pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int;
}
#[inline]
pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int {
let t = (*obj).ob_type;
let b = (*t).tp_as_buffer;
(!b.is_null() &&
(PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) &&
((*b).bf_getbuffer.is_some())) as c_int
(!b.is_null()
&& (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0)
&& ((*b).bf_getbuffer.is_some())) as c_int
}
#[inline]
pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int {
let t = (*obj).ob_type;
(PyType_HasFeature(t, Py_TPFLAGS_HAVE_ITER) != 0 &&
match (*t).tp_iternext {
(PyType_HasFeature(t, Py_TPFLAGS_HAVE_ITER) != 0 && match (*t).tp_iternext {
None => false,
Some(f) => f as *const c_void != _PyObject_NextNotImplemented as *const c_void,
}) as c_int
@ -244,7 +226,8 @@ pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int {
pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int {
let t = (*obj).ob_type;
let n = (*t).tp_as_number;
(!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) as c_int
(!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some())
as c_int
}
#[inline]
@ -270,13 +253,17 @@ pub unsafe fn PySequence_Fast_ITEMS(o : *mut PyObject) -> *mut *mut PyObject {
if ffi2::listobject::PyList_Check(o) != 0 {
(*(o as *mut ffi2::listobject::PyListObject)).ob_item
} else {
(*(o as *mut ffi2::tupleobject::PyTupleObject)).ob_item.as_mut_ptr()
(*(o as *mut ffi2::tupleobject::PyTupleObject))
.ob_item
.as_mut_ptr()
}
}
#[inline]
pub unsafe fn PySequence_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
(*(*Py_TYPE(o)).tp_as_sequence).sq_item.expect("Failed to get sq_item")(o, i)
(*(*Py_TYPE(o)).tp_as_sequence)
.sq_item
.expect("Failed to get sq_item")(o, i)
}
pub const PY_ITERSEARCH_COUNT: c_int = 1;

View File

@ -1,30 +1,29 @@
use std::os::raw::{c_void, c_char, c_int};
use libc::size_t;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use libc::size_t;
use std::os::raw::{c_char, c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void;
pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t)
-> *mut c_void;
pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void;
pub fn PyObject_Free(arg1: *mut c_void);
pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject)
-> *mut PyObject;
pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject,
arg3: Py_ssize_t) -> *mut PyVarObject;
pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject;
pub fn PyObject_InitVar(
arg1: *mut PyVarObject,
arg2: *mut PyTypeObject,
arg3: Py_ssize_t,
) -> *mut PyVarObject;
pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject;
pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t)
-> *mut PyVarObject;
pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject;
// GC Support
pub fn PyGC_Collect() -> Py_ssize_t;
pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t)
-> *mut PyVarObject;
pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) -> *mut PyVarObject;
pub fn _PyObject_GC_Malloc(arg1: size_t) -> *mut PyObject;
pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject;
pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t)
-> *mut PyVarObject;
pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject;
pub fn PyObject_GC_Track(arg1: *mut c_void);
pub fn PyObject_GC_UnTrack(arg1: *mut c_void);
pub fn PyObject_GC_Del(arg1: *mut c_void);
@ -40,10 +39,9 @@ pub unsafe fn PyType_IS_GC(t : *mut PyTypeObject) -> c_int {
/// Test if an object has a GC head
#[inline(always)]
pub unsafe fn PyObject_IS_GC(o: *mut PyObject) -> c_int {
(PyType_IS_GC(Py_TYPE(o)) != 0 &&
match (*Py_TYPE(o)).tp_is_gc {
(PyType_IS_GC(Py_TYPE(o)) != 0 && match (*Py_TYPE(o)).tp_is_gc {
Some(tp_is_gc) => tp_is_gc(o) != 0,
None => true
None => true,
}) as c_int
}
@ -51,8 +49,7 @@ pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int {
#[inline(always)]
#[allow(unused_parens)]
pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int {
(PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) != 0
&& ((*t).tp_weaklistoffset > 0)) as c_int
(PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) != 0 && ((*t).tp_weaklistoffset > 0)) as c_int
}
#[inline(always)]
@ -60,4 +57,3 @@ pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o : *mut PyObject) -> *mut *mut PyOb
let weaklistoffset = (*Py_TYPE(o)).tp_weaklistoffset as isize;
(o as *mut c_char).offset(weaklistoffset) as *mut *mut PyObject
}

View File

@ -1,11 +1,12 @@
use libc::size_t;
use std::os::raw::{c_void, c_int};
use ffi2::object::PyObject;
use libc::size_t;
use std::os::raw::{c_int, c_void};
#[allow(missing_copy_implementations)]
pub enum PyArena {}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyArena_New() -> *mut PyArena;
pub fn PyArena_Free(arg1: *mut PyArena);
pub fn PyArena_Malloc(arg1: *mut PyArena, size: size_t) -> *mut c_void;

View File

@ -1,7 +1,8 @@
use std::os::raw::{c_void, c_char, c_int};
use ffi2::object::*;
use std::os::raw::{c_char, c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCapsule_Type: PyTypeObject;
}
@ -12,25 +13,24 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == &mut PyCapsule_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyCapsule_New(pointer: *mut c_void,
#[cfg_attr(windows, link(name = "pythonXY"))]
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;
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;
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;
}

View File

@ -1,6 +1,7 @@
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut Py_DebugFlag: c_int;
pub static mut Py_VerboseFlag: c_int;
pub static mut Py_InteractiveFlag: c_int;
@ -22,4 +23,3 @@ use std::os::raw::{c_char, c_int};
pub fn Py_FatalError(message: *const c_char);
}

View File

@ -1,39 +1,45 @@
use std::os::raw::{c_char, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::classobject::*;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use ffi2::stringobject::PyString_AS_STRING;
#[cfg(py_sys_config = "Py_USING_UNICODE")]
use ffi2::unicodeobject::Py_UNICODE;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyErr_SetNone(arg1: *mut PyObject);
pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject);
pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char);
pub fn PyErr_Occurred() -> *mut PyObject;
pub fn PyErr_Clear();
pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject,
arg3: *mut *mut PyObject);
pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject);
pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject,
arg2: *mut PyObject) -> c_int;
pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int;
pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject,
pub fn PyErr_Fetch(
arg1: *mut *mut PyObject,
arg2: *mut *mut PyObject,
arg3: *mut *mut PyObject);
arg3: *mut *mut PyObject,
);
pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject);
pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int;
pub fn PyErr_NormalizeException(
arg1: *mut *mut PyObject,
arg2: *mut *mut PyObject,
arg3: *mut *mut PyObject,
);
}
#[inline]
pub unsafe fn PyExceptionClass_Check(x: *mut PyObject) -> c_int {
(PyClass_Check(x) != 0 || (PyType_Check(x) != 0 &&
PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) as c_int
(PyClass_Check(x) != 0
|| (PyType_Check(x) != 0
&& PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0))
as c_int
}
#[inline]
pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int {
(PyInstance_Check(x) != 0 ||
PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int
(PyInstance_Check(x) != 0
|| PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int
}
#[inline]
@ -54,7 +60,8 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject {
}
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyExc_BaseException: *mut PyObject;
pub static mut PyExc_Exception: *mut PyObject;
pub static mut PyExc_StopIteration: *mut PyObject;
@ -92,7 +99,8 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject {
pub static mut PyExc_UnicodeTranslateError: *mut PyObject;
pub static mut PyExc_ValueError: *mut PyObject;
pub static mut PyExc_ZeroDivisionError: *mut PyObject;
#[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject;
#[cfg(windows)]
pub static mut PyExc_WindowsError: *mut PyObject;
pub static mut PyExc_BufferError: *mut PyObject;
pub static mut PyExc_MemoryErrorInst: *mut PyObject;
pub static mut PyExc_RecursionErrorInst: *mut PyObject;
@ -110,107 +118,83 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject {
pub fn PyErr_BadArgument() -> c_int;
pub fn PyErr_NoMemory() -> *mut PyObject;
pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyErr_SetFromErrnoWithFilenameObject(arg1: *mut PyObject,
arg2: *mut PyObject)
-> *mut PyObject;
pub fn PyErr_SetFromErrnoWithFilename(arg1: *mut PyObject,
arg2: *const c_char)
-> *mut PyObject;
pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...)
-> *mut PyObject;
pub fn PyErr_SetFromErrnoWithFilenameObject(
arg1: *mut PyObject,
arg2: *mut PyObject,
) -> *mut PyObject;
pub fn PyErr_SetFromErrnoWithFilename(
arg1: *mut PyObject,
arg2: *const c_char,
) -> *mut PyObject;
pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject;
pub fn PyErr_BadInternalCall();
pub fn _PyErr_BadInternalCall(filename: *mut c_char,
lineno: c_int);
pub fn PyErr_NewException(name: *mut c_char, base: *mut PyObject,
dict: *mut PyObject) -> *mut PyObject;
pub fn PyErr_NewExceptionWithDoc(name: *mut c_char,
pub fn _PyErr_BadInternalCall(filename: *mut c_char, lineno: c_int);
pub fn PyErr_NewException(
name: *mut c_char,
base: *mut PyObject,
dict: *mut PyObject,
) -> *mut PyObject;
pub fn PyErr_NewExceptionWithDoc(
name: *mut c_char,
doc: *mut c_char,
base: *mut PyObject, dict: *mut PyObject)
-> *mut PyObject;
base: *mut PyObject,
dict: *mut PyObject,
) -> *mut PyObject;
pub fn PyErr_WriteUnraisable(arg1: *mut PyObject);
pub fn PyErr_CheckSignals() -> c_int;
pub fn PyErr_SetInterrupt();
pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int;
pub fn PyErr_SyntaxLocation(arg1: *const c_char,
arg2: c_int);
pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int)
-> *mut PyObject;
pub fn PyErr_SyntaxLocation(arg1: *const c_char, arg2: c_int);
pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) -> *mut PyObject;
}
#[cfg(py_sys_config = "Py_USING_UNICODE")]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyUnicodeDecodeError_Create(arg1: *const c_char,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyUnicodeDecodeError_Create(
arg1: *const c_char,
arg2: *const c_char,
arg3: Py_ssize_t, arg4: Py_ssize_t,
arg5: Py_ssize_t,
arg6: *const c_char)
-> *mut PyObject;
pub fn PyUnicodeEncodeError_Create(arg1: *const c_char,
arg2: *const Py_UNICODE,
arg3: Py_ssize_t, arg4: Py_ssize_t,
arg5: Py_ssize_t,
arg6: *const c_char)
-> *mut PyObject;
pub fn PyUnicodeTranslateError_Create(arg1: *const Py_UNICODE,
arg2: Py_ssize_t, arg3: Py_ssize_t,
arg3: Py_ssize_t,
arg4: Py_ssize_t,
arg5: *const c_char)
-> *mut PyObject;
pub fn PyUnicodeEncodeError_GetEncoding(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeDecodeError_GetEncoding(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeEncodeError_GetObject(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeDecodeError_GetObject(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeTranslateError_GetObject(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeEncodeError_GetStart(arg1: *mut PyObject,
arg2: *mut Py_ssize_t)
-> c_int;
pub fn PyUnicodeDecodeError_GetStart(arg1: *mut PyObject,
arg2: *mut Py_ssize_t)
-> c_int;
pub fn PyUnicodeTranslateError_GetStart(arg1: *mut PyObject,
arg2: *mut Py_ssize_t)
-> c_int;
pub fn PyUnicodeEncodeError_SetStart(arg1: *mut PyObject,
arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeDecodeError_SetStart(arg1: *mut PyObject,
arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeTranslateError_SetStart(arg1: *mut PyObject,
arg2: Py_ssize_t)
-> c_int;
pub fn PyUnicodeEncodeError_GetEnd(arg1: *mut PyObject,
arg2: *mut Py_ssize_t)
-> c_int;
pub fn PyUnicodeDecodeError_GetEnd(arg1: *mut PyObject,
arg2: *mut Py_ssize_t)
-> c_int;
pub fn PyUnicodeTranslateError_GetEnd(arg1: *mut PyObject,
arg2: *mut Py_ssize_t)
-> c_int;
pub fn PyUnicodeEncodeError_SetEnd(arg1: *mut PyObject, arg2: Py_ssize_t)
-> c_int;
pub fn PyUnicodeDecodeError_SetEnd(arg1: *mut PyObject, arg2: Py_ssize_t)
-> c_int;
pub fn PyUnicodeTranslateError_SetEnd(arg1: *mut PyObject,
arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeEncodeError_GetReason(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeDecodeError_GetReason(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeTranslateError_GetReason(arg1: *mut PyObject)
-> *mut PyObject;
pub fn PyUnicodeEncodeError_SetReason(arg1: *mut PyObject,
arg2: *const c_char)
-> c_int;
pub fn PyUnicodeDecodeError_SetReason(arg1: *mut PyObject,
arg2: *const c_char)
-> c_int;
pub fn PyUnicodeTranslateError_SetReason(arg1: *mut PyObject,
arg2: *const c_char)
-> c_int;
arg5: Py_ssize_t,
arg6: *const c_char,
) -> *mut PyObject;
pub fn PyUnicodeEncodeError_Create(
arg1: *const c_char,
arg2: *const Py_UNICODE,
arg3: Py_ssize_t,
arg4: Py_ssize_t,
arg5: Py_ssize_t,
arg6: *const c_char,
) -> *mut PyObject;
pub fn PyUnicodeTranslateError_Create(
arg1: *const Py_UNICODE,
arg2: Py_ssize_t,
arg3: Py_ssize_t,
arg4: Py_ssize_t,
arg5: *const c_char,
) -> *mut PyObject;
pub fn PyUnicodeEncodeError_GetEncoding(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeDecodeError_GetEncoding(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeEncodeError_GetObject(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeDecodeError_GetObject(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeTranslateError_GetObject(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeEncodeError_GetStart(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
pub fn PyUnicodeDecodeError_GetStart(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
pub fn PyUnicodeTranslateError_GetStart(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
pub fn PyUnicodeEncodeError_SetStart(arg1: *mut PyObject, arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeDecodeError_SetStart(arg1: *mut PyObject, arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeTranslateError_SetStart(arg1: *mut PyObject, arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeEncodeError_GetEnd(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
pub fn PyUnicodeDecodeError_GetEnd(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
pub fn PyUnicodeTranslateError_GetEnd(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
pub fn PyUnicodeEncodeError_SetEnd(arg1: *mut PyObject, arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeDecodeError_SetEnd(arg1: *mut PyObject, arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeTranslateError_SetEnd(arg1: *mut PyObject, arg2: Py_ssize_t) -> c_int;
pub fn PyUnicodeEncodeError_GetReason(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeDecodeError_GetReason(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeTranslateError_GetReason(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyUnicodeEncodeError_SetReason(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
pub fn PyUnicodeDecodeError_SetReason(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
pub fn PyUnicodeTranslateError_SetReason(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
}

View File

@ -1,6 +1,7 @@
use libc::{c_void, size_t};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyMem_Malloc(n: size_t) -> *mut c_void;
pub fn PyMem_Realloc(p: *mut c_void, n: size_t) -> *mut c_void;
pub fn PyMem_Free(p: *mut c_void);

View File

@ -1,4 +1,3 @@
pub type Py_uintptr_t = ::libc::uintptr_t;
pub type Py_intptr_t = ::libc::intptr_t;
pub type Py_ssize_t = ::libc::ssize_t;

View File

@ -1,13 +1,15 @@
use std::os::raw::{c_int, c_long};
use ffi2::object::PyObject;
use ffi2::frameobject::PyFrameObject;
use ffi2::object::PyObject;
use std::os::raw::{c_int, c_long};
pub enum PyInterpreterState {}
pub type Py_tracefunc =
unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyFrameObject,
arg3: c_int, arg4: *mut PyObject)
-> c_int;
pub type Py_tracefunc = unsafe extern "C" fn(
arg1: *mut PyObject,
arg2: *mut PyFrameObject,
arg3: c_int,
arg4: *mut PyObject,
) -> c_int;
/* The following values are used for 'what' for tracefunc functions: */
pub const PyTrace_CALL: c_int = 0;
@ -47,28 +49,29 @@ pub struct PyThreadState {
}
impl Clone for PyThreadState {
#[inline] fn clone(&self) -> PyThreadState { *self }
#[inline]
fn clone(&self) -> PyThreadState {
*self
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum PyGILState_STATE {
PyGILState_LOCKED,
PyGILState_UNLOCKED
PyGILState_UNLOCKED,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
static mut _PyThreadState_Current: *mut PyThreadState;
//static mut _PyThreadState_GetFrame: PyThreadFrameGetter;
pub fn PyInterpreterState_New() -> *mut PyInterpreterState;
pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState);
pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState);
pub fn PyThreadState_New(arg1: *mut PyInterpreterState)
-> *mut PyThreadState;
pub fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState)
-> *mut PyThreadState;
pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
pub fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
pub fn _PyThreadState_Init(arg1: *mut PyThreadState);
pub fn PyThreadState_Clear(arg1: *mut PyThreadState);
pub fn PyThreadState_Delete(arg1: *mut PyThreadState);
@ -77,17 +80,14 @@ pub enum PyGILState_STATE {
pub fn PyThreadState_Get() -> *mut PyThreadState;
pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState;
pub fn PyThreadState_GetDict() -> *mut PyObject;
pub fn PyThreadState_SetAsyncExc(arg1: c_long,
arg2: *mut PyObject) -> c_int;
pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int;
pub fn PyGILState_Ensure() -> PyGILState_STATE;
pub fn PyGILState_Release(arg1: PyGILState_STATE);
pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState;
fn _PyThread_CurrentFrames() -> *mut PyObject;
pub fn PyInterpreterState_Head() -> *mut PyInterpreterState;
pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState)
-> *mut PyInterpreterState;
pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState)
-> *mut PyThreadState;
pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) -> *mut PyInterpreterState;
pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) -> *mut PyThreadState;
pub fn PyThreadState_Next(arg1: *mut PyThreadState) -> *mut PyThreadState;
}
@ -102,5 +102,3 @@ pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
_PyThreadState_Current
}

View File

@ -1,12 +1,14 @@
use libc::{c_char, c_int, FILE};
use ffi2::object::*;
use ffi2::code::*;
use ffi2::pystate::PyThreadState;
use ffi2::object::*;
use ffi2::pyarena::PyArena;
use ffi2::pystate::PyThreadState;
use libc::{c_char, c_int, FILE};
pub const PyCF_MASK : c_int = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT |
CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION |
CO_FUTURE_UNICODE_LITERALS);
pub const PyCF_MASK: c_int = (CO_FUTURE_DIVISION
| CO_FUTURE_ABSOLUTE_IMPORT
| CO_FUTURE_WITH_STATEMENT
| CO_FUTURE_PRINT_FUNCTION
| CO_FUTURE_UNICODE_LITERALS);
pub const PyCF_MASK_OBSOLETE: c_int = (CO_NESTED);
pub const PyCF_SOURCE_IS_UTF8: c_int = 0x0100;
pub const PyCF_DONT_IMPLY_DEDENT: c_int = 0x0200;
@ -15,7 +17,7 @@ pub const PyCF_ONLY_AST : c_int = 0x0400;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyCompilerFlags {
cf_flags : c_int
cf_flags: c_int,
}
#[allow(missing_copy_implementations)]
@ -25,7 +27,8 @@ pub enum Struct__node { }
#[allow(missing_copy_implementations)]
pub enum Struct_symtable {}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn Py_SetProgramName(arg1: *mut c_char);
pub fn Py_GetProgramName() -> *mut c_char;
pub fn Py_SetPythonHome(arg1: *mut c_char);
@ -36,73 +39,96 @@ pub enum Struct_symtable { }
pub fn Py_IsInitialized() -> c_int;
pub fn Py_NewInterpreter() -> *mut PyThreadState;
pub fn Py_EndInterpreter(arg1: *mut PyThreadState);
pub fn PyRun_AnyFileFlags(arg1: *mut FILE, arg2: *const c_char,
arg3: *mut PyCompilerFlags) -> c_int;
pub fn PyRun_AnyFileExFlags(arg1: *mut FILE, arg2: *const c_char,
arg3: c_int,
arg4: *mut PyCompilerFlags) -> c_int;
pub fn PyRun_SimpleStringFlags(arg1: *const c_char,
arg2: *mut PyCompilerFlags)
-> c_int;
pub fn PyRun_SimpleFileExFlags(arg1: *mut FILE,
pub fn PyRun_AnyFileFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: *mut PyCompilerFlags,
) -> c_int;
pub fn PyRun_AnyFileExFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: c_int,
arg4: *mut PyCompilerFlags)
-> c_int;
pub fn PyRun_InteractiveOneFlags(arg1: *mut FILE,
arg4: *mut PyCompilerFlags,
) -> c_int;
pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int;
pub fn PyRun_SimpleFileExFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: *mut PyCompilerFlags)
-> c_int;
pub fn PyRun_InteractiveLoopFlags(arg1: *mut FILE,
arg3: c_int,
arg4: *mut PyCompilerFlags,
) -> c_int;
pub fn PyRun_InteractiveOneFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: *mut PyCompilerFlags)
-> c_int;
pub fn PyParser_ASTFromString(arg1: *const c_char,
arg3: *mut PyCompilerFlags,
) -> c_int;
pub fn PyRun_InteractiveLoopFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: *mut PyCompilerFlags,
) -> c_int;
pub fn PyParser_ASTFromString(
arg1: *const c_char,
arg2: *const c_char,
arg3: c_int,
flags: *mut PyCompilerFlags,
arg4: *mut PyArena) -> *mut Struct__mod;
pub fn PyParser_ASTFromFile(arg1: *mut FILE, arg2: *const c_char,
arg4: *mut PyArena,
) -> *mut Struct__mod;
pub fn PyParser_ASTFromFile(
arg1: *mut FILE,
arg2: *const c_char,
arg3: c_int,
arg4: *mut c_char,
arg5: *mut c_char,
arg6: *mut PyCompilerFlags,
arg7: *mut c_int, arg8: *mut PyArena)
-> *mut Struct__mod;
pub fn PyParser_SimpleParseStringFlags(arg1: *const c_char,
arg7: *mut c_int,
arg8: *mut PyArena,
) -> *mut Struct__mod;
pub fn PyParser_SimpleParseStringFlags(
arg1: *const c_char,
arg2: c_int,
arg3: c_int)
-> *mut Struct__node;
pub fn PyParser_SimpleParseFileFlags(arg1: *mut FILE,
arg3: c_int,
) -> *mut Struct__node;
pub fn PyParser_SimpleParseFileFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: c_int,
arg4: c_int)
-> *mut Struct__node;
pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int,
arg3: *mut PyObject, arg4: *mut PyObject,
arg5: *mut PyCompilerFlags) -> *mut PyObject;
pub fn PyRun_FileExFlags(arg1: *mut FILE, arg2: *const c_char,
arg3: c_int, arg4: *mut PyObject,
arg5: *mut PyObject, arg6: c_int,
arg7: *mut PyCompilerFlags) -> *mut PyObject;
pub fn Py_CompileStringFlags(arg1: *const c_char,
arg4: c_int,
) -> *mut Struct__node;
pub fn PyRun_StringFlags(
arg1: *const c_char,
arg2: c_int,
arg3: *mut PyObject,
arg4: *mut PyObject,
arg5: *mut PyCompilerFlags,
) -> *mut PyObject;
pub fn PyRun_FileExFlags(
arg1: *mut FILE,
arg2: *const c_char,
arg3: c_int,
arg4: *mut PyCompilerFlags) -> *mut PyObject;
pub fn Py_SymtableString(arg1: *const c_char,
arg2: *const c_char, arg3: c_int)
-> *mut Struct_symtable;
arg4: *mut PyObject,
arg5: *mut PyObject,
arg6: c_int,
arg7: *mut PyCompilerFlags,
) -> *mut PyObject;
pub fn Py_CompileStringFlags(
arg1: *const c_char,
arg2: *const c_char,
arg3: c_int,
arg4: *mut PyCompilerFlags,
) -> *mut PyObject;
pub fn Py_SymtableString(
arg1: *const c_char,
arg2: *const c_char,
arg3: c_int,
) -> *mut Struct_symtable;
pub fn PyErr_Print();
pub fn PyErr_PrintEx(arg1: c_int);
pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject);
pub fn Py_AtExit(func: Option<unsafe extern "C" fn()>)
-> c_int;
pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject);
pub fn Py_AtExit(func: Option<unsafe extern "C" fn()>) -> c_int;
pub fn Py_Exit(arg1: c_int);
pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char)
-> c_int;
pub fn Py_Main(argc: c_int, argv: *mut *mut c_char)
-> c_int;
pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) -> c_int;
pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) -> c_int;
pub fn Py_GetProgramFullPath() -> *mut c_char;
pub fn Py_GetPrefix() -> *mut c_char;
pub fn Py_GetExecPrefix() -> *mut c_char;
@ -118,4 +144,3 @@ pub enum Struct_symtable { }
fn _Py_hgidentifier() -> *const c_char;
fn _Py_hgversion() -> *const c_char;
}

View File

@ -1,7 +1,8 @@
use std::os::raw::c_int;
use ffi2::object::*;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyRange_Type: PyTypeObject;
}
@ -10,4 +11,3 @@ pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int {
let u: *mut PyTypeObject = &mut PyRange_Type;
(Py_TYPE(op) == u) as c_int
}

View File

@ -1,10 +1,11 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
//enum PySetObject { /* representation hidden */ }
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PySet_Type: PyTypeObject;
pub static mut PyFrozenSet_Type: PyTypeObject;
}
@ -24,9 +25,9 @@ pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int {
#[inline]
pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int {
(PyAnySet_CheckExact(ob) != 0 ||
PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 ||
PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int
(PyAnySet_CheckExact(ob) != 0
|| PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0
|| PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int
}
#[inline]
@ -41,15 +42,14 @@ pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int {
(Py_TYPE(ob) == f || PyType_IsSubtype(Py_TYPE(ob), f) != 0) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject;
pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject;
pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t;
pub fn PySet_Clear(set: *mut PyObject) -> c_int;
pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject)
-> c_int;
pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject)
-> c_int;
pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int;
//pub fn _PySet_Next(set: *mut PyObject, pos: *mut Py_ssize_t,
// key: *mut *mut PyObject) -> c_int;
@ -60,4 +60,3 @@ pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int {
//pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject)
// -> c_int;
}

View File

@ -1,8 +1,9 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
static mut _Py_EllipsisObject: PyObject;
}
@ -22,10 +23,11 @@ pub struct PySliceObject {
pub ob_type: *mut PyTypeObject,
pub start: *mut PyObject,
pub stop: *mut PyObject,
pub step: *mut PyObject
pub step: *mut PyObject,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PySlice_Type: PyTypeObject;
pub static mut PyEllipsis_Type: PyTypeObject;
}
@ -35,16 +37,26 @@ pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PySlice_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject,
step: *mut PyObject) -> *mut PyObject;
pub fn PySlice_GetIndices(r: *mut PyObject, length: Py_ssize_t,
start: *mut Py_ssize_t, stop: *mut Py_ssize_t,
step: *mut Py_ssize_t) -> c_int;
pub fn PySlice_GetIndicesEx(r: *mut PyObject, length: Py_ssize_t,
start: *mut Py_ssize_t, stop: *mut Py_ssize_t,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PySlice_New(
start: *mut PyObject,
stop: *mut PyObject,
step: *mut PyObject,
) -> *mut PyObject;
pub fn PySlice_GetIndices(
r: *mut PyObject,
length: Py_ssize_t,
start: *mut Py_ssize_t,
stop: *mut Py_ssize_t,
step: *mut Py_ssize_t,
slicelength: *mut Py_ssize_t)
-> c_int;
) -> c_int;
pub fn PySlice_GetIndicesEx(
r: *mut PyObject,
length: Py_ssize_t,
start: *mut Py_ssize_t,
stop: *mut Py_ssize_t,
step: *mut Py_ssize_t,
slicelength: *mut Py_ssize_t,
) -> c_int;
}

View File

@ -1,6 +1,6 @@
use std::os::raw::{c_char, c_int, c_long};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_long};
#[repr(C)]
#[allow(missing_copy_implementations)]
@ -17,7 +17,8 @@ pub struct PyStringObject {
pub ob_sval: [c_char; 1],
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyBaseString_Type: PyTypeObject;
pub static mut PyString_Type: PyTypeObject;
}
@ -30,7 +31,9 @@ pub unsafe fn PyString_Check(op : *mut PyObject) -> c_int {
#[inline(always)]
pub unsafe fn PyBaseString_Check(op: *mut PyObject) -> c_int {
PyType_FastSubclass(
Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS)
Py_TYPE(op),
Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS,
)
}
#[inline(always)]
@ -49,35 +52,46 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char {
(*(op as *mut PyStringObject)).ob_sval.as_mut_ptr()
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyString_FromString(v: *const c_char) -> *mut PyObject;
pub fn PyString_FromStringAndSize(v: *const c_char,
len: Py_ssize_t) -> *mut PyObject;
pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject;
pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject;
pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t;
pub fn PyString_AsString(string: *mut PyObject) -> *mut c_char;
pub fn PyString_AsStringAndSize(obj: *mut PyObject,
pub fn PyString_AsStringAndSize(
obj: *mut PyObject,
s: *mut *mut c_char,
len: *mut Py_ssize_t) -> c_int;
len: *mut Py_ssize_t,
) -> c_int;
pub fn PyString_Concat(string: *mut *mut PyObject, newpart: *mut PyObject);
pub fn PyString_ConcatAndDel(string: *mut *mut PyObject, newpart: *mut PyObject);
pub fn _PyString_Resize(string: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int;
pub fn PyString_Format(format: *mut PyObject, args: *mut PyObject)
-> *mut PyObject;
pub fn PyString_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
pub fn PyString_InternInPlace(string: *mut *mut PyObject);
pub fn PyString_InternFromString(v: *const c_char) -> *mut PyObject;
pub fn PyString_Decode(s: *const c_char, size: Py_ssize_t,
pub fn PyString_Decode(
s: *const c_char,
size: Py_ssize_t,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
pub fn PyString_AsDecodedObject(str: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyString_AsDecodedObject(
str: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
pub fn PyString_Encode(s: *const c_char, size: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyString_Encode(
s: *const c_char,
size: Py_ssize_t,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
pub fn PyString_AsEncodedObject(str: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyString_AsEncodedObject(
str: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
/*
pub fn PyString_Repr(arg1: *mut PyObject, arg2: c_int)
@ -129,4 +143,3 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char {
format_spec_len: Py_ssize_t)
-> *mut PyObject;*/
}

View File

@ -1,6 +1,6 @@
use std::os::raw::{c_char, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::PyObject;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[repr(C)]
#[derive(Copy, Clone)]
@ -9,7 +9,7 @@ pub struct PyMemberDef {
pub type_code: c_int,
pub offset: Py_ssize_t,
pub flags: c_int,
pub doc: *mut c_char
pub doc: *mut c_char,
}
/* Types */
@ -44,7 +44,6 @@ pub const T_ULONGLONG : c_int = 18;
pub const T_PYSSIZET: c_int = 19; /* Py_ssize_t */
/* Flags */
pub const READONLY: c_int = 1;
pub const RO: c_int = READONLY; /* Shorthand */
@ -52,9 +51,8 @@ pub const READ_RESTRICTED : c_int = 2;
pub const PY_WRITE_RESTRICTED: c_int = 4;
pub const RESTRICTED: c_int = (READ_RESTRICTED | PY_WRITE_RESTRICTED);
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyMember_GetOne(addr: *const c_char, l: *mut PyMemberDef) -> *mut PyObject;
pub fn PyMember_SetOne(addr: *mut c_char, l: *mut PyMemberDef, value: *mut PyObject) -> c_int;
}

View File

@ -1,7 +1,7 @@
use std::os::raw::c_int;
use ffi2::frameobject::PyFrameObject;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use ffi2::frameobject::PyFrameObject;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -15,13 +15,13 @@ pub struct PyTracebackObject {
pub tb_next: *mut PyTracebackObject,
pub tb_frame: *mut PyFrameObject,
pub tb_lasti: c_int,
pub tb_lineno: c_int
pub tb_lineno: c_int,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int;
pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject)
-> c_int;
pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub static mut PyTraceBack_Type: PyTypeObject;
}
@ -30,4 +30,3 @@ pub struct PyTracebackObject {
pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyTraceBack_Type) as c_int
}

View File

@ -1,6 +1,6 @@
use std::os::raw::c_int;
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -15,7 +15,8 @@ pub struct PyTupleObject {
pub ob_item: [*mut PyObject; 1],
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyTuple_Type: PyTypeObject;
}
@ -30,11 +31,13 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == u) as c_int
}
// Macro, trading safety for speed
#[inline(always)]
pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
*(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i as isize)
*(*(op as *mut PyTupleObject))
.ob_item
.as_ptr()
.offset(i as isize)
}
#[inline(always)]
@ -45,17 +48,19 @@ pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
/// Macro, *only* to be used to fill in brand new tuples
#[inline(always)]
pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
*(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i as isize) = v;
*(*(op as *mut PyTupleObject))
.ob_item
.as_mut_ptr()
.offset(i as isize) = v;
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject;
pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t;
pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) -> *mut PyObject;
pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t,
o: *mut PyObject) -> c_int;
pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t,
high: Py_ssize_t) -> *mut PyObject;
pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int;
pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject;
pub fn _PyTuple_Resize(p: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int;
pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject;
//pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject);

View File

@ -1,7 +1,7 @@
use libc::wchar_t;
use std::os::raw::{c_char, c_int, c_long, c_double};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use libc::wchar_t;
use std::os::raw::{c_char, c_double, c_int, c_long};
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
pub const Py_UNICODE_SIZE: Py_ssize_t = 4;
@ -30,7 +30,8 @@ pub struct PyUnicodeObject {
pub defenc: *mut PyObject,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyUnicode_Type: PyTypeObject;
}
@ -67,176 +68,276 @@ pub unsafe fn PyUnicode_AS_DATA(o: *mut PyObject) -> *const c_char {
pub const Py_UNICODE_REPLACEMENT_CHARACTER: Py_UNICODE = 0xFFFD;
#[allow(dead_code)]
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char,
size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE;
fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t;
fn PyUnicodeUCS4_GetMax() -> Py_UNICODE;
fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject,
length: Py_ssize_t) -> c_int;
fn PyUnicodeUCS4_FromEncodedObject(obj: *mut PyObject,
fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int;
fn PyUnicodeUCS4_FromEncodedObject(
obj: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_FromObject(obj: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_FromFormatV(arg1: *const c_char, ...) -> *mut PyObject;
fn PyUnicodeUCS4_FromFormat(arg1: *const c_char, ...) -> *mut PyObject;
fn _PyUnicode_FormatAdvanced(obj: *mut PyObject,
fn _PyUnicode_FormatAdvanced(
obj: *mut PyObject,
format_spec: *mut Py_UNICODE,
format_spec_len: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_FromWideChar(w: *const wchar_t, size: Py_ssize_t)
-> *mut PyObject;
fn PyUnicodeUCS4_AsWideChar(unicode: *mut PyUnicodeObject,
w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t;
format_spec_len: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_AsWideChar(
unicode: *mut PyUnicodeObject,
w: *mut wchar_t,
size: Py_ssize_t,
) -> Py_ssize_t;
fn PyUnicodeUCS4_FromOrdinal(ordinal: c_int) -> *mut PyObject;
fn PyUnicodeUCS4_ClearFreelist() -> c_int;
fn _PyUnicodeUCS4_AsDefaultEncodedString(arg1: *mut PyObject, arg2: *const c_char)
-> *mut PyObject;
fn _PyUnicodeUCS4_AsDefaultEncodedString(
arg1: *mut PyObject,
arg2: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_GetDefaultEncoding() -> *const c_char;
fn PyUnicodeUCS4_SetDefaultEncoding(encoding: *const c_char) -> c_int;
fn PyUnicodeUCS4_Decode(s: *const c_char, size: Py_ssize_t,
fn PyUnicodeUCS4_Decode(
s: *const c_char,
size: Py_ssize_t,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_Encode(s: *const Py_UNICODE, size: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_Encode(
s: *const Py_UNICODE,
size: Py_ssize_t,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_AsEncodedObject(unicode: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsEncodedObject(
unicode: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_AsEncodedString(unicode: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsEncodedString(
unicode: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject;
fn PyUnicode_DecodeUTF7(string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicode_DecodeUTF7Stateful(string: *const c_char,
fn PyUnicode_DecodeUTF7(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t) -> *mut PyObject;
fn PyUnicode_EncodeUTF7(data: *const Py_UNICODE, length: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicode_DecodeUTF7Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicode_EncodeUTF7(
data: *const Py_UNICODE,
length: Py_ssize_t,
base64SetO: c_int,
base64WhiteSpace: c_int,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF8(string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF8Stateful(string: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF8(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t) -> *mut PyObject;
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF8Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeUTF8(data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF32(string: *const c_char,
fn PyUnicodeUCS4_EncodeUTF8(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF32Stateful(string: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF32(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t) -> *mut PyObject;
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF32Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeUTF32(data: *const Py_UNICODE,
fn PyUnicodeUCS4_EncodeUTF32(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char,
byteorder: c_int) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF16(string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF16Stateful(string: *const c_char,
byteorder: c_int,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF16(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeUTF16(data: *const Py_UNICODE,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUTF16Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: c_int) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUnicodeEscape(string: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeUTF16(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
byteorder: c_int,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeUnicodeEscape(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeUnicodeEscape(data: *const Py_UNICODE,
length: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeRawUnicodeEscape(string: *const c_char,
fn PyUnicodeUCS4_EncodeUnicodeEscape(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeRawUnicodeEscape(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsRawUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeRawUnicodeEscape(data: *const Py_UNICODE,
length: Py_ssize_t) -> *mut PyObject;
fn _PyUnicode_DecodeUnicodeInternal(string: *const c_char,
fn PyUnicodeUCS4_EncodeRawUnicodeEscape(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeLatin1(string: *const c_char,
) -> *mut PyObject;
fn _PyUnicode_DecodeUnicodeInternal(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeLatin1(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeLatin1(data: *const Py_UNICODE,
fn PyUnicodeUCS4_EncodeLatin1(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeASCII(string: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeASCII(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeASCII(data: *const Py_UNICODE,
fn PyUnicodeUCS4_EncodeASCII(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeCharmap(string: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_DecodeCharmap(
string: *const c_char,
length: Py_ssize_t,
mapping: *mut PyObject,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_AsCharmapString(unicode: *mut PyObject,
mapping: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeCharmap(data: *const Py_UNICODE,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_AsCharmapString(
unicode: *mut PyObject,
mapping: *mut PyObject,
) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeCharmap(
data: *const Py_UNICODE,
length: Py_ssize_t,
mapping: *mut PyObject,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_TranslateCharmap(data: *const Py_UNICODE,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_TranslateCharmap(
data: *const Py_UNICODE,
length: Py_ssize_t,
table: *mut PyObject,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_EncodeDecimal(
s: *mut Py_UNICODE,
length: Py_ssize_t,
output: *mut c_char,
errors: *const c_char) -> c_int;
errors: *const c_char,
) -> c_int;
fn PyUnicodeUCS4_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_Split(s: *mut PyObject, sep: *mut PyObject,
maxsplit: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_Split(
s: *mut PyObject,
sep: *mut PyObject,
maxsplit: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject;
fn PyUnicodeUCS4_Partition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_RPartition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_RSplit(s: *mut PyObject, sep: *mut PyObject,
maxsplit: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char)
-> *mut PyObject;
fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject)
-> *mut PyObject;
fn PyUnicodeUCS4_Tailmatch(str: *mut PyObject, substr: *mut PyObject,
start: Py_ssize_t, end: Py_ssize_t,
direction: c_int) -> Py_ssize_t;
fn PyUnicodeUCS4_Find(str: *mut PyObject, substr: *mut PyObject,
start: Py_ssize_t, end: Py_ssize_t,
direction: c_int) -> Py_ssize_t;
fn PyUnicodeUCS4_Count(str: *mut PyObject, substr: *mut PyObject,
start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t;
fn PyUnicodeUCS4_Replace(str: *mut PyObject, substr: *mut PyObject,
replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS4_RSplit(
s: *mut PyObject,
sep: *mut PyObject,
maxsplit: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_Translate(
str: *mut PyObject,
table: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_Tailmatch(
str: *mut PyObject,
substr: *mut PyObject,
start: Py_ssize_t,
end: Py_ssize_t,
direction: c_int,
) -> Py_ssize_t;
fn PyUnicodeUCS4_Find(
str: *mut PyObject,
substr: *mut PyObject,
start: Py_ssize_t,
end: Py_ssize_t,
direction: c_int,
) -> Py_ssize_t;
fn PyUnicodeUCS4_Count(
str: *mut PyObject,
substr: *mut PyObject,
start: Py_ssize_t,
end: Py_ssize_t,
) -> Py_ssize_t;
fn PyUnicodeUCS4_Replace(
str: *mut PyObject,
substr: *mut PyObject,
replstr: *mut PyObject,
maxcount: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS4_Compare(left: *mut PyObject, right: *mut PyObject) -> c_int;
fn PyUnicodeUCS4_RichCompare(left: *mut PyObject,
right: *mut PyObject, op: c_int) -> *mut PyObject;
fn PyUnicodeUCS4_RichCompare(
left: *mut PyObject,
right: *mut PyObject,
op: c_int,
) -> *mut PyObject;
fn PyUnicodeUCS4_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS4_Contains(container: *mut PyObject, element: *mut PyObject) -> c_int;
fn _PyUnicode_XStrip(_self: *mut PyUnicodeObject,
striptype: c_int, sepobj: *mut PyObject) -> *mut PyObject;
fn _PyUnicode_XStrip(
_self: *mut PyUnicodeObject,
striptype: c_int,
sepobj: *mut PyObject,
) -> *mut PyObject;
fn _PyUnicodeUCS4_IsLowercase(ch: Py_UNICODE) -> c_int;
fn _PyUnicodeUCS4_IsUppercase(ch: Py_UNICODE) -> c_int;
fn _PyUnicodeUCS4_IsTitlecase(ch: Py_UNICODE) -> c_int;
@ -256,191 +357,274 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD;
#[allow(dead_code)]
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t)
-> *mut PyObject;
fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char,
size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_FromString(u: *const c_char)
-> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE;
fn PyUnicodeUCS2_GetSize(unicode: *mut PyObject) -> Py_ssize_t;
fn PyUnicodeUCS2_GetMax() -> Py_UNICODE;
fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject,
length: Py_ssize_t) -> c_int;
fn PyUnicodeUCS2_FromEncodedObject(obj: *mut PyObject,
fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int;
fn PyUnicodeUCS2_FromEncodedObject(
obj: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_FromObject(obj: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_FromFormatV(arg1: *const c_char, ...) -> *mut PyObject;
fn PyUnicodeUCS2_FromFormat(arg1: *const c_char, ...) -> *mut PyObject;
fn _PyUnicode_FormatAdvanced(obj: *mut PyObject,
fn _PyUnicode_FormatAdvanced(
obj: *mut PyObject,
format_spec: *mut Py_UNICODE,
format_spec_len: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_FromWideChar(w: *const wchar_t, size: Py_ssize_t)
-> *mut PyObject;
fn PyUnicodeUCS2_AsWideChar(unicode: *mut PyUnicodeObject,
w: *mut wchar_t, size: Py_ssize_t)
-> Py_ssize_t;
format_spec_len: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_AsWideChar(
unicode: *mut PyUnicodeObject,
w: *mut wchar_t,
size: Py_ssize_t,
) -> Py_ssize_t;
fn PyUnicodeUCS2_FromOrdinal(ordinal: c_int) -> *mut PyObject;
fn PyUnicodeUCS2_ClearFreelist() -> c_int;
fn _PyUnicodeUCS2_AsDefaultEncodedString(arg1: *mut PyObject,
arg2: *const c_char) -> *mut PyObject;
fn _PyUnicodeUCS2_AsDefaultEncodedString(
arg1: *mut PyObject,
arg2: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_GetDefaultEncoding() -> *const c_char;
fn PyUnicodeUCS2_SetDefaultEncoding(encoding: *const c_char) -> c_int;
fn PyUnicodeUCS2_Decode(s: *const c_char, size: Py_ssize_t,
fn PyUnicodeUCS2_Decode(
s: *const c_char,
size: Py_ssize_t,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_Encode(s: *const Py_UNICODE, size: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_Encode(
s: *const Py_UNICODE,
size: Py_ssize_t,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_AsEncodedObject(unicode: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsEncodedObject(
unicode: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_AsEncodedString(unicode: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsEncodedString(
unicode: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject;
fn PyUnicode_DecodeUTF7(string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicode_DecodeUTF7Stateful(string: *const c_char,
fn PyUnicode_DecodeUTF7(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t) -> *mut PyObject;
fn PyUnicode_EncodeUTF7(data: *const Py_UNICODE, length: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicode_DecodeUTF7Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicode_EncodeUTF7(
data: *const Py_UNICODE,
length: Py_ssize_t,
base64SetO: c_int,
base64WhiteSpace: c_int,
errors: *const c_char)
-> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF8(string: *const c_char,
length: Py_ssize_t,
errors: *const c_char)
-> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF8Stateful(string: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF8(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t)
-> *mut PyObject;
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF8Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeUTF8(data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF32(string: *const c_char,
fn PyUnicodeUCS2_EncodeUTF8(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF32Stateful(string: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF32(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t) -> *mut PyObject;
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF32Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeUTF32(data: *const Py_UNICODE,
fn PyUnicodeUCS2_EncodeUTF32(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char,
byteorder: c_int) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF16(string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF16Stateful(string: *const c_char,
byteorder: c_int,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF16(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeUTF16(data: *const Py_UNICODE,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUTF16Stateful(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
byteorder: c_int) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUnicodeEscape(string: *const c_char,
byteorder: *mut c_int,
consumed: *mut Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeUTF16(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
byteorder: c_int,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeUnicodeEscape(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeUnicodeEscape(data: *const Py_UNICODE,
length: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeRawUnicodeEscape(string: *const c_char,
fn PyUnicodeUCS2_EncodeUnicodeEscape(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeRawUnicodeEscape(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsRawUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeRawUnicodeEscape(data: *const Py_UNICODE,
length: Py_ssize_t) -> *mut PyObject;
fn _PyUnicode_DecodeUnicodeInternal(string: *const c_char,
fn PyUnicodeUCS2_EncodeRawUnicodeEscape(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeLatin1(string: *const c_char,
) -> *mut PyObject;
fn _PyUnicode_DecodeUnicodeInternal(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeLatin1(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeLatin1(data: *const Py_UNICODE,
fn PyUnicodeUCS2_EncodeLatin1(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeASCII(string: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeASCII(
string: *const c_char,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeASCII(data: *const Py_UNICODE,
fn PyUnicodeUCS2_EncodeASCII(
data: *const Py_UNICODE,
length: Py_ssize_t,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeCharmap(string: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_DecodeCharmap(
string: *const c_char,
length: Py_ssize_t,
mapping: *mut PyObject,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_AsCharmapString(unicode: *mut PyObject,
mapping: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeCharmap(data: *const Py_UNICODE,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_AsCharmapString(
unicode: *mut PyObject,
mapping: *mut PyObject,
) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeCharmap(
data: *const Py_UNICODE,
length: Py_ssize_t,
mapping: *mut PyObject,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_TranslateCharmap(data: *const Py_UNICODE,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_TranslateCharmap(
data: *const Py_UNICODE,
length: Py_ssize_t,
table: *mut PyObject,
errors: *const c_char) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_EncodeDecimal(
s: *mut Py_UNICODE,
length: Py_ssize_t,
output: *mut c_char,
errors: *const c_char) -> c_int;
fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject)
-> *mut PyObject;
fn PyUnicodeUCS2_Split(s: *mut PyObject, sep: *mut PyObject,
maxsplit: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_Splitlines(s: *mut PyObject, keepends: c_int)
-> *mut PyObject;
fn PyUnicodeUCS2_Partition(s: *mut PyObject, sep: *mut PyObject)
-> *mut PyObject;
fn PyUnicodeUCS2_RPartition(s: *mut PyObject, sep: *mut PyObject)
-> *mut PyObject;
fn PyUnicodeUCS2_RSplit(s: *mut PyObject, sep: *mut PyObject,
maxsplit: Py_ssize_t) -> *mut PyObject;
fn PyUnicodeUCS2_Translate(str: *mut PyObject, table: *mut PyObject,
errors: *const c_char)
-> *mut PyObject;
fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject)
-> *mut PyObject;
fn PyUnicodeUCS2_Tailmatch(str: *mut PyObject, substr: *mut PyObject,
start: Py_ssize_t, end: Py_ssize_t,
direction: c_int) -> Py_ssize_t;
fn PyUnicodeUCS2_Find(str: *mut PyObject, substr: *mut PyObject,
start: Py_ssize_t, end: Py_ssize_t,
direction: c_int) -> Py_ssize_t;
fn PyUnicodeUCS2_Count(str: *mut PyObject, substr: *mut PyObject,
start: Py_ssize_t, end: Py_ssize_t)
-> Py_ssize_t;
fn PyUnicodeUCS2_Replace(str: *mut PyObject, substr: *mut PyObject,
replstr: *mut PyObject, maxcount: Py_ssize_t)
-> *mut PyObject;
fn PyUnicodeUCS2_Compare(left: *mut PyObject, right: *mut PyObject)
-> c_int;
fn PyUnicodeUCS2_RichCompare(left: *mut PyObject,
right: *mut PyObject, op: c_int)
-> *mut PyObject;
fn PyUnicodeUCS2_Format(format: *mut PyObject, args: *mut PyObject)
-> *mut PyObject;
fn PyUnicodeUCS2_Contains(container: *mut PyObject,
element: *mut PyObject) -> c_int;
fn _PyUnicode_XStrip(_self: *mut PyUnicodeObject,
striptype: c_int, sepobj: *mut PyObject)
-> *mut PyObject;
errors: *const c_char,
) -> c_int;
fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_Split(
s: *mut PyObject,
sep: *mut PyObject,
maxsplit: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject;
fn PyUnicodeUCS2_Partition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_RPartition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_RSplit(
s: *mut PyObject,
sep: *mut PyObject,
maxsplit: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_Translate(
str: *mut PyObject,
table: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_Tailmatch(
str: *mut PyObject,
substr: *mut PyObject,
start: Py_ssize_t,
end: Py_ssize_t,
direction: c_int,
) -> Py_ssize_t;
fn PyUnicodeUCS2_Find(
str: *mut PyObject,
substr: *mut PyObject,
start: Py_ssize_t,
end: Py_ssize_t,
direction: c_int,
) -> Py_ssize_t;
fn PyUnicodeUCS2_Count(
str: *mut PyObject,
substr: *mut PyObject,
start: Py_ssize_t,
end: Py_ssize_t,
) -> Py_ssize_t;
fn PyUnicodeUCS2_Replace(
str: *mut PyObject,
substr: *mut PyObject,
replstr: *mut PyObject,
maxcount: Py_ssize_t,
) -> *mut PyObject;
fn PyUnicodeUCS2_Compare(left: *mut PyObject, right: *mut PyObject) -> c_int;
fn PyUnicodeUCS2_RichCompare(
left: *mut PyObject,
right: *mut PyObject,
op: c_int,
) -> *mut PyObject;
fn PyUnicodeUCS2_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
fn PyUnicodeUCS2_Contains(container: *mut PyObject, element: *mut PyObject) -> c_int;
fn _PyUnicode_XStrip(
_self: *mut PyUnicodeObject,
striptype: c_int,
sepobj: *mut PyObject,
) -> *mut PyObject;
fn _PyUnicodeUCS2_IsLowercase(ch: Py_UNICODE) -> c_int;
fn _PyUnicodeUCS2_IsUppercase(ch: Py_UNICODE) -> c_int;
fn _PyUnicodeUCS2_IsTitlecase(ch: Py_UNICODE) -> c_int;
@ -484,16 +668,20 @@ pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject {
#[inline(always)]
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject,
pub unsafe fn PyUnicode_FromEncodedObject(
obj: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject {
errors: *const c_char,
) -> *mut PyObject {
PyUnicodeUCS4_FromEncodedObject(obj, encoding, errors)
}
#[inline(always)]
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject,
pub unsafe fn PyUnicode_FromEncodedObject(
obj: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject {
errors: *const c_char,
) -> *mut PyObject {
PyUnicodeUCS2_FromEncodedObject(obj, encoding, errors)
}

View File

@ -1,16 +1,22 @@
use std::os::raw::{c_char, c_int};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::PyObject;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyErr_WarnEx(category: *mut PyObject, msg: *const c_char,
stacklevel: Py_ssize_t) -> c_int;
pub fn PyErr_WarnExplicit(arg1: *mut PyObject,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyErr_WarnEx(
category: *mut PyObject,
msg: *const c_char,
stacklevel: Py_ssize_t,
) -> c_int;
pub fn PyErr_WarnExplicit(
arg1: *mut PyObject,
arg2: *const c_char,
arg3: *const c_char,
arg4: c_int,
arg5: *const c_char,
arg6: *mut PyObject) -> c_int;
arg6: *mut PyObject,
) -> c_int;
}
#[inline]

View File

@ -1,6 +1,6 @@
use std::os::raw::{c_int, c_long};
use ffi2::pyport::Py_ssize_t;
use ffi2::object::*;
use ffi2::pyport::Py_ssize_t;
use std::os::raw::{c_int, c_long};
#[repr(C)]
#[derive(Copy, Clone)]
@ -15,10 +15,11 @@ pub struct PyWeakReference {
pub wr_callback: *mut PyObject,
pub hash: c_long,
pub wr_prev: *mut PyWeakReference,
pub wr_next: *mut PyWeakReference
pub wr_next: *mut PyWeakReference,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
static mut _PyWeakref_RefType: PyTypeObject;
static mut _PyWeakref_ProxyType: PyTypeObject;
static mut _PyWeakref_CallableProxyType: PyTypeObject;
@ -36,8 +37,8 @@ pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
#[inline(always)]
pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int {
((Py_TYPE(op) == &mut _PyWeakref_ProxyType) ||
(Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int
((Py_TYPE(op) == &mut _PyWeakref_ProxyType)
|| (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int
}
#[inline(always)]
@ -45,11 +46,10 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int {
(PyWeakref_CheckRef(op) != 0 || PyWeakref_CheckProxy(op) != 0) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject)
-> *mut PyObject;
pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject)
-> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject;
pub fn _PyWeakref_GetWeakrefCount(head: *mut PyWeakReference) -> Py_ssize_t;
@ -59,6 +59,9 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int {
#[inline(always)]
pub unsafe fn PyWeakref_GET_OBJECT(_ref: *mut PyObject) -> *mut PyObject {
let obj = (*(_ref as *mut PyWeakReference)).wr_object;
if Py_REFCNT(obj) > 0 { obj } else { Py_None() }
if Py_REFCNT(obj) > 0 {
obj
} else {
Py_None()
}
}

View File

@ -1,6 +1,7 @@
use ffi3::object::PyTypeObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFilter_Type: PyTypeObject;
pub static mut PyMap_Type: PyTypeObject;
pub static mut PyZip_Type: PyTypeObject;

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_int, c_long};
use ffi3::object::*;
use ffi3::longobject::PyLongObject;
use ffi3::object::*;
use std::os::raw::{c_int, c_long};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyBool_Type: PyTypeObject;
static mut _Py_FalseStruct: PyLongObject;
static mut _Py_TrueStruct: PyLongObject;
@ -23,4 +24,3 @@ pub unsafe fn Py_False() -> *mut PyObject {
pub unsafe fn Py_True() -> *mut PyObject {
&mut _Py_TrueStruct as *mut PyLongObject as *mut PyObject
}

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_char, c_int};
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyByteArray_Type: PyTypeObject;
pub static mut PyByteArrayIter_Type: PyTypeObject;
}
@ -17,15 +18,12 @@ pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyByteArray_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject;
pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject)
-> *mut PyObject;
pub fn PyByteArray_FromStringAndSize(string: *const c_char,
len: Py_ssize_t) -> *mut PyObject;
pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject;
pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject;
pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t;
pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char;
pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t)
-> c_int;
pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int;
}

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_char, c_int};
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyBytes_Type: PyTypeObject;
pub static mut PyBytesIter_Type: PyTypeObject;
}
@ -17,28 +18,29 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyBytes_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyBytes_FromStringAndSize(arg1: *const c_char,
arg2: Py_ssize_t) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyBytes_FromStringAndSize(arg1: *const c_char, arg2: Py_ssize_t) -> *mut PyObject;
pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject;
pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject;
//pub fn PyBytes_FromFormatV(arg1: *const c_char, arg2: va_list)
// -> *mut PyObject;
pub fn PyBytes_FromFormat(arg1: *const c_char, ...)
-> *mut PyObject;
pub fn PyBytes_FromFormat(arg1: *const c_char, ...) -> *mut PyObject;
pub fn PyBytes_Size(arg1: *mut PyObject) -> Py_ssize_t;
pub fn PyBytes_AsString(arg1: *mut PyObject) -> *mut c_char;
pub fn PyBytes_Repr(arg1: *mut PyObject, arg2: c_int)
-> *mut PyObject;
pub fn PyBytes_Concat(arg1: *mut *mut PyObject, arg2: *mut PyObject)
-> ();
pub fn PyBytes_ConcatAndDel(arg1: *mut *mut PyObject, arg2: *mut PyObject)
-> ();
pub fn PyBytes_DecodeEscape(arg1: *const c_char, arg2: Py_ssize_t,
arg3: *const c_char, arg4: Py_ssize_t,
arg5: *const c_char) -> *mut PyObject;
pub fn PyBytes_AsStringAndSize(obj: *mut PyObject,
pub fn PyBytes_Repr(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject;
pub fn PyBytes_Concat(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> ();
pub fn PyBytes_ConcatAndDel(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> ();
pub fn PyBytes_DecodeEscape(
arg1: *const c_char,
arg2: Py_ssize_t,
arg3: *const c_char,
arg4: Py_ssize_t,
arg5: *const c_char,
) -> *mut PyObject;
pub fn PyBytes_AsStringAndSize(
obj: *mut PyObject,
s: *mut *mut c_char,
len: *mut Py_ssize_t) -> c_int;
len: *mut Py_ssize_t,
) -> c_int;
}

View File

@ -1,14 +1,16 @@
use std::os::raw::{c_void, c_char, c_int};
use ffi3::object::PyObject;
use ffi3::pystate::PyThreadState;
#[cfg(Py_3_6)]
use ffi3::code::FreeFunc;
use ffi3::object::PyObject;
use ffi3::pystate::PyThreadState;
use std::os::raw::{c_char, c_int, c_void};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyEval_CallObjectWithKeywords(func: *mut PyObject,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_CallObjectWithKeywords(
func: *mut PyObject,
obj: *mut PyObject,
kwargs: *mut PyObject)
-> *mut PyObject;
kwargs: *mut PyObject,
) -> *mut PyObject;
}
#[inline]
@ -16,20 +18,23 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut
PyEval_CallObjectWithKeywords(func, arg, ::std::ptr::null_mut())
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyEval_CallFunction(obj: *mut PyObject,
format: *const c_char, ...)
-> *mut PyObject;
pub fn PyEval_CallMethod(obj: *mut PyObject,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject;
pub fn PyEval_CallMethod(
obj: *mut PyObject,
methodname: *const c_char,
format: *const c_char, ...)
-> *mut PyObject;
format: *const c_char,
...
) -> *mut PyObject;
pub fn PyEval_GetBuiltins() -> *mut PyObject;
pub fn PyEval_GetGlobals() -> *mut PyObject;
pub fn PyEval_GetLocals() -> *mut PyObject;
pub fn PyEval_GetFrame() -> *mut ::ffi3::PyFrameObject;
pub fn Py_AddPendingCall(func: Option<extern "C" fn(arg1: *mut c_void) -> c_int>,
arg: *mut c_void) -> c_int;
pub fn Py_AddPendingCall(
func: Option<extern "C" fn(arg1: *mut c_void) -> c_int>,
arg: *mut c_void,
) -> c_int;
pub fn Py_MakePendingCalls() -> c_int;
pub fn Py_SetRecursionLimit(arg1: c_int) -> ();
pub fn Py_GetRecursionLimit() -> c_int;
@ -42,24 +47,24 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut
#[cfg(Py_3_6)]
pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) -> *mut PyObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_GetFuncName(arg1: *mut PyObject) -> *const c_char;
pub fn PyEval_GetFuncDesc(arg1: *mut PyObject) -> *const c_char;
pub fn PyEval_GetCallStats(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyEval_EvalFrame(arg1: *mut ::ffi3::PyFrameObject) -> *mut PyObject;
#[cfg(Py_3_6)]
pub fn _PyEval_EvalFrameDefault(arg1: *mut ::ffi3::PyFrameObject,
exc: c_int) -> *mut PyObject;
pub fn _PyEval_EvalFrameDefault(arg1: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject;
#[cfg(Py_3_6)]
pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int;
pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int)
-> *mut PyObject;
pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject;
pub fn PyEval_SaveThread() -> *mut PyThreadState;
pub fn PyEval_RestoreThread(arg1: *mut PyThreadState) -> ();
}
#[cfg(py_sys_config = "WITH_THREAD")]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_ThreadsInitialized() -> c_int;
pub fn PyEval_InitThreads() -> ();
pub fn PyEval_AcquireLock() -> ();
@ -68,4 +73,3 @@ pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int)
pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState) -> ();
pub fn PyEval_ReInitThreads() -> ();
}

View File

@ -1,6 +1,6 @@
use std::os::raw::{c_void, c_uchar, c_char, c_int};
use ffi3::pyport::Py_ssize_t;
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int, c_uchar, c_void};
#[repr(C)]
#[derive(Copy, Clone)]
@ -32,7 +32,10 @@ pub struct PyCodeObject {
}
impl Default for PyCodeObject {
#[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } }
#[inline]
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
}
}
/* Masks for co_flags */
@ -67,31 +70,47 @@ pub const CO_MAXBLOCKS: usize = 20;
#[cfg(Py_3_6)]
pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCode_Type: PyTypeObject;
#[cfg(Py_3_6)]
pub fn _PyCode_GetExtra(code: *mut PyObject, index: Py_ssize_t,
extra: *const *mut c_void) -> c_int;
pub fn _PyCode_GetExtra(
code: *mut PyObject,
index: Py_ssize_t,
extra: *const *mut c_void,
) -> c_int;
#[cfg(Py_3_6)]
pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t,
extra: *mut c_void) -> c_int;
pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int;
pub fn PyCode_New(arg1: c_int, arg2: c_int,
arg3: c_int, arg4: c_int,
arg5: c_int, arg6: *mut PyObject,
arg7: *mut PyObject, arg8: *mut PyObject,
arg9: *mut PyObject, arg10: *mut PyObject,
arg11: *mut PyObject, arg12: *mut PyObject,
arg13: *mut PyObject, arg14: c_int,
arg15: *mut PyObject) -> *mut PyCodeObject;
pub fn PyCode_NewEmpty(filename: *const c_char,
pub fn PyCode_New(
arg1: c_int,
arg2: c_int,
arg3: c_int,
arg4: c_int,
arg5: c_int,
arg6: *mut PyObject,
arg7: *mut PyObject,
arg8: *mut PyObject,
arg9: *mut PyObject,
arg10: *mut PyObject,
arg11: *mut PyObject,
arg12: *mut PyObject,
arg13: *mut PyObject,
arg14: c_int,
arg15: *mut PyObject,
) -> *mut PyCodeObject;
pub fn PyCode_NewEmpty(
filename: *const c_char,
funcname: *const c_char,
firstlineno: c_int) -> *mut PyCodeObject;
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int)
-> c_int;
pub fn PyCode_Optimize(code: *mut PyObject, consts: *mut PyObject,
names: *mut PyObject, lnotab: *mut PyObject)
-> *mut PyObject;
firstlineno: c_int,
) -> *mut PyCodeObject;
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int;
pub fn PyCode_Optimize(
code: *mut PyObject,
consts: *mut PyObject,
names: *mut PyObject,
lnotab: *mut PyObject,
) -> *mut PyObject;
}
#[inline]

View File

@ -1,41 +1,45 @@
use std::os::raw::{c_char, c_int};
use ffi3::object::PyObject;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCodec_Register(search_function: *mut PyObject) -> c_int;
pub fn PyCodec_KnownEncoding(encoding: *const c_char)
-> c_int;
pub fn PyCodec_Encode(object: *mut PyObject,
pub fn PyCodec_KnownEncoding(encoding: *const c_char) -> c_int;
pub fn PyCodec_Encode(
object: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
pub fn PyCodec_Decode(object: *mut PyObject,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyCodec_Decode(
object: *mut PyObject,
encoding: *const c_char,
errors: *const c_char) -> *mut PyObject;
errors: *const c_char,
) -> *mut PyObject;
pub fn PyCodec_Encoder(encoding: *const c_char) -> *mut PyObject;
pub fn PyCodec_Decoder(encoding: *const c_char) -> *mut PyObject;
pub fn PyCodec_IncrementalEncoder(encoding: *const c_char,
errors: *const c_char)
-> *mut PyObject;
pub fn PyCodec_IncrementalDecoder(encoding: *const c_char,
errors: *const c_char)
-> *mut PyObject;
pub fn PyCodec_StreamReader(encoding: *const c_char,
pub fn PyCodec_IncrementalEncoder(
encoding: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyCodec_IncrementalDecoder(
encoding: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyCodec_StreamReader(
encoding: *const c_char,
stream: *mut PyObject,
errors: *const c_char)
-> *mut PyObject;
pub fn PyCodec_StreamWriter(encoding: *const c_char,
errors: *const c_char,
) -> *mut PyObject;
pub fn PyCodec_StreamWriter(
encoding: *const c_char,
stream: *mut PyObject,
errors: *const c_char)
-> *mut PyObject;
pub fn PyCodec_RegisterError(name: *const c_char,
error: *mut PyObject) -> c_int;
errors: *const c_char,
) -> *mut PyObject;
pub fn PyCodec_RegisterError(name: *const c_char, error: *mut PyObject) -> c_int;
pub fn PyCodec_LookupError(name: *const c_char) -> *mut PyObject;
pub fn PyCodec_StrictErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_IgnoreErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_ReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_XMLCharRefReplaceErrors(exc: *mut PyObject)
-> *mut PyObject;
pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject)
-> *mut PyObject;
pub fn PyCodec_XMLCharRefReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject) -> *mut PyObject;
}

View File

@ -1,8 +1,8 @@
use std::os::raw::{c_char, c_int};
use ffi3::object::PyObject;
use ffi3::pythonrun::*;
use ffi3::code::*;
use ffi3::object::PyObject;
use ffi3::pyarena::*;
use ffi3::pythonrun::*;
use std::os::raw::{c_char, c_int};
#[repr(C)]
#[derive(Copy, Clone)]
@ -32,28 +32,36 @@ pub const FUTURE_BARRY_AS_BDFL : &str = "barry_as_FLUFL";
pub const FUTURE_GENERATOR_STOP: &str = "generator_stop";
#[cfg(not(Py_LIMITED_API))]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject;
pub fn PyAST_CompileEx(_mod: *mut _mod,
pub fn PyAST_CompileEx(
_mod: *mut _mod,
filename: *const c_char,
flags: *mut PyCompilerFlags,
optimize: c_int, arena: *mut PyArena) -> *mut PyCodeObject;
optimize: c_int,
arena: *mut PyArena,
) -> *mut PyCodeObject;
pub fn PyAST_CompileObject(_mod: *mut _mod,
pub fn PyAST_CompileObject(
_mod: *mut _mod,
filename: *mut PyObject,
flags: *mut PyCompilerFlags,
optimize: c_int, arena: *mut PyArena) -> *mut PyCodeObject;
optimize: c_int,
arena: *mut PyArena,
) -> *mut PyCodeObject;
pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures;
pub fn PyFuture_FromASTObject(_mod: *mut _mod, filename: *mut PyObject) -> *mut PyFutureFeatures;
pub fn PyFuture_FromASTObject(
_mod: *mut _mod,
filename: *mut PyObject,
) -> *mut PyFutureFeatures;
pub fn PyCompile_OpcodeStackEffect(
opcode: c_int, oparg: c_int) -> c_int;
pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int;
}
pub const Py_single_input: c_int = 256;
pub const Py_file_input: c_int = 257;
pub const Py_eval_input: c_int = 258;

View File

@ -1,7 +1,8 @@
use std::os::raw::{c_double, c_int};
use ffi3::object::*;
use std::os::raw::{c_double, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyComplex_Type: PyTypeObject;
}
@ -15,10 +16,9 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyComplex_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyComplex_FromDoubles(real: c_double,
imag: c_double) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject;
pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double;
pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double;
}

View File

@ -1,11 +1,10 @@
use std::ptr;
use std::os::raw::{c_void, c_char, c_int};
use ffi3::methodobject::PyMethodDef;
use ffi3::object::{PyObject, PyTypeObject};
use ffi3::structmember::PyMemberDef;
use ffi3::methodobject::PyMethodDef;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
pub type getter =
unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject;
pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject;
pub type setter =
unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int;
@ -28,7 +27,8 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef {
closure: ptr::null_mut(),
};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyClassMethodDescr_Type: PyTypeObject;
pub static mut PyGetSetDescr_Type: PyTypeObject;
pub static mut PyMemberDescr_Type: PyTypeObject;
@ -37,8 +37,8 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef {
pub static mut PyDictProxy_Type: PyTypeObject;
pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject;
pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject,
arg2: *mut PyMethodDef) -> *mut PyObject;
pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef)
-> *mut PyObject;
pub fn PyDescr_NewMember(arg1: *mut PyTypeObject, arg2: *mut PyMemberDef) -> *mut PyObject;
pub fn PyDescr_NewGetSet(arg1: *mut PyTypeObject, arg2: *mut PyGetSetDef) -> *mut PyObject;
pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject;
@ -46,5 +46,3 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef {
pub static mut PyProperty_Type: PyTypeObject;
}

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_char, c_int};
use ffi3::pyport::Py_ssize_t;
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyDict_Type: PyTypeObject;
pub static mut PyDictIterKey_Type: PyTypeObject;
pub static mut PyDictIterValue_Type: PyTypeObject;
@ -42,15 +43,20 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int {
(PyDictKeys_Check(op) != 0 || PyDictItems_Check(op) != 0) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyDict_New() -> *mut PyObject;
pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject;
pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject;
pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int;
pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int;
pub fn PyDict_Clear(mp: *mut PyObject) -> ();
pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t,
key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int;
pub fn PyDict_Next(
mp: *mut PyObject,
pos: *mut Py_ssize_t,
key: *mut *mut PyObject,
value: *mut *mut PyObject,
) -> c_int;
pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject;
pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject;
pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject;
@ -61,7 +67,10 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int {
pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject, _override: c_int) -> c_int;
pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject, _override: c_int) -> c_int;
pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject;
pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char,
item: *mut PyObject) -> c_int;
pub fn PyDict_SetItemString(
dp: *mut PyObject,
key: *const c_char,
item: *mut PyObject,
) -> c_int;
pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int;
}

View File

@ -1,7 +1,7 @@
use ffi3::object::PyTypeObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyEnum_Type: PyTypeObject;
pub static mut PyReversed_Type: PyTypeObject;
}

View File

@ -1,13 +1,24 @@
use std::os::raw::c_int;
use ffi3::object::PyObject;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyEval_EvalCode(arg1: *mut PyObject, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
pub fn PyEval_EvalCodeEx(co: *mut PyObject, globals: *mut PyObject,
locals: *mut PyObject, args: *mut *mut PyObject,
argc: c_int, kwds: *mut *mut PyObject,
kwdc: c_int, defs: *mut *mut PyObject,
defc: c_int, kwdefs: *mut PyObject,
closure: *mut PyObject) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyEval_EvalCode(
arg1: *mut PyObject,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;
pub fn PyEval_EvalCodeEx(
co: *mut PyObject,
globals: *mut PyObject,
locals: *mut PyObject,
args: *mut *mut PyObject,
argc: c_int,
kwds: *mut *mut PyObject,
kwdc: c_int,
defs: *mut *mut PyObject,
defc: c_int,
kwdefs: *mut PyObject,
closure: *mut PyObject,
) -> *mut PyObject;
}

View File

@ -1,25 +1,26 @@
use std::os::raw::{c_char, c_int};
use ffi3::object::PyObject;
use std::os::raw::{c_char, c_int};
pub const PY_STDIOTEXTMODE: &str = "b";
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyFile_FromFd(arg1: c_int, arg2: *const c_char,
arg3: *const c_char, arg4: c_int,
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFile_FromFd(
arg1: c_int,
arg2: *const c_char,
arg3: *const c_char,
arg4: c_int,
arg5: *const c_char,
arg6: *const c_char,
arg7: *const c_char, arg8: c_int)
-> *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_WriteString(arg1: *const c_char,
arg2: *mut PyObject) -> c_int;
arg7: *const c_char,
arg8: c_int,
) -> *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_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int;
pub static mut Py_FileSystemDefaultEncoding: *const c_char;
#[cfg(Py_3_6)]
pub static mut Py_FileSystemDefaultEncodeErrors: *const c_char;
pub static mut Py_HasFileSystemDefaultEncoding: c_int;
}

View File

@ -1,7 +1,8 @@
use std::os::raw::{c_int, c_double};
use ffi3::object::*;
use std::os::raw::{c_double, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFloat_Type: PyTypeObject;
}
@ -15,7 +16,8 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyFloat_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFloat_GetMax() -> c_double;
pub fn PyFloat_GetMin() -> c_double;
pub fn PyFloat_GetInfo() -> *mut PyObject;
@ -23,4 +25,3 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int {
pub fn PyFloat_FromDouble(arg1: c_double) -> *mut PyObject;
pub fn PyFloat_AsDouble(arg1: *mut PyObject) -> c_double;
}

View File

@ -1,7 +1,7 @@
use std::os::raw::{c_char, c_int};
use ffi3::object::*;
use ffi3::code::{PyCodeObject, CO_MAXBLOCKS};
use ffi3::object::*;
use ffi3::pystate::PyThreadState;
use std::os::raw::{c_char, c_int};
#[repr(C)]
#[derive(Copy, Clone)]
@ -42,10 +42,11 @@ pub struct PyFrameObject {
pub f_iblock: c_int, /* index in f_blockstack */
pub f_executing: c_char, /* whether the frame is still executing */
pub f_blockstack: [PyTryBlock; CO_MAXBLOCKS], /* for try and loop blocks */
pub f_localsplus: [*mut PyObject; 1] /* locals+stack, dynamically sized */
pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyFrame_Type: PyTypeObject;
}
@ -54,11 +55,21 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyFrame_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject,
globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyFrame_New(
tstate: *mut PyThreadState,
code: *mut PyCodeObject,
globals: *mut PyObject,
locals: *mut PyObject,
) -> *mut PyFrameObject;
pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int) -> ();
pub fn PyFrame_BlockSetup(
f: *mut PyFrameObject,
_type: c_int,
handler: c_int,
level: c_int,
) -> ();
pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;
pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> ();

View File

@ -1,7 +1,7 @@
use std::os::raw::c_int;
use ffi3::pyport::Py_ssize_t;
use ffi3::object::*;
use ffi3::frameobject::PyFrameObject;
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[repr(C)]
#[derive(Copy, Clone)]
@ -15,10 +15,11 @@ pub struct PyGenObject {
pub gi_frame: *mut PyFrameObject,
pub gi_running: c_int,
pub gi_code: *mut PyObject,
pub gi_weakreflist: *mut PyObject
pub gi_weakreflist: *mut PyObject,
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyGen_Type: PyTypeObject;
}
@ -32,12 +33,14 @@ pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyGen_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject;
pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCoro_Type: PyTypeObject;
}
@ -46,7 +49,8 @@ pub unsafe fn PyCoro_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &mut PyCoro_Type)
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut _PyCoroWrapper_Type: PyTypeObject;
}
@ -56,7 +60,8 @@ pub unsafe fn PyCoroWrapper_Check(op: *mut PyObject) -> c_int {
}
#[cfg(Py_3_6)]
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyAsyncGen_Type: PyTypeObject;
}

View File

@ -1,68 +1,70 @@
use std::os::raw::{c_char, c_int, c_long};
use ffi3::object::PyObject;
use std::os::raw::{c_char, c_int, c_long};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyImport_GetMagicNumber() -> c_long;
pub fn PyImport_GetMagicTag() -> *const c_char;
pub fn PyImport_ExecCodeModule(name: *const c_char,
co: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ExecCodeModuleEx(name: *const c_char,
pub fn PyImport_ExecCodeModule(name: *const c_char, co: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ExecCodeModuleEx(
name: *const c_char,
co: *mut PyObject,
pathname: *const c_char)
-> *mut PyObject;
pub fn PyImport_ExecCodeModuleWithPathnames(name: *const c_char,
pathname: *const c_char,
) -> *mut PyObject;
pub fn PyImport_ExecCodeModuleWithPathnames(
name: *const c_char,
co: *mut PyObject,
pathname:
*const c_char,
cpathname:
*const c_char)
-> *mut PyObject;
pub fn PyImport_ExecCodeModuleObject(name: *mut PyObject,
pathname: *const c_char,
cpathname: *const c_char,
) -> *mut PyObject;
pub fn PyImport_ExecCodeModuleObject(
name: *mut PyObject,
co: *mut PyObject,
pathname: *mut PyObject,
cpathname: *mut PyObject)
-> *mut PyObject;
cpathname: *mut PyObject,
) -> *mut PyObject;
pub fn PyImport_GetModuleDict() -> *mut PyObject;
pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject;
pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject;
pub fn PyImport_ImportModule(name: *const c_char)
-> *mut PyObject;
pub fn PyImport_ImportModuleNoBlock(name: *const c_char)
-> *mut PyObject;
pub fn PyImport_ImportModuleLevel(name: *const c_char,
pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject;
pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject;
pub fn PyImport_ImportModuleLevel(
name: *const c_char,
globals: *mut PyObject,
locals: *mut PyObject,
fromlist: *mut PyObject,
level: c_int) -> *mut PyObject;
pub fn PyImport_ImportModuleLevelObject(name: *mut PyObject,
level: c_int,
) -> *mut PyObject;
pub fn PyImport_ImportModuleLevelObject(
name: *mut PyObject,
globals: *mut PyObject,
locals: *mut PyObject,
fromlist: *mut PyObject,
level: c_int)
-> *mut PyObject;
level: c_int,
) -> *mut PyObject;
}
#[inline]
pub unsafe fn PyImport_ImportModuleEx(name: *const c_char,
pub unsafe fn PyImport_ImportModuleEx(
name: *const c_char,
globals: *mut PyObject,
locals: *mut PyObject,
fromlist: *mut PyObject)
-> *mut PyObject {
fromlist: *mut PyObject,
) -> *mut PyObject {
PyImport_ImportModuleLevel(name, globals, locals, fromlist, 0)
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject;
pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject;
pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject;
pub fn PyImport_Cleanup() -> ();
pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject)
-> c_int;
pub fn PyImport_ImportFrozenModule(name: *const c_char)
-> c_int;
pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) -> c_int;
pub fn PyImport_ImportFrozenModule(name: *const c_char) -> c_int;
pub fn PyImport_AppendInittab(name: *const c_char,
initfunc: Option<extern "C" fn() -> *mut PyObject>)
-> c_int;
pub fn PyImport_AppendInittab(
name: *const c_char,
initfunc: Option<extern "C" fn() -> *mut PyObject>,
) -> c_int;
}

View File

@ -1,8 +1,8 @@
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyOS_InterruptOccurred() -> c_int;
pub fn PyOS_InitInterrupts() -> ();
pub fn PyOS_AfterFork() -> ();
}

View File

@ -1,13 +1,13 @@
use std::os::raw::c_int;
use ffi3::object::*;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PySeqIter_Type: PyTypeObject;
pub static mut PyCallIter_Type: PyTypeObject;
pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject;
pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject)
-> *mut PyObject;
pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject;
}
#[inline(always)]
@ -19,5 +19,3 @@ pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int {
pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyCallIter_Type) as c_int
}

View File

@ -1,8 +1,9 @@
use std::os::raw::c_int;
use ffi3::pyport::Py_ssize_t;
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::c_int;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyList_Type: PyTypeObject;
pub static mut PyListIter_Type: PyTypeObject;
pub static mut PyListRevIter_Type: PyTypeObject;
@ -18,17 +19,25 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyList_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject;
pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t;
pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int;
pub fn PyList_Insert(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int;
pub fn PyList_Append(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int;
pub fn PyList_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: Py_ssize_t) -> *mut PyObject;
pub fn PyList_SetSlice(arg1: *mut PyObject, arg2: Py_ssize_t,
arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int;
pub fn PyList_GetSlice(
arg1: *mut PyObject,
arg2: Py_ssize_t,
arg3: Py_ssize_t,
) -> *mut PyObject;
pub fn PyList_SetSlice(
arg1: *mut PyObject,
arg2: Py_ssize_t,
arg3: Py_ssize_t,
arg4: *mut PyObject,
) -> c_int;
pub fn PyList_Sort(arg1: *mut PyObject) -> c_int;
pub fn PyList_Reverse(arg1: *mut PyObject) -> c_int;
pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject;

View File

@ -1,13 +1,14 @@
use libc::size_t;
use std::os::raw::{
c_void, c_char, c_int, c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_uchar
};
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use libc::size_t;
use std::os::raw::{
c_char, c_double, c_int, c_long, c_longlong, c_uchar, c_ulong, c_ulonglong, c_void,
};
pub enum PyLongObject {}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyLong_Type: PyTypeObject;
}
@ -21,16 +22,15 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyLong_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyLong_FromLong(arg1: c_long) -> *mut PyObject;
pub fn PyLong_FromUnsignedLong(arg1: c_ulong) -> *mut PyObject;
pub fn PyLong_FromSize_t(arg1: size_t) -> *mut PyObject;
pub fn PyLong_FromSsize_t(arg1: Py_ssize_t) -> *mut PyObject;
pub fn PyLong_FromDouble(arg1: c_double) -> *mut PyObject;
pub fn PyLong_AsLong(arg1: *mut PyObject) -> c_long;
pub fn PyLong_AsLongAndOverflow(arg1: *mut PyObject,
arg2: *mut c_int)
-> c_long;
pub fn PyLong_AsLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_long;
pub fn PyLong_AsSsize_t(arg1: *mut PyObject) -> Py_ssize_t;
pub fn PyLong_AsSize_t(arg1: *mut PyObject) -> size_t;
pub fn PyLong_AsUnsignedLong(arg1: *mut PyObject) -> c_ulong;
@ -40,25 +40,18 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int {
pub fn PyLong_FromVoidPtr(arg1: *mut c_void) -> *mut PyObject;
pub fn PyLong_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void;
pub fn PyLong_FromLongLong(arg1: c_longlong) -> *mut PyObject;
pub fn PyLong_FromUnsignedLongLong(arg1: c_ulonglong)
-> *mut PyObject;
pub fn PyLong_FromUnsignedLongLong(arg1: c_ulonglong) -> *mut PyObject;
pub fn PyLong_AsLongLong(arg1: *mut PyObject) -> c_longlong;
pub fn PyLong_AsUnsignedLongLong(arg1: *mut PyObject)
-> c_ulonglong;
pub fn PyLong_AsUnsignedLongLongMask(arg1: *mut PyObject)
-> c_ulonglong;
pub fn PyLong_AsLongLongAndOverflow(arg1: *mut PyObject,
arg2: *mut c_int)
-> c_longlong;
pub fn PyLong_FromString(arg1: *const c_char,
pub fn PyLong_AsUnsignedLongLong(arg1: *mut PyObject) -> c_ulonglong;
pub fn PyLong_AsUnsignedLongLongMask(arg1: *mut PyObject) -> c_ulonglong;
pub fn PyLong_AsLongLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_longlong;
pub fn PyLong_FromString(
arg1: *const c_char,
arg2: *mut *mut c_char,
arg3: c_int) -> *mut PyObject;
pub fn PyOS_strtoul(arg1: *const c_char,
arg2: *mut *mut c_char, arg3: c_int)
-> c_ulong;
pub fn PyOS_strtol(arg1: *const c_char,
arg2: *mut *mut c_char, arg3: c_int)
-> c_long;
arg3: c_int,
) -> *mut PyObject;
pub fn PyOS_strtoul(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> c_ulong;
pub fn PyOS_strtol(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> c_long;
}
#[cfg(not(Py_LIMITED_API))]

View File

@ -1,8 +1,9 @@
use std::os::raw::{c_int, c_char};
use ffi3::pyport::Py_ssize_t;
use ffi3::object::*;
use ffi3::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyMemoryView_Type: PyTypeObject;
}
@ -11,12 +12,17 @@ pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int {
(Py_TYPE(op) == &mut PyMemoryView_Type) as c_int
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject;
pub fn PyMemoryView_FromMemory(mem: *mut c_char, size: Py_ssize_t,
flags: c_int) -> *mut PyObject;
pub fn PyMemoryView_GetContiguous(base: *mut PyObject,
pub fn PyMemoryView_FromMemory(
mem: *mut c_char,
size: Py_ssize_t,
flags: c_int,
) -> *mut PyObject;
pub fn PyMemoryView_GetContiguous(
base: *mut PyObject,
buffertype: c_int,
order: c_char) -> *mut PyObject;
order: c_char,
) -> *mut PyObject;
}

View File

@ -1,8 +1,9 @@
use ffi3::object::{PyObject, PyTypeObject, Py_TYPE};
use std::os::raw::{c_char, c_int};
use std::{mem, ptr};
use ffi3::object::{PyObject, PyTypeObject, Py_TYPE};
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyCFunction_Type: PyTypeObject;
}
@ -15,27 +16,29 @@ pub type PyCFunction =
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject;
#[cfg(all(Py_3_6, not(Py_LIMITED_API)))]
pub type _PyCFunctionFast =
unsafe extern "C" fn (slf: *mut PyObject,
pub type _PyCFunctionFast = unsafe extern "C" fn(
slf: *mut PyObject,
args: *mut *mut PyObject,
nargs: ::ffi3::pyport::Py_ssize_t,
kwnames: *mut PyObject) -> *mut PyObject;
kwnames: *mut PyObject,
) -> *mut PyObject;
pub type PyCFunctionWithKeywords =
unsafe extern "C" fn (slf: *mut PyObject,
args: *mut PyObject,
kwds: *mut PyObject) -> *mut PyObject;
unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject)
-> *mut PyObject;
pub type PyNoArgsFunction =
unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject;
pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option<PyCFunction>;
pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject;
pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int;
pub fn PyCFunction_Call(f: *mut PyObject,
pub fn PyCFunction_Call(
f: *mut PyObject,
args: *mut PyObject,
kwds: *mut PyObject) -> *mut PyObject;
kwds: *mut PyObject,
) -> *mut PyObject;
}
#[repr(C)]
@ -55,7 +58,9 @@ pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef {
};
impl Default for PyMethodDef {
fn default() -> PyMethodDef { unsafe { mem::zeroed() } }
fn default() -> PyMethodDef {
unsafe { mem::zeroed() }
}
}
#[inline(always)]
@ -63,9 +68,13 @@ pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut
PyCFunction_NewEx(ml, slf, ptr::null_mut())
}
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
pub fn PyCFunction_NewEx(arg1: *mut PyMethodDef, arg2: *mut PyObject,
arg3: *mut PyObject) -> *mut PyObject;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCFunction_NewEx(
arg1: *mut PyMethodDef,
arg2: *mut PyObject,
arg3: *mut PyObject,
) -> *mut PyObject;
}
/* Flag passed to newmethodobject */
@ -91,7 +100,7 @@ pub const METH_COEXIST : c_int = 0x0040;
#[cfg(all(Py_3_6, not(Py_LIMITED_API)))]
pub const METHOD_FASTCALL: c_int = 0x0080;
#[cfg_attr(windows, link(name="pythonXY"))] extern "C" {
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub fn PyCFunction_ClearFreeList() -> c_int;
}

Some files were not shown because too many files have changed in this diff Show More