commit
9f2afbc3cc
11
.travis.yml
11
.travis.yml
|
@ -10,28 +10,21 @@ cache:
|
|||
|
||||
matrix:
|
||||
include:
|
||||
- name: Python 2.7
|
||||
python: "2.7"
|
||||
env: FEATURES=python2
|
||||
- name: Python 3.5
|
||||
python: "3.5"
|
||||
env: FEATURES="python3 test-doc"
|
||||
env: FEATURES="test-doc"
|
||||
- name: Python 3.6
|
||||
python: "3.6"
|
||||
env: FEATURES=python3
|
||||
- name: Python 3.7
|
||||
python: "3.7"
|
||||
env: FEATURES=python3
|
||||
- name: Python 3.8-dev
|
||||
python: "3.8-dev"
|
||||
env: FEATURES=python3
|
||||
- name: Minimum nightly
|
||||
python: "3.7"
|
||||
# Keep this synced up with build.rs
|
||||
env: FEATURES=python3 TRAVIS_RUST_VERSION=nightly-2019-02-07
|
||||
env: TRAVIS_RUST_VERSION=nightly-2019-02-07
|
||||
allow_failures:
|
||||
- python: "3.8-dev"
|
||||
env: FEATURES=python3
|
||||
|
||||
env:
|
||||
global:
|
||||
|
|
|
@ -39,10 +39,7 @@ version_check = "0.1.5"
|
|||
[features]
|
||||
default = []
|
||||
|
||||
# Use this feature when building python2 binding.
|
||||
python2 = []
|
||||
|
||||
# Use this feature when building python3 binding.
|
||||
# this is no longer needed internally, but setuptools-rust assumes this feature
|
||||
python3 = []
|
||||
|
||||
# Use this feature when building an extension module.
|
||||
|
|
|
@ -16,7 +16,7 @@ A comparison with rust-cpython can be found [in the guide](https://pyo3.rs/maste
|
|||
|
||||
## Usage
|
||||
|
||||
PyO3 supports python 2.7 as well as python 3.5 and up. The minimum required rust version is 1.34.0-nightly 2019-02-06.
|
||||
PyO3 supports python 3.5 and up. The minimum required rust version is 1.34.0-nightly 2019-02-06.
|
||||
|
||||
You can either write a native python module in rust or use python from a rust binary.
|
||||
|
||||
|
|
|
@ -2,12 +2,8 @@ version: 0.2.{build}
|
|||
environment:
|
||||
TARGET: x86_64-pc-windows-msvc
|
||||
matrix:
|
||||
- PYTHON: "C:/Python27-x64"
|
||||
FEATURES: python2
|
||||
- PYTHON: "C:/Python35-x64"
|
||||
FEATURES: python3
|
||||
- PYTHON: "C:/Python36-x64"
|
||||
FEATURES: python3
|
||||
|
||||
install:
|
||||
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
|
||||
|
@ -21,9 +17,9 @@ install:
|
|||
- set RUST_BACKTRACE=1
|
||||
|
||||
build_script:
|
||||
- cargo build --verbose --features %FEATURES%
|
||||
- cargo build --verbose
|
||||
|
||||
test_script:
|
||||
- cargo test --verbose --features %FEATURES%
|
||||
- cargo test --verbose
|
||||
- pip install setuptools-rust pytest pytest-benchmark
|
||||
- cd examples/word-count && python setup.py install && pytest -v tests
|
||||
|
|
15
build.rs
15
build.rs
|
@ -7,6 +7,7 @@ use std::fs::File;
|
|||
use std::io;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use version_check::{is_min_date, is_min_version, supports_features};
|
||||
|
@ -482,11 +483,10 @@ fn configure(interpreter_version: &PythonVersion, lines: Vec<String>) -> Result<
|
|||
println!("cargo:rustc-cfg=Py_3_{}", i);
|
||||
flags += format!("CFG_Py_3_{},", i).as_ref();
|
||||
}
|
||||
println!("cargo:rustc-cfg=Py_3");
|
||||
}
|
||||
} else {
|
||||
println!("cargo:rustc-cfg=Py_2");
|
||||
flags += format!("CFG_Py_2,").as_ref();
|
||||
// fail PYTHON_SYS_EXECUTABLE=python2 cargo ...
|
||||
return Err("Python 2 is not supported".to_string());
|
||||
}
|
||||
return Ok(flags);
|
||||
}
|
||||
|
@ -580,7 +580,14 @@ fn main() -> Result<(), String> {
|
|||
find_interpreter_and_get_config()?
|
||||
};
|
||||
|
||||
let flags = configure(&interpreter_version, lines)?;
|
||||
let flags;
|
||||
match configure(&interpreter_version, lines) {
|
||||
Ok(val) => flags = val,
|
||||
Err(err) => {
|
||||
eprintln!("{}", err);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// WITH_THREAD is always on for 3.7
|
||||
if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 {
|
||||
|
|
|
@ -20,10 +20,6 @@ class PyTest(TestCommand):
|
|||
def get_py_version_cfgs():
|
||||
# For now each Cfg Py_3_X flag is interpreted as "at least 3.X"
|
||||
version = sys.version_info[0:2]
|
||||
|
||||
if version[0] == 2:
|
||||
return ["--cfg=Py_2"]
|
||||
|
||||
py3_min = 5
|
||||
out_cfg = []
|
||||
for minor in range(py3_min, version[1] + 1):
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[tox]
|
||||
envlist = py27,
|
||||
py35,
|
||||
envlist = py35,
|
||||
py36,
|
||||
py37,
|
||||
minversion = 2.9.0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# word-count
|
||||
|
||||
Demonstrates searching for a file in plain python, with rust singlethreaded and with rust multithreaded.
|
||||
Demonstrates searching for a file in plain python, with rust singlethreaded and with rust multithreaded.
|
||||
|
||||
## Build
|
||||
|
||||
|
@ -35,7 +35,7 @@ pytest -v tests
|
|||
|
||||
## Testing
|
||||
|
||||
To test python 2.7, 3.5, 3.6 and 3.7, install tox globally and run
|
||||
To test python 3.5, 3.6 and 3.7, install tox globally and run
|
||||
|
||||
```shell
|
||||
tox
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[tox]
|
||||
envlist = py27,
|
||||
py35,
|
||||
envlist = py35,
|
||||
py36,
|
||||
py37,
|
||||
minversion = 3.4.0
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Python version
|
||||
|
||||
PyO3 uses a build script to determine the python version and set the correct linker arguments. By default it uses the `python3` executable. With the `python2` feature it uses the `python2` executable. You can override the python interpreter by setting `PYTHON_SYS_EXECUTABLE`.
|
||||
PyO3 uses a build script to determine the python version and set the correct linker arguments. By default it uses the `python3` executable. You can override the python interpreter by setting `PYTHON_SYS_EXECUTABLE`, e.g., `PYTHON_SYS_EXECUTABLE=python3.6`.
|
||||
|
||||
## Linking
|
||||
|
||||
|
|
|
@ -503,18 +503,10 @@ Each methods corresponds to python's `self.attr`, `self.attr = value` and `del s
|
|||
* `fn __str__(&self) -> PyResult<impl ToPyObject<ObjectType=PyString>>`
|
||||
|
||||
Possible return types for `__str__` and `__repr__` are `PyResult<String>` or `PyResult<PyString>`.
|
||||
In Python 2.7, Unicode strings returned by `__str__` and `__repr__` will be converted to byte strings
|
||||
by the Python runtime, which results in an exception if the string contains non-ASCII characters.
|
||||
|
||||
* `fn __bytes__(&self) -> PyResult<PyBytes>`
|
||||
|
||||
On Python 3.x, provides the conversion to `bytes`.
|
||||
On Python 2.7, `__bytes__` is allowed but has no effect.
|
||||
|
||||
* `fn __unicode__(&self) -> PyResult<PyUnicode>`
|
||||
|
||||
On Python 2.7, provides the conversion to `unicode`.
|
||||
On Python 3.x, `__unicode__` is allowed but has no effect.
|
||||
Provides the conversion to `bytes`.
|
||||
|
||||
* `fn __format__(&self, format_spec: &str) -> PyResult<impl ToPyObject<ObjectType=PyString>>`
|
||||
|
||||
|
@ -540,9 +532,7 @@ Each methods corresponds to python's `self.attr`, `self.attr = value` and `del s
|
|||
|
||||
* `fn __bool__(&self) -> PyResult<bool>`
|
||||
|
||||
Determines the "truthiness" of the object.
|
||||
This method works for both python 3 and python 2,
|
||||
even on Python 2.7 where the Python spelling was `__nonzero__`.
|
||||
Determines the "truthyness" of the object.
|
||||
|
||||
### Garbage Collector Integration
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ A comparison with rust-cpython can be found [in the guide](https://pyo3.rs/maste
|
|||
|
||||
## Usage
|
||||
|
||||
PyO3 supports python 2.7 as well as python 3.5 and up. The minimum required rust version is 1.30.0-nightly 2018-08-18.
|
||||
PyO3 supports python 3.5 and up. The minimum required rust version is 1.34.0-nightly 2019-02-06.
|
||||
|
||||
You can either write a native python module in rust or use python from a rust binary.
|
||||
|
||||
|
|
|
@ -56,35 +56,31 @@ In python, modules are first class objects. This means can store them as values
|
|||
# extern crate pyo3;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::{wrap_pyfunction, wrap_pymodule};
|
||||
use pyo3::types::PyDict;
|
||||
use pyo3::types::IntoPyDict;
|
||||
|
||||
#[pyfunction]
|
||||
#[cfg(Py_3)]
|
||||
fn subfunction() -> String {
|
||||
"Subfunction".to_string()
|
||||
}
|
||||
|
||||
#[pymodule]
|
||||
#[cfg(Py_3)]
|
||||
fn submodule(_py: Python, module: &PyModule) -> PyResult<()> {
|
||||
module.add_wrapped(wrap_pyfunction!(subfunction))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[pymodule]
|
||||
#[cfg(Py_3)]
|
||||
fn supermodule(_py: Python, module: &PyModule) -> PyResult<()> {
|
||||
module.add_wrapped(wrap_pymodule!(submodule))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
fn nested_call() {
|
||||
let gil = GILGuard::acquire();
|
||||
let py = gil.python();
|
||||
let supermodule = wrap_pymodule!(supermodule)(py);
|
||||
let ctx = [("supermodule", supermodule)].into_py_dict(py);
|
||||
|
||||
py.run("assert supermodule.submodule.subfuntion() == 'Subfunction'", None, Some(&ctx)).unwrap();
|
||||
py.run("assert supermodule.submodule.subfunction() == 'Subfunction'", None, Some(&ctx)).unwrap();
|
||||
}
|
||||
```
|
||||
|
|
|
@ -60,11 +60,6 @@ pub const OBJECT: Proto = Proto {
|
|||
pyres: true,
|
||||
proto: "pyo3::class::basic::PyObjectBytesProtocol",
|
||||
},
|
||||
MethodProto::Unary {
|
||||
name: "__unicode__",
|
||||
pyres: true,
|
||||
proto: "pyo3::class::basic::PyObjectUnicodeProtocol",
|
||||
},
|
||||
MethodProto::Unary {
|
||||
name: "__bool__",
|
||||
pyres: false,
|
||||
|
|
|
@ -14,7 +14,7 @@ mod pymethod;
|
|||
mod pyproto;
|
||||
mod utils;
|
||||
|
||||
pub use module::{add_fn_to_module, process_functions_in_module, py2_init, py3_init};
|
||||
pub use module::{add_fn_to_module, process_functions_in_module, py_init};
|
||||
pub use pyclass::{build_py_class, PyClassArgs};
|
||||
pub use pyfunction::PyFunctionAttr;
|
||||
pub use pyimpl::{build_py_methods, impl_methods};
|
||||
|
|
|
@ -13,7 +13,7 @@ use syn::Ident;
|
|||
|
||||
/// Generates the function that is called by the python interpreter to initialize the native
|
||||
/// module
|
||||
pub fn py3_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream {
|
||||
pub fn py_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream {
|
||||
let cb_name = Ident::new(&format!("PyInit_{}", name), Span::call_site());
|
||||
|
||||
quote! {
|
||||
|
@ -27,18 +27,6 @@ pub fn py3_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn py2_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream {
|
||||
let cb_name = Ident::new(&format!("init{}", name), Span::call_site());
|
||||
|
||||
quote! {
|
||||
#[no_mangle]
|
||||
#[allow(non_snake_case)]
|
||||
pub unsafe extern "C" fn #cb_name() {
|
||||
pyo3::derive_utils::make_module(concat!(stringify!(#name), "\0"), #doc, #fnname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds and takes care of the #[pyfn(...)] in `#[pymodule]`
|
||||
pub fn process_functions_in_module(func: &mut syn::ItemFn) {
|
||||
let mut stmts: Vec<syn::Stmt> = Vec::new();
|
||||
|
|
|
@ -7,36 +7,15 @@ use proc_macro::TokenStream;
|
|||
use proc_macro2::Span;
|
||||
use pyo3_derive_backend::{
|
||||
add_fn_to_module, build_py_class, build_py_methods, build_py_proto, get_doc,
|
||||
process_functions_in_module, py2_init, py3_init, PyClassArgs, PyFunctionAttr,
|
||||
process_functions_in_module, py_init, PyClassArgs, PyFunctionAttr,
|
||||
};
|
||||
use quote::quote;
|
||||
use syn::parse_macro_input;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn pymodule2(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as syn::ItemFn);
|
||||
|
||||
let modname = if attr.is_empty() {
|
||||
ast.ident.clone()
|
||||
} else {
|
||||
parse_macro_input!(attr as syn::Ident)
|
||||
};
|
||||
|
||||
process_functions_in_module(&mut ast);
|
||||
|
||||
let expanded = py2_init(&ast.ident, &modname, get_doc(&ast.attrs, false));
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
#expanded
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Internally, this proc macro create a new c function called `PyInit_{my_module}`
|
||||
/// that then calls the init function you provided
|
||||
#[proc_macro_attribute]
|
||||
pub fn pymodule3(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
pub fn pymodule(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut ast = parse_macro_input!(input as syn::ItemFn);
|
||||
|
||||
let modname = if attr.is_empty() {
|
||||
|
@ -47,7 +26,7 @@ pub fn pymodule3(attr: TokenStream, input: TokenStream) -> TokenStream {
|
|||
|
||||
process_functions_in_module(&mut ast);
|
||||
|
||||
let expanded = py3_init(&ast.ident, &modname, get_doc(&ast.attrs, false));
|
||||
let expanded = py_init(&ast.ident, &modname, get_doc(&ast.attrs, false));
|
||||
|
||||
quote!(
|
||||
#ast
|
||||
|
|
|
@ -289,11 +289,7 @@ impl PyBuffer {
|
|||
#[inline]
|
||||
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, b'C' as libc::c_char) != 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,11 +297,7 @@ impl PyBuffer {
|
|||
#[inline]
|
||||
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, b'F' as libc::c_char) != 0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -713,7 +705,6 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)] // array.array doesn't implement the buffer protocol in python 2.7
|
||||
fn test_array_buffer() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
|
|
@ -99,14 +99,6 @@ pub trait PyObjectProtocol<'p>: PyTypeInfo {
|
|||
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>,
|
||||
|
@ -137,10 +129,6 @@ pub trait PyObjectReprProtocol<'p>: PyObjectProtocol<'p> {
|
|||
type Success: IntoPyObject;
|
||||
type Result: Into<PyResult<Self::Success>>;
|
||||
}
|
||||
pub trait PyObjectUnicodeProtocol<'p>: PyObjectProtocol<'p> {
|
||||
type Success: IntoPyObject;
|
||||
type Result: Into<PyResult<Self::Success>>;
|
||||
}
|
||||
pub trait PyObjectFormatProtocol<'p>: PyObjectProtocol<'p> {
|
||||
type Format: FromPyObject<'p>;
|
||||
type Success: IntoPyObject;
|
||||
|
|
|
@ -627,17 +627,10 @@ pub trait PyNumberProtocolImpl: PyObjectProtocolImpl {
|
|||
}
|
||||
fn tp_as_number() -> Option<ffi::PyNumberMethods> {
|
||||
if let Some(nb_bool) = <Self as PyObjectProtocolImpl>::nb_bool_fn() {
|
||||
#[cfg(Py_3)]
|
||||
let meth = ffi::PyNumberMethods {
|
||||
nb_bool: Some(nb_bool),
|
||||
..ffi::PyNumberMethods_INIT
|
||||
};
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
let meth = ffi::PyNumberMethods {
|
||||
nb_nonzero: Some(nb_bool),
|
||||
..ffi::PyNumberMethods_INIT
|
||||
};
|
||||
Some(meth)
|
||||
} else {
|
||||
None
|
||||
|
@ -651,7 +644,6 @@ impl<'p, T> PyNumberProtocolImpl for T
|
|||
where
|
||||
T: PyNumberProtocol<'p>,
|
||||
{
|
||||
#[cfg(Py_3)]
|
||||
fn tp_as_number() -> Option<ffi::PyNumberMethods> {
|
||||
Some(ffi::PyNumberMethods {
|
||||
nb_add: Self::nb_add(),
|
||||
|
@ -692,50 +684,6 @@ where
|
|||
nb_inplace_matrix_multiply: Self::nb_inplace_matrix_multiply(),
|
||||
})
|
||||
}
|
||||
#[cfg(not(Py_3))]
|
||||
fn tp_as_number() -> Option<ffi::PyNumberMethods> {
|
||||
Some(ffi::PyNumberMethods {
|
||||
nb_add: Self::nb_add(),
|
||||
nb_subtract: Self::nb_subtract(),
|
||||
nb_multiply: Self::nb_multiply(),
|
||||
nb_remainder: Self::nb_remainder(),
|
||||
nb_divmod: Self::nb_divmod(),
|
||||
nb_power: Self::nb_power(),
|
||||
nb_negative: Self::nb_negative(),
|
||||
nb_positive: Self::nb_positive(),
|
||||
nb_absolute: Self::nb_absolute(),
|
||||
nb_nonzero: <Self as PyObjectProtocolImpl>::nb_bool_fn(),
|
||||
nb_invert: Self::nb_invert(),
|
||||
nb_lshift: Self::nb_lshift(),
|
||||
nb_rshift: Self::nb_rshift(),
|
||||
nb_and: Self::nb_and(),
|
||||
nb_xor: Self::nb_xor(),
|
||||
nb_or: Self::nb_or(),
|
||||
nb_c_int: Self::nb_int(),
|
||||
nb_float: Self::nb_float(),
|
||||
nb_inplace_add: Self::nb_inplace_add(),
|
||||
nb_inplace_subtract: Self::nb_inplace_subtract(),
|
||||
nb_inplace_multiply: Self::nb_inplace_multiply(),
|
||||
nb_inplace_remainder: Self::nb_inplace_remainder(),
|
||||
nb_inplace_power: Self::nb_inplace_power(),
|
||||
nb_inplace_lshift: Self::nb_inplace_lshift(),
|
||||
nb_inplace_rshift: Self::nb_inplace_rshift(),
|
||||
nb_inplace_and: Self::nb_inplace_and(),
|
||||
nb_inplace_xor: Self::nb_inplace_xor(),
|
||||
nb_inplace_or: Self::nb_inplace_or(),
|
||||
nb_floor_divide: Self::nb_floor_divide(),
|
||||
nb_true_divide: Self::nb_true_divide(),
|
||||
nb_inplace_floor_divide: Self::nb_inplace_floor_divide(),
|
||||
nb_inplace_true_divide: Self::nb_inplace_true_divide(),
|
||||
nb_index: Self::nb_index(),
|
||||
nb_coerce: None,
|
||||
nb_divide: None,
|
||||
nb_hex: None,
|
||||
nb_inplace_divide: None,
|
||||
nb_long: None,
|
||||
nb_oct: None,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn methods() -> Vec<PyMethodDef> {
|
||||
|
|
|
@ -88,7 +88,6 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> {
|
|||
type Result: Into<PyResult<Self::Success>>;
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[doc(hidden)]
|
||||
pub trait PyAsyncProtocolImpl {
|
||||
fn tp_as_async() -> Option<ffi::PyAsyncMethods> {
|
||||
|
@ -100,10 +99,8 @@ pub trait PyAsyncProtocolImpl {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
impl<T> PyAsyncProtocolImpl for T {}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
impl<'p, T> PyAsyncProtocolImpl for T
|
||||
where
|
||||
T: PyAsyncProtocol<'p>,
|
||||
|
@ -186,7 +183,6 @@ trait PyAsyncAnextProtocolImpl {
|
|||
|
||||
impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p> {}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
mod anext {
|
||||
use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl};
|
||||
use crate::callback::CallbackConverter;
|
||||
|
|
|
@ -141,7 +141,6 @@ where
|
|||
T: PySequenceProtocol<'p>,
|
||||
{
|
||||
fn tp_as_sequence() -> Option<ffi::PySequenceMethods> {
|
||||
#[cfg(Py_3)]
|
||||
return Some(ffi::PySequenceMethods {
|
||||
sq_length: Self::sq_length(),
|
||||
sq_concat: Self::sq_concat(),
|
||||
|
@ -154,20 +153,6 @@ where
|
|||
sq_inplace_concat: Self::sq_inplace_concat(),
|
||||
sq_inplace_repeat: Self::sq_inplace_repeat(),
|
||||
});
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
return Some(ffi::PySequenceMethods {
|
||||
sq_length: Self::sq_length(),
|
||||
sq_concat: Self::sq_concat(),
|
||||
sq_repeat: Self::sq_repeat(),
|
||||
sq_item: Self::sq_item(),
|
||||
sq_slice: None,
|
||||
sq_ass_item: sq_ass_item_impl::sq_ass_item::<Self>(),
|
||||
sq_ass_slice: None,
|
||||
sq_contains: Self::sq_contains(),
|
||||
sq_inplace_concat: Self::sq_inplace_concat(),
|
||||
sq_inplace_repeat: Self::sq_inplace_repeat(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ pub fn parse_fn_args<'p>(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
/// Builds a module (or null) from a user given initializer. Used for `#[pymodule]`.
|
||||
pub unsafe fn make_module(
|
||||
name: &str,
|
||||
|
@ -158,43 +157,6 @@ pub unsafe fn make_module(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
#[doc(hidden)]
|
||||
/// Builds a module (or null) from a user given initializer. Used for `#[pymodule]`.
|
||||
pub unsafe fn make_module(
|
||||
name: &str,
|
||||
doc: &str,
|
||||
initializer: impl Fn(Python, &PyModule) -> PyResult<()>,
|
||||
) {
|
||||
init_once();
|
||||
|
||||
#[cfg(py_sys_config = "WITH_THREAD")]
|
||||
ffi::PyEval_InitThreads();
|
||||
|
||||
let _name = name.as_ptr() as *const _;
|
||||
let _pool = GILPool::new();
|
||||
let py = Python::assume_gil_acquired();
|
||||
let _module = ffi::Py_InitModule(_name, ptr::null_mut());
|
||||
if _module.is_null() {
|
||||
return;
|
||||
}
|
||||
|
||||
let _module = match py.from_borrowed_ptr_or_err::<PyModule>(_module) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
e.restore(py);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
_module
|
||||
.add("__doc__", doc)
|
||||
.expect("Failed to add doc for module");
|
||||
if let Err(e) = initializer(py, _module) {
|
||||
e.restore(py)
|
||||
}
|
||||
}
|
||||
|
||||
/// This trait wraps a T: IntoPyObject into PyResult<T> while PyResult<T> remains PyResult<T>.
|
||||
///
|
||||
/// This is necessary because proc macros run before typechecking and can't decide
|
||||
|
|
|
@ -424,7 +424,6 @@ macro_rules! impl_to_pyerr {
|
|||
};
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
/// Create `OSError` from `io::Error`
|
||||
impl std::convert::From<io::Error> for PyErr {
|
||||
fn from(err: io::Error) -> PyErr {
|
||||
|
@ -460,14 +459,6 @@ impl std::convert::From<io::Error> for PyErr {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
/// Create `OSError` from `io::Error`
|
||||
impl std::convert::From<io::Error> for PyErr {
|
||||
fn from(err: io::Error) -> PyErr {
|
||||
PyErr::from_value::<exceptions::OSError>(PyErrValue::ToArgs(Box::new(err)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract `errno` and `errdesc` from from `io::Error`
|
||||
impl PyErrArguments for io::Error {
|
||||
fn arguments(&self, py: Python) -> PyObject {
|
||||
|
|
|
@ -231,7 +231,6 @@ macro_rules! impl_native_exception (
|
|||
|
||||
impl_native_exception!(BaseException, PyExc_BaseException);
|
||||
impl_native_exception!(Exception, PyExc_Exception);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(StopAsyncIteration, PyExc_StopAsyncIteration);
|
||||
impl_native_exception!(StopIteration, PyExc_StopIteration);
|
||||
impl_native_exception!(GeneratorExit, PyExc_GeneratorExit);
|
||||
|
@ -256,7 +255,6 @@ impl_native_exception!(MemoryError, PyExc_MemoryError);
|
|||
impl_native_exception!(NameError, PyExc_NameError);
|
||||
impl_native_exception!(OverflowError, PyExc_OverflowError);
|
||||
impl_native_exception!(RuntimeError, PyExc_RuntimeError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(RecursionError, PyExc_RecursionError);
|
||||
impl_native_exception!(NotImplementedError, PyExc_NotImplementedError);
|
||||
impl_native_exception!(SyntaxError, PyExc_SyntaxError);
|
||||
|
@ -272,35 +270,20 @@ impl_native_exception!(UnicodeTranslateError, PyExc_UnicodeTranslateError);
|
|||
impl_native_exception!(ValueError, PyExc_ValueError);
|
||||
impl_native_exception!(ZeroDivisionError, PyExc_ZeroDivisionError);
|
||||
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(BlockingIOError, PyExc_BlockingIOError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(BrokenPipeError, PyExc_BrokenPipeError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(ChildProcessError, PyExc_ChildProcessError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(ConnectionError, PyExc_ConnectionError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(ConnectionAbortedError, PyExc_ConnectionAbortedError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(ConnectionRefusedError, PyExc_ConnectionRefusedError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(ConnectionResetError, PyExc_ConnectionResetError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(FileExistsError, PyExc_FileExistsError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(FileNotFoundError, PyExc_FileNotFoundError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(InterruptedError, PyExc_InterruptedError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(IsADirectoryError, PyExc_IsADirectoryError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(NotADirectoryError, PyExc_NotADirectoryError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(PermissionError, PyExc_PermissionError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(ProcessLookupError, PyExc_ProcessLookupError);
|
||||
#[cfg(Py_3)]
|
||||
impl_native_exception!(TimeoutError, PyExc_TimeoutError);
|
||||
|
||||
impl_native_exception!(EnvironmentError, PyExc_EnvironmentError);
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
pub use crate::ffi2::*;
|
||||
|
||||
#[cfg(Py_3)]
|
||||
pub use crate::ffi3::*;
|
||||
|
||||
pub use self::datetime::*;
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
use crate::ffi2::intobject::PyIntObject;
|
||||
use crate::ffi2::object::*;
|
||||
use std::os::raw::{c_int, c_long};
|
||||
|
||||
pub type PyBoolObject = PyIntObject;
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyBool_Type: PyTypeObject;
|
||||
static mut _Py_ZeroStruct: PyIntObject;
|
||||
static mut _Py_TrueStruct: PyIntObject;
|
||||
pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyBool_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_False() -> *mut PyObject {
|
||||
&mut _Py_ZeroStruct as *mut PyBoolObject as *mut PyObject
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_True() -> *mut PyObject {
|
||||
&mut _Py_TrueStruct as *mut PyBoolObject as *mut PyObject
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_int, c_void};
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyBuffer_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyBuffer_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyBuffer_Type;
|
||||
(Py_TYPE(op) == u) as 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;
|
||||
pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject;
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
/*#[repr(C)]
|
||||
#[deriving(Copy)]
|
||||
struct PyByteArrayObject {
|
||||
#[cfg(py_sys_config="Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config="Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
pub ob_exports: c_int,
|
||||
pub ob_alloc: Py_ssize_t,
|
||||
pub ob_bytes: *mut c_char,
|
||||
}*/
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyByteArray_Type: PyTypeObject;
|
||||
pub static mut PyByteArrayIter_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut PyByteArray_Type)
|
||||
}
|
||||
|
||||
pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyByteArray_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[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_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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char {
|
||||
PyByteArray_AsString(o)
|
||||
// #define PyByteArray_AS_STRING(self) \
|
||||
// (assert(PyByteArray_Check(self)), \
|
||||
// Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyByteArray_GET_SIZE(o: *mut PyObject) -> Py_ssize_t {
|
||||
// #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self))
|
||||
PyByteArray_Size(o)
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
pub use crate::ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS;
|
||||
pub use crate::ffi2::stringobject::PyStringObject as PyBytesObject;
|
||||
pub use crate::ffi2::stringobject::PyString_AS_STRING as PyBytes_AS_STRING;
|
||||
pub use crate::ffi2::stringobject::PyString_AsString as PyBytes_AsString;
|
||||
pub use crate::ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize;
|
||||
pub use crate::ffi2::stringobject::PyString_Check as PyBytes_Check;
|
||||
pub use crate::ffi2::stringobject::PyString_CheckExact as PyBytes_CheckExact;
|
||||
pub use crate::ffi2::stringobject::PyString_Concat as PyBytes_Concat;
|
||||
pub use crate::ffi2::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel;
|
||||
pub use crate::ffi2::stringobject::PyString_Format as PyBytes_Format;
|
||||
pub use crate::ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat;
|
||||
pub use crate::ffi2::stringobject::PyString_FromString as PyBytes_FromString;
|
||||
pub use crate::ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize;
|
||||
pub use crate::ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE;
|
||||
pub use crate::ffi2::stringobject::PyString_Size as PyBytes_Size;
|
||||
pub use crate::ffi2::stringobject::PyString_Type as PyBytes_Type;
|
|
@ -1,42 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
struct PyCellObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_ref: *mut PyObject,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyCell_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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" {
|
||||
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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCell_GET(op: *mut PyObject) -> *mut PyObject {
|
||||
(*(op as *mut PyCellObject)).ob_ref
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCell_SET(op: *mut PyObject, obj: *mut PyObject) {
|
||||
(*(op as *mut PyCellObject)).ob_ref = obj;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
use crate::ffi2::frameobject::PyFrameObject;
|
||||
use crate::ffi2::object::PyObject;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use crate::ffi2::pystate::{PyThreadState, Py_tracefunc};
|
||||
use crate::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,
|
||||
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,
|
||||
methodname: *const c_char,
|
||||
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;
|
||||
pub fn PyEval_GetGlobals() -> *mut PyObject;
|
||||
pub fn PyEval_GetLocals() -> *mut PyObject;
|
||||
pub fn PyEval_GetFrame() -> *mut PyFrameObject;
|
||||
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_MakePendingCalls() -> c_int;
|
||||
pub fn Py_SetRecursionLimit(arg1: c_int);
|
||||
pub fn Py_GetRecursionLimit() -> c_int;
|
||||
fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int;
|
||||
|
||||
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 PyFrameObject) -> *mut PyObject;
|
||||
pub fn PyEval_EvalFrameEx(f: *mut PyFrameObject, exc: c_int) -> *mut PyObject;
|
||||
pub fn PyEval_SaveThread() -> *mut PyThreadState;
|
||||
pub fn PyEval_RestoreThread(arg1: *mut PyThreadState);
|
||||
|
||||
fn _PyEval_SliceIndex(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> c_int;
|
||||
}
|
||||
|
||||
#[cfg(py_sys_config = "WITH_THREAD")]
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub fn PyEval_ThreadsInitialized() -> c_int;
|
||||
pub fn PyEval_InitThreads();
|
||||
pub fn PyEval_AcquireLock();
|
||||
pub fn PyEval_ReleaseLock();
|
||||
pub fn PyEval_AcquireThread(tstate: *mut PyThreadState);
|
||||
pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState);
|
||||
pub fn PyEval_ReInitThreads();
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyClassObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub cl_bases: *mut PyObject,
|
||||
pub cl_dict: *mut PyObject,
|
||||
pub cl_name: *mut PyObject,
|
||||
pub cl_getattr: *mut PyObject,
|
||||
pub cl_setattr: *mut PyObject,
|
||||
pub cl_delattr: *mut PyObject,
|
||||
pub cl_weakreflist: *mut PyObject,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyInstanceObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub in_class: *mut PyClassObject,
|
||||
pub in_dict: *mut PyObject,
|
||||
pub in_weakreflist: *mut PyObject,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyMethodObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub im_func: *mut PyObject,
|
||||
pub im_self: *mut PyObject,
|
||||
pub im_class: *mut PyObject,
|
||||
pub im_weakreflist: *mut PyObject,
|
||||
}
|
||||
|
||||
#[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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyClass_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyClass_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyInstance_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyInstance_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMethod_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyMethod_Type;
|
||||
(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;
|
||||
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;
|
||||
pub fn PyMethod_ClearFreeList() -> c_int;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMethod_GET_FUNCTION(meth: *mut PyObject) -> *mut PyObject {
|
||||
(*(meth as *mut PyMethodObject)).im_func
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMethod_GET_SELF(meth: *mut PyObject) -> *mut PyObject {
|
||||
(*(meth as *mut PyMethodObject)).im_self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMethod_GET_CLASS(meth: *mut PyObject) -> *mut PyObject {
|
||||
(*(meth as *mut PyMethodObject)).im_class
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyCObject_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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;
|
||||
pub fn PyCObject_FromVoidPtrAndDesc(
|
||||
cobj: *mut c_void,
|
||||
desc: *mut c_void,
|
||||
destruct: Option<unsafe extern "C" fn(arg1: *mut c_void, arg2: *mut c_void)>,
|
||||
) -> *mut PyObject;
|
||||
pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void;
|
||||
pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void;
|
||||
pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void;
|
||||
pub fn PyCObject_SetVoidPtr(_self: *mut PyObject, cobj: *mut c_void) -> c_int;
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyCodeObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub co_argcount: c_int,
|
||||
pub co_nlocals: c_int,
|
||||
pub co_stacksize: c_int,
|
||||
pub co_flags: c_int,
|
||||
pub co_code: *mut PyObject,
|
||||
pub co_consts: *mut PyObject,
|
||||
pub co_names: *mut PyObject,
|
||||
pub co_varnames: *mut PyObject,
|
||||
pub co_freevars: *mut PyObject,
|
||||
pub co_cellvars: *mut PyObject,
|
||||
pub co_filename: *mut PyObject,
|
||||
pub co_name: *mut PyObject,
|
||||
pub co_firstlineno: c_int,
|
||||
pub co_lnotab: *mut PyObject,
|
||||
pub co_zombieframe: *mut c_void,
|
||||
pub co_weakreflist: *mut PyObject,
|
||||
}
|
||||
|
||||
/* Masks for co_flags */
|
||||
pub const CO_OPTIMIZED: c_int = 0x0001;
|
||||
pub const CO_NEWLOCALS: c_int = 0x0002;
|
||||
pub const CO_VARARGS: c_int = 0x0004;
|
||||
pub const CO_VARKEYWORDS: c_int = 0x0008;
|
||||
pub const CO_NESTED: c_int = 0x0010;
|
||||
pub const CO_GENERATOR: c_int = 0x0020;
|
||||
/* The CO_NOFREE flag is set if there are no free or cell variables.
|
||||
This information is redundant, but it allows a single flag test
|
||||
to determine whether there is any extra work to be done when the
|
||||
call frame it setup.
|
||||
*/
|
||||
pub const CO_NOFREE: c_int = 0x0040;
|
||||
|
||||
pub const CO_FUTURE_DIVISION: c_int = 0x2000;
|
||||
pub const CO_FUTURE_ABSOLUTE_IMPORT: c_int = 0x4000; /* do absolute imports by default */
|
||||
pub const CO_FUTURE_WITH_STATEMENT: c_int = 0x8000;
|
||||
pub const CO_FUTURE_PRINT_FUNCTION: c_int = 0x1_0000;
|
||||
pub const CO_FUTURE_UNICODE_LITERALS: c_int = 0x2_0000;
|
||||
|
||||
pub const CO_MAXBLOCKS: usize = 20;
|
||||
|
||||
#[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,
|
||||
funcname: *const c_char,
|
||||
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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int {
|
||||
(Py_TYPE(op) == &mut PyCode_Type) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t {
|
||||
crate::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars)
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
use crate::ffi2::code::*;
|
||||
use crate::ffi2::pyarena::PyArena;
|
||||
use crate::ffi2::pythonrun::*;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyFutureFeatures {
|
||||
pub ff_features: c_int,
|
||||
pub ff_lineno: c_int,
|
||||
}
|
||||
|
||||
pub const FUTURE_NESTED_SCOPES: &'static str = "nested_scopes";
|
||||
pub const FUTURE_GENERATORS: &'static str = "generators";
|
||||
pub const FUTURE_DIVISION: &'static str = "division";
|
||||
pub const FUTURE_ABSOLUTE_IMPORT: &'static str = "absolute_import";
|
||||
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;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::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,
|
||||
}
|
||||
|
||||
#[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;
|
||||
pub fn _Py_c_prod(left: Py_complex, right: Py_complex) -> Py_complex;
|
||||
pub fn _Py_c_quot(dividend: Py_complex, divisor: Py_complex) -> Py_complex;
|
||||
pub fn _Py_c_pow(num: Py_complex, exp: Py_complex) -> Py_complex;
|
||||
pub fn _Py_c_abs(arg: Py_complex) -> c_double;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyComplexObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub cval: Py_complex,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyComplex_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut PyComplex_Type)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyComplex_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[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_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;
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
use crate::ffi2::methodobject::PyMethodDef;
|
||||
use crate::ffi2::object::{PyObject, PyTypeObject, Py_TYPE};
|
||||
use crate::ffi2::structmember::PyMemberDef;
|
||||
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 setter =
|
||||
unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyGetSetDef {
|
||||
pub name: *mut c_char,
|
||||
pub get: Option<getter>,
|
||||
pub set: Option<setter>,
|
||||
pub doc: *mut c_char,
|
||||
pub closure: *mut c_void,
|
||||
}
|
||||
|
||||
pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef {
|
||||
name: ptr::null_mut(),
|
||||
get: None,
|
||||
set: None,
|
||||
doc: ptr::null_mut(),
|
||||
closure: ptr::null_mut(),
|
||||
};
|
||||
|
||||
pub const PyGetSetDef_DICT: PyGetSetDef = PyGetSetDef_INIT;
|
||||
|
||||
impl Clone for PyGetSetDef {
|
||||
#[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;
|
||||
|
||||
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)]
|
||||
pub struct wrapperbase {
|
||||
pub name: *mut c_char,
|
||||
pub offset: c_int,
|
||||
pub function: *mut c_void,
|
||||
pub wrapper: Option<wrapperfunc>,
|
||||
pub doc: *mut c_char,
|
||||
pub flags: c_int,
|
||||
pub name_strobj: *mut PyObject,
|
||||
}
|
||||
|
||||
impl Clone for wrapperbase {
|
||||
#[inline]
|
||||
fn clone(&self) -> wrapperbase {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const PyWrapperFlag_KEYWORDS: c_int = 1;
|
||||
|
||||
#[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) -> *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,
|
||||
arg2: *mut wrapperbase,
|
||||
arg3: *mut c_void,
|
||||
) -> *mut PyObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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" {
|
||||
//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;
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::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" {
|
||||
pub static mut PyDict_Type: PyTypeObject;
|
||||
pub static mut PyDictIterKey_Type: PyTypeObject;
|
||||
pub static mut PyDictIterValue_Type: PyTypeObject;
|
||||
pub static mut PyDictIterItem_Type: PyTypeObject;
|
||||
pub static mut PyDictKeys_Type: PyTypeObject;
|
||||
pub static mut PyDictItems_Type: PyTypeObject;
|
||||
pub static mut PyDictValues_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyDict_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[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_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_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,
|
||||
hash: *mut c_long) -> c_int;
|
||||
pub fn _PyDict_Contains(mp: *mut PyObject, key: *mut PyObject,
|
||||
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;
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
use crate::ffi2::object::PyTypeObject;
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyEnum_Type: PyTypeObject;
|
||||
pub static mut PyReversed_Type: PyTypeObject;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
use crate::ffi2::code::PyCodeObject;
|
||||
use crate::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;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use libc::{size_t, FILE};
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyFile_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFile_Check(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut PyFile_Type)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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;
|
||||
pub fn PyFile_SetBufSize(arg1: *mut PyObject, arg2: c_int);
|
||||
pub fn PyFile_SetEncoding(arg1: *mut PyObject, arg2: *const c_char) -> c_int;
|
||||
pub fn PyFile_SetEncodingAndErrors(
|
||||
arg1: *mut PyObject,
|
||||
arg2: *const c_char,
|
||||
errors: *mut c_char,
|
||||
) -> c_int;
|
||||
pub fn PyFile_FromFile(
|
||||
arg1: *mut FILE,
|
||||
arg2: *mut c_char,
|
||||
arg3: *mut c_char,
|
||||
arg4: Option<unsafe extern "C" fn(arg1: *mut FILE) -> c_int>,
|
||||
) -> *mut PyObject;
|
||||
pub fn PyFile_AsFile(arg1: *mut PyObject) -> *mut FILE;
|
||||
//pub fn PyFile_IncUseCount(arg1: *mut PyFileObject);
|
||||
//pub fn PyFile_DecUseCount(arg1: *mut PyFileObject);
|
||||
pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject;
|
||||
pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int;
|
||||
pub fn PyFile_SoftSpace(arg1: *mut PyObject, arg2: c_int) -> c_int;
|
||||
pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int;
|
||||
pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int;
|
||||
pub fn Py_UniversalNewlineFgets(
|
||||
arg1: *mut c_char,
|
||||
arg2: c_int,
|
||||
arg3: *mut FILE,
|
||||
arg4: *mut PyObject,
|
||||
) -> *mut c_char;
|
||||
pub fn Py_UniversalNewlineFread(
|
||||
arg1: *mut c_char,
|
||||
arg2: size_t,
|
||||
arg3: *mut FILE,
|
||||
arg4: *mut PyObject,
|
||||
) -> size_t;
|
||||
|
||||
pub static mut Py_FileSystemDefaultEncoding: *const c_char;
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_double, c_int};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
struct PyFloatObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_fval: c_double,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyFloat_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut PyFloat_Type)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyFloat_Type;
|
||||
(Py_TYPE(op) == u) as 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;
|
||||
pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject;
|
||||
pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double;
|
||||
pub fn PyFloat_GetInfo() -> *mut PyObject;
|
||||
|
||||
pub fn PyFloat_GetMax() -> c_double;
|
||||
pub fn PyFloat_GetMin() -> c_double;
|
||||
pub fn PyFloat_ClearFreeList() -> c_int;
|
||||
}
|
||||
|
||||
pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double {
|
||||
(*(pyfloat as *mut PyFloatObject)).ob_fval
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
use crate::ffi2::code::{PyCodeObject, CO_MAXBLOCKS};
|
||||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use crate::ffi2::pystate::PyThreadState;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyTryBlock {
|
||||
pub b_type: c_int,
|
||||
pub b_handler: c_int,
|
||||
pub b_level: c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyFrameObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
pub f_back: *mut PyFrameObject, /* previous frame, or NULL */
|
||||
pub f_code: *mut PyCodeObject, /* code segment */
|
||||
pub f_builtins: *mut PyObject, /* builtin symbol table (PyDictObject) */
|
||||
pub f_globals: *mut PyObject, /* global symbol table (PyDictObject) */
|
||||
pub f_locals: *mut PyObject, /* local symbol table (any mapping) */
|
||||
pub f_valuestack: *mut *mut PyObject, /* points after the last local */
|
||||
/* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
|
||||
Frame evaluation usually NULLs it, but a frame that yields sets it
|
||||
to the current stack top. */
|
||||
pub f_stacktop: *mut *mut PyObject,
|
||||
pub f_trace: *mut PyObject, /* Trace function */
|
||||
|
||||
pub f_exc_type: *mut PyObject,
|
||||
pub f_exc_value: *mut PyObject,
|
||||
pub f_exc_traceback: *mut PyObject,
|
||||
|
||||
pub f_tstate: *mut PyThreadState,
|
||||
|
||||
pub f_lasti: c_int, /* Last instruction if called */
|
||||
/* Call PyFrame_GetLineNumber() instead of reading this field
|
||||
directly. As of 2.3 f_lineno is only valid when tracing is
|
||||
active (i.e. when f_trace is set). At other times we use
|
||||
PyCode_Addr2Line to calculate the line from the current
|
||||
bytecode index. */
|
||||
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 */
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyFrame_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
|
||||
((*op).ob_type == &mut PyFrame_Type) as c_int
|
||||
}
|
||||
|
||||
//#[inline]
|
||||
//pub unsafe fn PyFrame_IsRestricted(f: *mut PyFrameObject) -> 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;
|
||||
|
||||
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) -> ();
|
||||
pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> ();
|
||||
|
||||
pub fn PyFrame_ClearFreeList() -> c_int;
|
||||
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyFunction_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyFunction_Type;
|
||||
(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;
|
||||
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_GetClosure(f: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) -> c_int;
|
||||
|
||||
pub static mut PyClassMethod_Type: PyTypeObject;
|
||||
pub static mut PyStaticMethod_Type: PyTypeObject;
|
||||
|
||||
pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject;
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
use crate::ffi2::frameobject::PyFrameObject;
|
||||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyGenObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub gi_frame: *mut PyFrameObject,
|
||||
pub gi_running: c_int,
|
||||
pub gi_code: *mut PyObject,
|
||||
pub gi_weakreflist: *mut PyObject,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyGen_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut PyGen_Type)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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" {
|
||||
pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject;
|
||||
pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use std::os::raw::{c_char, c_int, c_long, c_uchar};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyImport_Struct_inittab {
|
||||
pub name: *mut c_char,
|
||||
pub initfunc: Option<unsafe extern "C" fn()>,
|
||||
}
|
||||
|
||||
impl Clone for PyImport_Struct_inittab {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyImport_Struct_inittab {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyImport_Struct_frozen {
|
||||
pub name: *mut c_char,
|
||||
pub code: *mut c_uchar,
|
||||
pub size: c_int,
|
||||
}
|
||||
|
||||
#[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,
|
||||
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,
|
||||
co: *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_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;
|
||||
|
||||
/*for internal use only:
|
||||
pub fn PyImport_Cleanup();
|
||||
pub fn _PyImport_AcquireLock();
|
||||
pub fn _PyImport_ReleaseLock() -> c_int;
|
||||
pub fn _PyImport_FindModule(arg1: *const c_char,
|
||||
arg2: *mut PyObject,
|
||||
arg3: *mut c_char, arg4: size_t,
|
||||
arg5: *mut *mut FILE,
|
||||
arg6: *mut *mut PyObject)
|
||||
-> *mut Struct_filedescr;
|
||||
pub fn _PyImport_IsScript(arg1: *mut Struct_filedescr) -> c_int;
|
||||
pub fn _PyImport_ReInitLock();
|
||||
pub fn _PyImport_FindExtension(arg1: *mut c_char,
|
||||
arg2: *mut c_char)
|
||||
-> *mut PyObject;
|
||||
pub fn _PyImport_FixupExtension(arg1: *mut c_char,
|
||||
arg2: *mut c_char)
|
||||
-> *mut PyObject;*/
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use libc::size_t;
|
||||
use std::os::raw::{c_char, c_int, c_long, c_ulong, c_ulonglong};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyIntObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_ival: c_long,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyInt_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyInt_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyInt_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyInt_Type;
|
||||
(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(py_sys_config = "Py_USING_UNICODE")]
|
||||
pub fn PyInt_FromUnicode(
|
||||
u: *mut crate::ffi2::unicodeobject::Py_UNICODE,
|
||||
length: Py_ssize_t,
|
||||
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;
|
||||
pub fn PyInt_AsLong(io: *mut PyObject) -> c_long;
|
||||
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_GetMax() -> c_long;
|
||||
//fn PyOS_strtoul(arg1: *mut c_char,
|
||||
// arg2: *mut *mut c_char, arg3: c_int)
|
||||
// -> c_ulong;
|
||||
//fn PyOS_strtol(arg1: *mut c_char,
|
||||
// arg2: *mut *mut c_char, arg3: c_int)
|
||||
// -> c_long;
|
||||
pub fn PyInt_ClearFreeList() -> c_int;
|
||||
//fn _PyInt_Format(v: *mut PyIntObject, base: c_int,
|
||||
// newstyle: c_int) -> *mut PyObject;
|
||||
//fn _PyInt_FormatAdvanced(obj: *mut PyObject,
|
||||
// format_spec: *mut c_char,
|
||||
// format_spec_len: Py_ssize_t)
|
||||
// -> *mut PyObject;
|
||||
}
|
||||
|
||||
pub unsafe fn PyInt_AS_LONG(io: *mut PyObject) -> c_long {
|
||||
(*(io as *mut PyIntObject)).ob_ival
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int {
|
||||
(Py_TYPE(op) == &mut PySeqIter_Type) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int {
|
||||
(Py_TYPE(op) == &mut PyCallIter_Type) as c_int
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyListObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
pub ob_item: *mut *mut PyObject,
|
||||
pub allocated: Py_ssize_t,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyList_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyList_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyList_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyList_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
/// Macro, trading safety for speed
|
||||
#[inline]
|
||||
pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
|
||||
*(*(op as *mut PyListObject)).ob_item.offset(i as isize)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyList_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
|
||||
Py_SIZE(op)
|
||||
}
|
||||
|
||||
/// Macro, *only* to be used to fill in brand new lists
|
||||
#[inline]
|
||||
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" {
|
||||
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) -> *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_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;
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::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,
|
||||
};
|
||||
|
||||
/// This is an opaque type in the python c api
|
||||
#[repr(transparent)]
|
||||
pub struct PyLongObject(*mut c_void);
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyLong_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyLong_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyLong_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyLong_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[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_FromDouble(v: c_double) -> *mut PyObject;
|
||||
pub fn PyLong_FromString(
|
||||
str: *mut c_char,
|
||||
pend: *mut *mut c_char,
|
||||
base: c_int,
|
||||
) -> *mut PyObject;
|
||||
#[cfg(py_sys_config = "Py_USING_UNICODE")]
|
||||
pub fn PyLong_FromUnicode(
|
||||
u: *mut crate::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_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_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong;
|
||||
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;
|
||||
|
||||
pub fn PyLong_GetInfo() -> *mut PyObject;
|
||||
|
||||
pub fn _PyLong_FromByteArray(
|
||||
bytes: *const c_uchar,
|
||||
n: size_t,
|
||||
little_endian: c_int,
|
||||
is_signed: c_int,
|
||||
) -> *mut PyObject;
|
||||
|
||||
pub fn _PyLong_AsByteArray(
|
||||
v: *mut PyLongObject,
|
||||
bytes: *const c_uchar,
|
||||
n: size_t,
|
||||
little_endian: c_int,
|
||||
is_signed: c_int,
|
||||
) -> c_int;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyMemoryView_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyMemoryView_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMemoryView_GET_BUFFER(op: *mut PyObject) -> *mut Py_buffer {
|
||||
&mut (*(op as *mut PyMemoryViewObject)).view
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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,
|
||||
buffertype: c_int,
|
||||
fort: c_char,
|
||||
) -> *mut PyObject;
|
||||
pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyMemoryView_FromBuffer(info: *mut Py_buffer) -> *mut PyObject;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyMemoryViewObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub base: *mut PyObject,
|
||||
pub view: Py_buffer,
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
use crate::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" {
|
||||
pub static mut PyCFunction_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyCFunction_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
pub type PyCFunction =
|
||||
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) -> *mut PyObject;
|
||||
|
||||
#[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;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyMethodDef {
|
||||
pub ml_name: *const c_char,
|
||||
pub ml_meth: Option<PyCFunction>,
|
||||
pub ml_flags: c_int,
|
||||
pub ml_doc: *const c_char,
|
||||
}
|
||||
|
||||
pub const PyMethodDef_INIT: PyMethodDef = PyMethodDef {
|
||||
ml_name: ::std::ptr::null(),
|
||||
ml_meth: None,
|
||||
ml_flags: 0,
|
||||
ml_doc: ::std::ptr::null(),
|
||||
};
|
||||
|
||||
impl Clone for PyMethodDef {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyMethodDef {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
/* Flag passed to newmethodobject */
|
||||
pub const METH_OLDARGS: c_int = 0x0000;
|
||||
pub const METH_VARARGS: c_int = 0x0001;
|
||||
pub const METH_KEYWORDS: c_int = 0x0002;
|
||||
/* METH_NOARGS and METH_O must not be combined with the flags above. */
|
||||
pub const METH_NOARGS: c_int = 0x0004;
|
||||
pub const METH_O: c_int = 0x0008;
|
||||
|
||||
/* METH_CLASS and METH_STATIC are a little different; these control
|
||||
the construction of methods for a class. These cannot be used for
|
||||
functions in modules. */
|
||||
pub const METH_CLASS: c_int = 0x0010;
|
||||
pub const METH_STATIC: c_int = 0x0020;
|
||||
|
||||
/* METH_COEXIST allows a method to be entered eventhough a slot has
|
||||
already filled the entry. When defined, the flag allows a separate
|
||||
method, "__contains__" for example, to coexist with a defined
|
||||
slot like sq_contains. */
|
||||
|
||||
pub const METH_COEXIST: c_int = 0x0040;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyMethodChain {
|
||||
pub methods: *mut PyMethodDef,
|
||||
pub link: *mut PyMethodChain,
|
||||
}
|
||||
|
||||
/*
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
struct PyCFunctionObject {
|
||||
#[cfg(py_sys_config="Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config="Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub m_ml: *mut PyMethodDef,
|
||||
pub m_self: *mut PyObject,
|
||||
pub m_module: *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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject {
|
||||
PyCFunction_NewEx(ml, slf, ptr::null_mut())
|
||||
}
|
142
src/ffi2/mod.rs
142
src/ffi2/mod.rs
|
@ -1,142 +0,0 @@
|
|||
//! Rust FFI declarations for Python 2
|
||||
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
|
||||
|
||||
use std::os::raw::c_int;
|
||||
|
||||
pub use self::boolobject::*;
|
||||
pub use self::bufferobject::*;
|
||||
pub use self::bytearrayobject::*;
|
||||
pub use self::bytesobject::*;
|
||||
pub use self::cellobject::*;
|
||||
pub use self::ceval::*;
|
||||
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::fileobject::*;
|
||||
pub use self::floatobject::*;
|
||||
pub use self::frameobject::PyFrameObject;
|
||||
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")]
|
||||
pub use self::unicodeobject::*;
|
||||
pub use self::warnings::*;
|
||||
pub use self::weakrefobject::*;
|
||||
|
||||
mod boolobject;
|
||||
mod bufferobject;
|
||||
mod bytearrayobject;
|
||||
mod bytesobject;
|
||||
mod cellobject;
|
||||
mod classobject;
|
||||
mod cobject;
|
||||
mod complexobject;
|
||||
mod descrobject;
|
||||
mod dictobject;
|
||||
mod enumobject;
|
||||
mod fileobject;
|
||||
mod floatobject;
|
||||
mod funcobject;
|
||||
mod genobject;
|
||||
mod intobject;
|
||||
mod iterobject;
|
||||
mod listobject;
|
||||
mod longobject;
|
||||
mod memoryobject;
|
||||
mod methodobject;
|
||||
mod moduleobject;
|
||||
mod object;
|
||||
mod objimpl;
|
||||
mod pycapsule;
|
||||
mod pydebug;
|
||||
mod pymem;
|
||||
mod pyport;
|
||||
mod rangeobject;
|
||||
mod setobject;
|
||||
mod sliceobject;
|
||||
mod stringobject;
|
||||
mod traceback;
|
||||
mod tupleobject;
|
||||
#[cfg(py_sys_config = "Py_USING_UNICODE")]
|
||||
mod unicodeobject; // TODO: incomplete
|
||||
mod warnings;
|
||||
mod weakrefobject;
|
||||
|
||||
// mod codecs; // TODO: incomplete
|
||||
mod pyerrors;
|
||||
|
||||
mod pystate;
|
||||
|
||||
mod ceval;
|
||||
mod modsupport;
|
||||
mod pyarena;
|
||||
mod pythonrun;
|
||||
// mod sysmodule; // TODO: incomplete
|
||||
// mod intrcheck; // TODO: incomplete
|
||||
mod import;
|
||||
|
||||
mod objectabstract;
|
||||
|
||||
mod code;
|
||||
mod compile;
|
||||
mod eval;
|
||||
|
||||
// mod pyctype; // TODO: incomplete
|
||||
// mod pystrtod; // TODO: incomplete
|
||||
// mod pystrcmp; // TODO: incomplete
|
||||
// mod dtoa; // TODO: incomplete
|
||||
|
||||
// mod pyfpe; // TODO: incomplete
|
||||
|
||||
// Additional headers that are not exported by Python.h
|
||||
pub mod frameobject;
|
||||
pub mod structmember;
|
||||
|
||||
pub const Py_single_input: c_int = 256;
|
||||
pub const Py_file_input: c_int = 257;
|
||||
pub const Py_eval_input: c_int = 258;
|
||||
|
||||
#[cfg(not(py_sys_config = "Py_USING_UNICODE"))]
|
||||
#[inline]
|
||||
pub fn PyUnicode_Check(op: *mut PyObject) -> libc::c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg(not(py_sys_config = "Py_USING_UNICODE"))]
|
||||
#[inline]
|
||||
pub fn PyUnicode_CheckExact(op: *mut PyObject) -> libc::c_int {
|
||||
0
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
use crate::ffi2::methodobject::PyMethodDef;
|
||||
use crate::ffi2::object::PyObject;
|
||||
use crate::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" {
|
||||
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,
|
||||
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;
|
||||
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,
|
||||
name: *const c_char,
|
||||
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,
|
||||
name: *const c_char,
|
||||
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,
|
||||
methods: *mut PyMethodDef,
|
||||
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,
|
||||
methods: *mut PyMethodDef,
|
||||
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,
|
||||
methods: *mut PyMethodDef,
|
||||
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,
|
||||
methods: *mut PyMethodDef,
|
||||
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")))]
|
||||
#[inline]
|
||||
pub unsafe fn Py_InitModule4(
|
||||
name: *const c_char,
|
||||
methods: *mut PyMethodDef,
|
||||
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]
|
||||
pub unsafe fn Py_InitModule4(
|
||||
name: *const c_char,
|
||||
methods: *mut PyMethodDef,
|
||||
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"))]
|
||||
#[inline]
|
||||
pub unsafe fn Py_InitModule4(
|
||||
name: *const c_char,
|
||||
methods: *mut PyMethodDef,
|
||||
doc: *const c_char,
|
||||
_self: *mut PyObject,
|
||||
apiver: c_int,
|
||||
) -> *mut PyObject {
|
||||
Py_InitModule4TraceRefs(name, methods, doc, _self, apiver)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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)
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
use crate::ffi2::methodobject::PyMethodDef;
|
||||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyModule_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut PyModule_Type)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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" {
|
||||
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;
|
||||
pub fn PyModule_GetNameObject(arg1: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyModule_GetName(arg1: *mut PyObject) -> *const c_char;
|
||||
pub fn PyModule_GetFilename(arg1: *mut PyObject) -> *const c_char;
|
||||
pub fn PyModule_GetFilenameObject(arg1: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef;
|
||||
pub fn PyModule_GetState(arg1: *mut PyObject) -> *mut c_void;
|
||||
pub fn PyModuleDef_Init(arg1: *mut PyModuleDef) -> *mut PyObject;
|
||||
pub static mut PyModuleDef_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyModuleDef_Base {
|
||||
pub ob_base: PyObject,
|
||||
pub m_init: Option<extern "C" fn() -> *mut PyObject>,
|
||||
pub m_index: Py_ssize_t,
|
||||
pub m_copy: *mut PyObject,
|
||||
}
|
||||
impl Clone for PyModuleDef_Base {
|
||||
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(),
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyModuleDef_Slot {
|
||||
pub slot: c_int,
|
||||
pub value: *mut c_void,
|
||||
}
|
||||
impl Clone for PyModuleDef_Slot {
|
||||
fn clone(&self) -> PyModuleDef_Slot {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const Py_mod_create: c_int = 1;
|
||||
pub const Py_mod_exec: c_int = 2;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyModuleDef {
|
||||
pub m_base: PyModuleDef_Base,
|
||||
pub m_name: *const c_char,
|
||||
pub m_doc: *const c_char,
|
||||
pub m_size: Py_ssize_t,
|
||||
pub m_methods: *mut PyMethodDef,
|
||||
pub m_slots: *mut PyModuleDef_Slot,
|
||||
pub m_traverse: Option<traverseproc>,
|
||||
pub m_clear: Option<inquiry>,
|
||||
pub m_free: Option<freefunc>,
|
||||
}
|
||||
impl Clone for PyModuleDef {
|
||||
fn clone(&self) -> PyModuleDef {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef {
|
||||
m_base: PyModuleDef_HEAD_INIT,
|
||||
m_name: ::std::ptr::null(),
|
||||
m_doc: ::std::ptr::null(),
|
||||
m_size: 0,
|
||||
m_methods: ::std::ptr::null_mut(),
|
||||
m_slots: ::std::ptr::null_mut(),
|
||||
m_traverse: None,
|
||||
m_clear: None,
|
||||
m_free: None,
|
||||
};
|
|
@ -1,885 +0,0 @@
|
|||
use crate::ffi2;
|
||||
use crate::ffi2::methodobject::PyMethodDef;
|
||||
use crate::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(Debug, Copy, Clone)]
|
||||
pub struct PyObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
}
|
||||
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
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(),
|
||||
};
|
||||
|
||||
#[cfg(not(py_sys_config = "Py_TRACE_REFS"))]
|
||||
pub const PyObject_HEAD_INIT: PyObject = PyObject {
|
||||
ob_refcnt: 1,
|
||||
ob_type: ::std::ptr::null_mut(),
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyVarObject {
|
||||
pub ob_base: PyObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t {
|
||||
(*ob).ob_refcnt
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject {
|
||||
(*ob).ob_type
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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 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;
|
||||
pub type coercion =
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
pub type objobjargproc =
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
pub type writebufferproc = 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;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Py_buffer {
|
||||
pub buf: *mut c_void,
|
||||
pub obj: *mut PyObject,
|
||||
pub len: Py_ssize_t,
|
||||
pub itemsize: Py_ssize_t,
|
||||
pub readonly: c_int,
|
||||
pub ndim: c_int,
|
||||
pub format: *mut c_char,
|
||||
pub shape: *mut Py_ssize_t,
|
||||
pub strides: *mut Py_ssize_t,
|
||||
pub suboffsets: *mut Py_ssize_t,
|
||||
pub smalltable: [Py_ssize_t; 2],
|
||||
pub internal: *mut c_void,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// flags:
|
||||
pub const PyBUF_SIMPLE: c_int = 0;
|
||||
pub const PyBUF_WRITABLE: c_int = 0x0001;
|
||||
pub const PyBUF_FORMAT: c_int = 0x0004;
|
||||
pub const PyBUF_ND: c_int = 0x0008;
|
||||
pub const PyBUF_STRIDES: c_int = (0x0010 | PyBUF_ND);
|
||||
pub const PyBUF_C_CONTIGUOUS: c_int = (0x0020 | PyBUF_STRIDES);
|
||||
pub const PyBUF_F_CONTIGUOUS: c_int = (0x0040 | PyBUF_STRIDES);
|
||||
pub const PyBUF_ANY_CONTIGUOUS: c_int = (0x0080 | PyBUF_STRIDES);
|
||||
pub const PyBUF_INDIRECT: c_int = (0x0100 | PyBUF_STRIDES);
|
||||
|
||||
pub const PyBUF_CONTIG: c_int = (PyBUF_ND | PyBUF_WRITABLE);
|
||||
pub const PyBUF_CONTIG_RO: c_int = (PyBUF_ND);
|
||||
|
||||
pub const PyBUF_STRIDED: c_int = (PyBUF_STRIDES | PyBUF_WRITABLE);
|
||||
pub const PyBUF_STRIDED_RO: c_int = (PyBUF_STRIDES);
|
||||
|
||||
pub const PyBUF_RECORDS: c_int = (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT);
|
||||
pub const PyBUF_RECORDS_RO: c_int = (PyBUF_STRIDES | PyBUF_FORMAT);
|
||||
|
||||
pub const PyBUF_FULL: c_int = (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT);
|
||||
pub const PyBUF_FULL_RO: c_int = (PyBUF_INDIRECT | PyBUF_FORMAT);
|
||||
|
||||
// buffertype:
|
||||
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 traverseproc =
|
||||
unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyNumberMethods {
|
||||
pub nb_add: Option<binaryfunc>,
|
||||
pub nb_subtract: Option<binaryfunc>,
|
||||
pub nb_multiply: Option<binaryfunc>,
|
||||
pub nb_divide: Option<binaryfunc>,
|
||||
pub nb_remainder: Option<binaryfunc>,
|
||||
pub nb_divmod: Option<binaryfunc>,
|
||||
pub nb_power: Option<ternaryfunc>,
|
||||
pub nb_negative: Option<unaryfunc>,
|
||||
pub nb_positive: Option<unaryfunc>,
|
||||
pub nb_absolute: Option<unaryfunc>,
|
||||
pub nb_nonzero: Option<inquiry>,
|
||||
pub nb_invert: Option<unaryfunc>,
|
||||
pub nb_lshift: Option<binaryfunc>,
|
||||
pub nb_rshift: Option<binaryfunc>,
|
||||
pub nb_and: Option<binaryfunc>,
|
||||
pub nb_xor: Option<binaryfunc>,
|
||||
pub nb_or: Option<binaryfunc>,
|
||||
pub nb_coerce: Option<coercion>,
|
||||
pub nb_c_int: Option<unaryfunc>,
|
||||
pub nb_long: Option<unaryfunc>,
|
||||
pub nb_float: Option<unaryfunc>,
|
||||
pub nb_oct: Option<unaryfunc>,
|
||||
pub nb_hex: Option<unaryfunc>,
|
||||
pub nb_inplace_add: Option<binaryfunc>,
|
||||
pub nb_inplace_subtract: Option<binaryfunc>,
|
||||
pub nb_inplace_multiply: Option<binaryfunc>,
|
||||
pub nb_inplace_divide: Option<binaryfunc>,
|
||||
pub nb_inplace_remainder: Option<binaryfunc>,
|
||||
pub nb_inplace_power: Option<ternaryfunc>,
|
||||
pub nb_inplace_lshift: Option<binaryfunc>,
|
||||
pub nb_inplace_rshift: Option<binaryfunc>,
|
||||
pub nb_inplace_and: Option<binaryfunc>,
|
||||
pub nb_inplace_xor: Option<binaryfunc>,
|
||||
pub nb_inplace_or: Option<binaryfunc>,
|
||||
pub nb_floor_divide: Option<binaryfunc>,
|
||||
pub nb_true_divide: Option<binaryfunc>,
|
||||
pub nb_inplace_floor_divide: Option<binaryfunc>,
|
||||
pub nb_inplace_true_divide: Option<binaryfunc>,
|
||||
pub nb_index: Option<unaryfunc>,
|
||||
}
|
||||
|
||||
impl Clone for PyNumberMethods {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyNumberMethods {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const PyNumberMethods_INIT: PyNumberMethods = PyNumberMethods {
|
||||
nb_add: None,
|
||||
nb_subtract: None,
|
||||
nb_multiply: None,
|
||||
nb_divide: None,
|
||||
nb_remainder: None,
|
||||
nb_divmod: None,
|
||||
nb_power: None,
|
||||
nb_negative: None,
|
||||
nb_positive: None,
|
||||
nb_absolute: None,
|
||||
nb_nonzero: None,
|
||||
nb_invert: None,
|
||||
nb_lshift: None,
|
||||
nb_rshift: None,
|
||||
nb_and: None,
|
||||
nb_xor: None,
|
||||
nb_or: None,
|
||||
nb_coerce: None,
|
||||
nb_c_int: None,
|
||||
nb_long: None,
|
||||
nb_float: None,
|
||||
nb_oct: None,
|
||||
nb_hex: None,
|
||||
nb_inplace_add: None,
|
||||
nb_inplace_subtract: None,
|
||||
nb_inplace_multiply: None,
|
||||
nb_inplace_divide: None,
|
||||
nb_inplace_remainder: None,
|
||||
nb_inplace_power: None,
|
||||
nb_inplace_lshift: None,
|
||||
nb_inplace_rshift: None,
|
||||
nb_inplace_and: None,
|
||||
nb_inplace_xor: None,
|
||||
nb_inplace_or: None,
|
||||
nb_floor_divide: None,
|
||||
nb_true_divide: None,
|
||||
nb_inplace_floor_divide: None,
|
||||
nb_inplace_true_divide: None,
|
||||
nb_index: None,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PySequenceMethods {
|
||||
pub sq_length: Option<lenfunc>,
|
||||
pub sq_concat: Option<binaryfunc>,
|
||||
pub sq_repeat: Option<ssizeargfunc>,
|
||||
pub sq_item: Option<ssizeargfunc>,
|
||||
pub sq_slice: Option<ssizessizeargfunc>,
|
||||
pub sq_ass_item: Option<ssizeobjargproc>,
|
||||
pub sq_ass_slice: Option<ssizessizeobjargproc>,
|
||||
pub sq_contains: Option<objobjproc>,
|
||||
pub sq_inplace_concat: Option<binaryfunc>,
|
||||
pub sq_inplace_repeat: Option<ssizeargfunc>,
|
||||
}
|
||||
|
||||
impl Clone for PySequenceMethods {
|
||||
#[inline]
|
||||
fn clone(&self) -> PySequenceMethods {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods {
|
||||
sq_length: None,
|
||||
sq_concat: None,
|
||||
sq_repeat: None,
|
||||
sq_item: None,
|
||||
sq_slice: None,
|
||||
sq_ass_item: None,
|
||||
sq_ass_slice: None,
|
||||
sq_contains: None,
|
||||
sq_inplace_concat: None,
|
||||
sq_inplace_repeat: None,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyMappingMethods {
|
||||
pub mp_length: Option<lenfunc>,
|
||||
pub mp_subscript: Option<binaryfunc>,
|
||||
pub mp_ass_subscript: Option<objobjargproc>,
|
||||
}
|
||||
|
||||
impl Clone for PyMappingMethods {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyMappingMethods {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods {
|
||||
mp_length: None,
|
||||
mp_subscript: None,
|
||||
mp_ass_subscript: None,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyBufferProcs {
|
||||
pub bf_getreadbuffer: Option<readbufferproc>,
|
||||
pub bf_getwritebuffer: Option<writebufferproc>,
|
||||
pub bf_getsegcount: Option<segcountproc>,
|
||||
pub bf_getcharbuffer: Option<charbufferproc>,
|
||||
pub bf_getbuffer: Option<getbufferproc>,
|
||||
pub bf_releasebuffer: Option<releasebufferproc>,
|
||||
}
|
||||
|
||||
impl Clone for PyBufferProcs {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyBufferProcs {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs {
|
||||
bf_getreadbuffer: None,
|
||||
bf_getwritebuffer: None,
|
||||
bf_getsegcount: None,
|
||||
bf_getcharbuffer: None,
|
||||
bf_getbuffer: None,
|
||||
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 printfunc =
|
||||
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut FILE, arg3: c_int) -> c_int;
|
||||
pub type getattrfunc =
|
||||
unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char) -> *mut PyObject;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
pub type descrgetfunc = 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;
|
||||
pub type initproc =
|
||||
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;
|
||||
pub type allocfunc =
|
||||
unsafe extern "C" fn(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyTypeObject {
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
pub tp_name: *const c_char,
|
||||
pub tp_basicsize: Py_ssize_t,
|
||||
pub tp_itemsize: Py_ssize_t,
|
||||
pub tp_dealloc: Option<destructor>,
|
||||
pub tp_print: Option<printfunc>,
|
||||
pub tp_getattr: Option<getattrfunc>,
|
||||
pub tp_setattr: Option<setattrfunc>,
|
||||
pub tp_compare: Option<cmpfunc>,
|
||||
pub tp_repr: Option<reprfunc>,
|
||||
pub tp_as_number: *mut PyNumberMethods,
|
||||
pub tp_as_sequence: *mut PySequenceMethods,
|
||||
pub tp_as_mapping: *mut PyMappingMethods,
|
||||
pub tp_hash: Option<hashfunc>,
|
||||
pub tp_call: Option<ternaryfunc>,
|
||||
pub tp_str: Option<reprfunc>,
|
||||
pub tp_getattro: Option<getattrofunc>,
|
||||
pub tp_setattro: Option<setattrofunc>,
|
||||
pub tp_as_buffer: *mut PyBufferProcs,
|
||||
pub tp_flags: c_long,
|
||||
pub tp_doc: *const c_char,
|
||||
pub tp_traverse: Option<traverseproc>,
|
||||
pub tp_clear: Option<inquiry>,
|
||||
pub tp_richcompare: Option<richcmpfunc>,
|
||||
pub tp_weaklistoffset: Py_ssize_t,
|
||||
pub tp_iter: Option<getiterfunc>,
|
||||
pub tp_iternext: Option<iternextfunc>,
|
||||
pub tp_methods: *mut PyMethodDef,
|
||||
pub tp_members: *mut ffi2::structmember::PyMemberDef,
|
||||
pub tp_getset: *mut ffi2::descrobject::PyGetSetDef,
|
||||
pub tp_base: *mut PyTypeObject,
|
||||
pub tp_dict: *mut PyObject,
|
||||
pub tp_descr_get: Option<descrgetfunc>,
|
||||
pub tp_descr_set: Option<descrsetfunc>,
|
||||
pub tp_dictoffset: Py_ssize_t,
|
||||
pub tp_init: Option<initproc>,
|
||||
pub tp_alloc: Option<allocfunc>,
|
||||
pub tp_new: Option<newfunc>,
|
||||
pub tp_free: Option<freefunc>,
|
||||
pub tp_is_gc: Option<inquiry>,
|
||||
pub tp_bases: *mut PyObject,
|
||||
pub tp_mro: *mut PyObject,
|
||||
pub tp_cache: *mut PyObject,
|
||||
pub tp_subclasses: *mut PyObject,
|
||||
pub tp_weaklist: *mut PyObject,
|
||||
pub tp_del: Option<destructor>,
|
||||
pub tp_version_tag: c_uint,
|
||||
}
|
||||
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject {
|
||||
_ob_next: ::std::ptr::null_mut(),
|
||||
_ob_prev: ::std::ptr::null_mut(),
|
||||
ob_refcnt: 1,
|
||||
ob_type: ::std::ptr::null_mut(),
|
||||
ob_size: 0,
|
||||
tp_name: ::std::ptr::null(),
|
||||
tp_basicsize: 0,
|
||||
tp_itemsize: 0,
|
||||
tp_dealloc: None,
|
||||
tp_print: None,
|
||||
tp_getattr: None,
|
||||
tp_setattr: None,
|
||||
tp_compare: None,
|
||||
tp_repr: None,
|
||||
tp_as_number: ::std::ptr::null_mut(),
|
||||
tp_as_sequence: ::std::ptr::null_mut(),
|
||||
tp_as_mapping: ::std::ptr::null_mut(),
|
||||
tp_hash: None,
|
||||
tp_call: None,
|
||||
tp_str: None,
|
||||
tp_getattro: None,
|
||||
tp_setattro: None,
|
||||
tp_as_buffer: ::std::ptr::null_mut(),
|
||||
tp_flags: Py_TPFLAGS_DEFAULT,
|
||||
tp_doc: ::std::ptr::null(),
|
||||
tp_traverse: None,
|
||||
tp_clear: None,
|
||||
tp_richcompare: None,
|
||||
tp_weaklistoffset: 0,
|
||||
tp_iter: None,
|
||||
tp_iternext: None,
|
||||
tp_methods: ::std::ptr::null_mut(),
|
||||
tp_members: ::std::ptr::null_mut(),
|
||||
tp_getset: ::std::ptr::null_mut(),
|
||||
tp_base: ::std::ptr::null_mut(),
|
||||
tp_dict: ::std::ptr::null_mut(),
|
||||
tp_descr_get: None,
|
||||
tp_descr_set: None,
|
||||
tp_dictoffset: 0,
|
||||
tp_init: None,
|
||||
tp_alloc: None,
|
||||
tp_new: None,
|
||||
tp_free: None,
|
||||
tp_is_gc: None,
|
||||
tp_bases: ::std::ptr::null_mut(),
|
||||
tp_mro: ::std::ptr::null_mut(),
|
||||
tp_cache: ::std::ptr::null_mut(),
|
||||
tp_subclasses: ::std::ptr::null_mut(),
|
||||
tp_weaklist: ::std::ptr::null_mut(),
|
||||
tp_del: None,
|
||||
tp_version_tag: 0,
|
||||
};
|
||||
|
||||
#[cfg(not(py_sys_config = "Py_TRACE_REFS"))]
|
||||
pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject {
|
||||
ob_refcnt: 1,
|
||||
ob_type: ::std::ptr::null_mut(),
|
||||
ob_size: 0,
|
||||
tp_name: ::std::ptr::null(),
|
||||
tp_basicsize: 0,
|
||||
tp_itemsize: 0,
|
||||
tp_dealloc: None,
|
||||
tp_print: None,
|
||||
tp_getattr: None,
|
||||
tp_setattr: None,
|
||||
tp_compare: None,
|
||||
tp_repr: None,
|
||||
tp_as_number: ::std::ptr::null_mut(),
|
||||
tp_as_sequence: ::std::ptr::null_mut(),
|
||||
tp_as_mapping: ::std::ptr::null_mut(),
|
||||
tp_hash: None,
|
||||
tp_call: None,
|
||||
tp_str: None,
|
||||
tp_getattro: None,
|
||||
tp_setattro: None,
|
||||
tp_as_buffer: ::std::ptr::null_mut(),
|
||||
tp_flags: Py_TPFLAGS_DEFAULT,
|
||||
tp_doc: ::std::ptr::null(),
|
||||
tp_traverse: None,
|
||||
tp_clear: None,
|
||||
tp_richcompare: None,
|
||||
tp_weaklistoffset: 0,
|
||||
tp_iter: None,
|
||||
tp_iternext: None,
|
||||
tp_methods: ::std::ptr::null_mut(),
|
||||
tp_members: ::std::ptr::null_mut(),
|
||||
tp_getset: ::std::ptr::null_mut(),
|
||||
tp_base: ::std::ptr::null_mut(),
|
||||
tp_dict: ::std::ptr::null_mut(),
|
||||
tp_descr_get: None,
|
||||
tp_descr_set: None,
|
||||
tp_dictoffset: 0,
|
||||
tp_init: None,
|
||||
tp_alloc: None,
|
||||
tp_new: None,
|
||||
tp_free: None,
|
||||
tp_is_gc: None,
|
||||
tp_bases: ::std::ptr::null_mut(),
|
||||
tp_mro: ::std::ptr::null_mut(),
|
||||
tp_cache: ::std::ptr::null_mut(),
|
||||
tp_subclasses: ::std::ptr::null_mut(),
|
||||
tp_weaklist: ::std::ptr::null_mut(),
|
||||
tp_del: None,
|
||||
tp_version_tag: 0,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyHeapTypeObject {
|
||||
pub ht_type: PyTypeObject,
|
||||
pub as_number: PyNumberMethods,
|
||||
pub as_mapping: PyMappingMethods,
|
||||
pub as_sequence: PySequenceMethods,
|
||||
pub as_buffer: PyBufferProcs,
|
||||
pub ht_name: *mut PyObject,
|
||||
pub ht_slots: *mut PyObject,
|
||||
}
|
||||
|
||||
impl Clone for PyHeapTypeObject {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyHeapTypeObject {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
// access macro to the members which are floating "behind" the object
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
|
||||
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" {
|
||||
pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_int {
|
||||
(Py_TYPE(ob) == tp || PyType_IsSubtype(Py_TYPE(ob), tp) != 0) as c_int
|
||||
}
|
||||
|
||||
#[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;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyType_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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" {
|
||||
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;
|
||||
fn _PyType_Lookup(arg1: *mut PyTypeObject, arg2: *mut PyObject) -> *mut PyObject;
|
||||
fn _PyObject_LookupSpecial(
|
||||
arg1: *mut PyObject,
|
||||
arg2: *mut c_char,
|
||||
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;
|
||||
fn _PyObject_Dump(o: *mut PyObject);
|
||||
pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject;
|
||||
fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject;
|
||||
pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject {
|
||||
PyObject_Str(o)
|
||||
}
|
||||
|
||||
#[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,
|
||||
arg2: *const c_char,
|
||||
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_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_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 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,
|
||||
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);
|
||||
fn _Py_HashDouble(arg1: c_double) -> c_long;
|
||||
fn _Py_HashPointer(arg1: *mut c_void) -> c_long;
|
||||
}
|
||||
|
||||
// Flag bits for printing:
|
||||
pub const Py_PRINT_RAW: c_int = 1; // No string quotes etc.
|
||||
|
||||
// https://github.com/rust-lang-nursery/rust-clippy/issues/3430
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::identity_op))]
|
||||
// PyBufferProcs contains bf_getcharbuffer
|
||||
pub const Py_TPFLAGS_HAVE_GETCHARBUFFER: c_long = (1 << 0);
|
||||
|
||||
// PySequenceMethods contains sq_contains
|
||||
pub const Py_TPFLAGS_HAVE_SEQUENCE_IN: c_long = (1 << 1);
|
||||
|
||||
// PySequenceMethods and PyNumberMethods contain in-place operators
|
||||
pub const Py_TPFLAGS_HAVE_INPLACEOPS: c_long = (1 << 3);
|
||||
|
||||
// PyNumberMethods do their own coercion
|
||||
pub const Py_TPFLAGS_CHECKTYPES: c_long = (1 << 4);
|
||||
|
||||
// tp_richcompare is defined
|
||||
pub const Py_TPFLAGS_HAVE_RICHCOMPARE: c_long = (1 << 5);
|
||||
|
||||
// Objects which are weakly referencable if their tp_weaklistoffset is >0
|
||||
pub const Py_TPFLAGS_HAVE_WEAKREFS: c_long = (1 << 6);
|
||||
|
||||
// tp_iter is defined
|
||||
pub const Py_TPFLAGS_HAVE_ITER: c_long = (1 << 7);
|
||||
|
||||
// New members introduced by Python 2.2 exist
|
||||
pub const Py_TPFLAGS_HAVE_CLASS: c_long = (1 << 8);
|
||||
|
||||
// Set if the type object is dynamically allocated
|
||||
pub const Py_TPFLAGS_HEAPTYPE: c_long = (1 << 9);
|
||||
|
||||
// Set if the type allows subclassing
|
||||
pub const Py_TPFLAGS_BASETYPE: c_long = (1 << 10);
|
||||
|
||||
// Set if the type is 'ready' -- fully initialized
|
||||
pub const Py_TPFLAGS_READY: c_long = (1 << 12);
|
||||
|
||||
// Set while the type is being 'readied', to prevent recursive ready calls
|
||||
pub const Py_TPFLAGS_READYING: c_long = (1 << 13);
|
||||
|
||||
// Objects support garbage collection (see objimp.h)
|
||||
pub const Py_TPFLAGS_HAVE_GC: c_long = (1 << 14);
|
||||
|
||||
// Two bits are preserved for Stackless Python, next after this is 17.
|
||||
const Py_TPFLAGS_HAVE_STACKLESS_EXTENSION: c_long = 0;
|
||||
|
||||
// Objects support nb_index in PyNumberMethods
|
||||
pub const Py_TPFLAGS_HAVE_INDEX: c_long = (1 << 17);
|
||||
|
||||
// Objects support type attribute cache
|
||||
pub const Py_TPFLAGS_HAVE_VERSION_TAG: c_long = (1 << 18);
|
||||
pub const Py_TPFLAGS_VALID_VERSION_TAG: c_long = (1 << 19);
|
||||
|
||||
/* Type is abstract and cannot be instantiated */
|
||||
pub const Py_TPFLAGS_IS_ABSTRACT: c_long = (1 << 20);
|
||||
|
||||
/* Has the new buffer protocol */
|
||||
pub const Py_TPFLAGS_HAVE_NEWBUFFER: c_long = (1 << 21);
|
||||
|
||||
/* These flags are used to determine if a type is a subclass. */
|
||||
pub const Py_TPFLAGS_INT_SUBCLASS: c_long = (1 << 23);
|
||||
pub const Py_TPFLAGS_LONG_SUBCLASS: c_long = (1 << 24);
|
||||
pub const Py_TPFLAGS_LIST_SUBCLASS: c_long = (1 << 25);
|
||||
pub const Py_TPFLAGS_TUPLE_SUBCLASS: c_long = (1 << 26);
|
||||
pub const Py_TPFLAGS_STRING_SUBCLASS: c_long = (1 << 27);
|
||||
pub const Py_TPFLAGS_UNICODE_SUBCLASS: c_long = (1 << 28);
|
||||
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);
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_long) -> c_int {
|
||||
(((*t).tp_flags & f) != 0) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_long) -> c_int {
|
||||
PyType_HasFeature(t, f)
|
||||
}
|
||||
|
||||
// Reference counting macros.
|
||||
#[inline]
|
||||
pub unsafe fn Py_INCREF(op: *mut PyObject) {
|
||||
if cfg!(py_sys_config = "Py_REF_DEBUG") {
|
||||
Py_IncRef(op)
|
||||
} else {
|
||||
(*op).ob_refcnt += 1
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_DECREF(op: *mut PyObject) {
|
||||
if cfg!(py_sys_config = "Py_REF_DEBUG") || cfg!(py_sys_config = "COUNT_ALLOCS") {
|
||||
Py_DecRef(op)
|
||||
} else {
|
||||
(*op).ob_refcnt -= 1;
|
||||
if (*op).ob_refcnt == 0 {
|
||||
(*Py_TYPE(op)).tp_dealloc.expect("Fail to get tp_dealloc")(op)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) {
|
||||
let tmp = *op;
|
||||
if !tmp.is_null() {
|
||||
*op = ptr::null_mut();
|
||||
Py_DECREF(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_XINCREF(op: *mut PyObject) {
|
||||
if !op.is_null() {
|
||||
Py_INCREF(op)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_XDECREF(op: *mut PyObject) {
|
||||
if !op.is_null() {
|
||||
Py_DECREF(op)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub fn Py_IncRef(o: *mut PyObject);
|
||||
pub fn Py_DecRef(o: *mut PyObject);
|
||||
|
||||
static mut _Py_NoneStruct: PyObject;
|
||||
static mut _Py_NotImplementedStruct: PyObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_None() -> *mut PyObject {
|
||||
&mut _Py_NoneStruct
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_NotImplemented() -> *mut PyObject {
|
||||
&mut _Py_NotImplementedStruct
|
||||
}
|
||||
|
||||
/* Rich comparison opcodes */
|
||||
pub const Py_LT: c_int = 0;
|
||||
pub const Py_LE: c_int = 1;
|
||||
pub const Py_EQ: c_int = 2;
|
||||
pub const Py_NE: c_int = 3;
|
||||
pub const Py_GT: c_int = 4;
|
||||
pub const Py_GE: c_int = 5;
|
||||
|
||||
#[inline]
|
||||
pub fn PyObject_Check(_arg1: *mut PyObject) -> c_int {
|
||||
1
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
fn _PyTrash_thread_deposit_object(o: *mut PyObject);
|
||||
fn _PyTrash_thread_destroy_chain();
|
||||
}
|
||||
|
||||
pub const PyTrash_UNWIND_LEVEL: c_int = 50;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_TRASHCAN<F: FnOnce() -> ()>(op: *mut PyObject, body: F) {
|
||||
let tstate = ffi2::pystate::PyThreadState_GET();
|
||||
if tstate.is_null() || (*tstate).trash_delete_nesting < PyTrash_UNWIND_LEVEL {
|
||||
if !tstate.is_null() {
|
||||
(*tstate).trash_delete_nesting += 1;
|
||||
}
|
||||
body();
|
||||
if !tstate.is_null() {
|
||||
(*tstate).trash_delete_nesting -= 1;
|
||||
if !(*tstate).trash_delete_later.is_null() && (*tstate).trash_delete_nesting <= 0 {
|
||||
_PyTrash_thread_destroy_chain();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_PyTrash_thread_deposit_object(op)
|
||||
}
|
||||
}
|
|
@ -1,297 +0,0 @@
|
|||
use crate::ffi2;
|
||||
use crate::ffi2::object::*;
|
||||
use crate::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 {
|
||||
PyObject_SetAttrString(o, attr_name, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_int {
|
||||
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,
|
||||
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;
|
||||
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,
|
||||
buffer: *mut *const c_char,
|
||||
buffer_len: *mut Py_ssize_t,
|
||||
) -> c_int;
|
||||
pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int;
|
||||
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: *mut *mut c_void,
|
||||
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 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;
|
||||
pub fn PyBuffer_Release(view: *mut Py_buffer);
|
||||
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) -> *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_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_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 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_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 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;
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[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 {
|
||||
None => false,
|
||||
Some(f) => f as *const c_void != _PyObject_NextNotImplemented as *const c_void,
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t {
|
||||
if ffi2::listobject::PyList_Check(o) != 0 {
|
||||
ffi2::listobject::PyList_GET_SIZE(o)
|
||||
} else {
|
||||
ffi2::tupleobject::PyTuple_GET_SIZE(o)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
|
||||
if ffi2::listobject::PyList_Check(o) != 0 {
|
||||
ffi2::listobject::PyList_GET_ITEM(o, i)
|
||||
} else {
|
||||
ffi2::tupleobject::PyTuple_GET_ITEM(o, i)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
#[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)
|
||||
}
|
||||
|
||||
pub const PY_ITERSEARCH_COUNT: c_int = 1;
|
||||
pub const PY_ITERSEARCH_INDEX: c_int = 2;
|
||||
pub const PY_ITERSEARCH_CONTAINS: c_int = 3;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMapping_DelItemString(o: *mut PyObject, key: *mut c_char) -> c_int {
|
||||
PyObject_DelItemString(o, key)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMapping_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int {
|
||||
PyObject_DelItem(o, key)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMapping_Keys(o: *mut PyObject) -> *mut PyObject {
|
||||
PyObject_CallMethod(o, "keys\0".as_ptr() as *mut c_char, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMapping_Values(o: *mut PyObject) -> *mut PyObject {
|
||||
PyObject_CallMethod(o, "values\0".as_ptr() as *mut c_char, ptr::null_mut())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject {
|
||||
PyObject_CallMethod(o, "items\0".as_ptr() as *mut c_char, ptr::null_mut())
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::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" {
|
||||
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_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_New(arg1: *mut PyTypeObject) -> *mut PyObject;
|
||||
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_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_Track(arg1: *mut c_void);
|
||||
pub fn PyObject_GC_UnTrack(arg1: *mut c_void);
|
||||
pub fn PyObject_GC_Del(arg1: *mut c_void);
|
||||
}
|
||||
|
||||
/// Test if a type has a GC head
|
||||
#[inline]
|
||||
#[allow(unused_parens)]
|
||||
pub unsafe fn PyType_IS_GC(t: *mut PyTypeObject) -> c_int {
|
||||
PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
|
||||
}
|
||||
|
||||
/// Test if an object has a GC head
|
||||
#[inline]
|
||||
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 {
|
||||
Some(tp_is_gc) => tp_is_gc(o) != 0,
|
||||
None => true,
|
||||
}) as c_int
|
||||
}
|
||||
|
||||
/* Test if a type supports weak references */
|
||||
#[inline]
|
||||
#[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
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
|
||||
pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o: *mut PyObject) -> *mut *mut PyObject {
|
||||
let weaklistoffset = (*Py_TYPE(o)).tp_weaklistoffset as isize;
|
||||
(o as *mut c_char).offset(weaklistoffset) as *mut *mut PyObject
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
use crate::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" {
|
||||
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;
|
||||
pub fn PyArena_AddPyObject(arg1: *mut PyArena, arg2: *mut PyObject) -> c_int;
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyCapsule_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
pub type PyCapsule_Destructor = unsafe extern "C" fn(o: *mut PyObject);
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int {
|
||||
(Py_TYPE(ob) == &mut PyCapsule_Type) as c_int
|
||||
}
|
||||
|
||||
#[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;
|
||||
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;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
#[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;
|
||||
pub static mut Py_InspectFlag: c_int;
|
||||
pub static mut Py_OptimizeFlag: c_int;
|
||||
pub static mut Py_NoSiteFlag: c_int;
|
||||
pub static mut Py_BytesWarningFlag: c_int;
|
||||
pub static mut Py_UseClassExceptionsFlag: c_int;
|
||||
pub static mut Py_FrozenFlag: c_int;
|
||||
pub static mut Py_TabcheckFlag: c_int;
|
||||
pub static mut Py_UnicodeFlag: c_int;
|
||||
pub static mut Py_IgnoreEnvironmentFlag: c_int;
|
||||
pub static mut Py_DivisionWarningFlag: c_int;
|
||||
pub static mut Py_DontWriteBytecodeFlag: c_int;
|
||||
pub static mut Py_NoUserSiteDirectory: c_int;
|
||||
pub static mut _Py_QnewFlag: c_int;
|
||||
pub static mut Py_Py3kWarningFlag: c_int;
|
||||
pub static mut Py_HashRandomizationFlag: c_int;
|
||||
|
||||
pub fn Py_FatalError(message: *const c_char);
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
use crate::ffi2::classobject::*;
|
||||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use crate::ffi2::stringobject::PyString_AS_STRING;
|
||||
#[cfg(py_sys_config = "Py_USING_UNICODE")]
|
||||
use crate::ffi2::unicodeobject::Py_UNICODE;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
#[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,
|
||||
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
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char {
|
||||
if PyClass_Check(x) != 0 {
|
||||
PyString_AS_STRING((*(x as *mut PyClassObject)).cl_name)
|
||||
} else {
|
||||
(*(x as *mut PyTypeObject)).tp_name
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject {
|
||||
if PyInstance_Check(x) != 0 {
|
||||
(*(x as *mut PyInstanceObject)).in_class as *mut PyObject
|
||||
} else {
|
||||
(*x).ob_type as *mut PyObject
|
||||
}
|
||||
}
|
||||
|
||||
#[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;
|
||||
pub static mut PyExc_GeneratorExit: *mut PyObject;
|
||||
pub static mut PyExc_StandardError: *mut PyObject;
|
||||
pub static mut PyExc_ArithmeticError: *mut PyObject;
|
||||
pub static mut PyExc_LookupError: *mut PyObject;
|
||||
pub static mut PyExc_AssertionError: *mut PyObject;
|
||||
pub static mut PyExc_AttributeError: *mut PyObject;
|
||||
pub static mut PyExc_EOFError: *mut PyObject;
|
||||
pub static mut PyExc_FloatingPointError: *mut PyObject;
|
||||
pub static mut PyExc_EnvironmentError: *mut PyObject;
|
||||
pub static mut PyExc_IOError: *mut PyObject;
|
||||
pub static mut PyExc_OSError: *mut PyObject;
|
||||
pub static mut PyExc_ImportError: *mut PyObject;
|
||||
pub static mut PyExc_IndexError: *mut PyObject;
|
||||
pub static mut PyExc_KeyError: *mut PyObject;
|
||||
pub static mut PyExc_KeyboardInterrupt: *mut PyObject;
|
||||
pub static mut PyExc_MemoryError: *mut PyObject;
|
||||
pub static mut PyExc_NameError: *mut PyObject;
|
||||
pub static mut PyExc_OverflowError: *mut PyObject;
|
||||
pub static mut PyExc_RuntimeError: *mut PyObject;
|
||||
pub static mut PyExc_NotImplementedError: *mut PyObject;
|
||||
pub static mut PyExc_SyntaxError: *mut PyObject;
|
||||
pub static mut PyExc_IndentationError: *mut PyObject;
|
||||
pub static mut PyExc_TabError: *mut PyObject;
|
||||
pub static mut PyExc_ReferenceError: *mut PyObject;
|
||||
pub static mut PyExc_SystemError: *mut PyObject;
|
||||
pub static mut PyExc_SystemExit: *mut PyObject;
|
||||
pub static mut PyExc_TypeError: *mut PyObject;
|
||||
pub static mut PyExc_UnboundLocalError: *mut PyObject;
|
||||
pub static mut PyExc_UnicodeError: *mut PyObject;
|
||||
pub static mut PyExc_UnicodeEncodeError: *mut PyObject;
|
||||
pub static mut PyExc_UnicodeDecodeError: *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;
|
||||
pub static mut PyExc_BufferError: *mut PyObject;
|
||||
pub static mut PyExc_MemoryErrorInst: *mut PyObject;
|
||||
pub static mut PyExc_RecursionErrorInst: *mut PyObject;
|
||||
pub static mut PyExc_Warning: *mut PyObject;
|
||||
pub static mut PyExc_UserWarning: *mut PyObject;
|
||||
pub static mut PyExc_DeprecationWarning: *mut PyObject;
|
||||
pub static mut PyExc_PendingDeprecationWarning: *mut PyObject;
|
||||
pub static mut PyExc_SyntaxWarning: *mut PyObject;
|
||||
pub static mut PyExc_RuntimeWarning: *mut PyObject;
|
||||
pub static mut PyExc_FutureWarning: *mut PyObject;
|
||||
pub static mut PyExc_ImportWarning: *mut PyObject;
|
||||
pub static mut PyExc_UnicodeWarning: *mut PyObject;
|
||||
pub static mut PyExc_BytesWarning: *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_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,
|
||||
doc: *mut c_char,
|
||||
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;
|
||||
}
|
||||
|
||||
#[cfg(py_sys_config = "Py_USING_UNICODE")]
|
||||
#[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,
|
||||
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;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
use libc::{c_void, size_t};
|
||||
|
||||
#[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);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
pub type Py_uintptr_t = ::libc::uintptr_t;
|
||||
pub type Py_intptr_t = ::libc::intptr_t;
|
||||
pub type Py_ssize_t = ::libc::ssize_t;
|
||||
pub type Py_hash_t = Py_ssize_t;
|
||||
pub type Py_uhash_t = ::libc::size_t;
|
||||
|
||||
pub const PY_SSIZE_T_MIN: Py_ssize_t = ::std::isize::MIN as Py_ssize_t;
|
||||
pub const PY_SSIZE_T_MAX: Py_ssize_t = ::std::isize::MAX as Py_ssize_t;
|
|
@ -1,104 +0,0 @@
|
|||
use crate::ffi2::frameobject::PyFrameObject;
|
||||
use crate::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;
|
||||
|
||||
/* The following values are used for 'what' for tracefunc functions: */
|
||||
pub const PyTrace_CALL: c_int = 0;
|
||||
pub const PyTrace_EXCEPTION: c_int = 1;
|
||||
pub const PyTrace_LINE: c_int = 2;
|
||||
pub const PyTrace_RETURN: c_int = 3;
|
||||
pub const PyTrace_C_CALL: c_int = 4;
|
||||
pub const PyTrace_C_EXCEPTION: c_int = 5;
|
||||
pub const PyTrace_C_RETURN: c_int = 6;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy)]
|
||||
pub struct PyThreadState {
|
||||
pub next: *mut PyThreadState,
|
||||
pub interp: *mut PyInterpreterState,
|
||||
pub frame: *mut PyFrameObject,
|
||||
pub recursion_depth: c_int,
|
||||
pub tracing: c_int,
|
||||
pub use_tracing: c_int,
|
||||
pub c_profilefunc: Option<Py_tracefunc>,
|
||||
pub c_tracefunc: Option<Py_tracefunc>,
|
||||
pub c_profileobj: *mut PyObject,
|
||||
pub c_traceobj: *mut PyObject,
|
||||
pub curexc_type: *mut PyObject,
|
||||
pub curexc_value: *mut PyObject,
|
||||
pub curexc_traceback: *mut PyObject,
|
||||
pub exc_type: *mut PyObject,
|
||||
pub exc_value: *mut PyObject,
|
||||
pub exc_traceback: *mut PyObject,
|
||||
pub dict: *mut PyObject,
|
||||
pub tick_counter: c_int,
|
||||
pub gilstate_counter: c_int,
|
||||
pub async_exc: *mut PyObject,
|
||||
pub thread_id: c_long,
|
||||
pub trash_delete_nesting: c_int,
|
||||
pub trash_delete_later: *mut PyObject,
|
||||
}
|
||||
|
||||
impl Clone for PyThreadState {
|
||||
#[inline]
|
||||
fn clone(&self) -> PyThreadState {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum PyGILState_STATE {
|
||||
PyGILState_LOCKED,
|
||||
PyGILState_UNLOCKED,
|
||||
}
|
||||
|
||||
#[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_Init(arg1: *mut PyThreadState);
|
||||
pub fn PyThreadState_Clear(arg1: *mut PyThreadState);
|
||||
pub fn PyThreadState_Delete(arg1: *mut PyThreadState);
|
||||
#[cfg(py_sys_config = "WITH_THREAD")]
|
||||
pub fn PyThreadState_DeleteCurrent();
|
||||
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 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 PyThreadState_Next(arg1: *mut PyThreadState) -> *mut PyThreadState;
|
||||
}
|
||||
|
||||
#[cfg(py_sys_config = "Py_DEBUG")]
|
||||
#[inline]
|
||||
pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
|
||||
PyThreadState_Get()
|
||||
}
|
||||
|
||||
#[cfg(not(py_sys_config = "Py_DEBUG"))]
|
||||
#[inline]
|
||||
pub unsafe fn PyThreadState_GET() -> *mut PyThreadState {
|
||||
_PyThreadState_Current
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
use crate::ffi2::code::*;
|
||||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyarena::PyArena;
|
||||
use crate::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_OBSOLETE: c_int = (CO_NESTED);
|
||||
pub const PyCF_SOURCE_IS_UTF8: c_int = 0x0100;
|
||||
pub const PyCF_DONT_IMPLY_DEDENT: c_int = 0x0200;
|
||||
pub const PyCF_ONLY_AST: c_int = 0x0400;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyCompilerFlags {
|
||||
cf_flags: c_int,
|
||||
}
|
||||
|
||||
#[allow(missing_copy_implementations)]
|
||||
pub enum Struct__mod {}
|
||||
#[allow(missing_copy_implementations)]
|
||||
pub enum Struct__node {}
|
||||
#[allow(missing_copy_implementations)]
|
||||
pub enum Struct_symtable {}
|
||||
|
||||
#[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);
|
||||
pub fn Py_GetPythonHome() -> *mut c_char;
|
||||
pub fn Py_Initialize();
|
||||
pub fn Py_InitializeEx(arg1: c_int);
|
||||
pub fn Py_Finalize();
|
||||
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,
|
||||
arg2: *const c_char,
|
||||
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 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,
|
||||
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,
|
||||
arg2: c_int,
|
||||
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,
|
||||
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 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_GetProgramFullPath() -> *mut c_char;
|
||||
pub fn Py_GetPrefix() -> *mut c_char;
|
||||
pub fn Py_GetExecPrefix() -> *mut c_char;
|
||||
pub fn Py_GetPath() -> *mut c_char;
|
||||
pub fn Py_GetVersion() -> *const c_char;
|
||||
pub fn Py_GetPlatform() -> *const c_char;
|
||||
pub fn Py_GetCopyright() -> *const c_char;
|
||||
pub fn Py_GetCompiler() -> *const c_char;
|
||||
pub fn Py_GetBuildInfo() -> *const c_char;
|
||||
fn _Py_svnversion() -> *const c_char;
|
||||
pub fn Py_SubversionRevision() -> *const c_char;
|
||||
pub fn Py_SubversionShortBranch() -> *const c_char;
|
||||
fn _Py_hgidentifier() -> *const c_char;
|
||||
fn _Py_hgversion() -> *const c_char;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyRange_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyRange_Check(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyRange_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
//enum PySetObject { /* representation hidden */ }
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PySet_Type: PyTypeObject;
|
||||
pub static mut PyFrozenSet_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int {
|
||||
let f: *mut PyTypeObject = &mut PyFrozenSet_Type;
|
||||
(Py_TYPE(ob) == f) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int {
|
||||
let s: *mut PyTypeObject = &mut PySet_Type;
|
||||
let f: *mut PyTypeObject = &mut PyFrozenSet_Type;
|
||||
(Py_TYPE(ob) == s || Py_TYPE(ob) == f) as 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
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int {
|
||||
let s: *mut PyTypeObject = &mut PySet_Type;
|
||||
(Py_TYPE(ob) == s || PyType_IsSubtype(Py_TYPE(ob), s) != 0) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyFrozenSet_Check(ob: *mut PyObject) -> c_int {
|
||||
let f: *mut PyTypeObject = &mut PyFrozenSet_Type;
|
||||
(Py_TYPE(ob) == f || PyType_IsSubtype(Py_TYPE(ob), f) != 0) as c_int
|
||||
}
|
||||
|
||||
#[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_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;
|
||||
//pub fn _PySet_NextEntry(set: *mut PyObject, pos: *mut Py_ssize_t,
|
||||
// key: *mut *mut PyObject,
|
||||
// hash: *mut c_long) -> c_int;
|
||||
pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject;
|
||||
//pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject)
|
||||
// -> c_int;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
static mut _Py_EllipsisObject: PyObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn Py_Ellipsis() -> *mut PyObject {
|
||||
&mut _Py_EllipsisObject
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PySliceObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub start: *mut PyObject,
|
||||
pub stop: *mut PyObject,
|
||||
pub step: *mut PyObject,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PySlice_Type: PyTypeObject;
|
||||
pub static mut PyEllipsis_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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,
|
||||
step: *mut Py_ssize_t,
|
||||
slicelength: *mut Py_ssize_t,
|
||||
) -> c_int;
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_int, c_long};
|
||||
|
||||
#[repr(C)]
|
||||
#[allow(missing_copy_implementations)]
|
||||
pub struct PyStringObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
pub ob_shash: c_long,
|
||||
pub ob_sstate: c_int,
|
||||
pub ob_sval: [c_char; 1],
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyBaseString_Type: PyTypeObject;
|
||||
pub static mut PyString_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyString_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyBaseString_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(
|
||||
Py_TYPE(op),
|
||||
Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS,
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyString_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyString_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyString_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
|
||||
(*(op as *mut PyStringObject)).ob_size
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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" {
|
||||
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_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,
|
||||
s: *mut *mut c_char,
|
||||
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_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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
encoding: *const c_char,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject;
|
||||
pub fn PyString_AsEncodedObject(
|
||||
str: *mut PyObject,
|
||||
encoding: *const c_char,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject;
|
||||
|
||||
/*
|
||||
pub fn PyString_Repr(arg1: *mut PyObject, arg2: c_int)
|
||||
-> *mut PyObject;
|
||||
pub fn _PyString_Eq(arg1: *mut PyObject, arg2: *mut PyObject)
|
||||
-> c_int;
|
||||
pub fn _PyString_FormatLong(arg1: *mut PyObject, arg2: c_int,
|
||||
arg3: c_int, arg4: c_int,
|
||||
arg5: *mut *mut c_char,
|
||||
arg6: *mut c_int) -> *mut PyObject;
|
||||
pub fn PyString_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 PyString_InternImmortal(arg1: *mut *mut PyObject);
|
||||
pub fn _Py_ReleaseInternedStrings();
|
||||
pub fn _PyString_Join(sep: *mut PyObject, x: *mut PyObject)
|
||||
-> *mut PyObject;
|
||||
pub fn PyString_AsEncodedString(str: *mut PyObject,
|
||||
encoding: *const c_char,
|
||||
errors: *const c_char)
|
||||
-> *mut PyObject;
|
||||
pub fn PyString_AsDecodedString(str: *mut PyObject,
|
||||
encoding: *const c_char,
|
||||
errors: *const c_char)
|
||||
-> *mut PyObject;
|
||||
|
||||
pub fn _PyString_InsertThousandsGroupingLocale(buffer:
|
||||
*mut c_char,
|
||||
n_buffer: Py_ssize_t,
|
||||
digits:
|
||||
*mut c_char,
|
||||
n_digits: Py_ssize_t,
|
||||
min_width: Py_ssize_t)
|
||||
-> Py_ssize_t;
|
||||
pub fn _PyString_InsertThousandsGrouping(buffer: *mut c_char,
|
||||
n_buffer: Py_ssize_t,
|
||||
digits: *mut c_char,
|
||||
n_digits: Py_ssize_t,
|
||||
min_width: Py_ssize_t,
|
||||
grouping: *const c_char,
|
||||
thousands_sep:
|
||||
*const c_char)
|
||||
-> Py_ssize_t;
|
||||
pub fn _PyBytes_FormatAdvanced(obj: *mut PyObject,
|
||||
format_spec: *mut c_char,
|
||||
format_spec_len: Py_ssize_t)
|
||||
-> *mut PyObject;*/
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
use crate::ffi2::object::PyObject;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_char, c_int};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyMemberDef {
|
||||
pub name: *mut c_char,
|
||||
pub type_code: c_int,
|
||||
pub offset: Py_ssize_t,
|
||||
pub flags: c_int,
|
||||
pub doc: *mut c_char,
|
||||
}
|
||||
|
||||
/* Types */
|
||||
pub const T_SHORT: c_int = 0;
|
||||
pub const T_INT: c_int = 1;
|
||||
pub const T_LONG: c_int = 2;
|
||||
pub const T_FLOAT: c_int = 3;
|
||||
pub const T_DOUBLE: c_int = 4;
|
||||
pub const T_STRING: c_int = 5;
|
||||
pub const T_OBJECT: c_int = 6;
|
||||
/* XXX the ordering here is weird for binary compatibility */
|
||||
pub const T_CHAR: c_int = 7; /* 1-character string */
|
||||
pub const T_BYTE: c_int = 8; /* 8-bit signed int */
|
||||
/* unsigned variants: */
|
||||
pub const T_UBYTE: c_int = 9;
|
||||
pub const T_USHORT: c_int = 10;
|
||||
pub const T_UINT: c_int = 11;
|
||||
pub const T_ULONG: c_int = 12;
|
||||
|
||||
/* Added by Jack: strings contained in the structure */
|
||||
pub const T_STRING_INPLACE: c_int = 13;
|
||||
|
||||
/* Added by Lillo: bools contained in the structure (assumed char) */
|
||||
pub const T_BOOL: c_int = 14;
|
||||
|
||||
pub const T_OBJECT_EX: c_int = 16; /* Like T_OBJECT, but raises AttributeError
|
||||
when the value is NULL, instead of
|
||||
converting to None. */
|
||||
|
||||
pub const T_LONGLONG: c_int = 17;
|
||||
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 */
|
||||
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" {
|
||||
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;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
use crate::ffi2::frameobject::PyFrameObject;
|
||||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyTracebackObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub tb_next: *mut PyTracebackObject,
|
||||
pub tb_frame: *mut PyFrameObject,
|
||||
pub tb_lasti: c_int,
|
||||
pub tb_lineno: c_int,
|
||||
}
|
||||
|
||||
#[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 static mut PyTraceBack_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int {
|
||||
(Py_TYPE(op) == &mut PyTraceBack_Type) as c_int
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyTupleObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub ob_size: Py_ssize_t,
|
||||
pub ob_item: [*mut PyObject; 1],
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyTuple_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyTuple_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyTuple_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyTuple_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
/// Macro, trading safety for speed
|
||||
#[inline]
|
||||
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)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
|
||||
Py_SIZE(op)
|
||||
}
|
||||
|
||||
/// Macro, *only* to be used to fill in brand new tuples
|
||||
#[inline]
|
||||
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;
|
||||
}
|
||||
|
||||
#[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_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);
|
||||
pub fn PyTuple_ClearFreeList() -> c_int;
|
||||
}
|
|
@ -1,687 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::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;
|
||||
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
|
||||
pub const Py_UNICODE_SIZE: Py_ssize_t = 2;
|
||||
|
||||
pub type Py_UCS4 = u32;
|
||||
|
||||
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
|
||||
pub type Py_UNICODE = u32;
|
||||
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
|
||||
pub type Py_UNICODE = u16;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyUnicodeObject {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub length: Py_ssize_t,
|
||||
pub data: *mut Py_UNICODE,
|
||||
pub hash: c_long,
|
||||
pub defenc: *mut PyObject,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
pub static mut PyUnicode_Type: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int {
|
||||
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int {
|
||||
let u: *mut PyTypeObject = &mut PyUnicode_Type;
|
||||
(Py_TYPE(op) == u) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyUnicode_GET_SIZE(o: *mut PyObject) -> Py_ssize_t {
|
||||
(*(o as *mut PyUnicodeObject)).length
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyUnicode_GET_DATA_SIZE(o: *mut PyObject) -> Py_ssize_t {
|
||||
(*(o as *mut PyUnicodeObject)).length * Py_UNICODE_SIZE
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyUnicode_AS_UNICODE(o: *mut PyObject) -> *mut Py_UNICODE {
|
||||
(*(o as *mut PyUnicodeObject)).data
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyUnicode_AS_DATA(o: *mut PyObject) -> *const c_char {
|
||||
(*(o as *mut PyUnicodeObject)).data as *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" {
|
||||
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_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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
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;
|
||||
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_GetDefaultEncoding() -> *const c_char;
|
||||
fn PyUnicodeUCS4_SetDefaultEncoding(encoding: *const c_char) -> c_int;
|
||||
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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
errors: *const c_char,
|
||||
byteorder: *mut c_int,
|
||||
) -> *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,
|
||||
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,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
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,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject;
|
||||
fn PyUnicodeUCS4_DecodeASCII(
|
||||
string: *const c_char,
|
||||
length: Py_ssize_t,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject;
|
||||
fn PyUnicodeUCS4_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject;
|
||||
fn PyUnicodeUCS4_EncodeASCII(
|
||||
data: *const Py_UNICODE,
|
||||
length: Py_ssize_t,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
mapping: *mut PyObject,
|
||||
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,
|
||||
output: *mut c_char,
|
||||
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_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_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_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 _PyUnicodeUCS4_IsLowercase(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsUppercase(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsTitlecase(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsWhitespace(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsLinebreak(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_ToLowercase(ch: Py_UNICODE) -> Py_UNICODE;
|
||||
fn _PyUnicodeUCS4_ToUppercase(ch: Py_UNICODE) -> Py_UNICODE;
|
||||
fn _PyUnicodeUCS4_ToTitlecase(ch: Py_UNICODE) -> Py_UNICODE;
|
||||
fn _PyUnicodeUCS4_ToDecimalDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_ToDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_ToNumeric(ch: Py_UNICODE) -> c_double;
|
||||
fn _PyUnicodeUCS4_IsDecimalDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsNumeric(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS4_IsAlpha(ch: Py_UNICODE) -> c_int;
|
||||
}
|
||||
|
||||
#[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;
|
||||
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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
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;
|
||||
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_GetDefaultEncoding() -> *const c_char;
|
||||
fn PyUnicodeUCS2_SetDefaultEncoding(encoding: *const c_char) -> c_int;
|
||||
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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
encoding: *const c_char,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
errors: *const c_char,
|
||||
byteorder: *mut c_int,
|
||||
) -> *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,
|
||||
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,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
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,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject;
|
||||
fn PyUnicodeUCS2_DecodeASCII(
|
||||
string: *const c_char,
|
||||
length: Py_ssize_t,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject;
|
||||
fn PyUnicodeUCS2_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject;
|
||||
fn PyUnicodeUCS2_EncodeASCII(
|
||||
data: *const Py_UNICODE,
|
||||
length: Py_ssize_t,
|
||||
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,
|
||||
length: Py_ssize_t,
|
||||
mapping: *mut PyObject,
|
||||
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,
|
||||
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;
|
||||
fn _PyUnicodeUCS2_IsLowercase(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsUppercase(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsTitlecase(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsWhitespace(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsLinebreak(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_ToLowercase(ch: Py_UNICODE) -> Py_UNICODE;
|
||||
fn _PyUnicodeUCS2_ToUppercase(ch: Py_UNICODE) -> Py_UNICODE;
|
||||
fn _PyUnicodeUCS2_ToTitlecase(ch: Py_UNICODE) -> Py_UNICODE;
|
||||
fn _PyUnicodeUCS2_ToDecimalDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_ToDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_ToNumeric(ch: Py_UNICODE) -> c_double;
|
||||
fn _PyUnicodeUCS2_IsDecimalDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsDigit(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsNumeric(ch: Py_UNICODE) -> c_int;
|
||||
fn _PyUnicodeUCS2_IsAlpha(ch: Py_UNICODE) -> c_int;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
|
||||
pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject {
|
||||
PyUnicodeUCS4_FromStringAndSize(u, size)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
|
||||
pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject {
|
||||
PyUnicodeUCS2_FromStringAndSize(u, size)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
|
||||
pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject {
|
||||
PyUnicodeUCS4_AsUTF8String(u)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
|
||||
pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject {
|
||||
PyUnicodeUCS2_AsUTF8String(u)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")]
|
||||
pub unsafe fn PyUnicode_FromEncodedObject(
|
||||
obj: *mut PyObject,
|
||||
encoding: *const c_char,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject {
|
||||
PyUnicodeUCS4_FromEncodedObject(obj, encoding, errors)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))]
|
||||
pub unsafe fn PyUnicode_FromEncodedObject(
|
||||
obj: *mut PyObject,
|
||||
encoding: *const c_char,
|
||||
errors: *const c_char,
|
||||
) -> *mut PyObject {
|
||||
PyUnicodeUCS2_FromEncodedObject(obj, encoding, errors)
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
use crate::ffi2::object::PyObject;
|
||||
use crate::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,
|
||||
arg2: *const c_char,
|
||||
arg3: *const c_char,
|
||||
arg4: c_int,
|
||||
arg5: *const c_char,
|
||||
arg6: *mut PyObject,
|
||||
) -> c_int;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int {
|
||||
PyErr_WarnEx(category, msg, 1)
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
use crate::ffi2::object::*;
|
||||
use crate::ffi2::pyport::Py_ssize_t;
|
||||
use std::os::raw::{c_int, c_long};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PyWeakReference {
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_next: *mut PyObject,
|
||||
#[cfg(py_sys_config = "Py_TRACE_REFS")]
|
||||
pub _ob_prev: *mut PyObject,
|
||||
pub ob_refcnt: Py_ssize_t,
|
||||
pub ob_type: *mut PyTypeObject,
|
||||
pub wr_object: *mut PyObject,
|
||||
pub wr_callback: *mut PyObject,
|
||||
pub hash: c_long,
|
||||
pub wr_prev: *mut PyWeakReference,
|
||||
pub wr_next: *mut PyWeakReference,
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, link(name = "pythonXY"))]
|
||||
extern "C" {
|
||||
static mut _PyWeakref_RefType: PyTypeObject;
|
||||
static mut _PyWeakref_ProxyType: PyTypeObject;
|
||||
static mut _PyWeakref_CallableProxyType: PyTypeObject;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int {
|
||||
PyObject_TypeCheck(op, &mut _PyWeakref_RefType)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
|
||||
(Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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;
|
||||
pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject;
|
||||
|
||||
pub fn _PyWeakref_GetWeakrefCount(head: *mut PyWeakReference) -> Py_ssize_t;
|
||||
pub fn _PyWeakref_ClearRef(slf: *mut PyWeakReference);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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()
|
||||
}
|
||||
}
|
|
@ -80,7 +80,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
|
||||
pytype_drop::<Self>(py, obj);
|
||||
|
||||
|
@ -108,29 +107,4 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
|
||||
pytype_drop::<Self>(py, obj);
|
||||
|
||||
if let Some(obj) = <Self as PyObjectWithFreeList>::get_free_list().insert(obj) {
|
||||
match Self::type_object().tp_free {
|
||||
Some(free) => free(obj as *mut c_void),
|
||||
None => {
|
||||
let ty = ffi::Py_TYPE(obj);
|
||||
if ffi::PyType_IS_GC(ty) != 0 {
|
||||
ffi::PyObject_GC_Del(obj as *mut c_void);
|
||||
} else {
|
||||
ffi::PyObject_Free(obj as *mut c_void);
|
||||
}
|
||||
|
||||
// For heap types, PyType_GenericAlloc calls INCREF on the type objects,
|
||||
// so we need to call DECREF here:
|
||||
if ffi::PyType_HasFeature(ty, ffi::Py_TPFLAGS_HEAPTYPE) != 0 {
|
||||
ffi::Py_DECREF(ty as *mut ffi::PyObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -140,10 +140,6 @@ pub use inventory;
|
|||
/// Raw ffi declarations for the c interface of python
|
||||
pub mod ffi;
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
mod ffi2;
|
||||
|
||||
#[cfg(Py_3)]
|
||||
mod ffi3;
|
||||
|
||||
pub mod buffer;
|
||||
|
@ -167,10 +163,7 @@ pub mod types;
|
|||
|
||||
/// The proc macros, which are also part of the prelude
|
||||
pub mod proc_macro {
|
||||
#[cfg(not(Py_3))]
|
||||
pub use pyo3cls::pymodule2 as pymodule;
|
||||
#[cfg(Py_3)]
|
||||
pub use pyo3cls::pymodule3 as pymodule;
|
||||
pub use pyo3cls::pymodule;
|
||||
/// The proc macro attributes
|
||||
pub use pyo3cls::{pyclass, pyfunction, pymethods, pyproto};
|
||||
}
|
||||
|
@ -198,7 +191,6 @@ macro_rules! wrap_pyfunction {
|
|||
/// Returns a function that takes a [Python] instance and returns a python module.
|
||||
///
|
||||
/// Use this together with `#[pymodule]` and [types::PyModule::add_wrapped].
|
||||
#[cfg(Py_3)]
|
||||
#[macro_export]
|
||||
macro_rules! wrap_pymodule {
|
||||
($module_name:ident) => {{
|
||||
|
@ -209,7 +201,7 @@ macro_rules! wrap_pymodule {
|
|||
}
|
||||
|
||||
m! {
|
||||
&|py| unsafe { crate::PyObject::from_owned_ptr(py, "method"()) }
|
||||
&|py| unsafe { pyo3::PyObject::from_owned_ptr(py, "method"()) }
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -23,10 +23,5 @@ pub use crate::{
|
|||
pub use crate::types::PyModule;
|
||||
// This is required for the constructor
|
||||
pub use crate::PyRawObject;
|
||||
pub use pyo3cls::pymodule;
|
||||
pub use pyo3cls::{pyclass, pyfunction, pymethods, pyproto};
|
||||
|
||||
#[cfg(Py_3)]
|
||||
pub use pyo3cls::pymodule3 as pymodule;
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
pub use pyo3cls::pymodule2 as pymodule;
|
||||
|
|
|
@ -199,11 +199,8 @@ pub trait PyObjectAlloc: PyTypeInfo + Sized {
|
|||
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
|
||||
Self::drop(py, obj);
|
||||
|
||||
#[cfg(Py_3)]
|
||||
{
|
||||
if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 {
|
||||
return;
|
||||
}
|
||||
if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
match Self::type_object().tp_free {
|
||||
|
@ -394,7 +391,7 @@ where
|
|||
// properties
|
||||
let mut props = py_class_properties::<T>();
|
||||
|
||||
if cfg!(Py_3) && has_dict {
|
||||
if has_dict {
|
||||
props.push(ffi::PyGetSetDef_DICT);
|
||||
}
|
||||
if !props.is_empty() {
|
||||
|
@ -415,7 +412,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
fn async_methods<T>(type_info: &mut ffi::PyTypeObject) {
|
||||
if let Some(meth) = <T as class::pyasync::PyAsyncProtocolImpl>::tp_as_async() {
|
||||
type_info.tp_as_async = Box::into_raw(Box::new(meth));
|
||||
|
@ -424,9 +420,6 @@ fn async_methods<T>(type_info: &mut ffi::PyTypeObject) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
fn async_methods<T>(_type_info: &mut ffi::PyTypeObject) {}
|
||||
|
||||
unsafe extern "C" fn tp_dealloc_callback<T>(obj: *mut ffi::PyObject)
|
||||
where
|
||||
T: PyObjectAlloc,
|
||||
|
@ -435,8 +428,6 @@ where
|
|||
let py = Python::assume_gil_acquired();
|
||||
<T as PyObjectAlloc>::dealloc(py, obj)
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
fn py_class_flags<T: PyTypeInfo>(type_object: &mut ffi::PyTypeObject) {
|
||||
if type_object.tp_traverse != None
|
||||
|| type_object.tp_clear != None
|
||||
|
@ -451,25 +442,6 @@ fn py_class_flags<T: PyTypeInfo>(type_object: &mut ffi::PyTypeObject) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
fn py_class_flags<T: PyTypeInfo>(type_object: &mut ffi::PyTypeObject) {
|
||||
if type_object.tp_traverse != None
|
||||
|| type_object.tp_clear != None
|
||||
|| T::FLAGS & PY_TYPE_FLAG_GC != 0
|
||||
{
|
||||
type_object.tp_flags =
|
||||
ffi::Py_TPFLAGS_DEFAULT | ffi::Py_TPFLAGS_CHECKTYPES | ffi::Py_TPFLAGS_HAVE_GC;
|
||||
} else {
|
||||
type_object.tp_flags = ffi::Py_TPFLAGS_DEFAULT | ffi::Py_TPFLAGS_CHECKTYPES;
|
||||
}
|
||||
if !type_object.tp_as_buffer.is_null() {
|
||||
type_object.tp_flags |= ffi::Py_TPFLAGS_HAVE_NEWBUFFER;
|
||||
}
|
||||
if T::FLAGS & PY_TYPE_FLAG_BASETYPE != 0 {
|
||||
type_object.tp_flags |= ffi::Py_TPFLAGS_BASETYPE;
|
||||
}
|
||||
}
|
||||
|
||||
fn py_class_method_defs<T: PyMethodsProtocol>() -> PyResult<(
|
||||
Option<ffi::newfunc>,
|
||||
Option<ffi::initproc>,
|
||||
|
@ -532,16 +504,12 @@ fn py_class_method_defs<T: PyMethodsProtocol>() -> PyResult<(
|
|||
Ok((new, init, call, defs))
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
fn py_class_async_methods<T>(defs: &mut Vec<ffi::PyMethodDef>) {
|
||||
for def in <T as class::pyasync::PyAsyncProtocolImpl>::methods() {
|
||||
defs.push(def.as_method_def());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
fn py_class_async_methods<T>(_defs: &mut Vec<ffi::PyMethodDef>) {}
|
||||
|
||||
fn py_class_properties<T: PyMethodsProtocol>() -> Vec<ffi::PyGetSetDef> {
|
||||
let mut defs = HashMap::new();
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::instance::PyNativeType;
|
|||
use crate::object::PyObject;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
use std::ops::*;
|
||||
use std::os::raw::c_double;
|
||||
|
||||
|
@ -30,7 +29,7 @@ impl PyComplex {
|
|||
unsafe { ffi::PyComplex_ImagAsDouble(self.as_ptr()) }
|
||||
}
|
||||
/// Returns `|self|`.
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub fn abs(&self) -> c_double {
|
||||
unsafe {
|
||||
let val = (*(self.as_ptr() as *mut ffi::PyComplexObject)).cval;
|
||||
|
@ -38,7 +37,7 @@ impl PyComplex {
|
|||
}
|
||||
}
|
||||
/// Returns `self ** other`
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
pub fn pow(&self, other: &PyComplex) -> &PyComplex {
|
||||
unsafe {
|
||||
self.py()
|
||||
|
@ -47,7 +46,7 @@ impl PyComplex {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[inline(always)]
|
||||
unsafe fn complex_operation(
|
||||
l: &PyComplex,
|
||||
|
@ -59,7 +58,7 @@ unsafe fn complex_operation(
|
|||
ffi::PyComplex_FromCComplex(operation(l_val, r_val))
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl<'py> Add for &'py PyComplex {
|
||||
type Output = &'py PyComplex;
|
||||
fn add(self, other: &'py PyComplex) -> &'py PyComplex {
|
||||
|
@ -70,7 +69,7 @@ impl<'py> Add for &'py PyComplex {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl<'py> Sub for &'py PyComplex {
|
||||
type Output = &'py PyComplex;
|
||||
fn sub(self, other: &'py PyComplex) -> &'py PyComplex {
|
||||
|
@ -81,7 +80,7 @@ impl<'py> Sub for &'py PyComplex {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl<'py> Mul for &'py PyComplex {
|
||||
type Output = &'py PyComplex;
|
||||
fn mul(self, other: &'py PyComplex) -> &'py PyComplex {
|
||||
|
@ -92,7 +91,7 @@ impl<'py> Mul for &'py PyComplex {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl<'py> Div for &'py PyComplex {
|
||||
type Output = &'py PyComplex;
|
||||
fn div(self, other: &'py PyComplex) -> &'py PyComplex {
|
||||
|
@ -103,7 +102,7 @@ impl<'py> Div for &'py PyComplex {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
impl<'py> Neg for &'py PyComplex {
|
||||
type Output = &'py PyComplex;
|
||||
fn neg(self) -> &'py PyComplex {
|
||||
|
@ -153,7 +152,7 @@ mod complex_conversion {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[allow(clippy::float_cmp)] // The comparison is for an error value
|
||||
impl<'source> FromPyObject<'source> for Complex<$float> {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Complex<$float>> {
|
||||
|
@ -167,7 +166,7 @@ mod complex_conversion {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[cfg(all(Py_LIMITED_API, Py_3))]
|
||||
#[cfg(Py_LIMITED_API)]
|
||||
#[allow(clippy::float_cmp)] // The comparison is for an error value
|
||||
impl<'source> FromPyObject<'source> for Complex<$float> {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Complex<$float>> {
|
||||
|
@ -228,7 +227,7 @@ mod test {
|
|||
assert_eq!(complex.imag(), 1.2);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_add() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -240,7 +239,7 @@ mod test {
|
|||
assert_approx_eq!(res.imag(), 3.8);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_sub() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -252,7 +251,7 @@ mod test {
|
|||
assert_approx_eq!(res.imag(), -1.4);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_mul() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -264,7 +263,7 @@ mod test {
|
|||
assert_approx_eq!(res.imag(), 9.0);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_div() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -276,7 +275,7 @@ mod test {
|
|||
assert_approx_eq!(res.imag(), -0.8505154639175257);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_neg() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -287,7 +286,7 @@ mod test {
|
|||
assert_approx_eq!(res.imag(), -1.2);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_abs() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -296,7 +295,7 @@ mod test {
|
|||
assert_approx_eq!(val.abs(), 3.2310988842807022);
|
||||
}
|
||||
|
||||
#[cfg(any(not(Py_LIMITED_API), not(Py_3)))]
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
#[test]
|
||||
fn test_pow() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
|
|
@ -15,19 +15,12 @@ pub use self::floatob::PyFloat;
|
|||
pub use self::iterator::PyIterator;
|
||||
pub use self::list::PyList;
|
||||
pub use self::module::PyModule;
|
||||
#[cfg(not(Py_3))]
|
||||
pub use self::num2::{PyInt, PyLong};
|
||||
#[cfg(Py_3)]
|
||||
pub use self::num3::PyLong;
|
||||
#[cfg(Py_3)]
|
||||
pub use self::num3::PyLong as PyInt;
|
||||
pub use self::num::PyLong;
|
||||
pub use self::num::PyLong as PyInt;
|
||||
pub use self::sequence::PySequence;
|
||||
pub use self::set::{PyFrozenSet, PySet};
|
||||
pub use self::slice::{PySlice, PySliceIndices};
|
||||
#[cfg(Py_3)]
|
||||
pub use self::string::{PyBytes, PyString, PyString as PyUnicode};
|
||||
#[cfg(not(Py_3))]
|
||||
pub use self::string2::{PyBytes, PyString, PyUnicode};
|
||||
pub use self::tuple::PyTuple;
|
||||
pub use self::typeobject::PyType;
|
||||
|
||||
|
@ -173,24 +166,10 @@ mod floatob;
|
|||
mod iterator;
|
||||
mod list;
|
||||
mod module;
|
||||
mod num;
|
||||
mod sequence;
|
||||
mod set;
|
||||
mod slice;
|
||||
mod stringutils;
|
||||
mod string;
|
||||
mod tuple;
|
||||
mod typeobject;
|
||||
|
||||
#[macro_use]
|
||||
mod num_common;
|
||||
|
||||
#[cfg(Py_3)]
|
||||
mod num3;
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
mod num2;
|
||||
|
||||
#[cfg(Py_3)]
|
||||
mod string;
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
mod string2;
|
||||
|
|
|
@ -45,7 +45,6 @@ impl PyModule {
|
|||
/// 'file_name' is the file name to associate with the module
|
||||
/// (this is used when Python reports errors, for example)
|
||||
/// 'module_name' is the name to give the module
|
||||
#[cfg(Py_3)]
|
||||
pub fn from_code<'p>(
|
||||
py: Python<'p>,
|
||||
code: &str,
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
//! common macros for num2.rs and num3.rs
|
||||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{FromPyObject, IntoPyObject, ToPyObject};
|
||||
use num_traits::cast::cast;
|
||||
use std::i64;
|
||||
use std::os::raw::c_int;
|
||||
use std::os::raw::{c_long, c_uchar};
|
||||
|
||||
pub(super) fn err_if_invalid_value<T: PartialEq + Copy>(
|
||||
py: Python,
|
||||
|
@ -102,6 +114,133 @@ pub(super) const IS_LITTLE_ENDIAN: c_int = 1;
|
|||
#[cfg(not(target_endian = "little"))]
|
||||
pub(super) const IS_LITTLE_ENDIAN: c_int = 0;
|
||||
|
||||
/// Represents a Python `int` object.
|
||||
///
|
||||
/// You can usually avoid directly working with this type
|
||||
/// by using [`ToPyObject`](trait.ToPyObject.html)
|
||||
/// and [extract](struct.PyObject.html#method.extract)
|
||||
/// with the primitive Rust integer types.
|
||||
#[repr(transparent)]
|
||||
pub struct PyLong(PyObject);
|
||||
|
||||
pyobject_native_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check);
|
||||
|
||||
macro_rules! int_fits_c_long (
|
||||
($rust_type:ty) => (
|
||||
impl ToPyObject for $rust_type {
|
||||
#![cfg_attr(feature="cargo-clippy", allow(clippy::cast_lossless))]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(*self as c_long))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for $rust_type {
|
||||
#![cfg_attr(feature="cargo-clippy", allow(clippy::cast_lossless))]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(self as c_long))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'source> FromPyObject<'source> for $rust_type {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Self> {
|
||||
let ptr = obj.as_ptr();
|
||||
let val = unsafe {
|
||||
let num = ffi::PyNumber_Index(ptr);
|
||||
if num.is_null() {
|
||||
Err(PyErr::fetch(obj.py()))
|
||||
} else {
|
||||
let val = err_if_invalid_value(obj.py(), -1, ffi::PyLong_AsLong(num));
|
||||
ffi::Py_DECREF(num);
|
||||
val
|
||||
}
|
||||
}?;
|
||||
match cast::<c_long, $rust_type>(val) {
|
||||
Some(v) => Ok(v),
|
||||
None => Err(exceptions::OverflowError.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! int_convert_u64_or_i64 (
|
||||
($rust_type:ty, $pylong_from_ll_or_ull:expr, $pylong_as_ll_or_ull:expr) => (
|
||||
impl ToPyObject for $rust_type {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, $pylong_from_ll_or_ull(*self))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for $rust_type {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, $pylong_from_ll_or_ull(self))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'source> FromPyObject<'source> for $rust_type {
|
||||
fn extract(ob: &'source PyAny) -> PyResult<$rust_type>
|
||||
{
|
||||
let ptr = ob.as_ptr();
|
||||
unsafe {
|
||||
let num = ffi::PyNumber_Index(ptr);
|
||||
if num.is_null() {
|
||||
Err(PyErr::fetch(ob.py()))
|
||||
} else {
|
||||
let result = err_if_invalid_value(ob.py(), !0, $pylong_as_ll_or_ull(num));
|
||||
ffi::Py_DECREF(num);
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
int_fits_c_long!(i8);
|
||||
int_fits_c_long!(u8);
|
||||
int_fits_c_long!(i16);
|
||||
int_fits_c_long!(u16);
|
||||
int_fits_c_long!(i32);
|
||||
|
||||
// If c_long is 64-bits, we can use more types with int_fits_c_long!:
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(u32);
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_fits_larger_int!(u32, u64);
|
||||
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(i64);
|
||||
|
||||
// manual implementation for i64 on systems with 32-bit long
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_convert_u64_or_i64!(i64, ffi::PyLong_FromLongLong, ffi::PyLong_AsLongLong);
|
||||
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(isize);
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_fits_larger_int!(isize, i64);
|
||||
|
||||
int_fits_larger_int!(usize, u64);
|
||||
|
||||
// u64 has a manual implementation as it never fits into signed long
|
||||
int_convert_u64_or_i64!(
|
||||
u64,
|
||||
ffi::PyLong_FromUnsignedLongLong,
|
||||
ffi::PyLong_AsUnsignedLongLong
|
||||
);
|
||||
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
int_convert_bignum!(i128, 16, IS_LITTLE_ENDIAN, 1);
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
int_convert_bignum!(u128, 16, IS_LITTLE_ENDIAN, 0);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::Python;
|
||||
|
@ -207,4 +346,59 @@ mod test {
|
|||
assert!(err.is_instance::<exceptions::OverflowError>(py));
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! test_common (
|
||||
($test_mod_name:ident, $t:ty) => (
|
||||
mod $test_mod_name {
|
||||
use crate::exceptions;
|
||||
use crate::ToPyObject;
|
||||
use crate::Python;
|
||||
|
||||
#[test]
|
||||
fn from_py_string_type_error() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = ("123").to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance::<exceptions::TypeError>(py));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_py_float_type_error() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = (12.3).to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance::<exceptions::TypeError>(py));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_py_object_and_back() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let val = 123 as $t;
|
||||
let obj = val.to_object(py);
|
||||
assert_eq!(obj.extract::<$t>(py).unwrap(), val as $t);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
test_common!(i8, i8);
|
||||
test_common!(u8, u8);
|
||||
test_common!(i16, i16);
|
||||
test_common!(u16, u16);
|
||||
test_common!(i32, i32);
|
||||
test_common!(u32, u32);
|
||||
test_common!(i64, i64);
|
||||
test_common!(u64, u64);
|
||||
test_common!(isize, isize);
|
||||
test_common!(usize, usize);
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
test_common!(i128, i128);
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
test_common!(u128, u128);
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use super::num_common::{err_if_invalid_value, IS_LITTLE_ENDIAN};
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
use crate::instance::{Py, PyNativeType};
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::IntoPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{FromPyObject, IntoPyObject, ToPyObject};
|
||||
use num_traits::cast::cast;
|
||||
use std::os::raw::{c_long, c_uchar};
|
||||
|
||||
/// Represents a Python `int` object.
|
||||
///
|
||||
/// Note that in Python 2.x, `int` and `long` are different types.
|
||||
///
|
||||
/// You can usually avoid directly working with this type
|
||||
/// by using [`ToPyObject`](trait.ToPyObject.html)
|
||||
/// and [extract](struct.PyObject.html#method.extract)
|
||||
/// with the primitive Rust integer types.
|
||||
#[repr(transparent)]
|
||||
pub struct PyInt(PyObject);
|
||||
|
||||
pyobject_native_type!(PyInt, ffi::PyInt_Type, ffi::PyInt_Check);
|
||||
|
||||
/// In Python 2.x, represents a Python `long` object.
|
||||
/// Both `PyInt` and `PyLong` refer to the same type on Python 3.x.
|
||||
///
|
||||
/// You can usually avoid directly working with this type
|
||||
/// by using [`ToPyObject`](trait.ToPyObject.html)
|
||||
/// and [extract](struct.PyObject.html#method.extract)
|
||||
/// with the primitive Rust integer types.
|
||||
pub struct PyLong(PyObject);
|
||||
|
||||
pyobject_native_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check);
|
||||
|
||||
impl PyInt {
|
||||
/// Creates a new Python 2.7 `int` object.
|
||||
///
|
||||
/// Note: you might want to call `val.to_object(py)` instead
|
||||
/// to avoid truncation if the value does not fit into a `c_long`,
|
||||
/// and to make your code compatible with Python 3.x.
|
||||
pub fn new(_py: Python, val: c_long) -> Py<PyInt> {
|
||||
unsafe { Py::from_owned_ptr_or_panic(ffi::PyLong_FromLong(val)) }
|
||||
}
|
||||
|
||||
/// Gets the value of this integer.
|
||||
///
|
||||
/// Warning: `PyInt::value()` is only supported for Python 2.7 `int` objects,
|
||||
/// but not for `long` objects.
|
||||
/// In almost all cases, you can avoid the distinction between these types
|
||||
/// by simply calling `obj.extract::<i32>()`.
|
||||
pub fn value(&self) -> c_long {
|
||||
unsafe { ffi::PyInt_AS_LONG(self.0.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! int_fits_c_long(
|
||||
($rust_type:ty) => (
|
||||
impl ToPyObject for $rust_type {
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, ffi::PyInt_FromLong(*self as c_long))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for $rust_type {
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, ffi::PyInt_FromLong(self as c_long))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'source> FromPyObject<'source> for $rust_type {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Self> {
|
||||
let val = unsafe { ffi::PyLong_AsLong(obj.as_ptr()) };
|
||||
if val == -1 && PyErr::occurred(obj.py()) {
|
||||
return Err(PyErr::fetch(obj.py()));
|
||||
}
|
||||
match cast::<c_long, $rust_type>(val) {
|
||||
Some(v) => Ok(v),
|
||||
None => Err(exceptions::OverflowError.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! int_convert_u64_or_i64 (
|
||||
($rust_type:ty, $pylong_from_ll_or_ull:expr, $pylong_as_ull_or_ull:expr) => (
|
||||
impl ToPyObject for $rust_type {
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
let ptr = match cast::<$rust_type, c_long>(*self) {
|
||||
Some(v) => ffi::PyInt_FromLong(v),
|
||||
None => $pylong_from_ll_or_ull(*self)
|
||||
};
|
||||
PyObject::from_owned_ptr_or_panic(py, ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for $rust_type {
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
let ptr = match cast::<$rust_type, c_long>(self) {
|
||||
Some(v) => ffi::PyInt_FromLong(v),
|
||||
None => $pylong_from_ll_or_ull(self)
|
||||
};
|
||||
PyObject::from_owned_ptr_or_panic(py, ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <'source> FromPyObject<'source> for $rust_type {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<$rust_type>
|
||||
{
|
||||
let ptr = obj.as_ptr();
|
||||
unsafe {
|
||||
if ffi::PyLong_Check(ptr) != 0 {
|
||||
err_if_invalid_value(obj.py(), !0, $pylong_as_ull_or_ull(ptr))
|
||||
} else if ffi::PyInt_Check(ptr) != 0 {
|
||||
match cast::<c_long, $rust_type>(ffi::PyInt_AS_LONG(ptr)) {
|
||||
Some(v) => Ok(v),
|
||||
None => Err(exceptions::OverflowError.into())
|
||||
}
|
||||
} else {
|
||||
let num = PyObject::from_owned_ptr_or_err(
|
||||
obj.py(), ffi::PyNumber_Long(ptr))?;
|
||||
err_if_invalid_value(
|
||||
obj.py(), !0, $pylong_as_ull_or_ull(num.into_ptr()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
int_fits_c_long!(i8);
|
||||
int_fits_c_long!(u8);
|
||||
int_fits_c_long!(i16);
|
||||
int_fits_c_long!(u16);
|
||||
int_fits_c_long!(i32);
|
||||
|
||||
// If c_long is 64-bits, we can use more types with int_fits_c_long!:
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(u32);
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_fits_larger_int!(u32, u64);
|
||||
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(i64);
|
||||
|
||||
// manual implementation for i64 on systems with 32-bit long
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_convert_u64_or_i64!(i64, ffi::PyLong_FromLongLong, ffi::PyLong_AsLongLong);
|
||||
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(isize);
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_fits_larger_int!(isize, i64);
|
||||
|
||||
int_fits_larger_int!(usize, u64);
|
||||
|
||||
// u64 has a manual implementation as it never fits into signed long
|
||||
int_convert_u64_or_i64!(
|
||||
u64,
|
||||
ffi::PyLong_FromUnsignedLongLong,
|
||||
ffi::PyLong_AsUnsignedLongLong
|
||||
);
|
||||
|
||||
int_convert_bignum!(i128, 16, IS_LITTLE_ENDIAN, 1);
|
||||
int_convert_bignum!(u128, 16, IS_LITTLE_ENDIAN, 0);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::Python;
|
||||
use crate::ToPyObject;
|
||||
|
||||
macro_rules! num_to_py_object_and_back (
|
||||
($func_name:ident, $t1:ty, $t2:ty) => (
|
||||
#[test]
|
||||
fn $func_name() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let val = 123 as $t1;
|
||||
let obj = val.to_object(py);
|
||||
assert_eq!(obj.extract::<$t2>(py).unwrap(), val as $t2);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
num_to_py_object_and_back!(to_from_f64, f64, f64);
|
||||
num_to_py_object_and_back!(to_from_f32, f32, f32);
|
||||
num_to_py_object_and_back!(to_from_i8, i8, i8);
|
||||
num_to_py_object_and_back!(to_from_u8, u8, u8);
|
||||
num_to_py_object_and_back!(to_from_i16, i16, i16);
|
||||
num_to_py_object_and_back!(to_from_u16, u16, u16);
|
||||
num_to_py_object_and_back!(to_from_i32, i32, i32);
|
||||
num_to_py_object_and_back!(to_from_u32, u32, u32);
|
||||
num_to_py_object_and_back!(to_from_i64, i64, i64);
|
||||
num_to_py_object_and_back!(to_from_u64, u64, u64);
|
||||
num_to_py_object_and_back!(to_from_isize, isize, isize);
|
||||
num_to_py_object_and_back!(to_from_usize, usize, usize);
|
||||
num_to_py_object_and_back!(to_from_i128, i128, i128);
|
||||
num_to_py_object_and_back!(to_from_u128, u128, u128);
|
||||
num_to_py_object_and_back!(float_to_i32, f64, i32);
|
||||
num_to_py_object_and_back!(float_to_u32, f64, u32);
|
||||
num_to_py_object_and_back!(float_to_i64, f64, i64);
|
||||
num_to_py_object_and_back!(float_to_u64, f64, u64);
|
||||
num_to_py_object_and_back!(int_to_float, i32, f64);
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use super::num_common::{err_if_invalid_value, IS_LITTLE_ENDIAN};
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::PyAny;
|
||||
use crate::AsPyPointer;
|
||||
use crate::Python;
|
||||
use crate::{FromPyObject, IntoPyObject, ToPyObject};
|
||||
use num_traits::cast::cast;
|
||||
use std::i64;
|
||||
use std::os::raw::{c_long, c_uchar};
|
||||
|
||||
/// Represents a Python `int` object.
|
||||
///
|
||||
/// You can usually avoid directly working with this type
|
||||
/// by using [`ToPyObject`](trait.ToPyObject.html)
|
||||
/// and [extract](struct.PyObject.html#method.extract)
|
||||
/// with the primitive Rust integer types.
|
||||
#[repr(transparent)]
|
||||
pub struct PyLong(PyObject);
|
||||
|
||||
pyobject_native_type!(PyLong, ffi::PyLong_Type, ffi::PyLong_Check);
|
||||
|
||||
macro_rules! int_fits_c_long (
|
||||
($rust_type:ty) => (
|
||||
impl ToPyObject for $rust_type {
|
||||
#![cfg_attr(feature="cargo-clippy", allow(clippy::cast_lossless))]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(*self as c_long))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for $rust_type {
|
||||
#![cfg_attr(feature="cargo-clippy", allow(clippy::cast_lossless))]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, ffi::PyLong_FromLong(self as c_long))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'source> FromPyObject<'source> for $rust_type {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Self> {
|
||||
let ptr = obj.as_ptr();
|
||||
let val = unsafe {
|
||||
let num = ffi::PyNumber_Index(ptr);
|
||||
if num.is_null() {
|
||||
Err(PyErr::fetch(obj.py()))
|
||||
} else {
|
||||
let val = err_if_invalid_value(obj.py(), -1, ffi::PyLong_AsLong(num));
|
||||
ffi::Py_DECREF(num);
|
||||
val
|
||||
}
|
||||
}?;
|
||||
match cast::<c_long, $rust_type>(val) {
|
||||
Some(v) => Ok(v),
|
||||
None => Err(exceptions::OverflowError.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! int_convert_u64_or_i64 (
|
||||
($rust_type:ty, $pylong_from_ll_or_ull:expr, $pylong_as_ll_or_ull:expr) => (
|
||||
impl ToPyObject for $rust_type {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, $pylong_from_ll_or_ull(*self))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl IntoPyObject for $rust_type {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
unsafe {
|
||||
PyObject::from_owned_ptr_or_panic(py, $pylong_from_ll_or_ull(self))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'source> FromPyObject<'source> for $rust_type {
|
||||
fn extract(ob: &'source PyAny) -> PyResult<$rust_type>
|
||||
{
|
||||
let ptr = ob.as_ptr();
|
||||
unsafe {
|
||||
let num = ffi::PyNumber_Index(ptr);
|
||||
if num.is_null() {
|
||||
Err(PyErr::fetch(ob.py()))
|
||||
} else {
|
||||
let result = err_if_invalid_value(ob.py(), !0, $pylong_as_ll_or_ull(num));
|
||||
ffi::Py_DECREF(num);
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
int_fits_c_long!(i8);
|
||||
int_fits_c_long!(u8);
|
||||
int_fits_c_long!(i16);
|
||||
int_fits_c_long!(u16);
|
||||
int_fits_c_long!(i32);
|
||||
|
||||
// If c_long is 64-bits, we can use more types with int_fits_c_long!:
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(u32);
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_fits_larger_int!(u32, u64);
|
||||
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(i64);
|
||||
|
||||
// manual implementation for i64 on systems with 32-bit long
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_convert_u64_or_i64!(i64, ffi::PyLong_FromLongLong, ffi::PyLong_AsLongLong);
|
||||
|
||||
#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))]
|
||||
int_fits_c_long!(isize);
|
||||
#[cfg(any(target_pointer_width = "32", target_os = "windows"))]
|
||||
int_fits_larger_int!(isize, i64);
|
||||
|
||||
int_fits_larger_int!(usize, u64);
|
||||
|
||||
// u64 has a manual implementation as it never fits into signed long
|
||||
int_convert_u64_or_i64!(
|
||||
u64,
|
||||
ffi::PyLong_FromUnsignedLongLong,
|
||||
ffi::PyLong_AsUnsignedLongLong
|
||||
);
|
||||
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
int_convert_bignum!(i128, 16, IS_LITTLE_ENDIAN, 1);
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
int_convert_bignum!(u128, 16, IS_LITTLE_ENDIAN, 0);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
macro_rules! test_common (
|
||||
($test_mod_name:ident, $t:ty) => (
|
||||
mod $test_mod_name {
|
||||
use crate::exceptions;
|
||||
use crate::ToPyObject;
|
||||
use crate::Python;
|
||||
|
||||
#[test]
|
||||
fn from_py_string_type_error() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = ("123").to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance::<exceptions::TypeError>(py));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_py_float_type_error() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = (12.3).to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance::<exceptions::TypeError>(py));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_py_object_and_back() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let val = 123 as $t;
|
||||
let obj = val.to_object(py);
|
||||
assert_eq!(obj.extract::<$t>(py).unwrap(), val as $t);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
test_common!(i8, i8);
|
||||
test_common!(u8, u8);
|
||||
test_common!(i16, i16);
|
||||
test_common!(u16, u16);
|
||||
test_common!(i32, i32);
|
||||
test_common!(u32, u32);
|
||||
test_common!(i64, i64);
|
||||
test_common!(u64, u64);
|
||||
test_common!(isize, isize);
|
||||
test_common!(usize, usize);
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
test_common!(i128, i128);
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
test_common!(u128, u128);
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
|
||||
use crate::conversion::FromPyObject;
|
||||
use crate::conversion::{IntoPyObject, PyTryFrom, ToPyObject};
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
|
@ -113,6 +115,87 @@ impl PyBytes {
|
|||
}
|
||||
}
|
||||
|
||||
/// Converts Rust `str` to Python object.
|
||||
/// See `PyString::new` for details on the conversion.
|
||||
impl ToPyObject for str {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoPyObject for &'a str {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Rust `Cow<str>` to Python object.
|
||||
/// See `PyString::new` for details on the conversion.
|
||||
impl<'a> ToPyObject for Cow<'a, str> {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Rust `String` to Python object.
|
||||
/// See `PyString::new` for details on the conversion.
|
||||
impl ToPyObject for String {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPyObject for String {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyString::new(py, &self).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoPyObject for &'a String {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows extracting strings from Python objects.
|
||||
/// Accepts Python `str` and `unicode` objects.
|
||||
impl<'source> crate::FromPyObject<'source> for Cow<'source, str> {
|
||||
fn extract(ob: &'source PyAny) -> PyResult<Self> {
|
||||
<PyString as PyTryFrom>::try_from(ob)?.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows extracting strings from Python objects.
|
||||
/// Accepts Python `str` and `unicode` objects.
|
||||
impl<'a> crate::FromPyObject<'a> for &'a str {
|
||||
fn extract(ob: &'a PyAny) -> PyResult<Self> {
|
||||
let s: Cow<'a, str> = crate::FromPyObject::extract(ob)?;
|
||||
match s {
|
||||
Cow::Borrowed(r) => Ok(r),
|
||||
Cow::Owned(r) => {
|
||||
let r = ob.py().register_any(r);
|
||||
Ok(r.as_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows extracting strings from Python objects.
|
||||
/// Accepts Python `str` and `unicode` objects.
|
||||
impl<'source> FromPyObject<'source> for String {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Self> {
|
||||
<PyString as PyTryFrom>::try_from(obj)?
|
||||
.to_string()
|
||||
.map(Cow::into_owned)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::PyString;
|
||||
|
|
|
@ -1,265 +0,0 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
//
|
||||
// based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython
|
||||
|
||||
use super::PyAny;
|
||||
use crate::err::{PyErr, PyResult};
|
||||
use crate::exceptions;
|
||||
use crate::ffi;
|
||||
use crate::instance::{Py, PyNativeType};
|
||||
use crate::object::PyObject;
|
||||
use crate::objectprotocol::ObjectProtocol;
|
||||
use crate::AsPyPointer;
|
||||
use crate::IntoPyPointer;
|
||||
use crate::Python;
|
||||
use std::borrow::Cow;
|
||||
use std::os::raw::c_char;
|
||||
use std::str;
|
||||
|
||||
/// Represents a Python `string`.
|
||||
#[repr(transparent)]
|
||||
pub struct PyString(PyObject);
|
||||
|
||||
pyobject_native_type!(PyString, ffi::PyBaseString_Type, ffi::PyBaseString_Check);
|
||||
|
||||
/// Represents a Python `unicode string`.
|
||||
#[repr(transparent)]
|
||||
pub struct PyUnicode(PyObject);
|
||||
|
||||
pyobject_native_type!(PyUnicode, ffi::PyUnicode_Type, ffi::PyUnicode_Check);
|
||||
|
||||
/// Represents a Python `byte` string. Corresponds to `str` in Python 2
|
||||
#[repr(transparent)]
|
||||
pub struct PyBytes(PyObject);
|
||||
|
||||
pyobject_native_type!(PyBytes, ffi::PyBaseString_Type, ffi::PyString_Check);
|
||||
|
||||
impl PyString {
|
||||
/// Creates a new Python string object.
|
||||
///
|
||||
/// This function will create a byte string if the
|
||||
/// input string is ASCII-only; and a unicode string otherwise.
|
||||
/// Use `PyUnicode::new()` to always create a unicode string.
|
||||
///
|
||||
/// Panics if out of memory.
|
||||
pub fn new(py: Python, s: &str) -> Py<PyString> {
|
||||
if s.is_ascii() {
|
||||
PyBytes::new(py, s.as_bytes()).into()
|
||||
} else {
|
||||
PyUnicode::new(py, s).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_object(src: &PyAny, encoding: &str, errors: &str) -> PyResult<Py<PyString>> {
|
||||
unsafe {
|
||||
Ok(Py::from_owned_ptr_or_err(
|
||||
src.py(),
|
||||
ffi::PyUnicode_FromEncodedObject(
|
||||
src.as_ptr(),
|
||||
encoding.as_ptr() as *const c_char,
|
||||
errors.as_ptr() as *const c_char,
|
||||
),
|
||||
)?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the Python string as a byte slice.
|
||||
#[inline]
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
if let Ok(bytes) = self.cast_as::<PyBytes>() {
|
||||
bytes.as_bytes()
|
||||
} else if let Ok(unicode) = self.cast_as::<PyUnicode>() {
|
||||
unicode.as_bytes()
|
||||
} else {
|
||||
panic!("PyString is neither `str` nor `unicode`")
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the `PyString` into a Rust string.
|
||||
///
|
||||
/// On Python 2.7, if the `PyString` refers to a byte string,
|
||||
/// it will be decoded using UTF-8.
|
||||
///
|
||||
/// Returns a `UnicodeDecodeError` if the input is not valid unicode
|
||||
/// (containing unpaired surrogates, or a Python 2.7 byte string that is
|
||||
/// not valid UTF-8).
|
||||
pub fn to_string(&self) -> PyResult<Cow<str>> {
|
||||
match std::str::from_utf8(self.as_bytes()) {
|
||||
Ok(s) => Ok(Cow::Borrowed(s)),
|
||||
Err(e) => Err(PyErr::from_instance(
|
||||
exceptions::UnicodeDecodeError::new_utf8(self.py(), self.as_bytes(), e)?,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the `PyString` into a Rust string.
|
||||
///
|
||||
/// On Python 2.7, if the `PyString` refers to a byte string,
|
||||
/// it will be decoded using UTF-8.
|
||||
///
|
||||
/// Unpaired surrogates and (on Python 2.7) invalid UTF-8 sequences are
|
||||
/// replaced with U+FFFD REPLACEMENT CHARACTER.
|
||||
pub fn to_string_lossy(&self) -> Cow<str> {
|
||||
String::from_utf8_lossy(self.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl PyBytes {
|
||||
/// Creates a new Python byte string object.
|
||||
/// The byte string is initialized by copying the data from the `&[u8]`.
|
||||
///
|
||||
/// Panics if out of memory.
|
||||
pub fn new(_py: Python, s: &[u8]) -> Py<PyBytes> {
|
||||
let ptr = s.as_ptr() as *const c_char;
|
||||
let len = s.len() as ffi::Py_ssize_t;
|
||||
unsafe { Py::from_owned_ptr_or_panic(ffi::PyBytes_FromStringAndSize(ptr, len)) }
|
||||
}
|
||||
|
||||
/// Get the Python string as a byte slice.
|
||||
#[inline]
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
let buffer = ffi::PyBytes_AsString(self.as_ptr()) as *const u8;
|
||||
let length = ffi::PyBytes_Size(self.as_ptr()) as usize;
|
||||
debug_assert!(!buffer.is_null());
|
||||
std::slice::from_raw_parts(buffer, length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PyUnicode {
|
||||
/// Creates a new Python unicode string object.
|
||||
///
|
||||
/// Panics if out of memory.
|
||||
pub fn new(_py: Python, s: &str) -> Py<PyUnicode> {
|
||||
let ptr = s.as_ptr() as *const c_char;
|
||||
let len = s.len() as ffi::Py_ssize_t;
|
||||
unsafe { Py::from_owned_ptr_or_panic(ffi::PyUnicode_FromStringAndSize(ptr, len)) }
|
||||
}
|
||||
|
||||
pub fn from_object(src: &PyAny, encoding: &str, errors: &str) -> PyResult<Py<PyUnicode>> {
|
||||
unsafe {
|
||||
Ok(Py::from_owned_ptr_or_err(
|
||||
src.py(),
|
||||
ffi::PyUnicode_FromEncodedObject(
|
||||
src.as_ptr(),
|
||||
encoding.as_ptr() as *const c_char,
|
||||
errors.as_ptr() as *const c_char,
|
||||
),
|
||||
)?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the Python string as a byte slice.
|
||||
#[inline]
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
// PyUnicode_AsUTF8String would return null if the pointer did not reference a valid
|
||||
// unicode object, but because we have a valid PyUnicode, assume success
|
||||
let data: Py<PyBytes> =
|
||||
Py::from_owned_ptr(ffi::PyUnicode_AsUTF8String(self.0.as_ptr()));
|
||||
let buffer = ffi::PyBytes_AsString(data.as_ptr()) as *const u8;
|
||||
let length = ffi::PyBytes_Size(data.as_ptr()) as usize;
|
||||
debug_assert!(!buffer.is_null());
|
||||
std::slice::from_raw_parts(buffer, length)
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the `PyString` into a Rust string.
|
||||
///
|
||||
/// Returns a `UnicodeDecodeError` if the input is not valid unicode
|
||||
/// (containing unpaired surrogates).
|
||||
pub fn to_string(&self) -> PyResult<Cow<str>> {
|
||||
match std::str::from_utf8(self.as_bytes()) {
|
||||
Ok(s) => Ok(Cow::Borrowed(s)),
|
||||
Err(e) => Err(PyErr::from_instance(
|
||||
exceptions::UnicodeDecodeError::new_utf8(self.py(), self.as_bytes(), e)?,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the `PyString` into a Rust string.
|
||||
///
|
||||
/// Unpaired surrogates are replaced with U+FFFD REPLACEMENT CHARACTER.
|
||||
pub fn to_string_lossy(&self) -> Cow<str> {
|
||||
String::from_utf8_lossy(self.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts from `PyBytes` to `PyString`.
|
||||
impl std::convert::From<Py<PyBytes>> for Py<PyString> {
|
||||
#[inline]
|
||||
fn from(ob: Py<PyBytes>) -> Py<PyString> {
|
||||
unsafe { Py::from_owned_ptr(ob.into_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts from `PyUnicode` to `PyString`.
|
||||
impl std::convert::From<Py<PyUnicode>> for Py<PyString> {
|
||||
#[inline]
|
||||
fn from(ob: Py<PyUnicode>) -> Py<PyString> {
|
||||
unsafe { Py::from_owned_ptr(ob.into_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::PyString;
|
||||
use crate::instance::AsPyRef;
|
||||
use crate::object::PyObject;
|
||||
use crate::Python;
|
||||
use crate::{FromPyObject, PyTryFrom, ToPyObject};
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[test]
|
||||
fn test_non_bmp() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let s = "\u{1F30F}";
|
||||
let py_string = s.to_object(py);
|
||||
assert_eq!(s, py_string.extract::<String>(py).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_str() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let s = "Hello Python";
|
||||
let py_string = s.to_object(py);
|
||||
|
||||
let s2: &str = FromPyObject::extract(py_string.as_ref(py).into()).unwrap();
|
||||
assert_eq!(s, s2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_as_bytes() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let s = "ascii 🐈";
|
||||
let obj: PyObject = PyString::new(py, s).into();
|
||||
let py_string = <PyString as PyTryFrom>::try_from(obj.as_ref(py)).unwrap();
|
||||
assert_eq!(s.as_bytes(), py_string.as_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_string_ascii() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let s = "ascii";
|
||||
let obj: PyObject = PyString::new(py, s).into();
|
||||
let py_string = <PyString as PyTryFrom>::try_from(obj.as_ref(py)).unwrap();
|
||||
assert!(py_string.to_string().is_ok());
|
||||
assert_eq!(Cow::Borrowed(s), py_string.to_string().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_string_unicode() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
let s = "哈哈🐈";
|
||||
let obj: PyObject = PyString::new(py, s).into();
|
||||
let py_string = <PyString as PyTryFrom>::try_from(obj.as_ref(py)).unwrap();
|
||||
assert!(py_string.to_string().is_ok());
|
||||
assert_eq!(Cow::Borrowed(s), py_string.to_string().unwrap());
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
use crate::err::PyResult;
|
||||
use crate::instance::PyNativeType;
|
||||
use crate::object::PyObject;
|
||||
use crate::types::{PyAny, PyString};
|
||||
use crate::FromPyObject;
|
||||
use crate::Python;
|
||||
use crate::{IntoPyObject, PyTryFrom, ToPyObject};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Converts Rust `str` to Python object.
|
||||
/// See `PyString::new` for details on the conversion.
|
||||
impl ToPyObject for str {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoPyObject for &'a str {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Rust `Cow<str>` to Python object.
|
||||
/// See `PyString::new` for details on the conversion.
|
||||
impl<'a> ToPyObject for Cow<'a, str> {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Rust `String` to Python object.
|
||||
/// See `PyString::new` for details on the conversion.
|
||||
impl ToPyObject for String {
|
||||
#[inline]
|
||||
fn to_object(&self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPyObject for String {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyString::new(py, &self).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoPyObject for &'a String {
|
||||
#[inline]
|
||||
fn into_object(self, py: Python) -> PyObject {
|
||||
PyString::new(py, self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows extracting strings from Python objects.
|
||||
/// Accepts Python `str` and `unicode` objects.
|
||||
impl<'source> crate::FromPyObject<'source> for Cow<'source, str> {
|
||||
fn extract(ob: &'source PyAny) -> PyResult<Self> {
|
||||
<PyString as PyTryFrom>::try_from(ob)?.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows extracting strings from Python objects.
|
||||
/// Accepts Python `str` and `unicode` objects.
|
||||
impl<'a> crate::FromPyObject<'a> for &'a str {
|
||||
fn extract(ob: &'a PyAny) -> PyResult<Self> {
|
||||
let s: Cow<'a, str> = crate::FromPyObject::extract(ob)?;
|
||||
match s {
|
||||
Cow::Borrowed(r) => Ok(r),
|
||||
Cow::Owned(r) => {
|
||||
let r = ob.py().register_any(r);
|
||||
Ok(r.as_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows extracting strings from Python objects.
|
||||
/// Accepts Python `str` and `unicode` objects.
|
||||
impl<'source> FromPyObject<'source> for String {
|
||||
fn extract(obj: &'source PyAny) -> PyResult<Self> {
|
||||
<PyString as PyTryFrom>::try_from(obj)?
|
||||
.to_string()
|
||||
.map(Cow::into_owned)
|
||||
}
|
||||
}
|
|
@ -253,7 +253,6 @@ fn rich_comparisons() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn rich_comparisons_python_3_type_error() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
|
|
@ -60,7 +60,6 @@ impl PyBufferProtocol for TestClass {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[test]
|
||||
fn test_buffer() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -77,22 +76,3 @@ fn test_buffer() {
|
|||
let d = [("ob", t)].into_py_dict(py);
|
||||
py.run("assert bytes(ob) == b' 23'", None, Some(d)).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
#[test]
|
||||
fn test_buffer() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let t = Py::new(
|
||||
py,
|
||||
TestClass {
|
||||
vec: vec![b' ', b'2', b'3'],
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let d = [("ob", t)].into_py_dict(py);
|
||||
py.run("assert memoryview(ob).tobytes() == ' 23'", None, Some(d))
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -65,16 +65,10 @@ fn empty_class_in_module() {
|
|||
"EmptyClassInModule"
|
||||
);
|
||||
|
||||
let builtin = if cfg!(feature = "python2") {
|
||||
"__builtin__"
|
||||
} else {
|
||||
"builtins"
|
||||
};
|
||||
|
||||
let module: String = ty.getattr("__module__").unwrap().extract().unwrap();
|
||||
|
||||
// Rationale: The class can be added to many modules, but will only be initialized once.
|
||||
// We currently have no way of determining a canonical module, so builtins is better
|
||||
// than using whatever calls init first.
|
||||
assert_eq!(module, builtin);
|
||||
assert_eq!(module, "builtins");
|
||||
}
|
||||
|
|
|
@ -100,7 +100,6 @@ fn test_delta_check() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn test_datetime_utc() {
|
||||
use pyo3::types::PyDateTime;
|
||||
|
||||
|
@ -123,7 +122,6 @@ fn test_datetime_utc() {
|
|||
assert_eq!(offset, 0f32);
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
static INVALID_DATES: &'static [(i32, u8, u8)] = &[
|
||||
(-1, 1, 1),
|
||||
(0, 1, 1),
|
||||
|
@ -136,7 +134,6 @@ static INVALID_DATES: &'static [(i32, u8, u8)] = &[
|
|||
(2018, 1, 32),
|
||||
];
|
||||
|
||||
#[cfg(Py_3)]
|
||||
static INVALID_TIMES: &'static [(u8, u8, u8, u32)] =
|
||||
&[(25, 0, 0, 0), (255, 0, 0, 0), (0, 60, 0, 0), (0, 0, 61, 0)];
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use pyo3::class::{
|
|||
use pyo3::exceptions::{IndexError, ValueError};
|
||||
use pyo3::ffi;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{IntoPyDict, PyAny, PyBytes, PySlice, PyString, PyType};
|
||||
use pyo3::types::{IntoPyDict, PyAny, PyBytes, PySlice, PyType};
|
||||
use pyo3::AsPyPointer;
|
||||
use std::{isize, iter};
|
||||
|
||||
|
@ -100,14 +100,8 @@ impl<'p> PyObjectProtocol<'p> for StringMethods {
|
|||
let gil = GILGuard::acquire();
|
||||
Ok(PyBytes::new(gil.python(), b"bytes").into())
|
||||
}
|
||||
|
||||
fn __unicode__(&self) -> PyResult<PyObject> {
|
||||
let gil = GILGuard::acquire();
|
||||
Ok(PyString::new(gil.python(), "unicode").into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[test]
|
||||
fn string_methods() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
@ -120,19 +114,6 @@ fn string_methods() {
|
|||
py_assert!(py, obj, "bytes(obj) == b'bytes'");
|
||||
}
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
#[test]
|
||||
fn string_methods() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let obj = Py::new(py, StringMethods {}).unwrap();
|
||||
py_assert!(py, obj, "str(obj) == 'str'");
|
||||
py_assert!(py, obj, "repr(obj) == 'repr'");
|
||||
py_assert!(py, obj, "unicode(obj) == 'unicode'");
|
||||
py_assert!(py, obj, "'{0:x}'.format(obj) == 'format(x)'");
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
struct Comparisons {
|
||||
val: i32,
|
||||
|
@ -452,7 +433,6 @@ fn dunder_dict_support() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[test]
|
||||
fn access_dunder_dict() {
|
||||
let gil = Python::acquire_gil();
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
use pyo3::prelude::*;
|
||||
|
||||
#[cfg(Py_3)]
|
||||
use pyo3::types::IntoPyDict;
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
#[pyclass]
|
||||
#[cfg(Py_3)]
|
||||
struct EmptyClass {}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
fn sum_as_string(a: i64, b: i64) -> String {
|
||||
format!("{}", a + b).to_string()
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
#[cfg(Py_3)]
|
||||
/// Doubles the given value
|
||||
fn double(x: usize) -> usize {
|
||||
x * 2
|
||||
|
@ -25,7 +20,6 @@ fn double(x: usize) -> usize {
|
|||
|
||||
/// This module is implemented in Rust.
|
||||
#[pymodule]
|
||||
#[cfg(Py_3)]
|
||||
fn module_with_functions(py: Python, m: &PyModule) -> PyResult<()> {
|
||||
use pyo3::wrap_pyfunction;
|
||||
|
||||
|
@ -51,7 +45,6 @@ fn module_with_functions(py: Python, m: &PyModule) -> PyResult<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn test_module_with_functions() {
|
||||
use pyo3::wrap_pymodule;
|
||||
|
||||
|
@ -83,7 +76,6 @@ fn some_name(_: Python, _: &PyModule) -> PyResult<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn test_module_renaming() {
|
||||
use pyo3::wrap_pymodule;
|
||||
|
||||
|
@ -101,7 +93,6 @@ fn test_module_renaming() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn test_module_from_code() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
@ -129,13 +120,11 @@ fn test_module_from_code() {
|
|||
}
|
||||
|
||||
#[pyfunction]
|
||||
#[cfg(Py_3)]
|
||||
fn r#move() -> usize {
|
||||
42
|
||||
}
|
||||
|
||||
#[pymodule]
|
||||
#[cfg(Py_3)]
|
||||
fn raw_ident_module(_py: Python, module: &PyModule) -> PyResult<()> {
|
||||
use pyo3::wrap_pyfunction;
|
||||
|
||||
|
@ -143,7 +132,6 @@ fn raw_ident_module(_py: Python, module: &PyModule) -> PyResult<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn test_raw_idents() {
|
||||
use pyo3::wrap_pymodule;
|
||||
|
||||
|
@ -156,12 +144,10 @@ fn test_raw_idents() {
|
|||
}
|
||||
|
||||
#[pyfunction]
|
||||
#[cfg(Py_3)]
|
||||
fn subfunction() -> String {
|
||||
"Subfunction".to_string()
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[pymodule]
|
||||
fn submodule(_py: Python, module: &PyModule) -> PyResult<()> {
|
||||
use pyo3::wrap_pyfunction;
|
||||
|
@ -170,13 +156,11 @@ fn submodule(_py: Python, module: &PyModule) -> PyResult<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[pyfunction]
|
||||
fn superfunction() -> String {
|
||||
"Superfunction".to_string()
|
||||
}
|
||||
|
||||
#[cfg(Py_3)]
|
||||
#[pymodule]
|
||||
fn supermodule(_py: Python, module: &PyModule) -> PyResult<()> {
|
||||
use pyo3::{wrap_pyfunction, wrap_pymodule};
|
||||
|
@ -187,7 +171,6 @@ fn supermodule(_py: Python, module: &PyModule) -> PyResult<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(Py_3)]
|
||||
fn test_module_nesting() {
|
||||
use pyo3::wrap_pymodule;
|
||||
|
||||
|
|
Loading…
Reference in New Issue