From 9193855194b88ec43a450726231331ac45d6c029 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 15 Mar 2018 19:24:07 +0200 Subject: [PATCH 001/138] wip --- .gitignore | 2 + Cargo.toml | 7 +- build.rs | 164 +++++++----- examples/debug_build.rs | 541 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 649 insertions(+), 65 deletions(-) create mode 100644 examples/debug_build.rs diff --git a/.gitignore b/.gitignore index 9c6831e9efc..8d1a301095f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ __pycache__/ *.out *.egg-info extensions/stamps/ + +cmake-build-debug/ diff --git a/Cargo.toml b/Cargo.toml index 4c4746cd45f..6e3596b63fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,11 +24,16 @@ libc = "0.2" spin = "0.4.6" num-traits = "0.2" pyo3cls = { version = "^0.2.1" } +regex = "0.2" +version_check = "0.1" [build-dependencies] regex = "0.2" version_check = "0.1" +[[example]] +name = "debug_build" + [features] default = [] @@ -39,7 +44,7 @@ python2 = [] python3 = [] # Enable additional features that require nightly rust -#nightly = [] +nightly = [] # Use this feature when building an extension module. # It tells the linker to keep the python symbols unresolved, diff --git a/build.rs b/build.rs index 8c2b61fca3d..f96d56b17db 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,8 @@ +#![feature(asm)] +#![feature(core_intrinsics)] + +use std::intrinsics::breakpoint; + extern crate regex; extern crate version_check; @@ -8,6 +13,7 @@ use std::fmt; use regex::Regex; use version_check::{supports_features, is_min_version, is_min_date}; +use std::path::Path; // Specifies the minimum nightly version needed to compile pyo3. const MIN_DATE: &'static str = "2017-11-07"; @@ -17,11 +23,10 @@ const MIN_VERSION: &'static str = "1.23.0-nightly"; struct PythonVersion { major: u8, // minor == None means any minor version will do - minor: Option + minor: Option, } impl PartialEq for PythonVersion { - fn eq(&self, o: &PythonVersion) -> bool { self.major == o.major && (self.minor.is_none() || self.minor == o.minor) } @@ -45,13 +50,13 @@ const CFG_KEY: &'static str = "py_sys_config"; // windows' python writes out lines with the windows crlf sequence; // posix platforms and mac os should write out lines with just lf. -#[cfg(target_os="windows")] +#[cfg(target_os = "windows")] static NEWLINE_SEQUENCE: &'static str = "\r\n"; -#[cfg(not(target_os="windows"))] +#[cfg(not(target_os = "windows"))] static NEWLINE_SEQUENCE: &'static str = "\n"; -// A list of python interpreter compile-time preprocessor defines that +// A list of python interpreter compile-time preprocessor defines that // we will pick up and pass to rustc via --cfg=py_sys_config={varname}; // this allows using them conditional cfg attributes in the .rs files, so // @@ -61,9 +66,9 @@ static NEWLINE_SEQUENCE: &'static str = "\n"; // // see Misc/SpecialBuilds.txt in the python source for what these mean. // -// (hrm, this is sort of re-implementing what distutils does, except +// (hrm, this is sort of re-implementing what distutils does, except // by passing command line args instead of referring to a python.h) -#[cfg(not(target_os="windows"))] +#[cfg(not(target_os = "windows"))] static SYSCONFIG_FLAGS: [&'static str; 7] = [ "Py_USING_UNICODE", "Py_UNICODE_WIDE", @@ -75,24 +80,24 @@ static SYSCONFIG_FLAGS: [&'static str; 7] = [ ]; static SYSCONFIG_VALUES: [&'static str; 1] = [ - // cfg doesn't support flags with values, just bools - so flags - // below are translated into bools as {varname}_{val} + // cfg doesn't support flags with values, just bools - so flags + // below are translated into bools as {varname}_{val} // // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 "Py_UNICODE_SIZE" // note - not present on python 3.3+, which is always wide ]; /// Examine python's compile flags to pass to cfg by launching -/// the interpreter and printing variables of interest from +/// the interpreter and printing variables of interest from /// sysconfig.get_config_vars. -#[cfg(not(target_os="windows"))] -fn get_config_vars(python_path: &String) -> Result, String> { +#[cfg(not(target_os = "windows"))] +fn get_config_vars(python_path: &String) -> Result, String> { let mut script = "import sysconfig; \ config = sysconfig.get_config_vars();".to_owned(); for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!("print(config.get('{}', {}))", k, - if is_value(k) { "None" } else { "0" } )); + script.push_str(&format!("print(config.get('{}', {}))", k, + if is_value(k) { "None" } else { "0" })); script.push_str(";"); } @@ -137,10 +142,10 @@ config = sysconfig.get_config_vars();".to_owned(); Ok(all_vars) } -#[cfg(target_os="windows")] +#[cfg(target_os = "windows")] fn get_config_vars(_: &String) -> Result, String> { // sysconfig is missing all the flags on windows, so we can't actually - // query the interpreter directly for its build flags. + // query the interpreter directly for its build flags. // // For the time being, this is the flags as defined in the python source's // PC\pyconfig.h. This won't work correctly if someone has built their @@ -156,7 +161,7 @@ fn get_config_vars(_: &String) -> Result, String> { // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the // Debug configuration, which this script doesn't currently support anyway. // map.insert("Py_DEBUG", "1"); - + // Uncomment these manually if your python was built with these and you want // the cfg flags to be set in rust. // @@ -203,9 +208,9 @@ fn run_python_script(interpreter: &str, script: &str) -> Result return Ok(out); } -#[cfg(not(target_os="macos"))] -#[cfg(not(target_os="windows"))] -fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, enable_shared: bool) +#[cfg(not(target_os = "macos"))] +#[cfg(not(target_os = "windows"))] +fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, enable_shared: bool) -> Result { if enable_shared { @@ -215,30 +220,56 @@ fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, enable_shared: bool) } } -#[cfg(target_os="macos")] -fn get_macos_linkmodel() -> Result +#[cfg(target_os = "windows")] +fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result { - let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; - let out = run_python_script("python", script).unwrap(); - Ok(out.trim_right().to_owned()) + // Py_ENABLE_SHARED doesn't seem to be present on windows. + Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, + match version.minor { + Some(minor) => minor.to_string(), + None => "".to_owned() + })) } -#[cfg(target_os="macos")] -fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, _: bool) -> Result +#[cfg(target_os = "macos")] +fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, _: bool) -> Result { - // os x can be linked to a framework or static or dynamic, and + let path = Path::new(interpreter_path); + let file_stem = path.file_stem().unwrap().to_str().unwrap(); + + let link_library_name: String; + + if file_stem.starts_with("pypy") { + link_library_name = "pypy".to_string(); + } else if file_stem.starts_with("python") { + link_library_name = "python".to_string(); + } else { + unreachable!() + } + + // os x can be linked to a framework or static or dynamic, and // Py_ENABLE_SHARED is wrong; framework means shared library - match get_macos_linkmodel().unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", - ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", - ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", - ld_version)), + match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib=static={}{}", + file_stem, ld_version)), + "shared" => Ok(format!("cargo:rustc-link-lib={}{}", + file_stem, ld_version)), + "framework" => Ok(format!("cargo:rustc-link-lib={}{}", + file_stem, ld_version)), other => Err(format!("unknown linkmodel {}", other)) } } + +#[cfg(target_os = "macos")] +fn get_macos_linkmodel(interpreter_path: &str) -> Result +{ + let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; + let out = run_python_script(interpreter_path, script).unwrap(); + Ok(out.trim_right().to_owned()) +} + + /// Parse string as interpreter version. fn get_interpreter_version(line: &str) -> Result { @@ -246,24 +277,29 @@ fn get_interpreter_version(line: &str) -> Result match version_re.captures(&line) { Some(cap) => Ok(PythonVersion { major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()) + minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), }), None => Err( format!("Unexpected response to version query {}", line)) } } -#[cfg(target_os="windows")] -fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result -{ - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned() - })) +fn check_pypy(interpreter_path: &str) -> bool { + let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; + let is_pypy: bool = run_python_script(interpreter_path, script) + .unwrap() + .to_lowercase() + .trim_right() + .parse() + .unwrap(); + + if is_pypy { + println!("cargo:rustc-cfg=PyPy"); + } + return is_pypy; } + /// Locate a suitable python interpreter and extract config from it. /// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided /// path a Python executable, and raises an error if the version doesn't match. @@ -276,6 +312,7 @@ fn find_interpreter_and_get_config(expected_version: &PythonVersion) if let Some(sys_executable) = env::var_os("PYTHON_SYS_EXECUTABLE") { let interpreter_path = sys_executable.to_str() .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); + let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); if expected_version == &interpreter_version { @@ -321,6 +358,7 @@ print(sys.exec_prefix);"; let out = try!(run_python_script(interpreter, script)); let lines: Vec = out.split(NEWLINE_SEQUENCE).map(|line| line.to_owned()).collect(); let interpreter_version = try!(get_interpreter_version(&lines[0])); + let is_pypy = check_pypy(interpreter); Ok((interpreter_version, lines)) } @@ -329,7 +367,6 @@ print(sys.exec_prefix);"; /// /// Note that if the python doesn't satisfy expected_version, this will error. fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, String), String> { - let (interpreter_version, interpreter_path, lines) = try!( find_interpreter_and_get_config(expected_version)); @@ -340,8 +377,8 @@ fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, Stri let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); if !is_extension_module || cfg!(target_os="windows") { - println!("{}", get_rustc_link_lib(&interpreter_version, - ld_version, enable_shared == "1").unwrap()); + println!("{}", get_rustc_link_lib(&interpreter_version, &interpreter_path, + ld_version, enable_shared == "1").unwrap()); if libpath != "None" { println!("cargo:rustc-link-search=native={}", libpath); } else if cfg!(target_os="windows") { @@ -351,15 +388,15 @@ fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, Stri let mut flags = String::new(); - if let PythonVersion { major: 3, minor: some_minor} = interpreter_version { + if let PythonVersion { major: 3, minor: some_minor } = interpreter_version { if env::var_os("CARGO_FEATURE_PEP_384").is_some() { println!("cargo:rustc-cfg=Py_LIMITED_API"); } if let Some(minor) = some_minor { if minor < PY3_MIN_MINOR { - return Err(format!("Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor)) + return Err(format!("Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor)); } - for i in 5..(minor+1) { + for i in 5..(minor + 1) { println!("cargo:rustc-cfg=Py_3_{}", i); flags += format!("CFG_Py_3_{},", i).as_ref(); } @@ -391,7 +428,7 @@ fn version_from_env() -> Result { minor: match cap.get(3) { Some(s) => Some(s.as_str().parse().unwrap()), None => None - } + }, }), None => () } @@ -428,7 +465,7 @@ fn check_rustc_version() { print_version_err(&*version, &*date); panic!("Aborting compilation due to incompatible compiler.") } - }, + } _ => { println!("cargo:warning={}", "pyo3 was unable to check rustc compatibility."); println!("cargo:warning={}", "Build may fail due to incompatible rustc version."); @@ -438,19 +475,19 @@ fn check_rustc_version() { fn main() { check_rustc_version(); - // 1. Setup cfg variables so we can do conditional compilation in this - // library based on the python interpeter's compilation flags. This is + // 1. Setup cfg variables so we can do conditional compilation in this + // library based on the python interpeter's compilation flags. This is // necessary for e.g. matching the right unicode and threading interfaces. // // This locates the python interpreter based on the PATH, which should // work smoothly with an activated virtualenv. // - // If you have troubles with your shell accepting '.' in a var name, - // try using 'env' (sorry but this isn't our fault - it just has to + // If you have troubles with your shell accepting '.' in a var name, + // try using 'env' (sorry but this isn't our fault - it just has to // match the pkg-config package name, which is going to have a . in it). let version = match version_from_env() { Ok(v) => v, - Err(_) => PythonVersion{major: 3, minor: None} + Err(_) => PythonVersion { major: 3, minor: None } }; let (python_interpreter_path, flags) = configure_from_path(&version).unwrap(); let mut config_map = get_config_vars(&python_interpreter_path).unwrap(); @@ -468,9 +505,9 @@ fn main() { } } - // 2. Export python interpreter compilation flags as cargo variables that + // 2. Export python interpreter compilation flags as cargo variables that // will be visible to dependents. All flags will be available to dependent - // build scripts in the environment variable DEP_PYTHON27_PYTHON_FLAGS as + // build scripts in the environment variable DEP_PYTHON27_PYTHON_FLAGS as // comma separated list; each item in the list looks like // // {VAL,FLAG}_{flag_name}=val; @@ -479,7 +516,7 @@ fn main() { // VAL indicates it can take on any value // // rust-cypthon/build.rs contains an example of how to unpack this data - // into cfg flags that replicate the ones present in this library, so + // into cfg flags that replicate theones present in this library, so // you can use the same cfg syntax. //let mut flags = flags; let flags: String = config_map.iter().fold("".to_owned(), |memo, (key, val)| { @@ -492,7 +529,6 @@ fn main() { } }) + flags.as_str(); - println!("cargo:python_flags={}", - if flags.len() > 0 { &flags[..flags.len()-1] } else { "" }); - + println!("cargo:python_flags={}", + if flags.len() > 0 { &flags[..flags.len() - 1] } else { "" }); } diff --git a/examples/debug_build.rs b/examples/debug_build.rs new file mode 100644 index 00000000000..8191553cae6 --- /dev/null +++ b/examples/debug_build.rs @@ -0,0 +1,541 @@ +#![feature(asm)] +#![feature(core_intrinsics)] + +use std::intrinsics::breakpoint; + +extern crate regex; +extern crate version_check; + +use std::process::Command; +use std::collections::HashMap; +use std::env; +use std::fmt; + +use regex::Regex; +use version_check::{supports_features, is_min_version, is_min_date}; +use std::path::Path; + +// Specifies the minimum nightly version needed to compile pyo3. +const MIN_DATE: &'static str = "2017-11-07"; +const MIN_VERSION: &'static str = "1.23.0-nightly"; + +#[derive(Debug)] +struct PythonVersion { + major: u8, + // minor == None means any minor version will do + minor: Option, +} + +impl PartialEq for PythonVersion { + fn eq(&self, o: &PythonVersion) -> bool { + self.major == o.major && (self.minor.is_none() || self.minor == o.minor) + } +} + +impl fmt::Display for PythonVersion { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + try!(self.major.fmt(f)); + try!(f.write_str(".")); + match self.minor { + Some(minor) => try!(minor.fmt(f)), + None => try!(f.write_str("*")) + }; + Ok(()) + } +} + +const PY3_MIN_MINOR: u8 = 5; + +const CFG_KEY: &'static str = "py_sys_config"; + +// windows' python writes out lines with the windows crlf sequence; +// posix platforms and mac os should write out lines with just lf. +#[cfg(target_os = "windows")] +static NEWLINE_SEQUENCE: &'static str = "\r\n"; + +#[cfg(not(target_os = "windows"))] +static NEWLINE_SEQUENCE: &'static str = "\n"; + +// A list of python interpreter compile-time preprocessor defines that +// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; +// this allows using them conditional cfg attributes in the .rs files, so +// +// #[cfg(py_sys_config="{varname}"] +// +// is the equivalent of #ifdef {varname} name in C. +// +// see Misc/SpecialBuilds.txt in the python source for what these mean. +// +// (hrm, this is sort of re-implementing what distutils does, except +// by passing command line args instead of referring to a python.h) +#[cfg(not(target_os = "windows"))] +static SYSCONFIG_FLAGS: [&'static str; 7] = [ + "Py_USING_UNICODE", + "Py_UNICODE_WIDE", + "WITH_THREAD", + "Py_DEBUG", + "Py_REF_DEBUG", + "Py_TRACE_REFS", + "COUNT_ALLOCS", +]; + +static SYSCONFIG_VALUES: [&'static str; 1] = [ + // cfg doesn't support flags with values, just bools - so flags + // below are translated into bools as {varname}_{val} + // + // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 + "Py_UNICODE_SIZE" // note - not present on python 3.3+, which is always wide +]; + +/// Examine python's compile flags to pass to cfg by launching +/// the interpreter and printing variables of interest from +/// sysconfig.get_config_vars. +#[cfg(not(target_os = "windows"))] +fn get_config_vars(python_path: &String) -> Result, String> { + let mut script = "import sysconfig; \ +config = sysconfig.get_config_vars();".to_owned(); + + for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { + script.push_str(&format!("print(config.get('{}', {}))", k, + if is_value(k) { "None" } else { "0" })); + script.push_str(";"); + } + + let mut cmd = Command::new(python_path); + cmd.arg("-c").arg(script); + + let out = try!(cmd.output().map_err(|e| { + format!("failed to run python interpreter `{:?}`: {}", cmd, e) + })); + + if !out.status.success() { + let stderr = String::from_utf8(out.stderr).unwrap(); + let mut msg = format!("python script failed with stderr:\n\n"); + msg.push_str(&stderr); + return Err(msg); + } + + let stdout = String::from_utf8(out.stdout).unwrap(); + let split_stdout: Vec<&str> = stdout.trim_right().split(NEWLINE_SEQUENCE).collect(); + if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { + return Err( + format!("python stdout len didn't return expected number of lines: +{}", split_stdout.len()).to_string()); + } + let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); + // let var_map: HashMap = HashMap::new(); + let mut all_vars = all_vars.zip(split_stdout.iter()) + .fold(HashMap::new(), |mut memo: HashMap, (&k, &v)| { + if !(v.to_owned() == "None" && is_value(k)) { + memo.insert(k.to_owned(), v.to_owned()); + } + memo + }); + + let debug = if let Some(val) = all_vars.get("Py_DEBUG") { val == "1" } else { false }; + if debug { + all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); + all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); + all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + } + + Ok(all_vars) +} + +#[cfg(target_os = "windows")] +fn get_config_vars(_: &String) -> Result, String> { + // sysconfig is missing all the flags on windows, so we can't actually + // query the interpreter directly for its build flags. + // + // For the time being, this is the flags as defined in the python source's + // PC\pyconfig.h. This won't work correctly if someone has built their + // python with a modified pyconfig.h - sorry if that is you, you will have + // to comment/uncomment the lines below. + let mut map: HashMap = HashMap::new(); + map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); + map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); + + // This is defined #ifdef _DEBUG. The visual studio build seems to produce + // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the + // Debug configuration, which this script doesn't currently support anyway. + // map.insert("Py_DEBUG", "1"); + + // Uncomment these manually if your python was built with these and you want + // the cfg flags to be set in rust. + // + // map.insert("Py_REF_DEBUG", "1"); + // map.insert("Py_TRACE_REFS", "1"); + // map.insert("COUNT_ALLOCS", 1"); + Ok(map) +} + +fn is_value(key: &str) -> bool { + SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() +} + +fn cfg_line_for_var(key: &str, val: &str) -> Option { + if is_value(key) { + // is a value; suffix the key name with the value + Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) + } else if val != "0" { + // is a flag that isn't zero + Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) + } else { + // is a flag that is zero + None + } +} + +/// Run a python script using the specified interpreter binary. +fn run_python_script(interpreter: &str, script: &str) -> Result { + let mut cmd = Command::new(interpreter); + cmd.arg("-c").arg(script); + + let out = try!(cmd.output().map_err(|e| { + format!("failed to run python interpreter `{:?}`: {}", cmd, e) + })); + + if !out.status.success() { + let stderr = String::from_utf8(out.stderr).unwrap(); + let mut msg = format!("python script failed with stderr:\n\n"); + msg.push_str(&stderr); + return Err(msg); + } + + let out = String::from_utf8(out.stdout).unwrap(); + return Ok(out); +} + +#[cfg(not(target_os = "macos"))] +#[cfg(not(target_os = "windows"))] +fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, enable_shared: bool) + -> Result +{ + if enable_shared { + Ok(format!("cargo:rustc-link-lib=python{}", ld_version)) + } else { + Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) + } +} + +#[cfg(target_os = "windows")] +fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result +{ + // Py_ENABLE_SHARED doesn't seem to be present on windows. + Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, + match version.minor { + Some(minor) => minor.to_string(), + None => "".to_owned() + })) +} + +#[cfg(target_os = "macos")] +fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, _: bool) -> Result +{ + let path = Path::new(interpreter_path); + let file_stem = path.file_stem().unwrap().to_str().unwrap(); + + let link_library_name: String; + + // os x can be linked to a framework or static or dynamic, and + // Py_ENABLE_SHARED is wrong; framework means shared library + if file_stem.starts_with("pypy") { + if file_stem == "pypy" { + link_library_name = "pypy".to_string(); + } else if file_stem == "pypy3" { + link_library_name = "pypy3".to_string(); + } else { + return Err(format!("unknown interpreter {}", file_stem)); + } + match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib=static={}", link_library_name)), + "shared" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), + "framework" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), + other => Err(format!("unknown linkmodel {}", other)) + } + } else if file_stem.starts_with("python") { + match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), + "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + other => Err(format!("unknown linkmodel {}", other)) + } + } else { + return Err(format!("unknown interpreter {}", file_stem)); + } +} + + +#[cfg(target_os = "macos")] +fn get_macos_linkmodel(interpreter_path: &str) -> Result +{ + let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; + let out = run_python_script(interpreter_path, script).unwrap(); + Ok(out.trim_right().to_owned()) +} + + +/// Parse string as interpreter version. +fn get_interpreter_version(line: &str) -> Result +{ + let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); + match version_re.captures(&line) { + Some(cap) => Ok(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), + }), + None => Err( + format!("Unexpected response to version query {}", line)) + } +} + +fn check_pypy(interpreter_path: &str) -> bool { + let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; + let is_pypy: bool = run_python_script(interpreter_path, script) + .unwrap() + .to_lowercase() + .trim_right() + .parse() + .unwrap(); + + if is_pypy { + println!("cargo:rustc-cfg=PyPy"); + } + return is_pypy; +} + + +/// Locate a suitable python interpreter and extract config from it. +/// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided +/// path a Python executable, and raises an error if the version doesn't match. +/// Else tries to execute the interpreter as "python", "python{major version}", +/// "python{major version}.{minor version}" in order until one +/// is of the version we are expecting. +fn find_interpreter_and_get_config(expected_version: &PythonVersion) + -> Result<(PythonVersion, String, Vec), String> +{ + if let Some(sys_executable) = env::var_os("PYTHON_SYS_EXECUTABLE") { + let interpreter_path = sys_executable.to_str() + .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); + + let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); + + if expected_version == &interpreter_version { + return Ok((interpreter_version, interpreter_path.to_owned(), lines)); + } else { + return Err(format!("Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ + \tmin version {} != found {}", + interpreter_path, expected_version, interpreter_version)); + } + } + // check default python + let interpreter_path = "python"; + let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); + if expected_version == &interpreter_version { + return Ok((interpreter_version, interpreter_path.to_owned(), lines)); + } + + let major_interpreter_path = &format!("python{}", expected_version.major); + let (interpreter_version, lines) = try!(get_config_from_interpreter(major_interpreter_path)); + if expected_version == &interpreter_version { + return Ok((interpreter_version, major_interpreter_path.to_owned(), lines)); + } + + if let Some(minor) = expected_version.minor { + let minor_interpreter_path = &format!("python{}.{}", expected_version.major, minor); + let (interpreter_version, lines) = try!(get_config_from_interpreter( + minor_interpreter_path)); + if expected_version == &interpreter_version { + return Ok((interpreter_version, minor_interpreter_path.to_owned(), lines)); + } + } + + Err(format!("No python interpreter found")) +} + +/// Extract compilation vars from the specified interpreter. +fn get_config_from_interpreter(interpreter: &str) -> Result<(PythonVersion, Vec), String> { + let script = "import sys; import sysconfig; print(sys.version_info[0:2]); \ +print(sysconfig.get_config_var('LIBDIR')); \ +print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ +print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ +print(sys.exec_prefix);"; + let out = try!(run_python_script(interpreter, script)); + let lines: Vec = out.split(NEWLINE_SEQUENCE).map(|line| line.to_owned()).collect(); + let interpreter_version = try!(get_interpreter_version(&lines[0])); + let is_pypy = check_pypy(interpreter); + Ok((interpreter_version, lines)) +} + +/// Deduce configuration from the 'python' in the current PATH and print +/// cargo vars to stdout. +/// +/// Note that if the python doesn't satisfy expected_version, this will error. +fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, String), String> { + let (interpreter_version, interpreter_path, lines) = try!( + find_interpreter_and_get_config(expected_version)); + + let libpath: &str = &lines[1]; + let enable_shared: &str = &lines[2]; + let ld_version: &str = &lines[3]; + let exec_prefix: &str = &lines[4]; + + let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); + if !is_extension_module || cfg!(target_os="windows") { + println!("{}", get_rustc_link_lib(&interpreter_version, &interpreter_path, + ld_version, enable_shared == "1").unwrap()); + if libpath != "None" { + println!("cargo:rustc-link-search=native={}", libpath); + } else if cfg!(target_os="windows") { + println!("cargo:rustc-link-search=native={}\\libs", exec_prefix); + } + } + + let mut flags = String::new(); + + if let PythonVersion { major: 3, minor: some_minor } = interpreter_version { + if env::var_os("CARGO_FEATURE_PEP_384").is_some() { + println!("cargo:rustc-cfg=Py_LIMITED_API"); + } + if let Some(minor) = some_minor { + if minor < PY3_MIN_MINOR { + return Err(format!("Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor)); + } + for i in 5..(minor + 1) { + 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(); + } + return Ok((interpreter_path, flags)); +} + +/// Determine the python version we're supposed to be building +/// from the features passed via the environment. +/// +/// The environment variable can choose to omit a minor +/// version if the user doesn't care. +fn version_from_env() -> Result { + let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); + // sort env::vars so we get more explicit version specifiers first + // so if the user passes e.g. the python-3 feature and the python-3-5 + // feature, python-3-5 takes priority. + let mut vars = env::vars().collect::>(); + vars.sort_by(|a, b| b.cmp(a)); + for (key, _) in vars { + match re.captures(&key) { + Some(cap) => return Ok(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: match cap.get(3) { + Some(s) => Some(s.as_str().parse().unwrap()), + None => None + }, + }), + None => () + } + } + + Err("Python version feature was not found. At least one python version \ + feature must be enabled.".to_owned()) +} + +fn check_rustc_version() { + let ok_channel = supports_features(); + let ok_version = is_min_version(MIN_VERSION); + let ok_date = is_min_date(MIN_DATE); + + let print_version_err = |version: &str, date: &str| { + eprintln!("Installed version is: {} ({}). Minimum required: {} ({}).", + version, + date, + MIN_VERSION, + MIN_DATE); + }; + + match (ok_channel, ok_version, ok_date) { + (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { + if !ok_channel { + eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); + print_version_err(&*version, &*date); + panic!("Aborting compilation due to incompatible compiler.") + } + + if !ok_version || !ok_date { + eprintln!("Error: pyo3 requires a more recent version of rustc."); + eprintln!("Use `rustup update` or your preferred method to update Rust"); + print_version_err(&*version, &*date); + panic!("Aborting compilation due to incompatible compiler.") + } + } + _ => { + println!("cargo:warning={}", "pyo3 was unable to check rustc compatibility."); + println!("cargo:warning={}", "Build may fail due to incompatible rustc version."); + } + } +} + +fn main() { + check_rustc_version(); + // 1. Setup cfg variables so we can do conditional compilation in this + // library based on the python interpeter's compilation flags. This is + // necessary for e.g. matching the right unicode and threading interfaces. + // + // This locates the python interpreter based on the PATH, which should + // work smoothly with an activated virtualenv. + // + // If you have troubles with your shell accepting '.' in a var name, + // try using 'env' (sorry but this isn't our fault - it just has to + // match the pkg-config package name, which is going to have a . in it). + let version = match version_from_env() { + Ok(v) => v, + Err(_) => PythonVersion { major: 3, minor: None } + }; + let (python_interpreter_path, flags) = configure_from_path(&version).unwrap(); + let mut config_map = get_config_vars(&python_interpreter_path).unwrap(); + + // WITH_THREAD is always on for 3.7 + let (interpreter_version, _, _) = find_interpreter_and_get_config(&version).unwrap(); + if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { + config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + } + + for (key, val) in &config_map { + match cfg_line_for_var(key, val) { + Some(line) => println!("{}", line), + None => () + } + } + + // 2. Export python interpreter compilation flags as cargo variables that + // will be visible to dependents. All flags will be available to dependent + // build scripts in the environment variable DEP_PYTHON27_PYTHON_FLAGS as + // comma separated list; each item in the list looks like + // + // {VAL,FLAG}_{flag_name}=val; + // + // FLAG indicates the variable is always 0 or 1 + // VAL indicates it can take on any value + // + // rust-cypthon/build.rs contains an example of how to unpack this data + // into cfg flags that replicate theones present in this library, so + // you can use the same cfg syntax. + //let mut flags = flags; + let flags: String = config_map.iter().fold("".to_owned(), |memo, (key, val)| { + if is_value(key) { + memo + format!("VAL_{}={},", key, val).as_ref() + } else if val != "0" { + memo + format!("FLAG_{}={},", key, val).as_ref() + } else { + memo + } + }) + flags.as_str(); + + println!("cargo:python_flags={}", + if flags.len() > 0 { &flags[..flags.len() - 1] } else { "" }); +} From e67df5dbd83d6661f35fcc9246ef4f5790f5a208 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 00:50:16 +0200 Subject: [PATCH 002/138] removed stuff --- build.rs | 48 ++-- examples/debug_build.rs | 541 ---------------------------------------- 2 files changed, 27 insertions(+), 562 deletions(-) delete mode 100644 examples/debug_build.rs diff --git a/build.rs b/build.rs index f96d56b17db..369f4d3d49e 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,3 @@ -#![feature(asm)] -#![feature(core_intrinsics)] - -use std::intrinsics::breakpoint; - extern crate regex; extern crate version_check; @@ -239,24 +234,31 @@ fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &st let link_library_name: String; + // os x can be linked to a framework or static or dynamic, and + // Py_ENABLE_SHARED is wrong; framework means shared library if file_stem.starts_with("pypy") { - link_library_name = "pypy".to_string(); + if file_stem == "pypy" { + link_library_name = "pypy".to_string(); + } else if file_stem == "pypy3" { + link_library_name = "pypy3-c".to_string(); + } else { + return Err(format!("unknown interpreter {}", file_stem)); + } + match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), + "shared" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), + "framework" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), + other => Err(format!("unknown linkmodel {}", other)) + } } else if file_stem.starts_with("python") { - link_library_name = "python".to_string(); + match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), + "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + other => Err(format!("unknown linkmodel {}", other)) + } } else { - unreachable!() - } - - // os x can be linked to a framework or static or dynamic, and - // Py_ENABLE_SHARED is wrong; framework means shared library - match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static={}{}", - file_stem, ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib={}{}", - file_stem, ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib={}{}", - file_stem, ld_version)), - other => Err(format!("unknown linkmodel {}", other)) + return Err(format!("unknown interpreter {}", file_stem)); } } @@ -358,7 +360,7 @@ print(sys.exec_prefix);"; let out = try!(run_python_script(interpreter, script)); let lines: Vec = out.split(NEWLINE_SEQUENCE).map(|line| line.to_owned()).collect(); let interpreter_version = try!(get_interpreter_version(&lines[0])); - let is_pypy = check_pypy(interpreter); + check_pypy(interpreter); Ok((interpreter_version, lines)) } @@ -370,12 +372,14 @@ fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, Stri let (interpreter_version, interpreter_path, lines) = try!( find_interpreter_and_get_config(expected_version)); + // TODO: on pypy get this from somewhere else let libpath: &str = &lines[1]; let enable_shared: &str = &lines[2]; let ld_version: &str = &lines[3]; let exec_prefix: &str = &lines[4]; let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); + if !is_extension_module || cfg!(target_os="windows") { println!("{}", get_rustc_link_lib(&interpreter_version, &interpreter_path, ld_version, enable_shared == "1").unwrap()); @@ -492,6 +496,8 @@ fn main() { let (python_interpreter_path, flags) = configure_from_path(&version).unwrap(); let mut config_map = get_config_vars(&python_interpreter_path).unwrap(); + config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + // WITH_THREAD is always on for 3.7 let (interpreter_version, _, _) = find_interpreter_and_get_config(&version).unwrap(); if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { diff --git a/examples/debug_build.rs b/examples/debug_build.rs deleted file mode 100644 index 8191553cae6..00000000000 --- a/examples/debug_build.rs +++ /dev/null @@ -1,541 +0,0 @@ -#![feature(asm)] -#![feature(core_intrinsics)] - -use std::intrinsics::breakpoint; - -extern crate regex; -extern crate version_check; - -use std::process::Command; -use std::collections::HashMap; -use std::env; -use std::fmt; - -use regex::Regex; -use version_check::{supports_features, is_min_version, is_min_date}; -use std::path::Path; - -// Specifies the minimum nightly version needed to compile pyo3. -const MIN_DATE: &'static str = "2017-11-07"; -const MIN_VERSION: &'static str = "1.23.0-nightly"; - -#[derive(Debug)] -struct PythonVersion { - major: u8, - // minor == None means any minor version will do - minor: Option, -} - -impl PartialEq for PythonVersion { - fn eq(&self, o: &PythonVersion) -> bool { - self.major == o.major && (self.minor.is_none() || self.minor == o.minor) - } -} - -impl fmt::Display for PythonVersion { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(self.major.fmt(f)); - try!(f.write_str(".")); - match self.minor { - Some(minor) => try!(minor.fmt(f)), - None => try!(f.write_str("*")) - }; - Ok(()) - } -} - -const PY3_MIN_MINOR: u8 = 5; - -const CFG_KEY: &'static str = "py_sys_config"; - -// windows' python writes out lines with the windows crlf sequence; -// posix platforms and mac os should write out lines with just lf. -#[cfg(target_os = "windows")] -static NEWLINE_SEQUENCE: &'static str = "\r\n"; - -#[cfg(not(target_os = "windows"))] -static NEWLINE_SEQUENCE: &'static str = "\n"; - -// A list of python interpreter compile-time preprocessor defines that -// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; -// this allows using them conditional cfg attributes in the .rs files, so -// -// #[cfg(py_sys_config="{varname}"] -// -// is the equivalent of #ifdef {varname} name in C. -// -// see Misc/SpecialBuilds.txt in the python source for what these mean. -// -// (hrm, this is sort of re-implementing what distutils does, except -// by passing command line args instead of referring to a python.h) -#[cfg(not(target_os = "windows"))] -static SYSCONFIG_FLAGS: [&'static str; 7] = [ - "Py_USING_UNICODE", - "Py_UNICODE_WIDE", - "WITH_THREAD", - "Py_DEBUG", - "Py_REF_DEBUG", - "Py_TRACE_REFS", - "COUNT_ALLOCS", -]; - -static SYSCONFIG_VALUES: [&'static str; 1] = [ - // cfg doesn't support flags with values, just bools - so flags - // below are translated into bools as {varname}_{val} - // - // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 - "Py_UNICODE_SIZE" // note - not present on python 3.3+, which is always wide -]; - -/// Examine python's compile flags to pass to cfg by launching -/// the interpreter and printing variables of interest from -/// sysconfig.get_config_vars. -#[cfg(not(target_os = "windows"))] -fn get_config_vars(python_path: &String) -> Result, String> { - let mut script = "import sysconfig; \ -config = sysconfig.get_config_vars();".to_owned(); - - for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!("print(config.get('{}', {}))", k, - if is_value(k) { "None" } else { "0" })); - script.push_str(";"); - } - - let mut cmd = Command::new(python_path); - cmd.arg("-c").arg(script); - - let out = try!(cmd.output().map_err(|e| { - format!("failed to run python interpreter `{:?}`: {}", cmd, e) - })); - - if !out.status.success() { - let stderr = String::from_utf8(out.stderr).unwrap(); - let mut msg = format!("python script failed with stderr:\n\n"); - msg.push_str(&stderr); - return Err(msg); - } - - let stdout = String::from_utf8(out.stdout).unwrap(); - let split_stdout: Vec<&str> = stdout.trim_right().split(NEWLINE_SEQUENCE).collect(); - if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { - return Err( - format!("python stdout len didn't return expected number of lines: -{}", split_stdout.len()).to_string()); - } - let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); - // let var_map: HashMap = HashMap::new(); - let mut all_vars = all_vars.zip(split_stdout.iter()) - .fold(HashMap::new(), |mut memo: HashMap, (&k, &v)| { - if !(v.to_owned() == "None" && is_value(k)) { - memo.insert(k.to_owned(), v.to_owned()); - } - memo - }); - - let debug = if let Some(val) = all_vars.get("Py_DEBUG") { val == "1" } else { false }; - if debug { - all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); - } - - Ok(all_vars) -} - -#[cfg(target_os = "windows")] -fn get_config_vars(_: &String) -> Result, String> { - // sysconfig is missing all the flags on windows, so we can't actually - // query the interpreter directly for its build flags. - // - // For the time being, this is the flags as defined in the python source's - // PC\pyconfig.h. This won't work correctly if someone has built their - // python with a modified pyconfig.h - sorry if that is you, you will have - // to comment/uncomment the lines below. - let mut map: HashMap = HashMap::new(); - map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); - map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); - - // This is defined #ifdef _DEBUG. The visual studio build seems to produce - // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the - // Debug configuration, which this script doesn't currently support anyway. - // map.insert("Py_DEBUG", "1"); - - // Uncomment these manually if your python was built with these and you want - // the cfg flags to be set in rust. - // - // map.insert("Py_REF_DEBUG", "1"); - // map.insert("Py_TRACE_REFS", "1"); - // map.insert("COUNT_ALLOCS", 1"); - Ok(map) -} - -fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() -} - -fn cfg_line_for_var(key: &str, val: &str) -> Option { - if is_value(key) { - // is a value; suffix the key name with the value - Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) - } else if val != "0" { - // is a flag that isn't zero - Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) - } else { - // is a flag that is zero - None - } -} - -/// Run a python script using the specified interpreter binary. -fn run_python_script(interpreter: &str, script: &str) -> Result { - let mut cmd = Command::new(interpreter); - cmd.arg("-c").arg(script); - - let out = try!(cmd.output().map_err(|e| { - format!("failed to run python interpreter `{:?}`: {}", cmd, e) - })); - - if !out.status.success() { - let stderr = String::from_utf8(out.stderr).unwrap(); - let mut msg = format!("python script failed with stderr:\n\n"); - msg.push_str(&stderr); - return Err(msg); - } - - let out = String::from_utf8(out.stdout).unwrap(); - return Ok(out); -} - -#[cfg(not(target_os = "macos"))] -#[cfg(not(target_os = "windows"))] -fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, enable_shared: bool) - -> Result -{ - if enable_shared { - Ok(format!("cargo:rustc-link-lib=python{}", ld_version)) - } else { - Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) - } -} - -#[cfg(target_os = "windows")] -fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result -{ - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned() - })) -} - -#[cfg(target_os = "macos")] -fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, _: bool) -> Result -{ - let path = Path::new(interpreter_path); - let file_stem = path.file_stem().unwrap().to_str().unwrap(); - - let link_library_name: String; - - // os x can be linked to a framework or static or dynamic, and - // Py_ENABLE_SHARED is wrong; framework means shared library - if file_stem.starts_with("pypy") { - if file_stem == "pypy" { - link_library_name = "pypy".to_string(); - } else if file_stem == "pypy3" { - link_library_name = "pypy3".to_string(); - } else { - return Err(format!("unknown interpreter {}", file_stem)); - } - match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static={}", link_library_name)), - "shared" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), - "framework" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), - other => Err(format!("unknown linkmodel {}", other)) - } - } else if file_stem.starts_with("python") { - match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - other => Err(format!("unknown linkmodel {}", other)) - } - } else { - return Err(format!("unknown interpreter {}", file_stem)); - } -} - - -#[cfg(target_os = "macos")] -fn get_macos_linkmodel(interpreter_path: &str) -> Result -{ - let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; - let out = run_python_script(interpreter_path, script).unwrap(); - Ok(out.trim_right().to_owned()) -} - - -/// Parse string as interpreter version. -fn get_interpreter_version(line: &str) -> Result -{ - let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); - match version_re.captures(&line) { - Some(cap) => Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), - }), - None => Err( - format!("Unexpected response to version query {}", line)) - } -} - -fn check_pypy(interpreter_path: &str) -> bool { - let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; - let is_pypy: bool = run_python_script(interpreter_path, script) - .unwrap() - .to_lowercase() - .trim_right() - .parse() - .unwrap(); - - if is_pypy { - println!("cargo:rustc-cfg=PyPy"); - } - return is_pypy; -} - - -/// Locate a suitable python interpreter and extract config from it. -/// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided -/// path a Python executable, and raises an error if the version doesn't match. -/// Else tries to execute the interpreter as "python", "python{major version}", -/// "python{major version}.{minor version}" in order until one -/// is of the version we are expecting. -fn find_interpreter_and_get_config(expected_version: &PythonVersion) - -> Result<(PythonVersion, String, Vec), String> -{ - if let Some(sys_executable) = env::var_os("PYTHON_SYS_EXECUTABLE") { - let interpreter_path = sys_executable.to_str() - .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); - - let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); - - if expected_version == &interpreter_version { - return Ok((interpreter_version, interpreter_path.to_owned(), lines)); - } else { - return Err(format!("Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ - \tmin version {} != found {}", - interpreter_path, expected_version, interpreter_version)); - } - } - // check default python - let interpreter_path = "python"; - let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); - if expected_version == &interpreter_version { - return Ok((interpreter_version, interpreter_path.to_owned(), lines)); - } - - let major_interpreter_path = &format!("python{}", expected_version.major); - let (interpreter_version, lines) = try!(get_config_from_interpreter(major_interpreter_path)); - if expected_version == &interpreter_version { - return Ok((interpreter_version, major_interpreter_path.to_owned(), lines)); - } - - if let Some(minor) = expected_version.minor { - let minor_interpreter_path = &format!("python{}.{}", expected_version.major, minor); - let (interpreter_version, lines) = try!(get_config_from_interpreter( - minor_interpreter_path)); - if expected_version == &interpreter_version { - return Ok((interpreter_version, minor_interpreter_path.to_owned(), lines)); - } - } - - Err(format!("No python interpreter found")) -} - -/// Extract compilation vars from the specified interpreter. -fn get_config_from_interpreter(interpreter: &str) -> Result<(PythonVersion, Vec), String> { - let script = "import sys; import sysconfig; print(sys.version_info[0:2]); \ -print(sysconfig.get_config_var('LIBDIR')); \ -print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ -print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ -print(sys.exec_prefix);"; - let out = try!(run_python_script(interpreter, script)); - let lines: Vec = out.split(NEWLINE_SEQUENCE).map(|line| line.to_owned()).collect(); - let interpreter_version = try!(get_interpreter_version(&lines[0])); - let is_pypy = check_pypy(interpreter); - Ok((interpreter_version, lines)) -} - -/// Deduce configuration from the 'python' in the current PATH and print -/// cargo vars to stdout. -/// -/// Note that if the python doesn't satisfy expected_version, this will error. -fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, String), String> { - let (interpreter_version, interpreter_path, lines) = try!( - find_interpreter_and_get_config(expected_version)); - - let libpath: &str = &lines[1]; - let enable_shared: &str = &lines[2]; - let ld_version: &str = &lines[3]; - let exec_prefix: &str = &lines[4]; - - let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - if !is_extension_module || cfg!(target_os="windows") { - println!("{}", get_rustc_link_lib(&interpreter_version, &interpreter_path, - ld_version, enable_shared == "1").unwrap()); - if libpath != "None" { - println!("cargo:rustc-link-search=native={}", libpath); - } else if cfg!(target_os="windows") { - println!("cargo:rustc-link-search=native={}\\libs", exec_prefix); - } - } - - let mut flags = String::new(); - - if let PythonVersion { major: 3, minor: some_minor } = interpreter_version { - if env::var_os("CARGO_FEATURE_PEP_384").is_some() { - println!("cargo:rustc-cfg=Py_LIMITED_API"); - } - if let Some(minor) = some_minor { - if minor < PY3_MIN_MINOR { - return Err(format!("Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor)); - } - for i in 5..(minor + 1) { - 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(); - } - return Ok((interpreter_path, flags)); -} - -/// Determine the python version we're supposed to be building -/// from the features passed via the environment. -/// -/// The environment variable can choose to omit a minor -/// version if the user doesn't care. -fn version_from_env() -> Result { - let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); - // sort env::vars so we get more explicit version specifiers first - // so if the user passes e.g. the python-3 feature and the python-3-5 - // feature, python-3-5 takes priority. - let mut vars = env::vars().collect::>(); - vars.sort_by(|a, b| b.cmp(a)); - for (key, _) in vars { - match re.captures(&key) { - Some(cap) => return Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: match cap.get(3) { - Some(s) => Some(s.as_str().parse().unwrap()), - None => None - }, - }), - None => () - } - } - - Err("Python version feature was not found. At least one python version \ - feature must be enabled.".to_owned()) -} - -fn check_rustc_version() { - let ok_channel = supports_features(); - let ok_version = is_min_version(MIN_VERSION); - let ok_date = is_min_date(MIN_DATE); - - let print_version_err = |version: &str, date: &str| { - eprintln!("Installed version is: {} ({}). Minimum required: {} ({}).", - version, - date, - MIN_VERSION, - MIN_DATE); - }; - - match (ok_channel, ok_version, ok_date) { - (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { - if !ok_channel { - eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - - if !ok_version || !ok_date { - eprintln!("Error: pyo3 requires a more recent version of rustc."); - eprintln!("Use `rustup update` or your preferred method to update Rust"); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - } - _ => { - println!("cargo:warning={}", "pyo3 was unable to check rustc compatibility."); - println!("cargo:warning={}", "Build may fail due to incompatible rustc version."); - } - } -} - -fn main() { - check_rustc_version(); - // 1. Setup cfg variables so we can do conditional compilation in this - // library based on the python interpeter's compilation flags. This is - // necessary for e.g. matching the right unicode and threading interfaces. - // - // This locates the python interpreter based on the PATH, which should - // work smoothly with an activated virtualenv. - // - // If you have troubles with your shell accepting '.' in a var name, - // try using 'env' (sorry but this isn't our fault - it just has to - // match the pkg-config package name, which is going to have a . in it). - let version = match version_from_env() { - Ok(v) => v, - Err(_) => PythonVersion { major: 3, minor: None } - }; - let (python_interpreter_path, flags) = configure_from_path(&version).unwrap(); - let mut config_map = get_config_vars(&python_interpreter_path).unwrap(); - - // WITH_THREAD is always on for 3.7 - let (interpreter_version, _, _) = find_interpreter_and_get_config(&version).unwrap(); - if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { - config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - } - - for (key, val) in &config_map { - match cfg_line_for_var(key, val) { - Some(line) => println!("{}", line), - None => () - } - } - - // 2. Export python interpreter compilation flags as cargo variables that - // will be visible to dependents. All flags will be available to dependent - // build scripts in the environment variable DEP_PYTHON27_PYTHON_FLAGS as - // comma separated list; each item in the list looks like - // - // {VAL,FLAG}_{flag_name}=val; - // - // FLAG indicates the variable is always 0 or 1 - // VAL indicates it can take on any value - // - // rust-cypthon/build.rs contains an example of how to unpack this data - // into cfg flags that replicate theones present in this library, so - // you can use the same cfg syntax. - //let mut flags = flags; - let flags: String = config_map.iter().fold("".to_owned(), |memo, (key, val)| { - if is_value(key) { - memo + format!("VAL_{}={},", key, val).as_ref() - } else if val != "0" { - memo + format!("FLAG_{}={},", key, val).as_ref() - } else { - memo - } - }) + flags.as_str(); - - println!("cargo:python_flags={}", - if flags.len() > 0 { &flags[..flags.len() - 1] } else { "" }); -} From c9d69671e1d7212db81b2183edf209e66dca0bbc Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 00:51:03 +0200 Subject: [PATCH 003/138] removed another change --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e3596b63fb..e021d720b4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,6 @@ version_check = "0.1" regex = "0.2" version_check = "0.1" -[[example]] -name = "debug_build" - [features] default = [] From d44a07c9ea575c619796cf2b81a7a759e9480149 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 00:51:23 +0200 Subject: [PATCH 004/138] implemented minimum amouth of ifdefs to make pypy3 hello world to compile --- src/ffi3/ceval.rs | 1 + src/ffi3/codecs.rs | 3 ++- src/ffi3/dictobject.rs | 5 +++++ src/ffi3/listobject.rs | 2 ++ src/ffi3/methodobject.rs | 1 + src/ffi3/modsupport.rs | 2 ++ src/ffi3/object.rs | 33 +++++++++++++++++++++++++++++++++ src/ffi3/objectabstract.rs | 1 + src/ffi3/pyerrors.rs | 5 +++++ src/ffi3/pythonrun.rs | 2 ++ src/ffi3/unicodeobject.rs | 2 ++ src/objects/exc.rs | 4 +++- 12 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 327b227891c..781a676aa28 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -61,6 +61,7 @@ pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) #[cfg(py_sys_config = "WITH_THREAD")] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyEval_ThreadsInitialized() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_InitThreads")] pub fn PyEval_InitThreads() -> (); pub fn PyEval_AcquireLock() -> (); pub fn PyEval_ReleaseLock() -> (); diff --git a/src/ffi3/codecs.rs b/src/ffi3/codecs.rs index 7090ca65856..f7278276e7d 100644 --- a/src/ffi3/codecs.rs +++ b/src/ffi3/codecs.rs @@ -1,7 +1,8 @@ use std::os::raw::{c_char, c_int}; use ffi3::object::PyObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] +extern "C" { pub fn PyCodec_Register(search_function: *mut PyObject) -> c_int; pub fn PyCodec_KnownEncoding(encoding: *const c_char) -> c_int; diff --git a/src/ffi3/dictobject.rs b/src/ffi3/dictobject.rs index 55621f3322b..a82aceaeb1b 100644 --- a/src/ffi3/dictobject.rs +++ b/src/ffi3/dictobject.rs @@ -43,9 +43,12 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; pub fn PyDict_Clear(mp: *mut PyObject) -> (); @@ -53,7 +56,9 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; diff --git a/src/ffi3/listobject.rs b/src/ffi3/listobject.rs index ac68e5f3e44..99c6ce39f9a 100644 --- a/src/ffi3/listobject.rs +++ b/src/ffi3/listobject.rs @@ -20,7 +20,9 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Size")] pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetItem")] pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; pub fn PyList_Insert(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index 3a1c3edcba9..49db6065932 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -64,6 +64,7 @@ pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] pub fn PyCFunction_NewEx(arg1: *mut PyMethodDef, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi3/modsupport.rs b/src/ffi3/modsupport.rs index c404aa64e16..ddb82f5b33f 100644 --- a/src/ffi3/modsupport.rs +++ b/src/ffi3/modsupport.rs @@ -42,6 +42,7 @@ pub const PYTHON_ABI_VERSION: i32 = 3; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg(not(py_sys_config="Py_TRACE_REFS"))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Create2")] pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; @@ -62,6 +63,7 @@ pub const PYTHON_ABI_VERSION: i32 = 3; #[cfg(py_sys_config="Py_TRACE_REFS")] #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Create2")] pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { PyModule_Create2TraceRefs(module, apiver) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 302563a5c6e..6955796da93 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -4,6 +4,7 @@ use ffi3::pyport::{Py_ssize_t, Py_hash_t}; #[repr(C)] #[derive(Copy, Clone, Debug)] +#[cfg(not(PyPy))] pub struct PyObject { #[cfg(py_sys_config="Py_TRACE_REFS")] _ob_next: *mut PyObject, @@ -13,17 +14,46 @@ pub struct PyObject { pub ob_type: *mut PyTypeObject, } +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[cfg(PyPy)] +pub struct PyObject { + pub ob_refcnt: Py_ssize_t, + pub ob_pypy_link: Py_ssize_t, + pub ob_type: *mut PyTypeObject, +} + +#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(not(PyPy))] +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"))] +#[cfg(not(PyPy))] +pub const PyObject_HEAD_INIT: PyObject = PyObject { + ob_refcnt: 1, + ob_type: ::std::ptr::null_mut() +}; + #[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, + ob_pypy_link: 0, ob_type: ::std::ptr::null_mut() }; #[cfg(not(py_sys_config="Py_TRACE_REFS"))] +#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, + ob_pypy_link: 0, ob_type: ::std::ptr::null_mut() }; @@ -653,6 +683,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { arg3: *mut PyObject) -> c_int; pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] 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; @@ -743,6 +774,7 @@ pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_Dealloc")] pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } @@ -795,6 +827,7 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; static mut _Py_NotImplementedStruct: PyObject; } diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index bfedf6fb0ae..96fb20d0086 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -18,6 +18,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ kw: *mut PyObject) -> *mut PyObject; pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "\u{1}_PyPyObject_CallFunction")] pub fn PyObject_CallFunction(callable_object: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 121fc592d37..660ac1774b0 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -9,8 +9,10 @@ use ffi3::object::*; string: *const c_char) -> (); pub fn PyErr_Occurred() -> *mut PyObject; pub fn PyErr_Clear() -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Fetch")] pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); pub fn PyErr_GetExcInfo(arg1: *mut *mut PyObject, @@ -84,12 +86,15 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub static mut PyExc_IndentationError: *mut PyObject; pub static mut PyExc_TabError: *mut PyObject; pub static mut PyExc_ReferenceError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; pub static mut PyExc_SystemExit: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; pub static mut PyExc_UnicodeTranslateError: *mut PyObject; pub static mut PyExc_ValueError: *mut PyObject; diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index 309573c86a0..2889e8b0bdb 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -167,7 +167,9 @@ pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: start: c_int) -> *mut symtable; + #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_Print")] pub fn PyErr_Print() -> (); + #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int) -> (); pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index 26e6bbed4b2..ea6bc4beeab 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -44,6 +44,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] pub fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; pub fn PyUnicode_FromString(u: *const c_char) -> *mut PyObject; @@ -97,6 +98,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8AndSize")] pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut c_char; diff --git a/src/objects/exc.rs b/src/objects/exc.rs index c5cc2dce6e7..e57f7ee2dbb 100644 --- a/src/objects/exc.rs +++ b/src/objects/exc.rs @@ -139,7 +139,9 @@ impl UnicodeDecodeError { unsafe { let input: &[c_char] = mem::transmute(input); py.from_owned_ptr_or_err( - ffi::PyUnicodeDecodeError_Create( + ffi::PyObject_CallFunction( + ffi::PyExc_UnicodeDecodeError, + cstr!("sy#nns").as_ptr(), encoding.as_ptr(), input.as_ptr(), input.len() as ffi::Py_ssize_t, From 409849db8b741c9cabff8a50789f9fa67e01de00 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 00:51:23 +0200 Subject: [PATCH 005/138] implemented minimum amount of ifdefs to make pypy3 hello world to compile --- src/ffi3/ceval.rs | 1 + src/ffi3/codecs.rs | 3 ++- src/ffi3/dictobject.rs | 5 +++++ src/ffi3/listobject.rs | 2 ++ src/ffi3/methodobject.rs | 1 + src/ffi3/modsupport.rs | 2 ++ src/ffi3/object.rs | 33 +++++++++++++++++++++++++++++++++ src/ffi3/objectabstract.rs | 1 + src/ffi3/pyerrors.rs | 5 +++++ src/ffi3/pythonrun.rs | 2 ++ src/ffi3/unicodeobject.rs | 2 ++ src/objects/exc.rs | 4 +++- 12 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 327b227891c..781a676aa28 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -61,6 +61,7 @@ pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) #[cfg(py_sys_config = "WITH_THREAD")] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyEval_ThreadsInitialized() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_InitThreads")] pub fn PyEval_InitThreads() -> (); pub fn PyEval_AcquireLock() -> (); pub fn PyEval_ReleaseLock() -> (); diff --git a/src/ffi3/codecs.rs b/src/ffi3/codecs.rs index 7090ca65856..f7278276e7d 100644 --- a/src/ffi3/codecs.rs +++ b/src/ffi3/codecs.rs @@ -1,7 +1,8 @@ use std::os::raw::{c_char, c_int}; use ffi3::object::PyObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] +extern "C" { pub fn PyCodec_Register(search_function: *mut PyObject) -> c_int; pub fn PyCodec_KnownEncoding(encoding: *const c_char) -> c_int; diff --git a/src/ffi3/dictobject.rs b/src/ffi3/dictobject.rs index 55621f3322b..a82aceaeb1b 100644 --- a/src/ffi3/dictobject.rs +++ b/src/ffi3/dictobject.rs @@ -43,9 +43,12 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; pub fn PyDict_Clear(mp: *mut PyObject) -> (); @@ -53,7 +56,9 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; diff --git a/src/ffi3/listobject.rs b/src/ffi3/listobject.rs index ac68e5f3e44..99c6ce39f9a 100644 --- a/src/ffi3/listobject.rs +++ b/src/ffi3/listobject.rs @@ -20,7 +20,9 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Size")] pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetItem")] pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; pub fn PyList_Insert(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index 3a1c3edcba9..49db6065932 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -64,6 +64,7 @@ pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] pub fn PyCFunction_NewEx(arg1: *mut PyMethodDef, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi3/modsupport.rs b/src/ffi3/modsupport.rs index c404aa64e16..ddb82f5b33f 100644 --- a/src/ffi3/modsupport.rs +++ b/src/ffi3/modsupport.rs @@ -42,6 +42,7 @@ pub const PYTHON_ABI_VERSION: i32 = 3; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg(not(py_sys_config="Py_TRACE_REFS"))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Create2")] pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; @@ -62,6 +63,7 @@ pub const PYTHON_ABI_VERSION: i32 = 3; #[cfg(py_sys_config="Py_TRACE_REFS")] #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Create2")] pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { PyModule_Create2TraceRefs(module, apiver) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 302563a5c6e..6955796da93 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -4,6 +4,7 @@ use ffi3::pyport::{Py_ssize_t, Py_hash_t}; #[repr(C)] #[derive(Copy, Clone, Debug)] +#[cfg(not(PyPy))] pub struct PyObject { #[cfg(py_sys_config="Py_TRACE_REFS")] _ob_next: *mut PyObject, @@ -13,17 +14,46 @@ pub struct PyObject { pub ob_type: *mut PyTypeObject, } +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[cfg(PyPy)] +pub struct PyObject { + pub ob_refcnt: Py_ssize_t, + pub ob_pypy_link: Py_ssize_t, + pub ob_type: *mut PyTypeObject, +} + +#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(not(PyPy))] +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"))] +#[cfg(not(PyPy))] +pub const PyObject_HEAD_INIT: PyObject = PyObject { + ob_refcnt: 1, + ob_type: ::std::ptr::null_mut() +}; + #[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, + ob_pypy_link: 0, ob_type: ::std::ptr::null_mut() }; #[cfg(not(py_sys_config="Py_TRACE_REFS"))] +#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, + ob_pypy_link: 0, ob_type: ::std::ptr::null_mut() }; @@ -653,6 +683,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { arg3: *mut PyObject) -> c_int; pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] 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; @@ -743,6 +774,7 @@ pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_Dealloc")] pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } @@ -795,6 +827,7 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; static mut _Py_NotImplementedStruct: PyObject; } diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index bfedf6fb0ae..96fb20d0086 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -18,6 +18,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ kw: *mut PyObject) -> *mut PyObject; pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "\u{1}_PyPyObject_CallFunction")] pub fn PyObject_CallFunction(callable_object: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 121fc592d37..660ac1774b0 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -9,8 +9,10 @@ use ffi3::object::*; string: *const c_char) -> (); pub fn PyErr_Occurred() -> *mut PyObject; pub fn PyErr_Clear() -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Fetch")] pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); pub fn PyErr_GetExcInfo(arg1: *mut *mut PyObject, @@ -84,12 +86,15 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub static mut PyExc_IndentationError: *mut PyObject; pub static mut PyExc_TabError: *mut PyObject; pub static mut PyExc_ReferenceError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; pub static mut PyExc_SystemExit: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; pub static mut PyExc_UnicodeTranslateError: *mut PyObject; pub static mut PyExc_ValueError: *mut PyObject; diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index 309573c86a0..2889e8b0bdb 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -167,7 +167,9 @@ pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: start: c_int) -> *mut symtable; + #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_Print")] pub fn PyErr_Print() -> (); + #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int) -> (); pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index 26e6bbed4b2..ea6bc4beeab 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -44,6 +44,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] pub fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; pub fn PyUnicode_FromString(u: *const c_char) -> *mut PyObject; @@ -97,6 +98,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8AndSize")] pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut c_char; diff --git a/src/objects/exc.rs b/src/objects/exc.rs index c5cc2dce6e7..e57f7ee2dbb 100644 --- a/src/objects/exc.rs +++ b/src/objects/exc.rs @@ -139,7 +139,9 @@ impl UnicodeDecodeError { unsafe { let input: &[c_char] = mem::transmute(input); py.from_owned_ptr_or_err( - ffi::PyUnicodeDecodeError_Create( + ffi::PyObject_CallFunction( + ffi::PyExc_UnicodeDecodeError, + cstr!("sy#nns").as_ptr(), encoding.as_ptr(), input.as_ptr(), input.len() as ffi::Py_ssize_t, From 61ecd79053af93d40646c857981d39f4ff0a8f54 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 21:33:26 +0200 Subject: [PATCH 006/138] hacking on build.rs --- .cargo/config | 3 + build.rs | 254 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 168 insertions(+), 89 deletions(-) create mode 100644 .cargo/config diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 00000000000..4287c59637d --- /dev/null +++ b/.cargo/config @@ -0,0 +1,3 @@ +[build] +rustflags = ["-Clink-args=-Wl,-rpath,/Users/omerba/anaconda/lib/", + "-Clink-arg=-undefined", "-Clink-arg=dynamic_lookup"] \ No newline at end of file diff --git a/build.rs b/build.rs index 369f4d3d49e..25b3532c6a1 100644 --- a/build.rs +++ b/build.rs @@ -8,12 +8,29 @@ use std::fmt; use regex::Regex; use version_check::{supports_features, is_min_version, is_min_date}; -use std::path::Path; +use std::path::{Path, PathBuf}; + +#[feature(match_default_bindings)] // Specifies the minimum nightly version needed to compile pyo3. const MIN_DATE: &'static str = "2017-11-07"; const MIN_VERSION: &'static str = "1.23.0-nightly"; +fn canonicalize_executable

(exe_name: P) -> Option + where P: AsRef, +{ + env::var_os("PATH").and_then(|paths| { + env::split_paths(&paths).filter_map(|dir| { + let full_path = dir.join(&exe_name); + if full_path.is_file() { + Some(full_path) + } else { + None + } + }).next() + }) +} + #[derive(Debug)] struct PythonVersion { major: u8, @@ -39,6 +56,60 @@ impl fmt::Display for PythonVersion { } } +#[derive(Debug)] +struct InterpreterConfig<'a> { + version: &'a PythonVersion, + path: &'a Path, + libpath: String, + enable_shared: bool, + ld_version: String, + exec_prefix: String, + is_pypy: bool, +} + +impl<'a> InterpreterConfig<'a> { + fn from_cpython(interpreter: &'a Path) -> Result { + let script = "import sys; import sysconfig;\ + print(sys.version_info[0:2]); \ + print(sysconfig.get_config_var('LIBDIR')); \ + print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ + print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ + print(sys.exec_prefix);"; + + let out = try!(run_python_script(interpreter.to_str(), script)); + + let lines: Vec = + out.lines() + .map(|line: &str| line.to_owned()) + .collect(); + + let cpython_version = try!(parse_interpreter_version(&lines[0])); + + Ok(InterpreterConfig { + version: &cpython_version, + path: interpreter, + libpath: lines[1], + enable_shared: lines[2].parse().unwrap(), + ld_version: lines[3], + exec_prefix: lines[4], + is_pypy: false, + }) + } + + fn from_pypy(interpreter: &'a Path) -> Result { + Ok(InterpreterConfig { + version: &PythonVersion { major: 3, minor: Some(5) }, + path: interpreter, + libpath: "/Users/omerba/anaconda/lib".to_string(), + enable_shared: true, + ld_version: "3.5".to_string(), + exec_prefix: "/Users/omerba/anaconda".to_string(), + is_pypy: true, + }) + } +} + + const PY3_MIN_MINOR: u8 = 5; const CFG_KEY: &'static str = "py_sys_config"; @@ -216,8 +287,17 @@ fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &st } #[cfg(target_os = "windows")] -fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result +fn get_rustc_link_lib(interpreter_config: InterpreterConfig) -> Result { + if interpreter_config.is_pypy { + let link_library_name = match interpreter_config.version.major { + 2 => "pypy-c", + 3 => "pypy3-c" + }; + // All modern PyPy versions with cpyext are compiled as shared libraries. + return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + } + // Py_ENABLE_SHARED doesn't seem to be present on windows. Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, match version.minor { @@ -227,38 +307,24 @@ fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result Result +fn get_rustc_link_lib(interpreter_config: InterpreterConfig) -> Result { - let path = Path::new(interpreter_path); - let file_stem = path.file_stem().unwrap().to_str().unwrap(); - - let link_library_name: String; + if interpreter_config.is_pypy { + let link_library_name = match interpreter_config.version.major { + 2 => "pypy-c", + 3 => "pypy3-c" + }; + // All modern PyPy versions with cpyext are compiled as shared libraries. + return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + } // os x can be linked to a framework or static or dynamic, and // Py_ENABLE_SHARED is wrong; framework means shared library - if file_stem.starts_with("pypy") { - if file_stem == "pypy" { - link_library_name = "pypy".to_string(); - } else if file_stem == "pypy3" { - link_library_name = "pypy3-c".to_string(); - } else { - return Err(format!("unknown interpreter {}", file_stem)); - } - match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), - "shared" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), - "framework" => Ok(format!("cargo:rustc-link-lib={}", link_library_name)), - other => Err(format!("unknown linkmodel {}", other)) - } - } else if file_stem.starts_with("python") { - match get_macos_linkmodel(interpreter_path).unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - other => Err(format!("unknown linkmodel {}", other)) - } - } else { - return Err(format!("unknown interpreter {}", file_stem)); + match get_macos_linkmodel(interpreter_config.path).unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", interpreter_config.ld_version)), + "shared" => Ok(format!("cargo:rustc-link-lib=python{}", interpreter_config.ld_version)), + "framework" => Ok(format!("cargo:rustc-link-lib=python{}", interpreter_config.ld_version)), + other => Err(format!("unknown linkmodel {}", other)) } } @@ -273,7 +339,7 @@ fn get_macos_linkmodel(interpreter_path: &str) -> Result /// Parse string as interpreter version. -fn get_interpreter_version(line: &str) -> Result +fn parse_interpreter_version(line: &str) -> Result { let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); match version_re.captures(&line) { @@ -308,91 +374,74 @@ fn check_pypy(interpreter_path: &str) -> bool { /// Else tries to execute the interpreter as "python", "python{major version}", /// "python{major version}.{minor version}" in order until one /// is of the version we are expecting. -fn find_interpreter_and_get_config(expected_version: &PythonVersion) - -> Result<(PythonVersion, String, Vec), String> +fn find_interpreter(expected_version: &PythonVersion) + -> Result { - if let Some(sys_executable) = env::var_os("PYTHON_SYS_EXECUTABLE") { - let interpreter_path = sys_executable.to_str() + // To use PyPy, a valid pypy executable must be passed to PYTHON_SYS_EXECUTABLE + if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { + let interpreter_path_or_executable = interpreter_from_env.to_str() .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); - let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); + let interpreter_path = canonicalize_executable(interpreter_path_or_executable); - if expected_version == &interpreter_version { - return Ok((interpreter_version, interpreter_path.to_owned(), lines)); - } else { - return Err(format!("Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ + if interpreter_path.is_some() { + let interpreter_config: InterpreterConfig = try!(InterpreterConfig::from_pypy(&Path::new(interpreter_path.expect()))); + + if expected_version == interpreter_config.version { + return Ok(interpreter_config); + } else { + return Err(format!("Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ \tmin version {} != found {}", - interpreter_path, expected_version, interpreter_version)); + interpreter_path_or_executable, expected_version, interpreter_config.version)); + } + } else { + Err(format!("Could not find interpreter passed in PYTHON_SYS_EXECUTABLE={}\n", interpreter_path_or_executable)); } } + // check default python - let interpreter_path = "python"; - let (interpreter_version, lines) = try!(get_config_from_interpreter(interpreter_path)); - if expected_version == &interpreter_version { - return Ok((interpreter_version, interpreter_path.to_owned(), lines)); - } + let system_python = "python"; - let major_interpreter_path = &format!("python{}", expected_version.major); - let (interpreter_version, lines) = try!(get_config_from_interpreter(major_interpreter_path)); - if expected_version == &interpreter_version { - return Ok((interpreter_version, major_interpreter_path.to_owned(), lines)); + let mut possible_python_paths = vec!["python".to_string(), &format!("python{}", expected_version.major)]; + if let Some(minor) = expected_version.minor { + possible_python_paths.push( + &format!("python{}.{}", expected_version.major, minor) + ) } - if let Some(minor) = expected_version.minor { - let minor_interpreter_path = &format!("python{}.{}", expected_version.major, minor); - let (interpreter_version, lines) = try!(get_config_from_interpreter( - minor_interpreter_path)); - if expected_version == &interpreter_version { - return Ok((interpreter_version, minor_interpreter_path.to_owned(), lines)); + for possible_path in possible_python_paths { + let interpreter_path = canonicalize_executable(system_python); + if interpreter_path.is_some() { + let interpreter_config = try!(InterpreterConfig::from_cpython(interpreter_path)); + if expected_version == interpreter_config.version { + return Ok(interpreter_config); + } } } Err(format!("No python interpreter found")) } -/// Extract compilation vars from the specified interpreter. -fn get_config_from_interpreter(interpreter: &str) -> Result<(PythonVersion, Vec), String> { - let script = "import sys; import sysconfig; print(sys.version_info[0:2]); \ -print(sysconfig.get_config_var('LIBDIR')); \ -print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ -print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ -print(sys.exec_prefix);"; - let out = try!(run_python_script(interpreter, script)); - let lines: Vec = out.split(NEWLINE_SEQUENCE).map(|line| line.to_owned()).collect(); - let interpreter_version = try!(get_interpreter_version(&lines[0])); - check_pypy(interpreter); - Ok((interpreter_version, lines)) -} - /// Deduce configuration from the 'python' in the current PATH and print /// cargo vars to stdout. /// /// Note that if the python doesn't satisfy expected_version, this will error. -fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, String), String> { - let (interpreter_version, interpreter_path, lines) = try!( - find_interpreter_and_get_config(expected_version)); - - // TODO: on pypy get this from somewhere else - let libpath: &str = &lines[1]; - let enable_shared: &str = &lines[2]; - let ld_version: &str = &lines[3]; - let exec_prefix: &str = &lines[4]; - +fn emit_cargo_vars_from_configuration(interpreter_config: InterpreterConfig) -> Result<(String, String), String> { let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); if !is_extension_module || cfg!(target_os="windows") { - println!("{}", get_rustc_link_lib(&interpreter_version, &interpreter_path, - ld_version, enable_shared == "1").unwrap()); - if libpath != "None" { - println!("cargo:rustc-link-search=native={}", libpath); + println!("{:?}", get_rustc_link_lib(interpreter_config)); + + if interpreter_config.libpath != "None" { + println!("cargo:rustc-link-search=native={}", interpreter_config.libpath); } else if cfg!(target_os="windows") { - println!("cargo:rustc-link-search=native={}\\libs", exec_prefix); + println!("cargo:rustc-link-search=native={}\\libs", interpreter_config.exec_prefix); } } let mut flags = String::new(); - if let PythonVersion { major: 3, minor: some_minor } = interpreter_version { + if let &PythonVersion { major: 3, minor: some_minor } = interpreter_config.version { if env::var_os("CARGO_FEATURE_PEP_384").is_some() { println!("cargo:rustc-cfg=Py_LIMITED_API"); } @@ -410,7 +459,7 @@ fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, Stri println!("cargo:rustc-cfg=Py_2"); flags += format!("CFG_Py_2,").as_ref(); } - return Ok((interpreter_path, flags)); + return Ok((interpreter_config, flags)); } /// Determine the python version we're supposed to be building @@ -424,6 +473,7 @@ fn version_from_env() -> Result { // so if the user passes e.g. the python-3 feature and the python-3-5 // feature, python-3-5 takes priority. let mut vars = env::vars().collect::>(); + vars.sort_by(|a, b| b.cmp(a)); for (key, _) in vars { match re.captures(&key) { @@ -493,13 +543,15 @@ fn main() { Ok(v) => v, Err(_) => PythonVersion { major: 3, minor: None } }; - let (python_interpreter_path, flags) = configure_from_path(&version).unwrap(); + + let interpreter_configuration: InterpreterConfig = try!(find_interpreter(&version)); + let (python_interpreter_path, flags) = emit_cargo_vars_from_configuration(interpreter_configuration).unwrap(); let mut config_map = get_config_vars(&python_interpreter_path).unwrap(); config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); // WITH_THREAD is always on for 3.7 - let (interpreter_version, _, _) = find_interpreter_and_get_config(&version).unwrap(); + let (interpreter_version, _, _) = find_interpreter(&version).unwrap(); if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); } @@ -538,3 +590,27 @@ fn main() { println!("cargo:python_flags={}", if flags.len() > 0 { &flags[..flags.len() - 1] } else { "" }); } + + +#[cfg(test)] +mod test { + use std::env; + use {find_interpreter, PythonVersion, InterpreterConfig}; + + #[test] + fn test_correctly_detects_cpython() { + let python_version_major_only = PythonVersion { major: 3, minor: None }; + let expected_config = InterpreterConfig { + version: python_version_major_only, + path: ("bla"), + libpath: String::from("bla"), + enable_shared: false, + ld_version: String::from("bla"), + exec_prefix: String::from("bla"), + is_pypy: false, + }; + + assert_eq!(find_interpreter(&python_version_major_only).unwrap(), expected_config) + } +} + From 63a986e97ded2f8b34642ccf2d1401d861ccb722 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 22:10:47 +0200 Subject: [PATCH 007/138] compiler is happy! --- build.rs | 380 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 222 insertions(+), 158 deletions(-) diff --git a/build.rs b/build.rs index 25b3532c6a1..0964aea3ddb 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,7 @@ use std::env; use std::fmt; use regex::Regex; -use version_check::{supports_features, is_min_version, is_min_date}; +use version_check::{is_min_date, is_min_version, supports_features}; use std::path::{Path, PathBuf}; #[feature(match_default_bindings)] @@ -17,17 +17,20 @@ const MIN_DATE: &'static str = "2017-11-07"; const MIN_VERSION: &'static str = "1.23.0-nightly"; fn canonicalize_executable

(exe_name: P) -> Option - where P: AsRef, +where + P: AsRef, { env::var_os("PATH").and_then(|paths| { - env::split_paths(&paths).filter_map(|dir| { - let full_path = dir.join(&exe_name); - if full_path.is_file() { - Some(full_path) - } else { - None - } - }).next() + env::split_paths(&paths) + .filter_map(|dir| { + let full_path = dir.join(&exe_name); + if full_path.is_file() { + Some(full_path) + } else { + None + } + }) + .next() }) } @@ -50,16 +53,16 @@ impl fmt::Display for PythonVersion { try!(f.write_str(".")); match self.minor { Some(minor) => try!(minor.fmt(f)), - None => try!(f.write_str("*")) + None => try!(f.write_str("*")), }; Ok(()) } } #[derive(Debug)] -struct InterpreterConfig<'a> { - version: &'a PythonVersion, - path: &'a Path, +struct InterpreterConfig { + version: PythonVersion, + path: PathBuf, libpath: String, enable_shared: bool, ld_version: String, @@ -67,8 +70,8 @@ struct InterpreterConfig<'a> { is_pypy: bool, } -impl<'a> InterpreterConfig<'a> { - fn from_cpython(interpreter: &'a Path) -> Result { +impl InterpreterConfig { + fn from_cpython(interpreter: PathBuf) -> Result { let script = "import sys; import sysconfig;\ print(sys.version_info[0:2]); \ print(sysconfig.get_config_var('LIBDIR')); \ @@ -76,29 +79,29 @@ impl<'a> InterpreterConfig<'a> { print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ print(sys.exec_prefix);"; - let out = try!(run_python_script(interpreter.to_str(), script)); + let out = try!(run_python_script(&interpreter, script)); - let lines: Vec = - out.lines() - .map(|line: &str| line.to_owned()) - .collect(); + let lines: Vec<&str> = out.lines().collect(); let cpython_version = try!(parse_interpreter_version(&lines[0])); Ok(InterpreterConfig { - version: &cpython_version, + version: cpython_version, path: interpreter, - libpath: lines[1], + libpath: lines[1].to_string(), enable_shared: lines[2].parse().unwrap(), - ld_version: lines[3], - exec_prefix: lines[4], + ld_version: lines[3].to_string(), + exec_prefix: lines[4].to_string(), is_pypy: false, }) } - fn from_pypy(interpreter: &'a Path) -> Result { + fn from_pypy(interpreter: PathBuf) -> Result { Ok(InterpreterConfig { - version: &PythonVersion { major: 3, minor: Some(5) }, + version: PythonVersion { + major: 3, + minor: Some(5), + }, path: interpreter, libpath: "/Users/omerba/anaconda/lib".to_string(), enable_shared: true, @@ -109,7 +112,6 @@ impl<'a> InterpreterConfig<'a> { } } - const PY3_MIN_MINOR: u8 = 5; const CFG_KEY: &'static str = "py_sys_config"; @@ -150,55 +152,54 @@ static SYSCONFIG_VALUES: [&'static str; 1] = [ // below are translated into bools as {varname}_{val} // // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 - "Py_UNICODE_SIZE" // note - not present on python 3.3+, which is always wide + "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide ]; /// Examine python's compile flags to pass to cfg by launching /// the interpreter and printing variables of interest from /// sysconfig.get_config_vars. #[cfg(not(target_os = "windows"))] -fn get_config_vars(python_path: &String) -> Result, String> { +fn get_config_vars(python_path: &PathBuf) -> Result, String> { let mut script = "import sysconfig; \ -config = sysconfig.get_config_vars();".to_owned(); + config = sysconfig.get_config_vars();" + .to_owned(); for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!("print(config.get('{}', {}))", k, - if is_value(k) { "None" } else { "0" })); + script.push_str(&format!( + "print(config.get('{}', {}))", + k, + if is_value(k) { "None" } else { "0" } + )); script.push_str(";"); } - let mut cmd = Command::new(python_path); - cmd.arg("-c").arg(script); - - let out = try!(cmd.output().map_err(|e| { - format!("failed to run python interpreter `{:?}`: {}", cmd, e) - })); - - if !out.status.success() { - let stderr = String::from_utf8(out.stderr).unwrap(); - let mut msg = format!("python script failed with stderr:\n\n"); - msg.push_str(&stderr); - return Err(msg); - } + let out = try!(run_python_script(python_path, &script)); - let stdout = String::from_utf8(out.stdout).unwrap(); - let split_stdout: Vec<&str> = stdout.trim_right().split(NEWLINE_SEQUENCE).collect(); + let split_stdout: Vec<&str> = out.trim_right().split(NEWLINE_SEQUENCE).collect(); if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { - return Err( - format!("python stdout len didn't return expected number of lines: -{}", split_stdout.len()).to_string()); + return Err(format!( + "python stdout len didn't return expected number of lines: +{}", + split_stdout.len() + ).to_string()); } let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); // let var_map: HashMap = HashMap::new(); - let mut all_vars = all_vars.zip(split_stdout.iter()) - .fold(HashMap::new(), |mut memo: HashMap, (&k, &v)| { + let mut all_vars = all_vars.zip(split_stdout.iter()).fold( + HashMap::new(), + |mut memo: HashMap, (&k, &v)| { if !(v.to_owned() == "None" && is_value(k)) { memo.insert(k.to_owned(), v.to_owned()); } memo - }); + }, + ); - let debug = if let Some(val) = all_vars.get("Py_DEBUG") { val == "1" } else { false }; + let debug = if let Some(val) = all_vars.get("Py_DEBUG") { + val == "1" + } else { + false + }; if debug { all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); @@ -255,13 +256,14 @@ fn cfg_line_for_var(key: &str, val: &str) -> Option { } /// Run a python script using the specified interpreter binary. -fn run_python_script(interpreter: &str, script: &str) -> Result { - let mut cmd = Command::new(interpreter); +fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result { + let mut cmd = Command::new(interpreter_path); cmd.arg("-c").arg(script); - let out = try!(cmd.output().map_err(|e| { - format!("failed to run python interpreter `{:?}`: {}", cmd, e) - })); + let out = try!( + cmd.output() + .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e)) + ); if !out.status.success() { let stderr = String::from_utf8(out.stderr).unwrap(); @@ -276,43 +278,49 @@ fn run_python_script(interpreter: &str, script: &str) -> Result #[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "windows"))] -fn get_rustc_link_lib(_: &PythonVersion, interpreter_path: &str, ld_version: &str, enable_shared: bool) - -> Result -{ - if enable_shared { - Ok(format!("cargo:rustc-link-lib=python{}", ld_version)) +fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { + if interpreter_config.enable_shared { + Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )) } else { - Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) + Ok(format!( + "cargo:rustc-link-lib=static=python{}", + interpreter_config.ld_version + )) } } #[cfg(target_os = "windows")] -fn get_rustc_link_lib(interpreter_config: InterpreterConfig) -> Result -{ +fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { if interpreter_config.is_pypy { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", - 3 => "pypy3-c" + 3 => "pypy3-c", }; // All modern PyPy versions with cpyext are compiled as shared libraries. return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); } // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned() - })) + Ok(format!( + "cargo:rustc-link-lib=pythonXY:python{}{}", + version.major, + match version.minor { + Some(minor) => minor.to_string(), + None => "".to_owned(), + } + )) } #[cfg(target_os = "macos")] -fn get_rustc_link_lib(interpreter_config: InterpreterConfig) -> Result -{ +fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { if interpreter_config.is_pypy { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", - 3 => "pypy3-c" + 3 => "pypy3-c", + _ => unreachable!(), }; // All modern PyPy versions with cpyext are compiled as shared libraries. return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); @@ -320,39 +328,46 @@ fn get_rustc_link_lib(interpreter_config: InterpreterConfig) -> Result Ok(format!("cargo:rustc-link-lib=static=python{}", interpreter_config.ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", interpreter_config.ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", interpreter_config.ld_version)), - other => Err(format!("unknown linkmodel {}", other)) + match get_macos_linkmodel(&interpreter_config.path) + .unwrap() + .as_ref() + { + "static" => Ok(format!( + "cargo:rustc-link-lib=static=python{}", + interpreter_config.ld_version + )), + "shared" => Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )), + "framework" => Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )), + other => Err(format!("unknown linkmodel {}", other)), } } - #[cfg(target_os = "macos")] -fn get_macos_linkmodel(interpreter_path: &str) -> Result -{ +fn get_macos_linkmodel(interpreter_path: &PathBuf) -> Result { let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; let out = run_python_script(interpreter_path, script).unwrap(); Ok(out.trim_right().to_owned()) } - /// Parse string as interpreter version. -fn parse_interpreter_version(line: &str) -> Result -{ +fn parse_interpreter_version(line: &str) -> Result { let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); match version_re.captures(&line) { Some(cap) => Ok(PythonVersion { major: cap.get(1).unwrap().as_str().parse().unwrap(), minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), }), - None => Err( - format!("Unexpected response to version query {}", line)) + None => Err(format!("Unexpected response to version query {}", line)), } } -fn check_pypy(interpreter_path: &str) -> bool { +fn check_pypy(interpreter_path: &PathBuf) -> bool { let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; let is_pypy: bool = run_python_script(interpreter_path, script) .unwrap() @@ -360,60 +375,64 @@ fn check_pypy(interpreter_path: &str) -> bool { .trim_right() .parse() .unwrap(); - - if is_pypy { - println!("cargo:rustc-cfg=PyPy"); - } return is_pypy; } - /// Locate a suitable python interpreter and extract config from it. /// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided /// path a Python executable, and raises an error if the version doesn't match. /// Else tries to execute the interpreter as "python", "python{major version}", /// "python{major version}.{minor version}" in order until one /// is of the version we are expecting. -fn find_interpreter(expected_version: &PythonVersion) - -> Result -{ +fn find_interpreter(expected_version: &PythonVersion) -> Result { // To use PyPy, a valid pypy executable must be passed to PYTHON_SYS_EXECUTABLE if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { - let interpreter_path_or_executable = interpreter_from_env.to_str() + let interpreter_path_or_executable = interpreter_from_env + .to_str() .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); - let interpreter_path = canonicalize_executable(interpreter_path_or_executable); + let interpreter_path = + canonicalize_executable(interpreter_path_or_executable).expect(&format!( + "Could not find interpreter passed in PYTHON_SYS_EXECUTABLE={}\n", + interpreter_path_or_executable + )); - if interpreter_path.is_some() { - let interpreter_config: InterpreterConfig = try!(InterpreterConfig::from_pypy(&Path::new(interpreter_path.expect()))); + let interpreter_config: InterpreterConfig; - if expected_version == interpreter_config.version { - return Ok(interpreter_config); - } else { - return Err(format!("Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ - \tmin version {} != found {}", - interpreter_path_or_executable, expected_version, interpreter_config.version)); - } + if check_pypy(&interpreter_path) { + interpreter_config = try!(InterpreterConfig::from_pypy(interpreter_path)); } else { - Err(format!("Could not find interpreter passed in PYTHON_SYS_EXECUTABLE={}\n", interpreter_path_or_executable)); + interpreter_config = try!(InterpreterConfig::from_cpython(interpreter_path)); + } + + if expected_version == &interpreter_config.version { + return Ok(interpreter_config); + } else { + return Err(format!( + "Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ + \tmin version {} != found {}", + interpreter_path_or_executable, expected_version, interpreter_config.version + )); } } // check default python let system_python = "python"; - let mut possible_python_paths = vec!["python".to_string(), &format!("python{}", expected_version.major)]; + let mut possible_python_paths = vec![ + "python".to_string(), + format!("python{}", expected_version.major), + ]; if let Some(minor) = expected_version.minor { - possible_python_paths.push( - &format!("python{}.{}", expected_version.major, minor) - ) + possible_python_paths.push(format!("python{}.{}", expected_version.major, minor)) } for possible_path in possible_python_paths { - let interpreter_path = canonicalize_executable(system_python); + let interpreter_path = canonicalize_executable(&possible_path); if interpreter_path.is_some() { - let interpreter_config = try!(InterpreterConfig::from_cpython(interpreter_path)); - if expected_version == interpreter_config.version { + let interpreter_config = + try!(InterpreterConfig::from_cpython(interpreter_path.unwrap())); + if expected_version == &interpreter_config.version { return Ok(interpreter_config); } } @@ -426,28 +445,47 @@ fn find_interpreter(expected_version: &PythonVersion) /// cargo vars to stdout. /// /// Note that if the python doesn't satisfy expected_version, this will error. -fn emit_cargo_vars_from_configuration(interpreter_config: InterpreterConfig) -> Result<(String, String), String> { +fn emit_cargo_vars_from_configuration( + interpreter_config: &InterpreterConfig, +) -> Result { let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - if !is_extension_module || cfg!(target_os="windows") { - println!("{:?}", get_rustc_link_lib(interpreter_config)); + if interpreter_config.is_pypy { + println!("cargo:rustc-cfg=PyPy"); + } + + if !is_extension_module || cfg!(target_os = "windows") { + println!("{:?}", get_rustc_link_lib(&interpreter_config)); if interpreter_config.libpath != "None" { - println!("cargo:rustc-link-search=native={}", interpreter_config.libpath); - } else if cfg!(target_os="windows") { - println!("cargo:rustc-link-search=native={}\\libs", interpreter_config.exec_prefix); + println!( + "cargo:rustc-link-search=native={}", + interpreter_config.libpath + ); + } else if cfg!(target_os = "windows") { + println!( + "cargo:rustc-link-search=native={}\\libs", + interpreter_config.exec_prefix + ); } } let mut flags = String::new(); - if let &PythonVersion { major: 3, minor: some_minor } = interpreter_config.version { + if let PythonVersion { + major: 3, + minor: some_minor, + } = interpreter_config.version + { if env::var_os("CARGO_FEATURE_PEP_384").is_some() { println!("cargo:rustc-cfg=Py_LIMITED_API"); } if let Some(minor) = some_minor { if minor < PY3_MIN_MINOR { - return Err(format!("Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor)); + return Err(format!( + "Python 3 required version is 3.{}, current version is 3.{}", + PY3_MIN_MINOR, minor + )); } for i in 5..(minor + 1) { println!("cargo:rustc-cfg=Py_3_{}", i); @@ -459,7 +497,7 @@ fn emit_cargo_vars_from_configuration(interpreter_config: InterpreterConfig) -> println!("cargo:rustc-cfg=Py_2"); flags += format!("CFG_Py_2,").as_ref(); } - return Ok((interpreter_config, flags)); + return Ok(flags); } /// Determine the python version we're supposed to be building @@ -477,19 +515,24 @@ fn version_from_env() -> Result { vars.sort_by(|a, b| b.cmp(a)); for (key, _) in vars { match re.captures(&key) { - Some(cap) => return Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: match cap.get(3) { - Some(s) => Some(s.as_str().parse().unwrap()), - None => None - }, - }), - None => () + Some(cap) => { + return Ok(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: match cap.get(3) { + Some(s) => Some(s.as_str().parse().unwrap()), + None => None, + }, + }); + } + None => (), } } - Err("Python version feature was not found. At least one python version \ - feature must be enabled.".to_owned()) + Err( + "Python version feature was not found. At least one python version \ + feature must be enabled." + .to_owned(), + ) } fn check_rustc_version() { @@ -498,11 +541,10 @@ fn check_rustc_version() { let ok_date = is_min_date(MIN_DATE); let print_version_err = |version: &str, date: &str| { - eprintln!("Installed version is: {} ({}). Minimum required: {} ({}).", - version, - date, - MIN_VERSION, - MIN_DATE); + eprintln!( + "Installed version is: {} ({}). Minimum required: {} ({}).", + version, date, MIN_VERSION, MIN_DATE + ); }; match (ok_channel, ok_version, ok_date) { @@ -521,8 +563,14 @@ fn check_rustc_version() { } } _ => { - println!("cargo:warning={}", "pyo3 was unable to check rustc compatibility."); - println!("cargo:warning={}", "Build may fail due to incompatible rustc version."); + println!( + "cargo:warning={}", + "pyo3 was unable to check rustc compatibility." + ); + println!( + "cargo:warning={}", + "Build may fail due to incompatible rustc version." + ); } } } @@ -541,25 +589,31 @@ fn main() { // match the pkg-config package name, which is going to have a . in it). let version = match version_from_env() { Ok(v) => v, - Err(_) => PythonVersion { major: 3, minor: None } + Err(_) => PythonVersion { + major: 3, + minor: None, + }, }; - let interpreter_configuration: InterpreterConfig = try!(find_interpreter(&version)); - let (python_interpreter_path, flags) = emit_cargo_vars_from_configuration(interpreter_configuration).unwrap(); - let mut config_map = get_config_vars(&python_interpreter_path).unwrap(); + let interpreter_configuration: InterpreterConfig = find_interpreter(&version).unwrap(); + + let flags = emit_cargo_vars_from_configuration(&interpreter_configuration).unwrap(); + + let mut config_map = get_config_vars(&interpreter_configuration.path).unwrap(); config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); // WITH_THREAD is always on for 3.7 - let (interpreter_version, _, _) = find_interpreter(&version).unwrap(); - if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { + if interpreter_configuration.version.major == 3 + && interpreter_configuration.version.minor.unwrap_or(0) >= 7 + { config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); } for (key, val) in &config_map { match cfg_line_for_var(key, val) { Some(line) => println!("{}", line), - None => () + None => (), } } @@ -587,19 +641,27 @@ fn main() { } }) + flags.as_str(); - println!("cargo:python_flags={}", - if flags.len() > 0 { &flags[..flags.len() - 1] } else { "" }); + println!( + "cargo:python_flags={}", + if flags.len() > 0 { + &flags[..flags.len() - 1] + } else { + "" + } + ); } - #[cfg(test)] mod test { use std::env; - use {find_interpreter, PythonVersion, InterpreterConfig}; + use {find_interpreter, InterpreterConfig, PythonVersion}; #[test] fn test_correctly_detects_cpython() { - let python_version_major_only = PythonVersion { major: 3, minor: None }; + let python_version_major_only = PythonVersion { + major: 3, + minor: None, + }; let expected_config = InterpreterConfig { version: python_version_major_only, path: ("bla"), @@ -610,7 +672,9 @@ mod test { is_pypy: false, }; - assert_eq!(find_interpreter(&python_version_major_only).unwrap(), expected_config) + assert_eq!( + find_interpreter(&python_version_major_only).unwrap(), + expected_config + ) } } - From b3540b657b53709553ac9b4b31de3bcfb0bd708f Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 18 Mar 2018 22:43:44 +0200 Subject: [PATCH 008/138] few todos remain --- build.rs | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/build.rs b/build.rs index 0964aea3ddb..f7729af82bd 100644 --- a/build.rs +++ b/build.rs @@ -10,8 +10,6 @@ use regex::Regex; use version_check::{is_min_date, is_min_version, supports_features}; use std::path::{Path, PathBuf}; -#[feature(match_default_bindings)] - // Specifies the minimum nightly version needed to compile pyo3. const MIN_DATE: &'static str = "2017-11-07"; const MIN_VERSION: &'static str = "1.23.0-nightly"; @@ -89,13 +87,14 @@ impl InterpreterConfig { version: cpython_version, path: interpreter, libpath: lines[1].to_string(), - enable_shared: lines[2].parse().unwrap(), + enable_shared: lines[2] == "1", ld_version: lines[3].to_string(), exec_prefix: lines[4].to_string(), is_pypy: false, }) } + // TODO: implement me nicely! fn from_pypy(interpreter: PathBuf) -> Result { Ok(InterpreterConfig { version: PythonVersion { @@ -160,9 +159,7 @@ static SYSCONFIG_VALUES: [&'static str; 1] = [ /// sysconfig.get_config_vars. #[cfg(not(target_os = "windows"))] fn get_config_vars(python_path: &PathBuf) -> Result, String> { - let mut script = "import sysconfig; \ - config = sysconfig.get_config_vars();" - .to_owned(); + let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { script.push_str(&format!( @@ -178,8 +175,7 @@ fn get_config_vars(python_path: &PathBuf) -> Result, Str let split_stdout: Vec<&str> = out.trim_right().split(NEWLINE_SEQUENCE).collect(); if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { return Err(format!( - "python stdout len didn't return expected number of lines: -{}", + "python stdout len didn't return expected number of lines: {}", split_stdout.len() ).to_string()); } @@ -210,7 +206,7 @@ fn get_config_vars(python_path: &PathBuf) -> Result, Str } #[cfg(target_os = "windows")] -fn get_config_vars(_: &String) -> Result, String> { +fn get_config_vars(_: &PathBuf) -> Result, String> { // sysconfig is missing all the flags on windows, so we can't actually // query the interpreter directly for its build flags. // @@ -279,6 +275,16 @@ fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result Result { + if interpreter_config.is_pypy { + let link_library_name = match interpreter_config.version.major { + 2 => "pypy-c", + 3 => "pypy3-c", + _ => unreachable!(), + }; + // All modern PyPy versions with cpyext are compiled as shared libraries. + return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + } + if interpreter_config.enable_shared { Ok(format!( "cargo:rustc-link-lib=python{}", @@ -298,6 +304,7 @@ fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result "pypy-c", 3 => "pypy3-c", + _ => unreachable!(), }; // All modern PyPy versions with cpyext are compiled as shared libraries. return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); @@ -416,9 +423,6 @@ fn find_interpreter(expected_version: &PythonVersion) -> Result Date: Thu, 29 Mar 2018 17:28:13 +0300 Subject: [PATCH 009/138] extracted build logic to seperate module --- Cargo.toml | 6 +- build.rs | 615 +------------------------------- pyo3build/Cargo.toml | 14 + pyo3build/src/lib.rs | 2 + pyo3build/src/py_interpreter.rs | 569 +++++++++++++++++++++++++++++ pyo3build/src/rustc_version.rs | 46 +++ 6 files changed, 639 insertions(+), 613 deletions(-) create mode 100644 pyo3build/Cargo.toml create mode 100644 pyo3build/src/lib.rs create mode 100644 pyo3build/src/py_interpreter.rs create mode 100644 pyo3build/src/rustc_version.rs diff --git a/Cargo.toml b/Cargo.toml index e021d720b4b..ab8b6b90d3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,9 @@ license = "Apache-2.0" exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] build = "build.rs" +[lib] +doctest = false + [badges] travis-ci = { repository = "PyO3/pyo3", branch = "master" } appveyor = { repository = "PyO3/pyo3" } @@ -28,8 +31,7 @@ regex = "0.2" version_check = "0.1" [build-dependencies] -regex = "0.2" -version_check = "0.1" +pyo3-build-utils = {version = "*", path="pyo3build"} [features] default = [] diff --git a/build.rs b/build.rs index f7729af82bd..3eee245dd58 100644 --- a/build.rs +++ b/build.rs @@ -1,583 +1,7 @@ -extern crate regex; -extern crate version_check; +extern crate pyo3_build_utils; -use std::process::Command; -use std::collections::HashMap; -use std::env; -use std::fmt; - -use regex::Regex; -use version_check::{is_min_date, is_min_version, supports_features}; -use std::path::{Path, PathBuf}; - -// Specifies the minimum nightly version needed to compile pyo3. -const MIN_DATE: &'static str = "2017-11-07"; -const MIN_VERSION: &'static str = "1.23.0-nightly"; - -fn canonicalize_executable

(exe_name: P) -> Option -where - P: AsRef, -{ - env::var_os("PATH").and_then(|paths| { - env::split_paths(&paths) - .filter_map(|dir| { - let full_path = dir.join(&exe_name); - if full_path.is_file() { - Some(full_path) - } else { - None - } - }) - .next() - }) -} - -#[derive(Debug)] -struct PythonVersion { - major: u8, - // minor == None means any minor version will do - minor: Option, -} - -impl PartialEq for PythonVersion { - fn eq(&self, o: &PythonVersion) -> bool { - self.major == o.major && (self.minor.is_none() || self.minor == o.minor) - } -} - -impl fmt::Display for PythonVersion { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(self.major.fmt(f)); - try!(f.write_str(".")); - match self.minor { - Some(minor) => try!(minor.fmt(f)), - None => try!(f.write_str("*")), - }; - Ok(()) - } -} - -#[derive(Debug)] -struct InterpreterConfig { - version: PythonVersion, - path: PathBuf, - libpath: String, - enable_shared: bool, - ld_version: String, - exec_prefix: String, - is_pypy: bool, -} - -impl InterpreterConfig { - fn from_cpython(interpreter: PathBuf) -> Result { - let script = "import sys; import sysconfig;\ - print(sys.version_info[0:2]); \ - print(sysconfig.get_config_var('LIBDIR')); \ - print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ - print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ - print(sys.exec_prefix);"; - - let out = try!(run_python_script(&interpreter, script)); - - let lines: Vec<&str> = out.lines().collect(); - - let cpython_version = try!(parse_interpreter_version(&lines[0])); - - Ok(InterpreterConfig { - version: cpython_version, - path: interpreter, - libpath: lines[1].to_string(), - enable_shared: lines[2] == "1", - ld_version: lines[3].to_string(), - exec_prefix: lines[4].to_string(), - is_pypy: false, - }) - } - - // TODO: implement me nicely! - fn from_pypy(interpreter: PathBuf) -> Result { - Ok(InterpreterConfig { - version: PythonVersion { - major: 3, - minor: Some(5), - }, - path: interpreter, - libpath: "/Users/omerba/anaconda/lib".to_string(), - enable_shared: true, - ld_version: "3.5".to_string(), - exec_prefix: "/Users/omerba/anaconda".to_string(), - is_pypy: true, - }) - } -} - -const PY3_MIN_MINOR: u8 = 5; - -const CFG_KEY: &'static str = "py_sys_config"; - -// windows' python writes out lines with the windows crlf sequence; -// posix platforms and mac os should write out lines with just lf. -#[cfg(target_os = "windows")] -static NEWLINE_SEQUENCE: &'static str = "\r\n"; - -#[cfg(not(target_os = "windows"))] -static NEWLINE_SEQUENCE: &'static str = "\n"; - -// A list of python interpreter compile-time preprocessor defines that -// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; -// this allows using them conditional cfg attributes in the .rs files, so -// -// #[cfg(py_sys_config="{varname}"] -// -// is the equivalent of #ifdef {varname} name in C. -// -// see Misc/SpecialBuilds.txt in the python source for what these mean. -// -// (hrm, this is sort of re-implementing what distutils does, except -// by passing command line args instead of referring to a python.h) -#[cfg(not(target_os = "windows"))] -static SYSCONFIG_FLAGS: [&'static str; 7] = [ - "Py_USING_UNICODE", - "Py_UNICODE_WIDE", - "WITH_THREAD", - "Py_DEBUG", - "Py_REF_DEBUG", - "Py_TRACE_REFS", - "COUNT_ALLOCS", -]; - -static SYSCONFIG_VALUES: [&'static str; 1] = [ - // cfg doesn't support flags with values, just bools - so flags - // below are translated into bools as {varname}_{val} - // - // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 - "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide -]; - -/// Examine python's compile flags to pass to cfg by launching -/// the interpreter and printing variables of interest from -/// sysconfig.get_config_vars. -#[cfg(not(target_os = "windows"))] -fn get_config_vars(python_path: &PathBuf) -> Result, String> { - let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); - - for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!( - "print(config.get('{}', {}))", - k, - if is_value(k) { "None" } else { "0" } - )); - script.push_str(";"); - } - - let out = try!(run_python_script(python_path, &script)); - - let split_stdout: Vec<&str> = out.trim_right().split(NEWLINE_SEQUENCE).collect(); - if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { - return Err(format!( - "python stdout len didn't return expected number of lines: {}", - split_stdout.len() - ).to_string()); - } - let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); - // let var_map: HashMap = HashMap::new(); - let mut all_vars = all_vars.zip(split_stdout.iter()).fold( - HashMap::new(), - |mut memo: HashMap, (&k, &v)| { - if !(v.to_owned() == "None" && is_value(k)) { - memo.insert(k.to_owned(), v.to_owned()); - } - memo - }, - ); - - let debug = if let Some(val) = all_vars.get("Py_DEBUG") { - val == "1" - } else { - false - }; - if debug { - all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); - } - - Ok(all_vars) -} - -#[cfg(target_os = "windows")] -fn get_config_vars(_: &PathBuf) -> Result, String> { - // sysconfig is missing all the flags on windows, so we can't actually - // query the interpreter directly for its build flags. - // - // For the time being, this is the flags as defined in the python source's - // PC\pyconfig.h. This won't work correctly if someone has built their - // python with a modified pyconfig.h - sorry if that is you, you will have - // to comment/uncomment the lines below. - let mut map: HashMap = HashMap::new(); - map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); - map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); - - // This is defined #ifdef _DEBUG. The visual studio build seems to produce - // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the - // Debug configuration, which this script doesn't currently support anyway. - // map.insert("Py_DEBUG", "1"); - - // Uncomment these manually if your python was built with these and you want - // the cfg flags to be set in rust. - // - // map.insert("Py_REF_DEBUG", "1"); - // map.insert("Py_TRACE_REFS", "1"); - // map.insert("COUNT_ALLOCS", 1"); - Ok(map) -} - -fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() -} - -fn cfg_line_for_var(key: &str, val: &str) -> Option { - if is_value(key) { - // is a value; suffix the key name with the value - Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) - } else if val != "0" { - // is a flag that isn't zero - Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) - } else { - // is a flag that is zero - None - } -} - -/// Run a python script using the specified interpreter binary. -fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result { - let mut cmd = Command::new(interpreter_path); - cmd.arg("-c").arg(script); - - let out = try!( - cmd.output() - .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e)) - ); - - if !out.status.success() { - let stderr = String::from_utf8(out.stderr).unwrap(); - let mut msg = format!("python script failed with stderr:\n\n"); - msg.push_str(&stderr); - return Err(msg); - } - - let out = String::from_utf8(out.stdout).unwrap(); - return Ok(out); -} - -#[cfg(not(target_os = "macos"))] -#[cfg(not(target_os = "windows"))] -fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { - if interpreter_config.is_pypy { - let link_library_name = match interpreter_config.version.major { - 2 => "pypy-c", - 3 => "pypy3-c", - _ => unreachable!(), - }; - // All modern PyPy versions with cpyext are compiled as shared libraries. - return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); - } - - if interpreter_config.enable_shared { - Ok(format!( - "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version - )) - } else { - Ok(format!( - "cargo:rustc-link-lib=static=python{}", - interpreter_config.ld_version - )) - } -} - -#[cfg(target_os = "windows")] -fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { - if interpreter_config.is_pypy { - let link_library_name = match interpreter_config.version.major { - 2 => "pypy-c", - 3 => "pypy3-c", - _ => unreachable!(), - }; - // All modern PyPy versions with cpyext are compiled as shared libraries. - return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); - } - - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!( - "cargo:rustc-link-lib=pythonXY:python{}{}", - version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned(), - } - )) -} - -#[cfg(target_os = "macos")] -fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { - if interpreter_config.is_pypy { - let link_library_name = match interpreter_config.version.major { - 2 => "pypy-c", - 3 => "pypy3-c", - _ => unreachable!(), - }; - // All modern PyPy versions with cpyext are compiled as shared libraries. - return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); - } - - // os x can be linked to a framework or static or dynamic, and - // Py_ENABLE_SHARED is wrong; framework means shared library - match get_macos_linkmodel(&interpreter_config.path) - .unwrap() - .as_ref() - { - "static" => Ok(format!( - "cargo:rustc-link-lib=static=python{}", - interpreter_config.ld_version - )), - "shared" => Ok(format!( - "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version - )), - "framework" => Ok(format!( - "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version - )), - other => Err(format!("unknown linkmodel {}", other)), - } -} - -#[cfg(target_os = "macos")] -fn get_macos_linkmodel(interpreter_path: &PathBuf) -> Result { - let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; - let out = run_python_script(interpreter_path, script).unwrap(); - Ok(out.trim_right().to_owned()) -} - -/// Parse string as interpreter version. -fn parse_interpreter_version(line: &str) -> Result { - let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); - match version_re.captures(&line) { - Some(cap) => Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), - }), - None => Err(format!("Unexpected response to version query {}", line)), - } -} - -fn check_pypy(interpreter_path: &PathBuf) -> bool { - let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; - let is_pypy: bool = run_python_script(interpreter_path, script) - .unwrap() - .to_lowercase() - .trim_right() - .parse() - .unwrap(); - return is_pypy; -} - -/// Locate a suitable python interpreter and extract config from it. -/// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided -/// path a Python executable, and raises an error if the version doesn't match. -/// Else tries to execute the interpreter as "python", "python{major version}", -/// "python{major version}.{minor version}" in order until one -/// is of the version we are expecting. -fn find_interpreter(expected_version: &PythonVersion) -> Result { - // To use PyPy, a valid pypy executable must be passed to PYTHON_SYS_EXECUTABLE - if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { - let interpreter_path_or_executable = interpreter_from_env - .to_str() - .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); - - let interpreter_path = - canonicalize_executable(interpreter_path_or_executable).expect(&format!( - "Could not find interpreter passed in PYTHON_SYS_EXECUTABLE={}\n", - interpreter_path_or_executable - )); - - let interpreter_config: InterpreterConfig; - - if check_pypy(&interpreter_path) { - interpreter_config = try!(InterpreterConfig::from_pypy(interpreter_path)); - } else { - interpreter_config = try!(InterpreterConfig::from_cpython(interpreter_path)); - } - - if expected_version == &interpreter_config.version { - return Ok(interpreter_config); - } else { - return Err(format!( - "Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ - \tmin version {} != found {}", - interpreter_path_or_executable, expected_version, interpreter_config.version - )); - } - } - - let mut possible_python_paths = vec![ - "python".to_string(), - format!("python{}", expected_version.major), - ]; - if let Some(minor) = expected_version.minor { - possible_python_paths.push(format!("python{}.{}", expected_version.major, minor)) - } - - for possible_path in possible_python_paths { - let interpreter_path = canonicalize_executable(&possible_path); - if interpreter_path.is_some() { - let interpreter_config = - try!(InterpreterConfig::from_cpython(interpreter_path.unwrap())); - if expected_version == &interpreter_config.version { - return Ok(interpreter_config); - } - } - } - - Err(format!("No python interpreter found")) -} - -/// Deduce configuration from the 'python' in the current PATH and print -/// cargo vars to stdout. -/// -/// Note that if the python doesn't satisfy expected_version, this will error. -fn emit_cargo_vars_from_configuration( - interpreter_config: &InterpreterConfig, -) -> Result { - let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - - if interpreter_config.is_pypy { - println!("cargo:rustc-cfg=PyPy"); - } - - if !is_extension_module || cfg!(target_os = "windows") { - println!("{}", get_rustc_link_lib(&interpreter_config).unwrap()); - - if interpreter_config.libpath != "None" { - println!( - "cargo:rustc-link-search=native={}", - interpreter_config.libpath - ); - } else if cfg!(target_os = "windows") { - println!( - "cargo:rustc-link-search=native={}\\libs", - interpreter_config.exec_prefix - ); - } - } - - let mut flags = String::new(); - - if let PythonVersion { - major: 3, - minor: some_minor, - } = interpreter_config.version - { - if env::var_os("CARGO_FEATURE_PEP_384").is_some() { - println!("cargo:rustc-cfg=Py_LIMITED_API"); - } - if let Some(minor) = some_minor { - if minor < PY3_MIN_MINOR { - return Err(format!( - "Python 3 required version is 3.{}, current version is 3.{}", - PY3_MIN_MINOR, minor - )); - } - for i in 5..(minor + 1) { - 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(); - } - return Ok(flags); -} - -/// Determine the python version we're supposed to be building -/// from the features passed via the environment. -/// -/// The environment variable can choose to omit a minor -/// version if the user doesn't care. -fn version_from_env() -> Result { - let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); - // sort env::vars so we get more explicit version specifiers first - // so if the user passes e.g. the python-3 feature and the python-3-5 - // feature, python-3-5 takes priority. - let mut vars = env::vars().collect::>(); - - vars.sort_by(|a, b| b.cmp(a)); - for (key, _) in vars { - match re.captures(&key) { - Some(cap) => { - return Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: match cap.get(3) { - Some(s) => Some(s.as_str().parse().unwrap()), - None => None, - }, - }); - } - None => (), - } - } - - Err( - "Python version feature was not found. At least one python version \ - feature must be enabled." - .to_owned(), - ) -} - -fn check_rustc_version() { - let ok_channel = supports_features(); - let ok_version = is_min_version(MIN_VERSION); - let ok_date = is_min_date(MIN_DATE); - - let print_version_err = |version: &str, date: &str| { - eprintln!( - "Installed version is: {} ({}). Minimum required: {} ({}).", - version, date, MIN_VERSION, MIN_DATE - ); - }; - - match (ok_channel, ok_version, ok_date) { - (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { - if !ok_channel { - eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - - if !ok_version || !ok_date { - eprintln!("Error: pyo3 requires a more recent version of rustc."); - eprintln!("Use `rustup update` or your preferred method to update Rust"); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - } - _ => { - println!( - "cargo:warning={}", - "pyo3 was unable to check rustc compatibility." - ); - println!( - "cargo:warning={}", - "Build may fail due to incompatible rustc version." - ); - } - } -} +use pyo3_build_utils::rustc_version::check_rustc_version; +use pyo3_build_utils::py_interpreter::{find_interpreter, emit_cargo_vars_from_configuration, get_config_vars}; fn main() { check_rustc_version(); @@ -653,35 +77,4 @@ fn main() { "" } ); -} - -// TODO: move this somewhere these test could be ran -#[cfg(test)] -mod test { - use std::env; - use {find_interpreter, InterpreterConfig, PythonVersion}; - - #[test] - fn test_correctly_detects_cpython() { - let python_version_major_only = PythonVersion { - major: 3, - minor: None, - }; - let expected_config = InterpreterConfig { - version: python_version_major_only, - path: ("bla"), - libpath: String::from("bla"), - enable_shared: false, - ld_version: String::from("bla"), - exec_prefix: String::from("bla"), - is_pypy: false, - }; - - let interpreter = find_interpreter(&python_version_major_only).unwrap(); - - println!("{}", interpreter); - - assert_eq!(interpreter.version, expected_config.version); - assert_eq!(interpreter.path, expected_config.path); - } -} +} \ No newline at end of file diff --git a/pyo3build/Cargo.toml b/pyo3build/Cargo.toml new file mode 100644 index 00000000000..3aa0891a4d1 --- /dev/null +++ b/pyo3build/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "pyo3-build-utils" +version = "0.0.1" +description = "Build utilities from PyO3" +authors = ["PyO3 Project and Contributors (exe_name: P) -> Option + where + P: AsRef, +{ + env::var_os("PATH").and_then(|paths| { + env::split_paths(&paths) + .filter_map(|dir| { + let full_path = dir.join(&exe_name); + if full_path.is_file() { + Some(full_path) + } else { + None + } + }) + .next() + }) +} + +#[derive(Debug, Copy, Clone)] +pub struct PythonVersion { + major: u8, + // minor == None means any minor version will do + minor: Option, +} + +impl PartialEq for PythonVersion { + fn eq(&self, o: &PythonVersion) -> bool { + self.major == o.major && (self.minor.is_none() || self.minor == o.minor) + } +} + +impl fmt::Display for PythonVersion { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + try!(self.major.fmt(f)); + try!(f.write_str(".")); + match self.minor { + Some(minor) => try!(minor.fmt(f)), + None => try!(f.write_str("*")), + }; + Ok(()) + } +} + +#[derive(Debug)] +pub struct InterpreterConfig { + version: PythonVersion, + path: PathBuf, + libpath: String, + enable_shared: bool, + ld_version: String, + exec_prefix: String, + is_pypy: bool, +} + +impl InterpreterConfig { + fn from_cpython(interpreter: PathBuf) -> Result { + let script = "import sys; import sysconfig;\ + print(sys.version_info[0:2]); \ + print(sysconfig.get_config_var('LIBDIR')); \ + print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ + print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ + print(sys.exec_prefix);"; + + let out = try!(run_python_script(&interpreter, script)); + + let lines: Vec<&str> = out.lines().collect(); + + let cpython_version = try!(parse_interpreter_version(&lines[0])); + + Ok(InterpreterConfig { + version: cpython_version, + path: interpreter, + libpath: lines[1].to_string(), + enable_shared: lines[2] == "1", + ld_version: lines[3].to_string(), + exec_prefix: lines[4].to_string(), + is_pypy: false, + }) + } + + // TODO: implement me nicely! + fn from_pypy(interpreter: PathBuf) -> Result { + Ok(InterpreterConfig { + version: PythonVersion { + major: 3, + minor: Some(5), + }, + path: interpreter, + libpath: "/Users/omerba/anaconda/lib".to_string(), + enable_shared: true, + ld_version: "3.5".to_string(), + exec_prefix: "/Users/omerba/anaconda".to_string(), + is_pypy: true, + }) + } +} + +const PY3_MIN_MINOR: u8 = 5; + +const CFG_KEY: &'static str = "py_sys_config"; + +// windows' python writes out lines with the windows crlf sequence; +// posix platforms and mac os should write out lines with just lf. +#[cfg(target_os = "windows")] +static NEWLINE_SEQUENCE: &'static str = "\r\n"; + +#[cfg(not(target_os = "windows"))] +static NEWLINE_SEQUENCE: &'static str = "\n"; + +// A list of python interpreter compile-time preprocessor defines that +// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; +// this allows using them conditional cfg attributes in the .rs files, so +// +// #[cfg(py_sys_config="{varname}"] +// +// is the equivalent of #ifdef {varname} name in C. +// +// see Misc/SpecialBuilds.txt in the python source for what these mean. +// +// (hrm, this is sort of re-implementing what distutils does, except +// by passing command line args instead of referring to a python.h) +#[cfg(not(target_os = "windows"))] +static SYSCONFIG_FLAGS: [&'static str; 7] = [ + "Py_USING_UNICODE", + "Py_UNICODE_WIDE", + "WITH_THREAD", + "Py_DEBUG", + "Py_REF_DEBUG", + "Py_TRACE_REFS", + "COUNT_ALLOCS", +]; + +static SYSCONFIG_VALUES: [&'static str; 1] = [ + // cfg doesn't support flags with values, just bools - so flags + // below are translated into bools as {varname}_{val} + // + // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 + "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide +]; + +/// Examine python's compile flags to pass to cfg by launching +/// the interpreter and printing variables of interest from +/// sysconfig.get_config_vars. +#[cfg(not(target_os = "windows"))] +pub fn get_config_vars(python_path: &PathBuf) -> Result, String> { + let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); + + for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { + script.push_str(&format!( + "print(config.get('{}', {}))", + k, + if is_value(k) { "None" } else { "0" } + )); + script.push_str(";"); + } + + let out = try!(run_python_script(python_path, &script)); + + let split_stdout: Vec<&str> = out.trim_right().split(NEWLINE_SEQUENCE).collect(); + if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { + return Err(format!( + "python stdout len didn't return expected number of lines: {}", + split_stdout.len() + ).to_string()); + } + let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); + // let var_map: HashMap = HashMap::new(); + let mut all_vars = all_vars.zip(split_stdout.iter()).fold( + HashMap::new(), + |mut memo: HashMap, (&k, &v)| { + if !(v.to_owned() == "None" && is_value(k)) { + memo.insert(k.to_owned(), v.to_owned()); + } + memo + }, + ); + + let debug = if let Some(val) = all_vars.get("Py_DEBUG") { + val == "1" + } else { + false + }; + if debug { + all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); + all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); + all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + } + + Ok(all_vars) +} + +#[cfg(target_os = "windows")] +pub fn get_config_vars(_: &PathBuf) -> Result, String> { + // sysconfig is missing all the flags on windows, so we can't actually + // query the interpreter directly for its build flags. + // + // For the time being, this is the flags as defined in the python source's + // PC\pyconfig.h. This won't work correctly if someone has built their + // python with a modified pyconfig.h - sorry if that is you, you will have + // to comment/uncomment the lines below. + let mut map: HashMap = HashMap::new(); + map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); + map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); + + // This is defined #ifdef _DEBUG. The visual studio build seems to produce + // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the + // Debug configuration, which this script doesn't currently support anyway. + // map.insert("Py_DEBUG", "1"); + + // Uncomment these manually if your python was built with these and you want + // the cfg flags to be set in rust. + // + // map.insert("Py_REF_DEBUG", "1"); + // map.insert("Py_TRACE_REFS", "1"); + // map.insert("COUNT_ALLOCS", 1"); + Ok(map) +} + +fn is_value(key: &str) -> bool { + SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() +} + +fn cfg_line_for_var(key: &str, val: &str) -> Option { + if is_value(key) { + // is a value; suffix the key name with the value + Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) + } else if val != "0" { + // is a flag that isn't zero + Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) + } else { + // is a flag that is zero + None + } +} + +/// Run a python script using the specified interpreter binary. +fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result { + let mut cmd = Command::new(interpreter_path); + cmd.arg("-c").arg(script); + + let out = try!( + cmd.output() + .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e)) + ); + + if !out.status.success() { + let stderr = String::from_utf8(out.stderr).unwrap(); + let mut msg = format!("python script failed with stderr:\n\n"); + msg.push_str(&stderr); + return Err(msg); + } + + let out = String::from_utf8(out.stdout).unwrap(); + return Ok(out); +} + +#[cfg(not(target_os = "macos"))] +#[cfg(not(target_os = "windows"))] +fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { + if interpreter_config.is_pypy { + let link_library_name = match interpreter_config.version.major { + 2 => "pypy-c", + 3 => "pypy3-c", + _ => unreachable!(), + }; + // All modern PyPy versions with cpyext are compiled as shared libraries. + return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + } + + if interpreter_config.enable_shared { + Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )) + } else { + Ok(format!( + "cargo:rustc-link-lib=static=python{}", + interpreter_config.ld_version + )) + } +} + +#[cfg(target_os = "windows")] +fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { + if interpreter_config.is_pypy { + let link_library_name = match interpreter_config.version.major { + 2 => "pypy-c", + 3 => "pypy3-c", + _ => unreachable!(), + }; + // All modern PyPy versions with cpyext are compiled as shared libraries. + return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + } + + // Py_ENABLE_SHARED doesn't seem to be present on windows. + Ok(format!( + "cargo:rustc-link-lib=pythonXY:python{}{}", + version.major, + match version.minor { + Some(minor) => minor.to_string(), + None => "".to_owned(), + } + )) +} + +#[cfg(target_os = "macos")] +fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { + if interpreter_config.is_pypy { + let link_library_name = match interpreter_config.version.major { + 2 => "pypy-c", + 3 => "pypy3-c", + _ => unreachable!(), + }; + // All modern PyPy versions with cpyext are compiled as shared libraries. + return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + } + + // os x can be linked to a framework or static or dynamic, and + // Py_ENABLE_SHARED is wrong; framework means shared library + match get_macos_linkmodel(&interpreter_config.path) + .unwrap() + .as_ref() + { + "static" => Ok(format!( + "cargo:rustc-link-lib=static=python{}", + interpreter_config.ld_version + )), + "shared" => Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )), + "framework" => Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )), + other => Err(format!("unknown linkmodel {}", other)), + } +} + +#[cfg(target_os = "macos")] +fn get_macos_linkmodel(interpreter_path: &PathBuf) -> Result { + let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; + let out = run_python_script(interpreter_path, script).unwrap(); + Ok(out.trim_right().to_owned()) +} + +/// Parse string as interpreter version. +fn parse_interpreter_version(line: &str) -> Result { + let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); + match version_re.captures(&line) { + Some(cap) => Ok(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), + }), + None => Err(format!("Unexpected response to version query {}", line)), + } +} + +fn check_pypy(interpreter_path: &PathBuf) -> bool { + let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; + let is_pypy: bool = run_python_script(interpreter_path, script) + .unwrap() + .to_lowercase() + .trim_right() + .parse() + .unwrap(); + return is_pypy; +} + +/// Locate a suitable python interpreter and extract config from it. +/// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided +/// path a Python executable, and raises an error if the version doesn't match. +/// Else tries to execute the interpreter as "python", "python{major version}", +/// "python{major version}.{minor version}" in order until one +/// is of the version we are expecting. +pub fn find_interpreter(expected_version: &PythonVersion) -> Result { + // To use PyPy, a valid pypy executable must be passed to PYTHON_SYS_EXECUTABLE + if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { + let interpreter_path_or_executable = interpreter_from_env + .to_str() + .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); + + let interpreter_path = + canonicalize_executable(interpreter_path_or_executable).expect(&format!( + "Could not find interpreter passed in PYTHON_SYS_EXECUTABLE={}\n", + interpreter_path_or_executable + )); + + let interpreter_config: InterpreterConfig; + + if check_pypy(&interpreter_path) { + interpreter_config = try!(InterpreterConfig::from_pypy(interpreter_path)); + } else { + interpreter_config = try!(InterpreterConfig::from_cpython(interpreter_path)); + } + + if expected_version == &interpreter_config.version { + return Ok(interpreter_config); + } else { + return Err(format!( + "Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ + \tmin version {} != found {}", + interpreter_path_or_executable, expected_version, interpreter_config.version + )); + } + } + + let mut possible_python_paths = vec![ + "python".to_string(), + format!("python{}", expected_version.major), + ]; + if let Some(minor) = expected_version.minor { + possible_python_paths.push(format!("python{}.{}", expected_version.major, minor)) + } + + for possible_path in possible_python_paths { + let interpreter_path = canonicalize_executable(&possible_path); + if interpreter_path.is_some() { + let interpreter_config = + try!(InterpreterConfig::from_cpython(interpreter_path.unwrap())); + if expected_version == &interpreter_config.version { + return Ok(interpreter_config); + } + } + } + + Err(format!("No python interpreter found")) +} + +/// Deduce configuration from the 'python' in the current PATH and print +/// cargo vars to stdout. +/// +/// Note that if the python doesn't satisfy expected_version, this will error. +pub fn emit_cargo_vars_from_configuration( + interpreter_config: &InterpreterConfig, +) -> Result { + let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); + + if interpreter_config.is_pypy { + println!("cargo:rustc-cfg=PyPy"); + } + + if !is_extension_module || cfg!(target_os = "windows") { + println!("{}", get_rustc_link_lib(&interpreter_config).unwrap()); + + if interpreter_config.libpath != "None" { + println!( + "cargo:rustc-link-search=native={}", + interpreter_config.libpath + ); + } else if cfg!(target_os = "windows") { + println!( + "cargo:rustc-link-search=native={}\\libs", + interpreter_config.exec_prefix + ); + } + } + + let mut flags = String::new(); + + if let PythonVersion { + major: 3, + minor: some_minor, + } = interpreter_config.version + { + if env::var_os("CARGO_FEATURE_PEP_384").is_some() { + println!("cargo:rustc-cfg=Py_LIMITED_API"); + } + if let Some(minor) = some_minor { + if minor < PY3_MIN_MINOR { + return Err(format!( + "Python 3 required version is 3.{}, current version is 3.{}", + PY3_MIN_MINOR, minor + )); + } + for i in 5..(minor + 1) { + 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(); + } + return Ok(flags); +} + +/// Determine the python version we're supposed to be building +/// from the features passed via the environment. +/// +/// The environment variable can choose to omit a minor +/// version if the user doesn't care. +fn version_from_env() -> Result { + let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); + // sort env::vars so we get more explicit version specifiers first + // so if the user passes e.g. the python-3 feature and the python-3-5 + // feature, python-3-5 takes priority. + let mut vars = env::vars().collect::>(); + + vars.sort_by(|a, b| b.cmp(a)); + for (key, _) in vars { + match re.captures(&key) { + Some(cap) => { + return Ok(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: match cap.get(3) { + Some(s) => Some(s.as_str().parse().unwrap()), + None => None, + }, + }); + } + None => (), + } + } + + Err( + "Python version feature was not found. At least one python version \ + feature must be enabled." + .to_owned(), + ) +} + +// TODO: move this somewhere these test could be ran +#[cfg(test)] +mod test { + use std::env; + use py_interpreter::{PythonVersion, InterpreterConfig, run_python_script, find_interpreter}; + use std::path::PathBuf; + + #[test] + fn test_correctly_detects_cpython() { + let python_version_major_only = PythonVersion { + major: 3, + minor: None, + }; + let expected_config = InterpreterConfig { + version: python_version_major_only, + path: (PathBuf::from("bla")), + libpath: String::from("bla"), + enable_shared: false, + ld_version: String::from("bla"), + exec_prefix: String::from("bla"), + is_pypy: false, + }; + + let interpreter = find_interpreter(&python_version_major_only).unwrap(); + + println!("{:?}", interpreter); + + assert_eq!(interpreter.version, expected_config.version); + assert_eq!(interpreter.path, expected_config.path); + } +} diff --git a/pyo3build/src/rustc_version.rs b/pyo3build/src/rustc_version.rs new file mode 100644 index 00000000000..d3021b0964c --- /dev/null +++ b/pyo3build/src/rustc_version.rs @@ -0,0 +1,46 @@ +extern crate version_check; +use self::version_check::{is_min_date, is_min_version, supports_features}; + +// Specifies the minimum nightly version needed to compile pyo3. +const MIN_DATE: &'static str = "2017-11-07"; +const MIN_VERSION: &'static str = "1.23.0-nightly"; + +pub fn check_rustc_version() { + let ok_channel = supports_features(); + let ok_version = is_min_version(MIN_VERSION); + let ok_date = is_min_date(MIN_DATE); + + let print_version_err = |version: &str, date: &str| { + eprintln!( + "Installed version is: {} ({}). Minimum required: {} ({}).", + version, date, MIN_VERSION, MIN_DATE + ); + }; + + match (ok_channel, ok_version, ok_date) { + (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { + if !ok_channel { + eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); + print_version_err(&*version, &*date); + panic!("Aborting compilation due to incompatible compiler.") + } + + if !ok_version || !ok_date { + eprintln!("Error: pyo3 requires a more recent version of rustc."); + eprintln!("Use `rustup update` or your preferred method to update Rust"); + print_version_err(&*version, &*date); + panic!("Aborting compilation due to incompatible compiler.") + } + } + _ => { + println!( + "cargo:warning={}", + "pyo3 was unable to check rustc compatibility." + ); + println!( + "cargo:warning={}", + "Build may fail due to incompatible rustc version." + ); + } + } +} From 1e70333fc83eb99998baf9f2ca4fb6055a7ee065 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 29 Mar 2018 17:47:09 +0300 Subject: [PATCH 010/138] added pypy test --- pyo3build/src/py_interpreter.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 55c9d6b6ddf..db51a68cfd7 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -550,12 +550,16 @@ mod test { minor: None, }; let expected_config = InterpreterConfig { - version: python_version_major_only, - path: (PathBuf::from("bla")), - libpath: String::from("bla"), + version: PythonVersion { + major: 3, + minor: Some(6) + }, + // We can't reliably test this unless we make some assumptions + path: (PathBuf::from("/Users/omerba/anaconda/bin/python")), + libpath: String::from("some_lib_path"), enable_shared: false, - ld_version: String::from("bla"), - exec_prefix: String::from("bla"), + ld_version: String::from("3.6m"), + exec_prefix: String::from("some_exec_prefix"), is_pypy: false, }; @@ -566,4 +570,17 @@ mod test { assert_eq!(interpreter.version, expected_config.version); assert_eq!(interpreter.path, expected_config.path); } + + #[test] + fn test_correctly_detects_python_from_envvar() { + env::set_var("PYTHON_SYS_EXECUTABLE", "/Users/omerba/anaconda/envs/python-rust-bindings/bin/pypy3"); + let python_version_major_only = PythonVersion { + major: 3, + minor: None, + }; + let interpreter = find_interpreter(&python_version_major_only).unwrap(); + env::set_var("PYTHON_SYS_EXECUTABLE", ""); + + assert_eq!(interpreter.is_pypy, true); + } } From 8e19bafa7b5987c41b8ecb3d72cb729bd390e8c2 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 2 Apr 2018 18:51:15 +0300 Subject: [PATCH 011/138] finally fixed pypy structs --- Cargo.toml | 4 + build.rs | 5 + pyo3build/Cargo.toml | 2 +- pyo3build/src/lib.rs | 2 +- pyo3build/src/py_interpreter.rs | 257 ++++++++++++++++++++++---------- src/lib.rs | 3 + 6 files changed, 192 insertions(+), 81 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab8b6b90d3e..d4c39362ed0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,10 @@ num-traits = "0.2" pyo3cls = { version = "^0.2.1" } regex = "0.2" version_check = "0.1" +pretty_assertions = "0.5.1" + +[dev-dependencies] +pretty_assertions = "0.5.1" [build-dependencies] pyo3-build-utils = {version = "*", path="pyo3build"} diff --git a/build.rs b/build.rs index 3eee245dd58..a2dea19a9e6 100644 --- a/build.rs +++ b/build.rs @@ -2,6 +2,11 @@ extern crate pyo3_build_utils; use pyo3_build_utils::rustc_version::check_rustc_version; use pyo3_build_utils::py_interpreter::{find_interpreter, emit_cargo_vars_from_configuration, get_config_vars}; +use pyo3_build_utils::py_interpreter::PythonVersion; +use pyo3_build_utils::py_interpreter::InterpreterConfig; +use pyo3_build_utils::py_interpreter::version_from_env; +use pyo3_build_utils::py_interpreter::cfg_line_for_var; +use pyo3_build_utils::py_interpreter::is_value; fn main() { check_rustc_version(); diff --git a/pyo3build/Cargo.toml b/pyo3build/Cargo.toml index 3aa0891a4d1..e07974e456e 100644 --- a/pyo3build/Cargo.toml +++ b/pyo3build/Cargo.toml @@ -11,4 +11,4 @@ license = "Apache-2.0" [dependencies] regex = "0.2" -version_check = "0.1" +version_check = "0.1" \ No newline at end of file diff --git a/pyo3build/src/lib.rs b/pyo3build/src/lib.rs index b37cb13929c..a50bb61917b 100644 --- a/pyo3build/src/lib.rs +++ b/pyo3build/src/lib.rs @@ -1,2 +1,2 @@ pub mod py_interpreter; -pub mod rustc_version; \ No newline at end of file +pub mod rustc_version; diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index db51a68cfd7..0a4477d7880 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -1,17 +1,86 @@ -use std::fmt; -use std::process::Command; use std::env; +use std::fmt; use std::path::{Path, PathBuf}; +use std::process::Command; extern crate regex; + use self::regex::Regex; use std::collections::HashMap; use std::string::String; +// Code copied from python wheel package +const GET_ABI_TAG: &'static str = " +from sysconfig import get_config_var +import platform +import sys + +def get_impl_ver(): + impl_ver = get_config_var('py_version_nodot') + if not impl_ver or get_abbr_impl() == 'pp': + impl_ver = ''.join(map(str, get_impl_version_info())) + return impl_ver + +def get_flag(var, fallback, expected=True, warn=True): + val = get_config_var(var) + if val is None: + if warn: + warnings.warn('Config variable {0} is unset, Python ABI tag may ' + 'be incorrect'.format(var), RuntimeWarning, 2) + return fallback() + return val == expected + + +def get_abbr_impl(): + impl = platform.python_implementation() + if impl == 'PyPy': + return 'pp' + elif impl == 'Jython': + return 'jy' + elif impl == 'IronPython': + return 'ip' + elif impl == 'CPython': + return 'cp' + + raise LookupError('Unknown Python implementation: ' + impl) + +def get_abi_tag(): + soabi = get_config_var('SOABI') + impl = get_abbr_impl() + if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'): + d = '' + m = '' + u = '' + if get_flag('Py_DEBUG', + lambda: hasattr(sys, 'gettotalrefcount'), + warn=(impl == 'cp')): + d = 'd' + if get_flag('WITH_PYMALLOC', + lambda: impl == 'cp', + warn=(impl == 'cp')): + m = 'm' + if get_flag('Py_UNICODE_SIZE', + lambda: sys.maxunicode == 0x10ffff, + expected=4, + warn=(impl == 'cp' and + sys.version_info < (3, 3))) \ + and sys.version_info < (3, 3): + u = 'u' + abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u) + elif soabi and soabi.startswith('cpython-'): + abi = 'cp' + soabi.split('-')[1] + elif soabi: + abi = soabi.replace('.', '_').replace('-', '_') + else: + abi = None + return abi + +print(get_abi_tag()) +"; // TODO: I'm not sure this works in windows -fn canonicalize_executable

(exe_name: P) -> Option +pub fn canonicalize_executable

(exe_name: P) -> Option where P: AsRef, { @@ -31,9 +100,9 @@ fn canonicalize_executable

(exe_name: P) -> Option #[derive(Debug, Copy, Clone)] pub struct PythonVersion { - major: u8, + pub major: u8, // minor == None means any minor version will do - minor: Option, + pub minor: Option, } impl PartialEq for PythonVersion { @@ -54,18 +123,34 @@ impl fmt::Display for PythonVersion { } } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct InterpreterConfig { - version: PythonVersion, - path: PathBuf, - libpath: String, - enable_shared: bool, - ld_version: String, - exec_prefix: String, - is_pypy: bool, + pub version: PythonVersion, + pub path: PathBuf, + pub libpath: String, + pub enable_shared: bool, + pub ld_version: String, + pub exec_prefix: String, + pub abi_version: String, + pub is_pypy: bool, } impl InterpreterConfig { + fn new(interpreter: PathBuf) -> Result { + let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; + let is_pypy: bool = run_python_script(&interpreter, script) + .unwrap() + .to_lowercase() + .trim_right() + .parse() + .unwrap(); + + if is_pypy { + return InterpreterConfig::from_pypy(interpreter); + } else { + return InterpreterConfig::from_cpython(interpreter); + } + } fn from_cpython(interpreter: PathBuf) -> Result { let script = "import sys; import sysconfig;\ print(sys.version_info[0:2]); \ @@ -75,17 +160,21 @@ impl InterpreterConfig { print(sys.exec_prefix);"; let out = try!(run_python_script(&interpreter, script)); - let lines: Vec<&str> = out.lines().collect(); - let cpython_version = try!(parse_interpreter_version(&lines[0])); + let abi_tag = try!(run_python_script(&interpreter, GET_ABI_TAG)) + .trim_right() + .to_string(); + + let interpreter_version = try!(parse_interpreter_version(&lines[0])); Ok(InterpreterConfig { - version: cpython_version, + version: interpreter_version, path: interpreter, libpath: lines[1].to_string(), enable_shared: lines[2] == "1", ld_version: lines[3].to_string(), + abi_version: abi_tag, exec_prefix: lines[4].to_string(), is_pypy: false, }) @@ -93,6 +182,15 @@ impl InterpreterConfig { // TODO: implement me nicely! fn from_pypy(interpreter: PathBuf) -> Result { + let script = "import sysconfig; import os;\ + print(os.path.join(sysconfig.get_path('data'), 'lib')) + print(sys.exec_prefix); + "; + + let abi_tag = try!(run_python_script(&interpreter, GET_ABI_TAG)) + .trim_right() + .to_string(); + Ok(InterpreterConfig { version: PythonVersion { major: 3, @@ -103,22 +201,41 @@ impl InterpreterConfig { enable_shared: true, ld_version: "3.5".to_string(), exec_prefix: "/Users/omerba/anaconda".to_string(), + abi_version: abi_tag, is_pypy: true, }) } } -const PY3_MIN_MINOR: u8 = 5; - const CFG_KEY: &'static str = "py_sys_config"; -// windows' python writes out lines with the windows crlf sequence; -// posix platforms and mac os should write out lines with just lf. -#[cfg(target_os = "windows")] -static NEWLINE_SEQUENCE: &'static str = "\r\n"; +static SYSCONFIG_VALUES: [&'static str; 1] = [ + // cfg doesn't support flags with values, just bools - so flags + // below are translated into bools as {varname}_{val} + // + // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 + "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide +]; -#[cfg(not(target_os = "windows"))] -static NEWLINE_SEQUENCE: &'static str = "\n"; + +pub fn is_value(key: &str) -> bool { + SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() +} + +pub fn cfg_line_for_var(key: &str, val: &str) -> Option { + if is_value(key) { + // is a value; suffix the key name with the value + Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) + } else if val != "0" { + // is a flag that isn't zero + Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) + } else { + // is a flag that is zero + None + } +} + +const PY3_MIN_MINOR: u8 = 5; // A list of python interpreter compile-time preprocessor defines that // we will pick up and pass to rustc via --cfg=py_sys_config={varname}; @@ -143,14 +260,6 @@ static SYSCONFIG_FLAGS: [&'static str; 7] = [ "COUNT_ALLOCS", ]; -static SYSCONFIG_VALUES: [&'static str; 1] = [ - // cfg doesn't support flags with values, just bools - so flags - // below are translated into bools as {varname}_{val} - // - // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 - "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide -]; - /// Examine python's compile flags to pass to cfg by launching /// the interpreter and printing variables of interest from /// sysconfig.get_config_vars. @@ -169,7 +278,7 @@ pub fn get_config_vars(python_path: &PathBuf) -> Result, let out = try!(run_python_script(python_path, &script)); - let split_stdout: Vec<&str> = out.trim_right().split(NEWLINE_SEQUENCE).collect(); + let split_stdout: Vec<&str> = out.trim_right().lines().collect(); if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { return Err(format!( "python stdout len didn't return expected number of lines: {}", @@ -231,22 +340,6 @@ pub fn get_config_vars(_: &PathBuf) -> Result, String> { Ok(map) } -fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() -} - -fn cfg_line_for_var(key: &str, val: &str) -> Option { - if is_value(key) { - // is a value; suffix the key name with the value - Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) - } else if val != "0" { - // is a flag that isn't zero - Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) - } else { - // is a flag that is zero - None - } -} /// Run a python script using the specified interpreter binary. fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result { @@ -371,17 +464,6 @@ fn parse_interpreter_version(line: &str) -> Result { } } -fn check_pypy(interpreter_path: &PathBuf) -> bool { - let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; - let is_pypy: bool = run_python_script(interpreter_path, script) - .unwrap() - .to_lowercase() - .trim_right() - .parse() - .unwrap(); - return is_pypy; -} - /// Locate a suitable python interpreter and extract config from it. /// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided /// path a Python executable, and raises an error if the version doesn't match. @@ -401,13 +483,7 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result Result Result { +pub fn version_from_env() -> Result { let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); // sort env::vars so we get more explicit version specifiers first // so if the user passes e.g. the python-3 feature and the python-3-5 @@ -539,8 +614,9 @@ fn version_from_env() -> Result { // TODO: move this somewhere these test could be ran #[cfg(test)] mod test { + use py_interpreter::canonicalize_executable; + use py_interpreter::{find_interpreter, run_python_script, InterpreterConfig, PythonVersion}; use std::env; - use py_interpreter::{PythonVersion, InterpreterConfig, run_python_script, find_interpreter}; use std::path::PathBuf; #[test] @@ -552,14 +628,15 @@ mod test { let expected_config = InterpreterConfig { version: PythonVersion { major: 3, - minor: Some(6) + minor: Some(6), }, // We can't reliably test this unless we make some assumptions path: (PathBuf::from("/Users/omerba/anaconda/bin/python")), - libpath: String::from("some_lib_path"), - enable_shared: false, + libpath: String::from("/Users/omerba/anaconda/lib"), + enable_shared: true, ld_version: String::from("3.6m"), - exec_prefix: String::from("some_exec_prefix"), + exec_prefix: String::from("/Users/omerba/anaconda"), + abi_version: String::from("cp36m"), is_pypy: false, }; @@ -567,20 +644,42 @@ mod test { println!("{:?}", interpreter); - assert_eq!(interpreter.version, expected_config.version); - assert_eq!(interpreter.path, expected_config.path); + assert_eq!(interpreter, expected_config); } #[test] fn test_correctly_detects_python_from_envvar() { - env::set_var("PYTHON_SYS_EXECUTABLE", "/Users/omerba/anaconda/envs/python-rust-bindings/bin/pypy3"); + let test_path = + canonicalize_executable("pypy3").expect("pypy3 not found in PATH, cannot test"); + + env::set_var( + "PYTHON_SYS_EXECUTABLE", + test_path.into_os_string().into_string().unwrap(), + ); + let python_version_major_only = PythonVersion { major: 3, minor: None, }; + let interpreter = find_interpreter(&python_version_major_only).unwrap(); env::set_var("PYTHON_SYS_EXECUTABLE", ""); - assert_eq!(interpreter.is_pypy, true); + let expected_config = InterpreterConfig { + version: PythonVersion { + major: 3, + minor: Some(5), + }, + // We can't reliably test this unless we make some assumptions + path: (PathBuf::from("/Users/omerba/anaconda/bin/pypy3")), + libpath: String::from("/Users/omerba/anaconda/lib"), + enable_shared: true, + ld_version: String::from("3.5"), + exec_prefix: String::from("/Users/omerba/anaconda"), + abi_version: String::from("pypy3_510"), + is_pypy: true, + }; + + assert_eq!(interpreter, expected_config); } } diff --git a/src/lib.rs b/src/lib.rs index 8f1b65f62b1..78b71818a4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -140,6 +140,9 @@ extern crate spin; extern crate pyo3cls; #[macro_use] extern crate log; +#[macro_use] +extern crate pretty_assertions; + #[cfg(not(Py_3))] mod ffi2; From 7ee426a200079b959572de1995fa82071679ba17 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 2 Apr 2018 18:55:41 +0300 Subject: [PATCH 012/138] removed some todos --- pyo3build/src/py_interpreter.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 0a4477d7880..ea052449df9 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -180,27 +180,29 @@ impl InterpreterConfig { }) } - // TODO: implement me nicely! fn from_pypy(interpreter: PathBuf) -> Result { - let script = "import sysconfig; import os;\ - print(os.path.join(sysconfig.get_path('data'), 'lib')) + let script = "import sysconfig; import sys; import os;\ + print(sys.version_info[0:2]); \ + print(os.path.join(sysconfig.get_path('data'), 'lib')); \ print(sys.exec_prefix); "; + let out = try!(run_python_script(&interpreter, script)); + let lines: Vec<&str> = out.lines().collect(); + let abi_tag = try!(run_python_script(&interpreter, GET_ABI_TAG)) .trim_right() .to_string(); + let interpreter_version = try!(parse_interpreter_version(&lines[0])); + Ok(InterpreterConfig { - version: PythonVersion { - major: 3, - minor: Some(5), - }, + version: interpreter_version, path: interpreter, - libpath: "/Users/omerba/anaconda/lib".to_string(), + libpath: lines[1].to_string(), enable_shared: true, ld_version: "3.5".to_string(), - exec_prefix: "/Users/omerba/anaconda".to_string(), + exec_prefix: lines[2].to_string(), abi_version: abi_tag, is_pypy: true, }) @@ -611,7 +613,7 @@ pub fn version_from_env() -> Result { ) } -// TODO: move this somewhere these test could be ran + #[cfg(test)] mod test { use py_interpreter::canonicalize_executable; From 6f464aab84019309ea6a173523a29892d2f7dd1a Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 2 Apr 2018 19:12:37 +0300 Subject: [PATCH 013/138] test should now be machine independent --- pyo3build/src/py_interpreter.rs | 36 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index ea052449df9..56ba5e395e1 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -620,6 +620,7 @@ mod test { use py_interpreter::{find_interpreter, run_python_script, InterpreterConfig, PythonVersion}; use std::env; use std::path::PathBuf; + use py_interpreter::GET_ABI_TAG; #[test] fn test_correctly_detects_cpython() { @@ -632,12 +633,11 @@ mod test { major: 3, minor: Some(6), }, - // We can't reliably test this unless we make some assumptions - path: (PathBuf::from("/Users/omerba/anaconda/bin/python")), - libpath: String::from("/Users/omerba/anaconda/lib"), + path: (canonicalize_executable("python").unwrap()), + libpath: String::from("some_path"), enable_shared: true, ld_version: String::from("3.6m"), - exec_prefix: String::from("/Users/omerba/anaconda"), + exec_prefix: String::from("some_path"), abi_version: String::from("cp36m"), is_pypy: false, }; @@ -646,7 +646,11 @@ mod test { println!("{:?}", interpreter); - assert_eq!(interpreter, expected_config); + assert_eq!(interpreter.version, expected_config.version); + assert_eq!(interpreter.enable_shared, expected_config.enable_shared); + assert_eq!(interpreter.ld_version, expected_config.ld_version); + assert_eq!(interpreter.abi_version, expected_config.abi_version); + assert_eq!(interpreter.is_pypy, expected_config.is_pypy); } #[test] @@ -656,7 +660,7 @@ mod test { env::set_var( "PYTHON_SYS_EXECUTABLE", - test_path.into_os_string().into_string().unwrap(), + test_path.clone().into_os_string().into_string().unwrap() ); let python_version_major_only = PythonVersion { @@ -667,21 +671,31 @@ mod test { let interpreter = find_interpreter(&python_version_major_only).unwrap(); env::set_var("PYTHON_SYS_EXECUTABLE", ""); + let abi_tag = run_python_script(&test_path, GET_ABI_TAG) + .unwrap() + .trim_right() + .to_string(); + + let expected_config = InterpreterConfig { version: PythonVersion { major: 3, minor: Some(5), }, // We can't reliably test this unless we make some assumptions - path: (PathBuf::from("/Users/omerba/anaconda/bin/pypy3")), - libpath: String::from("/Users/omerba/anaconda/lib"), + path: (canonicalize_executable("python").unwrap()), + libpath: String::from("some_path"), enable_shared: true, ld_version: String::from("3.5"), - exec_prefix: String::from("/Users/omerba/anaconda"), - abi_version: String::from("pypy3_510"), + exec_prefix: String::from("some_path"), + abi_version: String::from(abi_tag), is_pypy: true, }; - assert_eq!(interpreter, expected_config); + assert_eq!(interpreter.version, expected_config.version); + assert_eq!(interpreter.enable_shared, expected_config.enable_shared); + assert_eq!(interpreter.ld_version, expected_config.ld_version); + assert_eq!(interpreter.abi_version, expected_config.abi_version); + assert_eq!(interpreter.is_pypy, expected_config.is_pypy); } } From 7abadd9029cea8e27d3f1305fbacb063d7c4ab50 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 12:18:08 +0300 Subject: [PATCH 014/138] fixed all pypy3 symbols --- src/ffi3/bytesobject.rs | 5 +++-- src/ffi3/ceval.rs | 5 +++-- src/ffi3/import.rs | 2 +- src/ffi3/modsupport.rs | 12 +++++++++++- src/ffi3/moduleobject.rs | 5 ++++- src/ffi3/object.rs | 7 ++++++- src/ffi3/objectabstract.rs | 15 +++++++++++++-- src/ffi3/objimpl.rs | 10 +++++++++- src/ffi3/pycapsule.rs | 15 +++++++++++++-- src/ffi3/pydebug.rs | 16 ++++++++++++++-- src/ffi3/pyerrors.rs | 6 +++++- src/ffi3/pymem.rs | 11 +++++++++-- src/ffi3/rangeobject.rs | 2 +- src/ffi3/structseq.rs | 2 +- src/ffi3/sysmodule.rs | 5 +++-- src/ffi3/traceback.rs | 2 +- src/ffi3/tupleobject.rs | 4 +++- src/ffi3/unicodeobject.rs | 9 +++++++-- src/ffi3/warnings.rs | 2 +- 19 files changed, 108 insertions(+), 27 deletions(-) diff --git a/src/ffi3/bytesobject.rs b/src/ffi3/bytesobject.rs index 8ef354879a6..c89b840998a 100644 --- a/src/ffi3/bytesobject.rs +++ b/src/ffi3/bytesobject.rs @@ -22,6 +22,8 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { arg2: Py_ssize_t) -> *mut PyObject; pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject; pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromFormat")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromFormatV")] //pub fn PyBytes_FromFormatV(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; pub fn PyBytes_FromFormat(arg1: *const c_char, ...) @@ -40,5 +42,4 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { pub fn PyBytes_AsStringAndSize(obj: *mut PyObject, s: *mut *mut c_char, len: *mut Py_ssize_t) -> c_int; -} - +} \ No newline at end of file diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 781a676aa28..5a9fe86a840 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -17,9 +17,11 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallFunction")] pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallMethod")] pub fn PyEval_CallMethod(obj: *mut PyObject, methodname: *const c_char, format: *const c_char, ...) @@ -68,5 +70,4 @@ pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) pub fn PyEval_AcquireThread(tstate: *mut PyThreadState) -> (); pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState) -> (); pub fn PyEval_ReInitThreads() -> (); -} - +} \ No newline at end of file diff --git a/src/ffi3/import.rs b/src/ffi3/import.rs index 67beaa53a84..34b95f93859 100644 --- a/src/ffi3/import.rs +++ b/src/ffi3/import.rs @@ -29,6 +29,7 @@ use ffi3::object::PyObject; -> *mut PyObject; pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleLevel")] pub fn PyImport_ImportModuleLevel(name: *const c_char, globals: *mut PyObject, locals: *mut PyObject, @@ -65,4 +66,3 @@ pub unsafe fn PyImport_ImportModuleEx(name: *const c_char, initfunc: Option *mut PyObject>) -> c_int; } - diff --git a/src/ffi3/modsupport.rs b/src/ffi3/modsupport.rs index ddb82f5b33f..758e0fe2e43 100644 --- a/src/ffi3/modsupport.rs +++ b/src/ffi3/modsupport.rs @@ -5,27 +5,37 @@ use ffi3::moduleobject::PyModuleDef; use ffi3::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_Parse")] pub fn PyArg_Parse(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTuple")] pub fn PyArg_ParseTuple(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTupleAndKeywords")] pub fn PyArg_ParseTupleAndKeywords(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *const c_char, arg4: *mut *mut c_char, ...) -> c_int; pub fn PyArg_ValidateKeywordArguments(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_UnpackTuple")] pub fn PyArg_UnpackTuple(arg1: *mut PyObject, arg2: *const c_char, arg3: Py_ssize_t, arg4: Py_ssize_t, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BuildValue")] pub fn Py_BuildValue(arg1: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_BuildValue_SizeT")] //pub fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_VaBuildValue")] //pub fn Py_VaBuildValue(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddObject")] pub fn PyModule_AddObject(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddIntConstant")] pub fn PyModule_AddIntConstant(arg1: *mut PyObject, arg2: *const c_char, arg3: c_long) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddStringConstant")] pub fn PyModule_AddStringConstant(arg1: *mut PyObject, arg2: *const c_char, arg3: *const c_char) -> c_int; @@ -85,4 +95,4 @@ pub unsafe fn PyModule_Create(module: *mut PyModuleDef) -> *mut PyObject { #[inline] pub unsafe fn PyModule_FromDefAndSpec(def: *mut PyModuleDef, spec: *mut PyObject) -> *mut PyObject { PyModule_FromDefAndSpec2(def, spec, if cfg!(Py_LIMITED_API) { PYTHON_ABI_VERSION } else { PYTHON_API_VERSION }) -} +} \ No newline at end of file diff --git a/src/ffi3/moduleobject.rs b/src/ffi3/moduleobject.rs index bf2cfaa0039..7f2132d086a 100644 --- a/src/ffi3/moduleobject.rs +++ b/src/ffi3/moduleobject.rs @@ -25,8 +25,11 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDef")] pub fn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetState")] pub fn PyModule_GetState(arg1: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModuleDef_Init")] pub fn PyModuleDef_Init(arg1: *mut PyModuleDef) -> *mut PyObject; pub static mut PyModuleDef_Type: PyTypeObject; } @@ -81,4 +84,4 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { m_traverse: None, m_clear: None, m_free: None -}; +}; \ No newline at end of file diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 6955796da93..20ebe2e536c 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -620,6 +620,7 @@ impl Default for PyType_Spec { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_FromSpec")] pub fn PyType_FromSpec(arg1: *mut PyType_Spec) -> *mut PyObject; pub fn PyType_FromSpecWithBases(arg1: *mut PyType_Spec, arg2: *mut PyObject) @@ -660,6 +661,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericAlloc")] 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; @@ -707,6 +709,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg(not(Py_LIMITED_API))] pub fn PyObject_CallFinalizer(arg1: *mut PyObject) -> (); #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFinalizerFromDealloc")] pub fn PyObject_CallFinalizerFromDealloc(arg1: *mut PyObject) -> c_int; pub fn PyObject_Dir(arg1: *mut PyObject) -> *mut PyObject; @@ -782,6 +785,7 @@ pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { #[inline(always)] pub unsafe fn Py_INCREF(op : *mut PyObject) { if cfg!(py_sys_config="Py_REF_DEBUG") { + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IncRef")] Py_IncRef(op) } else { (*op).ob_refcnt += 1 @@ -791,6 +795,7 @@ pub unsafe fn Py_INCREF(op : *mut PyObject) { #[inline(always)] pub unsafe fn Py_DECREF(op: *mut PyObject) { if cfg!(py_sys_config="Py_REF_DEBUG") { + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DecRef")] Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -858,4 +863,4 @@ pub fn PyObject_Check(_arg1: *mut PyObject) -> c_int { #[inline] pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int { 0 -} +} \ No newline at end of file diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index 96fb20d0086..935e7747a9c 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -18,17 +18,21 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ kw: *mut PyObject) -> *mut PyObject; pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunction")] #[cfg_attr(PyPy, link_name = "\u{1}_PyPyObject_CallFunction")] pub fn PyObject_CallFunction(callable_object: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethod")] pub fn PyObject_CallMethod(o: *mut PyObject, method: *const c_char, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunctionObjArgs")] pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethodObjArgs")] pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, method: *mut PyObject, ...) -> *mut PyObject; @@ -59,11 +63,14 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsReadBuffer")] pub fn PyObject_AsReadBuffer(obj: *mut PyObject, buffer: *mut *const c_void, buffer_len: *mut Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsWriteBuffer")] pub fn PyObject_AsWriteBuffer(obj: *mut PyObject, buffer: *mut *mut c_void, buffer_len: *mut Py_ssize_t) @@ -79,13 +86,17 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetBuffer")] pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_GetPointer")] pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_ToContiguous")] pub fn PyBuffer_ToContiguous(buf: *mut c_void, view: *mut Py_buffer, len: Py_ssize_t, order: c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromContiguous")] pub fn PyBuffer_FromContiguous(view: *mut Py_buffer, buf: *mut c_void, len: Py_ssize_t, order: c_char) -> c_int; @@ -102,6 +113,7 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { buf: *mut c_void, len: Py_ssize_t, readonly: c_int, flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer) -> (); } @@ -287,5 +299,4 @@ pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int typeorclass: *mut PyObject) -> c_int; pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; -} - +} \ No newline at end of file diff --git a/src/ffi3/objimpl.rs b/src/ffi3/objimpl.rs index c033e43aea9..36a3cdd1e0e 100644 --- a/src/ffi3/objimpl.rs +++ b/src/ffi3/objimpl.rs @@ -7,14 +7,19 @@ use ffi3::object::*; pub fn PyObject_Malloc(size: size_t) -> *mut c_void; pub fn PyObject_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; pub fn PyObject_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Free")] pub fn PyObject_Free(ptr: *mut c_void) -> (); #[cfg(not(Py_LIMITED_API))] pub fn _Py_GetAllocatedBlocks() -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Init")] pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_InitVar")] pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject, arg3: Py_ssize_t) -> *mut PyVarObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_New")] pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_NewVar")] pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn PyGC_Collect() -> Py_ssize_t; @@ -64,10 +69,13 @@ pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int { pub fn _PyObject_GC_Malloc(size: size_t) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn _PyObject_GC_Calloc(size: size_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GC_New")] pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GC_NewVar")] 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) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GC_Del")] pub fn PyObject_GC_Del(arg1: *mut c_void) -> (); } @@ -83,4 +91,4 @@ pub unsafe fn PyType_SUPPORTS_WEAKREFS(t : *mut PyTypeObject) -> c_int { 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 u8).offset(weaklistoffset) as *mut *mut PyObject -} +} \ No newline at end of file diff --git a/src/ffi3/pycapsule.rs b/src/ffi3/pycapsule.rs index e1fbc1932f3..d809d87a6d0 100644 --- a/src/ffi3/pycapsule.rs +++ b/src/ffi3/pycapsule.rs @@ -2,6 +2,7 @@ use std::os::raw::{c_void, c_char, c_int}; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -13,31 +14,41 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_New")] pub fn PyCapsule_New(pointer: *mut c_void, name: *const c_char, destructor: Option) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetPointer")] pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_IsValid")] pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetPointer")] pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetDestructor")] pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, destructor: Option) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetName")] pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetContext")] pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Import")] pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; -} - +} \ No newline at end of file diff --git a/src/ffi3/pydebug.rs b/src/ffi3/pydebug.rs index 651981c4ccc..1aed602e70d 100644 --- a/src/ffi3/pydebug.rs +++ b/src/ffi3/pydebug.rs @@ -2,23 +2,35 @@ use std::os::raw::c_int; #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; pub static mut Py_QuietFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; pub static mut Py_UnbufferedStdioFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; pub static mut Py_IsolatedFlag: c_int; #[cfg(all(Py_3_6, windows))] pub static mut Py_LegacyWindowsStdioFlag: c_int; -} - +} \ No newline at end of file diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 660ac1774b0..ecc5dc2a87e 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -20,6 +20,7 @@ use ffi3::object::*; arg3: *mut *mut PyObject) -> (); pub fn PyErr_SetExcInfo(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char) -> !; pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; @@ -144,6 +145,7 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; pub fn PyErr_SetFromErrnoWithFilename( exc: *mut PyObject, filename: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Format")] pub fn PyErr_Format( exception: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; #[cfg(Py_3_6)] @@ -155,8 +157,10 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub fn PyErr_BadInternalCall() -> (); pub fn _PyErr_BadInternalCall(filename: *const c_char, lineno: c_int) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewException")] pub fn PyErr_NewException(name: *const c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewExceptionWithDoc")] pub fn PyErr_NewExceptionWithDoc(name: *const c_char, doc: *const c_char, base: *mut PyObject, dict: *mut PyObject) @@ -209,4 +213,4 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { reason: *const c_char) -> c_int; pub fn PyUnicodeTranslateError_SetReason(exc: *mut PyObject, reason: *const c_char) -> c_int; -} +} \ No newline at end of file diff --git a/src/ffi3/pymem.rs b/src/ffi3/pymem.rs index f1c8fb7565e..4c7627234a8 100644 --- a/src/ffi3/pymem.rs +++ b/src/ffi3/pymem.rs @@ -3,19 +3,27 @@ use libc::size_t; #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawMalloc")] pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawCalloc")] pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawRealloc")] pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawFree")] pub fn PyMem_RawFree(ptr: *mut c_void) -> (); } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Malloc")] pub fn PyMem_Malloc(size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Calloc")] pub fn PyMem_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Realloc")] pub fn PyMem_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Free")] pub fn PyMem_Free(ptr: *mut c_void) -> (); } @@ -56,5 +64,4 @@ pub struct PyMemAllocatorEx { pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx) -> (); pub fn PyMem_SetupDebugHooks() -> (); -} - +} \ No newline at end of file diff --git a/src/ffi3/rangeobject.rs b/src/ffi3/rangeobject.rs index 6fb46c83feb..5644590e2a2 100644 --- a/src/ffi3/rangeobject.rs +++ b/src/ffi3/rangeobject.rs @@ -2,6 +2,7 @@ use std::os::raw::c_int; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; pub static mut PyRangeIter_Type: PyTypeObject; pub static mut PyLongRangeIter_Type: PyTypeObject; @@ -11,4 +12,3 @@ use ffi3::object::*; pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyRange_Type) as c_int } - diff --git a/src/ffi3/structseq.rs b/src/ffi3/structseq.rs index 2afc9c88cd7..f1b1009cbd6 100644 --- a/src/ffi3/structseq.rs +++ b/src/ffi3/structseq.rs @@ -19,6 +19,7 @@ pub struct PyStructSequence_Desc { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyStructSequence_New")] pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) -> *mut PyTypeObject; pub fn PyStructSequence_New(_type: *mut PyTypeObject) -> *mut PyObject; @@ -27,4 +28,3 @@ pub struct PyStructSequence_Desc { pub fn PyStructSequence_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; } - diff --git a/src/ffi3/sysmodule.rs b/src/ffi3/sysmodule.rs index 7fe13796cee..0b7549ad9f3 100644 --- a/src/ffi3/sysmodule.rs +++ b/src/ffi3/sysmodule.rs @@ -12,7 +12,9 @@ use ffi3::pyport::Py_ssize_t; pub fn PySys_SetArgvEx(arg1: c_int, arg2: *mut *mut wchar_t, arg3: c_int) -> (); pub fn PySys_SetPath(arg1: *const wchar_t) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_WriteStdout")] pub fn PySys_WriteStdout(format: *const c_char, ...) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_WriteStderr")] pub fn PySys_WriteStderr(format: *const c_char, ...) -> (); pub fn PySys_FormatStdout(format: *const c_char, ...) -> (); pub fn PySys_FormatStderr(format: *const c_char, ...) -> (); @@ -22,5 +24,4 @@ use ffi3::pyport::Py_ssize_t; pub fn PySys_HasWarnOptions() -> c_int; pub fn PySys_AddXOption(arg1: *const wchar_t) -> (); pub fn PySys_GetXOptions() -> *mut PyObject; -} - +} \ No newline at end of file diff --git a/src/ffi3/traceback.rs b/src/ffi3/traceback.rs index c567472042e..201acd2303c 100644 --- a/src/ffi3/traceback.rs +++ b/src/ffi3/traceback.rs @@ -4,6 +4,7 @@ use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyTraceBack_Here(arg1: *mut ::ffi3::PyFrameObject) -> c_int; pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } @@ -11,4 +12,3 @@ use ffi3::object::*; pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } - diff --git a/src/ffi3/tupleobject.rs b/src/ffi3/tupleobject.rs index 43df59ca8da..270500b7abc 100644 --- a/src/ffi3/tupleobject.rs +++ b/src/ffi3/tupleobject.rs @@ -25,6 +25,7 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_New")] pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; pub fn PyTuple_Size(arg1: *mut PyObject) -> Py_ssize_t; pub fn PyTuple_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; @@ -32,6 +33,7 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { arg3: *mut PyObject) -> c_int; pub fn PyTuple_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Pack")] pub fn PyTuple_Pack(arg1: Py_ssize_t, ...) -> *mut PyObject; pub fn PyTuple_ClearFreeList() -> c_int; } @@ -54,4 +56,4 @@ pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { #[cfg(not(Py_LIMITED_API))] 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; -} +} \ No newline at end of file diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index ea6bc4beeab..6fe959e44b6 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -66,7 +66,9 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_AsUnicodeAndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut Py_UNICODE; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetLength")] pub fn PyUnicode_GetLength(unicode: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetSize")] pub fn PyUnicode_GetSize(unicode: *mut PyObject) -> Py_ssize_t; pub fn PyUnicode_ReadChar(unicode: *mut PyObject, index: Py_ssize_t) -> Py_UCS4; @@ -81,6 +83,8 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; errors: *const c_char) -> *mut PyObject; pub fn PyUnicode_FromObject(obj: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromFormat")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromFormatV")] //pub fn PyUnicode_FromFormatV(format: *const c_char, // vargs: va_list) -> *mut PyObject; pub fn PyUnicode_FromFormat(format: *const c_char, ...) @@ -89,10 +93,12 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_InternImmortal(arg1: *mut *mut PyObject) -> (); pub fn PyUnicode_InternFromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromWideChar")] pub fn PyUnicode_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; pub fn PyUnicode_AsWideChar(unicode: *mut PyObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideCharString")] pub fn PyUnicode_AsWideCharString(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut wchar_t; pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; @@ -327,5 +333,4 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_IsIdentifier(s: *mut PyObject) -> c_int; #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_AsUnicodeCopy(unicode: *mut PyObject) -> *mut Py_UNICODE; -} - +} \ No newline at end of file diff --git a/src/ffi3/warnings.rs b/src/ffi3/warnings.rs index 64a11c19587..086a93451db 100644 --- a/src/ffi3/warnings.rs +++ b/src/ffi3/warnings.rs @@ -6,6 +6,7 @@ use ffi3::object::PyObject; pub fn PyErr_WarnEx(category: *mut PyObject, message: *const c_char, stack_level: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WarnFormat")] pub fn PyErr_WarnFormat(category: *mut PyObject, stack_level: Py_ssize_t, format: *const c_char, ...) -> c_int; @@ -20,4 +21,3 @@ use ffi3::object::PyObject; module: *const c_char, registry: *mut PyObject) -> c_int; } - From eb99b2458335f8529bbc66aa57391a7b24e209eb Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 15:40:54 +0300 Subject: [PATCH 015/138] added pypy feature --- Cargo.toml | 3 ++ pyo3build/src/py_interpreter.rs | 70 ++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4c39362ed0..f933003b928 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,9 @@ python2 = [] # Use this feature when building python3 binding. python3 = [] +# Use this feature when building pypy binding. +pypy = [] + # Enable additional features that require nightly rust nightly = [] diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 56ba5e395e1..a98f6b1081e 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -98,11 +98,13 @@ pub fn canonicalize_executable

(exe_name: P) -> Option }) } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone)] pub struct PythonVersion { pub major: u8, // minor == None means any minor version will do pub minor: Option, + // kind = "pypy" or "cpython" are supported, default to cpython + pub kind: Option, } impl PartialEq for PythonVersion { @@ -166,10 +168,14 @@ impl InterpreterConfig { .trim_right() .to_string(); - let interpreter_version = try!(parse_interpreter_version(&lines[0])); + let (major, minor )= try!(parse_interpreter_version(&lines[0])); Ok(InterpreterConfig { - version: interpreter_version, + version: PythonVersion { + major, + minor: Some(minor), + kind: Some("cpython".to_string()) + }, path: interpreter, libpath: lines[1].to_string(), enable_shared: lines[2] == "1", @@ -179,7 +185,6 @@ impl InterpreterConfig { is_pypy: false, }) } - fn from_pypy(interpreter: PathBuf) -> Result { let script = "import sysconfig; import sys; import os;\ print(sys.version_info[0:2]); \ @@ -194,10 +199,14 @@ impl InterpreterConfig { .trim_right() .to_string(); - let interpreter_version = try!(parse_interpreter_version(&lines[0])); + let (major, minor )= try!(parse_interpreter_version(&lines[0])); Ok(InterpreterConfig { - version: interpreter_version, + version: PythonVersion { + major, + minor: Some(minor), + kind: Some("pypy".to_string()) + }, path: interpreter, libpath: lines[1].to_string(), enable_shared: true, @@ -455,13 +464,11 @@ fn get_macos_linkmodel(interpreter_path: &PathBuf) -> Result { } /// Parse string as interpreter version. -fn parse_interpreter_version(line: &str) -> Result { +fn parse_interpreter_version(line: &str) -> Result<(u8, u8), String> { let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); match version_re.captures(&line) { - Some(cap) => Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), - }), + Some(cap) => Ok((cap.get(1).unwrap().as_str().parse().unwrap(), + cap.get(2).unwrap().as_str().parse().unwrap())), None => Err(format!("Unexpected response to version query {}", line)), } } @@ -473,7 +480,6 @@ fn parse_interpreter_version(line: &str) -> Result { /// "python{major version}.{minor version}" in order until one /// is of the version we are expecting. pub fn find_interpreter(expected_version: &PythonVersion) -> Result { - // To use PyPy, a valid pypy executable must be passed to PYTHON_SYS_EXECUTABLE if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { let interpreter_path_or_executable = interpreter_from_env .to_str() @@ -498,12 +504,21 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result match kind.as_ref() { + "pypy" => "pypy", + "cpython" => "python", + other => return Err(format!("Unsupported interpreter {}", other)) + }, + None => "python" + }; + let mut possible_python_paths = vec![ - "python".to_string(), - format!("python{}", expected_version.major), + interpreter_binary_name.to_string(), + format!("{}{}", &interpreter_binary_name, expected_version.major), ]; if let Some(minor) = expected_version.minor { - possible_python_paths.push(format!("python{}.{}", expected_version.major, minor)) + possible_python_paths.push(format!("{}{}.{}", &interpreter_binary_name, expected_version.major, minor)) } for possible_path in possible_python_paths { @@ -528,9 +543,7 @@ pub fn emit_cargo_vars_from_configuration( ) -> Result { let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - if interpreter_config.is_pypy { - println!("cargo:rustc-cfg=PyPy"); - } + println!("cargo:rustc-cfg={}", interpreter_config.abi_version); if !is_extension_module || cfg!(target_os = "windows") { println!("{}", get_rustc_link_lib(&interpreter_config).unwrap()); @@ -553,11 +566,19 @@ pub fn emit_cargo_vars_from_configuration( if let PythonVersion { major: 3, minor: some_minor, + kind: ref some_kind, } = interpreter_config.version { if env::var_os("CARGO_FEATURE_PEP_384").is_some() { println!("cargo:rustc-cfg=Py_LIMITED_API"); } + + if let Some(kind) = some_kind { + if kind == "pypy" { + println!("cargo:rustc-cfg=PyPy") + } + } + if let Some(minor) = some_minor { if minor < PY3_MIN_MINOR { return Err(format!( @@ -585,6 +606,14 @@ pub fn emit_cargo_vars_from_configuration( /// version if the user doesn't care. pub fn version_from_env() -> Result { let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); + + let interpreter_kind; + if cfg!(feature="pypy") { + interpreter_kind = "pypy".to_string() + } else { + interpreter_kind = "cpython".to_string() + } + // sort env::vars so we get more explicit version specifiers first // so if the user passes e.g. the python-3 feature and the python-3-5 // feature, python-3-5 takes priority. @@ -595,6 +624,7 @@ pub fn version_from_env() -> Result { match re.captures(&key) { Some(cap) => { return Ok(PythonVersion { + kind: Some(interpreter_kind), major: cap.get(1).unwrap().as_str().parse().unwrap(), minor: match cap.get(3) { Some(s) => Some(s.as_str().parse().unwrap()), @@ -627,11 +657,13 @@ mod test { let python_version_major_only = PythonVersion { major: 3, minor: None, + kind: None }; let expected_config = InterpreterConfig { version: PythonVersion { major: 3, minor: Some(6), + kind: Some("cpython".to_string()) }, path: (canonicalize_executable("python").unwrap()), libpath: String::from("some_path"), @@ -666,6 +698,7 @@ mod test { let python_version_major_only = PythonVersion { major: 3, minor: None, + kind: None }; let interpreter = find_interpreter(&python_version_major_only).unwrap(); @@ -681,6 +714,7 @@ mod test { version: PythonVersion { major: 3, minor: Some(5), + kind: Some("pypy".to_string()) }, // We can't reliably test this unless we make some assumptions path: (canonicalize_executable("python").unwrap()), From 94426a704bc2b255948aade6b9b6213467872b11 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 15:52:39 +0300 Subject: [PATCH 016/138] removed `is_pypy` --- pyo3build/src/py_interpreter.rs | 44 ++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index a98f6b1081e..073da542fd2 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -133,8 +133,7 @@ pub struct InterpreterConfig { pub enable_shared: bool, pub ld_version: String, pub exec_prefix: String, - pub abi_version: String, - pub is_pypy: bool, + pub abi_version: String } impl InterpreterConfig { @@ -181,8 +180,7 @@ impl InterpreterConfig { enable_shared: lines[2] == "1", ld_version: lines[3].to_string(), abi_version: abi_tag, - exec_prefix: lines[4].to_string(), - is_pypy: false, + exec_prefix: lines[4].to_string() }) } fn from_pypy(interpreter: PathBuf) -> Result { @@ -212,8 +210,7 @@ impl InterpreterConfig { enable_shared: true, ld_version: "3.5".to_string(), exec_prefix: lines[2].to_string(), - abi_version: abi_tag, - is_pypy: true, + abi_version: abi_tag }) } } @@ -376,7 +373,15 @@ fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result Result { - if interpreter_config.is_pypy { + let is_pypy = match interpreter_config.version.kind { + Some(ref kind) => match kind.as_ref() { + "pypy" => true, + _ => false + }, + None => false + }; + + if is_pypy { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", 3 => "pypy3-c", @@ -401,7 +406,15 @@ fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result Result { - if interpreter_config.is_pypy { + let is_pypy = match interpreter_config.version.kind { + Some(ref kind) => match kind.as_ref() { + "pypy" => true, + _ => false + }, + None => false + }; + + if is_pypy { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", 3 => "pypy3-c", @@ -424,7 +437,15 @@ fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result Result { - if interpreter_config.is_pypy { + let is_pypy = match interpreter_config.version.kind { + Some(ref kind) => match kind.as_ref() { + "pypy" => true, + _ => false + }, + None => false + }; + + if is_pypy { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", 3 => "pypy3-c", @@ -649,7 +670,6 @@ mod test { use py_interpreter::canonicalize_executable; use py_interpreter::{find_interpreter, run_python_script, InterpreterConfig, PythonVersion}; use std::env; - use std::path::PathBuf; use py_interpreter::GET_ABI_TAG; #[test] @@ -671,7 +691,6 @@ mod test { ld_version: String::from("3.6m"), exec_prefix: String::from("some_path"), abi_version: String::from("cp36m"), - is_pypy: false, }; let interpreter = find_interpreter(&python_version_major_only).unwrap(); @@ -682,7 +701,6 @@ mod test { assert_eq!(interpreter.enable_shared, expected_config.enable_shared); assert_eq!(interpreter.ld_version, expected_config.ld_version); assert_eq!(interpreter.abi_version, expected_config.abi_version); - assert_eq!(interpreter.is_pypy, expected_config.is_pypy); } #[test] @@ -723,13 +741,11 @@ mod test { ld_version: String::from("3.5"), exec_prefix: String::from("some_path"), abi_version: String::from(abi_tag), - is_pypy: true, }; assert_eq!(interpreter.version, expected_config.version); assert_eq!(interpreter.enable_shared, expected_config.enable_shared); assert_eq!(interpreter.ld_version, expected_config.ld_version); assert_eq!(interpreter.abi_version, expected_config.abi_version); - assert_eq!(interpreter.is_pypy, expected_config.is_pypy); } } From d730494b3c5cc3934f823d8c36fd092f4767dbee Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 16:11:15 +0300 Subject: [PATCH 017/138] added pypy2 declerations also --- src/ffi2/bufferobject.rs | 8 +++++++- src/ffi2/bytesobject.rs | 3 ++- src/ffi2/ceval.rs | 5 +++-- src/ffi2/classobject.rs | 2 +- src/ffi2/cobject.rs | 9 ++++++++- src/ffi2/complexobject.rs | 5 +++-- src/ffi2/funcobject.rs | 2 +- src/ffi2/modsupport.rs | 12 +++++++++++- src/ffi2/objectabstract.rs | 16 +++++++++++++++- src/ffi2/pycapsule.rs | 14 +++++++++++++- src/ffi2/pydebug.rs | 22 ++++++++++++++++++++-- src/ffi2/pyerrors.rs | 6 ++++-- src/ffi2/pymem.rs | 3 ++- src/ffi2/rangeobject.rs | 2 +- src/ffi2/stringobject.rs | 2 +- src/ffi2/traceback.rs | 2 +- src/ffi2/tupleobject.rs | 3 ++- 17 files changed, 95 insertions(+), 21 deletions(-) diff --git a/src/ffi2/bufferobject.rs b/src/ffi2/bufferobject.rs index 868ef0d3e71..b18302f5182 100644 --- a/src/ffi2/bufferobject.rs +++ b/src/ffi2/bufferobject.rs @@ -3,6 +3,7 @@ use ffi2::object::*; use ffi2::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Type")] pub static mut PyBuffer_Type: PyTypeObject; } @@ -15,14 +16,19 @@ pub unsafe fn PyBuffer_Check(op : *mut PyObject) -> c_int { pub const Py_END_OF_BUFFER: Py_ssize_t = -1; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromObject")] pub fn PyBuffer_FromObject(base: *mut PyObject, offset: Py_ssize_t, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromReadWriteObject")] pub fn PyBuffer_FromReadWriteObject(base: *mut PyObject, offset: Py_ssize_t, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromMemory")] pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromReadWriteMemory")] pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_New")] pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject; -} +} \ No newline at end of file diff --git a/src/ffi2/bytesobject.rs b/src/ffi2/bytesobject.rs index 51d4988124e..17b0379c009 100644 --- a/src/ffi2/bytesobject.rs +++ b/src/ffi2/bytesobject.rs @@ -7,10 +7,11 @@ pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString; +#[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromFormat")] pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat; pub use ffi2::stringobject::PyString_Size as PyBytes_Size; pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString; pub use ffi2::stringobject::PyString_Concat as PyBytes_Concat; pub use ffi2::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel; pub use ffi2::stringobject::PyString_Format as PyBytes_Format; -pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; +pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; \ No newline at end of file diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 316ca0a1e38..3cb76bdda9e 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -9,8 +9,10 @@ use ffi2::pythonrun::PyCompilerFlags; pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallFunction")] pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallMethod")] pub fn PyEval_CallMethod(obj: *mut PyObject, methodname: *const c_char, format: *const c_char, ...) -> *mut PyObject; @@ -51,5 +53,4 @@ use ffi2::pythonrun::PyCompilerFlags; pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); -} - +} \ No newline at end of file diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index a11e49d1374..2f57a097689 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -52,6 +52,7 @@ pub struct PyMethodObject { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyClass_Type: PyTypeObject; pub static mut PyInstance_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Type")] pub static mut PyMethod_Type: PyTypeObject; } @@ -106,4 +107,3 @@ pub unsafe fn PyMethod_GET_SELF(meth : *mut PyObject) -> *mut PyObject { pub unsafe fn PyMethod_GET_CLASS(meth : *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_class } - diff --git a/src/ffi2/cobject.rs b/src/ffi2/cobject.rs index b655ae39a08..34045702a4e 100644 --- a/src/ffi2/cobject.rs +++ b/src/ffi2/cobject.rs @@ -2,6 +2,7 @@ use std::os::raw::{c_void, c_char, c_int}; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_Type")] pub static mut PyCObject_Type: PyTypeObject; } @@ -11,17 +12,23 @@ pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_FromVoidPtr")] pub fn PyCObject_FromVoidPtr(cobj: *mut c_void, destruct: Option) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_FromVoidPtrAndDesc")] pub fn PyCObject_FromVoidPtrAndDesc( cobj: *mut c_void, desc: *mut c_void, destruct: Option) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_AsVoidPtr")] pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_GetDesc")] pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_Import")] pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_SetVoidPtr")] pub fn PyCObject_SetVoidPtr(_self: *mut PyObject, cobj: *mut c_void) -> c_int; -} +} \ No newline at end of file diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index f0d1b9d2808..f58f420c699 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -47,11 +47,13 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromCComplex")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_AsCComplex")] pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex; @@ -59,5 +61,4 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { // format_spec: *mut c_char, // format_spec_len: Py_ssize_t) // -> *mut PyObject; -} - +} \ No newline at end of file diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index 075116a32ab..e28b61b5c19 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -2,6 +2,7 @@ use std::os::raw::c_int; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFunction_Type")] pub static mut PyFunction_Type: PyTypeObject; } @@ -31,4 +32,3 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; } - diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index c1450dbc00a..2f06c1cd804 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -5,26 +5,36 @@ use ffi2::object::PyObject; use ffi2::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_Parse")] pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTuple")] pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTupleAndKeywords")] pub fn PyArg_ParseTupleAndKeywords(args: *mut PyObject, kw: *mut PyObject, format: *const c_char, keywords: *mut *mut c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_UnpackTuple")] pub fn PyArg_UnpackTuple(args: *mut PyObject, name: *const c_char, min: Py_ssize_t, max: Py_ssize_t, ...) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BuildValue")] pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_BuildValue_SizeT")] //fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyArg_NoKeywords")] //fn _PyArg_NoKeywords(funcname: *const c_char, // kw: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddObject")] pub fn PyModule_AddObject(module: *mut PyObject, name: *const c_char, value: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddIntConstant")] pub fn PyModule_AddIntConstant(module: *mut PyObject, name: *const c_char, value: c_long) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddStringConstant")] pub fn PyModule_AddStringConstant(module: *mut PyObject, name: *const c_char, value: *const c_char) -> c_int; @@ -91,4 +101,4 @@ pub unsafe fn Py_InitModule(name: *const c_char, methods: *mut PyMethodDef) -> * #[inline(always)] 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) -} +} \ No newline at end of file diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index 96ef08ea6d6..0215115865c 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -21,21 +21,27 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ kw: *mut PyObject) -> *mut PyObject; pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunction")] pub fn PyObject_CallFunction(callable_object: *mut PyObject, format: *mut c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethod")] pub fn PyObject_CallMethod(o: *mut PyObject, m: *mut c_char, format: *mut c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_CallFunction_SizeT")] fn _PyObject_CallFunction_SizeT(callable: *mut PyObject, format: *mut c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_CallMethod_SizeT")] fn _PyObject_CallMethod_SizeT(o: *mut PyObject, name: *mut c_char, format: *mut c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunctionObjArgs")] pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethodObjArgs")] pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; @@ -54,24 +60,31 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsReadBuffer")] pub fn PyObject_AsReadBuffer(obj: *mut PyObject, buffer: *mut *const c_void, buffer_len: *mut Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsWriteBuffer")] pub fn PyObject_AsWriteBuffer(obj: *mut PyObject, buffer: *mut *mut c_void, buffer_len: *mut Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetBuffer")] pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_GetPointer")] pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_ToContiguous")] pub fn PyBuffer_ToContiguous(buf: *mut c_void, view: *mut Py_buffer, len: Py_ssize_t, fort: c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromContiguous")] pub fn PyBuffer_FromContiguous(view: *mut Py_buffer, buf: *mut c_void, len: Py_ssize_t, fort: c_char) -> c_int; @@ -88,6 +101,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ buf: *mut c_void, len: Py_ssize_t, readonly: c_int, flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; @@ -306,4 +320,4 @@ pub unsafe fn PyMapping_Values(o : *mut PyObject) -> *mut PyObject { #[inline] pub unsafe fn PyMapping_Items(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "items\0".as_ptr() as *mut i8, ptr::null_mut()) -} +} \ No newline at end of file diff --git a/src/ffi2/pycapsule.rs b/src/ffi2/pycapsule.rs index 84316530ffa..f3d4ea7a94e 100644 --- a/src/ffi2/pycapsule.rs +++ b/src/ffi2/pycapsule.rs @@ -2,6 +2,7 @@ use std::os::raw::{c_void, c_char, c_int}; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -13,24 +14,35 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_New")] pub fn PyCapsule_New(pointer: *mut c_void, name: *const c_char, destructor: Option) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetPointer")] pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_IsValid")] pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetPointer")] pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetDestructor")] pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, destructor: Option) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetName")] pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetContext")] pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Import")] pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; -} +} \ No newline at end of file diff --git a/src/ffi2/pydebug.rs b/src/ffi2/pydebug.rs index c54f77d21d6..6b51cc4827a 100644 --- a/src/ffi2/pydebug.rs +++ b/src/ffi2/pydebug.rs @@ -1,25 +1,43 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_TabcheckFlag")] pub static mut Py_TabcheckFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_UnicodeFlag")] pub static mut Py_UnicodeFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DivisionWarningFlag")] pub static mut Py_DivisionWarningFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_QnewFlag")] pub static mut _Py_QnewFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_Py3kWarningFlag")] pub static mut Py_Py3kWarningFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char); -} - +} \ No newline at end of file diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index a613ab68dd0..69eb9a37f54 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -116,13 +116,16 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub fn PyErr_SetFromErrnoWithFilename(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Format")] 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); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewException")] pub fn PyErr_NewException(name: *mut c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewExceptionWithDoc")] pub fn PyErr_NewExceptionWithDoc(name: *mut c_char, doc: *mut c_char, base: *mut PyObject, dict: *mut PyObject) @@ -212,5 +215,4 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub fn PyUnicodeTranslateError_SetReason(arg1: *mut PyObject, arg2: *const c_char) -> c_int; -} - +} \ No newline at end of file diff --git a/src/ffi2/pymem.rs b/src/ffi2/pymem.rs index 66db582acb3..ef208151f47 100644 --- a/src/ffi2/pymem.rs +++ b/src/ffi2/pymem.rs @@ -1,7 +1,8 @@ use libc::{c_void, size_t}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Malloc")] 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); -} +} \ No newline at end of file diff --git a/src/ffi2/rangeobject.rs b/src/ffi2/rangeobject.rs index 6299665678b..15d3fe175a1 100644 --- a/src/ffi2/rangeobject.rs +++ b/src/ffi2/rangeobject.rs @@ -2,6 +2,7 @@ use std::os::raw::c_int; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; } @@ -10,4 +11,3 @@ pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyRange_Type; (Py_TYPE(op) == u) as c_int } - diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index a54a816f88a..beac8b280b0 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -53,6 +53,7 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromFormat")] 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; @@ -129,4 +130,3 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { format_spec_len: Py_ssize_t) -> *mut PyObject;*/ } - diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index 71a963315ab..86b8b684b29 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -23,6 +23,7 @@ pub struct PyTracebackObject { pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } @@ -30,4 +31,3 @@ pub struct PyTracebackObject { pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } - diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index 277582077cf..94ec10156e6 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -57,7 +57,8 @@ pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObjec 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; //pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject); pub fn PyTuple_ClearFreeList() -> c_int; -} +} \ No newline at end of file From e945127e7b4017ae82b8e713bd5040ab87aeb202 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 16:31:06 +0300 Subject: [PATCH 018/138] fix for cpython2 --- build.rs | 1 + pyo3build/src/py_interpreter.rs | 1 + src/objects/exc.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index a2dea19a9e6..c12a8734ae3 100644 --- a/build.rs +++ b/build.rs @@ -25,6 +25,7 @@ fn main() { Err(_) => PythonVersion { major: 3, minor: None, + kind: None }, }; diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 073da542fd2..e06acf9e1e2 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -629,6 +629,7 @@ pub fn version_from_env() -> Result { let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); let interpreter_kind; + if cfg!(feature="pypy") { interpreter_kind = "pypy".to_string() } else { diff --git a/src/objects/exc.rs b/src/objects/exc.rs index e57f7ee2dbb..db6c80840c8 100644 --- a/src/objects/exc.rs +++ b/src/objects/exc.rs @@ -141,7 +141,7 @@ impl UnicodeDecodeError { py.from_owned_ptr_or_err( ffi::PyObject_CallFunction( ffi::PyExc_UnicodeDecodeError, - cstr!("sy#nns").as_ptr(), + cstr!("sy#nns").as_ptr() as *mut i8, encoding.as_ptr(), input.as_ptr(), input.len() as ffi::Py_ssize_t, From 1d7deca8bca8f287d4aa1f3c1df8d2f7f38342a3 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 18:31:02 +0300 Subject: [PATCH 019/138] improved libpypy detection --- build.rs | 2 +- pyo3build/src/py_interpreter.rs | 115 +++++----- src/ffi2/object.rs | 384 ++++++++++++++++++-------------- 3 files changed, 272 insertions(+), 229 deletions(-) diff --git a/build.rs b/build.rs index c12a8734ae3..46762c8a90f 100644 --- a/build.rs +++ b/build.rs @@ -33,7 +33,7 @@ fn main() { let flags = emit_cargo_vars_from_configuration(&interpreter_configuration).unwrap(); - let mut config_map = get_config_vars(&interpreter_configuration.path).unwrap(); + let mut config_map = get_config_vars(&interpreter_configuration).unwrap(); config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index e06acf9e1e2..ac363d3056a 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -133,7 +133,7 @@ pub struct InterpreterConfig { pub enable_shared: bool, pub ld_version: String, pub exec_prefix: String, - pub abi_version: String + pub abi_version: String, } impl InterpreterConfig { @@ -167,29 +167,40 @@ impl InterpreterConfig { .trim_right() .to_string(); - let (major, minor )= try!(parse_interpreter_version(&lines[0])); + let (major, minor) = try!(parse_interpreter_version(&lines[0])); Ok(InterpreterConfig { version: PythonVersion { major, minor: Some(minor), - kind: Some("cpython".to_string()) + kind: Some("cpython".to_string()), }, path: interpreter, libpath: lines[1].to_string(), enable_shared: lines[2] == "1", ld_version: lines[3].to_string(), abi_version: abi_tag, - exec_prefix: lines[4].to_string() + exec_prefix: lines[4].to_string(), }) } fn from_pypy(interpreter: PathBuf) -> Result { - let script = "import sysconfig; import sys; import os;\ - print(sys.version_info[0:2]); \ - print(os.path.join(sysconfig.get_path('data'), 'lib')); \ - print(sys.exec_prefix); - "; - + let script = "\ +import sysconfig +import sys +import os + +def get_pypy_link_lib(): + data_dir = os.path.join(sysconfig.get_path('data')) + for r, dirs, files in os.walk(data_dir): + for f in files: + if 'libpypy-c' in f or 'libpypy3-c' in f: + return os.path.dirname(os.path.join(r, f)) + raise Exception('cannot locate libpypy') + +print(sys.version_info[0:2]) +print(get_pypy_link_lib()) +print(sys.exec_prefix) +"; let out = try!(run_python_script(&interpreter, script)); let lines: Vec<&str> = out.lines().collect(); @@ -197,22 +208,32 @@ impl InterpreterConfig { .trim_right() .to_string(); - let (major, minor )= try!(parse_interpreter_version(&lines[0])); + let (major, minor) = try!(parse_interpreter_version(&lines[0])); Ok(InterpreterConfig { version: PythonVersion { major, minor: Some(minor), - kind: Some("pypy".to_string()) + kind: Some("pypy".to_string()), }, path: interpreter, libpath: lines[1].to_string(), enable_shared: true, - ld_version: "3.5".to_string(), + ld_version: format!("{}.{}", major, minor).to_string(), exec_prefix: lines[2].to_string(), - abi_version: abi_tag + abi_version: abi_tag, }) } + + fn is_pypy(&self) -> bool { + match self.version.kind { + Some(ref kind) => match kind.as_ref() { + "pypy" => true, + _ => false + }, + None => false + } + } } const CFG_KEY: &'static str = "py_sys_config"; @@ -272,7 +293,7 @@ static SYSCONFIG_FLAGS: [&'static str; 7] = [ /// the interpreter and printing variables of interest from /// sysconfig.get_config_vars. #[cfg(not(target_os = "windows"))] -pub fn get_config_vars(python_path: &PathBuf) -> Result, String> { +pub fn get_config_vars(interpreter_config: &InterpreterConfig) -> Result, String> { let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { @@ -284,7 +305,7 @@ pub fn get_config_vars(python_path: &PathBuf) -> Result, script.push_str(";"); } - let out = try!(run_python_script(python_path, &script)); + let out = try!(run_python_script(&interpreter_config.path, &script)); let split_stdout: Vec<&str> = out.trim_right().lines().collect(); if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { @@ -305,6 +326,11 @@ pub fn get_config_vars(python_path: &PathBuf) -> Result, }, ); + if interpreter_config.is_pypy() { + all_vars.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + all_vars.insert("Py_UNICODE_WIDE".to_owned(), "4".to_owned()); + }; + let debug = if let Some(val) = all_vars.get("Py_DEBUG") { val == "1" } else { @@ -320,7 +346,7 @@ pub fn get_config_vars(python_path: &PathBuf) -> Result, } #[cfg(target_os = "windows")] -pub fn get_config_vars(_: &PathBuf) -> Result, String> { +pub fn get_config_vars(_: &InterpreterConfig) -> Result, String> { // sysconfig is missing all the flags on windows, so we can't actually // query the interpreter directly for its build flags. // @@ -373,15 +399,7 @@ fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result Result { - let is_pypy = match interpreter_config.version.kind { - Some(ref kind) => match kind.as_ref() { - "pypy" => true, - _ => false - }, - None => false - }; - - if is_pypy { + if interpreter_config.is_pypy() { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", 3 => "pypy3-c", @@ -406,15 +424,7 @@ fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result Result { - let is_pypy = match interpreter_config.version.kind { - Some(ref kind) => match kind.as_ref() { - "pypy" => true, - _ => false - }, - None => false - }; - - if is_pypy { + if interpreter_config.is_pypy() { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", 3 => "pypy3-c", @@ -437,15 +447,7 @@ fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result Result { - let is_pypy = match interpreter_config.version.kind { - Some(ref kind) => match kind.as_ref() { - "pypy" => true, - _ => false - }, - None => false - }; - - if is_pypy { + if interpreter_config.is_pypy() { let link_library_name = match interpreter_config.version.major { 2 => "pypy-c", 3 => "pypy3-c", @@ -525,7 +527,7 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result match kind.as_ref() { "pypy" => "pypy", "cpython" => "python", @@ -587,19 +589,13 @@ pub fn emit_cargo_vars_from_configuration( if let PythonVersion { major: 3, minor: some_minor, - kind: ref some_kind, + kind: ref _some_kind, } = interpreter_config.version { if env::var_os("CARGO_FEATURE_PEP_384").is_some() { println!("cargo:rustc-cfg=Py_LIMITED_API"); } - if let Some(kind) = some_kind { - if kind == "pypy" { - println!("cargo:rustc-cfg=PyPy") - } - } - if let Some(minor) = some_minor { if minor < PY3_MIN_MINOR { return Err(format!( @@ -617,6 +613,11 @@ pub fn emit_cargo_vars_from_configuration( println!("cargo:rustc-cfg=Py_2"); flags += format!("CFG_Py_2,").as_ref(); } + + if interpreter_config.is_pypy() { + println!("cargo:rustc-cfg=PyPy"); + }; + return Ok(flags); } @@ -678,13 +679,13 @@ mod test { let python_version_major_only = PythonVersion { major: 3, minor: None, - kind: None + kind: None, }; let expected_config = InterpreterConfig { version: PythonVersion { major: 3, minor: Some(6), - kind: Some("cpython".to_string()) + kind: Some("cpython".to_string()), }, path: (canonicalize_executable("python").unwrap()), libpath: String::from("some_path"), @@ -711,13 +712,13 @@ mod test { env::set_var( "PYTHON_SYS_EXECUTABLE", - test_path.clone().into_os_string().into_string().unwrap() + test_path.clone().into_os_string().into_string().unwrap(), ); let python_version_major_only = PythonVersion { major: 3, minor: None, - kind: None + kind: None, }; let interpreter = find_interpreter(&python_version_major_only).unwrap(); @@ -733,7 +734,7 @@ mod test { version: PythonVersion { major: 3, minor: Some(5), - kind: Some("pypy".to_string()) + kind: Some("pypy".to_string()), }, // We can't reliably test this unless we make some assumptions path: (canonicalize_executable("python").unwrap()), diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 647ef7e07d0..796186c96d4 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -6,28 +6,58 @@ use ffi2::pyport::{Py_ssize_t, Py_hash_t}; use ffi2::methodobject::PyMethodDef; #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] +#[cfg(not(PyPy))] 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, + #[cfg(py_sys_config = "Py_TRACE_REFS")] + _ob_next: *mut PyObject, + #[cfg(py_sys_config = "Py_TRACE_REFS")] + _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, } -#[cfg(py_sys_config="Py_TRACE_REFS")] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[cfg(PyPy)] +pub struct PyObject { + pub ob_refcnt: Py_ssize_t, + pub ob_pypy_link: Py_ssize_t, + pub ob_type: *mut PyTypeObject, +} + +#[cfg(py_sys_config = "Py_TRACE_REFS")] +#[cfg(not(PyPy))] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), }; -#[cfg(not(py_sys_config="Py_TRACE_REFS"))] +#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] +#[cfg(not(PyPy))] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), +}; + +#[cfg(py_sys_config = "Py_TRACE_REFS")] +#[cfg(PyPy)] +pub const PyObject_HEAD_INIT: PyObject = PyObject { + _ob_next: ::std::ptr::null_mut(), + _ob_prev: ::std::ptr::null_mut(), + ob_refcnt: 1, + ob_pypy_link: 0, + ob_type: ::std::ptr::null_mut(), +}; + +#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] +#[cfg(PyPy)] +pub const PyObject_HEAD_INIT: PyObject = PyObject { + ob_refcnt: 1, + ob_pypy_link: 0, + ob_type: ::std::ptr::null_mut(), }; #[repr(C)] @@ -38,74 +68,74 @@ pub struct PyVarObject { } #[inline(always)] -pub unsafe fn Py_REFCNT(ob : *mut PyObject) -> Py_ssize_t { +pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { (*ob).ob_refcnt } #[inline(always)] -pub unsafe fn Py_TYPE(ob : *mut PyObject) -> *mut PyTypeObject { +pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject { (*ob).ob_type } #[inline(always)] -pub unsafe fn Py_SIZE(ob : *mut PyObject) -> Py_ssize_t { +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; +unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type binaryfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; +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; +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; +unsafe extern "C" fn(arg1: *mut PyObject) -> c_int; pub type lenfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t; +unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t; pub type coercion = - unsafe extern "C" fn (arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject) -> c_int; pub type ssizeargfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub type ssizessizeargfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: Py_ssize_t) -> *mut PyObject; pub type intobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, arg3: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut PyObject) -> c_int; pub type intintobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, - arg3: c_int, arg4: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, + arg3: c_int, arg4: *mut PyObject) -> c_int; pub type ssizeobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: *mut PyObject) -> c_int; pub type ssizessizeobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; pub type objobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> c_int; pub type getreadbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, - arg3: *mut *mut c_void) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, + arg3: *mut *mut c_void) -> c_int; pub type getwritebufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, - arg3: *mut *mut c_void) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, + arg3: *mut *mut c_void) -> c_int; pub type getsegcountproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_int) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *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; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_char) -> c_int; pub type readbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_void) -> Py_ssize_t; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: *mut *mut c_void) -> Py_ssize_t; pub type writebufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_void) -> Py_ssize_t; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: *mut *mut c_void) -> Py_ssize_t; pub type segcountproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> Py_ssize_t; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_ssize_t) -> Py_ssize_t; pub type charbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_char) -> Py_ssize_t; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: *mut *mut c_char) -> Py_ssize_t; #[repr(C)] #[derive(Copy, Clone)] @@ -125,46 +155,46 @@ pub struct Py_buffer { } pub type getbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer, - arg3: c_int) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer, + arg3: c_int) -> c_int; pub type releasebufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer); +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer); // 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_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_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_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_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); +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 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; +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; +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; +unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; #[repr(C)] @@ -212,10 +242,11 @@ pub struct PyNumberMethods { } impl Clone for PyNumberMethods { - #[inline] fn clone(&self) -> PyNumberMethods { *self } + #[inline] + fn clone(&self) -> PyNumberMethods { *self } } -pub const PyNumberMethods_INIT : PyNumberMethods = PyNumberMethods { +pub const PyNumberMethods_INIT: PyNumberMethods = PyNumberMethods { nb_add: None, nb_subtract: None, nb_multiply: None, @@ -273,10 +304,11 @@ pub struct PySequenceMethods { } impl Clone for PySequenceMethods { - #[inline] fn clone(&self) -> PySequenceMethods { *self } + #[inline] + fn clone(&self) -> PySequenceMethods { *self } } -pub const PySequenceMethods_INIT : PySequenceMethods = PySequenceMethods { +pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods { sq_length: None, sq_concat: None, sq_repeat: None, @@ -298,10 +330,11 @@ pub struct PyMappingMethods { } impl Clone for PyMappingMethods { - #[inline] fn clone(&self) -> PyMappingMethods { *self } + #[inline] + fn clone(&self) -> PyMappingMethods { *self } } -pub const PyMappingMethods_INIT : PyMappingMethods = PyMappingMethods { +pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods { mp_length: None, mp_subscript: None, mp_ass_subscript: None, @@ -319,10 +352,11 @@ pub struct PyBufferProcs { } impl Clone for PyBufferProcs { - #[inline] fn clone(&self) -> PyBufferProcs { *self } + #[inline] + fn clone(&self) -> PyBufferProcs { *self } } -pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs { +pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { bf_getreadbuffer: None, bf_getwritebuffer: None, bf_getsegcount: None, @@ -332,48 +366,48 @@ pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs { }; pub type freefunc = - unsafe extern "C" fn(arg1: *mut c_void); +unsafe extern "C" fn(arg1: *mut c_void); pub type destructor = - unsafe extern "C" fn(arg1: *mut PyObject); +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; +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; +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; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub type setattrfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_char, - arg3: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, + arg3: *mut PyObject) -> c_int; pub type setattrofunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; +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; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; pub type reprfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type hashfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; +unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; pub type richcmpfunc = - unsafe extern "C" fn (arg1: *mut PyObject, - arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject, + arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; pub type getiterfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type iternextfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type descrgetfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> *mut PyObject; pub type descrsetfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> c_int; pub type initproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; +unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> c_int; pub type newfunc = - unsafe extern "C" fn (arg1: *mut PyTypeObject, - arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyTypeObject, + arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; pub type allocfunc = - unsafe extern "C" fn (arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject; +unsafe extern "C" fn(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject; #[repr(C)] #[derive(Copy)] @@ -430,11 +464,12 @@ pub struct PyTypeObject { } impl Clone for PyTypeObject { - #[inline] fn clone(&self) -> PyTypeObject { *self } + #[inline] + fn clone(&self) -> PyTypeObject { *self } } -#[cfg(py_sys_config="Py_TRACE_REFS")] -pub const PyTypeObject_INIT : PyTypeObject = PyTypeObject { +#[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, @@ -488,8 +523,8 @@ pub const PyTypeObject_INIT : PyTypeObject = PyTypeObject { tp_version_tag: 0, }; -#[cfg(not(py_sys_config="Py_TRACE_REFS"))] -pub const PyTypeObject_INIT : PyTypeObject = PyTypeObject { +#[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, @@ -554,7 +589,8 @@ pub struct PyHeapTypeObject { } impl Clone for PyHeapTypeObject { - #[inline] fn clone(&self) -> PyHeapTypeObject { *self } + #[inline] + fn clone(&self) -> PyHeapTypeObject { *self } } // access macro to the members which are floating "behind" the object @@ -564,7 +600,8 @@ pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2: (etype as *mut u8).offset(basicsize as isize) as *mut ffi2::structmember::PyMemberDef } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } @@ -573,7 +610,8 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ (Py_TYPE(ob) == tp || PyType_IsSubtype(Py_TYPE(ob), tp) != 0) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyType_Type: PyTypeObject; pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; @@ -589,7 +627,8 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == (&mut PyType_Type as *mut _)) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, @@ -614,8 +653,9 @@ 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")] +#[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; @@ -664,99 +704,99 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { } // Flag bits for printing: -pub const Py_PRINT_RAW : c_int = 1; // No string quotes etc. +pub const Py_PRINT_RAW: c_int = 1; // No string quotes etc. // PyBufferProcs contains bf_getcharbuffer -pub const Py_TPFLAGS_HAVE_GETCHARBUFFER : c_long = (1<<0); +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); +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); +pub const Py_TPFLAGS_HAVE_INPLACEOPS: c_long = (1 << 3); // PyNumberMethods do their own coercion -pub const Py_TPFLAGS_CHECKTYPES : c_long = (1<<4); +pub const Py_TPFLAGS_CHECKTYPES: c_long = (1 << 4); // tp_richcompare is defined -pub const Py_TPFLAGS_HAVE_RICHCOMPARE : c_long = (1<<5); +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); +pub const Py_TPFLAGS_HAVE_WEAKREFS: c_long = (1 << 6); // tp_iter is defined -pub const Py_TPFLAGS_HAVE_ITER : c_long = (1<<7); +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); +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); +pub const Py_TPFLAGS_HEAPTYPE: c_long = (1 << 9); // Set if the type allows subclassing -pub const Py_TPFLAGS_BASETYPE : c_long = (1<<10); +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); +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); +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); +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; +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); +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); +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); +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); +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 | - 0); +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 | + 0); #[inline(always)] -pub unsafe fn PyType_HasFeature(t : *mut PyTypeObject, f : c_long) -> c_int { +pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_long) -> c_int { (((*t).tp_flags & f) != 0) as c_int } #[inline(always)] -pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_long) -> c_int { +pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_long) -> c_int { PyType_HasFeature(t, f) } // Reference counting macros. #[inline(always)] -pub unsafe fn Py_INCREF(op : *mut PyObject) { +pub unsafe fn Py_INCREF(op: *mut PyObject) { if cfg!(py_sys_config="Py_REF_DEBUG") { Py_IncRef(op) } else { @@ -786,20 +826,21 @@ pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) { } #[inline(always)] -pub unsafe fn Py_XINCREF(op : *mut PyObject) { +pub unsafe fn Py_XINCREF(op: *mut PyObject) { if !op.is_null() { Py_INCREF(op) } } #[inline(always)] -pub unsafe fn Py_XDECREF(op : *mut PyObject) { +pub unsafe fn Py_XDECREF(op: *mut PyObject) { if !op.is_null() { Py_DECREF(op) } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); @@ -818,12 +859,12 @@ pub unsafe fn Py_NotImplemented() -> *mut PyObject { } /* 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; +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 { @@ -835,15 +876,16 @@ pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int { 0 } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { fn _PyTrash_thread_deposit_object(o: *mut PyObject); fn _PyTrash_thread_destroy_chain(); } -pub const PyTrash_UNWIND_LEVEL : c_int = 50; +pub const PyTrash_UNWIND_LEVEL: c_int = 50; #[inline(always)] -pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { +pub unsafe fn Py_TRASHCAN ()>(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() { From 1fe3f75e03ad093d5504d4019d296b665abcb3a6 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 18:46:16 +0300 Subject: [PATCH 020/138] added all pypy2 macros --- src/ffi2/boolobject.rs | 7 ++- src/ffi2/bytearrayobject.rs | 11 ++++- src/ffi2/cellobject.rs | 3 +- src/ffi2/ceval.rs | 16 +++++++ src/ffi2/classobject.rs | 7 ++- src/ffi2/code.rs | 7 ++- src/ffi2/complexobject.rs | 6 +++ src/ffi2/descrobject.rs | 13 ++++-- src/ffi2/dictobject.rs | 22 ++++++++- src/ffi2/eval.rs | 3 +- src/ffi2/fileobject.rs | 12 ++++- src/ffi2/floatobject.rs | 10 +++- src/ffi2/frameobject.rs | 2 +- src/ffi2/funcobject.rs | 7 ++- src/ffi2/genobject.rs | 5 +- src/ffi2/import.rs | 13 +++++- src/ffi2/iterobject.rs | 4 +- src/ffi2/listobject.rs | 18 +++++++- src/ffi2/longobject.rs | 28 ++++++++++- src/ffi2/memoryobject.rs | 7 ++- src/ffi2/methodobject.rs | 8 +++- src/ffi2/mod.rs | 4 +- src/ffi2/moduleobject.rs | 7 ++- src/ffi2/object.rs | 39 +++++++++++++++- src/ffi2/objectabstract.rs | 92 +++++++++++++++++++++++++++++++++++++ src/ffi2/objimpl.rs | 5 +- src/ffi2/pyerrors.rs | 66 ++++++++++++++++++++++++++ src/ffi2/pystate.rs | 15 ++++-- src/ffi2/pythonrun.rs | 15 +++++- src/ffi2/setobject.rs | 19 +++++++- src/ffi2/sliceobject.rs | 9 +++- src/ffi2/traceback.rs | 5 +- src/ffi2/tupleobject.rs | 6 +++ src/ffi2/unicodeobject.rs | 12 ++++- src/ffi2/warnings.rs | 4 +- src/ffi2/weakrefobject.rs | 11 ++++- 36 files changed, 465 insertions(+), 53 deletions(-) diff --git a/src/ffi2/boolobject.rs b/src/ffi2/boolobject.rs index 1ea79af49b5..36887a88730 100644 --- a/src/ffi2/boolobject.rs +++ b/src/ffi2/boolobject.rs @@ -5,13 +5,18 @@ use ffi2::intobject::PyIntObject; pub type PyBoolObject = PyIntObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_ZeroStruct")] static mut _Py_ZeroStruct: PyIntObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_TrueStruct")] static mut _Py_TrueStruct: PyIntObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Check")] pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyBool_Type; (Py_TYPE(op) == u) as c_int @@ -25,4 +30,4 @@ pub unsafe fn Py_False() -> *mut PyObject { #[inline(always)] pub unsafe fn Py_True() -> *mut PyObject { &mut _Py_TrueStruct as *mut PyBoolObject as *mut PyObject -} +} \ No newline at end of file diff --git a/src/ffi2/bytearrayobject.rs b/src/ffi2/bytearrayobject.rs index a5c529010f5..45cceaf919c 100644 --- a/src/ffi2/bytearrayobject.rs +++ b/src/ffi2/bytearrayobject.rs @@ -18,27 +18,36 @@ struct PyByteArrayObject { }*/ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } +#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Check")] pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyByteArray_Type) } +#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_CheckExact")] 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" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Concat")] pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromStringAndSize")] pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Resize")] pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; } @@ -55,4 +64,4 @@ pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char { 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) -} +} \ No newline at end of file diff --git a/src/ffi2/cellobject.rs b/src/ffi2/cellobject.rs index 3edb4e5742a..3fcea485d78 100644 --- a/src/ffi2/cellobject.rs +++ b/src/ffi2/cellobject.rs @@ -15,6 +15,7 @@ struct PyCellObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCell_Type")] pub static mut PyCell_Type: PyTypeObject; } @@ -37,4 +38,4 @@ pub unsafe fn PyCell_GET(op: *mut PyObject) -> *mut PyObject { #[inline(always)] pub unsafe fn PyCell_SET(op: *mut PyObject, obj: *mut PyObject) { (*(op as *mut PyCellObject)).ob_ref = obj; -} +} \ No newline at end of file diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 3cb76bdda9e..7339c99a2a3 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -6,6 +6,7 @@ use ffi2::pystate::{PyThreadState, Py_tracefunc}; use ffi2::pythonrun::PyCompilerFlags; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallObjectWithKeywords")] pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; @@ -18,18 +19,26 @@ use ffi2::pythonrun::PyCompilerFlags; format: *const c_char, ...) -> *mut PyObject; pub fn PyEval_SetProfile(func: Option, obj: *mut PyObject); pub fn PyEval_SetTrace(func: Option, obj: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut PyFrameObject; pub fn PyEval_GetRestricted() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_MergeCompilerFlags")] pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int; pub fn Py_FlushLine() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AddPendingCall")] pub fn Py_AddPendingCall(func: Option c_int>, arg: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; @@ -38,19 +47,26 @@ use ffi2::pythonrun::PyCompilerFlags; 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState); + #[cfg_attr(PyPy, link_name="\u{1}__PyPyEval_SliceIndex")] 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" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_InitThreads")] pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); pub fn PyEval_ReleaseLock(); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); } \ No newline at end of file diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index 2f57a097689..7d53e86f4c8 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -50,6 +50,7 @@ pub struct PyMethodObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyClass_Type")] pub static mut PyClass_Type: PyTypeObject; pub static mut PyInstance_Type: PyTypeObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Type")] @@ -69,6 +70,7 @@ pub unsafe fn PyInstance_Check(op : *mut PyObject) -> c_int { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Check")] pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyMethod_Type; (Py_TYPE(op) == u) as c_int @@ -81,9 +83,12 @@ pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { arg3: *mut PyObject) -> *mut PyObject; pub fn PyInstance_NewRaw(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_New")] pub fn PyMethod_New(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Function")] pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Self")] 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) @@ -106,4 +111,4 @@ pub unsafe fn PyMethod_GET_SELF(meth : *mut PyObject) -> *mut PyObject { #[inline(always)] pub unsafe fn PyMethod_GET_CLASS(meth : *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_class -} +} \ No newline at end of file diff --git a/src/ffi2/code.rs b/src/ffi2/code.rs index 0402e8ef35b..c826c11850b 100644 --- a/src/ffi2/code.rs +++ b/src/ffi2/code.rs @@ -54,6 +54,7 @@ pub const CO_MAXBLOCKS : usize = 20; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyCode_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_New")] pub fn PyCode_New(arg1: c_int, arg2: c_int, arg3: c_int, arg4: c_int, arg5: *mut PyObject, arg6: *mut PyObject, @@ -62,11 +63,13 @@ pub const CO_MAXBLOCKS : usize = 20; arg11: *mut PyObject, arg12: *mut PyObject, arg13: c_int, arg14: *mut PyObject) -> *mut PyCodeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_NewEmpty")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_Check")] //fn _PyCode_CheckLineNumber(co: *mut PyCodeObject, // lasti: c_int, // bounds: *mut PyAddrPair) -> c_int; @@ -81,7 +84,7 @@ pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_GetNumFree")] pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { ::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) -} - +} \ No newline at end of file diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index f58f420c699..9e18108c447 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -32,15 +32,18 @@ pub struct PyComplexObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Check")] pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_CheckExact")] pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyComplex_Type; (Py_TYPE(op) == u) as c_int @@ -49,9 +52,12 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromDoubles")] pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_AsCComplex")] pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex; diff --git a/src/ffi2/descrobject.rs b/src/ffi2/descrobject.rs index 6a06c56ced5..02c85019c73 100644 --- a/src/ffi2/descrobject.rs +++ b/src/ffi2/descrobject.rs @@ -61,14 +61,20 @@ impl Clone for wrapperbase { pub const PyWrapperFlag_KEYWORDS : c_int = 1; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDescr_NewClassMethod")] pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; pub fn PyDescr_NewMember(arg1: *mut PyTypeObject, @@ -86,12 +92,9 @@ pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_New")] //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; -} - - - - +} \ No newline at end of file diff --git a/src/ffi2/dictobject.rs b/src/ffi2/dictobject.rs index 57263ac2bb0..bd9fc679849 100644 --- a/src/ffi2/dictobject.rs +++ b/src/ffi2/dictobject.rs @@ -5,6 +5,7 @@ use ffi2::object::*; //pub enum PyDictObject { /* representation hidden */ } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Type")] pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -26,30 +27,46 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_New")] pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Contains")] pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItem")] pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItemString")] pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItemString")] pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItemString")] pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Next")] pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; @@ -60,12 +77,13 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { hash: c_long) -> c_int; pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/ + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Update")] pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Merge")] 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; -} - +} \ No newline at end of file diff --git a/src/ffi2/eval.rs b/src/ffi2/eval.rs index 4a2660f78e7..263d2c26a5b 100644 --- a/src/ffi2/eval.rs +++ b/src/ffi2/eval.rs @@ -3,6 +3,7 @@ use ffi2::object::PyObject; use ffi2::code::PyCodeObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_EvalCode")] 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, @@ -13,4 +14,4 @@ use ffi2::code::PyCodeObject; -> *mut PyObject; fn _PyEval_CallTracing(func: *mut PyObject, args: *mut PyObject) -> *mut PyObject; -} +} \ No newline at end of file diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index 6838ca3e723..bae27bec8a5 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -8,6 +8,7 @@ use ffi2::object::*; #[inline(always)] pub unsafe fn PyFile_Check(op : *mut PyObject) -> c_int { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] PyObject_TypeCheck(op, &mut PyFile_Type) } @@ -20,8 +21,10 @@ pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int { pub const PY_STDIOTEXTMODE : &'static str = "b"; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_FromString")] pub fn PyFile_FromString(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_SetBufSize")] pub fn PyFile_SetBufSize(arg1: *mut PyObject, arg2: c_int); pub fn PyFile_SetEncoding(arg1: *mut PyObject, arg2: *const c_char) -> c_int; @@ -29,6 +32,7 @@ pub const PY_STDIOTEXTMODE : &'static str = "b"; arg2: *const c_char, errors: *mut c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_FromFile")] pub fn PyFile_FromFile(arg1: *mut FILE, arg2: *mut c_char, arg3: *mut c_char, arg4: Option c_int>) @@ -36,15 +40,20 @@ pub const PY_STDIOTEXTMODE : &'static str = "b"; pub fn PyFile_AsFile(arg1: *mut PyObject) -> *mut FILE; //pub fn PyFile_IncUseCount(arg1: *mut PyFileObject); //pub fn PyFile_DecUseCount(arg1: *mut PyFileObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_Name")] pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_GetLine")] pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteObject")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteString")] pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsFileDescriptor")] pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int; pub fn Py_UniversalNewlineFgets(arg1: *mut c_char, arg2: c_int, arg3: *mut FILE, @@ -55,5 +64,4 @@ pub const PY_STDIOTEXTMODE : &'static str = "b"; -> size_t; pub static mut Py_FileSystemDefaultEncoding: *const c_char; -} - +} \ No newline at end of file diff --git a/src/ffi2/floatobject.rs b/src/ffi2/floatobject.rs index faa0688b47f..f45bc7332c5 100644 --- a/src/ffi2/floatobject.rs +++ b/src/ffi2/floatobject.rs @@ -15,15 +15,18 @@ struct PyFloatObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Check")] pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_CheckExact")] pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyFloat_Type; (Py_TYPE(op) == u) as c_int @@ -32,10 +35,13 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { pub const PyFloat_STR_PRECISION : c_int = 12; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromString")] pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; @@ -44,7 +50,7 @@ pub const PyFloat_STR_PRECISION : c_int = 12; pub fn PyFloat_ClearFreeList() -> c_int; } +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_AS_DOUBLE")] pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double { (*(pyfloat as *mut PyFloatObject)).ob_fval -} - +} \ No newline at end of file diff --git a/src/ffi2/frameobject.rs b/src/ffi2/frameobject.rs index 004b5440655..69656813f39 100644 --- a/src/ffi2/frameobject.rs +++ b/src/ffi2/frameobject.rs @@ -67,6 +67,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { //} #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrame_New")] pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; @@ -79,4 +80,3 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { pub fn PyFrame_ClearFreeList() -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; } - diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index e28b61b5c19..a002b68b6e3 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -7,6 +7,7 @@ use ffi2::object::*; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFunction_Check")] pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyFunction_Type; (Py_TYPE(op) == u) as c_int @@ -16,6 +17,7 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFunction_GetCode")] 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; @@ -27,8 +29,11 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { -> c_int; pub static mut PyClassMethod_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyStaticMethod_Type")] pub static mut PyStaticMethod_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyClassMethod_New")] pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyStaticMethod_New")] pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; -} +} \ No newline at end of file diff --git a/src/ffi2/genobject.rs b/src/ffi2/genobject.rs index 9dd8f2cc3d0..cba10c25a15 100644 --- a/src/ffi2/genobject.rs +++ b/src/ffi2/genobject.rs @@ -23,11 +23,13 @@ pub struct PyGenObject { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } @@ -35,5 +37,4 @@ pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> 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; -} - +} \ No newline at end of file diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index 9b0b7b9eda2..6ade24adcd9 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -21,6 +21,8 @@ pub struct PyImport_Struct_frozen { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_Import")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModule")] pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, globals: *mut PyObject, locals: *mut PyObject, @@ -31,6 +33,7 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleNoBlock")] pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; pub fn PyImport_ImportModuleLevel(name: *mut c_char, @@ -40,16 +43,21 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, level: c_int) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModule")] pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModuleEx")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_ImportFrozenModule(name: *mut c_char) -> c_int; @@ -66,7 +74,9 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, /*for internal use only: pub fn PyImport_Cleanup(); + #[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_AcquireLock")] pub fn _PyImport_AcquireLock(); + #[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_ReleaseLock")] pub fn _PyImport_ReleaseLock() -> c_int; pub fn _PyImport_FindModule(arg1: *const c_char, arg2: *mut PyObject, @@ -82,5 +92,4 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, pub fn _PyImport_FixupExtension(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject;*/ -} - +} \ No newline at end of file diff --git a/src/ffi2/iterobject.rs b/src/ffi2/iterobject.rs index 45bd06a644b..f0433ef9e26 100644 --- a/src/ffi2/iterobject.rs +++ b/src/ffi2/iterobject.rs @@ -5,7 +5,9 @@ use ffi2::object::*; pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallIter_New")] pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } @@ -18,4 +20,4 @@ pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int { #[inline(always)] pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCallIter_Type) as c_int -} +} \ No newline at end of file diff --git a/src/ffi2/listobject.rs b/src/ffi2/listobject.rs index 2724e4e6e36..805ce266d54 100644 --- a/src/ffi2/listobject.rs +++ b/src/ffi2/listobject.rs @@ -17,6 +17,7 @@ pub struct PyListObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; } @@ -34,41 +35,54 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { // Macro, trading safety for speed #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_ITEM")] 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(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_SIZE")] 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(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SET_ITEM")] pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { *(*(op as *mut PyListObject)).ob_item.offset(i as isize) = v; } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Size")] pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetItem")] pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetItem")] pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Insert")] pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Append")] pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetSlice")] pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetSlice")] pub fn PyList_SetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t, itemlist: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Sort")] pub fn PyList_Sort(list: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Reverse")] pub fn PyList_Reverse(list: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_AsTuple")] pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject; //fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) //-> *mut PyObject; -} - +} \ No newline at end of file diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 3d13c58b94a..44a7a56687a 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -7,6 +7,7 @@ use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } @@ -22,38 +23,59 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLong")] pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLongLong")] pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromDouble")] pub fn PyLong_FromDouble(v: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromString")] 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")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnicode")] pub fn PyLong_FromUnicode(u: *mut ::ffi2::unicodeobject::Py_UNICODE, length: Py_ssize_t, base: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLong")] pub fn PyLong_AsLong(pylong: *mut PyObject) -> c_long; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongAndOverflow")] pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLong")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLongAndOverflow")] pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLong")] pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLongMask")] pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsDouble")] pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void; pub fn PyLong_GetInfo() -> *mut PyObject; @@ -63,8 +85,11 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { pub fn _PyLong_Frexp(a: *mut PyLongObject, e: *mut Py_ssize_t) -> c_double; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_Sign")] pub fn _PyLong_Sign(v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_NumBits")] pub fn _PyLong_NumBits(v: *mut PyObject) -> size_t; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_FromByteArray")] pub fn _PyLong_FromByteArray(bytes: *const c_uchar, n: size_t, little_endian: c_int, is_signed: c_int) -> *mut PyObject; @@ -79,5 +104,4 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { format_spec: *mut c_char, format_spec_len: Py_ssize_t) -> *mut PyObject;*/ -} - +} \ No newline at end of file diff --git a/src/ffi2/memoryobject.rs b/src/ffi2/memoryobject.rs index 4fded996378..6d6487ab636 100644 --- a/src/ffi2/memoryobject.rs +++ b/src/ffi2/memoryobject.rs @@ -3,10 +3,12 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Check")] pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyMemoryView_Type; (Py_TYPE(op) == u) as c_int @@ -27,7 +29,9 @@ pub unsafe fn PyMemoryView_GET_BASE(op : *mut PyObject) -> *mut PyObject { pub fn PyMemoryView_GetContiguous(base: *mut PyObject, buffertype: c_int, fort: c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromBuffer")] pub fn PyMemoryView_FromBuffer(info: *mut Py_buffer) -> *mut PyObject; } @@ -42,5 +46,4 @@ pub struct PyMemoryViewObject { pub ob_type: *mut PyTypeObject, pub base: *mut PyObject, pub view: Py_buffer, -} - +} \ No newline at end of file diff --git a/src/ffi2/methodobject.rs b/src/ffi2/methodobject.rs index 282ad062b09..3d5ace9f1a5 100644 --- a/src/ffi2/methodobject.rs +++ b/src/ffi2/methodobject.rs @@ -3,10 +3,12 @@ use std::os::raw::{c_char, c_int}; use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Check")] pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyCFunction_Type; (Py_TYPE(op) == u) as c_int @@ -26,6 +28,7 @@ pub type PyNoArgsFunction = #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; @@ -99,8 +102,10 @@ struct PyCFunctionObject { */ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FindMethod")] pub fn Py_FindMethod(methods: *mut PyMethodDef, slf: *mut PyObject, name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] 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, @@ -111,5 +116,4 @@ struct PyCFunctionObject { #[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { PyCFunction_NewEx(ml, slf, ptr::null_mut()) -} - +} \ No newline at end of file diff --git a/src/ffi2/mod.rs b/src/ffi2/mod.rs index 099a33023c0..88c25d5395b 100644 --- a/src/ffi2/mod.rs +++ b/src/ffi2/mod.rs @@ -133,8 +133,10 @@ pub const Py_eval_input: c_int = 258; #[cfg(not(py_sys_config="Py_USING_UNICODE"))] #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Check")] pub fn PyUnicode_Check(op : *mut PyObject) -> libc::c_int { 0 } #[cfg(not(py_sys_config="Py_USING_UNICODE"))] #[inline(always)] -pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 } +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CheckExact")] +pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 } \ No newline at end of file diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index 14da5f46548..58acd259369 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -4,10 +4,12 @@ use ffi2::object::*; use ffi2::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Check")] pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } @@ -18,9 +20,12 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_New")] pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDict")] pub fn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetName")] 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; @@ -90,4 +95,4 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { m_traverse: None, m_clear: None, m_free: None -}; +}; \ No newline at end of file diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 796186c96d4..5d3a49ff3b4 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -602,17 +602,21 @@ pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2: #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_IsSubtype")] pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] 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" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; } @@ -629,26 +633,34 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericNew")] pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyType_Lookup")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int; fn _PyObject_Dump(o: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Str")] fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Bytes")] pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { PyObject_Str(o) } @@ -656,37 +668,56 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(py_sys_config = "Py_USING_UNICODE")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Unicode")] pub fn PyObject_Unicode(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Compare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompare")] pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompareBool")] pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttr")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttrString")] pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] pub fn PyObject_SetAttrString(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttr")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttrString")] 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; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericSetAttr")] pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallable_Check")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_ClearWeakRefs")] pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject); fn _PyObject_SlotCompare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; fn _PyObject_GenericGetAttrWithDict(arg1: *mut PyObject, @@ -696,10 +727,13 @@ extern "C" { arg2: *mut PyObject, arg3: *mut PyObject, arg4: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Dir")] 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); + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_HashDouble")] fn _Py_HashDouble(arg1: c_double) -> c_long; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_HashPointer")] fn _Py_HashPointer(arg1: *mut c_void) -> c_long; } @@ -844,7 +878,9 @@ extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } @@ -901,5 +937,4 @@ pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { } else { _PyTrash_thread_deposit_object(op) } -} - +} \ No newline at end of file diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index 0215115865c..8c6d0c71e7c 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -5,7 +5,11 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttr")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } @@ -17,8 +21,10 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject, result: *mut c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Call")] pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, kw: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallObject")] pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunction")] @@ -44,18 +50,25 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethodObjArgs")] pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_LengthHint")] pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetItem")] pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetItem")] pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelItem")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsCharBuffer")] pub fn PyObject_AsCharBuffer(obj: *mut PyObject, buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t) @@ -90,6 +103,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ fort: c_char) -> c_int; pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_IsContiguous")] pub fn PyBuffer_IsContiguous(view: *mut Py_buffer, fort: c_char) -> c_int; pub fn PyBuffer_FillContiguousStrides(ndims: c_int, @@ -97,138 +111,205 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ strides: *mut Py_ssize_t, itemsize: c_int, fort: c_char); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FillInfo")] 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; #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Format")] pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Add")] pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Subtract")] pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Multiply")] pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Divide")] pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_FloorDivide")] pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_TrueDivide")] pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Remainder")] pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Divmod")] pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Power")] pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Lshift")] pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Rshift")] pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_And")] pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Xor")] pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_AsSsize_t")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAdd")] pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceSubtract")] pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceMultiply")] pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceDivide")] pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceFloorDivide")] pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceTrueDivide")] pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRemainder")] pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlacePower")] pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceLshift")] pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRshift")] pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAnd")] pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceXor")] pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceOr")] pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Length")] pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Concat")] pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Repeat")] pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetItem")] pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetSlice")] pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetItem")] pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelItem")] pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetSlice")] pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelSlice")] pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Contains")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Index")] pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceConcat")] pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceRepeat")] pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Length")] pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKey")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKeyString")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_GetItemString")] pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_SetItemString")] pub fn PyMapping_SetItemString(o: *mut PyObject, key: *mut c_char, value: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsInstance")] pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsSubclass")] pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } @@ -245,6 +326,7 @@ pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int { #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Check")] pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; (PyType_HasFeature(t, Py_TPFLAGS_HAVE_ITER) != 0 && @@ -255,6 +337,7 @@ pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyIndex_Check")] pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let n = (*t).tp_as_number; @@ -262,8 +345,10 @@ pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast_GET_SIZE")] pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { if ffi2::listobject::PyList_Check(o) != 0 { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_SIZE")] ffi2::listobject::PyList_GET_SIZE(o) } else { ffi2::tupleobject::PyTuple_GET_SIZE(o) @@ -271,8 +356,10 @@ pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast_GET_ITEM")] pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_ITEM")] ffi2::listobject::PyList_GET_ITEM(o, i) } else { ffi2::tupleobject::PyTuple_GET_ITEM(o, i) @@ -280,6 +367,7 @@ pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mu } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast_ITEMS")] 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 @@ -289,6 +377,7 @@ pub unsafe fn PySequence_Fast_ITEMS(o : *mut PyObject) -> *mut *mut PyObject { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_ITEM")] 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) } @@ -308,16 +397,19 @@ pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Keys")] pub unsafe fn PyMapping_Keys(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "keys\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Values")] pub unsafe fn PyMapping_Values(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "values\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Items")] pub unsafe fn PyMapping_Items(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "items\0".as_ptr() as *mut i8, ptr::null_mut()) } \ No newline at end of file diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index aac600257e1..5691f06e85c 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -4,7 +4,9 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Malloc")] pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Realloc")] pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; pub fn PyObject_Free(arg1: *mut c_void); @@ -59,5 +61,4 @@ pub unsafe fn PyType_SUPPORTS_WEAKREFS(t : *mut PyTypeObject) -> c_int { 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 -} - +} \ No newline at end of file diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index 69eb9a37f54..c457fbc9c02 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -7,18 +7,28 @@ use ffi2::stringobject::PyString_AS_STRING; use ffi2::unicodeobject::Py_UNICODE; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetString")] pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Clear")] pub fn PyErr_Clear(); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Fetch")] pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_GivenExceptionMatches")] pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NormalizeException")] pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject); @@ -46,6 +56,7 @@ pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { if PyInstance_Check(x) != 0 { (*(x as *mut PyInstanceObject)).in_class as *mut PyObject @@ -55,61 +66,112 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; pub static mut PyExc_StandardError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; pub static mut PyExc_MemoryErrorInst: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RecursionError")] pub static mut PyExc_RecursionErrorInst: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilename")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; @@ -119,6 +181,7 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Format")] pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall(); pub fn _PyErr_BadInternalCall(filename: *mut c_char, lineno: c_int); @@ -130,8 +193,11 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { doc: *mut c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; pub fn PyErr_SyntaxLocation(arg1: *const c_char, diff --git a/src/ffi2/pystate.rs b/src/ffi2/pystate.rs index 7577ef8184c..648bf7d0a08 100644 --- a/src/ffi2/pystate.rs +++ b/src/ffi2/pystate.rs @@ -60,30 +60,41 @@ pub enum PyGILState_STATE { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Get")] //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); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_New")] 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); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState); #[cfg(py_sys_config="WITH_THREAD")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent(); pub fn PyThreadState_Get() -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; fn _PyThread_CurrentFrames() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyInterpreterState_Next")] pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) -> *mut PyInterpreterState; pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) @@ -101,6 +112,4 @@ pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { #[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { _PyThreadState_Current -} - - +} \ No newline at end of file diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index e28b68ec1e6..968da83c468 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -27,12 +27,14 @@ pub enum Struct_symtable { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetProgramName")] 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(); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IsInitialized")] pub fn Py_IsInitialized() -> c_int; pub fn Py_NewInterpreter() -> *mut PyThreadState; pub fn Py_EndInterpreter(arg1: *mut PyThreadState); @@ -41,6 +43,7 @@ pub enum Struct_symtable { } pub fn PyRun_AnyFileExFlags(arg1: *mut FILE, arg2: *const c_char, arg3: c_int, arg4: *mut PyCompilerFlags) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_SimpleString")] pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int; @@ -78,13 +81,17 @@ pub enum Struct_symtable { } arg3: c_int, arg4: c_int) -> *mut Struct__node; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_String")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_StringFlags")] pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int, arg3: *mut PyObject, arg4: *mut PyObject, arg5: *mut PyCompilerFlags) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_File")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_CompileStringFlags")] pub fn Py_CompileStringFlags(arg1: *const c_char, arg2: *const c_char, arg3: c_int, @@ -92,10 +99,14 @@ pub enum Struct_symtable { } pub fn Py_SymtableString(arg1: *const c_char, arg2: *const c_char, arg3: c_int) -> *mut Struct_symtable; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Print")] pub fn PyErr_Print(); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Display")] pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AtExit")] pub fn Py_AtExit(func: Option) -> c_int; pub fn Py_Exit(arg1: c_int); @@ -107,6 +118,7 @@ pub enum Struct_symtable { } pub fn Py_GetPrefix() -> *mut c_char; pub fn Py_GetExecPrefix() -> *mut c_char; pub fn Py_GetPath() -> *mut c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; @@ -117,5 +129,4 @@ pub enum Struct_symtable { } pub fn Py_SubversionShortBranch() -> *const c_char; fn _Py_hgidentifier() -> *const c_char; fn _Py_hgversion() -> *const c_char; -} - +} \ No newline at end of file diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index fbd2ece25f5..959f65dad16 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -5,17 +5,23 @@ use ffi2::object::*; //enum PySetObject { /* representation hidden */ } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Check")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_CheckExact")] 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] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_Check")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_CheckExact")] pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { let s : *mut PyTypeObject = &mut PySet_Type; let f : *mut PyTypeObject = &mut PyFrozenSet_Type; @@ -25,11 +31,13 @@ pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { #[inline] pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { (PyAnySet_CheckExact(ob) != 0 || + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_IsSubtype")] PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Check")] 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 @@ -42,22 +50,29 @@ pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_New")] pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_New")] pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Contains")] pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Discard")] pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Add")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; //pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) // -> c_int; -} - +} \ No newline at end of file diff --git a/src/ffi2/sliceobject.rs b/src/ffi2/sliceobject.rs index c458fa51482..4830c2b52f6 100644 --- a/src/ffi2/sliceobject.rs +++ b/src/ffi2/sliceobject.rs @@ -3,6 +3,7 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -26,25 +27,29 @@ pub struct PySliceObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Check")] 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" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_New")] pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject, step: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndices")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndicesEx")] 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; -} - +} \ No newline at end of file diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index 86b8b684b29..dba9c2c6e58 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -19,7 +19,9 @@ pub struct PyTracebackObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; @@ -28,6 +30,7 @@ pub struct PyTracebackObject { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Check")] pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int -} +} \ No newline at end of file diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index 94ec10156e6..6293365e837 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -16,6 +16,7 @@ pub struct PyTupleObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; } @@ -50,12 +51,17 @@ pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObjec #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Size")] pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetItem")] pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_SetItem")] pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetSlice")] pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyTuple_Resize")] pub fn _PyTuple_Resize(p: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int; #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index 32503fcb0cc..13eb54c7cc2 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -31,15 +31,18 @@ pub struct PyUnicodeObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Check")] pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CheckExact")] pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyUnicode_Type; (Py_TYPE(op) == u) as c_int @@ -86,6 +89,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] fn _PyUnicode_FormatAdvanced(obj: *mut PyObject, format_spec: *mut Py_UNICODE, format_spec_len: Py_ssize_t) -> *mut PyObject; @@ -112,6 +116,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; encoding: *const c_char, errors: *const c_char) -> *mut PyObject; fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] fn PyUnicode_DecodeUTF7(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -460,6 +465,8 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject { PyUnicodeUCS4_FromStringAndSize(u, size) } @@ -472,6 +479,8 @@ pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS4_AsUTF8String(u) } @@ -484,6 +493,7 @@ pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject { @@ -496,4 +506,4 @@ pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject { PyUnicodeUCS2_FromEncodedObject(obj, encoding, errors) -} +} \ No newline at end of file diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index a609b0e8512..7d5a6c04611 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -3,6 +3,8 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Warn")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WarnEx")] pub fn PyErr_WarnEx(category: *mut PyObject, msg: *const c_char, stacklevel: Py_ssize_t) -> c_int; pub fn PyErr_WarnExplicit(arg1: *mut PyObject, @@ -16,4 +18,4 @@ use ffi2::object::PyObject; #[inline] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) -} +} \ No newline at end of file diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index f13714d08af..03898f32419 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -25,16 +25,20 @@ pub struct PyWeakReference { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_Check")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckProxy")] 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 @@ -46,10 +50,13 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewRef")] pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewProxy")] pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_GetObject")] pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject; pub fn _PyWeakref_GetWeakrefCount(head: *mut PyWeakReference) -> Py_ssize_t; @@ -57,8 +64,8 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_GET_OBJECT")] 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() } -} - +} \ No newline at end of file From 2ffa0ff97aad07f217e9b1670c65631bb628eba6 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 18:47:01 +0300 Subject: [PATCH 021/138] fixed errneous type --- src/ffi2/setobject.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index 959f65dad16..e33fabe5ac8 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -31,7 +31,6 @@ pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { #[inline] pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { (PyAnySet_CheckExact(ob) != 0 || - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_IsSubtype")] PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int } From 007559384fe6939c6627ccc36ce48235804652da Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 19:02:32 +0300 Subject: [PATCH 022/138] more fixes --- pyo3build/src/py_interpreter.rs | 3 ++- src/ffi2/classobject.rs | 2 ++ src/ffi2/object.rs | 6 +++--- src/ffi2/stringobject.rs | 6 ++++++ src/ffi2/unicodeobject.rs | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index ac363d3056a..ebadf0d2bd1 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -328,7 +328,8 @@ pub fn get_config_vars(interpreter_config: &InterpreterConfig) -> Result c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttr")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttrString")] pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] pub fn PyObject_SetAttrString(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttr")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttrString")] pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttr")] pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttr")] pub fn PyObject_HasAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index beac8b280b0..81e96726435 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -50,12 +50,16 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromString")] pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromStringAndSize")] pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromFormat")] pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_Size")] pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_AsString")] pub fn PyString_AsString(string: *mut PyObject) -> *mut c_char; pub fn PyString_AsStringAndSize(obj: *mut PyObject, s: *mut *mut c_char, @@ -70,12 +74,14 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { pub fn PyString_Decode(s: *const c_char, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_AsDecodedObject")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_AsEncodedObject")] pub fn PyString_AsEncodedObject(str: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index 13eb54c7cc2..767d764177e 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -89,7 +89,6 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] fn _PyUnicode_FormatAdvanced(obj: *mut PyObject, format_spec: *mut Py_UNICODE, format_spec_len: Py_ssize_t) -> *mut PyObject; @@ -238,6 +237,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] 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, From aa5cc32ef6663acb53c53dee04d9eca3dd4f592a Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 19:07:29 +0300 Subject: [PATCH 023/138] fix python2 string macros --- src/ffi2/unicodeobject.rs | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index 767d764177e..e8e19f9dcfc 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -74,18 +74,26 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[allow(dead_code)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetMax")] fn PyUnicodeUCS4_GetMax() -> Py_UNICODE; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Resize")] fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] fn PyUnicodeUCS4_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromObject")] 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; @@ -94,23 +102,30 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; format_spec_len: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideChar")] fn PyUnicodeUCS4_AsWideChar(unicode: *mut PyUnicodeObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS4_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS4_ClearFreelist() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyUnicode_AsDefaultEncodedString")] fn _PyUnicodeUCS4_AsDefaultEncodedString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS4_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS4_SetDefaultEncoding(encoding: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedObject")] fn PyUnicodeUCS4_AsEncodedObject(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedString")] fn PyUnicodeUCS4_AsEncodedString(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; @@ -127,6 +142,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; base64SetO: c_int, base64WhiteSpace: c_int, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF8")] fn PyUnicodeUCS4_DecodeUTF8(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -134,10 +150,14 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS4_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] fn PyUnicodeUCS4_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF32")] fn PyUnicodeUCS4_DecodeUTF32(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -147,11 +167,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF32String")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF16")] fn PyUnicodeUCS4_DecodeUTF16(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -161,6 +183,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF16String")] fn PyUnicodeUCS4_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, @@ -169,6 +192,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS4_DecodeUnicodeEscape(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeEscapeString")] fn PyUnicodeUCS4_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUnicodeEscape(data: *const Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; @@ -181,17 +205,23 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn _PyUnicode_DecodeUnicodeInternal(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeLatin1")] fn PyUnicodeUCS4_DecodeLatin1(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS4_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeLatin1")] fn PyUnicodeUCS4_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeASCII")] fn PyUnicodeUCS4_DecodeASCII(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS4_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeASCII")] fn PyUnicodeUCS4_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -209,12 +239,16 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeDecimal")] fn PyUnicodeUCS4_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Concat")] fn PyUnicodeUCS4_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Split")] fn PyUnicodeUCS4_Split(s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Splitlines")] 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; @@ -222,22 +256,29 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; maxsplit: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Join")] fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Tailmatch")] fn PyUnicodeUCS4_Tailmatch(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Find")] fn PyUnicodeUCS4_Find(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Count")] fn PyUnicodeUCS4_Count(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Replace")] fn PyUnicodeUCS4_Replace(str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Compare")] 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; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] 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, @@ -262,20 +303,28 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[allow(dead_code)] #[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] fn PyUnicodeUCS2_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS2_GetSize(unicode: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetMax")] fn PyUnicodeUCS2_GetMax() -> Py_UNICODE; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Resize")] fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] fn PyUnicodeUCS2_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromObject")] 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; @@ -284,24 +333,31 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; format_spec_len: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS2_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideChar")] fn PyUnicodeUCS2_AsWideChar(unicode: *mut PyUnicodeObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS2_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS2_ClearFreelist() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}__PyPyUnicode_AsDefaultEncodedString")] fn _PyUnicodeUCS2_AsDefaultEncodedString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS2_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS2_SetDefaultEncoding(encoding: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedObject")] fn PyUnicodeUCS2_AsEncodedObject(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedString")] fn PyUnicodeUCS2_AsEncodedString(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; @@ -318,6 +374,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; base64WhiteSpace: c_int, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF8")] fn PyUnicodeUCS2_DecodeUTF8(string: *const c_char, length: Py_ssize_t, errors: *const c_char) @@ -327,10 +384,14 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS2_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] fn PyUnicodeUCS2_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF32")] fn PyUnicodeUCS2_DecodeUTF32(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -340,11 +401,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF32String")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF16")] fn PyUnicodeUCS2_DecodeUTF16(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -354,6 +417,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF16String")] fn PyUnicodeUCS2_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, @@ -362,6 +426,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS2_DecodeUnicodeEscape(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeEscapeString")] fn PyUnicodeUCS2_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUnicodeEscape(data: *const Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; @@ -374,17 +439,23 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn _PyUnicode_DecodeUnicodeInternal(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeLatin1")] fn PyUnicodeUCS2_DecodeLatin1(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS2_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeLatin1")] fn PyUnicodeUCS2_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeASCII")] fn PyUnicodeUCS2_DecodeASCII(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS2_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeASCII")] fn PyUnicodeUCS2_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -402,13 +473,17 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeDecimal")] fn PyUnicodeUCS2_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Concat")] fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Split")] fn PyUnicodeUCS2_Split(s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Splitlines")] fn PyUnicodeUCS2_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject; fn PyUnicodeUCS2_Partition(s: *mut PyObject, sep: *mut PyObject) @@ -420,25 +495,32 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS2_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Join")] fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Tailmatch")] fn PyUnicodeUCS2_Tailmatch(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Find")] fn PyUnicodeUCS2_Find(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Count")] fn PyUnicodeUCS2_Count(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Replace")] fn PyUnicodeUCS2_Replace(str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Compare")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] fn PyUnicodeUCS2_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_Contains(container: *mut PyObject, From 8517db4283ed8e135510b487e15c230a8a9c331b Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 19:12:06 +0300 Subject: [PATCH 024/138] modsupport symbol --- src/ffi2/modsupport.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index 2f06c1cd804..0d81bf8f8af 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -40,6 +40,7 @@ use ffi2::methodobject::PyMethodDef; value: *const c_char) -> c_int; #[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))] + #[cfg_attr(PyPy, link_name="\u{1}__Py_InitPyPyModule")] fn Py_InitModule4_64(name: *const c_char, methods: *mut PyMethodDef, doc: *const c_char, _self: *mut PyObject, From bed2cc7474d002b88716bb92698a6a178816382d Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 19:13:16 +0300 Subject: [PATCH 025/138] fix --- src/ffi2/modsupport.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index 0d81bf8f8af..fd05407c5c2 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -40,7 +40,7 @@ use ffi2::methodobject::PyMethodDef; value: *const c_char) -> c_int; #[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))] - #[cfg_attr(PyPy, link_name="\u{1}__Py_InitPyPyModule")] + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_InitPyPyModule")] fn Py_InitModule4_64(name: *const c_char, methods: *mut PyMethodDef, doc: *const c_char, _self: *mut PyObject, From ba8a36ea8cc1051ef8a4026531ff29ed966b0fb2 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 21:26:05 +0300 Subject: [PATCH 026/138] fixed and added many symbols --- src/ffi2/fileobject.rs | 1 - src/ffi2/longobject.rs | 2 +- src/ffi2/moduleobject.rs | 2 - src/ffi2/object.rs | 2 - src/ffi2/objectabstract.rs | 7 +-- src/ffi2/pyerrors.rs | 2 +- src/ffi2/pythonrun.rs | 3 -- src/ffi2/warnings.rs | 2 +- src/ffi2/weakrefobject.rs | 1 - src/ffi3/boolobject.rs | 7 ++- src/ffi3/bytearrayobject.rs | 13 +++++- src/ffi3/bytesobject.rs | 8 ++++ src/ffi3/ceval.rs | 14 ++++++ src/ffi3/code.rs | 6 ++- src/ffi3/codecs.rs | 5 ++- src/ffi3/complexobject.rs | 9 +++- src/ffi3/descrobject.rs | 13 ++++-- src/ffi3/dictobject.rs | 14 +++++- src/ffi3/eval.rs | 3 +- src/ffi3/fileobject.rs | 6 ++- src/ffi3/floatobject.rs | 9 +++- src/ffi3/frameobject.rs | 3 +- src/ffi3/genobject.rs | 5 ++- src/ffi3/import.rs | 9 +++- src/ffi3/intrcheck.rs | 5 ++- src/ffi3/iterobject.rs | 4 +- src/ffi3/listobject.rs | 12 ++++- src/ffi3/longobject.rs | 25 ++++++++++- src/ffi3/memoryobject.rs | 7 ++- src/ffi3/methodobject.rs | 7 ++- src/ffi3/moduleobject.rs | 3 ++ src/ffi3/object.rs | 28 ++++++++++++ src/ffi3/objectabstract.rs | 82 ++++++++++++++++++++++++++++++++++ src/ffi3/objimpl.rs | 2 + src/ffi3/pyerrors.rs | 88 +++++++++++++++++++++++++++++++++++++ src/ffi3/pystate.rs | 12 ++++- src/ffi3/pystrtod.rs | 5 ++- src/ffi3/pythonrun.rs | 10 ++++- src/ffi3/setobject.rs | 16 ++++++- src/ffi3/sliceobject.rs | 9 +++- src/ffi3/structseq.rs | 3 +- src/ffi3/sysmodule.rs | 2 + src/ffi3/traceback.rs | 5 ++- src/ffi3/tupleobject.rs | 5 +++ src/ffi3/unicodeobject.rs | 51 +++++++++++++++++++++ src/ffi3/warnings.rs | 2 +- src/ffi3/weakrefobject.rs | 9 +++- 47 files changed, 473 insertions(+), 65 deletions(-) diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index bae27bec8a5..ef20bf4e07c 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -8,7 +8,6 @@ use ffi2::object::*; #[inline(always)] pub unsafe fn PyFile_Check(op : *mut PyObject) -> c_int { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] PyObject_TypeCheck(op, &mut PyFile_Type) } diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 44a7a56687a..0299e51040a 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -55,7 +55,6 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLong")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLongAndOverflow")] pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) @@ -64,6 +63,7 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t; #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLong")] pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index 58acd259369..36a7fa9c1b9 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -20,12 +20,10 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_New")] pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDict")] pub fn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetName")] 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; diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 5c257c425da..24b676ddb6f 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -602,12 +602,10 @@ pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2: #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_IsSubtype")] pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] 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 } diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index 8c6d0c71e7c..61ae45b35ac 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -5,15 +5,13 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttr")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttr")] pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_int { PyObject_SetAttr(o, attr_name, ptr::null_mut()) } @@ -63,7 +61,6 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetItem")] pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelItem")] pub fn PyObject_DelItemString(o: *mut PyObject, key: *mut c_char) -> c_int; pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject) @@ -294,10 +291,10 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Length")] pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKey")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKeyString")] pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKey")] pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_GetItemString")] diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index c457fbc9c02..53c7d5fd704 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -170,11 +170,11 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub fn PyErr_NoMemory() -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilename")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilename")] pub fn PyErr_SetFromErrnoWithFilename(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index 968da83c468..f131f8f2397 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -43,7 +43,6 @@ pub enum Struct_symtable { } pub fn PyRun_AnyFileExFlags(arg1: *mut FILE, arg2: *const c_char, arg3: c_int, arg4: *mut PyCompilerFlags) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_SimpleString")] pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int; @@ -81,12 +80,10 @@ pub enum Struct_symtable { } arg3: c_int, arg4: c_int) -> *mut Struct__node; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_String")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_StringFlags")] pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int, arg3: *mut PyObject, arg4: *mut PyObject, arg5: *mut PyCompilerFlags) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_File")] pub fn PyRun_FileExFlags(arg1: *mut FILE, arg2: *const c_char, arg3: c_int, arg4: *mut PyObject, arg5: *mut PyObject, arg6: c_int, diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index 7d5a6c04611..6c3819c32b3 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -3,7 +3,6 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Warn")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WarnEx")] pub fn PyErr_WarnEx(category: *mut PyObject, msg: *const c_char, stacklevel: Py_ssize_t) -> c_int; @@ -16,6 +15,7 @@ use ffi2::object::PyObject; } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Warn")] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) } \ No newline at end of file diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index 03898f32419..dd3b4e476c8 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -25,7 +25,6 @@ pub struct PyWeakReference { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_Check")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) diff --git a/src/ffi3/boolobject.rs b/src/ffi3/boolobject.rs index ba06c31f8fb..6f8d7d04ff0 100644 --- a/src/ffi3/boolobject.rs +++ b/src/ffi3/boolobject.rs @@ -3,13 +3,17 @@ use ffi3::object::*; use ffi3::longobject::PyLongObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; static mut _Py_FalseStruct: PyLongObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_TrueStruct")] static mut _Py_TrueStruct: PyLongObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Check")] pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyBool_Type) as c_int } @@ -22,5 +26,4 @@ pub unsafe fn Py_False() -> *mut PyObject { #[inline(always)] pub unsafe fn Py_True() -> *mut PyObject { &mut _Py_TrueStruct as *mut PyLongObject as *mut PyObject -} - +} \ No newline at end of file diff --git a/src/ffi3/bytearrayobject.rs b/src/ffi3/bytearrayobject.rs index 9e9a79bec71..7b68405f78a 100644 --- a/src/ffi3/bytearrayobject.rs +++ b/src/ffi3/bytearrayobject.rs @@ -3,29 +3,38 @@ use ffi3::object::*; use ffi3::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Check")] pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] PyObject_TypeCheck(op, &mut PyByteArray_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_CheckExact")] pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyByteArray_Type) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Concat")] pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromStringAndSize")] pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Resize")] pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; -} - +} \ No newline at end of file diff --git a/src/ffi3/bytesobject.rs b/src/ffi3/bytesobject.rs index c89b840998a..6d41c60c996 100644 --- a/src/ffi3/bytesobject.rs +++ b/src/ffi3/bytesobject.rs @@ -3,6 +3,7 @@ use ffi3::object::*; use ffi3::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_Type")] pub static mut PyBytes_Type: PyTypeObject; pub static mut PyBytesIter_Type: PyTypeObject; } @@ -18,9 +19,11 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromStringAndSize")] pub fn PyBytes_FromStringAndSize(arg1: *const c_char, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromObject")] pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromFormat")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromFormatV")] @@ -28,17 +31,22 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { // -> *mut PyObject; pub fn PyBytes_FromFormat(arg1: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_Size")] pub fn PyBytes_Size(arg1: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_AsString")] pub fn PyBytes_AsString(arg1: *mut PyObject) -> *mut c_char; pub fn PyBytes_Repr(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_Concat")] pub fn PyBytes_Concat(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_ConcatAndDel")] pub fn PyBytes_ConcatAndDel(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> (); pub fn PyBytes_DecodeEscape(arg1: *const c_char, arg2: Py_ssize_t, arg3: *const c_char, arg4: Py_ssize_t, arg5: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_AsStringAndSize")] pub fn PyBytes_AsStringAndSize(obj: *mut PyObject, s: *mut *mut c_char, len: *mut Py_ssize_t) -> c_int; diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 5a9fe86a840..0c8fbb9c56d 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -5,6 +5,7 @@ use ffi3::pystate::PyThreadState; use ffi3::code::FreeFunc; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallObjectWithKeywords")] pub fn PyEval_CallObjectWithKeywords(func: *mut PyObject, obj: *mut PyObject, kwargs: *mut PyObject) @@ -26,19 +27,27 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut methodname: *const c_char, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut ::ffi3::PyFrameObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AddPendingCall")] pub fn Py_AddPendingCall(func: Option c_int>, arg: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; static mut _Py_CheckRecursionLimit: c_int; } +#[cfg_attr(PyPy, link_name="\u{1}_PyPy_EnterRecursiveCall")] // TODO: Py_EnterRecursiveCall etc. #[cfg(Py_3_6)] @@ -56,18 +65,23 @@ pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int; pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState) -> (); } #[cfg(py_sys_config = "WITH_THREAD")] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_InitThreads")] pub fn PyEval_InitThreads() -> (); pub fn PyEval_AcquireLock() -> (); pub fn PyEval_ReleaseLock() -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState) -> (); pub fn PyEval_ReInitThreads() -> (); } \ No newline at end of file diff --git a/src/ffi3/code.rs b/src/ffi3/code.rs index 5c51540b59f..93b77f1826c 100644 --- a/src/ffi3/code.rs +++ b/src/ffi3/code.rs @@ -76,6 +76,7 @@ pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_New")] pub fn PyCode_New(arg1: c_int, arg2: c_int, arg3: c_int, arg4: c_int, arg5: c_int, arg6: *mut PyObject, @@ -84,6 +85,7 @@ pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; arg11: *mut PyObject, arg12: *mut PyObject, arg13: *mut PyObject, arg14: c_int, arg15: *mut PyObject) -> *mut PyCodeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_NewEmpty")] pub fn PyCode_NewEmpty(filename: *const c_char, funcname: *const c_char, firstlineno: c_int) -> *mut PyCodeObject; @@ -95,11 +97,13 @@ pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_Check")] pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCode_Type) as c_int } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_GetNumFree")] pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { ::ffi3::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) -} +} \ No newline at end of file diff --git a/src/ffi3/codecs.rs b/src/ffi3/codecs.rs index f7278276e7d..058957cae71 100644 --- a/src/ffi3/codecs.rs +++ b/src/ffi3/codecs.rs @@ -14,9 +14,11 @@ extern "C" { errors: *const c_char) -> *mut PyObject; pub fn PyCodec_Encoder(encoding: *const c_char) -> *mut PyObject; pub fn PyCodec_Decoder(encoding: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCodec_IncrementalEncoder")] pub fn PyCodec_IncrementalEncoder(encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCodec_IncrementalDecoder")] pub fn PyCodec_IncrementalDecoder(encoding: *const c_char, errors: *const c_char) -> *mut PyObject; @@ -38,5 +40,4 @@ extern "C" { -> *mut PyObject; pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject) -> *mut PyObject; -} - +} \ No newline at end of file diff --git a/src/ffi3/complexobject.rs b/src/ffi3/complexobject.rs index 136db879119..dbd959795e8 100644 --- a/src/ffi3/complexobject.rs +++ b/src/ffi3/complexobject.rs @@ -2,23 +2,28 @@ use std::os::raw::{c_double, c_int}; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Check")] pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_CheckExact")] pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyComplex_Type) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromDoubles")] pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; -} - +} \ No newline at end of file diff --git a/src/ffi3/descrobject.rs b/src/ffi3/descrobject.rs index 187344c5524..37843289577 100644 --- a/src/ffi3/descrobject.rs +++ b/src/ffi3/descrobject.rs @@ -29,22 +29,29 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { }; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyClassMethodDescr_Type")] pub static mut PyClassMethodDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethodDescr_Type")] pub static mut PyMethodDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDescr_NewClassMethod")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_New")] pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject; pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; -} - - +} \ No newline at end of file diff --git a/src/ffi3/dictobject.rs b/src/ffi3/dictobject.rs index a82aceaeb1b..cff2adc1c27 100644 --- a/src/ffi3/dictobject.rs +++ b/src/ffi3/dictobject.rs @@ -50,23 +50,35 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItem")] pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Next")] pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Contains")] pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Update")] pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Merge")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItemString")] pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItemString")] pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItemString")] pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; -} +} \ No newline at end of file diff --git a/src/ffi3/eval.rs b/src/ffi3/eval.rs index fac2dd47ab4..248b44602e7 100644 --- a/src/ffi3/eval.rs +++ b/src/ffi3/eval.rs @@ -2,6 +2,7 @@ use std::os::raw::c_int; use ffi3::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_EvalCode")] pub fn PyEval_EvalCode(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; pub fn PyEval_EvalCodeEx(co: *mut PyObject, globals: *mut PyObject, @@ -10,4 +11,4 @@ use ffi3::object::PyObject; kwdc: c_int, defs: *mut *mut PyObject, defc: c_int, kwdefs: *mut PyObject, closure: *mut PyObject) -> *mut PyObject; -} +} \ No newline at end of file diff --git a/src/ffi3/fileobject.rs b/src/ffi3/fileobject.rs index 0211afebe1c..4e1e1641206 100644 --- a/src/ffi3/fileobject.rs +++ b/src/ffi3/fileobject.rs @@ -10,10 +10,13 @@ pub const PY_STDIOTEXTMODE : &str = "b"; arg6: *const c_char, arg7: *const c_char, arg8: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_GetLine")] pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteObject")] pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteString")] pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; @@ -21,5 +24,4 @@ pub const PY_STDIOTEXTMODE : &str = "b"; #[cfg(Py_3_6)] pub static mut Py_FileSystemDefaultEncodeErrors: *const c_char; pub static mut Py_HasFileSystemDefaultEncoding: c_int; -} - +} \ No newline at end of file diff --git a/src/ffi3/floatobject.rs b/src/ffi3/floatobject.rs index 1bfa7137a63..93e99f52b13 100644 --- a/src/ffi3/floatobject.rs +++ b/src/ffi3/floatobject.rs @@ -2,15 +2,18 @@ use std::os::raw::{c_int, c_double}; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Check")] pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_CheckExact")] pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFloat_Type) as c_int } @@ -19,8 +22,10 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { pub fn PyFloat_GetMax() -> c_double; pub fn PyFloat_GetMin() -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromString")] pub fn PyFloat_FromString(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(arg1: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(arg1: *mut PyObject) -> c_double; -} - +} \ No newline at end of file diff --git a/src/ffi3/frameobject.rs b/src/ffi3/frameobject.rs index 98c99d22bc5..99f94e3af96 100644 --- a/src/ffi3/frameobject.rs +++ b/src/ffi3/frameobject.rs @@ -55,6 +55,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrame_New")] pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; @@ -67,4 +68,4 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { pub fn PyFrame_ClearFreeList() -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; -} +} \ No newline at end of file diff --git a/src/ffi3/genobject.rs b/src/ffi3/genobject.rs index f1651c0d21b..813e5d700b8 100644 --- a/src/ffi3/genobject.rs +++ b/src/ffi3/genobject.rs @@ -23,11 +23,13 @@ pub struct PyGenObject { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } @@ -42,6 +44,7 @@ pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyCoro_Check")] pub unsafe fn PyCoro_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyCoro_Type) } @@ -70,4 +73,4 @@ pub unsafe fn PyAsyncGen_Check(op: *mut PyObject) -> c_int { #[inline(always)] pub unsafe fn PyAsyncGen_Check(_op: *mut PyObject) -> c_int { 0 -} +} \ No newline at end of file diff --git a/src/ffi3/import.rs b/src/ffi3/import.rs index 34b95f93859..a633bbcaac2 100644 --- a/src/ffi3/import.rs +++ b/src/ffi3/import.rs @@ -4,8 +4,10 @@ use ffi3::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyImport_GetMagicNumber() -> c_long; pub fn PyImport_GetMagicTag() -> *const c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModule")] pub fn PyImport_ExecCodeModule(name: *const c_char, co: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModuleEx")] pub fn PyImport_ExecCodeModuleEx(name: *const c_char, co: *mut PyObject, pathname: *const c_char) @@ -22,11 +24,14 @@ use ffi3::object::PyObject; pathname: *mut PyObject, cpathname: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject; pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModule")] pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleNoBlock")] pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleLevel")] @@ -35,6 +40,7 @@ use ffi3::object::PyObject; locals: *mut PyObject, fromlist: *mut PyObject, level: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleLevelObject")] pub fn PyImport_ImportModuleLevelObject(name: *mut PyObject, globals: *mut PyObject, locals: *mut PyObject, @@ -55,6 +61,7 @@ pub unsafe fn PyImport_ImportModuleEx(name: *const c_char, #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; pub fn PyImport_Cleanup() -> (); pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) @@ -65,4 +72,4 @@ pub unsafe fn PyImport_ImportModuleEx(name: *const c_char, pub fn PyImport_AppendInittab(name: *const c_char, initfunc: Option *mut PyObject>) -> c_int; -} +} \ No newline at end of file diff --git a/src/ffi3/intrcheck.rs b/src/ffi3/intrcheck.rs index e704162f8e0..015ad9ec0f9 100644 --- a/src/ffi3/intrcheck.rs +++ b/src/ffi3/intrcheck.rs @@ -1,8 +1,9 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_InterruptOccurred")] pub fn PyOS_InterruptOccurred() -> c_int; pub fn PyOS_InitInterrupts() -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_AfterFork")] pub fn PyOS_AfterFork() -> (); -} - +} \ No newline at end of file diff --git a/src/ffi3/iterobject.rs b/src/ffi3/iterobject.rs index 91e611e07f0..850f8288d6d 100644 --- a/src/ffi3/iterobject.rs +++ b/src/ffi3/iterobject.rs @@ -5,7 +5,9 @@ use ffi3::object::*; pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallIter_New")] pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } @@ -19,5 +21,3 @@ pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int { pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCallIter_Type) as c_int } - - diff --git a/src/ffi3/listobject.rs b/src/ffi3/listobject.rs index 99c6ce39f9a..183a8b8fbbe 100644 --- a/src/ffi3/listobject.rs +++ b/src/ffi3/listobject.rs @@ -3,6 +3,7 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; pub static mut PyListIter_Type: PyTypeObject; pub static mut PyListRevIter_Type: PyTypeObject; @@ -19,19 +20,28 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Size")] pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t; #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetItem")] pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetItem")] pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Insert")] pub fn PyList_Insert(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Append")] pub fn PyList_Append(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetSlice")] pub fn PyList_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetSlice")] pub fn PyList_SetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Sort")] pub fn PyList_Sort(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Reverse")] pub fn PyList_Reverse(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_AsTuple")] pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject; -} +} \ No newline at end of file diff --git a/src/ffi3/longobject.rs b/src/ffi3/longobject.rs index 5c8ef0153ef..dcf508d9ede 100644 --- a/src/ffi3/longobject.rs +++ b/src/ffi3/longobject.rs @@ -6,6 +6,7 @@ use ffi3::pyport::Py_ssize_t; pub enum PyLongObject {} #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } @@ -20,34 +21,55 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLong")] pub fn PyLong_FromLong(arg1: c_long) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(arg1: c_ulong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(arg1: size_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(arg1: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromDouble")] pub fn PyLong_FromDouble(arg1: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLong")] pub fn PyLong_AsLong(arg1: *mut PyObject) -> c_long; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongAndOverflow")] pub fn PyLong_AsLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_long; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(arg1: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsSize_t")] pub fn PyLong_AsSize_t(arg1: *mut PyObject) -> size_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(arg1: *mut PyObject) -> c_ulong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(arg1: *mut PyObject) -> c_ulong; pub fn PyLong_GetInfo() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsDouble")] pub fn PyLong_AsDouble(arg1: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(arg1: *mut c_void) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(arg1: c_longlong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLongLong")] pub fn PyLong_FromUnsignedLongLong(arg1: c_ulonglong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(arg1: *mut PyObject) -> c_longlong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLong")] pub fn PyLong_AsUnsignedLongLong(arg1: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLongMask")] pub fn PyLong_AsUnsignedLongLongMask(arg1: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLongAndOverflow")] pub fn PyLong_AsLongLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_longlong; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromString")] pub fn PyLong_FromString(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> *mut PyObject; @@ -57,5 +79,4 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { pub fn PyOS_strtol(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> c_long; -} - +} \ No newline at end of file diff --git a/src/ffi3/memoryobject.rs b/src/ffi3/memoryobject.rs index 9ed779c9472..800f1c2ceb2 100644 --- a/src/ffi3/memoryobject.rs +++ b/src/ffi3/memoryobject.rs @@ -3,20 +3,23 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Check")] pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyMemoryView_Type) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromMemory")] pub fn PyMemoryView_FromMemory(mem: *mut c_char, size: Py_ssize_t, flags: c_int) -> *mut PyObject; pub fn PyMemoryView_GetContiguous(base: *mut PyObject, buffertype: c_int, order: c_char) -> *mut PyObject; -} - +} \ No newline at end of file diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index 49db6065932..77911149078 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -3,10 +3,12 @@ use std::{mem, ptr}; use ffi3::object::{PyObject, PyTypeObject, Py_TYPE}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Check")] pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCFunction_Type) as c_int } @@ -30,6 +32,7 @@ pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; @@ -60,6 +63,7 @@ impl Default for PyMethodDef { #[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] PyCFunction_NewEx(ml, slf, ptr::null_mut()) } @@ -94,5 +98,4 @@ pub const METHOD_FASTCALL : c_int = 0x0080; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyCFunction_ClearFreeList() -> c_int; -} - +} \ No newline at end of file diff --git a/src/ffi3/moduleobject.rs b/src/ffi3/moduleobject.rs index 7f2132d086a..7271de8ac1d 100644 --- a/src/ffi3/moduleobject.rs +++ b/src/ffi3/moduleobject.rs @@ -4,10 +4,12 @@ use ffi3::object::*; use ffi3::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Check")] pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } @@ -20,6 +22,7 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDict")] 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; diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 20ebe2e536c..d6c03685343 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -623,6 +623,7 @@ impl Default for PyType_Spec { #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_FromSpec")] pub fn PyType_FromSpec(arg1: *mut PyType_Spec) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_FromSpecWithBases")] pub fn PyType_FromSpecWithBases(arg1: *mut PyType_Spec, arg2: *mut PyObject) -> *mut PyObject; @@ -630,6 +631,7 @@ impl Default for PyType_Spec { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_IsSubtype")] pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } @@ -640,8 +642,10 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { /// built-in 'type' + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; /// built-in 'object' + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; /// built-in 'super' pub static mut PySuper_Type: PyTypeObject; @@ -660,51 +664,73 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericAlloc")] pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericNew")] pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut ::libc::FILE, flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Str")] pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_ASCII")] pub fn PyObject_ASCII(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Bytes")] pub fn PyObject_Bytes(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompare")] pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompareBool")] pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttrString")] pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] pub fn PyObject_SetAttrString(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttrString")] 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; #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericSetAttr")] pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; pub fn PyObject_GenericSetDict(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallable_Check")] pub fn PyCallable_Check(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_ClearWeakRefs")] pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject) -> (); #[cfg(not(Py_LIMITED_API))] pub fn PyObject_CallFinalizer(arg1: *mut PyObject) -> (); @@ -712,6 +738,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFinalizerFromDealloc")] pub fn PyObject_CallFinalizerFromDealloc(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Dir")] 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) -> (); @@ -834,6 +861,7 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) { #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index 935e7747a9c..0becdad6dda 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -4,7 +4,9 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttr")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } @@ -14,8 +16,10 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Call")] pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, kw: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallObject")] pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunction")] @@ -36,7 +40,9 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, method: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; } @@ -47,11 +53,14 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_LengthHint")] pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetItem")] pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetItem")] pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, v: *mut PyObject) -> c_int; pub fn PyObject_DelItemString(o: *mut PyObject, @@ -59,6 +68,7 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { -> c_int; pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsCharBuffer")] pub fn PyObject_AsCharBuffer(obj: *mut PyObject, buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t) @@ -102,6 +112,7 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { order: c_char) -> c_int; pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_IsContiguous")] pub fn PyBuffer_IsContiguous(view: *const Py_buffer, fort: c_char) -> c_int; pub fn PyBuffer_FillContiguousStrides(ndims: c_int, @@ -109,6 +120,7 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { strides: *mut Py_ssize_t, itemsize: c_int, fort: c_char) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FillInfo")] 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) @@ -118,13 +130,16 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Format")] pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Check")] pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { (match (*(*o).ob_type).tp_iternext { Some(tp_iternext) => tp_iternext as *const c_void != ::ffi3::object::_PyObject_NextNotImplemented as *const c_void, @@ -133,118 +148,171 @@ pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Add")] pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Subtract")] pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Multiply")] pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_MatrixMultiply")] pub fn PyNumber_MatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_FloorDivide")] pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_TrueDivide")] pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Remainder")] pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Divmod")] pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Power")] pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Lshift")] pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Rshift")] pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_And")] pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Xor")] pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyIndex_Check")] pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { let tp_as_number = (*(*o).ob_type).tp_as_number; (!tp_as_number.is_null() && (*tp_as_number).nb_index.is_some()) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_AsSsize_t")] pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAdd")] pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceSubtract")] pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceMultiply")] pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceMatrixMultiply")] pub fn PyNumber_InPlaceMatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceFloorDivide")] pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceTrueDivide")] pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRemainder")] pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlacePower")] pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceLshift")] pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRshift")] pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAnd")] pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceXor")] pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceOr")] pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Length")] pub unsafe fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t { PySequence_Size(o) } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Concat")] pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Repeat")] pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetItem")] pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetSlice")] pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetItem")] pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelItem")] pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetSlice")] pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelSlice")] pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast")] pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char) -> *mut PyObject; // TODO: PySequence_Fast macros pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Contains")] pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) -> c_int; } @@ -255,17 +323,23 @@ pub unsafe fn PySequence_In(o: *mut PyObject, value: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Index")] pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceConcat")] pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceRepeat")] pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Length")] pub unsafe fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t { PyMapping_Size(o) } @@ -281,22 +355,30 @@ pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKeyString")] pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *const c_char) -> c_int; pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Keys")] pub fn PyMapping_Keys(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Values")] pub fn PyMapping_Values(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Items")] pub fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_GetItemString")] pub fn PyMapping_GetItemString(o: *mut PyObject, key: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_SetItemString")] pub fn PyMapping_SetItemString(o: *mut PyObject, key: *const c_char, value: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsInstance")] pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsSubclass")] pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } \ No newline at end of file diff --git a/src/ffi3/objimpl.rs b/src/ffi3/objimpl.rs index 36a3cdd1e0e..68f5209011f 100644 --- a/src/ffi3/objimpl.rs +++ b/src/ffi3/objimpl.rs @@ -4,8 +4,10 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Malloc")] pub fn PyObject_Malloc(size: size_t) -> *mut c_void; pub fn PyObject_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Realloc")] pub fn PyObject_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Free")] pub fn PyObject_Free(ptr: *mut c_void) -> (); diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index ecc5dc2a87e..b7a27af09aa 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -3,11 +3,16 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetString")] pub fn PyErr_SetString(exception: *mut PyObject, string: *const c_char) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Clear")] pub fn PyErr_Clear() -> (); #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Fetch")] pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, @@ -15,26 +20,37 @@ use ffi3::object::*; #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_GetExcInfo")] pub fn PyErr_GetExcInfo(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetExcInfo")] pub fn PyErr_SetExcInfo(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char) -> !; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_GivenExceptionMatches")] pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NormalizeException")] pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_SetTraceback")] pub fn PyException_SetTraceback(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_GetTraceback")] pub fn PyException_GetTraceback(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_GetCause")] pub fn PyException_GetCause(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_SetCause")] pub fn PyException_SetCause(arg1: *mut PyObject, arg2: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_GetContext")] pub fn PyException_GetContext(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_SetContext")] pub fn PyException_SetContext(arg1: *mut PyObject, arg2: *mut PyObject) -> (); } @@ -51,70 +67,123 @@ pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { (*x).ob_type as *mut PyObject } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_StopAsyncIteration")] pub static mut PyExc_StopAsyncIteration: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; #[cfg(Py_3_6)] pub static mut PyExc_ModuleNotFoundError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RecursionError")] pub static mut PyExc_RecursionError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BlockingIOError")] pub static mut PyExc_BlockingIOError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BrokenPipeError")] pub static mut PyExc_BrokenPipeError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ChildProcessError")] pub static mut PyExc_ChildProcessError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionError")] pub static mut PyExc_ConnectionError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionAbortedError")] pub static mut PyExc_ConnectionAbortedError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionRefusedError")] pub static mut PyExc_ConnectionRefusedError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionResetError")] pub static mut PyExc_ConnectionResetError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FileExistsError")] pub static mut PyExc_FileExistsError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FileNotFoundError")] pub static mut PyExc_FileNotFoundError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_InterruptedError")] pub static mut PyExc_InterruptedError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IsADirectoryError")] pub static mut PyExc_IsADirectoryError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NotADirectoryError")] pub static mut PyExc_NotADirectoryError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_PermissionError")] pub static mut PyExc_PermissionError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ProcessLookupError")] pub static mut PyExc_ProcessLookupError: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TimeoutError")] pub static mut PyExc_TimeoutError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; @@ -124,21 +193,36 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub static mut PyExc_RecursionErrorInst: *mut PyObject; /* Predefined warning categories */ + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ResourceWarning")] pub static mut PyExc_ResourceWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject( arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub fn PyErr_SetFromErrnoWithFilenameObjects( @@ -154,6 +238,7 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { arg3: *mut PyObject, arg4: *mut PyObject) -> *mut PyObject; pub fn PyErr_SetImportError(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall() -> (); pub fn _PyErr_BadInternalCall(filename: *const c_char, lineno: c_int) -> (); @@ -165,8 +250,11 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { doc: *const c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt() -> (); pub fn PyErr_SyntaxLocation(filename: *const c_char, lineno: c_int) -> (); pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, diff --git a/src/ffi3/pystate.rs b/src/ffi3/pystate.rs index 256490f3ff9..39606ffda94 100644 --- a/src/ffi3/pystate.rs +++ b/src/ffi3/pystate.rs @@ -29,17 +29,24 @@ pub struct PyThreadState { //fn _PyState_AddModule(arg1: *mut PyObject, // arg2: *mut PyModuleDef) -> c_int; pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_New")] pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState; //fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) // -> *mut PyThreadState; //fn _PyThreadState_Init(arg1: *mut PyThreadState) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState) -> (); #[cfg(py_sys_config="WITH_THREAD")] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent() -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Get")] pub fn PyThreadState_Get() -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; @@ -53,7 +60,9 @@ pub enum PyGILState_STATE { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE) -> (); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; } @@ -61,5 +70,4 @@ pub enum PyGILState_STATE { #[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { PyThreadState_Get() -} - +} \ No newline at end of file diff --git a/src/ffi3/pystrtod.rs b/src/ffi3/pystrtod.rs index 94254f36d75..6b46c470433 100644 --- a/src/ffi3/pystrtod.rs +++ b/src/ffi3/pystrtod.rs @@ -2,10 +2,12 @@ use std::os::raw::{c_char, c_int, c_double}; use ffi3::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_string_to_double")] pub fn PyOS_string_to_double(str: *const c_char, endptr: *mut *mut c_char, overflow_exception: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_double_to_string")] pub fn PyOS_double_to_string(val: c_double, format_code: c_char, precision: c_int, @@ -22,5 +24,4 @@ pub const Py_DTSF_ALT : c_int = 0x04; /* "alternate" formatting. it's form /* PyOS_double_to_string's "type", if non-NULL, will be set to one of: */ pub const Py_DTST_FINITE: c_int = 0; pub const Py_DTST_INFINITE: c_int = 1; -pub const Py_DTST_NAN: c_int = 2; - +pub const Py_DTST_NAN: c_int = 2; \ No newline at end of file diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index 2889e8b0bdb..915c1141041 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -10,12 +10,14 @@ use ffi3::pyarena::PyArena; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { // TODO: these moved to pylifecycle.h pub fn Py_SetProgramName(arg1: *mut wchar_t) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetProgramName")] pub fn Py_GetProgramName() -> *mut wchar_t; pub fn Py_SetPythonHome(arg1: *mut wchar_t) -> (); pub fn Py_GetPythonHome() -> *mut wchar_t; pub fn Py_Initialize() -> (); pub fn Py_InitializeEx(arg1: c_int) -> (); pub fn Py_Finalize() -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IsInitialized")] pub fn Py_IsInitialized() -> c_int; pub fn Py_NewInterpreter() -> *mut PyThreadState; pub fn Py_EndInterpreter(arg1: *mut PyThreadState) -> (); @@ -122,6 +124,7 @@ pub unsafe fn PyParser_SimpleParseFile(fp: *mut FILE, s: *const c_char, b: c_int arg4: c_int) -> *mut _node; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_StringFlags")] pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int, arg3: *mut PyObject, arg4: *mut PyObject, arg5: *mut PyCompilerFlags) -> *mut PyObject; @@ -142,6 +145,7 @@ pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int } #[cfg(not(Py_LIMITED_API))] #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPy_CompileStringFlags")] pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: c_int, f: *mut PyCompilerFlags) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, f, -1) } @@ -171,10 +175,12 @@ pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: pub fn PyErr_Print() -> (); #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Display")] pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); // TODO: these moved to pylifecycle.h + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AtExit")] pub fn Py_AtExit(func: Option ()>) -> c_int; pub fn Py_Exit(arg1: c_int) -> (); @@ -185,10 +191,10 @@ pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: pub fn Py_GetExecPrefix() -> *mut wchar_t; pub fn Py_GetPath() -> *mut wchar_t; pub fn Py_SetPath(arg1: *const wchar_t) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetVersion")] 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; -} - +} \ No newline at end of file diff --git a/src/ffi3/setobject.rs b/src/ffi3/setobject.rs index 935b831e1b8..0df3ae156cb 100644 --- a/src/ffi3/setobject.rs +++ b/src/ffi3/setobject.rs @@ -3,17 +3,21 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; pub static mut PySetIter_Type: PyTypeObject; } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Check")] pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_Check")] pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } @@ -26,6 +30,7 @@ pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Check")] pub unsafe fn PySet_Check(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0) as c_int } @@ -36,15 +41,22 @@ pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_New")] pub fn PySet_New(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_New")] pub fn PyFrozenSet_New(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Contains")] pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Discard")] pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Add")] pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; -} - +} \ No newline at end of file diff --git a/src/ffi3/sliceobject.rs b/src/ffi3/sliceobject.rs index d1e1e535ff0..197d5bf24ce 100644 --- a/src/ffi3/sliceobject.rs +++ b/src/ffi3/sliceobject.rs @@ -3,6 +3,7 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}__PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -12,25 +13,29 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Check")] 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" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_New")] pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject, step: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndices")] 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; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndicesEx")] 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; -} - +} \ No newline at end of file diff --git a/src/ffi3/structseq.rs b/src/ffi3/structseq.rs index f1b1009cbd6..0fb54cccf0d 100644 --- a/src/ffi3/structseq.rs +++ b/src/ffi3/structseq.rs @@ -19,7 +19,6 @@ pub struct PyStructSequence_Desc { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyStructSequence_New")] pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) -> *mut PyTypeObject; pub fn PyStructSequence_New(_type: *mut PyTypeObject) -> *mut PyObject; @@ -27,4 +26,4 @@ pub struct PyStructSequence_Desc { arg3: *mut PyObject) -> (); pub fn PyStructSequence_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; -} +} \ No newline at end of file diff --git a/src/ffi3/sysmodule.rs b/src/ffi3/sysmodule.rs index 0b7549ad9f3..618c382b20a 100644 --- a/src/ffi3/sysmodule.rs +++ b/src/ffi3/sysmodule.rs @@ -5,7 +5,9 @@ use ffi3::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn Py_DecodeLocale(arg1: *const c_char, arg2: Py_ssize_t) -> *mut wchar_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_GetObject")] pub fn PySys_GetObject(arg1: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_SetObject")] pub fn PySys_SetObject(arg1: *const c_char, arg2: *mut PyObject) -> c_int; pub fn PySys_SetArgv(arg1: c_int, arg2: *mut *mut wchar_t) -> (); diff --git a/src/ffi3/traceback.rs b/src/ffi3/traceback.rs index 201acd2303c..aad174f56e9 100644 --- a/src/ffi3/traceback.rs +++ b/src/ffi3/traceback.rs @@ -2,13 +2,16 @@ use std::os::raw::c_int; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut ::ffi3::PyFrameObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Check")] pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int -} +} \ No newline at end of file diff --git a/src/ffi3/tupleobject.rs b/src/ffi3/tupleobject.rs index 270500b7abc..4822098cce4 100644 --- a/src/ffi3/tupleobject.rs +++ b/src/ffi3/tupleobject.rs @@ -10,6 +10,7 @@ pub struct PyTupleObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; pub static mut PyTupleIter_Type: PyTypeObject; } @@ -27,10 +28,14 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_New")] pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Size")] pub fn PyTuple_Size(arg1: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetItem")] pub fn PyTuple_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_SetItem")] pub fn PyTuple_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetSlice")] pub fn PyTuple_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Pack")] diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index 6fe959e44b6..e738fe534a4 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -11,16 +11,19 @@ pub type Py_UCS2 = u16; pub type Py_UCS1 = u8; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; pub static mut PyUnicodeIter_Type: PyTypeObject; } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Check")] pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CheckExact")] pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyUnicode_Type) as c_int } @@ -41,6 +44,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; length: Py_ssize_t, fill_char: Py_UCS4) -> Py_ssize_t; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; @@ -61,8 +65,10 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; -> *mut Py_UCS4; pub fn PyUnicode_AsUCS4Copy(unicode: *mut PyObject) -> *mut Py_UCS4; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeAndSize")] pub fn PyUnicode_AsUnicodeAndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut Py_UNICODE; @@ -75,13 +81,17 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_WriteChar(unicode: *mut PyObject, index: Py_ssize_t, character: Py_UCS4) -> c_int; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetMax")] pub fn PyUnicode_GetMax() -> Py_UNICODE; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Resize")] pub fn PyUnicode_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] pub fn PyUnicode_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromObject")] pub fn PyUnicode_FromObject(obj: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromFormat")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromFormatV")] @@ -89,18 +99,22 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; // vargs: va_list) -> *mut PyObject; pub fn PyUnicode_FromFormat(format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_InternInPlace")] pub fn PyUnicode_InternInPlace(arg1: *mut *mut PyObject) -> (); pub fn PyUnicode_InternImmortal(arg1: *mut *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_InternFromString")] pub fn PyUnicode_InternFromString(u: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromWideChar")] pub fn PyUnicode_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideChar")] pub fn PyUnicode_AsWideChar(unicode: *mut PyObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideCharString")] pub fn PyUnicode_AsWideCharString(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut wchar_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromOrdinal")] pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg(not(Py_LIMITED_API))] @@ -109,8 +123,11 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; size: *mut Py_ssize_t) -> *mut c_char; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *mut c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetDefaultEncoding")] pub fn PyUnicode_GetDefaultEncoding() -> *const c_char; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] pub fn PyUnicode_Decode(s: *const c_char, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; @@ -126,10 +143,12 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_Encode(s: *const Py_UNICODE, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedObject")] pub fn PyUnicode_AsEncodedObject(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedString")] pub fn PyUnicode_AsEncodedString(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) @@ -154,6 +173,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; base64WhiteSpace: c_int, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF8")] pub fn PyUnicode_DecodeUTF8(string: *const c_char, length: Py_ssize_t, errors: *const c_char) @@ -163,11 +183,14 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] pub fn PyUnicode_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] pub fn PyUnicode_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF32")] pub fn PyUnicode_DecodeUTF32(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -179,11 +202,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF32String")] pub fn PyUnicode_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_EncodeUTF32(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char, byteorder: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF16")] pub fn PyUnicode_DecodeUTF16(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -195,6 +220,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF16String")] pub fn PyUnicode_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, @@ -204,6 +230,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeEscapeString")] pub fn PyUnicode_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] @@ -219,21 +246,27 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_EncodeRawUnicodeEscape(data: *const Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeLatin1")] pub fn PyUnicode_DecodeLatin1(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsLatin1String")] pub fn PyUnicode_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeLatin1")] pub fn PyUnicode_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeASCII")] pub fn PyUnicode_DecodeASCII(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsASCIIString")] pub fn PyUnicode_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeASCII")] pub fn PyUnicode_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -256,11 +289,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeDecimal")] pub fn PyUnicode_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char) -> c_int; #[cfg(not(Py_LIMITED_API))] + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_TransformDecimalToASCII")] pub fn PyUnicode_TransformDecimalToASCII(s: *mut Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; @@ -274,24 +309,32 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_EncodeLocale(unicode: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FSConverter")] pub fn PyUnicode_FSConverter(arg1: *mut PyObject, arg2: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FSDecoder")] pub fn PyUnicode_FSDecoder(arg1: *mut PyObject, arg2: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeFSDefault")] pub fn PyUnicode_DecodeFSDefault(s: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeFSDefaultAndSize")] pub fn PyUnicode_DecodeFSDefaultAndSize(s: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeFSDefault")] pub fn PyUnicode_EncodeFSDefault(unicode: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Concat")] pub fn PyUnicode_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; pub fn PyUnicode_Append(pleft: *mut *mut PyObject, right: *mut PyObject) -> (); pub fn PyUnicode_AppendAndDel(pleft: *mut *mut PyObject, right: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Split")] pub fn PyUnicode_Split(s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Splitlines")] pub fn PyUnicode_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject; pub fn PyUnicode_Partition(s: *mut PyObject, sep: *mut PyObject) @@ -303,29 +346,37 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Join")] pub fn PyUnicode_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Tailmatch")] pub fn PyUnicode_Tailmatch(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Find")] pub fn PyUnicode_Find(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; pub fn PyUnicode_FindChar(str: *mut PyObject, ch: Py_UCS4, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Count")] pub fn PyUnicode_Count(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Replace")] pub fn PyUnicode_Replace(str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Compare")] pub fn PyUnicode_Compare(left: *mut PyObject, right: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CompareWithASCIIString")] pub fn PyUnicode_CompareWithASCIIString(left: *mut PyObject, right: *const c_char) -> c_int; pub fn PyUnicode_RichCompare(left: *mut PyObject, right: *mut PyObject, op: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] pub fn PyUnicode_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; pub fn PyUnicode_Contains(container: *mut PyObject, diff --git a/src/ffi3/warnings.rs b/src/ffi3/warnings.rs index 086a93451db..3f04459e5a9 100644 --- a/src/ffi3/warnings.rs +++ b/src/ffi3/warnings.rs @@ -20,4 +20,4 @@ use ffi3::object::PyObject; lineno: c_int, module: *const c_char, registry: *mut PyObject) -> c_int; -} +} \ No newline at end of file diff --git a/src/ffi3/weakrefobject.rs b/src/ffi3/weakrefobject.rs index edfa52ebcee..6d3d2af0d7f 100644 --- a/src/ffi3/weakrefobject.rs +++ b/src/ffi3/weakrefobject.rs @@ -10,16 +10,19 @@ pub enum PyWeakReference {} } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_Check")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline(always)] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckProxy")] 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 @@ -31,10 +34,12 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewRef")] pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewProxy")] pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_GetObject")] pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject; -} - +} \ No newline at end of file From 4ad11d802ab66da2c4747ec16fa3c92775a284ea Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 22:36:21 +0300 Subject: [PATCH 027/138] fixes --- src/ffi2/import.rs | 3 +-- src/ffi2/setobject.rs | 4 ++-- src/ffi2/unicodeobject.rs | 8 ++------ src/ffi3/objectabstract.rs | 2 +- src/ffi3/setobject.rs | 4 ++-- src/ffi3/weakrefobject.rs | 2 +- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index 6ade24adcd9..d0f410cc335 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -21,8 +21,6 @@ pub struct PyImport_Struct_frozen { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_Import")] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModule")] pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, globals: *mut PyObject, locals: *mut PyObject, @@ -31,6 +29,7 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModule")] pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleNoBlock")] diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index e33fabe5ac8..c5f1fe2aec4 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -12,7 +12,6 @@ use ffi2::object::*; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Check")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_CheckExact")] pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { let f : *mut PyTypeObject = &mut PyFrozenSet_Type; @@ -20,7 +19,6 @@ pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_Check")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_CheckExact")] pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { let s : *mut PyTypeObject = &mut PySet_Type; @@ -29,6 +27,7 @@ pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_Check")] pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { (PyAnySet_CheckExact(ob) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 || @@ -43,6 +42,7 @@ pub unsafe fn PySet_Check(ob : *mut PyObject) -> c_int { } #[inline] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Check")] 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 diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index e8e19f9dcfc..7ea26c45684 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -76,10 +76,10 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; @@ -150,7 +150,6 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS4_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] @@ -306,10 +305,10 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] @@ -384,7 +383,6 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS2_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] @@ -547,7 +545,6 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject { PyUnicodeUCS4_FromStringAndSize(u, size) @@ -561,7 +558,6 @@ pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS4_AsUTF8String(u) diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index 0becdad6dda..71037f6df3d 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -4,7 +4,7 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttr")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] PyObject_SetAttrString(o, attr_name, ptr::null_mut()) diff --git a/src/ffi3/setobject.rs b/src/ffi3/setobject.rs index 0df3ae156cb..a73c034b66d 100644 --- a/src/ffi3/setobject.rs +++ b/src/ffi3/setobject.rs @@ -11,13 +11,13 @@ use ffi3::object::*; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Check")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_CheckExact")] pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_Check")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_CheckExact")] pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } diff --git a/src/ffi3/weakrefobject.rs b/src/ffi3/weakrefobject.rs index 6d3d2af0d7f..08da7a60963 100644 --- a/src/ffi3/weakrefobject.rs +++ b/src/ffi3/weakrefobject.rs @@ -10,7 +10,7 @@ pub enum PyWeakReference {} } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_Check")] +#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } From f4deaf5c71b9e458e5095ced8ba9b343f7f46b8f Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 3 Apr 2018 23:16:00 +0300 Subject: [PATCH 028/138] remove dup --- src/ffi2/unicodeobject.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index 7ea26c45684..e099d3a1387 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -277,7 +277,6 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS4_RichCompare(left: *mut PyObject, right: *mut PyObject, op: c_int) -> *mut PyObject; #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] 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, From 11a1423045fe618afbce7b368f36323bf3cc85db Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 5 Apr 2018 12:14:31 +0300 Subject: [PATCH 029/138] remove mac-specific config --- .cargo/config | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .cargo/config diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index 4287c59637d..00000000000 --- a/.cargo/config +++ /dev/null @@ -1,3 +0,0 @@ -[build] -rustflags = ["-Clink-args=-Wl,-rpath,/Users/omerba/anaconda/lib/", - "-Clink-arg=-undefined", "-Clink-arg=dynamic_lookup"] \ No newline at end of file From aca3917075055a972a7db4f01145827245a73035 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 7 Apr 2018 21:27:34 +0300 Subject: [PATCH 030/138] fix all name mangling macros --- src/ffi2/boolobject.rs | 10 +- src/ffi2/bufferobject.rs | 12 +-- src/ffi2/bytearrayobject.rs | 18 ++-- src/ffi2/bytesobject.rs | 2 +- src/ffi2/cellobject.rs | 2 +- src/ffi2/ceval.rs | 36 +++---- src/ffi2/classobject.rs | 14 +-- src/ffi2/cobject.rs | 14 +-- src/ffi2/code.rs | 8 +- src/ffi2/complexobject.rs | 16 +-- src/ffi2/descrobject.rs | 14 +-- src/ffi2/dictobject.rs | 38 +++---- src/ffi2/eval.rs | 2 +- src/ffi2/fileobject.rs | 16 +-- src/ffi2/floatobject.rs | 14 +-- src/ffi2/frameobject.rs | 2 +- src/ffi2/funcobject.rs | 12 +-- src/ffi2/genobject.rs | 4 +- src/ffi2/import.rs | 14 +-- src/ffi2/iterobject.rs | 4 +- src/ffi2/listobject.rs | 30 +++--- src/ffi2/longobject.rs | 44 ++++---- src/ffi2/memoryobject.rs | 8 +- src/ffi2/methodobject.rs | 10 +- src/ffi2/mod.rs | 4 +- src/ffi2/modsupport.rs | 22 ++-- src/ffi2/moduleobject.rs | 6 +- src/ffi2/object.rs | 68 ++++++------ src/ffi2/objectabstract.rs | 206 ++++++++++++++++++------------------ src/ffi2/objimpl.rs | 4 +- src/ffi2/pycapsule.rs | 24 ++--- src/ffi2/pydebug.rs | 38 +++---- src/ffi2/pyerrors.rs | 138 ++++++++++++------------ src/ffi2/pymem.rs | 2 +- src/ffi2/pystate.rs | 22 ++-- src/ffi2/pythonrun.rs | 18 ++-- src/ffi2/rangeobject.rs | 2 +- src/ffi2/setobject.rs | 30 +++--- src/ffi2/sliceobject.rs | 12 +-- src/ffi2/stringobject.rs | 14 +-- src/ffi2/traceback.rs | 8 +- src/ffi2/tupleobject.rs | 14 +-- src/ffi2/unicodeobject.rs | 174 +++++++++++++++--------------- src/ffi2/warnings.rs | 4 +- src/ffi2/weakrefobject.rs | 14 +-- src/ffi3/boolobject.rs | 8 +- src/ffi3/bytearrayobject.rs | 20 ++-- src/ffi3/bytesobject.rs | 20 ++-- src/ffi3/ceval.rs | 34 +++--- src/ffi3/code.rs | 8 +- src/ffi3/codecs.rs | 4 +- src/ffi3/complexobject.rs | 12 +-- src/ffi3/descrobject.rs | 18 ++-- src/ffi3/dictobject.rs | 34 +++--- src/ffi3/eval.rs | 2 +- src/ffi3/fileobject.rs | 6 +- src/ffi3/floatobject.rs | 12 +-- src/ffi3/frameobject.rs | 2 +- src/ffi3/genobject.rs | 6 +- src/ffi3/import.rs | 16 +-- src/ffi3/intrcheck.rs | 4 +- src/ffi3/iterobject.rs | 4 +- src/ffi3/listobject.rs | 24 ++--- src/ffi3/longobject.rs | 44 ++++---- src/ffi3/memoryobject.rs | 8 +- src/ffi3/methodobject.rs | 10 +- src/ffi3/modsupport.rs | 24 ++--- src/ffi3/moduleobject.rs | 12 +-- src/ffi3/object.rs | 72 ++++++------- src/ffi3/objectabstract.rs | 190 ++++++++++++++++----------------- src/ffi3/objimpl.rs | 20 ++-- src/ffi3/pycapsule.rs | 24 ++--- src/ffi3/pydebug.rs | 26 ++--- src/ffi3/pyerrors.rs | 191 ++++++++++++++++----------------- src/ffi3/pymem.rs | 16 +-- src/ffi3/pystate.rs | 18 ++-- src/ffi3/pystrtod.rs | 4 +- src/ffi3/pythonrun.rs | 18 ++-- src/ffi3/rangeobject.rs | 2 +- src/ffi3/setobject.rs | 26 ++--- src/ffi3/sliceobject.rs | 12 +-- src/ffi3/sysmodule.rs | 8 +- src/ffi3/traceback.rs | 8 +- src/ffi3/tupleobject.rs | 14 +-- src/ffi3/unicodeobject.rs | 118 ++++++++++----------- src/ffi3/warnings.rs | 2 +- src/ffi3/weakrefobject.rs | 12 +-- 87 files changed, 1139 insertions(+), 1142 deletions(-) diff --git a/src/ffi2/boolobject.rs b/src/ffi2/boolobject.rs index 36887a88730..add24350184 100644 --- a/src/ffi2/boolobject.rs +++ b/src/ffi2/boolobject.rs @@ -5,18 +5,18 @@ use ffi2::intobject::PyIntObject; pub type PyBoolObject = PyIntObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Type")] + #[cfg_attr(PyPy, link_name="PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_ZeroStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_ZeroStruct")] static mut _Py_ZeroStruct: PyIntObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_TrueStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyIntObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_FromLong")] + #[cfg_attr(PyPy, link_name="PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Check")] +#[cfg_attr(PyPy, link_name="PyPyBool_Check")] pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyBool_Type; (Py_TYPE(op) == u) as c_int diff --git a/src/ffi2/bufferobject.rs b/src/ffi2/bufferobject.rs index b18302f5182..5a8e9cca66a 100644 --- a/src/ffi2/bufferobject.rs +++ b/src/ffi2/bufferobject.rs @@ -3,7 +3,7 @@ use ffi2::object::*; use ffi2::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Type")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_Type")] pub static mut PyBuffer_Type: PyTypeObject; } @@ -16,19 +16,19 @@ pub unsafe fn PyBuffer_Check(op : *mut PyObject) -> c_int { pub const Py_END_OF_BUFFER: Py_ssize_t = -1; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FromObject")] pub fn PyBuffer_FromObject(base: *mut PyObject, offset: Py_ssize_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromReadWriteObject")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FromReadWriteObject")] pub fn PyBuffer_FromReadWriteObject(base: *mut PyObject, offset: Py_ssize_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromMemory")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FromMemory")] pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromReadWriteMemory")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FromReadWriteMemory")] pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_New")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_New")] pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject; } \ No newline at end of file diff --git a/src/ffi2/bytearrayobject.rs b/src/ffi2/bytearrayobject.rs index 45cceaf919c..8e60265c33b 100644 --- a/src/ffi2/bytearrayobject.rs +++ b/src/ffi2/bytearrayobject.rs @@ -18,36 +18,36 @@ struct PyByteArrayObject { }*/ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Type")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Check")] +#[cfg_attr(PyPy, link_name="PyPyByteArray_Check")] pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyByteArray_Type) } -#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyByteArray_CheckExact")] 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" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Concat")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Concat")] pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_FromStringAndSize")] pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Size")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_AsString")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Resize")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Resize")] pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; } diff --git a/src/ffi2/bytesobject.rs b/src/ffi2/bytesobject.rs index 17b0379c009..9d2ef2209bd 100644 --- a/src/ffi2/bytesobject.rs +++ b/src/ffi2/bytesobject.rs @@ -7,7 +7,7 @@ pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString; -#[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromFormat")] +#[cfg_attr(PyPy, link_name="PyPyString_FromFormat")] pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat; pub use ffi2::stringobject::PyString_Size as PyBytes_Size; pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString; diff --git a/src/ffi2/cellobject.rs b/src/ffi2/cellobject.rs index 3fcea485d78..ee18c31e9df 100644 --- a/src/ffi2/cellobject.rs +++ b/src/ffi2/cellobject.rs @@ -15,7 +15,7 @@ struct PyCellObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCell_Type")] + #[cfg_attr(PyPy, link_name="PyPyCell_Type")] pub static mut PyCell_Type: PyTypeObject; } diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 7339c99a2a3..9dc0cd66279 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -6,39 +6,39 @@ use ffi2::pystate::{PyThreadState, Py_tracefunc}; use ffi2::pythonrun::PyCompilerFlags; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallObjectWithKeywords")] + #[cfg_attr(PyPy, link_name="PyPyEval_CallObjectWithKeywords")] pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallFunction")] + #[cfg_attr(PyPy, link_name="PyPyEval_CallFunction")] pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallMethod")] + #[cfg_attr(PyPy, link_name="PyPyEval_CallMethod")] pub fn PyEval_CallMethod(obj: *mut PyObject, methodname: *const c_char, format: *const c_char, ...) -> *mut PyObject; pub fn PyEval_SetProfile(func: Option, obj: *mut PyObject); pub fn PyEval_SetTrace(func: Option, obj: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetBuiltins")] + #[cfg_attr(PyPy, link_name="PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetGlobals")] + #[cfg_attr(PyPy, link_name="PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetLocals")] + #[cfg_attr(PyPy, link_name="PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut PyFrameObject; pub fn PyEval_GetRestricted() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_MergeCompilerFlags")] + #[cfg_attr(PyPy, link_name="PyPyEval_MergeCompilerFlags")] pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int; pub fn Py_FlushLine() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AddPendingCall")] + #[cfg_attr(PyPy, link_name="PyPy_AddPendingCall")] pub fn Py_AddPendingCall(func: Option c_int>, arg: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_MakePendingCalls")] + #[cfg_attr(PyPy, link_name="PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_SetRecursionLimit")] + #[cfg_attr(PyPy, link_name="PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetRecursionLimit")] + #[cfg_attr(PyPy, link_name="PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; @@ -47,26 +47,26 @@ use ffi2::pythonrun::PyCompilerFlags; 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_SaveThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_RestoreThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name="\u{1}__PyPyEval_SliceIndex")] + #[cfg_attr(PyPy, link_name="_PyPyEval_SliceIndex")] 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" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ThreadsInitialized")] + #[cfg_attr(PyPy, link_name="PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_InitThreads")] + #[cfg_attr(PyPy, link_name="PyPyEval_InitThreads")] pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); pub fn PyEval_ReleaseLock(); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_AcquireThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ReleaseThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); } \ No newline at end of file diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index 5bd388f14b3..5caabf3c858 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -50,12 +50,12 @@ pub struct PyMethodObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyClass_Type")] + #[cfg_attr(PyPy, link_name="PyPyClass_Type")] pub static mut PyClass_Type: PyTypeObject; // TODO: check why this symbol isn't exported by libpypy - #[cfg_attr(PyPy, link_name="\u{1}_PyPyClass_Type")] + #[cfg_attr(PyPy, link_name="PyPyClass_Type")] pub static mut PyInstance_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Type")] + #[cfg_attr(PyPy, link_name="PyPyMethod_Type")] pub static mut PyMethod_Type: PyTypeObject; } @@ -72,7 +72,7 @@ pub unsafe fn PyInstance_Check(op : *mut PyObject) -> c_int { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Check")] +#[cfg_attr(PyPy, link_name="PyPyMethod_Check")] pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyMethod_Type; (Py_TYPE(op) == u) as c_int @@ -85,12 +85,12 @@ pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { arg3: *mut PyObject) -> *mut PyObject; pub fn PyInstance_NewRaw(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_New")] + #[cfg_attr(PyPy, link_name="PyPyMethod_New")] pub fn PyMethod_New(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Function")] + #[cfg_attr(PyPy, link_name="PyPyMethod_Function")] pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethod_Self")] + #[cfg_attr(PyPy, link_name="PyPyMethod_Self")] 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) diff --git a/src/ffi2/cobject.rs b/src/ffi2/cobject.rs index 34045702a4e..b75aefa7457 100644 --- a/src/ffi2/cobject.rs +++ b/src/ffi2/cobject.rs @@ -2,7 +2,7 @@ use std::os::raw::{c_void, c_char, c_int}; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_Type")] + #[cfg_attr(PyPy, link_name="PyPyCObject_Type")] pub static mut PyCObject_Type: PyTypeObject; } @@ -12,23 +12,23 @@ pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_FromVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyCObject_FromVoidPtr")] pub fn PyCObject_FromVoidPtr(cobj: *mut c_void, destruct: Option) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_FromVoidPtrAndDesc")] + #[cfg_attr(PyPy, link_name="PyPyCObject_FromVoidPtrAndDesc")] pub fn PyCObject_FromVoidPtrAndDesc( cobj: *mut c_void, desc: *mut c_void, destruct: Option) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_AsVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyCObject_AsVoidPtr")] pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_GetDesc")] + #[cfg_attr(PyPy, link_name="PyPyCObject_GetDesc")] pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_Import")] + #[cfg_attr(PyPy, link_name="PyPyCObject_Import")] pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCObject_SetVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyCObject_SetVoidPtr")] pub fn PyCObject_SetVoidPtr(_self: *mut PyObject, cobj: *mut c_void) -> c_int; } \ No newline at end of file diff --git a/src/ffi2/code.rs b/src/ffi2/code.rs index c826c11850b..f083169039d 100644 --- a/src/ffi2/code.rs +++ b/src/ffi2/code.rs @@ -54,7 +54,7 @@ pub const CO_MAXBLOCKS : usize = 20; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyCode_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_New")] + #[cfg_attr(PyPy, link_name="PyPyCode_New")] pub fn PyCode_New(arg1: c_int, arg2: c_int, arg3: c_int, arg4: c_int, arg5: *mut PyObject, arg6: *mut PyObject, @@ -63,13 +63,13 @@ pub const CO_MAXBLOCKS : usize = 20; arg11: *mut PyObject, arg12: *mut PyObject, arg13: c_int, arg14: *mut PyObject) -> *mut PyCodeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_NewEmpty")] + #[cfg_attr(PyPy, link_name="PyPyCode_NewEmpty")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_Check")] + #[cfg_attr(PyPy, link_name="PyPyCode_Check")] //fn _PyCode_CheckLineNumber(co: *mut PyCodeObject, // lasti: c_int, // bounds: *mut PyAddrPair) -> c_int; @@ -84,7 +84,7 @@ pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_GetNumFree")] +#[cfg_attr(PyPy, link_name="PyPyCode_GetNumFree")] pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { ::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } \ No newline at end of file diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index 9e18108c447..457836c0984 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -32,34 +32,34 @@ pub struct PyComplexObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Type")] + #[cfg_attr(PyPy, link_name="PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Check")] +#[cfg_attr(PyPy, link_name="PyPyComplex_Check")] pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyComplex_CheckExact")] 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" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromCComplex")] + #[cfg_attr(PyPy, link_name="PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromDoubles")] + #[cfg_attr(PyPy, link_name="PyPyComplex_FromDoubles")] pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_RealAsDouble")] + #[cfg_attr(PyPy, link_name="PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_ImagAsDouble")] + #[cfg_attr(PyPy, link_name="PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_AsCComplex")] + #[cfg_attr(PyPy, link_name="PyPyComplex_AsCComplex")] pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex; diff --git a/src/ffi2/descrobject.rs b/src/ffi2/descrobject.rs index 02c85019c73..998b934149e 100644 --- a/src/ffi2/descrobject.rs +++ b/src/ffi2/descrobject.rs @@ -61,20 +61,20 @@ impl Clone for wrapperbase { pub const PyWrapperFlag_KEYWORDS : c_int = 1; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWrapperDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_Type")] + #[cfg_attr(PyPy, link_name="PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyGetSetDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemberDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyProperty_Type")] + #[cfg_attr(PyPy, link_name="PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDescr_NewClassMethod")] + #[cfg_attr(PyPy, link_name="PyPyDescr_NewClassMethod")] pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; pub fn PyDescr_NewMember(arg1: *mut PyTypeObject, @@ -92,7 +92,7 @@ pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_New")] + #[cfg_attr(PyPy, link_name="PyPyDictProxy_New")] //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) diff --git a/src/ffi2/dictobject.rs b/src/ffi2/dictobject.rs index bd9fc679849..0e5a05cf606 100644 --- a/src/ffi2/dictobject.rs +++ b/src/ffi2/dictobject.rs @@ -5,7 +5,7 @@ use ffi2::object::*; //pub enum PyDictObject { /* representation hidden */ } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Type")] + #[cfg_attr(PyPy, link_name="PyPyDict_Type")] pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -27,46 +27,46 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_New")] + #[cfg_attr(PyPy, link_name="PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_New")] + #[cfg_attr(PyPy, link_name="PyPyDictProxy_New")] pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Clear")] + #[cfg_attr(PyPy, link_name="PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Contains")] + #[cfg_attr(PyPy, link_name="PyPyDict_Contains")] pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Copy")] + #[cfg_attr(PyPy, link_name="PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItem")] + #[cfg_attr(PyPy, link_name="PyPyDict_DelItem")] pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItemString")] + #[cfg_attr(PyPy, link_name="PyPyDict_GetItemString")] pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItemString")] + #[cfg_attr(PyPy, link_name="PyPyDict_SetItemString")] pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItemString")] + #[cfg_attr(PyPy, link_name="PyPyDict_DelItemString")] pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Keys")] + #[cfg_attr(PyPy, link_name="PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Values")] + #[cfg_attr(PyPy, link_name="PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Items")] + #[cfg_attr(PyPy, link_name="PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Size")] + #[cfg_attr(PyPy, link_name="PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Next")] + #[cfg_attr(PyPy, link_name="PyPyDict_Next")] pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; @@ -77,10 +77,10 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { hash: c_long) -> c_int; pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/ - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Update")] + #[cfg_attr(PyPy, link_name="PyPyDict_Update")] pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Merge")] + #[cfg_attr(PyPy, link_name="PyPyDict_Merge")] 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, diff --git a/src/ffi2/eval.rs b/src/ffi2/eval.rs index 263d2c26a5b..b5a980c3267 100644 --- a/src/ffi2/eval.rs +++ b/src/ffi2/eval.rs @@ -3,7 +3,7 @@ use ffi2::object::PyObject; use ffi2::code::PyCodeObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_EvalCode")] + #[cfg_attr(PyPy, link_name="PyPyEval_EvalCode")] 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, diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index ef20bf4e07c..328b740defd 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -20,10 +20,10 @@ pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int { pub const PY_STDIOTEXTMODE : &'static str = "b"; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_FromString")] + #[cfg_attr(PyPy, link_name="PyPyFile_FromString")] pub fn PyFile_FromString(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_SetBufSize")] + #[cfg_attr(PyPy, link_name="PyPyFile_SetBufSize")] pub fn PyFile_SetBufSize(arg1: *mut PyObject, arg2: c_int); pub fn PyFile_SetEncoding(arg1: *mut PyObject, arg2: *const c_char) -> c_int; @@ -31,7 +31,7 @@ pub const PY_STDIOTEXTMODE : &'static str = "b"; arg2: *const c_char, errors: *mut c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_FromFile")] + #[cfg_attr(PyPy, link_name="PyPyFile_FromFile")] pub fn PyFile_FromFile(arg1: *mut FILE, arg2: *mut c_char, arg3: *mut c_char, arg4: Option c_int>) @@ -39,20 +39,20 @@ pub const PY_STDIOTEXTMODE : &'static str = "b"; pub fn PyFile_AsFile(arg1: *mut PyObject) -> *mut FILE; //pub fn PyFile_IncUseCount(arg1: *mut PyFileObject); //pub fn PyFile_DecUseCount(arg1: *mut PyFileObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_Name")] + #[cfg_attr(PyPy, link_name="PyPyFile_Name")] pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_GetLine")] + #[cfg_attr(PyPy, link_name="PyPyFile_GetLine")] pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteObject")] + #[cfg_attr(PyPy, link_name="PyPyFile_WriteObject")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteString")] + #[cfg_attr(PyPy, link_name="PyPyFile_WriteString")] pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsFileDescriptor")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsFileDescriptor")] pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int; pub fn Py_UniversalNewlineFgets(arg1: *mut c_char, arg2: c_int, arg3: *mut FILE, diff --git a/src/ffi2/floatobject.rs b/src/ffi2/floatobject.rs index f45bc7332c5..ad5c4ab7ae4 100644 --- a/src/ffi2/floatobject.rs +++ b/src/ffi2/floatobject.rs @@ -15,18 +15,18 @@ struct PyFloatObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Type")] + #[cfg_attr(PyPy, link_name="PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Check")] +#[cfg_attr(PyPy, link_name="PyPyFloat_Check")] pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyFloat_CheckExact")] pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyFloat_Type; (Py_TYPE(op) == u) as c_int @@ -35,13 +35,13 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { pub const PyFloat_STR_PRECISION : c_int = 12; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromString")] + #[cfg_attr(PyPy, link_name="PyPyFloat_FromString")] pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromDouble")] + #[cfg_attr(PyPy, link_name="PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_AsDouble")] + #[cfg_attr(PyPy, link_name="PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; @@ -50,7 +50,7 @@ pub const PyFloat_STR_PRECISION : c_int = 12; pub fn PyFloat_ClearFreeList() -> c_int; } -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_AS_DOUBLE")] +#[cfg_attr(PyPy, link_name="PyPyFloat_AS_DOUBLE")] pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double { (*(pyfloat as *mut PyFloatObject)).ob_fval } \ No newline at end of file diff --git a/src/ffi2/frameobject.rs b/src/ffi2/frameobject.rs index 69656813f39..fd361a8589c 100644 --- a/src/ffi2/frameobject.rs +++ b/src/ffi2/frameobject.rs @@ -67,7 +67,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { //} #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrame_New")] + #[cfg_attr(PyPy, link_name="PyPyFrame_New")] pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index a002b68b6e3..c5dc7b2b15b 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -2,12 +2,12 @@ use std::os::raw::c_int; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFunction_Type")] + #[cfg_attr(PyPy, link_name="PyPyFunction_Type")] pub static mut PyFunction_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFunction_Check")] +#[cfg_attr(PyPy, link_name="PyPyFunction_Check")] pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyFunction_Type; (Py_TYPE(op) == u) as c_int @@ -17,7 +17,7 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFunction_GetCode")] + #[cfg_attr(PyPy, link_name="PyPyFunction_GetCode")] 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; @@ -29,11 +29,11 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { -> c_int; pub static mut PyClassMethod_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyStaticMethod_Type")] + #[cfg_attr(PyPy, link_name="PyPyStaticMethod_Type")] pub static mut PyStaticMethod_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyClassMethod_New")] + #[cfg_attr(PyPy, link_name="PyPyClassMethod_New")] pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyStaticMethod_New")] + #[cfg_attr(PyPy, link_name="PyPyStaticMethod_New")] pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; } \ No newline at end of file diff --git a/src/ffi2/genobject.rs b/src/ffi2/genobject.rs index cba10c25a15..ded528accb6 100644 --- a/src/ffi2/genobject.rs +++ b/src/ffi2/genobject.rs @@ -23,13 +23,13 @@ pub struct PyGenObject { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_Check")] +#[cfg_attr(PyPy, link_name="PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index d0f410cc335..eaf8a0e2694 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -29,10 +29,10 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_ImportModule")] pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleNoBlock")] + #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleNoBlock")] pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; pub fn PyImport_ImportModuleLevel(name: *mut c_char, @@ -42,21 +42,21 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, level: c_int) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ReloadModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_AddModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModule")] pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModuleEx")] + #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModuleEx")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_GetModuleDict")] + #[cfg_attr(PyPy, link_name="PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_ImportFrozenModule(name: *mut c_char) -> c_int; diff --git a/src/ffi2/iterobject.rs b/src/ffi2/iterobject.rs index f0433ef9e26..86f0a8a43e9 100644 --- a/src/ffi2/iterobject.rs +++ b/src/ffi2/iterobject.rs @@ -5,9 +5,9 @@ use ffi2::object::*; pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySeqIter_New")] + #[cfg_attr(PyPy, link_name="PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallIter_New")] + #[cfg_attr(PyPy, link_name="PyPyCallIter_New")] pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi2/listobject.rs b/src/ffi2/listobject.rs index 805ce266d54..96661ec1db1 100644 --- a/src/ffi2/listobject.rs +++ b/src/ffi2/listobject.rs @@ -17,7 +17,7 @@ pub struct PyListObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Type")] + #[cfg_attr(PyPy, link_name="PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; } @@ -35,53 +35,53 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { // Macro, trading safety for speed #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_ITEM")] +#[cfg_attr(PyPy, link_name="PyPyList_GET_ITEM")] 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(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_SIZE")] +#[cfg_attr(PyPy, link_name="PyPyList_GET_SIZE")] 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(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SET_ITEM")] +#[cfg_attr(PyPy, link_name="PyPyList_SET_ITEM")] pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { *(*(op as *mut PyListObject)).ob_item.offset(i as isize) = v; } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_New")] + #[cfg_attr(PyPy, link_name="PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Size")] + #[cfg_attr(PyPy, link_name="PyPyList_Size")] pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyList_GetItem")] pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyList_SetItem")] pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Insert")] + #[cfg_attr(PyPy, link_name="PyPyList_Insert")] pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Append")] + #[cfg_attr(PyPy, link_name="PyPyList_Append")] pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetSlice")] + #[cfg_attr(PyPy, link_name="PyPyList_GetSlice")] pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetSlice")] + #[cfg_attr(PyPy, link_name="PyPyList_SetSlice")] pub fn PyList_SetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t, itemlist: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Sort")] + #[cfg_attr(PyPy, link_name="PyPyList_Sort")] pub fn PyList_Sort(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Reverse")] + #[cfg_attr(PyPy, link_name="PyPyList_Reverse")] pub fn PyList_Reverse(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_AsTuple")] + #[cfg_attr(PyPy, link_name="PyPyList_AsTuple")] pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject; //fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) //-> *mut PyObject; diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 0299e51040a..26f82fc08fa 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -7,7 +7,7 @@ use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_Type")] + #[cfg_attr(PyPy, link_name="PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } @@ -23,59 +23,59 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromLong")] pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSsize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLongLong")] pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromDouble")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromDouble")] pub fn PyLong_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromString")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromString")] 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")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnicode")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromUnicode")] pub fn PyLong_FromUnicode(u: *mut ::ffi2::unicodeobject::Py_UNICODE, length: Py_ssize_t, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLong")] pub fn PyLong_AsLong(pylong: *mut PyObject) -> c_long; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongAndOverflow")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLongAndOverflow")] pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLongAndOverflow")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLongAndOverflow")] pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsSsize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLong")] pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongMask")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLongMask")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLongMask")] pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsDouble")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsDouble")] pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void; pub fn PyLong_GetInfo() -> *mut PyObject; diff --git a/src/ffi2/memoryobject.rs b/src/ffi2/memoryobject.rs index 6d6487ab636..de58612c151 100644 --- a/src/ffi2/memoryobject.rs +++ b/src/ffi2/memoryobject.rs @@ -3,12 +3,12 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Type")] + #[cfg_attr(PyPy, link_name="PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Check")] +#[cfg_attr(PyPy, link_name="PyPyMemoryView_Check")] pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyMemoryView_Type; (Py_TYPE(op) == u) as c_int @@ -29,9 +29,9 @@ pub unsafe fn PyMemoryView_GET_BASE(op : *mut PyObject) -> *mut PyObject { pub fn PyMemoryView_GetContiguous(base: *mut PyObject, buffertype: c_int, fort: c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromBuffer")] + #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromBuffer")] pub fn PyMemoryView_FromBuffer(info: *mut Py_buffer) -> *mut PyObject; } diff --git a/src/ffi2/methodobject.rs b/src/ffi2/methodobject.rs index 3d5ace9f1a5..3b991374c70 100644 --- a/src/ffi2/methodobject.rs +++ b/src/ffi2/methodobject.rs @@ -3,12 +3,12 @@ use std::os::raw::{c_char, c_int}; use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Type")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Check")] +#[cfg_attr(PyPy, link_name="PyPyCFunction_Check")] pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyCFunction_Type; (Py_TYPE(op) == u) as c_int @@ -28,7 +28,7 @@ pub type PyNoArgsFunction = #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_GetFunction")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; @@ -102,10 +102,10 @@ struct PyCFunctionObject { */ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FindMethod")] + #[cfg_attr(PyPy, link_name="PyPy_FindMethod")] pub fn Py_FindMethod(methods: *mut PyMethodDef, slf: *mut PyObject, name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_NewEx")] 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, diff --git a/src/ffi2/mod.rs b/src/ffi2/mod.rs index 88c25d5395b..2b9c627f475 100644 --- a/src/ffi2/mod.rs +++ b/src/ffi2/mod.rs @@ -133,10 +133,10 @@ pub const Py_eval_input: c_int = 258; #[cfg(not(py_sys_config="Py_USING_UNICODE"))] #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Check")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_Check")] pub fn PyUnicode_Check(op : *mut PyObject) -> libc::c_int { 0 } #[cfg(not(py_sys_config="Py_USING_UNICODE"))] #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_CheckExact")] pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 } \ No newline at end of file diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index fd05407c5c2..05212aba0b7 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -5,42 +5,42 @@ use ffi2::object::PyObject; use ffi2::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_Parse")] + #[cfg_attr(PyPy, link_name="PyPyArg_Parse")] pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTuple")] + #[cfg_attr(PyPy, link_name="PyPyArg_ParseTuple")] pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTupleAndKeywords")] + #[cfg_attr(PyPy, link_name="PyPyArg_ParseTupleAndKeywords")] pub fn PyArg_ParseTupleAndKeywords(args: *mut PyObject, kw: *mut PyObject, format: *const c_char, keywords: *mut *mut c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_UnpackTuple")] + #[cfg_attr(PyPy, link_name="PyPyArg_UnpackTuple")] pub fn PyArg_UnpackTuple(args: *mut PyObject, name: *const c_char, min: Py_ssize_t, max: Py_ssize_t, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BuildValue")] + #[cfg_attr(PyPy, link_name="PyPy_BuildValue")] pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_BuildValue_SizeT")] + #[cfg_attr(PyPy, link_name="_PyPy_BuildValue_SizeT")] //fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyArg_NoKeywords")] + #[cfg_attr(PyPy, link_name="_PyPyArg_NoKeywords")] //fn _PyArg_NoKeywords(funcname: *const c_char, // kw: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddObject")] + #[cfg_attr(PyPy, link_name="PyPyModule_AddObject")] pub fn PyModule_AddObject(module: *mut PyObject, name: *const c_char, value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddIntConstant")] + #[cfg_attr(PyPy, link_name="PyPyModule_AddIntConstant")] pub fn PyModule_AddIntConstant(module: *mut PyObject, name: *const c_char, value: c_long) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddStringConstant")] + #[cfg_attr(PyPy, link_name="PyPyModule_AddStringConstant")] 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")))] - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_InitPyPyModule")] + #[cfg_attr(PyPy, link_name="_PyPy_InitPyPyModule")] fn Py_InitModule4_64(name: *const c_char, methods: *mut PyMethodDef, doc: *const c_char, _self: *mut PyObject, diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index 36a7fa9c1b9..a802c82fab1 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -4,12 +4,12 @@ use ffi2::object::*; use ffi2::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Type")] + #[cfg_attr(PyPy, link_name="PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Check")] +#[cfg_attr(PyPy, link_name="PyPyModule_Check")] pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } @@ -22,7 +22,7 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDict")] + #[cfg_attr(PyPy, link_name="PyPyModule_GetDict")] 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; diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 24b676ddb6f..7d11584d8b3 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -612,9 +612,9 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Type")] + #[cfg_attr(PyPy, link_name="PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBaseObject_Type")] + #[cfg_attr(PyPy, link_name="PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; } @@ -631,34 +631,34 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Ready")] + #[cfg_attr(PyPy, link_name="PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericNew")] + #[cfg_attr(PyPy, link_name="PyPyType_GenericNew")] pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyType_Lookup")] + #[cfg_attr(PyPy, link_name="_PyPyType_Lookup")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Modified")] + #[cfg_attr(PyPy, link_name="PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Print")] + #[cfg_attr(PyPy, link_name="PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int; fn _PyObject_Dump(o: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Repr")] + #[cfg_attr(PyPy, link_name="PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Str")] + #[cfg_attr(PyPy, link_name="PyPyObject_Str")] fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Bytes")] +#[cfg_attr(PyPy, link_name="PyPyObject_Bytes")] pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { PyObject_Str(o) } @@ -666,56 +666,56 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(py_sys_config = "Py_USING_UNICODE")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Unicode")] + #[cfg_attr(PyPy, link_name="PyPyObject_Unicode")] pub fn PyObject_Unicode(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Compare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompare")] + #[cfg_attr(PyPy, link_name="PyPyObject_RichCompare")] pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompareBool")] + #[cfg_attr(PyPy, link_name="PyPyObject_RichCompareBool")] pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttrString")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetAttrString")] pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetAttrString")] pub fn PyObject_SetAttrString(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttrString")] + #[cfg_attr(PyPy, link_name="PyPyObject_HasAttrString")] pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetAttr")] pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetAttr")] pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_HasAttr")] pub fn PyObject_HasAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GetDictPtr")] + #[cfg_attr(PyPy, link_name="_PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SelfIter")] + #[cfg_attr(PyPy, link_name="PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericGetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericSetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_GenericSetAttr")] pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Hash")] + #[cfg_attr(PyPy, link_name="PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HashNotImplemented")] + #[cfg_attr(PyPy, link_name="PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsTrue")] + #[cfg_attr(PyPy, link_name="PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Not")] + #[cfg_attr(PyPy, link_name="PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallable_Check")] + #[cfg_attr(PyPy, link_name="PyPyCallable_Check")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_ClearWeakRefs")] + #[cfg_attr(PyPy, link_name="PyPyObject_ClearWeakRefs")] pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject); fn _PyObject_SlotCompare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; fn _PyObject_GenericGetAttrWithDict(arg1: *mut PyObject, @@ -725,13 +725,13 @@ extern "C" { arg2: *mut PyObject, arg3: *mut PyObject, arg4: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Dir")] + #[cfg_attr(PyPy, link_name="PyPyObject_Dir")] 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); - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_HashDouble")] + #[cfg_attr(PyPy, link_name="_PyPy_HashDouble")] fn _Py_HashDouble(arg1: c_double) -> c_long; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_HashPointer")] + #[cfg_attr(PyPy, link_name="_PyPy_HashPointer")] fn _Py_HashPointer(arg1: *mut c_void) -> c_long; } @@ -876,9 +876,9 @@ extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NoneStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NotImplementedStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index 61ae45b35ac..af8e5497e72 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -5,13 +5,13 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttrString")] +#[cfg_attr(PyPy, link_name="PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttr")] +#[cfg_attr(PyPy, link_name="PyPyObject_DelAttr")] pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_int { PyObject_SetAttr(o, attr_name, ptr::null_mut()) } @@ -19,88 +19,88 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject, result: *mut c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Call")] + #[cfg_attr(PyPy, link_name="PyPyObject_Call")] pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, kw: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallObject")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallObject")] pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunction")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallFunction")] pub fn PyObject_CallFunction(callable_object: *mut PyObject, format: *mut c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethod")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallMethod")] pub fn PyObject_CallMethod(o: *mut PyObject, m: *mut c_char, format: *mut c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_CallFunction_SizeT")] + #[cfg_attr(PyPy, link_name="_PyPyObject_CallFunction_SizeT")] fn _PyObject_CallFunction_SizeT(callable: *mut PyObject, format: *mut c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_CallMethod_SizeT")] + #[cfg_attr(PyPy, link_name="_PyPyObject_CallMethod_SizeT")] fn _PyObject_CallMethod_SizeT(o: *mut PyObject, name: *mut c_char, format: *mut c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunctionObjArgs")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallFunctionObjArgs")] pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethodObjArgs")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallMethodObjArgs")] pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] + #[cfg_attr(PyPy, link_name="PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Size")] + #[cfg_attr(PyPy, link_name="PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_LengthHint")] + #[cfg_attr(PyPy, link_name="PyPyObject_LengthHint")] pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetItem")] pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetItem")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsCharBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsCharBuffer")] pub fn PyObject_AsCharBuffer(obj: *mut PyObject, buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CheckReadBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsReadBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsReadBuffer")] pub fn PyObject_AsReadBuffer(obj: *mut PyObject, buffer: *mut *const c_void, buffer_len: *mut Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsWriteBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsWriteBuffer")] pub fn PyObject_AsWriteBuffer(obj: *mut PyObject, buffer: *mut *mut c_void, buffer_len: *mut Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetBuffer")] pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_GetPointer")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_GetPointer")] pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_ToContiguous")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_ToContiguous")] pub fn PyBuffer_ToContiguous(buf: *mut c_void, view: *mut Py_buffer, len: Py_ssize_t, fort: c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromContiguous")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FromContiguous")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_IsContiguous")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_IsContiguous")] pub fn PyBuffer_IsContiguous(view: *mut Py_buffer, fort: c_char) -> c_int; pub fn PyBuffer_FillContiguousStrides(ndims: c_int, @@ -108,205 +108,205 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ strides: *mut Py_ssize_t, itemsize: c_int, fort: c_char); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FillInfo")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FillInfo")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Release")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Format")] + #[cfg_attr(PyPy, link_name="PyPyObject_Format")] pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetIter")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Next")] + #[cfg_attr(PyPy, link_name="PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Check")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Add")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Add")] pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Subtract")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Subtract")] pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Multiply")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Multiply")] pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Divide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Divide")] pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_FloorDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_FloorDivide")] pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_TrueDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_TrueDivide")] pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Remainder")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Remainder")] pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Divmod")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Divmod")] pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Power")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Power")] pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Negative")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Positive")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Absolute")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Invert")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Lshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Lshift")] pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Rshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Rshift")] pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_And")] + #[cfg_attr(PyPy, link_name="PyPyNumber_And")] pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Xor")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Xor")] pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Or")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Index")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_AsSsize_t")] + #[cfg_attr(PyPy, link_name="PyPyNumber_AsSsize_t")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Long")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Float")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAdd")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAdd")] pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceSubtract")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceSubtract")] pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceMultiply")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceMultiply")] pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceDivide")] pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceFloorDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceFloorDivide")] pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceTrueDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceTrueDivide")] pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRemainder")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRemainder")] pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlacePower")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlacePower")] pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceLshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceLshift")] pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRshift")] pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAnd")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAnd")] pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceXor")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceXor")] pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceOr")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceOr")] pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Check")] + #[cfg_attr(PyPy, link_name="PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Size")] + #[cfg_attr(PyPy, link_name="PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Length")] + #[cfg_attr(PyPy, link_name="PyPySequence_Length")] pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Concat")] + #[cfg_attr(PyPy, link_name="PyPySequence_Concat")] pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Repeat")] + #[cfg_attr(PyPy, link_name="PyPySequence_Repeat")] pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetItem")] + #[cfg_attr(PyPy, link_name="PyPySequence_GetItem")] pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetSlice")] + #[cfg_attr(PyPy, link_name="PyPySequence_GetSlice")] pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetItem")] + #[cfg_attr(PyPy, link_name="PyPySequence_SetItem")] pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelItem")] + #[cfg_attr(PyPy, link_name="PyPySequence_DelItem")] pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetSlice")] + #[cfg_attr(PyPy, link_name="PyPySequence_SetSlice")] pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelSlice")] + #[cfg_attr(PyPy, link_name="PyPySequence_DelSlice")] pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Tuple")] + #[cfg_attr(PyPy, link_name="PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_List")] + #[cfg_attr(PyPy, link_name="PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast")] + #[cfg_attr(PyPy, link_name="PyPySequence_Fast")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Contains")] + #[cfg_attr(PyPy, link_name="PyPySequence_Contains")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Index")] + #[cfg_attr(PyPy, link_name="PyPySequence_Index")] pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceConcat")] + #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceConcat")] pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceRepeat")] + #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceRepeat")] pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Check")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Size")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Length")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Length")] pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKeyString")] + #[cfg_attr(PyPy, link_name="PyPyMapping_HasKeyString")] pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKey")] + #[cfg_attr(PyPy, link_name="PyPyMapping_HasKey")] pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_GetItemString")] + #[cfg_attr(PyPy, link_name="PyPyMapping_GetItemString")] pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_SetItemString")] + #[cfg_attr(PyPy, link_name="PyPyMapping_SetItemString")] pub fn PyMapping_SetItemString(o: *mut PyObject, key: *mut c_char, value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsInstance")] + #[cfg_attr(PyPy, link_name="PyPyObject_IsInstance")] pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsSubclass")] + #[cfg_attr(PyPy, link_name="PyPyObject_IsSubclass")] pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } @@ -323,7 +323,7 @@ pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int { #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Check")] +#[cfg_attr(PyPy, link_name="PyPyIter_Check")] pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; (PyType_HasFeature(t, Py_TPFLAGS_HAVE_ITER) != 0 && @@ -334,7 +334,7 @@ pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyIndex_Check")] +#[cfg_attr(PyPy, link_name="PyPyIndex_Check")] pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let n = (*t).tp_as_number; @@ -342,10 +342,10 @@ pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast_GET_SIZE")] +#[cfg_attr(PyPy, link_name="PyPySequence_Fast_GET_SIZE")] pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_SIZE")] + #[cfg_attr(PyPy, link_name="PyPyList_GET_SIZE")] ffi2::listobject::PyList_GET_SIZE(o) } else { ffi2::tupleobject::PyTuple_GET_SIZE(o) @@ -353,10 +353,10 @@ pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast_GET_ITEM")] +#[cfg_attr(PyPy, link_name="PyPySequence_Fast_GET_ITEM")] pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GET_ITEM")] + #[cfg_attr(PyPy, link_name="PyPyList_GET_ITEM")] ffi2::listobject::PyList_GET_ITEM(o, i) } else { ffi2::tupleobject::PyTuple_GET_ITEM(o, i) @@ -364,7 +364,7 @@ pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mu } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast_ITEMS")] +#[cfg_attr(PyPy, link_name="PyPySequence_Fast_ITEMS")] 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 @@ -374,7 +374,7 @@ pub unsafe fn PySequence_Fast_ITEMS(o : *mut PyObject) -> *mut *mut PyObject { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_ITEM")] +#[cfg_attr(PyPy, link_name="PyPySequence_ITEM")] 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) } @@ -394,19 +394,19 @@ pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Keys")] +#[cfg_attr(PyPy, link_name="PyPyMapping_Keys")] pub unsafe fn PyMapping_Keys(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "keys\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Values")] +#[cfg_attr(PyPy, link_name="PyPyMapping_Values")] pub unsafe fn PyMapping_Values(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "values\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Items")] +#[cfg_attr(PyPy, link_name="PyPyMapping_Items")] pub unsafe fn PyMapping_Items(o : *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "items\0".as_ptr() as *mut i8, ptr::null_mut()) } \ No newline at end of file diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index 5691f06e85c..3472cd5f7f0 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -4,9 +4,9 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Malloc")] + #[cfg_attr(PyPy, link_name="PyPyObject_Malloc")] pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Realloc")] + #[cfg_attr(PyPy, link_name="PyPyObject_Realloc")] pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; pub fn PyObject_Free(arg1: *mut c_void); diff --git a/src/ffi2/pycapsule.rs b/src/ffi2/pycapsule.rs index f3d4ea7a94e..eec17cbf776 100644 --- a/src/ffi2/pycapsule.rs +++ b/src/ffi2/pycapsule.rs @@ -2,7 +2,7 @@ use std::os::raw::{c_void, c_char, c_int}; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Type")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -14,35 +14,35 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_New")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_New")] pub fn PyCapsule_New(pointer: *mut c_void, name: *const c_char, destructor: Option) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetPointer")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetPointer")] pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetDestructor")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetName")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetContext")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_IsValid")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_IsValid")] pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetPointer")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetPointer")] pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetDestructor")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetDestructor")] pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, destructor: Option) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetName")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetName")] pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetContext")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetContext")] pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Import")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_Import")] pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; } \ No newline at end of file diff --git a/src/ffi2/pydebug.rs b/src/ffi2/pydebug.rs index 6b51cc4827a..27d4f04fef8 100644 --- a/src/ffi2/pydebug.rs +++ b/src/ffi2/pydebug.rs @@ -1,43 +1,43 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DebugFlag")] + #[cfg_attr(PyPy, link_name="PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_VerboseFlag")] + #[cfg_attr(PyPy, link_name="PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InteractiveFlag")] + #[cfg_attr(PyPy, link_name="PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InspectFlag")] + #[cfg_attr(PyPy, link_name="PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_OptimizeFlag")] + #[cfg_attr(PyPy, link_name="PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoSiteFlag")] + #[cfg_attr(PyPy, link_name="PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BytesWarningFlag")] + #[cfg_attr(PyPy, link_name="PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_UseClassExceptionsFlag")] + #[cfg_attr(PyPy, link_name="PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FrozenFlag")] + #[cfg_attr(PyPy, link_name="PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_TabcheckFlag")] + #[cfg_attr(PyPy, link_name="PyPy_TabcheckFlag")] pub static mut Py_TabcheckFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_UnicodeFlag")] + #[cfg_attr(PyPy, link_name="PyPy_UnicodeFlag")] pub static mut Py_UnicodeFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IgnoreEnvironmentFlag")] + #[cfg_attr(PyPy, link_name="PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DivisionWarningFlag")] + #[cfg_attr(PyPy, link_name="PyPy_DivisionWarningFlag")] pub static mut Py_DivisionWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DontWriteBytecodeFlag")] + #[cfg_attr(PyPy, link_name="PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoUserSiteDirectory")] + #[cfg_attr(PyPy, link_name="PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_QnewFlag")] + #[cfg_attr(PyPy, link_name="_PyPy_QnewFlag")] pub static mut _Py_QnewFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_Py3kWarningFlag")] + #[cfg_attr(PyPy, link_name="PyPy_Py3kWarningFlag")] pub static mut Py_Py3kWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_HashRandomizationFlag")] + #[cfg_attr(PyPy, link_name="PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FatalError")] + #[cfg_attr(PyPy, link_name="PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char); } \ No newline at end of file diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index 53c7d5fd704..459a4743870 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -7,28 +7,28 @@ use ffi2::stringobject::PyString_AS_STRING; use ffi2::unicodeobject::Py_UNICODE; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetNone")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetObject")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetString")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetString")] pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Occurred")] + #[cfg_attr(PyPy, link_name="PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Clear")] + #[cfg_attr(PyPy, link_name="PyPyErr_Clear")] pub fn PyErr_Clear(); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Fetch")] + #[cfg_attr(PyPy, link_name="PyPyErr_Fetch")] pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Restore")] + #[cfg_attr(PyPy, link_name="PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_GivenExceptionMatches")] + #[cfg_attr(PyPy, link_name="PyPyErr_GivenExceptionMatches")] pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_ExceptionMatches")] + #[cfg_attr(PyPy, link_name="PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NormalizeException")] + #[cfg_attr(PyPy, link_name="PyPyErr_NormalizeException")] pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject); @@ -56,7 +56,7 @@ pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyExceptionInstance_Class")] +#[cfg_attr(PyPy, link_name="PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { if PyInstance_Check(x) != 0 { (*(x as *mut PyInstanceObject)).in_class as *mut PyObject @@ -66,138 +66,138 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BaseException")] + #[cfg_attr(PyPy, link_name="PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Exception")] + #[cfg_attr(PyPy, link_name="PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_StopIteration")] + #[cfg_attr(PyPy, link_name="PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_GeneratorExit")] + #[cfg_attr(PyPy, link_name="PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; pub static mut PyExc_StandardError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ArithmeticError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_LookupError")] + #[cfg_attr(PyPy, link_name="PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AssertionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AttributeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_EOFError")] + #[cfg_attr(PyPy, link_name="PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FloatingPointError")] + #[cfg_attr(PyPy, link_name="PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OSError")] + #[cfg_attr(PyPy, link_name="PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndexError")] + #[cfg_attr(PyPy, link_name="PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyError")] + #[cfg_attr(PyPy, link_name="PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyboardInterrupt")] + #[cfg_attr(PyPy, link_name="PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_MemoryError")] + #[cfg_attr(PyPy, link_name="PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NameError")] + #[cfg_attr(PyPy, link_name="PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OverflowError")] + #[cfg_attr(PyPy, link_name="PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NotImplementedError")] + #[cfg_attr(PyPy, link_name="PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxError")] + #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndentationError")] + #[cfg_attr(PyPy, link_name="PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TabError")] + #[cfg_attr(PyPy, link_name="PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ReferenceError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] + #[cfg_attr(PyPy, link_name="PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemExit")] + #[cfg_attr(PyPy, link_name="PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnboundLocalError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeEncodeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeTranslateError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ValueError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ZeroDivisionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BufferError")] + #[cfg_attr(PyPy, link_name="PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; pub static mut PyExc_MemoryErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RecursionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_RecursionError")] pub static mut PyExc_RecursionErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Warning")] + #[cfg_attr(PyPy, link_name="PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UserWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_DeprecationWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_PendingDeprecationWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FutureWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BytesWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadArgument")] + #[cfg_attr(PyPy, link_name="PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NoMemory")] + #[cfg_attr(PyPy, link_name="PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrno")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilenameObject")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilename")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrnoWithFilename")] pub fn PyErr_SetFromErrnoWithFilename(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Format")] + #[cfg_attr(PyPy, link_name="PyPyErr_Format")] pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadInternalCall")] + #[cfg_attr(PyPy, link_name="PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall(); pub fn _PyErr_BadInternalCall(filename: *mut c_char, lineno: c_int); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewException")] + #[cfg_attr(PyPy, link_name="PyPyErr_NewException")] pub fn PyErr_NewException(name: *mut c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewExceptionWithDoc")] + #[cfg_attr(PyPy, link_name="PyPyErr_NewExceptionWithDoc")] pub fn PyErr_NewExceptionWithDoc(name: *mut c_char, doc: *mut c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WriteUnraisable")] + #[cfg_attr(PyPy, link_name="PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_CheckSignals")] + #[cfg_attr(PyPy, link_name="PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetInterrupt")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; pub fn PyErr_SyntaxLocation(arg1: *const c_char, diff --git a/src/ffi2/pymem.rs b/src/ffi2/pymem.rs index ef208151f47..cb15a9a8835 100644 --- a/src/ffi2/pymem.rs +++ b/src/ffi2/pymem.rs @@ -1,7 +1,7 @@ use libc::{c_void, size_t}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Malloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_Malloc")] 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); diff --git a/src/ffi2/pystate.rs b/src/ffi2/pystate.rs index 648bf7d0a08..f4abbcd050c 100644 --- a/src/ffi2/pystate.rs +++ b/src/ffi2/pystate.rs @@ -60,41 +60,41 @@ pub enum PyGILState_STATE { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Get")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Get")] //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); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_New")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_New")] 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); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Clear")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Delete")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState); #[cfg(py_sys_config="WITH_THREAD")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_DeleteCurrent")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent(); pub fn PyThreadState_Get() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Swap")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_GetDict")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Ensure")] + #[cfg_attr(PyPy, link_name="PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Release")] + #[cfg_attr(PyPy, link_name="PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; fn _PyThread_CurrentFrames() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyInterpreterState_Head")] + #[cfg_attr(PyPy, link_name="PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyInterpreterState_Next")] + #[cfg_attr(PyPy, link_name="PyPyInterpreterState_Next")] pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) -> *mut PyInterpreterState; pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index f131f8f2397..a5276d633c4 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -27,14 +27,14 @@ pub enum Struct_symtable { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetProgramName")] + #[cfg_attr(PyPy, link_name="PyPy_GetProgramName")] 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(); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IsInitialized")] + #[cfg_attr(PyPy, link_name="PyPy_IsInitialized")] pub fn Py_IsInitialized() -> c_int; pub fn Py_NewInterpreter() -> *mut PyThreadState; pub fn Py_EndInterpreter(arg1: *mut PyThreadState); @@ -80,7 +80,7 @@ pub enum Struct_symtable { } arg3: c_int, arg4: c_int) -> *mut Struct__node; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_StringFlags")] + #[cfg_attr(PyPy, link_name="PyPyRun_StringFlags")] pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int, arg3: *mut PyObject, arg4: *mut PyObject, arg5: *mut PyCompilerFlags) -> *mut PyObject; @@ -88,7 +88,7 @@ pub enum Struct_symtable { } arg3: c_int, arg4: *mut PyObject, arg5: *mut PyObject, arg6: c_int, arg7: *mut PyCompilerFlags) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_CompileStringFlags")] + #[cfg_attr(PyPy, link_name="PyPy_CompileStringFlags")] pub fn Py_CompileStringFlags(arg1: *const c_char, arg2: *const c_char, arg3: c_int, @@ -96,14 +96,14 @@ pub enum Struct_symtable { } pub fn Py_SymtableString(arg1: *const c_char, arg2: *const c_char, arg3: c_int) -> *mut Struct_symtable; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Print")] + #[cfg_attr(PyPy, link_name="PyPyErr_Print")] pub fn PyErr_Print(); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_PrintEx")] + #[cfg_attr(PyPy, link_name="PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Display")] + #[cfg_attr(PyPy, link_name="PyPyErr_Display")] pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AtExit")] + #[cfg_attr(PyPy, link_name="PyPy_AtExit")] pub fn Py_AtExit(func: Option) -> c_int; pub fn Py_Exit(arg1: c_int); @@ -115,7 +115,7 @@ pub enum Struct_symtable { } pub fn Py_GetPrefix() -> *mut c_char; pub fn Py_GetExecPrefix() -> *mut c_char; pub fn Py_GetPath() -> *mut c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetVersion")] + #[cfg_attr(PyPy, link_name="PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; diff --git a/src/ffi2/rangeobject.rs b/src/ffi2/rangeobject.rs index 15d3fe175a1..0266225ac82 100644 --- a/src/ffi2/rangeobject.rs +++ b/src/ffi2/rangeobject.rs @@ -2,7 +2,7 @@ use std::os::raw::c_int; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRange_Type")] + #[cfg_attr(PyPy, link_name="PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; } diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index c5f1fe2aec4..49194c0245e 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -5,21 +5,21 @@ use ffi2::object::*; //enum PySetObject { /* representation hidden */ } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Type")] + #[cfg_attr(PyPy, link_name="PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Type")] + #[cfg_attr(PyPy, link_name="PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyFrozenSet_CheckExact")] 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] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyAnySet_CheckExact")] pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { let s : *mut PyTypeObject = &mut PySet_Type; let f : *mut PyTypeObject = &mut PyFrozenSet_Type; @@ -27,7 +27,7 @@ pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_Check")] +#[cfg_attr(PyPy, link_name="PyPyAnySet_Check")] pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { (PyAnySet_CheckExact(ob) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 || @@ -35,42 +35,42 @@ pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Check")] +#[cfg_attr(PyPy, link_name="PyPySet_Check")] 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] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Check")] +#[cfg_attr(PyPy, link_name="PyPyFrozenSet_Check")] 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" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_New")] + #[cfg_attr(PyPy, link_name="PyPySet_New")] pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_New")] + #[cfg_attr(PyPy, link_name="PyPyFrozenSet_New")] pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Size")] + #[cfg_attr(PyPy, link_name="PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Clear")] + #[cfg_attr(PyPy, link_name="PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Contains")] + #[cfg_attr(PyPy, link_name="PyPySet_Contains")] pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Discard")] + #[cfg_attr(PyPy, link_name="PyPySet_Discard")] pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Add")] + #[cfg_attr(PyPy, link_name="PyPySet_Add")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Pop")] + #[cfg_attr(PyPy, link_name="PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; //pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) // -> c_int; diff --git a/src/ffi2/sliceobject.rs b/src/ffi2/sliceobject.rs index 4830c2b52f6..1fec20c44d5 100644 --- a/src/ffi2/sliceobject.rs +++ b/src/ffi2/sliceobject.rs @@ -3,7 +3,7 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_EllipsisObject")] + #[cfg_attr(PyPy, link_name="_PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -27,26 +27,26 @@ pub struct PySliceObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Type")] + #[cfg_attr(PyPy, link_name="PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Check")] +#[cfg_attr(PyPy, link_name="PyPySlice_Check")] 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" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_New")] + #[cfg_attr(PyPy, link_name="PyPySlice_New")] pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject, step: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndices")] + #[cfg_attr(PyPy, link_name="PyPySlice_GetIndices")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndicesEx")] + #[cfg_attr(PyPy, link_name="PyPySlice_GetIndicesEx")] 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, diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index 81e96726435..4164bf13a54 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -50,16 +50,16 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromString")] + #[cfg_attr(PyPy, link_name="PyPyString_FromString")] pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyString_FromStringAndSize")] pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_FromFormat")] + #[cfg_attr(PyPy, link_name="PyPyString_FromFormat")] pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_Size")] + #[cfg_attr(PyPy, link_name="PyPyString_Size")] pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_AsString")] + #[cfg_attr(PyPy, link_name="PyPyString_AsString")] pub fn PyString_AsString(string: *mut PyObject) -> *mut c_char; pub fn PyString_AsStringAndSize(obj: *mut PyObject, s: *mut *mut c_char, @@ -74,14 +74,14 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { pub fn PyString_Decode(s: *const c_char, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_AsDecodedObject")] + #[cfg_attr(PyPy, link_name="PyPyString_AsDecodedObject")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyString_AsEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyString_AsEncodedObject")] pub fn PyString_AsEncodedObject(str: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index dba9c2c6e58..3f0b90f8535 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -19,18 +19,18 @@ pub struct PyTracebackObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Here")] + #[cfg_attr(PyPy, link_name="PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Print")] + #[cfg_attr(PyPy, link_name="PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Type")] + #[cfg_attr(PyPy, link_name="PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Check")] +#[cfg_attr(PyPy, link_name="PyPyTraceBack_Check")] pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } \ No newline at end of file diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index 6293365e837..e7aa1ae94d1 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -16,7 +16,7 @@ pub struct PyTupleObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Type")] + #[cfg_attr(PyPy, link_name="PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; } @@ -51,19 +51,19 @@ pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObjec #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Size")] + #[cfg_attr(PyPy, link_name="PyPyTuple_Size")] pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyTuple_GetItem")] pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyTuple_SetItem")] pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetSlice")] + #[cfg_attr(PyPy, link_name="PyPyTuple_GetSlice")] pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyTuple_Resize")] + #[cfg_attr(PyPy, link_name="_PyPyTuple_Resize")] pub fn _PyTuple_Resize(p: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Pack")] + #[cfg_attr(PyPy, link_name="PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; //pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject); pub fn PyTuple_ClearFreeList() -> c_int; diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index e099d3a1387..6ece4ead29c 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -31,18 +31,18 @@ pub struct PyUnicodeObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Type")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Check")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_Check")] pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_CheckExact")] pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { let u : *mut PyTypeObject = &mut PyUnicode_Type; (Py_TYPE(op) == u) as c_int @@ -74,26 +74,26 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[allow(dead_code)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromUnicode")] fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromString")] fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetMax")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetMax")] fn PyUnicodeUCS4_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Resize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Resize")] fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] fn PyUnicodeUCS4_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromObject")] 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; @@ -102,35 +102,35 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; format_spec_len: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideChar")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideChar")] fn PyUnicodeUCS4_AsWideChar(unicode: *mut PyUnicodeObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromOrdinal")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS4_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS4_ClearFreelist() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyUnicode_AsDefaultEncodedString")] + #[cfg_attr(PyPy, link_name="_PyPyUnicode_AsDefaultEncodedString")] fn _PyUnicodeUCS4_AsDefaultEncodedString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetDefaultEncoding")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS4_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS4_SetDefaultEncoding(encoding: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedObject")] fn PyUnicodeUCS4_AsEncodedObject(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedString")] fn PyUnicodeUCS4_AsEncodedString(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] fn PyUnicode_DecodeUTF7(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -142,7 +142,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; base64SetO: c_int, base64WhiteSpace: c_int, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF8")] fn PyUnicodeUCS4_DecodeUTF8(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -150,13 +150,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS4_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeUTF8")] fn PyUnicodeUCS4_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF32")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF32")] fn PyUnicodeUCS4_DecodeUTF32(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -166,13 +166,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF32String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF32String")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF16")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF16")] fn PyUnicodeUCS4_DecodeUTF16(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -182,7 +182,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF16String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF16String")] fn PyUnicodeUCS4_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, @@ -191,7 +191,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS4_DecodeUnicodeEscape(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeEscapeString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeEscapeString")] fn PyUnicodeUCS4_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUnicodeEscape(data: *const Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; @@ -204,23 +204,23 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn _PyUnicode_DecodeUnicodeInternal(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeLatin1")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeLatin1")] fn PyUnicodeUCS4_DecodeLatin1(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsLatin1String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS4_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeLatin1")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeLatin1")] fn PyUnicodeUCS4_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeASCII")] fn PyUnicodeUCS4_DecodeASCII(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsASCIIString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS4_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeASCII")] fn PyUnicodeUCS4_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -238,16 +238,16 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeDecimal")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeDecimal")] fn PyUnicodeUCS4_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Concat")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Concat")] fn PyUnicodeUCS4_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Split")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Split")] fn PyUnicodeUCS4_Split(s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Splitlines")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Splitlines")] 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; @@ -255,28 +255,28 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; maxsplit: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Join")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Join")] fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Tailmatch")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Tailmatch")] fn PyUnicodeUCS4_Tailmatch(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Find")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Find")] fn PyUnicodeUCS4_Find(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Count")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Count")] fn PyUnicodeUCS4_Count(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Replace")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Replace")] fn PyUnicodeUCS4_Replace(str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Compare")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Compare")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Format")] 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, @@ -301,28 +301,28 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[allow(dead_code)] #[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromUnicode")] fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromString")] fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicode")] fn PyUnicodeUCS2_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS2_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetMax")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetMax")] fn PyUnicodeUCS2_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Resize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Resize")] fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] fn PyUnicodeUCS2_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromObject")] 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; @@ -331,31 +331,31 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; format_spec_len: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS2_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideChar")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideChar")] fn PyUnicodeUCS2_AsWideChar(unicode: *mut PyUnicodeObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromOrdinal")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS2_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS2_ClearFreelist() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyUnicode_AsDefaultEncodedString")] + #[cfg_attr(PyPy, link_name="_PyPyUnicode_AsDefaultEncodedString")] fn _PyUnicodeUCS2_AsDefaultEncodedString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetDefaultEncoding")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS2_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS2_SetDefaultEncoding(encoding: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedObject")] fn PyUnicodeUCS2_AsEncodedObject(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedString")] fn PyUnicodeUCS2_AsEncodedString(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; @@ -372,7 +372,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; base64WhiteSpace: c_int, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF8")] fn PyUnicodeUCS2_DecodeUTF8(string: *const c_char, length: Py_ssize_t, errors: *const c_char) @@ -382,13 +382,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS2_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeUTF8")] fn PyUnicodeUCS2_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF32")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF32")] fn PyUnicodeUCS2_DecodeUTF32(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -398,13 +398,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF32String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF32String")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF16")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF16")] fn PyUnicodeUCS2_DecodeUTF16(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -414,7 +414,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; errors: *const c_char, byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF16String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF16String")] fn PyUnicodeUCS2_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, @@ -423,7 +423,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS2_DecodeUnicodeEscape(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeEscapeString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeEscapeString")] fn PyUnicodeUCS2_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUnicodeEscape(data: *const Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; @@ -436,23 +436,23 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn _PyUnicode_DecodeUnicodeInternal(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeLatin1")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeLatin1")] fn PyUnicodeUCS2_DecodeLatin1(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsLatin1String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS2_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeLatin1")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeLatin1")] fn PyUnicodeUCS2_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeASCII")] fn PyUnicodeUCS2_DecodeASCII(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsASCIIString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS2_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeASCII")] fn PyUnicodeUCS2_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -470,17 +470,17 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; length: Py_ssize_t, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeDecimal")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeDecimal")] fn PyUnicodeUCS2_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Concat")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Concat")] fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Split")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Split")] fn PyUnicodeUCS2_Split(s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Splitlines")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Splitlines")] fn PyUnicodeUCS2_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject; fn PyUnicodeUCS2_Partition(s: *mut PyObject, sep: *mut PyObject) @@ -492,32 +492,32 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; fn PyUnicodeUCS2_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Join")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Join")] fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Tailmatch")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Tailmatch")] fn PyUnicodeUCS2_Tailmatch(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Find")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Find")] fn PyUnicodeUCS2_Find(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Count")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Count")] fn PyUnicodeUCS2_Count(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Replace")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Replace")] fn PyUnicodeUCS2_Replace(str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Compare")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Compare")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Format")] fn PyUnicodeUCS2_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_Contains(container: *mut PyObject, @@ -544,7 +544,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject { PyUnicodeUCS4_FromStringAndSize(u, size) } @@ -557,7 +557,7 @@ pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS4_AsUTF8String(u) } @@ -570,7 +570,7 @@ pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { #[inline(always)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject { diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index 6c3819c32b3..0b9d8c9fe40 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -3,7 +3,7 @@ use ffi2::pyport::Py_ssize_t; use ffi2::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WarnEx")] + #[cfg_attr(PyPy, link_name="PyPyErr_WarnEx")] pub fn PyErr_WarnEx(category: *mut PyObject, msg: *const c_char, stacklevel: Py_ssize_t) -> c_int; pub fn PyErr_WarnExplicit(arg1: *mut PyObject, @@ -15,7 +15,7 @@ use ffi2::object::PyObject; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Warn")] +#[cfg_attr(PyPy, link_name="PyPyErr_Warn")] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) } \ No newline at end of file diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index dd3b4e476c8..44167c9f26c 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -25,19 +25,19 @@ pub struct PyWeakReference { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRef")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRefExact")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckProxy")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckProxy")] 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 @@ -49,13 +49,13 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewRef")] + #[cfg_attr(PyPy, link_name="PyPyWeakref_NewRef")] pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewProxy")] + #[cfg_attr(PyPy, link_name="PyPyWeakref_NewProxy")] pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_GetObject")] + #[cfg_attr(PyPy, link_name="PyPyWeakref_GetObject")] pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject; pub fn _PyWeakref_GetWeakrefCount(head: *mut PyWeakReference) -> Py_ssize_t; @@ -63,7 +63,7 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_GET_OBJECT")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_GET_OBJECT")] 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() } diff --git a/src/ffi3/boolobject.rs b/src/ffi3/boolobject.rs index 6f8d7d04ff0..d620af82e7c 100644 --- a/src/ffi3/boolobject.rs +++ b/src/ffi3/boolobject.rs @@ -3,17 +3,17 @@ use ffi3::object::*; use ffi3::longobject::PyLongObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Type")] + #[cfg_attr(PyPy, link_name="PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; static mut _Py_FalseStruct: PyLongObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_TrueStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyLongObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_FromLong")] + #[cfg_attr(PyPy, link_name="PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyBool_Check")] +#[cfg_attr(PyPy, link_name="PyPyBool_Check")] pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyBool_Type) as c_int } diff --git a/src/ffi3/bytearrayobject.rs b/src/ffi3/bytearrayobject.rs index 7b68405f78a..733fa2476eb 100644 --- a/src/ffi3/bytearrayobject.rs +++ b/src/ffi3/bytearrayobject.rs @@ -3,38 +3,38 @@ use ffi3::object::*; use ffi3::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Type")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Check")] +#[cfg_attr(PyPy, link_name="PyPyByteArray_Check")] pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] + #[cfg_attr(PyPy, link_name="PyPyObject_Type")] PyObject_TypeCheck(op, &mut PyByteArray_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyByteArray_CheckExact")] pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyByteArray_Type) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Concat")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Concat")] pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_FromStringAndSize")] pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Size")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_AsString")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyByteArray_Resize")] + #[cfg_attr(PyPy, link_name="PyPyByteArray_Resize")] pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; } \ No newline at end of file diff --git a/src/ffi3/bytesobject.rs b/src/ffi3/bytesobject.rs index 6d41c60c996..495fa33b9eb 100644 --- a/src/ffi3/bytesobject.rs +++ b/src/ffi3/bytesobject.rs @@ -3,7 +3,7 @@ use ffi3::object::*; use ffi3::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_Type")] + #[cfg_attr(PyPy, link_name="PyPyBytes_Type")] pub static mut PyBytes_Type: PyTypeObject; pub static mut PyBytesIter_Type: PyTypeObject; } @@ -19,34 +19,34 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyBytes_FromStringAndSize")] pub fn PyBytes_FromStringAndSize(arg1: *const c_char, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyBytes_FromObject")] pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromFormat")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_FromFormatV")] + #[cfg_attr(PyPy, link_name="PyPyBytes_FromFormat")] + #[cfg_attr(PyPy, link_name="PyPyBytes_FromFormatV")] //pub fn PyBytes_FromFormatV(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; pub fn PyBytes_FromFormat(arg1: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_Size")] + #[cfg_attr(PyPy, link_name="PyPyBytes_Size")] pub fn PyBytes_Size(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_AsString")] + #[cfg_attr(PyPy, link_name="PyPyBytes_AsString")] pub fn PyBytes_AsString(arg1: *mut PyObject) -> *mut c_char; pub fn PyBytes_Repr(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_Concat")] + #[cfg_attr(PyPy, link_name="PyPyBytes_Concat")] pub fn PyBytes_Concat(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_ConcatAndDel")] + #[cfg_attr(PyPy, link_name="PyPyBytes_ConcatAndDel")] pub fn PyBytes_ConcatAndDel(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> (); pub fn PyBytes_DecodeEscape(arg1: *const c_char, arg2: Py_ssize_t, arg3: *const c_char, arg4: Py_ssize_t, arg5: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBytes_AsStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyBytes_AsStringAndSize")] pub fn PyBytes_AsStringAndSize(obj: *mut PyObject, s: *mut *mut c_char, len: *mut Py_ssize_t) -> c_int; diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 0c8fbb9c56d..51f16694131 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -5,7 +5,7 @@ use ffi3::pystate::PyThreadState; use ffi3::code::FreeFunc; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallObjectWithKeywords")] + #[cfg_attr(PyPy, link_name="PyPyEval_CallObjectWithKeywords")] pub fn PyEval_CallObjectWithKeywords(func: *mut PyObject, obj: *mut PyObject, kwargs: *mut PyObject) @@ -18,36 +18,36 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallFunction")] + #[cfg_attr(PyPy, link_name="PyPyEval_CallFunction")] pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_CallMethod")] + #[cfg_attr(PyPy, link_name="PyPyEval_CallMethod")] pub fn PyEval_CallMethod(obj: *mut PyObject, methodname: *const c_char, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetBuiltins")] + #[cfg_attr(PyPy, link_name="PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetGlobals")] + #[cfg_attr(PyPy, link_name="PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_GetLocals")] + #[cfg_attr(PyPy, link_name="PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut ::ffi3::PyFrameObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AddPendingCall")] + #[cfg_attr(PyPy, link_name="PyPy_AddPendingCall")] pub fn Py_AddPendingCall(func: Option c_int>, arg: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_MakePendingCalls")] + #[cfg_attr(PyPy, link_name="PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_SetRecursionLimit")] + #[cfg_attr(PyPy, link_name="PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetRecursionLimit")] + #[cfg_attr(PyPy, link_name="PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; static mut _Py_CheckRecursionLimit: c_int; } -#[cfg_attr(PyPy, link_name="\u{1}_PyPy_EnterRecursiveCall")] +#[cfg_attr(PyPy, link_name="PyPy_EnterRecursiveCall")] // TODO: Py_EnterRecursiveCall etc. #[cfg(Py_3_6)] @@ -65,23 +65,23 @@ pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int; pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_SaveThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_RestoreThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState) -> (); } #[cfg(py_sys_config = "WITH_THREAD")] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ThreadsInitialized")] + #[cfg_attr(PyPy, link_name="PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_InitThreads")] + #[cfg_attr(PyPy, link_name="PyPyEval_InitThreads")] pub fn PyEval_InitThreads() -> (); pub fn PyEval_AcquireLock() -> (); pub fn PyEval_ReleaseLock() -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_AcquireThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_ReleaseThread")] + #[cfg_attr(PyPy, link_name="PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState) -> (); pub fn PyEval_ReInitThreads() -> (); } \ No newline at end of file diff --git a/src/ffi3/code.rs b/src/ffi3/code.rs index 93b77f1826c..818fa07405c 100644 --- a/src/ffi3/code.rs +++ b/src/ffi3/code.rs @@ -76,7 +76,7 @@ pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_New")] + #[cfg_attr(PyPy, link_name="PyPyCode_New")] pub fn PyCode_New(arg1: c_int, arg2: c_int, arg3: c_int, arg4: c_int, arg5: c_int, arg6: *mut PyObject, @@ -85,7 +85,7 @@ pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; arg11: *mut PyObject, arg12: *mut PyObject, arg13: *mut PyObject, arg14: c_int, arg15: *mut PyObject) -> *mut PyCodeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_NewEmpty")] + #[cfg_attr(PyPy, link_name="PyPyCode_NewEmpty")] pub fn PyCode_NewEmpty(filename: *const c_char, funcname: *const c_char, firstlineno: c_int) -> *mut PyCodeObject; @@ -97,13 +97,13 @@ pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_Check")] +#[cfg_attr(PyPy, link_name="PyPyCode_Check")] pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCode_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyCode_GetNumFree")] +#[cfg_attr(PyPy, link_name="PyPyCode_GetNumFree")] pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { ::ffi3::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } \ No newline at end of file diff --git a/src/ffi3/codecs.rs b/src/ffi3/codecs.rs index 058957cae71..187e26922ca 100644 --- a/src/ffi3/codecs.rs +++ b/src/ffi3/codecs.rs @@ -14,11 +14,11 @@ extern "C" { errors: *const c_char) -> *mut PyObject; pub fn PyCodec_Encoder(encoding: *const c_char) -> *mut PyObject; pub fn PyCodec_Decoder(encoding: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCodec_IncrementalEncoder")] + #[cfg_attr(PyPy, link_name="PyPyCodec_IncrementalEncoder")] pub fn PyCodec_IncrementalEncoder(encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCodec_IncrementalDecoder")] + #[cfg_attr(PyPy, link_name="PyPyCodec_IncrementalDecoder")] pub fn PyCodec_IncrementalDecoder(encoding: *const c_char, errors: *const c_char) -> *mut PyObject; diff --git a/src/ffi3/complexobject.rs b/src/ffi3/complexobject.rs index dbd959795e8..fcde0dd227a 100644 --- a/src/ffi3/complexobject.rs +++ b/src/ffi3/complexobject.rs @@ -2,28 +2,28 @@ use std::os::raw::{c_double, c_int}; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Type")] + #[cfg_attr(PyPy, link_name="PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_Check")] +#[cfg_attr(PyPy, link_name="PyPyComplex_Check")] pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyComplex_CheckExact")] pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyComplex_Type) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_FromDoubles")] + #[cfg_attr(PyPy, link_name="PyPyComplex_FromDoubles")] pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_RealAsDouble")] + #[cfg_attr(PyPy, link_name="PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyComplex_ImagAsDouble")] + #[cfg_attr(PyPy, link_name="PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; } \ No newline at end of file diff --git a/src/ffi3/descrobject.rs b/src/ffi3/descrobject.rs index 37843289577..bec2de4a246 100644 --- a/src/ffi3/descrobject.rs +++ b/src/ffi3/descrobject.rs @@ -29,29 +29,29 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { }; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyClassMethodDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyClassMethodDescr_Type")] pub static mut PyClassMethodDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyGetSetDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemberDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMethodDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyMethodDescr_Type")] pub static mut PyMethodDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWrapperDescr_Type")] + #[cfg_attr(PyPy, link_name="PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_Type")] + #[cfg_attr(PyPy, link_name="PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDescr_NewClassMethod")] + #[cfg_attr(PyPy, link_name="PyPyDescr_NewClassMethod")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDictProxy_New")] + #[cfg_attr(PyPy, link_name="PyPyDictProxy_New")] pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject; pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyProperty_Type")] + #[cfg_attr(PyPy, link_name="PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; } \ No newline at end of file diff --git a/src/ffi3/dictobject.rs b/src/ffi3/dictobject.rs index cff2adc1c27..9efa244997c 100644 --- a/src/ffi3/dictobject.rs +++ b/src/ffi3/dictobject.rs @@ -43,42 +43,42 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_New")] + #[cfg_attr(PyPy, link_name="PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItem")] + #[cfg_attr(PyPy, link_name="PyPyDict_DelItem")] pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Clear")] + #[cfg_attr(PyPy, link_name="PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Next")] + #[cfg_attr(PyPy, link_name="PyPyDict_Next")] pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Keys")] + #[cfg_attr(PyPy, link_name="PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Values")] + #[cfg_attr(PyPy, link_name="PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Items")] + #[cfg_attr(PyPy, link_name="PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Size")] + #[cfg_attr(PyPy, link_name="PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Copy")] + #[cfg_attr(PyPy, link_name="PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Contains")] + #[cfg_attr(PyPy, link_name="PyPyDict_Contains")] pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Update")] + #[cfg_attr(PyPy, link_name="PyPyDict_Update")] pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_Merge")] + #[cfg_attr(PyPy, link_name="PyPyDict_Merge")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_GetItemString")] + #[cfg_attr(PyPy, link_name="PyPyDict_GetItemString")] pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_SetItemString")] + #[cfg_attr(PyPy, link_name="PyPyDict_SetItemString")] pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyDict_DelItemString")] + #[cfg_attr(PyPy, link_name="PyPyDict_DelItemString")] pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; } \ No newline at end of file diff --git a/src/ffi3/eval.rs b/src/ffi3/eval.rs index 248b44602e7..3ee9ecdecc8 100644 --- a/src/ffi3/eval.rs +++ b/src/ffi3/eval.rs @@ -2,7 +2,7 @@ use std::os::raw::c_int; use ffi3::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyEval_EvalCode")] + #[cfg_attr(PyPy, link_name="PyPyEval_EvalCode")] pub fn PyEval_EvalCode(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; pub fn PyEval_EvalCodeEx(co: *mut PyObject, globals: *mut PyObject, diff --git a/src/ffi3/fileobject.rs b/src/ffi3/fileobject.rs index 4e1e1641206..db9011d2b26 100644 --- a/src/ffi3/fileobject.rs +++ b/src/ffi3/fileobject.rs @@ -10,13 +10,13 @@ pub const PY_STDIOTEXTMODE : &str = "b"; arg6: *const c_char, arg7: *const c_char, arg8: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_GetLine")] + #[cfg_attr(PyPy, link_name="PyPyFile_GetLine")] pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteObject")] + #[cfg_attr(PyPy, link_name="PyPyFile_WriteObject")] pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFile_WriteString")] + #[cfg_attr(PyPy, link_name="PyPyFile_WriteString")] pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; diff --git a/src/ffi3/floatobject.rs b/src/ffi3/floatobject.rs index 93e99f52b13..a9c574d90ef 100644 --- a/src/ffi3/floatobject.rs +++ b/src/ffi3/floatobject.rs @@ -2,18 +2,18 @@ use std::os::raw::{c_int, c_double}; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Type")] + #[cfg_attr(PyPy, link_name="PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_Check")] +#[cfg_attr(PyPy, link_name="PyPyFloat_Check")] pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyFloat_CheckExact")] pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFloat_Type) as c_int } @@ -22,10 +22,10 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { pub fn PyFloat_GetMax() -> c_double; pub fn PyFloat_GetMin() -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromString")] + #[cfg_attr(PyPy, link_name="PyPyFloat_FromString")] pub fn PyFloat_FromString(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_FromDouble")] + #[cfg_attr(PyPy, link_name="PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(arg1: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFloat_AsDouble")] + #[cfg_attr(PyPy, link_name="PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(arg1: *mut PyObject) -> c_double; } \ No newline at end of file diff --git a/src/ffi3/frameobject.rs b/src/ffi3/frameobject.rs index 99f94e3af96..e3c411ed998 100644 --- a/src/ffi3/frameobject.rs +++ b/src/ffi3/frameobject.rs @@ -55,7 +55,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrame_New")] + #[cfg_attr(PyPy, link_name="PyPyFrame_New")] pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; diff --git a/src/ffi3/genobject.rs b/src/ffi3/genobject.rs index 813e5d700b8..ad236fb041b 100644 --- a/src/ffi3/genobject.rs +++ b/src/ffi3/genobject.rs @@ -23,13 +23,13 @@ pub struct PyGenObject { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_Check")] +#[cfg_attr(PyPy, link_name="PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyGen_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } @@ -44,7 +44,7 @@ pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyCoro_Check")] +#[cfg_attr(PyPy, link_name="PyPyCoro_Check")] pub unsafe fn PyCoro_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyCoro_Type) } diff --git a/src/ffi3/import.rs b/src/ffi3/import.rs index a633bbcaac2..2ec3bf00aac 100644 --- a/src/ffi3/import.rs +++ b/src/ffi3/import.rs @@ -4,10 +4,10 @@ use ffi3::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyImport_GetMagicNumber() -> c_long; pub fn PyImport_GetMagicTag() -> *const c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModule")] pub fn PyImport_ExecCodeModule(name: *const c_char, co: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ExecCodeModuleEx")] + #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModuleEx")] pub fn PyImport_ExecCodeModuleEx(name: *const c_char, co: *mut PyObject, pathname: *const c_char) @@ -24,23 +24,23 @@ use ffi3::object::PyObject; pathname: *mut PyObject, cpathname: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_GetModuleDict")] + #[cfg_attr(PyPy, link_name="PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject; pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_ImportModule")] pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleNoBlock")] + #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleNoBlock")] pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleLevel")] + #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleLevel")] pub fn PyImport_ImportModuleLevel(name: *const c_char, globals: *mut PyObject, locals: *mut PyObject, fromlist: *mut PyObject, level: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ImportModuleLevelObject")] + #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleLevelObject")] pub fn PyImport_ImportModuleLevelObject(name: *mut PyObject, globals: *mut PyObject, locals: *mut PyObject, @@ -61,7 +61,7 @@ pub unsafe fn PyImport_ImportModuleEx(name: *const c_char, #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyImport_ReloadModule")] + #[cfg_attr(PyPy, link_name="PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; pub fn PyImport_Cleanup() -> (); pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) diff --git a/src/ffi3/intrcheck.rs b/src/ffi3/intrcheck.rs index 015ad9ec0f9..0dc2a0d9f42 100644 --- a/src/ffi3/intrcheck.rs +++ b/src/ffi3/intrcheck.rs @@ -1,9 +1,9 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_InterruptOccurred")] + #[cfg_attr(PyPy, link_name="PyPyOS_InterruptOccurred")] pub fn PyOS_InterruptOccurred() -> c_int; pub fn PyOS_InitInterrupts() -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_AfterFork")] + #[cfg_attr(PyPy, link_name="PyPyOS_AfterFork")] pub fn PyOS_AfterFork() -> (); } \ No newline at end of file diff --git a/src/ffi3/iterobject.rs b/src/ffi3/iterobject.rs index 850f8288d6d..f0f04c1f91a 100644 --- a/src/ffi3/iterobject.rs +++ b/src/ffi3/iterobject.rs @@ -5,9 +5,9 @@ use ffi3::object::*; pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySeqIter_New")] + #[cfg_attr(PyPy, link_name="PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallIter_New")] + #[cfg_attr(PyPy, link_name="PyPyCallIter_New")] pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi3/listobject.rs b/src/ffi3/listobject.rs index 183a8b8fbbe..48f3a520608 100644 --- a/src/ffi3/listobject.rs +++ b/src/ffi3/listobject.rs @@ -3,7 +3,7 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Type")] + #[cfg_attr(PyPy, link_name="PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; pub static mut PyListIter_Type: PyTypeObject; pub static mut PyListRevIter_Type: PyTypeObject; @@ -20,28 +20,28 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_New")] + #[cfg_attr(PyPy, link_name="PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Size")] + #[cfg_attr(PyPy, link_name="PyPyList_Size")] pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyList_GetItem")] pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyList_SetItem")] pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Insert")] + #[cfg_attr(PyPy, link_name="PyPyList_Insert")] pub fn PyList_Insert(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Append")] + #[cfg_attr(PyPy, link_name="PyPyList_Append")] pub fn PyList_Append(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_GetSlice")] + #[cfg_attr(PyPy, link_name="PyPyList_GetSlice")] pub fn PyList_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_SetSlice")] + #[cfg_attr(PyPy, link_name="PyPyList_SetSlice")] pub fn PyList_SetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Sort")] + #[cfg_attr(PyPy, link_name="PyPyList_Sort")] pub fn PyList_Sort(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_Reverse")] + #[cfg_attr(PyPy, link_name="PyPyList_Reverse")] pub fn PyList_Reverse(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyList_AsTuple")] + #[cfg_attr(PyPy, link_name="PyPyList_AsTuple")] pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject; } \ No newline at end of file diff --git a/src/ffi3/longobject.rs b/src/ffi3/longobject.rs index dcf508d9ede..3a20b4eba84 100644 --- a/src/ffi3/longobject.rs +++ b/src/ffi3/longobject.rs @@ -6,7 +6,7 @@ use ffi3::pyport::Py_ssize_t; pub enum PyLongObject {} #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_Type")] + #[cfg_attr(PyPy, link_name="PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } @@ -21,55 +21,55 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromLong")] pub fn PyLong_FromLong(arg1: c_long) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(arg1: c_ulong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(arg1: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromSsize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(arg1: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromDouble")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromDouble")] pub fn PyLong_FromDouble(arg1: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLong")] pub fn PyLong_AsLong(arg1: *mut PyObject) -> c_long; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongAndOverflow")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLongAndOverflow")] pub fn PyLong_AsLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_long; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsSsize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsSize_t")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsSize_t")] pub fn PyLong_AsSize_t(arg1: *mut PyObject) -> size_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(arg1: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongMask")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(arg1: *mut PyObject) -> c_ulong; pub fn PyLong_GetInfo() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsDouble")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsDouble")] pub fn PyLong_AsDouble(arg1: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(arg1: *mut c_void) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsVoidPtr")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(arg1: c_longlong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromUnsignedLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLongLong")] pub fn PyLong_FromUnsignedLongLong(arg1: c_ulonglong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(arg1: *mut PyObject) -> c_longlong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLong")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLong")] pub fn PyLong_AsUnsignedLongLong(arg1: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsUnsignedLongLongMask")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLongMask")] pub fn PyLong_AsUnsignedLongLongMask(arg1: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_AsLongLongAndOverflow")] + #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLongAndOverflow")] pub fn PyLong_AsLongLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_longlong; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyLong_FromString")] + #[cfg_attr(PyPy, link_name="PyPyLong_FromString")] pub fn PyLong_FromString(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> *mut PyObject; diff --git a/src/ffi3/memoryobject.rs b/src/ffi3/memoryobject.rs index 800f1c2ceb2..f37bec6a672 100644 --- a/src/ffi3/memoryobject.rs +++ b/src/ffi3/memoryobject.rs @@ -3,20 +3,20 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Type")] + #[cfg_attr(PyPy, link_name="PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_Check")] +#[cfg_attr(PyPy, link_name="PyPyMemoryView_Check")] pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyMemoryView_Type) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMemoryView_FromMemory")] + #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromMemory")] pub fn PyMemoryView_FromMemory(mem: *mut c_char, size: Py_ssize_t, flags: c_int) -> *mut PyObject; pub fn PyMemoryView_GetContiguous(base: *mut PyObject, diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index 77911149078..203a2f207df 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -3,12 +3,12 @@ use std::{mem, ptr}; use ffi3::object::{PyObject, PyTypeObject, Py_TYPE}; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Type")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_Check")] +#[cfg_attr(PyPy, link_name="PyPyCFunction_Check")] pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCFunction_Type) as c_int } @@ -32,7 +32,7 @@ pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_GetFunction")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; @@ -63,12 +63,12 @@ impl Default for PyMethodDef { #[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_NewEx")] PyCFunction_NewEx(ml, slf, ptr::null_mut()) } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCFunction_NewEx")] + #[cfg_attr(PyPy, link_name="PyPyCFunction_NewEx")] pub fn PyCFunction_NewEx(arg1: *mut PyMethodDef, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi3/modsupport.rs b/src/ffi3/modsupport.rs index 758e0fe2e43..2f2205261f1 100644 --- a/src/ffi3/modsupport.rs +++ b/src/ffi3/modsupport.rs @@ -5,37 +5,37 @@ use ffi3::moduleobject::PyModuleDef; use ffi3::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_Parse")] + #[cfg_attr(PyPy, link_name="PyPyArg_Parse")] pub fn PyArg_Parse(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTuple")] + #[cfg_attr(PyPy, link_name="PyPyArg_ParseTuple")] pub fn PyArg_ParseTuple(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_ParseTupleAndKeywords")] + #[cfg_attr(PyPy, link_name="PyPyArg_ParseTupleAndKeywords")] pub fn PyArg_ParseTupleAndKeywords(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *const c_char, arg4: *mut *mut c_char, ...) -> c_int; pub fn PyArg_ValidateKeywordArguments(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyArg_UnpackTuple")] + #[cfg_attr(PyPy, link_name="PyPyArg_UnpackTuple")] pub fn PyArg_UnpackTuple(arg1: *mut PyObject, arg2: *const c_char, arg3: Py_ssize_t, arg4: Py_ssize_t, ...) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BuildValue")] + #[cfg_attr(PyPy, link_name="PyPy_BuildValue")] pub fn Py_BuildValue(arg1: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_BuildValue_SizeT")] + #[cfg_attr(PyPy, link_name="_PyPy_BuildValue_SizeT")] //pub fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_VaBuildValue")] + #[cfg_attr(PyPy, link_name="PyPy_VaBuildValue")] //pub fn Py_VaBuildValue(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddObject")] + #[cfg_attr(PyPy, link_name="PyPyModule_AddObject")] pub fn PyModule_AddObject(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddIntConstant")] + #[cfg_attr(PyPy, link_name="PyPyModule_AddIntConstant")] pub fn PyModule_AddIntConstant(arg1: *mut PyObject, arg2: *const c_char, arg3: c_long) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_AddStringConstant")] + #[cfg_attr(PyPy, link_name="PyPyModule_AddStringConstant")] pub fn PyModule_AddStringConstant(arg1: *mut PyObject, arg2: *const c_char, arg3: *const c_char) -> c_int; @@ -52,7 +52,7 @@ pub const PYTHON_ABI_VERSION: i32 = 3; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg(not(py_sys_config="Py_TRACE_REFS"))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Create2")] + #[cfg_attr(PyPy, link_name="PyPyModule_Create2")] pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; @@ -73,7 +73,7 @@ pub const PYTHON_ABI_VERSION: i32 = 3; #[cfg(py_sys_config="Py_TRACE_REFS")] #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Create2")] +#[cfg_attr(PyPy, link_name="PyPyModule_Create2")] pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { PyModule_Create2TraceRefs(module, apiver) diff --git a/src/ffi3/moduleobject.rs b/src/ffi3/moduleobject.rs index 7271de8ac1d..6650505451f 100644 --- a/src/ffi3/moduleobject.rs +++ b/src/ffi3/moduleobject.rs @@ -4,12 +4,12 @@ use ffi3::object::*; use ffi3::methodobject::PyMethodDef; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Type")] + #[cfg_attr(PyPy, link_name="PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_Check")] +#[cfg_attr(PyPy, link_name="PyPyModule_Check")] pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } @@ -22,17 +22,17 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDict")] + #[cfg_attr(PyPy, link_name="PyPyModule_GetDict")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetDef")] + #[cfg_attr(PyPy, link_name="PyPyModule_GetDef")] pub fn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModule_GetState")] + #[cfg_attr(PyPy, link_name="PyPyModule_GetState")] pub fn PyModule_GetState(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyModuleDef_Init")] + #[cfg_attr(PyPy, link_name="PyPyModuleDef_Init")] pub fn PyModuleDef_Init(arg1: *mut PyModuleDef) -> *mut PyObject; pub static mut PyModuleDef_Type: PyTypeObject; } diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index d6c03685343..fee5e90eaf2 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -620,10 +620,10 @@ impl Default for PyType_Spec { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_FromSpec")] + #[cfg_attr(PyPy, link_name="PyPyType_FromSpec")] pub fn PyType_FromSpec(arg1: *mut PyType_Spec) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_FromSpecWithBases")] + #[cfg_attr(PyPy, link_name="PyPyType_FromSpecWithBases")] pub fn PyType_FromSpecWithBases(arg1: *mut PyType_Spec, arg2: *mut PyObject) -> *mut PyObject; @@ -631,7 +631,7 @@ impl Default for PyType_Spec { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_IsSubtype")] + #[cfg_attr(PyPy, link_name="PyPyType_IsSubtype")] pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } @@ -642,10 +642,10 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { /// built-in 'type' - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Type")] + #[cfg_attr(PyPy, link_name="PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; /// built-in 'object' - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBaseObject_Type")] + #[cfg_attr(PyPy, link_name="PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; /// built-in 'super' pub static mut PySuper_Type: PyTypeObject; @@ -664,81 +664,81 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Ready")] + #[cfg_attr(PyPy, link_name="PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericAlloc")] + #[cfg_attr(PyPy, link_name="PyPyType_GenericAlloc")] pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_GenericNew")] + #[cfg_attr(PyPy, link_name="PyPyType_GenericNew")] pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, kwds: *mut PyObject) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyType_Modified")] + #[cfg_attr(PyPy, link_name="PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Print")] + #[cfg_attr(PyPy, link_name="PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut ::libc::FILE, flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Repr")] + #[cfg_attr(PyPy, link_name="PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Str")] + #[cfg_attr(PyPy, link_name="PyPyObject_Str")] pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_ASCII")] + #[cfg_attr(PyPy, link_name="PyPyObject_ASCII")] pub fn PyObject_ASCII(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Bytes")] + #[cfg_attr(PyPy, link_name="PyPyObject_Bytes")] pub fn PyObject_Bytes(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompare")] + #[cfg_attr(PyPy, link_name="PyPyObject_RichCompare")] pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_RichCompareBool")] + #[cfg_attr(PyPy, link_name="PyPyObject_RichCompareBool")] pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetAttrString")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetAttrString")] pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttrString")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetAttrString")] pub fn PyObject_SetAttrString(arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HasAttrString")] + #[cfg_attr(PyPy, link_name="PyPyObject_HasAttrString")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetAttr")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SelfIter")] + #[cfg_attr(PyPy, link_name="PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericGetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GenericSetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_GenericSetAttr")] pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; pub fn PyObject_GenericSetDict(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Hash")] + #[cfg_attr(PyPy, link_name="PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_HashNotImplemented")] + #[cfg_attr(PyPy, link_name="PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsTrue")] + #[cfg_attr(PyPy, link_name="PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Not")] + #[cfg_attr(PyPy, link_name="PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCallable_Check")] + #[cfg_attr(PyPy, link_name="PyPyCallable_Check")] pub fn PyCallable_Check(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_ClearWeakRefs")] + #[cfg_attr(PyPy, link_name="PyPyObject_ClearWeakRefs")] pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject) -> (); #[cfg(not(Py_LIMITED_API))] pub fn PyObject_CallFinalizer(arg1: *mut PyObject) -> (); #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFinalizerFromDealloc")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallFinalizerFromDealloc")] pub fn PyObject_CallFinalizerFromDealloc(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Dir")] + #[cfg_attr(PyPy, link_name="PyPyObject_Dir")] 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) -> (); @@ -804,7 +804,7 @@ pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_Dealloc")] + #[cfg_attr(PyPy, link_name="_PyPy_Dealloc")] pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } @@ -812,7 +812,7 @@ pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { #[inline(always)] pub unsafe fn Py_INCREF(op : *mut PyObject) { if cfg!(py_sys_config="Py_REF_DEBUG") { - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IncRef")] + #[cfg_attr(PyPy, link_name="PyPy_IncRef")] Py_IncRef(op) } else { (*op).ob_refcnt += 1 @@ -822,7 +822,7 @@ pub unsafe fn Py_INCREF(op : *mut PyObject) { #[inline(always)] pub unsafe fn Py_DECREF(op: *mut PyObject) { if cfg!(py_sys_config="Py_REF_DEBUG") { - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DecRef")] + #[cfg_attr(PyPy, link_name="PyPy_DecRef")] Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -859,9 +859,9 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NoneStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_NotImplementedStruct")] + #[cfg_attr(PyPy, link_name="_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index 71037f6df3d..05d4549ce3b 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -4,9 +4,9 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_DelAttrString")] +#[cfg_attr(PyPy, link_name="PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetAttr")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetAttr")] PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } @@ -16,33 +16,33 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Call")] + #[cfg_attr(PyPy, link_name="PyPyObject_Call")] pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, kw: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallObject")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallObject")] pub fn PyObject_CallObject(callable_object: *mut PyObject, args: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunction")] - #[cfg_attr(PyPy, link_name = "\u{1}_PyPyObject_CallFunction")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallFunction")] + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] pub fn PyObject_CallFunction(callable_object: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethod")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallMethod")] pub fn PyObject_CallMethod(o: *mut PyObject, method: *const c_char, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallFunctionObjArgs")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallFunctionObjArgs")] pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CallMethodObjArgs")] + #[cfg_attr(PyPy, link_name="PyPyObject_CallMethodObjArgs")] pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, method: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Type")] + #[cfg_attr(PyPy, link_name="PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Size")] + #[cfg_attr(PyPy, link_name="PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; } @@ -53,14 +53,14 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_LengthHint")] + #[cfg_attr(PyPy, link_name="PyPyObject_LengthHint")] pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetItem")] pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyObject_SetItem")] pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, v: *mut PyObject) -> c_int; pub fn PyObject_DelItemString(o: *mut PyObject, @@ -68,19 +68,19 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { -> c_int; pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsCharBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsCharBuffer")] pub fn PyObject_AsCharBuffer(obj: *mut PyObject, buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_CheckReadBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsReadBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsReadBuffer")] pub fn PyObject_AsReadBuffer(obj: *mut PyObject, buffer: *mut *const c_void, buffer_len: *mut Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_AsWriteBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_AsWriteBuffer")] pub fn PyObject_AsWriteBuffer(obj: *mut PyObject, buffer: *mut *mut c_void, buffer_len: *mut Py_ssize_t) @@ -96,23 +96,23 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetBuffer")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetBuffer")] pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_GetPointer")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_GetPointer")] pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_ToContiguous")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_ToContiguous")] pub fn PyBuffer_ToContiguous(buf: *mut c_void, view: *mut Py_buffer, len: Py_ssize_t, order: c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FromContiguous")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FromContiguous")] pub fn PyBuffer_FromContiguous(view: *mut Py_buffer, buf: *mut c_void, len: Py_ssize_t, order: c_char) -> c_int; pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_IsContiguous")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_IsContiguous")] pub fn PyBuffer_IsContiguous(view: *const Py_buffer, fort: c_char) -> c_int; pub fn PyBuffer_FillContiguousStrides(ndims: c_int, @@ -120,26 +120,26 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { strides: *mut Py_ssize_t, itemsize: c_int, fort: c_char) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_FillInfo")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_FillInfo")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyBuffer_Release")] + #[cfg_attr(PyPy, link_name="PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer) -> (); } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Format")] + #[cfg_attr(PyPy, link_name="PyPyObject_Format")] pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GetIter")] + #[cfg_attr(PyPy, link_name="PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Check")] +#[cfg_attr(PyPy, link_name="PyPyIter_Check")] pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { (match (*(*o).ob_type).tp_iternext { Some(tp_iternext) => tp_iternext as *const c_void != ::ffi3::object::_PyObject_NextNotImplemented as *const c_void, @@ -148,171 +148,171 @@ pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyIter_Next")] + #[cfg_attr(PyPy, link_name="PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Check")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Add")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Add")] pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Subtract")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Subtract")] pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Multiply")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Multiply")] pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_MatrixMultiply")] + #[cfg_attr(PyPy, link_name="PyPyNumber_MatrixMultiply")] pub fn PyNumber_MatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_FloorDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_FloorDivide")] pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_TrueDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_TrueDivide")] pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Remainder")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Remainder")] pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Divmod")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Divmod")] pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Power")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Power")] pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Negative")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Positive")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Absolute")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Invert")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Lshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Lshift")] pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Rshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Rshift")] pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_And")] + #[cfg_attr(PyPy, link_name="PyPyNumber_And")] pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Xor")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Xor")] pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Or")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyIndex_Check")] +#[cfg_attr(PyPy, link_name="PyPyIndex_Check")] pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { let tp_as_number = (*(*o).ob_type).tp_as_number; (!tp_as_number.is_null() && (*tp_as_number).nb_index.is_some()) as c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Index")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_AsSsize_t")] + #[cfg_attr(PyPy, link_name="PyPyNumber_AsSsize_t")] pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Long")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_Float")] + #[cfg_attr(PyPy, link_name="PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAdd")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAdd")] pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceSubtract")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceSubtract")] pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceMultiply")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceMultiply")] pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceMatrixMultiply")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceMatrixMultiply")] pub fn PyNumber_InPlaceMatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceFloorDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceFloorDivide")] pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceTrueDivide")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceTrueDivide")] pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRemainder")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRemainder")] pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlacePower")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlacePower")] pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceLshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceLshift")] pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceRshift")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRshift")] pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceAnd")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAnd")] pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceXor")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceXor")] pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyNumber_InPlaceOr")] + #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceOr")] pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Check")] + #[cfg_attr(PyPy, link_name="PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Size")] + #[cfg_attr(PyPy, link_name="PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Length")] +#[cfg_attr(PyPy, link_name="PyPySequence_Length")] pub unsafe fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t { PySequence_Size(o) } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Concat")] + #[cfg_attr(PyPy, link_name="PyPySequence_Concat")] pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Repeat")] + #[cfg_attr(PyPy, link_name="PyPySequence_Repeat")] pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetItem")] + #[cfg_attr(PyPy, link_name="PyPySequence_GetItem")] pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_GetSlice")] + #[cfg_attr(PyPy, link_name="PyPySequence_GetSlice")] pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetItem")] + #[cfg_attr(PyPy, link_name="PyPySequence_SetItem")] pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelItem")] + #[cfg_attr(PyPy, link_name="PyPySequence_DelItem")] pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_SetSlice")] + #[cfg_attr(PyPy, link_name="PyPySequence_SetSlice")] pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_DelSlice")] + #[cfg_attr(PyPy, link_name="PyPySequence_DelSlice")] pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Tuple")] + #[cfg_attr(PyPy, link_name="PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_List")] + #[cfg_attr(PyPy, link_name="PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Fast")] + #[cfg_attr(PyPy, link_name="PyPySequence_Fast")] pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char) -> *mut PyObject; // TODO: PySequence_Fast macros pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Contains")] + #[cfg_attr(PyPy, link_name="PyPySequence_Contains")] pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) -> c_int; } @@ -323,23 +323,23 @@ pub unsafe fn PySequence_In(o: *mut PyObject, value: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_Index")] + #[cfg_attr(PyPy, link_name="PyPySequence_Index")] pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceConcat")] + #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceConcat")] pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySequence_InPlaceRepeat")] + #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceRepeat")] pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Check")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Size")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Length")] +#[cfg_attr(PyPy, link_name="PyPyMapping_Length")] pub unsafe fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t { PyMapping_Size(o) } @@ -355,30 +355,30 @@ pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_HasKeyString")] + #[cfg_attr(PyPy, link_name="PyPyMapping_HasKeyString")] pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *const c_char) -> c_int; pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Keys")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Keys")] pub fn PyMapping_Keys(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Values")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Values")] pub fn PyMapping_Values(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_Items")] + #[cfg_attr(PyPy, link_name="PyPyMapping_Items")] pub fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_GetItemString")] + #[cfg_attr(PyPy, link_name="PyPyMapping_GetItemString")] pub fn PyMapping_GetItemString(o: *mut PyObject, key: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMapping_SetItemString")] + #[cfg_attr(PyPy, link_name="PyPyMapping_SetItemString")] pub fn PyMapping_SetItemString(o: *mut PyObject, key: *const c_char, value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsInstance")] + #[cfg_attr(PyPy, link_name="PyPyObject_IsInstance")] pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_IsSubclass")] + #[cfg_attr(PyPy, link_name="PyPyObject_IsSubclass")] pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } \ No newline at end of file diff --git a/src/ffi3/objimpl.rs b/src/ffi3/objimpl.rs index 68f5209011f..8b7a50b41a6 100644 --- a/src/ffi3/objimpl.rs +++ b/src/ffi3/objimpl.rs @@ -4,24 +4,24 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Malloc")] + #[cfg_attr(PyPy, link_name="PyPyObject_Malloc")] pub fn PyObject_Malloc(size: size_t) -> *mut c_void; pub fn PyObject_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Realloc")] + #[cfg_attr(PyPy, link_name="PyPyObject_Realloc")] pub fn PyObject_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Free")] + #[cfg_attr(PyPy, link_name="PyPyObject_Free")] pub fn PyObject_Free(ptr: *mut c_void) -> (); #[cfg(not(Py_LIMITED_API))] pub fn _Py_GetAllocatedBlocks() -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_Init")] + #[cfg_attr(PyPy, link_name="PyPyObject_Init")] pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_InitVar")] + #[cfg_attr(PyPy, link_name="PyPyObject_InitVar")] pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject, arg3: Py_ssize_t) -> *mut PyVarObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_New")] + #[cfg_attr(PyPy, link_name="_PyPyObject_New")] pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_NewVar")] + #[cfg_attr(PyPy, link_name="_PyPyObject_NewVar")] pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn PyGC_Collect() -> Py_ssize_t; @@ -71,13 +71,13 @@ pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int { pub fn _PyObject_GC_Malloc(size: size_t) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn _PyObject_GC_Calloc(size: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GC_New")] + #[cfg_attr(PyPy, link_name="_PyPyObject_GC_New")] pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyObject_GC_NewVar")] + #[cfg_attr(PyPy, link_name="_PyPyObject_GC_NewVar")] 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) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyObject_GC_Del")] + #[cfg_attr(PyPy, link_name="PyPyObject_GC_Del")] pub fn PyObject_GC_Del(arg1: *mut c_void) -> (); } diff --git a/src/ffi3/pycapsule.rs b/src/ffi3/pycapsule.rs index d809d87a6d0..86d63fd0634 100644 --- a/src/ffi3/pycapsule.rs +++ b/src/ffi3/pycapsule.rs @@ -2,7 +2,7 @@ use std::os::raw::{c_void, c_char, c_int}; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Type")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -14,41 +14,41 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_New")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_New")] pub fn PyCapsule_New(pointer: *mut c_void, name: *const c_char, destructor: Option) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetPointer")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetPointer")] pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetDestructor")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetName")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_GetContext")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_IsValid")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_IsValid")] pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetPointer")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetPointer")] pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetDestructor")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetDestructor")] pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, destructor: Option) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetName")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetName")] pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_SetContext")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_SetContext")] pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyCapsule_Import")] + #[cfg_attr(PyPy, link_name="PyPyCapsule_Import")] pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; } \ No newline at end of file diff --git a/src/ffi3/pydebug.rs b/src/ffi3/pydebug.rs index 1aed602e70d..068e718efdf 100644 --- a/src/ffi3/pydebug.rs +++ b/src/ffi3/pydebug.rs @@ -2,33 +2,33 @@ use std::os::raw::c_int; #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DebugFlag")] + #[cfg_attr(PyPy, link_name="PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_VerboseFlag")] + #[cfg_attr(PyPy, link_name="PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; pub static mut Py_QuietFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InteractiveFlag")] + #[cfg_attr(PyPy, link_name="PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_InspectFlag")] + #[cfg_attr(PyPy, link_name="PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_OptimizeFlag")] + #[cfg_attr(PyPy, link_name="PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoSiteFlag")] + #[cfg_attr(PyPy, link_name="PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_BytesWarningFlag")] + #[cfg_attr(PyPy, link_name="PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_UseClassExceptionsFlag")] + #[cfg_attr(PyPy, link_name="PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FrozenFlag")] + #[cfg_attr(PyPy, link_name="PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IgnoreEnvironmentFlag")] + #[cfg_attr(PyPy, link_name="PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_DontWriteBytecodeFlag")] + #[cfg_attr(PyPy, link_name="PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_NoUserSiteDirectory")] + #[cfg_attr(PyPy, link_name="PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; pub static mut Py_UnbufferedStdioFlag: c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_HashRandomizationFlag")] + #[cfg_attr(PyPy, link_name="PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; pub static mut Py_IsolatedFlag: c_int; #[cfg(all(Py_3_6, windows))] diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index b7a27af09aa..5f83fd8df7c 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -3,54 +3,54 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetNone")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetObject")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetString")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetString")] pub fn PyErr_SetString(exception: *mut PyObject, string: *const c_char) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Occurred")] + #[cfg_attr(PyPy, link_name="PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Clear")] + #[cfg_attr(PyPy, link_name="PyPyErr_Clear")] pub fn PyErr_Clear() -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Fetch")] + #[cfg_attr(PyPy, link_name="PyPyErr_Fetch")] pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Restore")] + #[cfg_attr(PyPy, link_name="PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_GetExcInfo")] + #[cfg_attr(PyPy, link_name="PyPyErr_GetExcInfo")] pub fn PyErr_GetExcInfo(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetExcInfo")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetExcInfo")] pub fn PyErr_SetExcInfo(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_FatalError")] + #[cfg_attr(PyPy, link_name="PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char) -> !; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_GivenExceptionMatches")] + #[cfg_attr(PyPy, link_name="PyPyErr_GivenExceptionMatches")] pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_ExceptionMatches")] + #[cfg_attr(PyPy, link_name="PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NormalizeException")] + #[cfg_attr(PyPy, link_name="PyPyErr_NormalizeException")] pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_SetTraceback")] + #[cfg_attr(PyPy, link_name="PyPyException_SetTraceback")] pub fn PyException_SetTraceback(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_GetTraceback")] + #[cfg_attr(PyPy, link_name="PyPyException_GetTraceback")] pub fn PyException_GetTraceback(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_GetCause")] + #[cfg_attr(PyPy, link_name="PyPyException_GetCause")] pub fn PyException_GetCause(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_SetCause")] + #[cfg_attr(PyPy, link_name="PyPyException_SetCause")] pub fn PyException_SetCause(arg1: *mut PyObject, arg2: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_GetContext")] + #[cfg_attr(PyPy, link_name="PyPyException_GetContext")] pub fn PyException_GetContext(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyException_SetContext")] + #[cfg_attr(PyPy, link_name="PyPyException_SetContext")] pub fn PyException_SetContext(arg1: *mut PyObject, arg2: *mut PyObject) -> (); } @@ -67,123 +67,120 @@ pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyExceptionInstance_Class")] +#[cfg_attr(PyPy, link_name="PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { (*x).ob_type as *mut PyObject } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BaseException")] + #[cfg_attr(PyPy, link_name="PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Exception")] + #[cfg_attr(PyPy, link_name="PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_StopAsyncIteration")] + #[cfg_attr(PyPy, link_name="PyPyExc_StopAsyncIteration")] pub static mut PyExc_StopAsyncIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_StopIteration")] + #[cfg_attr(PyPy, link_name="PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_GeneratorExit")] + #[cfg_attr(PyPy, link_name="PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ArithmeticError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_LookupError")] + #[cfg_attr(PyPy, link_name="PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AssertionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_AttributeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BufferError")] + #[cfg_attr(PyPy, link_name="PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_EOFError")] + #[cfg_attr(PyPy, link_name="PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FloatingPointError")] + #[cfg_attr(PyPy, link_name="PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OSError")] + #[cfg_attr(PyPy, link_name="PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; #[cfg(Py_3_6)] pub static mut PyExc_ModuleNotFoundError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndexError")] + #[cfg_attr(PyPy, link_name="PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyError")] + #[cfg_attr(PyPy, link_name="PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_KeyboardInterrupt")] + #[cfg_attr(PyPy, link_name="PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_MemoryError")] + #[cfg_attr(PyPy, link_name="PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NameError")] + #[cfg_attr(PyPy, link_name="PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_OverflowError")] + #[cfg_attr(PyPy, link_name="PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RecursionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_RecursionError")] pub static mut PyExc_RecursionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NotImplementedError")] + #[cfg_attr(PyPy, link_name="PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxError")] + #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IndentationError")] + #[cfg_attr(PyPy, link_name="PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TabError")] + #[cfg_attr(PyPy, link_name="PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ReferenceError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemError")] + #[cfg_attr(PyPy, link_name="PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SystemExit")] + #[cfg_attr(PyPy, link_name="PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TypeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnboundLocalError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeEncodeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeDecodeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeTranslateError")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ValueError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ZeroDivisionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BlockingIOError")] + #[cfg_attr(PyPy, link_name="PyPyExc_BlockingIOError")] pub static mut PyExc_BlockingIOError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BrokenPipeError")] + #[cfg_attr(PyPy, link_name="PyPyExc_BrokenPipeError")] pub static mut PyExc_BrokenPipeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ChildProcessError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ChildProcessError")] pub static mut PyExc_ChildProcessError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionError")] pub static mut PyExc_ConnectionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionAbortedError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionAbortedError")] pub static mut PyExc_ConnectionAbortedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionRefusedError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionRefusedError")] pub static mut PyExc_ConnectionRefusedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ConnectionResetError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionResetError")] pub static mut PyExc_ConnectionResetError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FileExistsError")] + #[cfg_attr(PyPy, link_name="PyPyExc_FileExistsError")] pub static mut PyExc_FileExistsError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FileNotFoundError")] + #[cfg_attr(PyPy, link_name="PyPyExc_FileNotFoundError")] pub static mut PyExc_FileNotFoundError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_InterruptedError")] + #[cfg_attr(PyPy, link_name="PyPyExc_InterruptedError")] pub static mut PyExc_InterruptedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_IsADirectoryError")] + #[cfg_attr(PyPy, link_name="PyPyExc_IsADirectoryError")] pub static mut PyExc_IsADirectoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_NotADirectoryError")] + #[cfg_attr(PyPy, link_name="PyPyExc_NotADirectoryError")] pub static mut PyExc_NotADirectoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_PermissionError")] + #[cfg_attr(PyPy, link_name="PyPyExc_PermissionError")] pub static mut PyExc_PermissionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ProcessLookupError")] + #[cfg_attr(PyPy, link_name="PyPyExc_ProcessLookupError")] pub static mut PyExc_ProcessLookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_TimeoutError")] + #[cfg_attr(PyPy, link_name="PyPyExc_TimeoutError")] pub static mut PyExc_TimeoutError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; @@ -193,43 +190,43 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { pub static mut PyExc_RecursionErrorInst: *mut PyObject; /* Predefined warning categories */ - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_Warning")] + #[cfg_attr(PyPy, link_name="PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UserWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_DeprecationWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_PendingDeprecationWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_SyntaxWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_RuntimeWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_FutureWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ImportWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_UnicodeWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_BytesWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyExc_ResourceWarning")] + #[cfg_attr(PyPy, link_name="PyPyExc_ResourceWarning")] pub static mut PyExc_ResourceWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadArgument")] + #[cfg_attr(PyPy, link_name="PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NoMemory")] + #[cfg_attr(PyPy, link_name="PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrno")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetFromErrnoWithFilenameObject")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject( arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub fn PyErr_SetFromErrnoWithFilenameObjects( arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; pub fn PyErr_SetFromErrnoWithFilename( exc: *mut PyObject, filename: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Format")] + #[cfg_attr(PyPy, link_name="PyPyErr_Format")] pub fn PyErr_Format( exception: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; #[cfg(Py_3_6)] @@ -238,23 +235,23 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { arg3: *mut PyObject, arg4: *mut PyObject) -> *mut PyObject; pub fn PyErr_SetImportError(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_BadInternalCall")] + #[cfg_attr(PyPy, link_name="PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall() -> (); pub fn _PyErr_BadInternalCall(filename: *const c_char, lineno: c_int) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewException")] + #[cfg_attr(PyPy, link_name="PyPyErr_NewException")] pub fn PyErr_NewException(name: *const c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_NewExceptionWithDoc")] + #[cfg_attr(PyPy, link_name="PyPyErr_NewExceptionWithDoc")] pub fn PyErr_NewExceptionWithDoc(name: *const c_char, doc: *const c_char, base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WriteUnraisable")] + #[cfg_attr(PyPy, link_name="PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_CheckSignals")] + #[cfg_attr(PyPy, link_name="PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_SetInterrupt")] + #[cfg_attr(PyPy, link_name="PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt() -> (); pub fn PyErr_SyntaxLocation(filename: *const c_char, lineno: c_int) -> (); pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, diff --git a/src/ffi3/pymem.rs b/src/ffi3/pymem.rs index 4c7627234a8..6e0925352cc 100644 --- a/src/ffi3/pymem.rs +++ b/src/ffi3/pymem.rs @@ -3,27 +3,27 @@ use libc::size_t; #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawMalloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_RawMalloc")] pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawCalloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_RawCalloc")] pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawRealloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_RawRealloc")] pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_RawFree")] + #[cfg_attr(PyPy, link_name="PyPyMem_RawFree")] pub fn PyMem_RawFree(ptr: *mut c_void) -> (); } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Malloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_Malloc")] pub fn PyMem_Malloc(size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Calloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_Calloc")] pub fn PyMem_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Realloc")] + #[cfg_attr(PyPy, link_name="PyPyMem_Realloc")] pub fn PyMem_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyMem_Free")] + #[cfg_attr(PyPy, link_name="PyPyMem_Free")] pub fn PyMem_Free(ptr: *mut c_void) -> (); } diff --git a/src/ffi3/pystate.rs b/src/ffi3/pystate.rs index 39606ffda94..0ee99caee33 100644 --- a/src/ffi3/pystate.rs +++ b/src/ffi3/pystate.rs @@ -29,24 +29,24 @@ pub struct PyThreadState { //fn _PyState_AddModule(arg1: *mut PyObject, // arg2: *mut PyModuleDef) -> c_int; pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_New")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_New")] pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState; //fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) // -> *mut PyThreadState; //fn _PyThreadState_Init(arg1: *mut PyThreadState) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Clear")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Delete")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState) -> (); #[cfg(py_sys_config="WITH_THREAD")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_DeleteCurrent")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent() -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Get")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Get")] pub fn PyThreadState_Get() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_Swap")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyThreadState_GetDict")] + #[cfg_attr(PyPy, link_name="PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; @@ -60,9 +60,9 @@ pub enum PyGILState_STATE { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Ensure")] + #[cfg_attr(PyPy, link_name="PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyGILState_Release")] + #[cfg_attr(PyPy, link_name="PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE) -> (); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; } diff --git a/src/ffi3/pystrtod.rs b/src/ffi3/pystrtod.rs index 6b46c470433..e93abba8b2a 100644 --- a/src/ffi3/pystrtod.rs +++ b/src/ffi3/pystrtod.rs @@ -2,12 +2,12 @@ use std::os::raw::{c_char, c_int, c_double}; use ffi3::object::PyObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_string_to_double")] + #[cfg_attr(PyPy, link_name="PyPyOS_string_to_double")] pub fn PyOS_string_to_double(str: *const c_char, endptr: *mut *mut c_char, overflow_exception: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyOS_double_to_string")] + #[cfg_attr(PyPy, link_name="PyPyOS_double_to_string")] pub fn PyOS_double_to_string(val: c_double, format_code: c_char, precision: c_int, diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index 915c1141041..f307748c80c 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -10,14 +10,14 @@ use ffi3::pyarena::PyArena; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { // TODO: these moved to pylifecycle.h pub fn Py_SetProgramName(arg1: *mut wchar_t) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetProgramName")] + #[cfg_attr(PyPy, link_name="PyPy_GetProgramName")] pub fn Py_GetProgramName() -> *mut wchar_t; pub fn Py_SetPythonHome(arg1: *mut wchar_t) -> (); pub fn Py_GetPythonHome() -> *mut wchar_t; pub fn Py_Initialize() -> (); pub fn Py_InitializeEx(arg1: c_int) -> (); pub fn Py_Finalize() -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_IsInitialized")] + #[cfg_attr(PyPy, link_name="PyPy_IsInitialized")] pub fn Py_IsInitialized() -> c_int; pub fn Py_NewInterpreter() -> *mut PyThreadState; pub fn Py_EndInterpreter(arg1: *mut PyThreadState) -> (); @@ -124,7 +124,7 @@ pub unsafe fn PyParser_SimpleParseFile(fp: *mut FILE, s: *const c_char, b: c_int arg4: c_int) -> *mut _node; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRun_StringFlags")] + #[cfg_attr(PyPy, link_name="PyPyRun_StringFlags")] pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int, arg3: *mut PyObject, arg4: *mut PyObject, arg5: *mut PyCompilerFlags) -> *mut PyObject; @@ -145,7 +145,7 @@ pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPy_CompileStringFlags")] +#[cfg_attr(PyPy, link_name="PyPy_CompileStringFlags")] pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: c_int, f: *mut PyCompilerFlags) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, f, -1) } @@ -171,16 +171,16 @@ pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: start: c_int) -> *mut symtable; - #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_Print")] + #[cfg_attr(PyPy,link_name="PyPyErr_Print")] pub fn PyErr_Print() -> (); - #[cfg_attr(PyPy,link_name="\u{1}_PyPyErr_PrintEx")] + #[cfg_attr(PyPy,link_name="PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_Display")] + #[cfg_attr(PyPy, link_name="PyPyErr_Display")] pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); // TODO: these moved to pylifecycle.h - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_AtExit")] + #[cfg_attr(PyPy, link_name="PyPy_AtExit")] pub fn Py_AtExit(func: Option ()>) -> c_int; pub fn Py_Exit(arg1: c_int) -> (); @@ -191,7 +191,7 @@ pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: pub fn Py_GetExecPrefix() -> *mut wchar_t; pub fn Py_GetPath() -> *mut wchar_t; pub fn Py_SetPath(arg1: *const wchar_t) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPy_GetVersion")] + #[cfg_attr(PyPy, link_name="PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; diff --git a/src/ffi3/rangeobject.rs b/src/ffi3/rangeobject.rs index 5644590e2a2..fb8ee8d3abb 100644 --- a/src/ffi3/rangeobject.rs +++ b/src/ffi3/rangeobject.rs @@ -2,7 +2,7 @@ use std::os::raw::c_int; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyRange_Type")] + #[cfg_attr(PyPy, link_name="PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; pub static mut PyRangeIter_Type: PyTypeObject; pub static mut PyLongRangeIter_Type: PyTypeObject; diff --git a/src/ffi3/setobject.rs b/src/ffi3/setobject.rs index a73c034b66d..5a3fbce1474 100644 --- a/src/ffi3/setobject.rs +++ b/src/ffi3/setobject.rs @@ -3,21 +3,21 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Type")] + #[cfg_attr(PyPy, link_name="PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_Type")] + #[cfg_attr(PyPy, link_name="PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; pub static mut PySetIter_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyFrozenSet_CheckExact")] pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyAnySet_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyAnySet_CheckExact")] pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } @@ -30,7 +30,7 @@ pub unsafe fn PyAnySet_Check(ob : *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Check")] +#[cfg_attr(PyPy, link_name="PyPySet_Check")] pub unsafe fn PySet_Check(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0) as c_int } @@ -41,22 +41,22 @@ pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_New")] + #[cfg_attr(PyPy, link_name="PyPySet_New")] pub fn PySet_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyFrozenSet_New")] + #[cfg_attr(PyPy, link_name="PyPyFrozenSet_New")] pub fn PyFrozenSet_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Size")] + #[cfg_attr(PyPy, link_name="PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Clear")] + #[cfg_attr(PyPy, link_name="PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Contains")] + #[cfg_attr(PyPy, link_name="PyPySet_Contains")] pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Discard")] + #[cfg_attr(PyPy, link_name="PyPySet_Discard")] pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Add")] + #[cfg_attr(PyPy, link_name="PyPySet_Add")] pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySet_Pop")] + #[cfg_attr(PyPy, link_name="PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; } \ No newline at end of file diff --git a/src/ffi3/sliceobject.rs b/src/ffi3/sliceobject.rs index 197d5bf24ce..8279d4e3f5d 100644 --- a/src/ffi3/sliceobject.rs +++ b/src/ffi3/sliceobject.rs @@ -3,7 +3,7 @@ use ffi3::pyport::Py_ssize_t; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}__PyPy_EllipsisObject")] + #[cfg_attr(PyPy, link_name="_PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -13,26 +13,26 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Type")] + #[cfg_attr(PyPy, link_name="PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_Check")] +#[cfg_attr(PyPy, link_name="PyPySlice_Check")] 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" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_New")] + #[cfg_attr(PyPy, link_name="PyPySlice_New")] pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject, step: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndices")] + #[cfg_attr(PyPy, link_name="PyPySlice_GetIndices")] 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; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySlice_GetIndicesEx")] + #[cfg_attr(PyPy, link_name="PyPySlice_GetIndicesEx")] 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, diff --git a/src/ffi3/sysmodule.rs b/src/ffi3/sysmodule.rs index 618c382b20a..d45f0fab35d 100644 --- a/src/ffi3/sysmodule.rs +++ b/src/ffi3/sysmodule.rs @@ -5,18 +5,18 @@ use ffi3::pyport::Py_ssize_t; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn Py_DecodeLocale(arg1: *const c_char, arg2: Py_ssize_t) -> *mut wchar_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_GetObject")] + #[cfg_attr(PyPy, link_name="PyPySys_GetObject")] pub fn PySys_GetObject(arg1: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_SetObject")] + #[cfg_attr(PyPy, link_name="PyPySys_SetObject")] pub fn PySys_SetObject(arg1: *const c_char, arg2: *mut PyObject) -> c_int; pub fn PySys_SetArgv(arg1: c_int, arg2: *mut *mut wchar_t) -> (); pub fn PySys_SetArgvEx(arg1: c_int, arg2: *mut *mut wchar_t, arg3: c_int) -> (); pub fn PySys_SetPath(arg1: *const wchar_t) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_WriteStdout")] + #[cfg_attr(PyPy, link_name="PyPySys_WriteStdout")] pub fn PySys_WriteStdout(format: *const c_char, ...) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPySys_WriteStderr")] + #[cfg_attr(PyPy, link_name="PyPySys_WriteStderr")] pub fn PySys_WriteStderr(format: *const c_char, ...) -> (); pub fn PySys_FormatStdout(format: *const c_char, ...) -> (); pub fn PySys_FormatStderr(format: *const c_char, ...) -> (); diff --git a/src/ffi3/traceback.rs b/src/ffi3/traceback.rs index aad174f56e9..67ec25db6c3 100644 --- a/src/ffi3/traceback.rs +++ b/src/ffi3/traceback.rs @@ -2,16 +2,16 @@ use std::os::raw::c_int; use ffi3::object::*; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Here")] + #[cfg_attr(PyPy, link_name="PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut ::ffi3::PyFrameObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Print")] + #[cfg_attr(PyPy, link_name="PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Type")] + #[cfg_attr(PyPy, link_name="PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyTraceBack_Check")] +#[cfg_attr(PyPy, link_name="PyPyTraceBack_Check")] pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } \ No newline at end of file diff --git a/src/ffi3/tupleobject.rs b/src/ffi3/tupleobject.rs index 4822098cce4..f442748f1b2 100644 --- a/src/ffi3/tupleobject.rs +++ b/src/ffi3/tupleobject.rs @@ -10,7 +10,7 @@ pub struct PyTupleObject { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Type")] + #[cfg_attr(PyPy, link_name="PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; pub static mut PyTupleIter_Type: PyTypeObject; } @@ -26,19 +26,19 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_New")] + #[cfg_attr(PyPy, link_name="PyPyTuple_New")] pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Size")] + #[cfg_attr(PyPy, link_name="PyPyTuple_Size")] pub fn PyTuple_Size(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetItem")] + #[cfg_attr(PyPy, link_name="PyPyTuple_GetItem")] pub fn PyTuple_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_SetItem")] + #[cfg_attr(PyPy, link_name="PyPyTuple_SetItem")] pub fn PyTuple_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_GetSlice")] + #[cfg_attr(PyPy, link_name="PyPyTuple_GetSlice")] pub fn PyTuple_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyTuple_Pack")] + #[cfg_attr(PyPy, link_name="PyPyTuple_Pack")] pub fn PyTuple_Pack(arg1: Py_ssize_t, ...) -> *mut PyObject; pub fn PyTuple_ClearFreeList() -> c_int; } diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index e738fe534a4..ac87ab9fd8e 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -11,19 +11,19 @@ pub type Py_UCS2 = u16; pub type Py_UCS1 = u8; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Type")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; pub static mut PyUnicodeIter_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Check")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_Check")] pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CheckExact")] +#[cfg_attr(PyPy, link_name="PyPyUnicode_CheckExact")] pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyUnicode_Type) as c_int } @@ -44,11 +44,11 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; length: Py_ssize_t, fill_char: Py_UCS4) -> Py_ssize_t; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromUnicode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromUnicode")] pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromStringAndSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] pub fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; pub fn PyUnicode_FromString(u: *const c_char) -> *mut PyObject; @@ -65,69 +65,69 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; -> *mut Py_UCS4; pub fn PyUnicode_AsUCS4Copy(unicode: *mut PyObject) -> *mut Py_UCS4; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicode")] pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeAndSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeAndSize")] pub fn PyUnicode_AsUnicodeAndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut Py_UNICODE; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetLength")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetLength")] pub fn PyUnicode_GetLength(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetSize")] pub fn PyUnicode_GetSize(unicode: *mut PyObject) -> Py_ssize_t; pub fn PyUnicode_ReadChar(unicode: *mut PyObject, index: Py_ssize_t) -> Py_UCS4; pub fn PyUnicode_WriteChar(unicode: *mut PyObject, index: Py_ssize_t, character: Py_UCS4) -> c_int; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetMax")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetMax")] pub fn PyUnicode_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Resize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Resize")] pub fn PyUnicode_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] pub fn PyUnicode_FromEncodedObject(obj: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromObject")] pub fn PyUnicode_FromObject(obj: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromFormat")] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromFormatV")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromFormat")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromFormatV")] //pub fn PyUnicode_FromFormatV(format: *const c_char, // vargs: va_list) -> *mut PyObject; pub fn PyUnicode_FromFormat(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_InternInPlace")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_InternInPlace")] pub fn PyUnicode_InternInPlace(arg1: *mut *mut PyObject) -> (); pub fn PyUnicode_InternImmortal(arg1: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_InternFromString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_InternFromString")] pub fn PyUnicode_InternFromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromWideChar")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromWideChar")] pub fn PyUnicode_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideChar")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideChar")] pub fn PyUnicode_AsWideChar(unicode: *mut PyObject, w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsWideCharString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideCharString")] pub fn PyUnicode_AsWideCharString(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut wchar_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FromOrdinal")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FromOrdinal")] pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8AndSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8AndSize")] pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut c_char; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8")] pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_GetDefaultEncoding")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_GetDefaultEncoding")] pub fn PyUnicode_GetDefaultEncoding() -> *const c_char; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Decode")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] pub fn PyUnicode_Decode(s: *const c_char, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; @@ -143,12 +143,12 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_Encode(s: *const Py_UNICODE, size: Py_ssize_t, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedObject")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedObject")] pub fn PyUnicode_AsEncodedObject(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsEncodedString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedString")] pub fn PyUnicode_AsEncodedString(unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char) @@ -173,7 +173,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; base64WhiteSpace: c_int, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF8")] pub fn PyUnicode_DecodeUTF8(string: *const c_char, length: Py_ssize_t, errors: *const c_char) @@ -183,14 +183,14 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; errors: *const c_char, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF8String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] pub fn PyUnicode_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeUTF8")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeUTF8")] pub fn PyUnicode_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF32")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF32")] pub fn PyUnicode_DecodeUTF32(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -202,13 +202,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF32String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF32String")] pub fn PyUnicode_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_EncodeUTF32(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char, byteorder: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeUTF16")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF16")] pub fn PyUnicode_DecodeUTF16(string: *const c_char, length: Py_ssize_t, errors: *const c_char, @@ -220,7 +220,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; byteorder: *mut c_int, consumed: *mut Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUTF16String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF16String")] pub fn PyUnicode_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, @@ -230,7 +230,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsUnicodeEscapeString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeEscapeString")] pub fn PyUnicode_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] @@ -246,27 +246,27 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_EncodeRawUnicodeEscape(data: *const Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeLatin1")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeLatin1")] pub fn PyUnicode_DecodeLatin1(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsLatin1String")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsLatin1String")] pub fn PyUnicode_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeLatin1")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeLatin1")] pub fn PyUnicode_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeASCII")] pub fn PyUnicode_DecodeASCII(string: *const c_char, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_AsASCIIString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_AsASCIIString")] pub fn PyUnicode_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeASCII")] pub fn PyUnicode_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char) -> *mut PyObject; @@ -289,13 +289,13 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeDecimal")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeDecimal")] pub fn PyUnicode_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char) -> c_int; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_TransformDecimalToASCII")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_TransformDecimalToASCII")] pub fn PyUnicode_TransformDecimalToASCII(s: *mut Py_UNICODE, length: Py_ssize_t) -> *mut PyObject; @@ -309,32 +309,32 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_EncodeLocale(unicode: *mut PyObject, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FSConverter")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FSConverter")] pub fn PyUnicode_FSConverter(arg1: *mut PyObject, arg2: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_FSDecoder")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_FSDecoder")] pub fn PyUnicode_FSDecoder(arg1: *mut PyObject, arg2: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeFSDefault")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeFSDefault")] pub fn PyUnicode_DecodeFSDefault(s: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_DecodeFSDefaultAndSize")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeFSDefaultAndSize")] pub fn PyUnicode_DecodeFSDefaultAndSize(s: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_EncodeFSDefault")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeFSDefault")] pub fn PyUnicode_EncodeFSDefault(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Concat")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Concat")] pub fn PyUnicode_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; pub fn PyUnicode_Append(pleft: *mut *mut PyObject, right: *mut PyObject) -> (); pub fn PyUnicode_AppendAndDel(pleft: *mut *mut PyObject, right: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Split")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Split")] pub fn PyUnicode_Split(s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Splitlines")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Splitlines")] pub fn PyUnicode_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject; pub fn PyUnicode_Partition(s: *mut PyObject, sep: *mut PyObject) @@ -346,37 +346,37 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; pub fn PyUnicode_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Join")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Join")] pub fn PyUnicode_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Tailmatch")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Tailmatch")] pub fn PyUnicode_Tailmatch(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Find")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Find")] pub fn PyUnicode_Find(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; pub fn PyUnicode_FindChar(str: *mut PyObject, ch: Py_UCS4, start: Py_ssize_t, end: Py_ssize_t, direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Count")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Count")] pub fn PyUnicode_Count(str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Replace")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Replace")] pub fn PyUnicode_Replace(str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Compare")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Compare")] pub fn PyUnicode_Compare(left: *mut PyObject, right: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_CompareWithASCIIString")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_CompareWithASCIIString")] pub fn PyUnicode_CompareWithASCIIString(left: *mut PyObject, right: *const c_char) -> c_int; pub fn PyUnicode_RichCompare(left: *mut PyObject, right: *mut PyObject, op: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyUnicode_Format")] + #[cfg_attr(PyPy, link_name="PyPyUnicode_Format")] pub fn PyUnicode_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; pub fn PyUnicode_Contains(container: *mut PyObject, diff --git a/src/ffi3/warnings.rs b/src/ffi3/warnings.rs index 3f04459e5a9..a7aa9f5175d 100644 --- a/src/ffi3/warnings.rs +++ b/src/ffi3/warnings.rs @@ -6,7 +6,7 @@ use ffi3::object::PyObject; pub fn PyErr_WarnEx(category: *mut PyObject, message: *const c_char, stack_level: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyErr_WarnFormat")] + #[cfg_attr(PyPy, link_name="PyPyErr_WarnFormat")] pub fn PyErr_WarnFormat(category: *mut PyObject, stack_level: Py_ssize_t, format: *const c_char, ...) -> c_int; diff --git a/src/ffi3/weakrefobject.rs b/src/ffi3/weakrefobject.rs index 08da7a60963..0e8e45a2441 100644 --- a/src/ffi3/weakrefobject.rs +++ b/src/ffi3/weakrefobject.rs @@ -10,19 +10,19 @@ pub enum PyWeakReference {} } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRef")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckRefExact")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline(always)] -#[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_CheckProxy")] +#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckProxy")] 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 @@ -34,12 +34,12 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { } #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewRef")] + #[cfg_attr(PyPy, link_name="PyPyWeakref_NewRef")] pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_NewProxy")] + #[cfg_attr(PyPy, link_name="PyPyWeakref_NewProxy")] pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="\u{1}_PyPyWeakref_GetObject")] + #[cfg_attr(PyPy, link_name="PyPyWeakref_GetObject")] pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject; } \ No newline at end of file From 075f4a5e5d28fedb4897ee3a6262180fa3ce7583 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 7 Apr 2018 21:32:09 +0300 Subject: [PATCH 031/138] unite imports --- build.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index 46762c8a90f..89a78c3798c 100644 --- a/build.rs +++ b/build.rs @@ -1,12 +1,9 @@ extern crate pyo3_build_utils; use pyo3_build_utils::rustc_version::check_rustc_version; -use pyo3_build_utils::py_interpreter::{find_interpreter, emit_cargo_vars_from_configuration, get_config_vars}; -use pyo3_build_utils::py_interpreter::PythonVersion; -use pyo3_build_utils::py_interpreter::InterpreterConfig; -use pyo3_build_utils::py_interpreter::version_from_env; -use pyo3_build_utils::py_interpreter::cfg_line_for_var; -use pyo3_build_utils::py_interpreter::is_value; +use pyo3_build_utils::py_interpreter::{find_interpreter, emit_cargo_vars_from_configuration, + get_config_vars, PythonVersion, InterpreterConfig, + version_from_env, cfg_line_for_var, is_value}; fn main() { check_rustc_version(); From e68815fd97fae1e2008dd1115cac8a5b03b26e9c Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 26 Apr 2018 11:58:18 +0300 Subject: [PATCH 032/138] missing symbol --- src/ffi3/import.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ffi3/import.rs b/src/ffi3/import.rs index 2ec3bf00aac..9801c577a16 100644 --- a/src/ffi3/import.rs +++ b/src/ffi3/import.rs @@ -27,6 +27,7 @@ use ffi3::object::PyObject; #[cfg_attr(PyPy, link_name="PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name="PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name="PyPyImport_ImportModule")] pub fn PyImport_ImportModule(name: *const c_char) From 89fe0adcf778b89d60033804e0280fb688afe528 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 26 Apr 2018 12:13:03 +0300 Subject: [PATCH 033/138] fix pybool --- src/ffi3/boolobject.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ffi3/boolobject.rs b/src/ffi3/boolobject.rs index d620af82e7c..294c10c7269 100644 --- a/src/ffi3/boolobject.rs +++ b/src/ffi3/boolobject.rs @@ -5,6 +5,8 @@ use ffi3::longobject::PyLongObject; #[cfg_attr(windows, link(name="pythonXY"))] extern "C" { #[cfg_attr(PyPy, link_name="PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; + // define Py_False ((PyObject *) &_Py_ZeroStruct) + #[cfg_attr(PyPy, link_name="_PyPy_ZeroStruct")] static mut _Py_FalseStruct: PyLongObject; #[cfg_attr(PyPy, link_name="_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyLongObject; From 642a30575e0ad7f6df1e2c13f2318e33a4ba7e61 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 26 Apr 2018 12:13:22 +0300 Subject: [PATCH 034/138] implemented another missing symbol --- src/ffi3/object.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index fee5e90eaf2..2848c72e751 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -1,6 +1,7 @@ use std::ptr; use std::os::raw::{c_void, c_int, c_uint, c_ulong, c_char}; use ffi3::pyport::{Py_ssize_t, Py_hash_t}; +use ffi3::pyerrors::{PyErr_Format, PyExc_TypeError}; #[repr(C)] #[derive(Copy, Clone, Debug)] @@ -72,6 +73,21 @@ pub unsafe fn Py_REFCNT(ob : *mut PyObject) -> Py_ssize_t { (*ob).ob_refcnt } +macro_rules! cstr( + ($s: tt) => ( + // TODO: verify that $s is a string literal without nuls + unsafe { + ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) + } + ); +); + +#[cfg(PyPy)] +pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { + return PyErr_Format(PyExc_TypeError, cstr!("'%.200s' object is not iterable").as_ptr(), + Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject)) +} + #[inline(always)] pub unsafe fn Py_TYPE(ob : *mut PyObject) -> *mut PyTypeObject { (*ob).ob_type @@ -710,6 +726,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] + #[cfg(not(PyPy))] pub fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name="PyPyObject_GenericGetAttr")] From e0e46843db6051eb9bd344a4448a014a0efe2e8c Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 2 May 2018 23:46:40 +0300 Subject: [PATCH 035/138] it works --- pyo3build/src/py_interpreter.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index ebadf0d2bd1..d87dd4a814b 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -79,7 +79,6 @@ def get_abi_tag(): print(get_abi_tag()) "; -// TODO: I'm not sure this works in windows pub fn canonicalize_executable

(exe_name: P) -> Option where P: AsRef, From fc68c4a36f89999d1854eaa3505e658650f3c27e Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 3 May 2018 00:07:47 +0300 Subject: [PATCH 036/138] fix merge conflict --- Cargo.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 91ce526067d..dd29e25aaaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,14 +32,12 @@ pyo3cls = { version = "^0.2.1" } regex = "0.2" version_check = "0.1" pretty_assertions = "0.5.1" +pyo3-build-utils = {version = "*", path="pyo3build"} [dev-dependencies] pretty_assertions = "0.5.1" docmatic = "^0.1.2" -[build-dependencies] -pyo3-build-utils = {version = "*", path="pyo3build"} - [features] default = [] From 937be45db5e178babbccb2ae4e0f3ce239898aa1 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 4 May 2018 12:45:09 +0300 Subject: [PATCH 037/138] uncomment non default features --- Cargo.toml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd29e25aaaa..22f35c91e03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,6 @@ license = "Apache-2.0" exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"] build = "build.rs" -[lib] -doctest = false - [badges] travis-ci = { repository = "PyO3/pyo3", branch = "master" } appveyor = { repository = "PyO3/pyo3" } @@ -42,16 +39,16 @@ docmatic = "^0.1.2" default = [] # Use this feature when building python2 binding. -python2 = [] +# python2 = [] # Use this feature when building python3 binding. python3 = [] # Use this feature when building pypy binding. -pypy = [] +# pypy = [] # Enable additional features that require nightly rust -nightly = [] +# nightly = [] # Use this feature when building an extension module. # It tells the linker to keep the python symbols unresolved, From 9907633f432573f21d260fc4b05bd1f6a77d0526 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 28 Dec 2018 12:55:38 +0200 Subject: [PATCH 038/138] cargo.toml --- Cargo.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22f35c91e03..9f78080727a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ codecov = { repository = "PyO3/pyo3", branch = "master", service = "github" } [dependencies] log = "0.4" +pretty_assertions = "0.5.1" libc = "0.2" spin = "0.4.6" num-traits = "0.2" @@ -39,16 +40,16 @@ docmatic = "^0.1.2" default = [] # Use this feature when building python2 binding. -# python2 = [] + python2 = [] # Use this feature when building python3 binding. -python3 = [] +#python3 = [] # Use this feature when building pypy binding. -# pypy = [] + pypy = [] # Enable additional features that require nightly rust -# nightly = [] + nightly = [] # Use this feature when building an extension module. # It tells the linker to keep the python symbols unresolved, From 5c0b56caf44d120e91d783cf6889da54c5ee7b7b Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 28 Dec 2018 13:04:11 +0200 Subject: [PATCH 039/138] Cargo fmt --- build.rs | 11 +- src/argparse.rs | 67 +- src/buffer.rs | 268 ++++--- src/callback.rs | 22 +- src/class/async.rs | 135 ++-- src/class/basic.rs | 265 ++++--- src/class/buffer.rs | 54 +- src/class/context.rs | 41 +- src/class/descr.rs | 96 ++- src/class/gc.rs | 63 +- src/class/iter.rs | 72 +- src/class/macros.rs | 228 +++--- src/class/mapping.rs | 140 ++-- src/class/methods.rs | 45 +- src/class/mod.rs | 20 +- src/class/number.rs | 1167 +++++++++++++++++++++++------- src/class/sequence.rs | 240 ++++-- src/conversion.rs | 79 +- src/err.rs | 191 +++-- src/ffi2/boolobject.rs | 23 +- src/ffi2/bufferobject.rs | 47 +- src/ffi2/bytearrayobject.rs | 45 +- src/ffi2/bytesobject.rs | 22 +- src/ffi2/cellobject.rs | 22 +- src/ffi2/ceval.rs | 81 ++- src/ffi2/classobject.rs | 86 ++- src/ffi2/cobject.rs | 40 +- src/ffi2/code.rs | 97 +-- src/ffi2/compile.rs | 36 +- src/ffi2/complexobject.rs | 57 +- src/ffi2/descrobject.rs | 92 +-- src/ffi2/dictobject.rs | 103 ++- src/ffi2/enumobject.rs | 4 +- src/ffi2/eval.rs | 39 +- src/ffi2/fileobject.rs | 89 +-- src/ffi2/floatobject.rs | 44 +- src/ffi2/frameobject.rs | 75 +- src/ffi2/funcobject.rs | 40 +- src/ffi2/genobject.rs | 28 +- src/ffi2/import.rs | 126 ++-- src/ffi2/intobject.rs | 53 +- src/ffi2/iterobject.rs | 14 +- src/ffi2/listobject.rs | 86 +-- src/ffi2/longobject.rs | 153 ++-- src/ffi2/memoryobject.rs | 41 +- src/ffi2/methodobject.rs | 111 +-- src/ffi2/mod.rs | 158 ++-- src/ffi2/modsupport.rs | 177 +++-- src/ffi2/moduleobject.rs | 44 +- src/ffi2/object.rs | 374 +++++----- src/ffi2/objectabstract.rs | 602 ++++++++------- src/ffi2/objimpl.rs | 58 +- src/ffi2/pyarena.rs | 9 +- src/ffi2/pycapsule.rs | 66 +- src/ffi2/pydebug.rs | 43 +- src/ffi2/pyerrors.rs | 357 +++++---- src/ffi2/pymem.rs | 7 +- src/ffi2/pyport.rs | 5 +- src/ffi2/pystate.rs | 87 ++- src/ffi2/pythonrun.rs | 204 +++--- src/ffi2/rangeobject.rs | 11 +- src/ffi2/setobject.rs | 78 +- src/ffi2/sliceobject.rs | 65 +- src/ffi2/stringobject.rs | 190 ++--- src/ffi2/structmember.rs | 66 +- src/ffi2/traceback.rs | 30 +- src/ffi2/tupleobject.rs | 53 +- src/ffi2/unicodeobject.rs | 1040 +++++++++++++++----------- src/ffi2/warnings.rs | 34 +- src/ffi2/weakrefobject.rs | 50 +- src/ffi3/bltinmodule.rs | 3 +- src/ffi3/boolobject.rs | 21 +- src/ffi3/bytearrayobject.rs | 43 +- src/ffi3/bytesobject.rs | 67 +- src/ffi3/ceval.rs | 90 +-- src/ffi3/code.rs | 117 +-- src/ffi3/codecs.rs | 70 +- src/ffi3/compile.rs | 58 +- src/ffi3/complexobject.rs | 29 +- src/ffi3/descrobject.rs | 38 +- src/ffi3/dictobject.rs | 73 +- src/ffi3/enumobject.rs | 4 +- src/ffi3/eval.rs | 35 +- src/ffi3/fileobject.rs | 42 +- src/ffi3/floatobject.rs | 26 +- src/ffi3/frameobject.rs | 75 +- src/ffi3/genobject.rs | 39 +- src/ffi3/import.rs | 119 +-- src/ffi3/intrcheck.rs | 9 +- src/ffi3/iterobject.rs | 12 +- src/ffi3/listobject.rs | 55 +- src/ffi3/longobject.rs | 93 ++- src/ffi3/memoryobject.rs | 37 +- src/ffi3/methodobject.rs | 106 +-- src/ffi3/mod.rs | 129 ++-- src/ffi3/modsupport.rs | 151 ++-- src/ffi3/moduleobject.rs | 38 +- src/ffi3/object.rs | 488 +++++++------ src/ffi3/objectabstract.rs | 540 +++++++------- src/ffi3/objimpl.rs | 67 +- src/ffi3/osmodule.rs | 3 +- src/ffi3/pyarena.rs | 1 - src/ffi3/pycapsule.rs | 76 +- src/ffi3/pydebug.rs | 31 +- src/ffi3/pyerrors.rs | 357 ++++----- src/ffi3/pyhash.rs | 18 +- src/ffi3/pymem.rs | 68 +- src/ffi3/pyport.rs | 5 +- src/ffi3/pystate.rs | 44 +- src/ffi3/pystrtod.rs | 39 +- src/ffi3/pythonrun.rs | 283 ++++---- src/ffi3/rangeobject.rs | 9 +- src/ffi3/setobject.rs | 63 +- src/ffi3/sliceobject.rs | 59 +- src/ffi3/structmember.rs | 62 +- src/ffi3/structseq.rs | 22 +- src/ffi3/sysmodule.rs | 23 +- src/ffi3/traceback.rs | 17 +- src/ffi3/tupleobject.rs | 50 +- src/ffi3/typeslots.rs | 156 ++-- src/ffi3/unicodeobject.rs | 699 ++++++++++-------- src/ffi3/warnings.rs | 49 +- src/ffi3/weakrefobject.rs | 32 +- src/freelist.rs | 20 +- src/instance.rs | 132 ++-- src/lib.rs | 52 +- src/noargs.rs | 10 +- src/object.rs | 152 ++-- src/objectprotocol.rs | 290 +++++--- src/objects/boolobject.rs | 31 +- src/objects/bytearray.rs | 28 +- src/objects/dict.rs | 250 ++++--- src/objects/exc.rs | 62 +- src/objects/exc_impl.rs | 38 +- src/objects/floatob.rs | 16 +- src/objects/iterator.rs | 21 +- src/objects/list.rs | 76 +- src/objects/mod.rs | 33 +- src/objects/module.rs | 66 +- src/objects/num2.rs | 56 +- src/objects/num3.rs | 44 +- src/objects/sequence.rs | 130 ++-- src/objects/set.rs | 69 +- src/objects/slice.rs | 25 +- src/objects/string.rs | 45 +- src/objects/string2.rs | 47 +- src/objects/stringdata.rs | 73 +- src/objects/stringutils.rs | 6 +- src/objects/tuple.rs | 116 ++- src/objects/typeobject.rs | 29 +- src/prelude.rs | 17 +- src/python.rs | 187 +++-- src/pythonrun.rs | 69 +- src/typeob.rs | 165 +++-- tests/common.rs | 12 +- tests/test_arithmetics.rs | 138 +++- tests/test_buffer_protocol.rs | 28 +- tests/test_class_basics.rs | 27 +- tests/test_class_new.rs | 35 +- tests/test_doc.rs | 8 +- tests/test_gc.rs | 73 +- tests/test_getter_setter.rs | 11 +- tests/test_inheritance.rs | 21 +- tests/test_methods.rs | 114 ++- tests/test_module.rs | 37 +- tests/test_underscore_methods.rs | 129 ++-- tests/test_various.rs | 17 +- 167 files changed, 9513 insertions(+), 6998 deletions(-) diff --git a/build.rs b/build.rs index 89a78c3798c..84471c280d1 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,10 @@ extern crate pyo3_build_utils; +use pyo3_build_utils::py_interpreter::{ + cfg_line_for_var, emit_cargo_vars_from_configuration, find_interpreter, get_config_vars, + is_value, version_from_env, InterpreterConfig, PythonVersion, +}; use pyo3_build_utils::rustc_version::check_rustc_version; -use pyo3_build_utils::py_interpreter::{find_interpreter, emit_cargo_vars_from_configuration, - get_config_vars, PythonVersion, InterpreterConfig, - version_from_env, cfg_line_for_var, is_value}; fn main() { check_rustc_version(); @@ -22,7 +23,7 @@ fn main() { Err(_) => PythonVersion { major: 3, minor: None, - kind: None + kind: None, }, }; @@ -80,4 +81,4 @@ fn main() { "" } ); -} \ No newline at end of file +} diff --git a/src/argparse.rs b/src/argparse.rs index 4c5c8d159e3..288d2b5823e 100644 --- a/src/argparse.rs +++ b/src/argparse.rs @@ -3,11 +3,11 @@ // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython //! Python argument parsing -use ffi; +use conversion::PyTryFrom; use err::PyResult; +use ffi; +use objects::{exc, PyDict, PyObjectRef, PyString, PyTuple}; use python::Python; -use conversion::PyTryFrom; -use objects::{PyObjectRef, PyTuple, PyDict, PyString, exc}; #[derive(Debug)] /// Description of a python parameter; used for `parse_args()`. @@ -28,22 +28,26 @@ pub struct ParamDescription<'a> { /// * kwargs: Keyword arguments /// * output: Output array that receives the arguments. /// Must have same length as `params` and must be initialized to `None`. -pub fn parse_args<'p>(fname: Option<&str>, params: &[ParamDescription], - args: &'p PyTuple, kwargs: Option<&'p PyDict>, - accept_args: bool, accept_kwargs: bool, - output: &mut[Option<&'p PyObjectRef>]) -> PyResult<()> -{ +pub fn parse_args<'p>( + fname: Option<&str>, + params: &[ParamDescription], + args: &'p PyTuple, + kwargs: Option<&'p PyDict>, + accept_args: bool, + accept_kwargs: bool, + output: &mut [Option<&'p PyObjectRef>], +) -> PyResult<()> { let nargs = args.len(); let nkeywords = kwargs.map_or(0, |d| d.len()); if !accept_args && (nargs + nkeywords > params.len()) { - return Err(exc::TypeError::new( - format!("{}{} takes at most {} argument{} ({} given)", - fname.unwrap_or("function"), - if fname.is_some() { "()" } else { "" }, - params.len(), - if params.len() == 1 { "s" } else { "" }, - nargs + nkeywords - ))); + return Err(exc::TypeError::new(format!( + "{}{} takes at most {} argument{} ({} given)", + fname.unwrap_or("function"), + if fname.is_some() { "()" } else { "" }, + params.len(), + if params.len() == 1 { "s" } else { "" }, + nargs + nkeywords + ))); } let mut used_keywords = 0; // Iterate through the parameters and assign values to output: @@ -53,25 +57,32 @@ pub fn parse_args<'p>(fname: Option<&str>, params: &[ParamDescription], *out = Some(kwarg); used_keywords += 1; if i < nargs { - return Err(exc::TypeError::new( - format!("Argument given by name ('{}') and position ({})", p.name, i+1))); + return Err(exc::TypeError::new(format!( + "Argument given by name ('{}') and position ({})", + p.name, + i + 1 + ))); } - }, + } None => { if p.kw_only { if !p.is_optional { - return Err(exc::TypeError::new( - format!("Required argument ('{}') is keyword only argument", p.name))); + return Err(exc::TypeError::new(format!( + "Required argument ('{}') is keyword only argument", + p.name + ))); } *out = None; - } - else if i < nargs { + } else if i < nargs { *out = Some(args.get_item(i)); } else { *out = None; if !p.is_optional { - return Err(exc::TypeError::new( - format!("Required argument ('{}') (pos {}) not found", p.name, i+1))); + return Err(exc::TypeError::new(format!( + "Required argument ('{}') (pos {}) not found", + p.name, + i + 1 + ))); } } } @@ -83,8 +94,10 @@ pub fn parse_args<'p>(fname: Option<&str>, params: &[ParamDescription], let item = ::try_from(item)?; let key = ::try_from(item.get_item(0))?.to_string()?; if !params.iter().any(|p| p.name == key) { - return Err(exc::TypeError::new( - format!("'{}' is an invalid keyword argument for this function", key))); + return Err(exc::TypeError::new(format!( + "'{}' is an invalid keyword argument for this function", + key + ))); } } } diff --git a/src/buffer.rs b/src/buffer.rs index 529d3a22aca..240e914d852 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -17,16 +17,16 @@ // DEALINGS IN THE SOFTWARE. //! `PyBuffer` implementation -use std::os::raw; -use std::{mem, slice, cell}; -use std::ffi::CStr; use libc; +use std::ffi::CStr; +use std::os::raw; +use std::{cell, mem, slice}; -use ffi; -use exc; use err::{self, PyResult}; -use python::{Python, ToPyPointer}; +use exc; +use ffi; use objects::PyObjectRef; +use python::{Python, ToPyPointer}; /// Allows access to the underlying buffer used by a python object such as `bytes`, `bytearray` or `array.array`. pub struct PyBuffer(Box); // use Box<> because Python expects that the Py_buffer struct has a stable memory address @@ -42,7 +42,7 @@ pub enum ElementType { UnsignedInteger { bytes: usize }, Bool, Float { bytes: usize }, - Unknown + Unknown, } impl ElementType { @@ -54,7 +54,7 @@ impl ElementType { match slice[0] { b'@' => native_element_type_from_type_char(slice[1]), b'=' | b'<' | b'>' | b'!' => standard_element_type_from_type_char(slice[1]), - _ => ElementType::Unknown + _ => ElementType::Unknown, } } else { ElementType::Unknown @@ -65,24 +65,50 @@ impl ElementType { fn native_element_type_from_type_char(type_char: u8) -> ElementType { use self::ElementType::*; match type_char { - b'c' => UnsignedInteger { bytes: mem::size_of::() }, - b'b' => SignedInteger { bytes: mem::size_of::() }, - b'B' => UnsignedInteger { bytes: mem::size_of::() }, + b'c' => UnsignedInteger { + bytes: mem::size_of::(), + }, + b'b' => SignedInteger { + bytes: mem::size_of::(), + }, + b'B' => UnsignedInteger { + bytes: mem::size_of::(), + }, b'?' => Bool, - b'h' => SignedInteger { bytes: mem::size_of::() }, - b'H' => UnsignedInteger { bytes: mem::size_of::() }, - b'i' => SignedInteger { bytes: mem::size_of::() }, - b'I' => UnsignedInteger { bytes: mem::size_of::() }, - b'l' => SignedInteger { bytes: mem::size_of::() }, - b'L' => UnsignedInteger { bytes: mem::size_of::() }, - b'q' => SignedInteger { bytes: mem::size_of::() }, - b'Q' => UnsignedInteger { bytes: mem::size_of::() }, - b'n' => SignedInteger { bytes: mem::size_of::() }, - b'N' => UnsignedInteger { bytes: mem::size_of::() }, + b'h' => SignedInteger { + bytes: mem::size_of::(), + }, + b'H' => UnsignedInteger { + bytes: mem::size_of::(), + }, + b'i' => SignedInteger { + bytes: mem::size_of::(), + }, + b'I' => UnsignedInteger { + bytes: mem::size_of::(), + }, + b'l' => SignedInteger { + bytes: mem::size_of::(), + }, + b'L' => UnsignedInteger { + bytes: mem::size_of::(), + }, + b'q' => SignedInteger { + bytes: mem::size_of::(), + }, + b'Q' => UnsignedInteger { + bytes: mem::size_of::(), + }, + b'n' => SignedInteger { + bytes: mem::size_of::(), + }, + b'N' => UnsignedInteger { + bytes: mem::size_of::(), + }, b'e' => Float { bytes: 2 }, b'f' => Float { bytes: 4 }, b'd' => Float { bytes: 8 }, - _ => Unknown + _ => Unknown, } } @@ -90,18 +116,18 @@ fn standard_element_type_from_type_char(type_char: u8) -> ElementType { use self::ElementType::*; match type_char { b'c' | b'B' => UnsignedInteger { bytes: 1 }, - b'b' => SignedInteger { bytes: 1 }, + b'b' => SignedInteger { bytes: 1 }, b'?' => Bool, - b'h' => SignedInteger { bytes: 2 }, + b'h' => SignedInteger { bytes: 2 }, b'H' => UnsignedInteger { bytes: 2 }, - b'i' | b'l' => SignedInteger { bytes: 4 }, + b'i' | b'l' => SignedInteger { bytes: 4 }, b'I' | b'L' => UnsignedInteger { bytes: 4 }, - b'q' => SignedInteger { bytes: 8 }, + b'q' => SignedInteger { bytes: 8 }, b'Q' => UnsignedInteger { bytes: 8 }, b'e' => Float { bytes: 2 }, b'f' => Float { bytes: 4 }, b'd' => Float { bytes: 8 }, - _ => Unknown + _ => Unknown, } } @@ -109,7 +135,7 @@ fn standard_element_type_from_type_char(type_char: u8) -> ElementType { fn is_matching_endian(c: u8) -> bool { match c { b'@' | b'=' | b'<' => true, - _ => false + _ => false, } } @@ -117,7 +143,7 @@ fn is_matching_endian(c: u8) -> bool { fn is_matching_endian(c: u8) -> bool { match c { b'@' | b'=' | b'>' | b'!' => true, - _ => false + _ => false, } } @@ -140,7 +166,9 @@ impl PyBuffer { unsafe { let mut buf = Box::new(mem::zeroed::()); err::error_on_minusone( - py, ffi::PyObject_GetBuffer(obj.as_ptr(), &mut *buf, ffi::PyBUF_FULL_RO))?; + py, + ffi::PyObject_GetBuffer(obj.as_ptr(), &mut *buf, ffi::PyBUF_FULL_RO), + )?; validate(&buf); Ok(PyBuffer(buf)) } @@ -166,7 +194,7 @@ impl PyBuffer { unsafe { ffi::PyBuffer_GetPointer( &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, - indices.as_ptr() as *mut usize as *mut ffi::Py_ssize_t + indices.as_ptr() as *mut usize as *mut ffi::Py_ssize_t, ) } } @@ -215,9 +243,7 @@ impl PyBuffer { /// However, dimensions of length 0 are possible and might need special attention. #[inline] pub fn shape(&self) -> &[usize] { - unsafe { - slice::from_raw_parts(self.0.shape as *const usize, self.0.ndim as usize) - } + unsafe { slice::from_raw_parts(self.0.shape as *const usize, self.0.ndim as usize) } } /// Returns an array that holds, for each dimension, the number of bytes to skip to get to the next element in the dimension. @@ -226,9 +252,7 @@ impl PyBuffer { /// but a consumer MUST be able to handle the case `strides[n] <= 0`. #[inline] pub fn strides(&self) -> &[isize] { - unsafe { - slice::from_raw_parts(self.0.strides, self.0.ndim as usize) - } + unsafe { slice::from_raw_parts(self.0.strides, self.0.ndim as usize) } } /// An array of length ndim. @@ -242,7 +266,10 @@ impl PyBuffer { if self.0.suboffsets.is_null() { None } else { - Some(slice::from_raw_parts(self.0.suboffsets, self.0.ndim as usize)) + Some(slice::from_raw_parts( + self.0.suboffsets, + self.0.ndim as usize, + )) } } } @@ -262,7 +289,10 @@ impl PyBuffer { pub fn is_c_contiguous(&self) -> bool { unsafe { // Python 2.7 is not const-correct, so we need the cast to *mut - ffi::PyBuffer_IsContiguous(&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, b'C' as libc::c_char) != 0 + ffi::PyBuffer_IsContiguous( + &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, + b'C' as libc::c_char, + ) != 0 } } @@ -271,7 +301,10 @@ impl PyBuffer { pub fn is_fortran_contiguous(&self) -> bool { unsafe { // Python 2.7 is not const-correct, so we need the cast to *mut - ffi::PyBuffer_IsContiguous(&*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, b'F' as libc::c_char) != 0 + ffi::PyBuffer_IsContiguous( + &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, + b'F' as libc::c_char, + ) != 0 } } @@ -290,7 +323,12 @@ impl PyBuffer { && self.is_c_contiguous() && T::is_compatible_format(self.format()) { - unsafe { Some(slice::from_raw_parts(self.0.buf as *mut ReadOnlyCell, self.item_count())) } + unsafe { + Some(slice::from_raw_parts( + self.0.buf as *mut ReadOnlyCell, + self.item_count(), + )) + } } else { None } @@ -313,7 +351,12 @@ impl PyBuffer { && self.is_c_contiguous() && T::is_compatible_format(self.format()) { - unsafe { Some(slice::from_raw_parts(self.0.buf as *mut cell::Cell, self.item_count())) } + unsafe { + Some(slice::from_raw_parts( + self.0.buf as *mut cell::Cell, + self.item_count(), + )) + } } else { None } @@ -328,13 +371,21 @@ impl PyBuffer { /// /// The returned slice uses type `Cell` because it's theoretically possible for any call into the Python runtime /// to modify the values in the slice. - pub fn as_fortran_slice<'a, T: Element>(&'a self, _py: Python<'a>) -> Option<&'a [ReadOnlyCell]> { + pub fn as_fortran_slice<'a, T: Element>( + &'a self, + _py: Python<'a>, + ) -> Option<&'a [ReadOnlyCell]> { if mem::size_of::() == self.item_size() && (self.0.buf as usize) % mem::align_of::() == 0 && self.is_fortran_contiguous() && T::is_compatible_format(self.format()) { - unsafe { Some(slice::from_raw_parts(self.0.buf as *mut ReadOnlyCell, self.item_count())) } + unsafe { + Some(slice::from_raw_parts( + self.0.buf as *mut ReadOnlyCell, + self.item_count(), + )) + } } else { None } @@ -350,14 +401,22 @@ impl PyBuffer { /// /// The returned slice uses type `Cell` because it's theoretically possible for any call into the Python runtime /// to modify the values in the slice. - pub fn as_fortran_mut_slice<'a, T: Element>(&'a self, _py: Python<'a>) -> Option<&'a [cell::Cell]> { + pub fn as_fortran_mut_slice<'a, T: Element>( + &'a self, + _py: Python<'a>, + ) -> Option<&'a [cell::Cell]> { if !self.readonly() && mem::size_of::() == self.item_size() && (self.0.buf as usize) % mem::align_of::() == 0 && self.is_fortran_contiguous() && T::is_compatible_format(self.format()) { - unsafe { Some(slice::from_raw_parts(self.0.buf as *mut cell::Cell, self.item_count())) } + unsafe { + Some(slice::from_raw_parts( + self.0.buf as *mut cell::Cell, + self.item_count(), + )) + } } else { None } @@ -372,7 +431,7 @@ impl PyBuffer { /// To check whether the buffer format is compatible before calling this method, /// you can use `::is_compatible_format(buf.format())`. /// Alternatively, `match buffer::ElementType::from_format(buf.format())`. - pub fn copy_to_slice(&self, py: Python, target: &mut [T]) -> PyResult<()> { + pub fn copy_to_slice(&self, py: Python, target: &mut [T]) -> PyResult<()> { self.copy_to_slice_impl(py, target, b'C') } @@ -385,24 +444,38 @@ impl PyBuffer { /// To check whether the buffer format is compatible before calling this method, /// you can use `::is_compatible_format(buf.format())`. /// Alternatively, `match buffer::ElementType::from_format(buf.format())`. - pub fn copy_to_fortran_slice(&self, py: Python, target: &mut [T]) -> PyResult<()> { + pub fn copy_to_fortran_slice( + &self, + py: Python, + target: &mut [T], + ) -> PyResult<()> { self.copy_to_slice_impl(py, target, b'F') } - fn copy_to_slice_impl(&self, py: Python, target: &mut [T], fort: u8) -> PyResult<()> { + fn copy_to_slice_impl( + &self, + py: Python, + target: &mut [T], + fort: u8, + ) -> PyResult<()> { if mem::size_of_val(target) != self.len_bytes() { - return Err(exc::BufferError::new("Slice length does not match buffer length.")); + return Err(exc::BufferError::new( + "Slice length does not match buffer length.", + )); } if !T::is_compatible_format(self.format()) || mem::size_of::() != self.item_size() { return incompatible_format_error(); } unsafe { - err::error_on_minusone(py, ffi::PyBuffer_ToContiguous( - target.as_ptr() as *mut raw::c_void, - &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, - self.0.len, - fort as libc::c_char - )) + err::error_on_minusone( + py, + ffi::PyBuffer_ToContiguous( + target.as_ptr() as *mut raw::c_void, + &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, + self.0.len, + fort as libc::c_char, + ), + ) } } @@ -410,7 +483,7 @@ impl PyBuffer { /// If the buffer is multi-dimensional, the elements are written in C-style order. /// /// Fails if the buffer format is not compatible with type `T`. - pub fn to_vec(&self, py: Python) -> PyResult> { + pub fn to_vec(&self, py: Python) -> PyResult> { self.to_vec_impl(py, b'C') } @@ -418,11 +491,11 @@ impl PyBuffer { /// If the buffer is multi-dimensional, the elements are written in Fortran-style order. /// /// Fails if the buffer format is not compatible with type `T`. - pub fn to_fortran_vec(&self, py: Python) -> PyResult> { + pub fn to_fortran_vec(&self, py: Python) -> PyResult> { self.to_vec_impl(py, b'F') } - fn to_vec_impl(&self, py: Python, fort: u8) -> PyResult> { + fn to_vec_impl(&self, py: Python, fort: u8) -> PyResult> { if !T::is_compatible_format(self.format()) || mem::size_of::() != self.item_size() { incompatible_format_error()?; unreachable!(); @@ -432,12 +505,15 @@ impl PyBuffer { unsafe { // Copy the buffer into the uninitialized space in the vector. // Due to T:Copy, we don't need to be concerned with Drop impls. - err::error_on_minusone(py, ffi::PyBuffer_ToContiguous( - vec.as_mut_ptr() as *mut raw::c_void, - &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, - self.0.len, - fort as libc::c_char - ))?; + err::error_on_minusone( + py, + ffi::PyBuffer_ToContiguous( + vec.as_mut_ptr() as *mut raw::c_void, + &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, + self.0.len, + fort as libc::c_char, + ), + )?; // set vector length to mark the now-initialized space as usable vec.set_len(item_count); } @@ -454,7 +530,7 @@ impl PyBuffer { /// To check whether the buffer format is compatible before calling this method, /// use `::is_compatible_format(buf.format())`. /// Alternatively, `match buffer::ElementType::from_format(buf.format())`. - pub fn copy_from_slice(&self, py: Python, source: &[T]) -> PyResult<()> { + pub fn copy_from_slice(&self, py: Python, source: &[T]) -> PyResult<()> { self.copy_from_slice_impl(py, source, b'C') } @@ -468,27 +544,41 @@ impl PyBuffer { /// To check whether the buffer format is compatible before calling this method, /// use `::is_compatible_format(buf.format())`. /// Alternatively, `match buffer::ElementType::from_format(buf.format())`. - pub fn copy_from_fortran_slice(&self, py: Python, source: &[T]) -> PyResult<()> { + pub fn copy_from_fortran_slice( + &self, + py: Python, + source: &[T], + ) -> PyResult<()> { self.copy_from_slice_impl(py, source, b'F') } - fn copy_from_slice_impl(&self, py: Python, source: &[T], fort: u8) -> PyResult<()> { + fn copy_from_slice_impl( + &self, + py: Python, + source: &[T], + fort: u8, + ) -> PyResult<()> { if self.readonly() { return buffer_readonly_error(); } if mem::size_of_val(source) != self.len_bytes() { - return Err(exc::BufferError::new("Slice length does not match buffer length.")); + return Err(exc::BufferError::new( + "Slice length does not match buffer length.", + )); } if !T::is_compatible_format(self.format()) || mem::size_of::() != self.item_size() { return incompatible_format_error(); } unsafe { - err::error_on_minusone(py, ffi::PyBuffer_FromContiguous( - &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, - source.as_ptr() as *mut raw::c_void, - self.0.len, - fort as libc::c_char - )) + err::error_on_minusone( + py, + ffi::PyBuffer_FromContiguous( + &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer, + source.as_ptr() as *mut raw::c_void, + self.0.len, + fort as libc::c_char, + ), + ) } } @@ -502,7 +592,9 @@ impl PyBuffer { } fn incompatible_format_error() -> PyResult<()> { - Err(exc::BufferError::new("Slice type is incompatible with buffer format.")) + Err(exc::BufferError::new( + "Slice type is incompatible with buffer format.", + )) } fn buffer_readonly_error() -> PyResult<()> { @@ -523,7 +615,7 @@ impl Drop for PyBuffer { /// be modifying the data. pub struct ReadOnlyCell(cell::UnsafeCell); -impl ReadOnlyCell { +impl ReadOnlyCell { #[inline] pub fn get(&self) -> T { unsafe { *self.0.get() } @@ -562,12 +654,11 @@ impl_element!(isize, SignedInteger); impl_element!(f32, Float); impl_element!(f64, Float); - #[cfg(test)] mod test { - use std; - use python::{Python}; use super::PyBuffer; + use python::Python; + use std; #[allow(unused_imports)] use objectprotocol::ObjectProtocol; @@ -575,7 +666,10 @@ mod test { #[test] fn test_compatible_size() { // for the cast in PyBuffer::shape() - assert_eq!(std::mem::size_of::<::ffi::Py_ssize_t>(), std::mem::size_of::()); + assert_eq!( + std::mem::size_of::<::ffi::Py_ssize_t>(), + std::mem::size_of::() + ); } #[test] @@ -619,8 +713,11 @@ mod test { fn test_array_buffer() { let gil = Python::acquire_gil(); let py = gil.python(); - let array = py.import("array").unwrap().call_method( - "array", ("f", (1.0, 1.5, 2.0, 2.5)), ::NoArgs).unwrap(); + let array = py + .import("array") + .unwrap() + .call_method("array", ("f", (1.0, 1.5, 2.0, 2.5)), ::NoArgs) + .unwrap(); let buffer = PyBuffer::get(py, array.into()).unwrap(); assert_eq!(buffer.dimensions(), 1); assert_eq!(buffer.item_count(), 4); @@ -641,10 +738,11 @@ mod test { mut_slice[3].set(2.75); assert_eq!(slice[3].get(), 2.75); - buffer.copy_from_slice(py, &[10.0f32, 11.0, 12.0, 13.0]).unwrap(); + buffer + .copy_from_slice(py, &[10.0f32, 11.0, 12.0, 13.0]) + .unwrap(); assert_eq!(slice[2].get(), 12.0); assert_eq!(buffer.to_vec::(py).unwrap(), [10.0, 11.0, 12.0, 13.0]); } } - diff --git a/src/callback.rs b/src/callback.rs index 62d0f4a4be4..4abdab05fb9 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -3,14 +3,13 @@ //! Utilities for a Python callable object that invokes a Rust function. use std::os::raw::c_int; -use std::{ptr, isize}; +use std::{isize, ptr}; +use conversion::IntoPyObject; use err::PyResult; use ffi::{self, Py_hash_t}; -use python::{Python, IntoPyPointer}; use objects::exc::OverflowError; -use conversion::IntoPyObject; - +use python::{IntoPyPointer, Python}; pub trait CallbackConverter { type R; @@ -22,7 +21,8 @@ pub trait CallbackConverter { pub struct PyObjectCallbackConverter; impl CallbackConverter for PyObjectCallbackConverter - where S: IntoPyObject +where + S: IntoPyObject, { type R = *mut ffi::PyObject; @@ -36,7 +36,6 @@ impl CallbackConverter for PyObjectCallbackConverter } } - pub struct BoolCallbackConverter; impl CallbackConverter for BoolCallbackConverter { @@ -73,7 +72,6 @@ impl CallbackConverter for LenResultConverter { } } - pub struct UnitCallbackConverter; impl CallbackConverter<()> for UnitCallbackConverter { @@ -102,7 +100,7 @@ macro_rules! wrapping_cast { self as $to } } - } + }; } wrapping_cast!(u8, Py_hash_t); wrapping_cast!(u16, Py_hash_t); @@ -117,8 +115,9 @@ wrapping_cast!(i64, Py_hash_t); pub struct HashConverter; -impl CallbackConverter for HashConverter - where T: WrappingCastTo +impl CallbackConverter for HashConverter +where + T: WrappingCastTo, { type R = Py_hash_t; @@ -141,7 +140,8 @@ impl CallbackConverter for HashConverter #[inline] #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] pub unsafe fn cb_convert(_c: C, py: Python, value: PyResult) -> C::R - where C: CallbackConverter +where + C: CallbackConverter, { match value { Ok(val) => C::convert(val, py), diff --git a/src/class/async.rs b/src/class/async.rs index 7ec212d2b41..6363885a621 100644 --- a/src/class/async.rs +++ b/src/class/async.rs @@ -8,36 +8,56 @@ //! [PEP-0492](https://www.python.org/dev/peps/pep-0492/) //! -use ffi; -use err::PyResult; use callback::PyObjectCallbackConverter; -use typeob::PyTypeInfo; use class::methods::PyMethodDef; - +use err::PyResult; +use ffi; +use typeob::PyTypeInfo; /// Python Async/Await support interface. /// /// Each method in this trait corresponds to Python async/await implementation. #[allow(unused_variables)] pub trait PyAsyncProtocol<'p>: PyTypeInfo { + fn __await__(&'p self) -> Self::Result + where + Self: PyAsyncAwaitProtocol<'p>, + { + unimplemented!() + } - fn __await__(&'p self) - -> Self::Result where Self: PyAsyncAwaitProtocol<'p> { unimplemented!() } - - fn __aiter__(&'p self) - -> Self::Result where Self: PyAsyncAiterProtocol<'p> { unimplemented!() } + fn __aiter__(&'p self) -> Self::Result + where + Self: PyAsyncAiterProtocol<'p>, + { + unimplemented!() + } - fn __anext__(&'p mut self) - -> Self::Result where Self: PyAsyncAnextProtocol<'p> { unimplemented!() } + fn __anext__(&'p mut self) -> Self::Result + where + Self: PyAsyncAnextProtocol<'p>, + { + unimplemented!() + } - fn __aenter__(&'p mut self) - -> Self::Result where Self: PyAsyncAenterProtocol<'p> { unimplemented!() } + fn __aenter__(&'p mut self) -> Self::Result + where + Self: PyAsyncAenterProtocol<'p>, + { + unimplemented!() + } - fn __aexit__(&'p mut self, - exc_type: Option, - exc_value: Option, - traceback: Option) - -> Self::Result where Self: PyAsyncAexitProtocol<'p> { unimplemented!() } + fn __aexit__( + &'p mut self, + exc_type: Option, + exc_value: Option, + traceback: Option, + ) -> Self::Result + where + Self: PyAsyncAexitProtocol<'p>, + { + unimplemented!() + } } pub trait PyAsyncAwaitProtocol<'p>: PyAsyncProtocol<'p> { @@ -68,7 +88,6 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> { type Result: Into>; } - #[cfg(Py_3)] #[doc(hidden)] pub trait PyAsyncProtocolImpl { @@ -91,7 +110,10 @@ impl PyAsyncProtocolImpl for T { } #[cfg(Py_3)] -impl<'p, T> PyAsyncProtocolImpl for T where T: PyAsyncProtocol<'p> { +impl<'p, T> PyAsyncProtocolImpl for T +where + T: PyAsyncProtocol<'p>, +{ #[inline] fn tp_as_async() -> Option { Some(ffi::PyAsyncMethods { @@ -116,12 +138,13 @@ impl<'p, T> PyAsyncProtocolImpl for T where T: PyAsyncProtocol<'p> { } } - trait PyAsyncAwaitProtocolImpl { fn am_await() -> Option; } -impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p> +impl<'p, T> PyAsyncAwaitProtocolImpl for T +where + T: PyAsyncProtocol<'p>, { #[inline] default fn am_await() -> Option { @@ -129,12 +152,18 @@ impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p> } } -impl PyAsyncAwaitProtocolImpl for T where T: for<'p> PyAsyncAwaitProtocol<'p> +impl PyAsyncAwaitProtocolImpl for T +where + T: for<'p> PyAsyncAwaitProtocol<'p>, { #[inline] fn am_await() -> Option { - py_unary_func!(PyAsyncAwaitProtocol, T::__await__, - ::Success, PyObjectCallbackConverter) + py_unary_func!( + PyAsyncAwaitProtocol, + T::__await__, + ::Success, + PyObjectCallbackConverter + ) } } @@ -142,7 +171,9 @@ trait PyAsyncAiterProtocolImpl { fn am_aiter() -> Option; } -impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p> +impl<'p, T> PyAsyncAiterProtocolImpl for T +where + T: PyAsyncProtocol<'p>, { #[inline] default fn am_aiter() -> Option { @@ -150,12 +181,18 @@ impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p> } } -impl PyAsyncAiterProtocolImpl for T where T: for<'p> PyAsyncAiterProtocol<'p> +impl PyAsyncAiterProtocolImpl for T +where + T: for<'p> PyAsyncAiterProtocol<'p>, { #[inline] fn am_aiter() -> Option { - py_unary_func!(PyAsyncAiterProtocol, T::__aiter__, - ::Success, PyObjectCallbackConverter) + py_unary_func!( + PyAsyncAiterProtocol, + T::__aiter__, + ::Success, + PyObjectCallbackConverter + ) } } @@ -163,7 +200,9 @@ trait PyAsyncAnextProtocolImpl { fn am_anext() -> Option; } -impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p> +impl<'p, T> PyAsyncAnextProtocolImpl for T +where + T: PyAsyncProtocol<'p>, { #[inline] default fn am_anext() -> Option { @@ -171,20 +210,20 @@ impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p> } } - #[cfg(Py_3)] mod anext { - use std::ptr; - use ffi; + use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl}; use callback::CallbackConverter; use conversion::IntoPyObject; - use python::{Python, IntoPyPointer}; - use super::{PyAsyncAnextProtocolImpl, PyAsyncAnextProtocol}; + use ffi; + use python::{IntoPyPointer, Python}; + use std::ptr; pub struct IterANextResultConverter; - impl CallbackConverter> for IterANextResultConverter - where T: IntoPyObject + impl CallbackConverter> for IterANextResultConverter + where + T: IntoPyObject, { type R = *mut ffi::PyObject; @@ -194,7 +233,7 @@ mod anext { None => unsafe { ffi::PyErr_SetNone(ffi::PyExc_StopAsyncIteration); ptr::null_mut() - } + }, } } @@ -204,12 +243,18 @@ mod anext { } } - impl PyAsyncAnextProtocolImpl for T where T: for<'p> PyAsyncAnextProtocol<'p> + impl PyAsyncAnextProtocolImpl for T + where + T: for<'p> PyAsyncAnextProtocol<'p>, { #[inline] fn am_anext() -> Option { - py_unary_func!(PyAsyncAnextProtocol, T::__anext__, - Option, IterANextResultConverter) + py_unary_func!( + PyAsyncAnextProtocol, + T::__anext__, + Option, + IterANextResultConverter + ) } } } @@ -218,7 +263,9 @@ trait PyAsyncAenterProtocolImpl { fn __aenter__() -> Option; } -impl<'p, T> PyAsyncAenterProtocolImpl for T where T: PyAsyncProtocol<'p> +impl<'p, T> PyAsyncAenterProtocolImpl for T +where + T: PyAsyncProtocol<'p>, { #[inline] default fn __aenter__() -> Option { @@ -230,7 +277,9 @@ trait PyAsyncAexitProtocolImpl { fn __aexit__() -> Option; } -impl<'p, T> PyAsyncAexitProtocolImpl for T where T: PyAsyncProtocol<'p> +impl<'p, T> PyAsyncAexitProtocolImpl for T +where + T: PyAsyncProtocol<'p>, { #[inline] default fn __aexit__() -> Option { diff --git a/src/class/basic.rs b/src/class/basic.rs index c02832fd714..2f691018c5a 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -8,58 +8,99 @@ use std; use std::os::raw::c_int; -use ::CompareOp; -use ffi; +use callback::{BoolCallbackConverter, HashConverter, PyObjectCallbackConverter}; +use class::methods::PyMethodDef; +use conversion::{FromPyObject, IntoPyObject}; use err::{PyErr, PyResult}; -use python::{Python, IntoPyPointer}; +use ffi; +use objectprotocol::ObjectProtocol; use objects::{exc, PyObjectRef}; +use python::{IntoPyPointer, Python}; use typeob::PyTypeInfo; -use conversion::{FromPyObject, IntoPyObject}; -use objectprotocol::ObjectProtocol; -use callback::{PyObjectCallbackConverter, HashConverter, BoolCallbackConverter}; -use class::methods::PyMethodDef; - +use CompareOp; /// Basic python class customization #[allow(unused_variables)] pub trait PyObjectProtocol<'p>: PyTypeInfo { + fn __getattr__(&'p self, name: Self::Name) -> Self::Result + where + Self: PyObjectGetAttrProtocol<'p>, + { + unimplemented!() + } - fn __getattr__(&'p self, name: Self::Name) - -> Self::Result where Self: PyObjectGetAttrProtocol<'p> {unimplemented!()} - - fn __setattr__(&'p mut self, name: Self::Name, value: Self::Value) - -> Self::Result where Self: PyObjectSetAttrProtocol<'p> {unimplemented!()} + fn __setattr__(&'p mut self, name: Self::Name, value: Self::Value) -> Self::Result + where + Self: PyObjectSetAttrProtocol<'p>, + { + unimplemented!() + } - fn __delattr__(&'p mut self, name: Self::Name) - -> Self::Result where Self: PyObjectDelAttrProtocol<'p> {unimplemented!()} + fn __delattr__(&'p mut self, name: Self::Name) -> Self::Result + where + Self: PyObjectDelAttrProtocol<'p>, + { + unimplemented!() + } - fn __str__(&'p self) - -> Self::Result where Self: PyObjectStrProtocol<'p> {unimplemented!()} + fn __str__(&'p self) -> Self::Result + where + Self: PyObjectStrProtocol<'p>, + { + unimplemented!() + } - fn __repr__(&'p self) - -> Self::Result where Self: PyObjectReprProtocol<'p> {unimplemented!()} + fn __repr__(&'p self) -> Self::Result + where + Self: PyObjectReprProtocol<'p>, + { + unimplemented!() + } - fn __format__(&'p self, format_spec: Self::Format) - -> Self::Result where Self: PyObjectFormatProtocol<'p> {unimplemented!()} + fn __format__(&'p self, format_spec: Self::Format) -> Self::Result + where + Self: PyObjectFormatProtocol<'p>, + { + unimplemented!() + } - fn __hash__(&'p self) - -> Self::Result where Self: PyObjectHashProtocol<'p> {unimplemented!()} + fn __hash__(&'p self) -> Self::Result + where + Self: PyObjectHashProtocol<'p>, + { + unimplemented!() + } - fn __bool__(&'p self) - -> Self::Result where Self: PyObjectBoolProtocol<'p> {unimplemented!()} + fn __bool__(&'p self) -> Self::Result + where + Self: PyObjectBoolProtocol<'p>, + { + unimplemented!() + } - fn __bytes__(&'p self) - -> Self::Result where Self: PyObjectBytesProtocol<'p> {unimplemented!()} + fn __bytes__(&'p self) -> Self::Result + where + Self: PyObjectBytesProtocol<'p>, + { + unimplemented!() + } /// This method is used by Python2 only. - fn __unicode__(&'p self) - -> Self::Result where Self: PyObjectUnicodeProtocol<'p> {unimplemented!()} + fn __unicode__(&'p self) -> Self::Result + where + Self: PyObjectUnicodeProtocol<'p>, + { + unimplemented!() + } - fn __richcmp__(&'p self, other: Self::Other, op: CompareOp) - -> Self::Result where Self: PyObjectRichcmpProtocol<'p> {unimplemented!()} + fn __richcmp__(&'p self, other: Self::Other, op: CompareOp) -> Self::Result + where + Self: PyObjectRichcmpProtocol<'p>, + { + unimplemented!() + } } - pub trait PyObjectGetAttrProtocol<'p>: PyObjectProtocol<'p> { type Name: FromPyObject<'p>; type Success: IntoPyObject; @@ -107,7 +148,6 @@ pub trait PyObjectRichcmpProtocol<'p>: PyObjectProtocol<'p> { type Result: Into>; } - #[doc(hidden)] pub trait PyObjectProtocolImpl { fn methods() -> Vec; @@ -119,14 +159,16 @@ impl PyObjectProtocolImpl for T { default fn methods() -> Vec { Vec::new() } - default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) { - } + default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {} default fn nb_bool_fn() -> Option { None } } -impl<'p, T> PyObjectProtocolImpl for T where T: PyObjectProtocol<'p> { +impl<'p, T> PyObjectProtocolImpl for T +where + T: PyObjectProtocol<'p>, +{ #[inline] fn methods() -> Vec { let mut methods = Vec::new(); @@ -163,35 +205,46 @@ impl<'p, T> PyObjectProtocolImpl for T where T: PyObjectProtocol<'p> { trait PyObjectGetAttrProtocolImpl { fn tp_getattro() -> Option; } -impl<'p, T> PyObjectGetAttrProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectGetAttrProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_getattro() -> Option { None } } -impl PyObjectGetAttrProtocolImpl for T where T: for<'p> PyObjectGetAttrProtocol<'p> +impl PyObjectGetAttrProtocolImpl for T +where + T: for<'p> PyObjectGetAttrProtocol<'p>, { #[inline] fn tp_getattro() -> Option { - py_binary_func!(PyObjectGetAttrProtocol, - T::__getattr__, T::Success, PyObjectCallbackConverter) + py_binary_func!( + PyObjectGetAttrProtocol, + T::__getattr__, + T::Success, + PyObjectCallbackConverter + ) } } - trait PyObjectSetAttrProtocolImpl { fn tp_setattro() -> Option; } -impl<'p, T> PyObjectSetAttrProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectSetAttrProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_setattro() -> Option { None } } -impl PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtocol<'p> +impl PyObjectSetAttrProtocolImpl for T +where + T: for<'p> PyObjectSetAttrProtocol<'p>, { #[inline] fn tp_setattro() -> Option { @@ -199,18 +252,21 @@ impl PyObjectSetAttrProtocolImpl for T where T: for<'p> PyObjectSetAttrProtoc } } - trait PyObjectDelAttrProtocolImpl { fn tp_delattro() -> Option; } -impl<'p, T> PyObjectDelAttrProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectDelAttrProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_delattro() -> Option { None } } -impl PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtocol<'p> +impl PyObjectDelAttrProtocolImpl for T +where + T: for<'p> PyObjectDelAttrProtocol<'p>, { #[inline] default fn tp_delattro() -> Option { @@ -218,51 +274,70 @@ impl PyObjectDelAttrProtocolImpl for T where T: for<'p> PyObjectDelAttrProtoc } } impl PyObjectDelAttrProtocolImpl for T - where T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p> +where + T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, { #[inline] fn tp_delattro() -> Option { - py_func_set_del!(PyObjectSetAttrProtocol, PyObjectDelAttrProtocol, - T::__setattr__/__delattr__) + py_func_set_del!( + PyObjectSetAttrProtocol, + PyObjectDelAttrProtocol, + T::__setattr__ / __delattr__ + ) } } - trait PyObjectStrProtocolImpl { fn tp_str() -> Option; } -impl<'p, T> PyObjectStrProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectStrProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_str() -> Option { None } } -impl PyObjectStrProtocolImpl for T where T: for<'p> PyObjectStrProtocol<'p> +impl PyObjectStrProtocolImpl for T +where + T: for<'p> PyObjectStrProtocol<'p>, { #[inline] fn tp_str() -> Option { - py_unary_func!(PyObjectStrProtocol, T::__str__, - ::Success, PyObjectCallbackConverter) + py_unary_func!( + PyObjectStrProtocol, + T::__str__, + ::Success, + PyObjectCallbackConverter + ) } } trait PyObjectReprProtocolImpl { fn tp_repr() -> Option; } -impl<'p, T> PyObjectReprProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectReprProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_repr() -> Option { None } } -impl PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p> +impl PyObjectReprProtocolImpl for T +where + T: for<'p> PyObjectReprProtocol<'p>, { #[inline] fn tp_repr() -> Option { - py_unary_func!(PyObjectReprProtocol, - T::__repr__, T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyObjectReprProtocol, + T::__repr__, + T::Success, + PyObjectCallbackConverter + ) } } @@ -270,7 +345,9 @@ impl PyObjectReprProtocolImpl for T where T: for<'p> PyObjectReprProtocol<'p> pub trait PyObjectFormatProtocolImpl { fn __format__() -> Option; } -impl<'p, T> PyObjectFormatProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectFormatProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn __format__() -> Option { @@ -282,7 +359,9 @@ impl<'p, T> PyObjectFormatProtocolImpl for T where T: PyObjectProtocol<'p> pub trait PyObjectBytesProtocolImpl { fn __bytes__() -> Option; } -impl<'p, T> PyObjectBytesProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectBytesProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn __bytes__() -> Option { @@ -294,7 +373,9 @@ impl<'p, T> PyObjectBytesProtocolImpl for T where T: PyObjectProtocol<'p> pub trait PyObjectUnicodeProtocolImpl { fn __unicode__() -> Option; } -impl<'p, T> PyObjectUnicodeProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectUnicodeProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn __unicode__() -> Option { @@ -305,7 +386,9 @@ impl<'p, T> PyObjectUnicodeProtocolImpl for T where T: PyObjectProtocol<'p> trait PyObjectHashProtocolImpl { fn tp_hash() -> Option; } -impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectHashProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_hash() -> Option { @@ -313,36 +396,55 @@ impl<'p, T> PyObjectHashProtocolImpl for T where T: PyObjectProtocol<'p> } } impl PyObjectHashProtocolImpl for T - where T: for<'p> PyObjectHashProtocol<'p> +where + T: for<'p> PyObjectHashProtocol<'p>, { #[inline] fn tp_hash() -> Option { - py_unary_func!(PyObjectHashProtocol, T::__hash__, isize, HashConverter, ffi::Py_hash_t) + py_unary_func!( + PyObjectHashProtocol, + T::__hash__, + isize, + HashConverter, + ffi::Py_hash_t + ) } } trait PyObjectBoolProtocolImpl { fn nb_bool() -> Option; } -impl<'p, T> PyObjectBoolProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectBoolProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn nb_bool() -> Option { None } } -impl PyObjectBoolProtocolImpl for T where T: for<'p> PyObjectBoolProtocol<'p> +impl PyObjectBoolProtocolImpl for T +where + T: for<'p> PyObjectBoolProtocol<'p>, { #[inline] fn nb_bool() -> Option { - py_unary_func!(PyObjectBoolProtocol, T::__bool__, bool, BoolCallbackConverter, c_int) + py_unary_func!( + PyObjectBoolProtocol, + T::__bool__, + bool, + BoolCallbackConverter, + c_int + ) } } trait PyObjectRichcmpProtocolImpl { fn tp_richcompare() -> Option; } -impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p> +impl<'p, T> PyObjectRichcmpProtocolImpl for T +where + T: PyObjectProtocol<'p>, { #[inline] default fn tp_richcompare() -> Option { @@ -350,14 +452,18 @@ impl<'p, T> PyObjectRichcmpProtocolImpl for T where T: PyObjectProtocol<'p> } } impl PyObjectRichcmpProtocolImpl for T - where T: for<'p> PyObjectRichcmpProtocol<'p> +where + T: for<'p> PyObjectRichcmpProtocol<'p>, { #[inline] fn tp_richcompare() -> Option { - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - arg: *mut ffi::PyObject, - op: c_int) -> *mut ffi::PyObject - where T: for<'p> PyObjectRichcmpProtocol<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + arg: *mut ffi::PyObject, + op: c_int, + ) -> *mut ffi::PyObject + where + T: for<'p> PyObjectRichcmpProtocol<'p>, { let _pool = ::GILPool::new(); let py = Python::assume_gil_acquired(); @@ -366,16 +472,13 @@ impl PyObjectRichcmpProtocolImpl for T let res = match extract_op(op) { Ok(op) => match arg.extract() { - Ok(arg) => - slf.__richcmp__(arg, op).into(), + Ok(arg) => slf.__richcmp__(arg, op).into(), Err(e) => Err(e), }, - Err(e) => Err(e) + Err(e) => Err(e), }; match res { - Ok(val) => { - val.into_object(py).into_ptr() - } + Ok(val) => val.into_object(py).into_ptr(), Err(e) => { e.restore(py); std::ptr::null_mut() @@ -386,7 +489,6 @@ impl PyObjectRichcmpProtocolImpl for T } } - fn extract_op(op: c_int) -> PyResult { match op { ffi::Py_LT => Ok(CompareOp::Lt), @@ -396,6 +498,7 @@ fn extract_op(op: c_int) -> PyResult { ffi::Py_GT => Ok(CompareOp::Gt), ffi::Py_GE => Ok(CompareOp::Ge), _ => Err(PyErr::new::( - "tp_richcompare called with invalid comparison operator")) + "tp_richcompare called with invalid comparison operator", + )), } } diff --git a/src/class/buffer.rs b/src/class/buffer.rs index c74aaf19e21..03b175b606f 100644 --- a/src/class/buffer.rs +++ b/src/class/buffer.rs @@ -6,25 +6,30 @@ //! c-api use std::os::raw::c_int; -use ffi; +use callback::UnitCallbackConverter; use err::PyResult; +use ffi; use typeob::PyTypeInfo; -use callback::UnitCallbackConverter; - /// Buffer protocol interface /// /// For more information check [buffer protocol](https://docs.python.org/3/c-api/buffer.html) /// c-api #[allow(unused_variables)] -pub trait PyBufferProtocol<'p> : PyTypeInfo -{ - fn bf_getbuffer(&'p self, - view: *mut ffi::Py_buffer, flags: c_int) -> Self::Result - where Self: PyBufferGetBufferProtocol<'p> { unimplemented!() } +pub trait PyBufferProtocol<'p>: PyTypeInfo { + fn bf_getbuffer(&'p self, view: *mut ffi::Py_buffer, flags: c_int) -> Self::Result + where + Self: PyBufferGetBufferProtocol<'p>, + { + unimplemented!() + } fn bf_releasebuffer(&'p self, view: *mut ffi::Py_buffer) -> Self::Result - where Self: PyBufferReleaseBufferProtocol<'p> { unimplemented!() } + where + Self: PyBufferReleaseBufferProtocol<'p>, + { + unimplemented!() + } } pub trait PyBufferGetBufferProtocol<'p>: PyBufferProtocol<'p> { @@ -35,25 +40,28 @@ pub trait PyBufferReleaseBufferProtocol<'p>: PyBufferProtocol<'p> { type Result: Into>; } - #[doc(hidden)] pub trait PyBufferProtocolImpl { fn tp_as_buffer() -> Option; } impl PyBufferProtocolImpl for T { - default fn tp_as_buffer() -> Option { None } + default fn tp_as_buffer() -> Option { + None + } } -impl<'p, T> PyBufferProtocolImpl for T where T: PyBufferProtocol<'p> +impl<'p, T> PyBufferProtocolImpl for T +where + T: PyBufferProtocol<'p>, { #[inline] #[cfg_attr(feature = "cargo-clippy", allow(needless_update))] fn tp_as_buffer() -> Option { - Some(ffi::PyBufferProcs{ + Some(ffi::PyBufferProcs { bf_getbuffer: Self::cb_bf_getbuffer(), bf_releasebuffer: None, - .. ffi::PyBufferProcs_INIT + ..ffi::PyBufferProcs_INIT }) } } @@ -62,7 +70,9 @@ trait PyBufferGetBufferProtocolImpl { fn cb_bf_getbuffer() -> Option; } -impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p> +impl<'p, T> PyBufferGetBufferProtocolImpl for T +where + T: PyBufferProtocol<'p>, { #[inline] default fn cb_bf_getbuffer() -> Option { @@ -71,14 +81,18 @@ impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p> } impl PyBufferGetBufferProtocolImpl for T - where T: for<'p> PyBufferGetBufferProtocol<'p> +where + T: for<'p> PyBufferGetBufferProtocol<'p>, { #[inline] fn cb_bf_getbuffer() -> Option { - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - arg1: *mut ffi::Py_buffer, - arg2: c_int) -> c_int - where T: for<'p> PyBufferGetBufferProtocol<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + arg1: *mut ffi::Py_buffer, + arg2: c_int, + ) -> c_int + where + T: for<'p> PyBufferGetBufferProtocol<'p>, { let _pool = ::GILPool::new(); let py = ::Python::assume_gil_acquired(); diff --git a/src/class/context.rs b/src/class/context.rs index 4f0ac7aa71b..cec618a2337 100644 --- a/src/class/context.rs +++ b/src/class/context.rs @@ -4,23 +4,31 @@ //! Trait and support implementation for context manager api //! +use class::methods::PyMethodDef; use err::PyResult; use typeob::PyTypeInfo; -use class::methods::PyMethodDef; - /// Context manager interface #[allow(unused_variables)] pub trait PyContextProtocol<'p>: PyTypeInfo { + fn __enter__(&'p mut self) -> Self::Result + where + Self: PyContextEnterProtocol<'p>, + { + unimplemented!() + } - fn __enter__(&'p mut self) - -> Self::Result where Self: PyContextEnterProtocol<'p> {unimplemented!()} - - fn __exit__(&'p mut self, - exc_type: Option, - exc_value: Option, - traceback: Option) - -> Self::Result where Self: PyContextExitProtocol<'p> { unimplemented!() } + fn __exit__( + &'p mut self, + exc_type: Option, + exc_value: Option, + traceback: Option, + ) -> Self::Result + where + Self: PyContextExitProtocol<'p>, + { + unimplemented!() + } } pub trait PyContextEnterProtocol<'p>: PyContextProtocol<'p> { @@ -48,7 +56,10 @@ impl PyContextProtocolImpl for T { } } -impl<'p, T> PyContextProtocolImpl for T where T: PyContextProtocol<'p> { +impl<'p, T> PyContextProtocolImpl for T +where + T: PyContextProtocol<'p>, +{ #[inline] fn methods() -> Vec { let mut methods = Vec::new(); @@ -69,7 +80,9 @@ pub trait PyContextEnterProtocolImpl { fn __enter__() -> Option; } -impl<'p, T> PyContextEnterProtocolImpl for T where T: PyContextProtocol<'p> +impl<'p, T> PyContextEnterProtocolImpl for T +where + T: PyContextProtocol<'p>, { #[inline] default fn __enter__() -> Option { @@ -82,7 +95,9 @@ pub trait PyContextExitProtocolImpl { fn __exit__() -> Option; } -impl<'p, T> PyContextExitProtocolImpl for T where T: PyContextProtocol<'p> +impl<'p, T> PyContextExitProtocolImpl for T +where + T: PyContextProtocol<'p>, { #[inline] default fn __exit__() -> Option { diff --git a/src/class/descr.rs b/src/class/descr.rs index ff638cd9532..93fac3e767d 100644 --- a/src/class/descr.rs +++ b/src/class/descr.rs @@ -7,30 +7,44 @@ use std::os::raw::c_int; -use ffi; -use err::PyResult; -use objects::{PyType, PyObjectRef}; use callback::{PyObjectCallbackConverter, UnitCallbackConverter}; -use typeob::PyTypeInfo; use class::methods::PyMethodDef; -use conversion::{IntoPyObject, FromPyObject}; - +use conversion::{FromPyObject, IntoPyObject}; +use err::PyResult; +use ffi; +use objects::{PyObjectRef, PyType}; +use typeob::PyTypeInfo; /// Descriptor interface #[allow(unused_variables)] pub trait PyDescrProtocol<'p>: PyTypeInfo { + fn __get__(&'p self, instance: &'p PyObjectRef, owner: Option<&'p PyType>) -> Self::Result + where + Self: PyDescrGetProtocol<'p>, + { + unimplemented!() + } - fn __get__(&'p self, instance: &'p PyObjectRef, owner: Option<&'p PyType>) - -> Self::Result where Self: PyDescrGetProtocol<'p> { unimplemented!() } - - fn __set__(&'p self, instance: &'p PyObjectRef, value: &'p PyObjectRef) - -> Self::Result where Self: PyDescrSetProtocol<'p> { unimplemented!() } + fn __set__(&'p self, instance: &'p PyObjectRef, value: &'p PyObjectRef) -> Self::Result + where + Self: PyDescrSetProtocol<'p>, + { + unimplemented!() + } - fn __delete__(&'p self, instance: &'p PyObjectRef) - -> Self::Result where Self: PyDescrDeleteProtocol<'p> { unimplemented!() } + fn __delete__(&'p self, instance: &'p PyObjectRef) -> Self::Result + where + Self: PyDescrDeleteProtocol<'p>, + { + unimplemented!() + } - fn __set_name__(&'p self, instance: &'p PyObjectRef) - -> Self::Result where Self: PyDescrSetNameProtocol<'p> { unimplemented!() } + fn __set_name__(&'p self, instance: &'p PyObjectRef) -> Self::Result + where + Self: PyDescrSetNameProtocol<'p>, + { + unimplemented!() + } } pub trait PyDescrGetProtocol<'p>: PyDescrProtocol<'p> { @@ -56,40 +70,63 @@ pub trait PyDescrSetNameProtocol<'p>: PyDescrProtocol<'p> { type Result: Into>; } - trait PyDescrGetProtocolImpl { fn tp_descr_get() -> Option; } -impl<'p, T> PyDescrGetProtocolImpl for T where T: PyDescrProtocol<'p> { +impl<'p, T> PyDescrGetProtocolImpl for T +where + T: PyDescrProtocol<'p>, +{ default fn tp_descr_get() -> Option { None } } -impl PyDescrGetProtocolImpl for T where T: for<'p> PyDescrGetProtocol<'p> +impl PyDescrGetProtocolImpl for T +where + T: for<'p> PyDescrGetProtocol<'p>, { fn tp_descr_get() -> Option { - py_ternary_func!(PyDescrGetProtocol, T::__get__, T::Success, PyObjectCallbackConverter) + py_ternary_func!( + PyDescrGetProtocol, + T::__get__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyDescrSetProtocolImpl { fn tp_descr_set() -> Option; } -impl<'p, T> PyDescrSetProtocolImpl for T where T: PyDescrProtocol<'p> { +impl<'p, T> PyDescrSetProtocolImpl for T +where + T: PyDescrProtocol<'p>, +{ default fn tp_descr_set() -> Option { None } } -impl PyDescrSetProtocolImpl for T where T: for<'p> PyDescrSetProtocol<'p> +impl PyDescrSetProtocolImpl for T +where + T: for<'p> PyDescrSetProtocol<'p>, { fn tp_descr_set() -> Option { - py_ternary_func!(PyDescrSetProtocol, T::__set__, (), UnitCallbackConverter, c_int) + py_ternary_func!( + PyDescrSetProtocol, + T::__set__, + (), + UnitCallbackConverter, + c_int + ) } } trait PyDescrDelProtocolImpl { fn __del__() -> Option; } -impl<'p, T> PyDescrDelProtocolImpl for T where T: PyDescrProtocol<'p> { +impl<'p, T> PyDescrDelProtocolImpl for T +where + T: PyDescrProtocol<'p>, +{ default fn __del__() -> Option { None } @@ -98,7 +135,10 @@ impl<'p, T> PyDescrDelProtocolImpl for T where T: PyDescrProtocol<'p> { trait PyDescrSetNameProtocolImpl { fn __set_name__() -> Option; } -impl<'p, T> PyDescrSetNameProtocolImpl for T where T: PyDescrProtocol<'p> { +impl<'p, T> PyDescrSetNameProtocolImpl for T +where + T: PyDescrProtocol<'p>, +{ default fn __set_name__() -> Option { None } @@ -114,11 +154,13 @@ impl PyDescrProtocolImpl for T { default fn methods() -> Vec { Vec::new() } - default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) { - } + default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {} } -impl<'p, T> PyDescrProtocolImpl for T where T: PyDescrProtocol<'p> { +impl<'p, T> PyDescrProtocolImpl for T +where + T: PyDescrProtocol<'p>, +{ fn methods() -> Vec { Vec::new() } diff --git a/src/class/gc.rs b/src/class/gc.rs index 355d27e8c04..bc045b220b0 100644 --- a/src/class/gc.rs +++ b/src/class/gc.rs @@ -13,13 +13,14 @@ pub struct PyTraverseError(c_int); /// GC support #[allow(unused_variables)] -pub trait PyGCProtocol<'p> : PyTypeInfo { - - fn __traverse__(&'p self, visit: PyVisit) - -> Result<(), PyTraverseError> { unimplemented!() } - - fn __clear__(&'p mut self) { unimplemented!() } +pub trait PyGCProtocol<'p>: PyTypeInfo { + fn __traverse__(&'p self, visit: PyVisit) -> Result<(), PyTraverseError> { + unimplemented!() + } + fn __clear__(&'p mut self) { + unimplemented!() + } } pub trait PyGCTraverseProtocol<'p>: PyGCProtocol<'p> {} @@ -34,7 +35,9 @@ impl<'p, T> PyGCProtocolImpl for T { default fn update_type_object(_type_object: &mut ffi::PyTypeObject) {} } -impl<'p, T> PyGCProtocolImpl for T where T: PyGCProtocol<'p> +impl<'p, T> PyGCProtocolImpl for T +where + T: PyGCProtocol<'p>, { fn update_type_object(type_object: &mut ffi::PyTypeObject) { type_object.tp_traverse = Self::tp_traverse(); @@ -49,12 +52,13 @@ pub struct PyVisit<'p> { /// VisitProc contains a Python instance to ensure that /// 1) it is cannot be moved out of the traverse() call /// 2) it cannot be sent to other threads - _py: Python<'p> + _py: Python<'p>, } -impl <'p> PyVisit<'p> { +impl<'p> PyVisit<'p> { pub fn call(&self, obj: &T) -> Result<(), PyTraverseError> - where T: ToPyPointer + where + T: ToPyPointer, { let r = unsafe { (self.visit)(obj.as_ptr(), self.arg) }; if r == 0 { @@ -69,7 +73,9 @@ trait PyGCTraverseProtocolImpl { fn tp_traverse() -> Option; } -impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p> +impl<'p, T> PyGCTraverseProtocolImpl for T +where + T: PyGCProtocol<'p>, { #[inline] default fn tp_traverse() -> Option { @@ -78,23 +84,32 @@ impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p> } #[doc(hidden)] -impl PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p> +impl PyGCTraverseProtocolImpl for T +where + T: for<'p> PyGCTraverseProtocol<'p>, { #[inline] fn tp_traverse() -> Option { - unsafe extern "C" fn tp_traverse(slf: *mut ffi::PyObject, - visit: ffi::visitproc, - arg: *mut c_void) -> c_int - where T: for<'p> PyGCTraverseProtocol<'p> + unsafe extern "C" fn tp_traverse( + slf: *mut ffi::PyObject, + visit: ffi::visitproc, + arg: *mut c_void, + ) -> c_int + where + T: for<'p> PyGCTraverseProtocol<'p>, { let _pool = ::GILPool::new(); let py = Python::assume_gil_acquired(); let slf = py.mut_from_borrowed_ptr::(slf); - let visit = PyVisit { visit: visit, arg: arg, _py: py }; + let visit = PyVisit { + visit: visit, + arg: arg, + _py: py, + }; match slf.__traverse__(visit) { Ok(()) => 0, - Err(PyTraverseError(code)) => code + Err(PyTraverseError(code)) => code, } } @@ -102,12 +117,13 @@ impl PyGCTraverseProtocolImpl for T where T: for<'p> PyGCTraverseProtocol<'p> } } - trait PyGCClearProtocolImpl { fn tp_clear() -> Option; } -impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p> +impl<'p, T> PyGCClearProtocolImpl for T +where + T: PyGCProtocol<'p>, { #[inline] default fn tp_clear() -> Option { @@ -115,12 +131,15 @@ impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p> } } -impl PyGCClearProtocolImpl for T where T: for<'p> PyGCClearProtocol<'p> +impl PyGCClearProtocolImpl for T +where + T: for<'p> PyGCClearProtocol<'p>, { #[inline] fn tp_clear() -> Option { unsafe extern "C" fn tp_clear(slf: *mut ffi::PyObject) -> c_int - where T: for<'p> PyGCClearProtocol<'p> + where + T: for<'p> PyGCClearProtocol<'p>, { let _pool = ::GILPool::new(); let py = Python::assume_gil_acquired(); diff --git a/src/class/iter.rs b/src/class/iter.rs index fddd75a9de8..f014ab0aaa8 100644 --- a/src/class/iter.rs +++ b/src/class/iter.rs @@ -4,26 +4,32 @@ use std::ptr; -use ffi; +use callback::{CallbackConverter, PyObjectCallbackConverter}; +use conversion::IntoPyObject; use err::PyResult; -use python::{Python, IntoPyPointer}; +use ffi; +use python::{IntoPyPointer, Python}; use typeob::PyTypeInfo; -use conversion::IntoPyObject; -use callback::{CallbackConverter, PyObjectCallbackConverter}; - /// Python Iterator Interface. /// /// more information /// `https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_iter` #[allow(unused_variables)] -pub trait PyIterProtocol<'p> : PyTypeInfo { - fn __iter__(&'p mut self) - -> Self::Result where Self: PyIterIterProtocol<'p> { unimplemented!() } - - fn __next__(&'p mut self) - -> Self::Result where Self: PyIterNextProtocol<'p> { unimplemented!() } +pub trait PyIterProtocol<'p>: PyTypeInfo { + fn __iter__(&'p mut self) -> Self::Result + where + Self: PyIterIterProtocol<'p>, + { + unimplemented!() + } + fn __next__(&'p mut self) -> Self::Result + where + Self: PyIterNextProtocol<'p>, + { + unimplemented!() + } } pub trait PyIterIterProtocol<'p>: PyIterProtocol<'p> { @@ -36,7 +42,6 @@ pub trait PyIterNextProtocol<'p>: PyIterProtocol<'p> { type Result: Into>>; } - #[doc(hidden)] pub trait PyIterProtocolImpl { fn tp_as_iter(typeob: &mut ffi::PyTypeObject); @@ -47,7 +52,10 @@ impl PyIterProtocolImpl for T { default fn tp_as_iter(_: &mut ffi::PyTypeObject) {} } -impl<'p, T> PyIterProtocolImpl for T where T: PyIterProtocol<'p> { +impl<'p, T> PyIterProtocolImpl for T +where + T: PyIterProtocol<'p>, +{ #[inline] fn tp_as_iter(typeob: &mut ffi::PyTypeObject) { typeob.tp_iter = Self::tp_iter(); @@ -59,7 +67,9 @@ trait PyIterIterProtocolImpl { fn tp_iter() -> Option; } -impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p> +impl<'p, T> PyIterIterProtocolImpl for T +where + T: PyIterProtocol<'p>, { #[inline] default fn tp_iter() -> Option { @@ -67,11 +77,18 @@ impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p> } } -impl PyIterIterProtocolImpl for T where T: for<'p> PyIterIterProtocol<'p> +impl PyIterIterProtocolImpl for T +where + T: for<'p> PyIterIterProtocol<'p>, { #[inline] fn tp_iter() -> Option { - py_unary_func!(PyIterIterProtocol, T::__iter__, T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyIterIterProtocol, + T::__iter__, + T::Success, + PyObjectCallbackConverter + ) } } @@ -80,7 +97,8 @@ trait PyIterNextProtocolImpl { } impl<'p, T> PyIterNextProtocolImpl for T - where T: PyIterProtocol<'p> +where + T: PyIterProtocol<'p>, { #[inline] default fn tp_iternext() -> Option { @@ -88,20 +106,26 @@ impl<'p, T> PyIterNextProtocolImpl for T } } -impl PyIterNextProtocolImpl for T where T: for<'p> PyIterNextProtocol<'p> +impl PyIterNextProtocolImpl for T +where + T: for<'p> PyIterNextProtocol<'p>, { #[inline] fn tp_iternext() -> Option { - py_unary_func!(PyIterNextProtocol, T::__next__, - Option, IterNextConverter) + py_unary_func!( + PyIterNextProtocol, + T::__next__, + Option, + IterNextConverter + ) } } - struct IterNextConverter; -impl CallbackConverter> for IterNextConverter - where T: IntoPyObject +impl CallbackConverter> for IterNextConverter +where + T: IntoPyObject, { type R = *mut ffi::PyObject; @@ -111,7 +135,7 @@ impl CallbackConverter> for IterNextConverter None => unsafe { ffi::PyErr_SetNone(ffi::PyExc_StopIteration); ptr::null_mut() - } + }, } } diff --git a/src/class/macros.rs b/src/class/macros.rs index 086c5156046..3c6d86a260f 100644 --- a/src/class/macros.rs +++ b/src/class/macros.rs @@ -4,11 +4,18 @@ #[doc(hidden)] macro_rules! py_unary_func { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => { - py_unary_func!($trait, $class::$f, $res_type, $conv, *mut $crate::ffi::PyObject); + py_unary_func!( + $trait, + $class::$f, + $res_type, + $conv, + *mut $crate::ffi::PyObject + ); }; ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr, $ret_type:ty) => {{ unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject) -> $ret_type - where T: for<'p> $trait<'p> + where + T: for<'p> $trait<'p>, { let _pool = $crate::GILPool::new(); let py = $crate::Python::assume_gil_acquired(); @@ -17,16 +24,16 @@ macro_rules! py_unary_func { $crate::callback::cb_convert($conv, py, res) } Some(wrap::<$class>) - }} + }}; } #[macro_export] #[doc(hidden)] - macro_rules! py_unary_func_self { +macro_rules! py_unary_func_self { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:ty) => {{ - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject) - -> *mut $crate::ffi::PyObject - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject) -> *mut $crate::ffi::PyObject + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; let _pool = $crate::GILPool::new(); @@ -36,17 +43,16 @@ macro_rules! py_unary_func { $crate::callback::cb_convert($conv, py, res) } Some(wrap::<$class>) - }} + }}; } - #[macro_export] #[doc(hidden)] macro_rules! py_len_func { ($trait:ident, $class:ident :: $f:ident, $conv:expr) => {{ - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject) - -> $crate::ffi::Py_ssize_t - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject) -> $crate::ffi::Py_ssize_t + where + T: for<'p> $trait<'p>, { let _pool = $crate::GILPool::new(); let py = Python::assume_gil_acquired(); @@ -56,20 +62,26 @@ macro_rules! py_len_func { $crate::callback::cb_convert($conv, py, result) } Some(wrap::<$class>) - }} + }}; } #[macro_export] #[doc(hidden)] -macro_rules! py_binary_func{ +macro_rules! py_binary_func { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => { - py_binary_func!($trait, $class::$f, $res_type, $conv, *mut $crate::ffi::PyObject) + py_binary_func!( + $trait, + $class::$f, + $res_type, + $conv, + *mut $crate::ffi::PyObject + ) }; ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr, $return:ty) => {{ #[allow(unused_mut)] - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - arg: *mut ffi::PyObject) -> $return - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, arg: *mut ffi::PyObject) -> $return + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; let _pool = $crate::GILPool::new(); @@ -84,17 +96,20 @@ macro_rules! py_binary_func{ $crate::callback::cb_convert($conv, py, result) } Some(wrap::<$class>) - }} + }}; } #[macro_export] #[doc(hidden)] -macro_rules! py_binary_num_func{ +macro_rules! py_binary_num_func { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {{ #[allow(unused_mut)] - unsafe extern "C" fn wrap(lhs: *mut ffi::PyObject, - rhs: *mut ffi::PyObject) -> *mut $crate::ffi::PyObject - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + lhs: *mut ffi::PyObject, + rhs: *mut ffi::PyObject, + ) -> *mut $crate::ffi::PyObject + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; let _pool = $crate::GILPool::new(); @@ -112,17 +127,20 @@ macro_rules! py_binary_num_func{ $crate::callback::cb_convert($conv, py, result) } Some(wrap::<$class>) - }} + }}; } #[macro_export] #[doc(hidden)] -macro_rules! py_binary_self_func{ +macro_rules! py_binary_self_func { ($trait:ident, $class:ident :: $f:ident) => {{ #[allow(unused_mut)] - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - arg: *mut ffi::PyObject) -> *mut $crate::ffi::PyObject - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + arg: *mut ffi::PyObject, + ) -> *mut $crate::ffi::PyObject + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; @@ -147,18 +165,20 @@ macro_rules! py_binary_self_func{ } } Some(wrap::<$class>) - }} + }}; } - #[macro_export] #[doc(hidden)] macro_rules! py_ssizearg_func { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {{ #[allow(unused_mut)] - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - arg: $crate::ffi::Py_ssize_t) -> *mut $crate::ffi::PyObject - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + arg: $crate::ffi::Py_ssize_t, + ) -> *mut $crate::ffi::PyObject + where + T: for<'p> $trait<'p>, { let _pool = $crate::GILPool::new(); let py = $crate::Python::assume_gil_acquired(); @@ -167,20 +187,29 @@ macro_rules! py_ssizearg_func { $crate::callback::cb_convert($conv, py, result) } Some(wrap::<$class>) - }} + }}; } #[macro_export] #[doc(hidden)] -macro_rules! py_ternary_func{ +macro_rules! py_ternary_func { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => { - py_ternary_func!($trait, $class::$f, $res_type, $conv, *mut $crate::ffi::PyObject); + py_ternary_func!( + $trait, + $class::$f, + $res_type, + $conv, + *mut $crate::ffi::PyObject + ); }; ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr, $return_type:ty) => {{ - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject, - arg1: *mut $crate::ffi::PyObject, - arg2: *mut $crate::ffi::PyObject) -> $return_type - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + slf: *mut $crate::ffi::PyObject, + arg1: *mut $crate::ffi::PyObject, + arg2: *mut $crate::ffi::PyObject, + ) -> $return_type + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; @@ -193,25 +222,28 @@ macro_rules! py_ternary_func{ let result = match arg1.extract() { Ok(arg1) => match arg2.extract() { Ok(arg2) => slf.$f(arg1, arg2).into(), - Err(e) => Err(e.into()) + Err(e) => Err(e.into()), }, Err(e) => Err(e.into()), }; $crate::callback::cb_convert($conv, py, result) } - Some(wrap::) - }} + Some(wrap::) + }}; } #[macro_export] #[doc(hidden)] -macro_rules! py_ternary_num_func{ +macro_rules! py_ternary_num_func { ($trait:ident, $class:ident :: $f:ident, $res_type:ty, $conv:expr) => {{ - unsafe extern "C" fn wrap(arg1: *mut $crate::ffi::PyObject, - arg2: *mut $crate::ffi::PyObject, - arg3: *mut $crate::ffi::PyObject) -> *mut $crate::ffi::PyObject - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + arg1: *mut $crate::ffi::PyObject, + arg2: *mut $crate::ffi::PyObject, + arg3: *mut $crate::ffi::PyObject, + ) -> *mut $crate::ffi::PyObject + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; @@ -225,28 +257,30 @@ macro_rules! py_ternary_num_func{ Ok(arg1) => match arg2.extract() { Ok(arg2) => match arg3.extract() { Ok(arg3) => $class::$f(arg1, arg2, arg3).into(), - Err(e) => Err(e.into()) + Err(e) => Err(e.into()), }, - Err(e) => Err(e.into()) + Err(e) => Err(e.into()), }, Err(e) => Err(e.into()), }; $crate::callback::cb_convert($conv, py, result) } - Some(wrap::) - }} + Some(wrap::) + }}; } #[macro_export] #[doc(hidden)] -macro_rules! py_ternary_self_func{ +macro_rules! py_ternary_self_func { ($trait:ident, $class:ident :: $f:ident) => {{ - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject, - arg1: *mut $crate::ffi::PyObject, - arg2: *mut $crate::ffi::PyObject) - -> *mut $crate::ffi::PyObject - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + slf: *mut $crate::ffi::PyObject, + arg1: *mut $crate::ffi::PyObject, + arg2: *mut $crate::ffi::PyObject, + ) -> *mut $crate::ffi::PyObject + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; @@ -259,7 +293,7 @@ macro_rules! py_ternary_self_func{ let result = match arg1.extract() { Ok(arg1) => match arg2.extract() { Ok(arg2) => slf1.$f(arg1, arg2).into(), - Err(e) => Err(e.into()) + Err(e) => Err(e.into()), }, Err(e) => Err(e.into()), }; @@ -273,18 +307,20 @@ macro_rules! py_ternary_self_func{ } } Some(wrap::) - }} + }}; } - #[macro_export] #[doc(hidden)] -macro_rules! py_func_set{ +macro_rules! py_func_set { ($trait:ident, $class:ident :: $f:ident) => {{ - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject, - name: *mut $crate::ffi::PyObject, - value: *mut $crate::ffi::PyObject) -> $crate::c_int - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + slf: *mut $crate::ffi::PyObject, + name: *mut $crate::ffi::PyObject, + value: *mut $crate::ffi::PyObject, + ) -> $crate::c_int + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; @@ -293,8 +329,10 @@ macro_rules! py_func_set{ let slf = py.mut_from_borrowed_ptr::(slf); if value.is_null() { - let e = $crate::PyErr::new::( - format!("Subscript deletion not supported by {:?}", stringify!(T))); + let e = $crate::PyErr::new::(format!( + "Subscript deletion not supported by {:?}", + stringify!(T) + )); e.restore(py); -1 } else { @@ -302,15 +340,13 @@ macro_rules! py_func_set{ let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value); let result = match name.extract() { Ok(name) => match value.extract() { - Ok(value) => - slf.$f(name, value).into(), + Ok(value) => slf.$f(name, value).into(), Err(e) => Err(e.into()), }, Err(e) => Err(e.into()), }; match result { - Ok(_) => - 0, + Ok(_) => 0, Err(e) => { e.restore(py); -1 @@ -319,20 +355,22 @@ macro_rules! py_func_set{ } } - Some(wrap::) - }} + Some(wrap::) + }}; } - #[macro_export] #[doc(hidden)] -macro_rules! py_func_del{ +macro_rules! py_func_del { ($trait:ident, $class:ident :: $f:ident) => {{ #[allow(unused_mut)] - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject, - name: *mut $crate::ffi::PyObject, - value: *mut $crate::ffi::PyObject) -> $crate::c_int - where T: for<'p> $trait<'p> + unsafe extern "C" fn wrap( + slf: *mut $crate::ffi::PyObject, + name: *mut $crate::ffi::PyObject, + value: *mut $crate::ffi::PyObject, + ) -> $crate::c_int + where + T: for<'p> $trait<'p>, { use $crate::ObjectProtocol; @@ -355,26 +393,30 @@ macro_rules! py_func_del{ } } } else { - let e = PyErr::new::( - format!("Subscript assignment not supported by {:?}", stringify!(T))); + let e = PyErr::new::(format!( + "Subscript assignment not supported by {:?}", + stringify!(T) + )); e.restore(py); -1 } } - Some(wrap::) - }} + Some(wrap::) + }}; } - #[macro_export] #[doc(hidden)] -macro_rules! py_func_set_del{ +macro_rules! py_func_set_del { ($trait:ident, $trait2:ident, $class:ident :: $f:ident/$f2:ident) => {{ - unsafe extern "C" fn wrap(slf: *mut $crate::ffi::PyObject, - name: *mut $crate::ffi::PyObject, - value: *mut $crate::ffi::PyObject) -> $crate::c_int - where T: for<'p> $trait<'p> + for<'p> $trait2<'p> + unsafe extern "C" fn wrap( + slf: *mut $crate::ffi::PyObject, + name: *mut $crate::ffi::PyObject, + value: *mut $crate::ffi::PyObject, + ) -> $crate::c_int + where + T: for<'p> $trait<'p> + for<'p> $trait2<'p>, { use $crate::ObjectProtocol; @@ -399,9 +441,7 @@ macro_rules! py_func_set_del{ let value = py.from_borrowed_ptr::<$crate::PyObjectRef>(value); let result = match name.extract() { Ok(name) => match value.extract() { - Ok(value) => { - slf.$f(name, value).into() - }, + Ok(value) => slf.$f(name, value).into(), Err(e) => Err(e.into()), }, Err(e) => Err(e.into()), @@ -416,5 +456,5 @@ macro_rules! py_func_set_del{ } } Some(wrap::) - }} + }}; } diff --git a/src/class/mapping.rs b/src/class/mapping.rs index a510b90fd4e..d94ced11335 100644 --- a/src/class/mapping.rs +++ b/src/class/mapping.rs @@ -3,44 +3,68 @@ //! Python Mapping Interface //! Trait and support implementation for implementing mapping support -use ffi; +use callback::{LenResultConverter, PyObjectCallbackConverter}; +use class::methods::PyMethodDef; +use conversion::{FromPyObject, IntoPyObject}; use err::{PyErr, PyResult}; -use python::Python; +use ffi; use objects::exc; -use callback::{PyObjectCallbackConverter, LenResultConverter}; -use conversion::{IntoPyObject, FromPyObject}; +use python::Python; use typeob::PyTypeInfo; -use class::methods::PyMethodDef; - /// Mapping interface #[allow(unused_variables)] pub trait PyMappingProtocol<'p>: PyTypeInfo { + fn __len__(&'p self) -> Self::Result + where + Self: PyMappingLenProtocol<'p>, + { + unimplemented!() + } - fn __len__(&'p self) - -> Self::Result where Self: PyMappingLenProtocol<'p> {unimplemented!()} - - fn __getitem__(&'p self, key: Self::Key) - -> Self::Result where Self: PyMappingGetItemProtocol<'p> {unimplemented!()} - - fn __setitem__(&'p mut self, key: Self::Key, value: Self::Value) - -> Self::Result where Self: PyMappingSetItemProtocol<'p> {unimplemented!()} + fn __getitem__(&'p self, key: Self::Key) -> Self::Result + where + Self: PyMappingGetItemProtocol<'p>, + { + unimplemented!() + } - fn __delitem__(&'p mut self, key: Self::Key) - -> Self::Result where Self: PyMappingDelItemProtocol<'p> {unimplemented!()} + fn __setitem__(&'p mut self, key: Self::Key, value: Self::Value) -> Self::Result + where + Self: PyMappingSetItemProtocol<'p>, + { + unimplemented!() + } - fn __iter__(&'p self, py: Python<'p>) - -> Self::Result where Self: PyMappingIterProtocol<'p> {unimplemented!()} + fn __delitem__(&'p mut self, key: Self::Key) -> Self::Result + where + Self: PyMappingDelItemProtocol<'p>, + { + unimplemented!() + } - fn __contains__(&'p self, value: Self::Value) - -> Self::Result where Self: PyMappingContainsProtocol<'p> {unimplemented!()} + fn __iter__(&'p self, py: Python<'p>) -> Self::Result + where + Self: PyMappingIterProtocol<'p>, + { + unimplemented!() + } - fn __reversed__(&'p self) - -> Self::Result where Self: PyMappingReversedProtocol<'p> {unimplemented!()} + fn __contains__(&'p self, value: Self::Value) -> Self::Result + where + Self: PyMappingContainsProtocol<'p>, + { + unimplemented!() + } + fn __reversed__(&'p self) -> Self::Result + where + Self: PyMappingReversedProtocol<'p>, + { + unimplemented!() + } } - // The following are a bunch of marker traits used to detect // the existance of a slotted method. @@ -97,7 +121,10 @@ impl PyMappingProtocolImpl for T { } } -impl<'p, T> PyMappingProtocolImpl for T where T: PyMappingProtocol<'p> { +impl<'p, T> PyMappingProtocolImpl for T +where + T: PyMappingProtocol<'p>, +{ #[inline] fn tp_as_mapping() -> Option { let f = if let Some(df) = Self::mp_del_subscript() { @@ -135,7 +162,9 @@ trait PyMappingLenProtocolImpl { fn mp_length() -> Option; } -impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingLenProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn mp_length() -> Option { @@ -143,7 +172,9 @@ impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p> } } -impl PyMappingLenProtocolImpl for T where T: for<'p> PyMappingLenProtocol<'p> +impl PyMappingLenProtocolImpl for T +where + T: for<'p> PyMappingLenProtocol<'p>, { #[inline] fn mp_length() -> Option { @@ -155,7 +186,9 @@ trait PyMappingGetItemProtocolImpl { fn mp_subscript() -> Option; } -impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingGetItemProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn mp_subscript() -> Option { @@ -163,12 +196,18 @@ impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p> } } -impl PyMappingGetItemProtocolImpl for T where T: for<'p> PyMappingGetItemProtocol<'p> +impl PyMappingGetItemProtocolImpl for T +where + T: for<'p> PyMappingGetItemProtocol<'p>, { #[inline] fn mp_subscript() -> Option { - py_binary_func!(PyMappingGetItemProtocol, - T::__getitem__, T::Success, PyObjectCallbackConverter) + py_binary_func!( + PyMappingGetItemProtocol, + T::__getitem__, + T::Success, + PyObjectCallbackConverter + ) } } @@ -176,7 +215,9 @@ trait PyMappingSetItemProtocolImpl { fn mp_ass_subscript() -> Option; } -impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingSetItemProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn mp_ass_subscript() -> Option { @@ -184,7 +225,9 @@ impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p> } } -impl PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProtocol<'p> +impl PyMappingSetItemProtocolImpl for T +where + T: for<'p> PyMappingSetItemProtocol<'p>, { #[inline] fn mp_ass_subscript() -> Option { @@ -192,12 +235,13 @@ impl PyMappingSetItemProtocolImpl for T where T: for<'p> PyMappingSetItemProt } } - trait PyMappingDelItemProtocolImpl { fn mp_del_subscript() -> Option; } -impl<'p, T> PyMappingDelItemProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingDelItemProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn mp_del_subscript() -> Option { @@ -205,7 +249,9 @@ impl<'p, T> PyMappingDelItemProtocolImpl for T where T: PyMappingProtocol<'p> } } -impl PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProtocol<'p> +impl PyMappingDelItemProtocolImpl for T +where + T: for<'p> PyMappingDelItemProtocol<'p>, { #[inline] default fn mp_del_subscript() -> Option { @@ -213,24 +259,28 @@ impl PyMappingDelItemProtocolImpl for T where T: for<'p> PyMappingDelItemProt } } - impl PyMappingDelItemProtocolImpl for T - where T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p> +where + T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p>, { #[inline] fn mp_del_subscript() -> Option { - py_func_set_del!(PyMappingSetItemProtocol, PyMappingDelItemProtocol, - T::__setitem__/__delitem__) + py_func_set_del!( + PyMappingSetItemProtocol, + PyMappingDelItemProtocol, + T::__setitem__ / __delitem__ + ) } } - #[doc(hidden)] pub trait PyMappingContainsProtocolImpl { fn __contains__() -> Option; } -impl<'p, T> PyMappingContainsProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingContainsProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn __contains__() -> Option { @@ -243,7 +293,9 @@ pub trait PyMappingReversedProtocolImpl { fn __reversed__() -> Option; } -impl<'p, T> PyMappingReversedProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingReversedProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn __reversed__() -> Option { @@ -256,7 +308,9 @@ pub trait PyMappingIterProtocolImpl { fn __iter__() -> Option; } -impl<'p, T> PyMappingIterProtocolImpl for T where T: PyMappingProtocol<'p> +impl<'p, T> PyMappingIterProtocolImpl for T +where + T: PyMappingProtocol<'p>, { #[inline] default fn __iter__() -> Option { diff --git a/src/class/methods.rs b/src/class/methods.rs index fefac7b7ee0..a263432094a 100644 --- a/src/class/methods.rs +++ b/src/class/methods.rs @@ -67,34 +67,29 @@ unsafe impl Sync for PyGetterDef {} unsafe impl Sync for PySetterDef {} unsafe impl Sync for ffi::PyGetSetDef {} - impl PyMethodDef { - /// Convert `PyMethodDef` to Python method definition struct `ffi::PyMethodDef` pub fn as_method_def(&self) -> ffi::PyMethodDef { let meth = match self.ml_meth { PyMethodType::PyCFunction(meth) => meth, - PyMethodType::PyCFunctionWithKeywords(meth) => - unsafe { - std::mem::transmute::(meth) - }, - PyMethodType::PyNoArgsFunction(meth) => - unsafe { - std::mem::transmute::(meth) - }, - PyMethodType::PyNewFunc(meth) => - unsafe { - std::mem::transmute::(meth) - }, - PyMethodType::PyInitFunc(meth) => - unsafe { - std::mem::transmute::(meth) - }, + PyMethodType::PyCFunctionWithKeywords(meth) => unsafe { + std::mem::transmute::(meth) + }, + PyMethodType::PyNoArgsFunction(meth) => unsafe { + std::mem::transmute::(meth) + }, + PyMethodType::PyNewFunc(meth) => unsafe { + std::mem::transmute::(meth) + }, + PyMethodType::PyInitFunc(meth) => unsafe { + std::mem::transmute::(meth) + }, }; ffi::PyMethodDef { - ml_name: CString::new(self.ml_name).expect( - "Method name must not contain NULL byte").into_raw(), + ml_name: CString::new(self.ml_name) + .expect("Method name must not contain NULL byte") + .into_raw(), ml_meth: Some(meth), ml_flags: self.ml_flags, ml_doc: self.ml_doc.as_ptr() as *const _, @@ -106,8 +101,9 @@ impl PyGetterDef { /// Copy descriptor information to `ffi::PyGetSetDef` pub fn copy_to(&self, dst: &mut ffi::PyGetSetDef) { if dst.name.is_null() { - dst.name = CString::new(self.name).expect( - "Method name must not contain NULL byte").into_raw(); + dst.name = CString::new(self.name) + .expect("Method name must not contain NULL byte") + .into_raw(); } dst.get = Some(self.meth); } @@ -117,8 +113,9 @@ impl PySetterDef { /// Copy descriptor information to `ffi::PyGetSetDef` pub fn copy_to(&self, dst: &mut ffi::PyGetSetDef) { if dst.name.is_null() { - dst.name = CString::new(self.name).expect( - "Method name must not contain NULL byte").into_raw(); + dst.name = CString::new(self.name) + .expect("Method name must not contain NULL byte") + .into_raw(); } dst.set = Some(self.meth); } diff --git a/src/class/mod.rs b/src/class/mod.rs index 538dc1a40b6..aba3976ebda 100644 --- a/src/class/mod.rs +++ b/src/class/mod.rs @@ -2,33 +2,33 @@ //! Python object protocols -#[macro_use] mod macros; +#[macro_use] +mod macros; pub mod async; pub mod basic; pub mod buffer; pub mod context; pub mod descr; +pub mod gc; +pub mod iter; pub mod mapping; pub mod methods; pub mod number; -pub mod iter; -pub mod gc; pub mod sequence; -pub use self::basic::PyObjectProtocol; pub use self::async::PyAsyncProtocol; -pub use self::iter::PyIterProtocol; +pub use self::basic::PyObjectProtocol; pub use self::buffer::PyBufferProtocol; pub use self::context::PyContextProtocol; pub use self::descr::PyDescrProtocol; -pub use self::number::PyNumberProtocol; +pub use self::iter::PyIterProtocol; pub use self::mapping::PyMappingProtocol; +pub use self::number::PyNumberProtocol; pub use self::sequence::PySequenceProtocol; -pub use self::gc::{PyVisit, PyGCProtocol, PyTraverseError}; -pub use self::methods::{PyMethodDef, PyMethodDefType, PyMethodType, - PyGetterDef, PySetterDef}; +pub use self::gc::{PyGCProtocol, PyTraverseError, PyVisit}; +pub use self::methods::{PyGetterDef, PyMethodDef, PyMethodDefType, PyMethodType, PySetterDef}; use ffi; @@ -39,5 +39,5 @@ pub enum CompareOp { Eq = ffi::Py_EQ as isize, Ne = ffi::Py_NE as isize, Gt = ffi::Py_GT as isize, - Ge = ffi::Py_GE as isize + Ge = ffi::Py_GE as isize, } diff --git a/src/class/number.rs b/src/class/number.rs index d12002c14da..68df15c6814 100644 --- a/src/class/number.rs +++ b/src/class/number.rs @@ -3,125 +3,323 @@ //! Python Number Interface //! Trait and support implementation for implementing number protocol -use ffi; -use err::PyResult; use callback::PyObjectCallbackConverter; -use typeob::PyTypeInfo; -use class::methods::PyMethodDef; use class::basic::PyObjectProtocolImpl; -use {IntoPyObject, FromPyObject}; +use class::methods::PyMethodDef; +use err::PyResult; +use ffi; +use typeob::PyTypeInfo; +use {FromPyObject, IntoPyObject}; /// Number interface #[allow(unused_variables)] pub trait PyNumberProtocol<'p>: PyTypeInfo { + fn __add__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberAddProtocol<'p>, + { + unimplemented!() + } + fn __sub__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberSubProtocol<'p>, + { + unimplemented!() + } + fn __mul__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberMulProtocol<'p>, + { + unimplemented!() + } + fn __matmul__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberMatmulProtocol<'p>, + { + unimplemented!() + } + fn __truediv__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberTruedivProtocol<'p>, + { + unimplemented!() + } + fn __floordiv__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberFloordivProtocol<'p>, + { + unimplemented!() + } + fn __mod__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberModProtocol<'p>, + { + unimplemented!() + } + fn __divmod__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberDivmodProtocol<'p>, + { + unimplemented!() + } + fn __pow__(lhs: Self::Left, rhs: Self::Right, modulo: Self::Modulo) -> Self::Result + where + Self: PyNumberPowProtocol<'p>, + { + unimplemented!() + } + fn __lshift__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberLShiftProtocol<'p>, + { + unimplemented!() + } + fn __rshift__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberRShiftProtocol<'p>, + { + unimplemented!() + } + fn __and__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberAndProtocol<'p>, + { + unimplemented!() + } + fn __xor__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberXorProtocol<'p>, + { + unimplemented!() + } + fn __or__(lhs: Self::Left, rhs: Self::Right) -> Self::Result + where + Self: PyNumberOrProtocol<'p>, + { + unimplemented!() + } - fn __add__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberAddProtocol<'p> { unimplemented!() } - fn __sub__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberSubProtocol<'p> { unimplemented!() } - fn __mul__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberMulProtocol<'p> { unimplemented!() } - fn __matmul__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberMatmulProtocol<'p> { unimplemented!() } - fn __truediv__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberTruedivProtocol<'p> { unimplemented!() } - fn __floordiv__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberFloordivProtocol<'p> { unimplemented!() } - fn __mod__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberModProtocol<'p> { unimplemented!() } - fn __divmod__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberDivmodProtocol<'p> { unimplemented!() } - fn __pow__(lhs: Self::Left, rhs: Self::Right, modulo: Self::Modulo) - -> Self::Result where Self: PyNumberPowProtocol<'p> { unimplemented!() } - fn __lshift__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberLShiftProtocol<'p> { unimplemented!() } - fn __rshift__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberRShiftProtocol<'p> { unimplemented!() } - fn __and__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberAndProtocol<'p> { unimplemented!() } - fn __xor__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberXorProtocol<'p> { unimplemented!() } - fn __or__(lhs: Self::Left, rhs: Self::Right) - -> Self::Result where Self: PyNumberOrProtocol<'p> { unimplemented!() } - - fn __radd__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRAddProtocol<'p> { unimplemented!() } - fn __rsub__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRSubProtocol<'p> { unimplemented!() } - fn __rmul__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRMulProtocol<'p> { unimplemented!() } - fn __rmatmul__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRMatmulProtocol<'p> { unimplemented!() } - fn __rtruediv__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRTruedivProtocol<'p> { unimplemented!() } - fn __rfloordiv__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRFloordivProtocol<'p> { unimplemented!() } - fn __rmod__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRModProtocol<'p> { unimplemented!() } - fn __rdivmod__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRDivmodProtocol<'p> { unimplemented!() } - fn __rpow__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRPowProtocol<'p> { unimplemented!() } - fn __rlshift__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRLShiftProtocol<'p> { unimplemented!() } - fn __rrshift__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRRShiftProtocol<'p> { unimplemented!() } - fn __rand__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRAndProtocol<'p> { unimplemented!() } - fn __rxor__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberRXorProtocol<'p> { unimplemented!() } - fn __ror__(&'p self, other: Self::Other) - -> Self::Result where Self: PyNumberROrProtocol<'p> { unimplemented!() } - - fn __iadd__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIAddProtocol<'p> { unimplemented!() } - fn __isub__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberISubProtocol<'p> { unimplemented!() } - fn __imul__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIMulProtocol<'p> { unimplemented!() } - fn __imatmul__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIMatmulProtocol<'p> { unimplemented!() } - fn __itruediv__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberITruedivProtocol<'p> {unimplemented!()} - fn __ifloordiv__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIFloordivProtocol<'p> {unimplemented!() } - fn __imod__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIModProtocol<'p> { unimplemented!() } - fn __ipow__(&'p mut self, other: Self::Other, modulo: Self::Modulo) - -> Self::Result where Self: PyNumberIPowProtocol<'p> { unimplemented!() } - fn __ilshift__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberILShiftProtocol<'p> { unimplemented!() } - fn __irshift__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIRShiftProtocol<'p> { unimplemented!() } - fn __iand__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIAndProtocol<'p> { unimplemented!() } - fn __ixor__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIXorProtocol<'p> { unimplemented!() } - fn __ior__(&'p mut self, other: Self::Other) - -> Self::Result where Self: PyNumberIOrProtocol<'p> { unimplemented!() } + fn __radd__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRAddProtocol<'p>, + { + unimplemented!() + } + fn __rsub__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRSubProtocol<'p>, + { + unimplemented!() + } + fn __rmul__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRMulProtocol<'p>, + { + unimplemented!() + } + fn __rmatmul__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRMatmulProtocol<'p>, + { + unimplemented!() + } + fn __rtruediv__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRTruedivProtocol<'p>, + { + unimplemented!() + } + fn __rfloordiv__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRFloordivProtocol<'p>, + { + unimplemented!() + } + fn __rmod__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRModProtocol<'p>, + { + unimplemented!() + } + fn __rdivmod__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRDivmodProtocol<'p>, + { + unimplemented!() + } + fn __rpow__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRPowProtocol<'p>, + { + unimplemented!() + } + fn __rlshift__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRLShiftProtocol<'p>, + { + unimplemented!() + } + fn __rrshift__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRRShiftProtocol<'p>, + { + unimplemented!() + } + fn __rand__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRAndProtocol<'p>, + { + unimplemented!() + } + fn __rxor__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberRXorProtocol<'p>, + { + unimplemented!() + } + fn __ror__(&'p self, other: Self::Other) -> Self::Result + where + Self: PyNumberROrProtocol<'p>, + { + unimplemented!() + } + + fn __iadd__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIAddProtocol<'p>, + { + unimplemented!() + } + fn __isub__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberISubProtocol<'p>, + { + unimplemented!() + } + fn __imul__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIMulProtocol<'p>, + { + unimplemented!() + } + fn __imatmul__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIMatmulProtocol<'p>, + { + unimplemented!() + } + fn __itruediv__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberITruedivProtocol<'p>, + { + unimplemented!() + } + fn __ifloordiv__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIFloordivProtocol<'p>, + { + unimplemented!() + } + fn __imod__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIModProtocol<'p>, + { + unimplemented!() + } + fn __ipow__(&'p mut self, other: Self::Other, modulo: Self::Modulo) -> Self::Result + where + Self: PyNumberIPowProtocol<'p>, + { + unimplemented!() + } + fn __ilshift__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberILShiftProtocol<'p>, + { + unimplemented!() + } + fn __irshift__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIRShiftProtocol<'p>, + { + unimplemented!() + } + fn __iand__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIAndProtocol<'p>, + { + unimplemented!() + } + fn __ixor__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIXorProtocol<'p>, + { + unimplemented!() + } + fn __ior__(&'p mut self, other: Self::Other) -> Self::Result + where + Self: PyNumberIOrProtocol<'p>, + { + unimplemented!() + } // Unary arithmetic - fn __neg__(&'p self) - -> Self::Result where Self: PyNumberNegProtocol<'p> { unimplemented!() } - fn __pos__(&'p self) - -> Self::Result where Self: PyNumberPosProtocol<'p> { unimplemented!() } - fn __abs__(&'p self) - -> Self::Result where Self: PyNumberAbsProtocol<'p> { unimplemented!() } - fn __invert__(&'p self) - -> Self::Result where Self: PyNumberInvertProtocol<'p> { unimplemented!() } - fn __complex__(&'p self) - -> Self::Result where Self: PyNumberComplexProtocol<'p> { unimplemented!() } - fn __int__(&'p self) - -> Self::Result where Self: PyNumberIntProtocol<'p> { unimplemented!() } - fn __float__(&'p self) - -> Self::Result where Self: PyNumberFloatProtocol<'p> { unimplemented!() } - fn __round__(&'p self) - -> Self::Result where Self: PyNumberRoundProtocol<'p> { unimplemented!() } - fn __index__(&'p self) - -> Self::Result where Self: PyNumberIndexProtocol<'p> { unimplemented!() } + fn __neg__(&'p self) -> Self::Result + where + Self: PyNumberNegProtocol<'p>, + { + unimplemented!() + } + fn __pos__(&'p self) -> Self::Result + where + Self: PyNumberPosProtocol<'p>, + { + unimplemented!() + } + fn __abs__(&'p self) -> Self::Result + where + Self: PyNumberAbsProtocol<'p>, + { + unimplemented!() + } + fn __invert__(&'p self) -> Self::Result + where + Self: PyNumberInvertProtocol<'p>, + { + unimplemented!() + } + fn __complex__(&'p self) -> Self::Result + where + Self: PyNumberComplexProtocol<'p>, + { + unimplemented!() + } + fn __int__(&'p self) -> Self::Result + where + Self: PyNumberIntProtocol<'p>, + { + unimplemented!() + } + fn __float__(&'p self) -> Self::Result + where + Self: PyNumberFloatProtocol<'p>, + { + unimplemented!() + } + fn __round__(&'p self) -> Self::Result + where + Self: PyNumberRoundProtocol<'p>, + { + unimplemented!() + } + fn __index__(&'p self) -> Self::Result + where + Self: PyNumberIndexProtocol<'p>, + { + unimplemented!() + } } - pub trait PyNumberAddProtocol<'p>: PyNumberProtocol<'p> { type Left: FromPyObject<'p>; type Right: FromPyObject<'p>; @@ -208,7 +406,6 @@ pub trait PyNumberOrProtocol<'p>: PyNumberProtocol<'p> { type Result: Into>; } - pub trait PyNumberRAddProtocol<'p>: PyNumberProtocol<'p> { type Other: FromPyObject<'p>; type Success: IntoPyObject; @@ -376,8 +573,6 @@ pub trait PyNumberIndexProtocol<'p>: PyNumberProtocol<'p> { type Result: Into>; } - - #[doc(hidden)] pub trait PyNumberProtocolImpl { fn methods() -> Vec; @@ -390,8 +585,7 @@ impl<'p, T> PyNumberProtocolImpl for T { if let Some(nb_bool) = ::nb_bool_fn() { let meth = ffi::PyNumberMethods { nb_bool: Some(nb_bool), - .. - ffi::PyNumberMethods_INIT + ..ffi::PyNumberMethods_INIT }; Some(meth) } else { @@ -403,8 +597,7 @@ impl<'p, T> PyNumberProtocolImpl for T { if let Some(nb_bool) = ::nb_bool_fn() { let meth = ffi::PyNumberMethods { nb_nonzero: Some(nb_bool), - .. - ffi::PyNumberMethods_INIT + ..ffi::PyNumberMethods_INIT }; Some(meth) } else { @@ -416,7 +609,10 @@ impl<'p, T> PyNumberProtocolImpl for T { } } -impl<'p, T> PyNumberProtocolImpl for T where T: PyNumberProtocol<'p> { +impl<'p, T> PyNumberProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ #[cfg(Py_3)] fn tp_as_number() -> Option { Some(ffi::PyNumberMethods { @@ -563,199 +759,368 @@ impl<'p, T> PyNumberProtocolImpl for T where T: PyNumberProtocol<'p> { trait PyNumberAddProtocolImpl { fn nb_add() -> Option; } -impl<'p, T> PyNumberAddProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_add() -> Option {None} +impl<'p, T> PyNumberAddProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_add() -> Option { + None + } } -impl PyNumberAddProtocolImpl for T where T: for<'p> PyNumberAddProtocol<'p> { +impl PyNumberAddProtocolImpl for T +where + T: for<'p> PyNumberAddProtocol<'p>, +{ fn nb_add() -> Option { py_binary_num_func!( - PyNumberAddProtocol, T::__add__, T::Success, PyObjectCallbackConverter) + PyNumberAddProtocol, + T::__add__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberSubProtocolImpl { fn nb_subtract() -> Option; } -impl<'p, T> PyNumberSubProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_subtract() -> Option {None} +impl<'p, T> PyNumberSubProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_subtract() -> Option { + None + } } -impl PyNumberSubProtocolImpl for T where T: for<'p> PyNumberSubProtocol<'p> { +impl PyNumberSubProtocolImpl for T +where + T: for<'p> PyNumberSubProtocol<'p>, +{ fn nb_subtract() -> Option { py_binary_num_func!( - PyNumberSubProtocol, T::__sub__, T::Success, PyObjectCallbackConverter) + PyNumberSubProtocol, + T::__sub__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberMulProtocolImpl { fn nb_multiply() -> Option; } -impl<'p, T> PyNumberMulProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_multiply() -> Option {None} +impl<'p, T> PyNumberMulProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_multiply() -> Option { + None + } } -impl PyNumberMulProtocolImpl for T where T: for<'p> PyNumberMulProtocol<'p> { +impl PyNumberMulProtocolImpl for T +where + T: for<'p> PyNumberMulProtocol<'p>, +{ fn nb_multiply() -> Option { py_binary_num_func!( - PyNumberMulProtocol, T::__mul__, T::Success, PyObjectCallbackConverter) + PyNumberMulProtocol, + T::__mul__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberMatmulProtocolImpl { fn nb_matrix_multiply() -> Option; } -impl<'p, T> PyNumberMatmulProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_matrix_multiply() -> Option {None} +impl<'p, T> PyNumberMatmulProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_matrix_multiply() -> Option { + None + } } -impl PyNumberMatmulProtocolImpl for T where T: for<'p> PyNumberMatmulProtocol<'p> { +impl PyNumberMatmulProtocolImpl for T +where + T: for<'p> PyNumberMatmulProtocol<'p>, +{ fn nb_matrix_multiply() -> Option { py_binary_num_func!( - PyNumberMatmulProtocol, T::__matmul__, T::Success, PyObjectCallbackConverter) + PyNumberMatmulProtocol, + T::__matmul__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberTruedivProtocolImpl { fn nb_true_divide() -> Option; } -impl<'p, T> PyNumberTruedivProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_true_divide() -> Option {None} +impl<'p, T> PyNumberTruedivProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_true_divide() -> Option { + None + } } impl PyNumberTruedivProtocolImpl for T - where T: for<'p> PyNumberTruedivProtocol<'p> +where + T: for<'p> PyNumberTruedivProtocol<'p>, { fn nb_true_divide() -> Option { py_binary_num_func!( - PyNumberTruedivProtocol, T::__truediv__, T::Success, PyObjectCallbackConverter) + PyNumberTruedivProtocol, + T::__truediv__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberFloordivProtocolImpl { fn nb_floor_divide() -> Option; } -impl<'p, T> PyNumberFloordivProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_floor_divide() -> Option {None} +impl<'p, T> PyNumberFloordivProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_floor_divide() -> Option { + None + } } impl PyNumberFloordivProtocolImpl for T - where T: for<'p> PyNumberFloordivProtocol<'p> +where + T: for<'p> PyNumberFloordivProtocol<'p>, { fn nb_floor_divide() -> Option { py_binary_num_func!( - PyNumberFloordivProtocol, T::__floordiv__, T::Success, PyObjectCallbackConverter) + PyNumberFloordivProtocol, + T::__floordiv__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberModProtocolImpl { fn nb_remainder() -> Option; } -impl<'p, T> PyNumberModProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_remainder() -> Option {None} +impl<'p, T> PyNumberModProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_remainder() -> Option { + None + } } -impl PyNumberModProtocolImpl for T where T: for<'p> PyNumberModProtocol<'p> { +impl PyNumberModProtocolImpl for T +where + T: for<'p> PyNumberModProtocol<'p>, +{ fn nb_remainder() -> Option { py_binary_num_func!( - PyNumberModProtocol, T::__mod__, T::Success, PyObjectCallbackConverter) + PyNumberModProtocol, + T::__mod__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberDivmodProtocolImpl { fn nb_divmod() -> Option; } -impl<'p, T> PyNumberDivmodProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_divmod() -> Option {None} +impl<'p, T> PyNumberDivmodProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_divmod() -> Option { + None + } } -impl PyNumberDivmodProtocolImpl for T where T: for<'p> PyNumberDivmodProtocol<'p> { +impl PyNumberDivmodProtocolImpl for T +where + T: for<'p> PyNumberDivmodProtocol<'p>, +{ fn nb_divmod() -> Option { py_binary_num_func!( - PyNumberDivmodProtocol, T::__divmod__, T::Success, PyObjectCallbackConverter) + PyNumberDivmodProtocol, + T::__divmod__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberPowProtocolImpl { fn nb_power() -> Option; } -impl<'p, T> PyNumberPowProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_power() -> Option {None} +impl<'p, T> PyNumberPowProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_power() -> Option { + None + } } -impl PyNumberPowProtocolImpl for T where T: for<'p> PyNumberPowProtocol<'p> { +impl PyNumberPowProtocolImpl for T +where + T: for<'p> PyNumberPowProtocol<'p>, +{ fn nb_power() -> Option { py_ternary_num_func!( PyNumberPowProtocol, - T::__pow__, ::Success, PyObjectCallbackConverter) + T::__pow__, + ::Success, + PyObjectCallbackConverter + ) } } trait PyNumberLShiftProtocolImpl { fn nb_lshift() -> Option; } -impl<'p, T> PyNumberLShiftProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_lshift() -> Option {None} +impl<'p, T> PyNumberLShiftProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_lshift() -> Option { + None + } } -impl PyNumberLShiftProtocolImpl for T where T: for<'p> PyNumberLShiftProtocol<'p> { +impl PyNumberLShiftProtocolImpl for T +where + T: for<'p> PyNumberLShiftProtocol<'p>, +{ fn nb_lshift() -> Option { py_binary_num_func!( - PyNumberLShiftProtocol, T::__lshift__, T::Success, PyObjectCallbackConverter) + PyNumberLShiftProtocol, + T::__lshift__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberRShiftProtocolImpl { fn nb_rshift() -> Option; } -impl<'p, T> PyNumberRShiftProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_rshift() -> Option {None} +impl<'p, T> PyNumberRShiftProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_rshift() -> Option { + None + } } -impl PyNumberRShiftProtocolImpl for T where T: for<'p> PyNumberRShiftProtocol<'p> { +impl PyNumberRShiftProtocolImpl for T +where + T: for<'p> PyNumberRShiftProtocol<'p>, +{ fn nb_rshift() -> Option { py_binary_num_func!( - PyNumberRShiftProtocol, T::__rshift__, T::Success, PyObjectCallbackConverter) + PyNumberRShiftProtocol, + T::__rshift__, + T::Success, + PyObjectCallbackConverter + ) } } - trait PyNumberAndProtocolImpl { fn nb_and() -> Option; } -impl<'p, T> PyNumberAndProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_and() -> Option {None} +impl<'p, T> PyNumberAndProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_and() -> Option { + None + } } -impl PyNumberAndProtocolImpl for T where T: for<'p> PyNumberAndProtocol<'p> { +impl PyNumberAndProtocolImpl for T +where + T: for<'p> PyNumberAndProtocol<'p>, +{ fn nb_and() -> Option { py_binary_num_func!( - PyNumberAndProtocol, T::__and__, T::Success, PyObjectCallbackConverter) + PyNumberAndProtocol, + T::__and__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberXorProtocolImpl { fn nb_xor() -> Option; } -impl<'p, T> PyNumberXorProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_xor() -> Option {None} +impl<'p, T> PyNumberXorProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_xor() -> Option { + None + } } -impl PyNumberXorProtocolImpl for T where T: for<'p> PyNumberXorProtocol<'p> { +impl PyNumberXorProtocolImpl for T +where + T: for<'p> PyNumberXorProtocol<'p>, +{ fn nb_xor() -> Option { py_binary_num_func!( - PyNumberXorProtocol, T::__xor__, T::Success, PyObjectCallbackConverter) + PyNumberXorProtocol, + T::__xor__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberOrProtocolImpl { fn nb_or() -> Option; } -impl<'p, T> PyNumberOrProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_or() -> Option {None} +impl<'p, T> PyNumberOrProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_or() -> Option { + None + } } -impl PyNumberOrProtocolImpl for T where T: for<'p> PyNumberOrProtocol<'p> { +impl PyNumberOrProtocolImpl for T +where + T: for<'p> PyNumberOrProtocol<'p>, +{ fn nb_or() -> Option { py_binary_num_func!( - PyNumberOrProtocol, T::__or__, T::Success, PyObjectCallbackConverter) + PyNumberOrProtocol, + T::__or__, + T::Success, + PyObjectCallbackConverter + ) } } - trait PyNumberIAddProtocolImpl { fn nb_inplace_add() -> Option; } -impl<'p, T> PyNumberIAddProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_add() -> Option {None} +impl<'p, T> PyNumberIAddProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_add() -> Option { + None + } } -impl PyNumberIAddProtocolImpl for T where T: for<'p> PyNumberIAddProtocol<'p> { +impl PyNumberIAddProtocolImpl for T +where + T: for<'p> PyNumberIAddProtocol<'p>, +{ fn nb_inplace_add() -> Option { py_binary_self_func!(PyNumberIAddProtocol, T::__iadd__) } @@ -764,10 +1129,18 @@ impl PyNumberIAddProtocolImpl for T where T: for<'p> PyNumberIAddProtocol<'p> trait PyNumberISubProtocolImpl { fn nb_inplace_subtract() -> Option; } -impl<'p, T> PyNumberISubProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_subtract() -> Option {None} +impl<'p, T> PyNumberISubProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_subtract() -> Option { + None + } } -impl PyNumberISubProtocolImpl for T where T: for<'p> PyNumberISubProtocol<'p> { +impl PyNumberISubProtocolImpl for T +where + T: for<'p> PyNumberISubProtocol<'p>, +{ fn nb_inplace_subtract() -> Option { py_binary_self_func!(PyNumberISubProtocol, T::__isub__) } @@ -776,10 +1149,18 @@ impl PyNumberISubProtocolImpl for T where T: for<'p> PyNumberISubProtocol<'p> trait PyNumberIMulProtocolImpl { fn nb_inplace_multiply() -> Option; } -impl<'p, T> PyNumberIMulProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_multiply() -> Option {None} +impl<'p, T> PyNumberIMulProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_multiply() -> Option { + None + } } -impl PyNumberIMulProtocolImpl for T where T: for<'p> PyNumberIMulProtocol<'p> { +impl PyNumberIMulProtocolImpl for T +where + T: for<'p> PyNumberIMulProtocol<'p>, +{ fn nb_inplace_multiply() -> Option { py_binary_self_func!(PyNumberIMulProtocol, T::__imul__) } @@ -788,11 +1169,17 @@ impl PyNumberIMulProtocolImpl for T where T: for<'p> PyNumberIMulProtocol<'p> trait PyNumberIMatmulProtocolImpl { fn nb_inplace_matrix_multiply() -> Option; } -impl<'p, T> PyNumberIMatmulProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_matrix_multiply() -> Option {None} +impl<'p, T> PyNumberIMatmulProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_matrix_multiply() -> Option { + None + } } impl PyNumberIMatmulProtocolImpl for T - where T: for<'p> PyNumberIMatmulProtocol<'p> +where + T: for<'p> PyNumberIMatmulProtocol<'p>, { fn nb_inplace_matrix_multiply() -> Option { py_binary_self_func!(PyNumberIMatmulProtocol, T::__imatmul__) @@ -802,11 +1189,17 @@ impl PyNumberIMatmulProtocolImpl for T trait PyNumberITruedivProtocolImpl { fn nb_inplace_true_divide() -> Option; } -impl<'p, T> PyNumberITruedivProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_true_divide() -> Option {None} +impl<'p, T> PyNumberITruedivProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_true_divide() -> Option { + None + } } impl PyNumberITruedivProtocolImpl for T - where T: for<'p> PyNumberITruedivProtocol<'p> +where + T: for<'p> PyNumberITruedivProtocol<'p>, { fn nb_inplace_true_divide() -> Option { py_binary_self_func!(PyNumberITruedivProtocol, T::__itruediv__) @@ -816,11 +1209,17 @@ impl PyNumberITruedivProtocolImpl for T trait PyNumberIFloordivProtocolImpl { fn nb_inplace_floor_divide() -> Option; } -impl<'p, T> PyNumberIFloordivProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_floor_divide() -> Option {None} +impl<'p, T> PyNumberIFloordivProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_floor_divide() -> Option { + None + } } impl PyNumberIFloordivProtocolImpl for T - where T: for<'p> PyNumberIFloordivProtocol<'p> +where + T: for<'p> PyNumberIFloordivProtocol<'p>, { fn nb_inplace_floor_divide() -> Option { py_binary_self_func!(PyNumberIFloordivProtocol, T::__ifloordiv__) @@ -830,10 +1229,18 @@ impl PyNumberIFloordivProtocolImpl for T trait PyNumberIModProtocolImpl { fn nb_inplace_remainder() -> Option; } -impl<'p, T> PyNumberIModProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_remainder() -> Option {None} +impl<'p, T> PyNumberIModProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_remainder() -> Option { + None + } } -impl PyNumberIModProtocolImpl for T where T: for<'p> PyNumberIModProtocol<'p> { +impl PyNumberIModProtocolImpl for T +where + T: for<'p> PyNumberIModProtocol<'p>, +{ fn nb_inplace_remainder() -> Option { py_binary_self_func!(PyNumberIModProtocol, T::__imod__) } @@ -842,10 +1249,18 @@ impl PyNumberIModProtocolImpl for T where T: for<'p> PyNumberIModProtocol<'p> trait PyNumberIPowProtocolImpl { fn nb_inplace_power() -> Option; } -impl<'p, T> PyNumberIPowProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_power() -> Option {None} +impl<'p, T> PyNumberIPowProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_power() -> Option { + None + } } -impl PyNumberIPowProtocolImpl for T where T: for<'p> PyNumberIPowProtocol<'p> { +impl PyNumberIPowProtocolImpl for T +where + T: for<'p> PyNumberIPowProtocol<'p>, +{ fn nb_inplace_power() -> Option { py_ternary_self_func!(PyNumberIPowProtocol, T::__ipow__) } @@ -854,11 +1269,17 @@ impl PyNumberIPowProtocolImpl for T where T: for<'p> PyNumberIPowProtocol<'p> trait PyNumberILShiftProtocolImpl { fn nb_inplace_lshift() -> Option; } -impl<'p, T> PyNumberILShiftProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_lshift() -> Option {None} +impl<'p, T> PyNumberILShiftProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_lshift() -> Option { + None + } } impl PyNumberILShiftProtocolImpl for T - where T: for<'p> PyNumberILShiftProtocol<'p> +where + T: for<'p> PyNumberILShiftProtocol<'p>, { fn nb_inplace_lshift() -> Option { py_binary_self_func!(PyNumberILShiftProtocol, T::__ilshift__) @@ -868,25 +1289,38 @@ impl PyNumberILShiftProtocolImpl for T trait PyNumberIRShiftProtocolImpl { fn nb_inplace_rshift() -> Option; } -impl<'p, T> PyNumberIRShiftProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_rshift() -> Option {None} +impl<'p, T> PyNumberIRShiftProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_rshift() -> Option { + None + } } impl PyNumberIRShiftProtocolImpl for T - where T: for<'p> PyNumberIRShiftProtocol<'p> +where + T: for<'p> PyNumberIRShiftProtocol<'p>, { fn nb_inplace_rshift() -> Option { py_binary_self_func!(PyNumberIRShiftProtocol, T::__irshift__) } } - trait PyNumberIAndProtocolImpl { fn nb_inplace_and() -> Option; } -impl<'p, T> PyNumberIAndProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_and() -> Option {None} +impl<'p, T> PyNumberIAndProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_and() -> Option { + None + } } -impl PyNumberIAndProtocolImpl for T where T: for<'p> PyNumberIAndProtocol<'p> { +impl PyNumberIAndProtocolImpl for T +where + T: for<'p> PyNumberIAndProtocol<'p>, +{ fn nb_inplace_and() -> Option { py_binary_self_func!(PyNumberIAndProtocol, T::__iand__) } @@ -895,10 +1329,18 @@ impl PyNumberIAndProtocolImpl for T where T: for<'p> PyNumberIAndProtocol<'p> trait PyNumberIXorProtocolImpl { fn nb_inplace_xor() -> Option; } -impl<'p, T> PyNumberIXorProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_xor() -> Option {None} +impl<'p, T> PyNumberIXorProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_xor() -> Option { + None + } } -impl PyNumberIXorProtocolImpl for T where T: for<'p> PyNumberIXorProtocol<'p> { +impl PyNumberIXorProtocolImpl for T +where + T: for<'p> PyNumberIXorProtocol<'p>, +{ fn nb_inplace_xor() -> Option { py_binary_self_func!(PyNumberIXorProtocol, T::__ixor__) } @@ -907,222 +1349,387 @@ impl PyNumberIXorProtocolImpl for T where T: for<'p> PyNumberIXorProtocol<'p> trait PyNumberIOrProtocolImpl { fn nb_inplace_or() -> Option; } -impl<'p, T> PyNumberIOrProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_inplace_or() -> Option {None} +impl<'p, T> PyNumberIOrProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_inplace_or() -> Option { + None + } } -impl PyNumberIOrProtocolImpl for T where T: for<'p> PyNumberIOrProtocol<'p> { +impl PyNumberIOrProtocolImpl for T +where + T: for<'p> PyNumberIOrProtocol<'p>, +{ fn nb_inplace_or() -> Option { py_binary_self_func!(PyNumberIOrProtocol, T::__ior__) } } - trait PyNumberRAddProtocolImpl { fn __radd__() -> Option; } -impl<'p, T> PyNumberRAddProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __radd__() -> Option {None} +impl<'p, T> PyNumberRAddProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __radd__() -> Option { + None + } } trait PyNumberRSubProtocolImpl { fn __rsub__() -> Option; } -impl<'p, T> PyNumberRSubProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rsub__() -> Option {None} +impl<'p, T> PyNumberRSubProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rsub__() -> Option { + None + } } trait PyNumberRMulProtocolImpl { fn __rmul__() -> Option; } -impl<'p, T> PyNumberRMulProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rmul__() -> Option {None} +impl<'p, T> PyNumberRMulProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rmul__() -> Option { + None + } } trait PyNumberRMatmulProtocolImpl { fn __rmatmul__() -> Option; } -impl<'p, T> PyNumberRMatmulProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rmatmul__() -> Option {None} +impl<'p, T> PyNumberRMatmulProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rmatmul__() -> Option { + None + } } trait PyNumberRTruedivProtocolImpl { fn __rtruediv__() -> Option; } -impl<'p, T> PyNumberRTruedivProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rtruediv__() -> Option {None} +impl<'p, T> PyNumberRTruedivProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rtruediv__() -> Option { + None + } } trait PyNumberRFloordivProtocolImpl { fn __rfloordiv__() -> Option; } -impl<'p, T> PyNumberRFloordivProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rfloordiv__() -> Option {None} +impl<'p, T> PyNumberRFloordivProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rfloordiv__() -> Option { + None + } } trait PyNumberRModProtocolImpl { fn __rmod__() -> Option; } -impl<'p, T> PyNumberRModProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rmod__() -> Option {None} +impl<'p, T> PyNumberRModProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rmod__() -> Option { + None + } } trait PyNumberRDivmodProtocolImpl { fn __rdivmod__() -> Option; } -impl<'p, T> PyNumberRDivmodProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rdivmod__() -> Option {None} +impl<'p, T> PyNumberRDivmodProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rdivmod__() -> Option { + None + } } trait PyNumberRPowProtocolImpl { fn __rpow__() -> Option; } -impl<'p, T> PyNumberRPowProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rpow__() -> Option {None} +impl<'p, T> PyNumberRPowProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rpow__() -> Option { + None + } } trait PyNumberRLShiftProtocolImpl { fn __rlshift__() -> Option; } -impl<'p, T> PyNumberRLShiftProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rlshift__() -> Option {None} +impl<'p, T> PyNumberRLShiftProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rlshift__() -> Option { + None + } } trait PyNumberRRShiftProtocolImpl { fn __rrshift__() -> Option; } -impl<'p, T> PyNumberRRShiftProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rrshift__() -> Option {None} +impl<'p, T> PyNumberRRShiftProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rrshift__() -> Option { + None + } } - trait PyNumberRAndProtocolImpl { fn __rand__() -> Option; } -impl<'p, T> PyNumberRAndProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rand__() -> Option {None} +impl<'p, T> PyNumberRAndProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rand__() -> Option { + None + } } trait PyNumberRXorProtocolImpl { fn __rxor__() -> Option; } -impl<'p, T> PyNumberRXorProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __rxor__() -> Option {None} +impl<'p, T> PyNumberRXorProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __rxor__() -> Option { + None + } } trait PyNumberROrProtocolImpl { fn __ror__() -> Option; } -impl<'p, T> PyNumberROrProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __ror__() -> Option {None} +impl<'p, T> PyNumberROrProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __ror__() -> Option { + None + } } trait PyNumberNegProtocolImpl { fn nb_negative() -> Option; } -impl<'p, T> PyNumberNegProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_negative() -> Option {None} +impl<'p, T> PyNumberNegProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_negative() -> Option { + None + } } -impl PyNumberNegProtocolImpl for T where T: for<'p> PyNumberNegProtocol<'p> +impl PyNumberNegProtocolImpl for T +where + T: for<'p> PyNumberNegProtocol<'p>, { #[inline] fn nb_negative() -> Option { - py_unary_func!(PyNumberNegProtocol, T::__neg__, T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberNegProtocol, + T::__neg__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberPosProtocolImpl { fn nb_positive() -> Option; } -impl<'p, T> PyNumberPosProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_positive() -> Option {None} +impl<'p, T> PyNumberPosProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_positive() -> Option { + None + } } -impl PyNumberPosProtocolImpl for T where T: for<'p> PyNumberPosProtocol<'p> +impl PyNumberPosProtocolImpl for T +where + T: for<'p> PyNumberPosProtocol<'p>, { fn nb_positive() -> Option { - py_unary_func!(PyNumberPosProtocol, T::__pos__, T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberPosProtocol, + T::__pos__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberAbsProtocolImpl { fn nb_absolute() -> Option; } -impl<'p, T> PyNumberAbsProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_absolute() -> Option {None} +impl<'p, T> PyNumberAbsProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_absolute() -> Option { + None + } } -impl PyNumberAbsProtocolImpl for T where T: for<'p> PyNumberAbsProtocol<'p> +impl PyNumberAbsProtocolImpl for T +where + T: for<'p> PyNumberAbsProtocol<'p>, { fn nb_absolute() -> Option { - py_unary_func!(PyNumberAbsProtocol, T::__abs__, T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberAbsProtocol, + T::__abs__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberInvertProtocolImpl { fn nb_invert() -> Option; } -impl<'p, T> PyNumberInvertProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_invert() -> Option {None} +impl<'p, T> PyNumberInvertProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_invert() -> Option { + None + } } -impl PyNumberInvertProtocolImpl for T where T: for<'p> PyNumberInvertProtocol<'p> +impl PyNumberInvertProtocolImpl for T +where + T: for<'p> PyNumberInvertProtocol<'p>, { fn nb_invert() -> Option { - py_unary_func!(PyNumberInvertProtocol, T::__invert__, - T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberInvertProtocol, + T::__invert__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberIntProtocolImpl { fn nb_int() -> Option; } -impl<'p, T> PyNumberIntProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_int() -> Option {None} +impl<'p, T> PyNumberIntProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_int() -> Option { + None + } } -impl PyNumberIntProtocolImpl for T where T: for<'p> PyNumberIntProtocol<'p> +impl PyNumberIntProtocolImpl for T +where + T: for<'p> PyNumberIntProtocol<'p>, { fn nb_int() -> Option { - py_unary_func!(PyNumberIntProtocol, T::__int__, - T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberIntProtocol, + T::__int__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberFloatProtocolImpl { fn nb_float() -> Option; } -impl<'p, T> PyNumberFloatProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_float() -> Option {None} +impl<'p, T> PyNumberFloatProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_float() -> Option { + None + } } -impl PyNumberFloatProtocolImpl for T where T: for<'p> PyNumberFloatProtocol<'p> +impl PyNumberFloatProtocolImpl for T +where + T: for<'p> PyNumberFloatProtocol<'p>, { fn nb_float() -> Option { - py_unary_func!(PyNumberFloatProtocol, T::__float__, - T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberFloatProtocol, + T::__float__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberIndexProtocolImpl { fn nb_index() -> Option; } -impl<'p, T> PyNumberIndexProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn nb_index() -> Option {None} +impl<'p, T> PyNumberIndexProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn nb_index() -> Option { + None + } } impl PyNumberIndexProtocolImpl for T - where T: for<'p> PyNumberIndexProtocol<'p> +where + T: for<'p> PyNumberIndexProtocol<'p>, { fn nb_index() -> Option { - py_unary_func!(PyNumberIndexProtocol, - T::__index__, T::Success, PyObjectCallbackConverter) + py_unary_func!( + PyNumberIndexProtocol, + T::__index__, + T::Success, + PyObjectCallbackConverter + ) } } trait PyNumberComplexProtocolImpl { fn __complex__() -> Option; } -impl<'p, T> PyNumberComplexProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __complex__() -> Option {None} +impl<'p, T> PyNumberComplexProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __complex__() -> Option { + None + } } trait PyNumberRoundProtocolImpl { fn __round__() -> Option; } -impl<'p, T> PyNumberRoundProtocolImpl for T where T: PyNumberProtocol<'p> { - default fn __round__() -> Option {None} +impl<'p, T> PyNumberRoundProtocolImpl for T +where + T: PyNumberProtocol<'p>, +{ + default fn __round__() -> Option { + None + } } diff --git a/src/class/sequence.rs b/src/class/sequence.rs index 090870dc59a..92fdd106835 100644 --- a/src/class/sequence.rs +++ b/src/class/sequence.rs @@ -5,46 +5,80 @@ use std::os::raw::c_int; -use ffi; -use python::Python; +use callback::{BoolCallbackConverter, LenResultConverter, PyObjectCallbackConverter}; +use conversion::{FromPyObject, IntoPyObject}; use err::{PyErr, PyResult}; -use objects::{exc, PyObjectRef}; +use ffi; use objectprotocol::ObjectProtocol; -use callback::{PyObjectCallbackConverter, LenResultConverter, BoolCallbackConverter}; +use objects::{exc, PyObjectRef}; +use python::Python; use typeob::PyTypeInfo; -use conversion::{IntoPyObject, FromPyObject}; - /// Sequece interface #[allow(unused_variables)] -pub trait PySequenceProtocol<'p>: PyTypeInfo + Sized -{ +pub trait PySequenceProtocol<'p>: PyTypeInfo + Sized { fn __len__(&'p self) -> Self::Result - where Self: PySequenceLenProtocol<'p> { unimplemented!() } + where + Self: PySequenceLenProtocol<'p>, + { + unimplemented!() + } fn __getitem__(&'p self, key: isize) -> Self::Result - where Self: PySequenceGetItemProtocol<'p> { unimplemented!() } + where + Self: PySequenceGetItemProtocol<'p>, + { + unimplemented!() + } fn __setitem__(&'p mut self, key: isize, value: Self::Value) -> Self::Result - where Self: PySequenceSetItemProtocol<'p> { unimplemented!() } + where + Self: PySequenceSetItemProtocol<'p>, + { + unimplemented!() + } fn __delitem__(&'p mut self, key: isize) -> Self::Result - where Self: PySequenceDelItemProtocol<'p> { unimplemented!() } + where + Self: PySequenceDelItemProtocol<'p>, + { + unimplemented!() + } fn __contains__(&'p self, item: Self::Item) -> Self::Result - where Self: PySequenceContainsProtocol<'p> { unimplemented!() } + where + Self: PySequenceContainsProtocol<'p>, + { + unimplemented!() + } fn __concat__(&'p self, other: Self::Other) -> Self::Result - where Self: PySequenceConcatProtocol<'p> { unimplemented!() } + where + Self: PySequenceConcatProtocol<'p>, + { + unimplemented!() + } fn __repeat__(&'p self, count: isize) -> Self::Result - where Self: PySequenceRepeatProtocol<'p> { unimplemented!() } + where + Self: PySequenceRepeatProtocol<'p>, + { + unimplemented!() + } fn __inplace_concat__(&'p mut self, other: Self::Other) -> Self::Result - where Self: PySequenceInplaceConcatProtocol<'p> { unimplemented!() } + where + Self: PySequenceInplaceConcatProtocol<'p>, + { + unimplemented!() + } fn __inplace_repeat__(&'p mut self, count: isize) -> Self::Result - where Self: PySequenceInplaceRepeatProtocol<'p> { unimplemented!() } + where + Self: PySequenceInplaceRepeatProtocol<'p>, + { + unimplemented!() + } } // The following are a bunch of marker traits used to detect @@ -105,7 +139,10 @@ impl PySequenceProtocolImpl for T { } } -impl<'p, T> PySequenceProtocolImpl for T where T: PySequenceProtocol<'p> { +impl<'p, T> PySequenceProtocolImpl for T +where + T: PySequenceProtocol<'p>, +{ #[cfg(Py_3)] #[inline] fn tp_as_sequence() -> Option { @@ -156,7 +193,9 @@ trait PySequenceLenProtocolImpl { fn sq_length() -> Option; } -impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceLenProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_length() -> Option { @@ -164,7 +203,9 @@ impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p> } } -impl PySequenceLenProtocolImpl for T where T: for<'p> PySequenceLenProtocol<'p> +impl PySequenceLenProtocolImpl for T +where + T: for<'p> PySequenceLenProtocol<'p>, { #[inline] fn sq_length() -> Option { @@ -176,7 +217,9 @@ trait PySequenceGetItemProtocolImpl { fn sq_item() -> Option; } -impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceGetItemProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_item() -> Option { @@ -185,12 +228,17 @@ impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p> } impl PySequenceGetItemProtocolImpl for T - where T: for<'p> PySequenceGetItemProtocol<'p> +where + T: for<'p> PySequenceGetItemProtocol<'p>, { #[inline] fn sq_item() -> Option { py_ssizearg_func!( - PySequenceGetItemProtocol, T::__getitem__, T::Success, PyObjectCallbackConverter) + PySequenceGetItemProtocol, + T::__getitem__, + T::Success, + PyObjectCallbackConverter + ) } } @@ -198,7 +246,9 @@ trait PySequenceSetItemProtocolImpl { fn sq_ass_item() -> Option; } -impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceSetItemProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_ass_item() -> Option { @@ -207,30 +257,34 @@ impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p> } impl PySequenceSetItemProtocolImpl for T - where T: for<'p> PySequenceSetItemProtocol<'p> +where + T: for<'p> PySequenceSetItemProtocol<'p>, { #[inline] fn sq_ass_item() -> Option { - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - key: ffi::Py_ssize_t, - value: *mut ffi::PyObject) -> c_int - where T: for<'p> PySequenceSetItemProtocol<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + key: ffi::Py_ssize_t, + value: *mut ffi::PyObject, + ) -> c_int + where + T: for<'p> PySequenceSetItemProtocol<'p>, { let _pool = ::GILPool::new(); let py = Python::assume_gil_acquired(); let slf = py.mut_from_borrowed_ptr::(slf); if value.is_null() { - let e = PyErr::new::( - format!("Item deletion not supported by {:?}", stringify!(T))); + let e = PyErr::new::(format!( + "Item deletion not supported by {:?}", + stringify!(T) + )); e.restore(py); -1 } else { let value = py.from_borrowed_ptr::(value); let result = match value.extract() { - Ok(value) => { - slf.__setitem__(key as isize, value).into() - }, + Ok(value) => slf.__setitem__(key as isize, value).into(), Err(e) => Err(e), }; match result { @@ -249,7 +303,9 @@ impl PySequenceSetItemProtocolImpl for T trait PySequenceDelItemProtocolImpl { fn sq_del_item() -> Option; } -impl<'p, T> PySequenceDelItemProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceDelItemProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_del_item() -> Option { @@ -258,14 +314,18 @@ impl<'p, T> PySequenceDelItemProtocolImpl for T where T: PySequenceProtocol<'p> } impl PySequenceDelItemProtocolImpl for T - where T: for<'p> PySequenceDelItemProtocol<'p> +where + T: for<'p> PySequenceDelItemProtocol<'p>, { #[inline] default fn sq_del_item() -> Option { - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - key: ffi::Py_ssize_t, - value: *mut ffi::PyObject) -> c_int - where T: for<'p> PySequenceDelItemProtocol<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + key: ffi::Py_ssize_t, + value: *mut ffi::PyObject, + ) -> c_int + where + T: for<'p> PySequenceDelItemProtocol<'p>, { let _pool = ::GILPool::new(); let py = Python::assume_gil_acquired(); @@ -281,8 +341,10 @@ impl PySequenceDelItemProtocolImpl for T } } } else { - let e = PyErr::new::( - format!("Item assignment not supported by {:?}", stringify!(T))); + let e = PyErr::new::(format!( + "Item assignment not supported by {:?}", + stringify!(T) + )); e.restore(py); -1 } @@ -292,15 +354,18 @@ impl PySequenceDelItemProtocolImpl for T } impl PySequenceDelItemProtocolImpl for T - where T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p> +where + T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>, { #[inline] fn sq_del_item() -> Option { - unsafe extern "C" fn wrap(slf: *mut ffi::PyObject, - key: ffi::Py_ssize_t, - value: *mut ffi::PyObject) -> c_int - where T: for<'p> PySequenceSetItemProtocol<'p> + - for<'p> PySequenceDelItemProtocol<'p> + unsafe extern "C" fn wrap( + slf: *mut ffi::PyObject, + key: ffi::Py_ssize_t, + value: *mut ffi::PyObject, + ) -> c_int + where + T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>, { let _pool = ::GILPool::new(); let py = Python::assume_gil_acquired(); @@ -318,9 +383,7 @@ impl PySequenceDelItemProtocolImpl for T } else { let value = py.from_borrowed_ptr::(value); let result = match value.extract() { - Ok(value) => { - slf.__setitem__(key as isize, value).into() - }, + Ok(value) => slf.__setitem__(key as isize, value).into(), Err(e) => Err(e), }; match result { @@ -336,12 +399,13 @@ impl PySequenceDelItemProtocolImpl for T } } - trait PySequenceContainsProtocolImpl { fn sq_contains() -> Option; } -impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceContainsProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_contains() -> Option { @@ -350,12 +414,18 @@ impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p> } impl PySequenceContainsProtocolImpl for T - where T: for<'p> PySequenceContainsProtocol<'p> +where + T: for<'p> PySequenceContainsProtocol<'p>, { #[inline] fn sq_contains() -> Option { - py_binary_func!(PySequenceContainsProtocol, - T::__contains__, bool, BoolCallbackConverter, c_int) + py_binary_func!( + PySequenceContainsProtocol, + T::__contains__, + bool, + BoolCallbackConverter, + c_int + ) } } @@ -363,7 +433,9 @@ trait PySequenceConcatProtocolImpl { fn sq_concat() -> Option; } -impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceConcatProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_concat() -> Option { @@ -372,12 +444,17 @@ impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p> } impl PySequenceConcatProtocolImpl for T - where T: for<'p> PySequenceConcatProtocol<'p> +where + T: for<'p> PySequenceConcatProtocol<'p>, { #[inline] fn sq_concat() -> Option { - py_binary_func!(PySequenceConcatProtocol, - T::__concat__, T::Success, PyObjectCallbackConverter) + py_binary_func!( + PySequenceConcatProtocol, + T::__concat__, + T::Success, + PyObjectCallbackConverter + ) } } @@ -386,7 +463,8 @@ trait PySequenceRepeatProtocolImpl { } impl<'p, T> PySequenceRepeatProtocolImpl for T - where T: PySequenceProtocol<'p> +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_repeat() -> Option { @@ -394,12 +472,18 @@ impl<'p, T> PySequenceRepeatProtocolImpl for T } } -impl PySequenceRepeatProtocolImpl for T where T: for<'p> PySequenceRepeatProtocol<'p> +impl PySequenceRepeatProtocolImpl for T +where + T: for<'p> PySequenceRepeatProtocol<'p>, { #[inline] fn sq_repeat() -> Option { py_ssizearg_func!( - PySequenceRepeatProtocol, T::__repeat__, T::Success, PyObjectCallbackConverter) + PySequenceRepeatProtocol, + T::__repeat__, + T::Success, + PyObjectCallbackConverter + ) } } @@ -407,7 +491,9 @@ trait PySequenceInplaceConcatProtocolImpl { fn sq_inplace_concat() -> Option; } -impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceInplaceConcatProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_inplace_concat() -> Option { @@ -416,12 +502,17 @@ impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtoco } impl PySequenceInplaceConcatProtocolImpl for T - where T: for<'p> PySequenceInplaceConcatProtocol<'p> +where + T: for<'p> PySequenceInplaceConcatProtocol<'p>, { #[inline] fn sq_inplace_concat() -> Option { - py_binary_func!(PySequenceInplaceConcatProtocol, - T::__inplace_concat__, T, PyObjectCallbackConverter) + py_binary_func!( + PySequenceInplaceConcatProtocol, + T::__inplace_concat__, + T, + PyObjectCallbackConverter + ) } } @@ -429,7 +520,9 @@ trait PySequenceInplaceRepeatProtocolImpl { fn sq_inplace_repeat() -> Option; } -impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtocol<'p> +impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T +where + T: PySequenceProtocol<'p>, { #[inline] default fn sq_inplace_repeat() -> Option { @@ -438,11 +531,16 @@ impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtoco } impl PySequenceInplaceRepeatProtocolImpl for T - where T: for<'p> PySequenceInplaceRepeatProtocol<'p> +where + T: for<'p> PySequenceInplaceRepeatProtocol<'p>, { #[inline] fn sq_inplace_repeat() -> Option { - py_ssizearg_func!(PySequenceInplaceRepeatProtocol, - T::__inplace_repeat__, T, PyObjectCallbackConverter) + py_ssizearg_func!( + PySequenceInplaceRepeatProtocol, + T::__inplace_repeat__, + T, + PyObjectCallbackConverter + ) } } diff --git a/src/conversion.rs b/src/conversion.rs index 518b95fc0fd..59291ca9dd5 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -2,25 +2,21 @@ //! This module contains some conversion traits +use err::{PyDowncastError, PyResult}; use ffi; -use err::{PyResult, PyDowncastError}; -use python::{Python, ToPyPointer, IntoPyPointer}; +use instance::Py; use object::PyObject; use objects::{PyObjectRef, PyTuple}; +use python::{IntoPyPointer, Python, ToPyPointer}; use typeob::PyTypeInfo; -use instance::Py; - /// Conversion trait that allows various objects to be converted into `PyObject` pub trait ToPyObject { - /// Converts self into a Python object. fn to_object(&self, py: Python) -> PyObject; - } pub trait ToBorrowedObject: ToPyObject { - /// Converts self into a Python object and calls the specified closure /// on the native FFI pointer underlying the Python object. /// @@ -28,13 +24,18 @@ pub trait ToBorrowedObject: ToPyObject { /// to touch any reference counts when the input object already is a Python object. #[inline] fn with_borrowed_ptr(&self, py: Python, f: F) -> R - where F: FnOnce(*mut ffi::PyObject) -> R; + where + F: FnOnce(*mut ffi::PyObject) -> R; } -impl ToBorrowedObject for T where T: ToPyObject { +impl ToBorrowedObject for T +where + T: ToPyObject, +{ #[inline] default fn with_borrowed_ptr(&self, py: Python, f: F) -> R - where F: FnOnce(*mut ffi::PyObject) -> R + where + F: FnOnce(*mut ffi::PyObject) -> R, { let ptr = self.to_object(py).into_ptr(); let result = f(ptr); @@ -46,18 +47,14 @@ impl ToBorrowedObject for T where T: ToPyObject { /// Conversion trait that allows various objects to be converted into `PyObject` /// by consuming original object. pub trait IntoPyObject { - /// Converts self into a Python object. (Consumes self) fn into_object(self, py: Python) -> PyObject; } - /// Conversion trait that allows various objects to be converted into `PyTuple` object. pub trait IntoPyTuple { - /// Converts self into a PyTuple object. fn into_tuple(self, py: Python) -> Py; - } /// `FromPyObject` is implemented by various types that can be extracted from @@ -80,15 +77,17 @@ pub trait IntoPyTuple { /// /// In cases where the result does not depend on the `'prepared` lifetime, /// the inherent method `PyObject::extract()` can be used. -pub trait FromPyObject<'source> : Sized { +pub trait FromPyObject<'source>: Sized { /// Extracts `Self` from the source `PyObject`. fn extract(ob: &'source PyObjectRef) -> PyResult; } /// Identity conversion: allows using existing `PyObject` instances where /// `T: ToPyObject` is expected. -impl <'a, T: ?Sized> ToPyObject for &'a T where T: ToPyObject { - +impl<'a, T: ?Sized> ToPyObject for &'a T +where + T: ToPyObject, +{ #[inline] fn to_object(&self, py: Python) -> PyObject { ::to_object(*self, py) @@ -97,8 +96,10 @@ impl <'a, T: ?Sized> ToPyObject for &'a T where T: ToPyObject { /// `Option::Some` is converted like `T`. /// `Option::None` is converted to Python `None`. -impl ToPyObject for Option where T: ToPyObject { - +impl ToPyObject for Option +where + T: ToPyObject, +{ fn to_object(&self, py: Python) -> PyObject { match *self { Some(ref val) => val.to_object(py), @@ -107,8 +108,10 @@ impl ToPyObject for Option where T: ToPyObject { } } -impl IntoPyObject for Option where T: IntoPyObject { - +impl IntoPyObject for Option +where + T: IntoPyObject, +{ fn into_object(self, py: Python) -> PyObject { match self { Some(val) => val.into_object(py), @@ -130,7 +133,9 @@ impl IntoPyObject for () { } } -impl<'a, T> IntoPyObject for &'a T where T: ToPyPointer +impl<'a, T> IntoPyObject for &'a T +where + T: ToPyPointer, { #[inline] fn into_object(self, py: Python) -> PyObject { @@ -138,7 +143,10 @@ impl<'a, T> IntoPyObject for &'a T where T: ToPyPointer } } -impl<'a, T> IntoPyObject for &'a mut T where T: ToPyPointer { +impl<'a, T> IntoPyObject for &'a mut T +where + T: ToPyPointer, +{ #[inline] fn into_object(self, py: Python) -> PyObject { unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) } @@ -147,7 +155,8 @@ impl<'a, T> IntoPyObject for &'a mut T where T: ToPyPointer { /// Extract reference to instance from `PyObject` impl<'a, T> FromPyObject<'a> for &'a T - where T: PyTypeInfo +where + T: PyTypeInfo, { #[inline] default fn extract(ob: &'a PyObjectRef) -> PyResult<&'a T> { @@ -157,7 +166,8 @@ impl<'a, T> FromPyObject<'a> for &'a T /// Extract mutable reference to instance from `PyObject` impl<'a, T> FromPyObject<'a> for &'a mut T - where T: PyTypeInfo +where + T: PyTypeInfo, { #[inline] default fn extract(ob: &'a PyObjectRef) -> PyResult<&'a mut T> { @@ -165,7 +175,9 @@ impl<'a, T> FromPyObject<'a> for &'a mut T } } -impl<'a, T> FromPyObject<'a> for Option where T: FromPyObject<'a> +impl<'a, T> FromPyObject<'a> for Option +where + T: FromPyObject<'a>, { fn extract(obj: &'a PyObjectRef) -> PyResult { if obj.as_ptr() == unsafe { ffi::Py_None() } { @@ -173,7 +185,7 @@ impl<'a, T> FromPyObject<'a> for Option where T: FromPyObject<'a> } else { match T::extract(obj) { Ok(v) => Ok(Some(v)), - Err(e) => Err(e) + Err(e) => Err(e), } } } @@ -218,8 +230,10 @@ pub trait PyTryFrom: Sized { } // TryFrom implies TryInto -impl PyTryInto for PyObjectRef where U: PyTryFrom { - +impl PyTryInto for PyObjectRef +where + U: PyTryFrom, +{ type Error = U::Error; fn try_into(&self) -> Result<&U, U::Error> { @@ -236,9 +250,10 @@ impl PyTryInto for PyObjectRef where U: PyTryFrom { } } - -impl PyTryFrom for T where T: PyTypeInfo { - +impl PyTryFrom for T +where + T: PyTypeInfo, +{ type Error = PyDowncastError; fn try_from(value: &PyObjectRef) -> Result<&T, Self::Error> { diff --git a/src/err.rs b/src/err.rs index 59134ba23f4..b90623edd3d 100644 --- a/src/err.rs +++ b/src/err.rs @@ -1,18 +1,18 @@ // Copyright (c) 2017-present PyO3 Project and Contributors +use libc; use std; -use std::io; +use std::error::Error; use std::ffi::CString; +use std::io; use std::os::raw::c_char; -use std::error::Error; -use libc; +use conversion::{IntoPyObject, ToBorrowedObject, ToPyObject}; use ffi; -use python::{ToPyPointer, IntoPyPointer, Python}; -use object::PyObject; -use objects::{PyObjectRef, PyType, exc}; use instance::Py; +use object::PyObject; +use objects::{exc, PyObjectRef, PyType}; +use python::{IntoPyPointer, Python, ToPyPointer}; use typeob::PyTypeObject; -use conversion::{ToPyObject, IntoPyObject, ToBorrowedObject}; /// Defines a new exception type. /// @@ -78,8 +78,11 @@ macro_rules! py_exception { let py = gil.python(); TYPE_OBJECT = $crate::PyErr::new_type( - py, concat!(stringify!($module), ".", stringify!($name)), - Some(py.get_type::<$base>()), None); + py, + concat!(stringify!($module), ".", stringify!($name)), + Some(py.get_type::<$base>()), + None, + ); } TYPE_OBJECT } @@ -96,14 +99,15 @@ macro_rules! py_exception { fn type_object() -> $crate::Py<$crate::PyType> { unsafe { $crate::Py::from_borrowed_ptr( - $name::type_object() as *const _ as *mut $crate::ffi::PyObject) + $name::type_object() as *const _ as *mut $crate::ffi::PyObject + ) } } } }; ($module: ident, $name: ident) => { py_exception!($module, $name, $crate::exc::Exception); - } + }; } /// Represents a `PyErr` value @@ -156,7 +160,9 @@ impl PyErr { /// Example: /// `return Err(PyErr::new::("Error message"));` pub fn new(value: V) -> PyErr - where T: PyTypeObject, V: ToPyObject + 'static + where + T: PyTypeObject, + V: ToPyObject + 'static, { let ty = T::type_object(); assert_ne!(unsafe { ffi::PyExceptionClass_Check(ty.as_ptr()) }, 0); @@ -173,7 +179,8 @@ impl PyErr { /// like `exc::RuntimeError`. /// `args` is the a tuple of arguments to pass to the exception constructor. pub fn from_type(exc: Py, args: A) -> PyErr - where A: ToPyObject + 'static + where + A: ToPyObject + 'static, { PyErr { ptype: exc, @@ -184,7 +191,8 @@ impl PyErr { /// Creates a new PyErr of type `T`. pub fn from_value(value: PyErrValue) -> PyErr - where T: PyTypeObject + where + T: PyTypeObject, { let ty = T::type_object(); assert_ne!(unsafe { ffi::PyExceptionClass_Check(ty.as_ptr()) }, 0); @@ -207,7 +215,7 @@ impl PyErr { if unsafe { ffi::PyExceptionInstance_Check(ptr) } != 0 { PyErr { - ptype: unsafe { Py::from_borrowed_ptr( ffi::PyExceptionInstance_Class(ptr)) }, + ptype: unsafe { Py::from_borrowed_ptr(ffi::PyExceptionInstance_Class(ptr)) }, pvalue: PyErrValue::Value(obj.into()), ptraceback: None, } @@ -220,8 +228,7 @@ impl PyErr { } else { PyErr { ptype: exc::TypeError::type_object(), - pvalue: PyErrValue::ToObject( - Box::new("exceptions must derive from BaseException")), + pvalue: PyErrValue::ToObject(Box::new("exceptions must derive from BaseException")), ptraceback: None, } } @@ -238,9 +245,9 @@ impl PyErr { /// If no error is set, returns a `SystemError`. pub fn fetch(_: Python) -> PyErr { unsafe { - let mut ptype : *mut ffi::PyObject = std::ptr::null_mut(); - let mut pvalue : *mut ffi::PyObject = std::ptr::null_mut(); - let mut ptraceback : *mut ffi::PyObject = std::ptr::null_mut(); + let mut ptype: *mut ffi::PyObject = std::ptr::null_mut(); + let mut pvalue: *mut ffi::PyObject = std::ptr::null_mut(); + let mut ptraceback: *mut ffi::PyObject = std::ptr::null_mut(); ffi::PyErr_Fetch(&mut ptype, &mut pvalue, &mut ptraceback); PyErr::new_from_ffi_tuple(ptype, pvalue, ptraceback) } @@ -251,12 +258,15 @@ impl PyErr { /// /// `base` can be an existing exception type to subclass, or a tuple of classes /// `dict` specifies an optional dictionary of class variables and methods - pub fn new_type<'p>(_: Python<'p>, name: &str, base: Option<&PyType>, dict: Option) - -> *mut ffi::PyTypeObject - { + pub fn new_type<'p>( + _: Python<'p>, + name: &str, + base: Option<&PyType>, + dict: Option, + ) -> *mut ffi::PyTypeObject { let base: *mut ffi::PyObject = match base { None => std::ptr::null_mut(), - Some(obj) => obj.as_ptr() + Some(obj) => obj.as_ptr(), }; let dict: *mut ffi::PyObject = match dict { @@ -265,16 +275,18 @@ impl PyErr { }; unsafe { - let null_terminated_name = CString::new(name) - .expect("Failed to initialize nul terminated exception name"); - ffi::PyErr_NewException( - null_terminated_name.as_ptr() as *mut c_char, base, dict) as *mut ffi::PyTypeObject + let null_terminated_name = + CString::new(name).expect("Failed to initialize nul terminated exception name"); + ffi::PyErr_NewException(null_terminated_name.as_ptr() as *mut c_char, base, dict) + as *mut ffi::PyTypeObject } } - unsafe fn new_from_ffi_tuple(ptype: *mut ffi::PyObject, - pvalue: *mut ffi::PyObject, - ptraceback: *mut ffi::PyObject) -> PyErr { + unsafe fn new_from_ffi_tuple( + ptype: *mut ffi::PyObject, + pvalue: *mut ffi::PyObject, + ptraceback: *mut ffi::PyObject, + ) -> PyErr { // Note: must not panic to ensure all owned pointers get acquired correctly, // and because we mustn't panic in normalize(). @@ -313,7 +325,8 @@ impl PyErr { /// If `exc` is a class object, this also returns `true` when `self` is an instance of a subclass. /// If `exc` is a tuple, all exceptions in the tuple (and recursively in subtuples) are searched for a match. pub fn matches(&self, py: Python, exc: T) -> bool - where T: ToBorrowedObject + where + T: ToBorrowedObject, { exc.with_borrowed_ptr(py, |exc| unsafe { ffi::PyErr_GivenExceptionMatches(self.ptype.as_ptr(), exc) != 0 @@ -322,11 +335,11 @@ impl PyErr { /// Return true if the current exception is instance of `T` pub fn is_instance(&self, _py: Python) -> bool - where T: PyTypeObject + where + T: PyTypeObject, { unsafe { - ffi::PyErr_GivenExceptionMatches( - self.ptype.as_ptr(), T::type_object().as_ptr()) != 0 + ffi::PyErr_GivenExceptionMatches(self.ptype.as_ptr(), T::type_object().as_ptr()) != 0 } } @@ -344,7 +357,11 @@ impl PyErr { /// Helper function for normalizing the error by deconstructing and reconstructing the PyErr. /// Must not panic for safety in normalize() fn into_normalized(self, py: Python) -> PyErr { - let PyErr { ptype, pvalue, ptraceback } = self; + let PyErr { + ptype, + pvalue, + ptraceback, + } = self; let mut pvalue = match pvalue { PyErrValue::None => std::ptr::null_mut(), @@ -376,7 +393,11 @@ impl PyErr { /// This is the opposite of `PyErr::fetch()`. #[inline] pub fn restore(self, py: Python) { - let PyErr { ptype, pvalue, ptraceback } = self; + let PyErr { + ptype, + pvalue, + ptraceback, + } = self; let pvalue = match pvalue { PyErrValue::None => std::ptr::null_mut(), @@ -384,18 +405,27 @@ impl PyErr { PyErrValue::ToArgs(ob) => ob.arguments(py).into_ptr(), PyErrValue::ToObject(ob) => ob.to_object(py).into_ptr(), }; - unsafe { - ffi::PyErr_Restore(ptype.into_ptr(), pvalue, ptraceback.into_ptr()) - } + unsafe { ffi::PyErr_Restore(ptype.into_ptr(), pvalue, ptraceback.into_ptr()) } } /// Issue a warning message. /// May return a PyErr if warnings-as-errors is enabled. - pub fn warn(py: Python, category: &PyObjectRef, message: &str, stacklevel: i32) -> PyResult<()> { + pub fn warn( + py: Python, + category: &PyObjectRef, + message: &str, + stacklevel: i32, + ) -> PyResult<()> { let message = CString::new(message)?; unsafe { - error_on_minusone(py, ffi::PyErr_WarnEx( - category.as_ptr(), message.as_ptr(), stacklevel as ffi::Py_ssize_t)) + error_on_minusone( + py, + ffi::PyErr_WarnEx( + category.as_ptr(), + message.as_ptr(), + stacklevel as ffi::Py_ssize_t, + ), + ) } } @@ -407,7 +437,11 @@ impl PyErr { PyErrValue::ToObject(ref ob) => PyErrValue::Value(ob.to_object(py)), }; - let t = if let Some(ref val) = self.ptraceback { Some(val.clone_ref(py))} else { None }; + let t = if let Some(ref val) = self.ptraceback { + Some(val.clone_ref(py)) + } else { + None + }; PyErr { ptype: self.ptype.clone_ref(py), pvalue: v, @@ -423,14 +457,12 @@ impl std::fmt::Debug for PyErr { } impl IntoPyObject for PyErr { - fn into_object(self, py: Python) -> PyObject { self.instance(py) } } impl ToPyObject for PyErr { - fn to_object(&self, py: Python) -> PyObject { let err = self.clone_ref(py); err.instance(py) @@ -438,7 +470,6 @@ impl ToPyObject for PyErr { } impl<'a> IntoPyObject for &'a PyErr { - fn into_object(self, py: Python) -> PyObject { let err = self.clone_ref(py); err.instance(py) @@ -452,8 +483,8 @@ impl std::convert::From for PyErr { } } -impl <'p> std::fmt::Debug for PyDowncastError { - fn fmt(&self, f : &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { +impl<'p> std::fmt::Debug for PyDowncastError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { f.write_str("PyDowncastError") } } @@ -462,7 +493,9 @@ impl <'p> std::fmt::Debug for PyDowncastError { impl std::convert::From for std::io::Error { fn from(err: PyErr) -> Self { std::io::Error::new( - std::io::ErrorKind::Other, format!("Python exception: {:?}", err)) + std::io::ErrorKind::Other, + format!("Python exception: {:?}", err), + ) } } @@ -486,7 +519,7 @@ macro_rules! impl_to_pyerr { PyErr::from_value::<$pyexc>(PyErrValue::ToArgs(Box::new(err))) } } - } + }; } #[cfg(Py_3)] @@ -494,27 +527,31 @@ macro_rules! impl_to_pyerr { impl std::convert::From for PyErr { fn from(err: io::Error) -> PyErr { match err.kind() { - io::ErrorKind::BrokenPipe => - PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::ConnectionRefused => - PyErr::from_value::( - PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::ConnectionAborted => - PyErr::from_value::( - PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::ConnectionReset => - PyErr::from_value::( - PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::Interrupted => - PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::NotFound => - PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::WouldBlock => - PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), - io::ErrorKind::TimedOut => - PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), - _ => - PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), + io::ErrorKind::BrokenPipe => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::ConnectionRefused => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::ConnectionAborted => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::ConnectionReset => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::Interrupted => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::NotFound => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::WouldBlock => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + io::ErrorKind::TimedOut => { + PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) + } + _ => PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))), } } } @@ -527,7 +564,6 @@ impl std::convert::From for PyErr { } } - /// Extract `errno` and `errdesc` from from `io::Error` impl PyErrArguments for io::Error { fn arguments(&self, py: Python) -> PyObject { @@ -535,8 +571,7 @@ impl PyErrArguments for io::Error { } } -impl std::convert::From> for PyErr -{ +impl std::convert::From> for PyErr { fn from(err: std::io::IntoInnerError) -> PyErr { PyErr::from_value::(PyErrValue::ToArgs(Box::new(err))) } @@ -561,7 +596,9 @@ impl_to_pyerr!(std::char::DecodeUtf16Error, exc::UnicodeDecodeError); impl_to_pyerr!(std::net::AddrParseError, exc::ValueError); pub fn panic_after_error() -> ! { - unsafe { ffi::PyErr_Print(); } + unsafe { + ffi::PyErr_Print(); + } panic!("Python API called failed"); } @@ -577,8 +614,8 @@ pub fn error_on_minusone(py: Python, result: libc::c_int) -> PyResult<()> { #[cfg(test)] mod tests { - use ::{Python, PyErr}; use objects::exc; + use {PyErr, Python}; #[test] fn set_typeerror() { diff --git a/src/ffi2/boolobject.rs b/src/ffi2/boolobject.rs index add24350184..16267abc2de 100644 --- a/src/ffi2/boolobject.rs +++ b/src/ffi2/boolobject.rs @@ -1,24 +1,25 @@ -use std::os::raw::{c_int, c_long}; -use ffi2::object::*; use ffi2::intobject::PyIntObject; +use ffi2::object::*; +use std::os::raw::{c_int, c_long}; pub type PyBoolObject = PyIntObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyBool_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="_PyPy_ZeroStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_ZeroStruct")] static mut _Py_ZeroStruct: PyIntObject; - #[cfg_attr(PyPy, link_name="_PyPy_TrueStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyIntObject; - #[cfg_attr(PyPy, link_name="PyPyBool_FromLong")] + #[cfg_attr(PyPy, link_name = "PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyBool_Check")] -pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyBool_Type; +#[cfg_attr(PyPy, link_name = "PyPyBool_Check")] +pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int { + let u: *mut PyTypeObject = &mut PyBool_Type; (Py_TYPE(op) == u) as c_int } @@ -30,4 +31,4 @@ pub unsafe fn Py_False() -> *mut PyObject { #[inline(always)] pub unsafe fn Py_True() -> *mut PyObject { &mut _Py_TrueStruct as *mut PyBoolObject as *mut PyObject -} \ No newline at end of file +} diff --git a/src/ffi2/bufferobject.rs b/src/ffi2/bufferobject.rs index 5a8e9cca66a..1baadb18a59 100644 --- a/src/ffi2/bufferobject.rs +++ b/src/ffi2/bufferobject.rs @@ -1,34 +1,39 @@ -use std::os::raw::{c_void, c_int}; use ffi2::object::*; use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyBuffer_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBuffer_Type")] pub static mut PyBuffer_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyBuffer_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyBuffer_Type; +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" { - #[cfg_attr(PyPy, link_name="PyPyBuffer_FromObject")] - pub fn PyBuffer_FromObject(base: *mut PyObject, offset: Py_ssize_t, - size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBuffer_FromReadWriteObject")] - pub fn PyBuffer_FromReadWriteObject(base: *mut PyObject, - offset: Py_ssize_t, size: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBuffer_FromMemory")] - pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBuffer_FromReadWriteMemory")] - pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, - size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBuffer_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromObject")] + pub fn PyBuffer_FromObject( + base: *mut PyObject, + offset: Py_ssize_t, + size: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteObject")] + pub fn PyBuffer_FromReadWriteObject( + base: *mut PyObject, + offset: Py_ssize_t, + size: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromMemory")] + pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteMemory")] + pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_New")] pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject; -} \ No newline at end of file +} diff --git a/src/ffi2/bytearrayobject.rs b/src/ffi2/bytearrayobject.rs index 8e60265c33b..c80269bf8c6 100644 --- a/src/ffi2/bytearrayobject.rs +++ b/src/ffi2/bytearrayobject.rs @@ -1,6 +1,6 @@ -use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; /*#[repr(C)] #[deriving(Copy)] @@ -17,39 +17,38 @@ struct PyByteArrayObject { pub ob_bytes: *mut c_char, }*/ -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyByteArray_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name="PyPyByteArray_Check")] -pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyByteArray_Check")] +pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyByteArray_Type) } -#[cfg_attr(PyPy, link_name="PyPyByteArray_CheckExact")] -pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyByteArray_Type; +#[cfg_attr(PyPy, link_name = "PyPyByteArray_CheckExact")] +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" { - #[cfg_attr(PyPy, link_name="PyPyByteArray_FromObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyByteArray_Concat")] - pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyByteArray_FromStringAndSize")] - pub fn PyByteArray_FromStringAndSize(string: *const c_char, - len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyByteArray_Size")] + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Concat")] + pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromStringAndSize")] + pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyByteArray_AsString")] + #[cfg_attr(PyPy, link_name = "PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name="PyPyByteArray_Resize")] - pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Resize")] + pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; } #[inline(always)] @@ -64,4 +63,4 @@ pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char { 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) -} \ No newline at end of file +} diff --git a/src/ffi2/bytesobject.rs b/src/ffi2/bytesobject.rs index 9d2ef2209bd..5464b38a4f1 100644 --- a/src/ffi2/bytesobject.rs +++ b/src/ffi2/bytesobject.rs @@ -1,17 +1,17 @@ +pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; pub use ffi2::stringobject::PyStringObject as PyBytesObject; -pub use ffi2::stringobject::PyString_Type as PyBytes_Type; -pub use ffi2::stringobject::PyString_Check as PyBytes_Check; -pub use ffi2::stringobject::PyString_CheckExact as PyBytes_CheckExact; pub use ffi2::stringobject::PyString_AS_STRING as PyBytes_AS_STRING; -pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; -pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; -pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; -pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString; -#[cfg_attr(PyPy, link_name="PyPyString_FromFormat")] -pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat; -pub use ffi2::stringobject::PyString_Size as PyBytes_Size; pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString; +pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; +pub use ffi2::stringobject::PyString_Check as PyBytes_Check; +pub use ffi2::stringobject::PyString_CheckExact as PyBytes_CheckExact; pub use ffi2::stringobject::PyString_Concat as PyBytes_Concat; pub use ffi2::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel; pub use ffi2::stringobject::PyString_Format as PyBytes_Format; -pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; \ No newline at end of file +#[cfg_attr(PyPy, link_name = "PyPyString_FromFormat")] +pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat; +pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString; +pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; +pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; +pub use ffi2::stringobject::PyString_Size as PyBytes_Size; +pub use ffi2::stringobject::PyString_Type as PyBytes_Type; diff --git a/src/ffi2/cellobject.rs b/src/ffi2/cellobject.rs index ee18c31e9df..2cc5106ad4c 100644 --- a/src/ffi2/cellobject.rs +++ b/src/ffi2/cellobject.rs @@ -1,30 +1,32 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] struct PyCellObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub ob_ref: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCell_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCell_Type")] pub static mut PyCell_Type: PyTypeObject; } #[inline(always)] pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyCell_Type) as c_int + (Py_TYPE(op) == &mut PyCell_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyCell_New(obj: *mut PyObject) -> *mut PyObject; pub fn PyCell_Get(op: *mut PyObject) -> *mut PyObject; pub fn PyCell_Set(op: *mut PyObject, obj: *mut PyObject) -> c_int; @@ -38,4 +40,4 @@ pub unsafe fn PyCell_GET(op: *mut PyObject) -> *mut PyObject { #[inline(always)] pub unsafe fn PyCell_SET(op: *mut PyObject, obj: *mut PyObject) { (*(op as *mut PyCellObject)).ob_ref = obj; -} \ No newline at end of file +} diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 9dc0cd66279..02b05c3ba85 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -1,44 +1,50 @@ -use std::os::raw::{c_void, c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::PyObject; use ffi2::frameobject::PyFrameObject; +use ffi2::object::PyObject; +use ffi2::pyport::Py_ssize_t; use ffi2::pystate::{PyThreadState, Py_tracefunc}; use ffi2::pythonrun::PyCompilerFlags; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyEval_CallObjectWithKeywords")] - pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject, - args: *mut PyObject, - kwds: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_CallFunction")] - pub fn PyEval_CallFunction(obj: *mut PyObject, - format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_CallMethod")] - pub fn PyEval_CallMethod(obj: *mut PyObject, - methodname: *const c_char, - format: *const c_char, ...) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_CallObjectWithKeywords")] + pub fn PyEval_CallObjectWithKeywords( + callable: *mut PyObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_CallFunction")] + pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_CallMethod")] + pub fn PyEval_CallMethod( + obj: *mut PyObject, + methodname: *const c_char, + format: *const c_char, + ... + ) -> *mut PyObject; pub fn PyEval_SetProfile(func: Option, obj: *mut PyObject); pub fn PyEval_SetTrace(func: Option, obj: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyEval_GetBuiltins")] + #[cfg_attr(PyPy, link_name = "PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_GetGlobals")] + #[cfg_attr(PyPy, link_name = "PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_GetLocals")] + #[cfg_attr(PyPy, link_name = "PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut PyFrameObject; pub fn PyEval_GetRestricted() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyEval_MergeCompilerFlags")] + #[cfg_attr(PyPy, link_name = "PyPyEval_MergeCompilerFlags")] pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int; pub fn Py_FlushLine() -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_AddPendingCall")] - pub fn Py_AddPendingCall(func: Option c_int>, - arg: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_MakePendingCalls")] + #[cfg_attr(PyPy, link_name = "PyPy_AddPendingCall")] + pub fn Py_AddPendingCall( + func: Option c_int>, + arg: *mut c_void, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_SetRecursionLimit")] + #[cfg_attr(PyPy, link_name = "PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int); - #[cfg_attr(PyPy, link_name="PyPy_GetRecursionLimit")] + #[cfg_attr(PyPy, link_name = "PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; @@ -47,26 +53,27 @@ use ffi2::pythonrun::PyCompilerFlags; 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; - #[cfg_attr(PyPy, link_name="PyPyEval_SaveThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyEval_RestoreThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState); - - #[cfg_attr(PyPy, link_name="_PyPyEval_SliceIndex")] + + #[cfg_attr(PyPy, link_name = "_PyPyEval_SliceIndex")] 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" { - #[cfg_attr(PyPy, link_name="PyPyEval_ThreadsInitialized")] +#[cfg(py_sys_config = "WITH_THREAD")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyEval_InitThreads")] + #[cfg_attr(PyPy, link_name = "PyPyEval_InitThreads")] pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); pub fn PyEval_ReleaseLock(); - #[cfg_attr(PyPy, link_name="PyPyEval_AcquireThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); - #[cfg_attr(PyPy, link_name="PyPyEval_ReleaseThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); -} \ No newline at end of file +} diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index 5caabf3c858..4120a983caf 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -1,13 +1,13 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyClassObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -23,9 +23,9 @@ pub struct PyClassObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PyInstanceObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -37,9 +37,9 @@ pub struct PyInstanceObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PyMethodObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -49,68 +49,76 @@ pub struct PyMethodObject { pub im_weakreflist: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyClass_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyClass_Type: PyTypeObject; // TODO: check why this symbol isn't exported by libpypy - #[cfg_attr(PyPy, link_name="PyPyClass_Type")] + #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyInstance_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyMethod_Type")] + #[cfg_attr(PyPy, link_name = "PyPyMethod_Type")] pub static mut PyMethod_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyClass_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyClass_Type; +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(always)] -pub unsafe fn PyInstance_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyInstance_Type; +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(always)] -#[cfg_attr(PyPy, link_name="PyPyMethod_Check")] -pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyMethod_Type; +#[cfg_attr(PyPy, link_name = "PyPyMethod_Check")] +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; - #[cfg_attr(PyPy, link_name="PyPyMethod_New")] - pub fn PyMethod_New(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMethod_Function")] +#[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; + #[cfg_attr(PyPy, link_name = "PyPyMethod_New")] + pub fn PyMethod_New( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMethod_Function")] pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMethod_Self")] + #[cfg_attr(PyPy, link_name = "PyPyMethod_Self")] pub fn PyMethod_Self(arg1: *mut PyObject) -> *mut PyObject; pub fn PyMethod_Class(arg1: *mut PyObject) -> *mut PyObject; - fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) - -> *mut PyObject; - pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) - -> c_int; + fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) -> *mut PyObject; + pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; pub fn PyMethod_ClearFreeList() -> c_int; } #[inline(always)] -pub unsafe fn PyMethod_GET_FUNCTION(meth : *mut PyObject) -> *mut PyObject { +pub unsafe fn PyMethod_GET_FUNCTION(meth: *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_func } #[inline(always)] -pub unsafe fn PyMethod_GET_SELF(meth : *mut PyObject) -> *mut PyObject { +pub unsafe fn PyMethod_GET_SELF(meth: *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_self } #[inline(always)] -pub unsafe fn PyMethod_GET_CLASS(meth : *mut PyObject) -> *mut PyObject { +pub unsafe fn PyMethod_GET_CLASS(meth: *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_class -} \ No newline at end of file +} diff --git a/src/ffi2/cobject.rs b/src/ffi2/cobject.rs index b75aefa7457..51ac29bea0b 100644 --- a/src/ffi2/cobject.rs +++ b/src/ffi2/cobject.rs @@ -1,34 +1,36 @@ -use std::os::raw::{c_void, c_char, c_int}; use ffi2::object::*; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCObject_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCObject_Type")] pub static mut PyCObject_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int { +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" { - #[cfg_attr(PyPy, link_name="PyPyCObject_FromVoidPtr")] - pub fn PyCObject_FromVoidPtr(cobj: *mut c_void, - destruct: Option) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCObject_FromVoidPtrAndDesc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtr")] + pub fn PyCObject_FromVoidPtr( + cobj: *mut c_void, + destruct: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtrAndDesc")] pub fn PyCObject_FromVoidPtrAndDesc( cobj: *mut c_void, desc: *mut c_void, - destruct: Option) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCObject_AsVoidPtr")] + destruct: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCObject_AsVoidPtr")] pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCObject_GetDesc")] + #[cfg_attr(PyPy, link_name = "PyPyCObject_GetDesc")] pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCObject_Import")] - pub fn PyCObject_Import(module_name: *mut c_char, - cobject_name: *mut c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCObject_SetVoidPtr")] + #[cfg_attr(PyPy, link_name = "PyPyCObject_Import")] + pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCObject_SetVoidPtr")] pub fn PyCObject_SetVoidPtr(_self: *mut PyObject, cobj: *mut c_void) -> c_int; -} \ No newline at end of file +} diff --git a/src/ffi2/code.rs b/src/ffi2/code.rs index f083169039d..69252c8a1e6 100644 --- a/src/ffi2/code.rs +++ b/src/ffi2/code.rs @@ -1,13 +1,13 @@ -use std::os::raw::{c_char, c_int, c_void}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_void}; #[repr(C)] #[derive(Copy, Clone)] pub struct PyCodeObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -30,61 +30,74 @@ pub struct PyCodeObject { } /* 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; +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_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_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; +pub const CO_MAXBLOCKS: usize = 20; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyCode_Type: PyTypeObject; - - #[cfg_attr(PyPy, link_name="PyPyCode_New")] - 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; - #[cfg_attr(PyPy, link_name="PyPyCode_NewEmpty")] - 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; - #[cfg_attr(PyPy, link_name="PyPyCode_Check")] + + #[cfg_attr(PyPy, link_name = "PyPyCode_New")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyCode_Check")] //fn _PyCode_CheckLineNumber(co: *mut PyCodeObject, // lasti: c_int, // bounds: *mut PyAddrPair) -> c_int; - pub fn PyCode_Optimize(code: *mut PyObject, consts: *mut PyObject, - names: *mut PyObject, lineno_obj: *mut PyObject) - -> *mut PyObject; + pub fn PyCode_Optimize( + code: *mut PyObject, + consts: *mut PyObject, + names: *mut PyObject, + lineno_obj: *mut PyObject, + ) -> *mut PyObject; } #[inline(always)] -pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCode_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name="PyPyCode_GetNumFree")] -pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { +#[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")] +pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { ::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) -} \ No newline at end of file +} diff --git a/src/ffi2/compile.rs b/src/ffi2/compile.rs index a136e8f5104..fe3acadab54 100644 --- a/src/ffi2/compile.rs +++ b/src/ffi2/compile.rs @@ -1,7 +1,7 @@ -use std::os::raw::{c_char, c_int}; -use ffi2::pythonrun::*; use ffi2::code::*; use ffi2::pyarena::PyArena; +use ffi2::pythonrun::*; +use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] @@ -10,20 +10,22 @@ pub struct PyFutureFeatures { 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"; +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; +#[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; } diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index 457836c0984..47c9fe2165a 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -1,15 +1,16 @@ -use std::os::raw::{c_double, c_int}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_double, c_int}; #[repr(C)] #[derive(Copy, Clone)] pub struct Py_complex { pub real: c_double, - pub imag: c_double + pub imag: c_double, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn _Py_c_sum(left: Py_complex, right: Py_complex) -> Py_complex; pub fn _Py_c_diff(left: Py_complex, right: Py_complex) -> Py_complex; pub fn _Py_c_neg(complex: Py_complex) -> Py_complex; @@ -22,49 +23,49 @@ pub struct Py_complex { #[repr(C)] #[derive(Copy, Clone)] pub struct PyComplexObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub cval: Py_complex, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyComplex_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyComplex_Check")] -pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyComplex_Check")] +pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyComplex_CheckExact")] -pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyComplex_Type; +#[cfg_attr(PyPy, link_name = "PyPyComplex_CheckExact")] +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" { - #[cfg_attr(PyPy, link_name="PyPyComplex_FromCComplex")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyComplex_FromDoubles")] - pub fn PyComplex_FromDoubles(real: c_double, - imag: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyComplex_RealAsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")] + pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="PyPyComplex_ImagAsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="PyPyComplex_AsCComplex")] + #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")] 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; -} \ No newline at end of file +//fn _PyComplex_FormatAdvanced(obj: *mut PyObject, +// format_spec: *mut c_char, +// format_spec_len: Py_ssize_t) +// -> *mut PyObject; +} diff --git a/src/ffi2/descrobject.rs b/src/ffi2/descrobject.rs index 998b934149e..521e7c6ac95 100644 --- a/src/ffi2/descrobject.rs +++ b/src/ffi2/descrobject.rs @@ -1,16 +1,13 @@ -use std::ptr; -use std::os::raw::{c_void, c_char, c_int}; +use ffi2::methodobject::PyMethodDef; use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; use ffi2::structmember::PyMemberDef; -use ffi2::methodobject::PyMethodDef; +use std::os::raw::{c_char, c_int, c_void}; +use std::ptr; -pub type getter = - unsafe extern "C" fn - (slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; +pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; pub type setter = - unsafe extern "C" fn (slf: *mut PyObject, value: *mut PyObject, - closure: *mut c_void) -> c_int; + unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int; #[repr(C)] #[derive(Copy)] @@ -22,7 +19,7 @@ pub struct PyGetSetDef { pub closure: *mut c_void, } -pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { +pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef { name: ptr::null_mut(), get: None, set: None, @@ -31,16 +28,24 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { }; impl Clone for PyGetSetDef { - #[inline] fn clone(&self) -> PyGetSetDef { *self } + #[inline] + fn clone(&self) -> PyGetSetDef { + *self + } } -pub type wrapperfunc = - unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject, - wrapped: *mut c_void) -> *mut PyObject; +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; +pub type wrapperfunc_kwds = unsafe extern "C" fn( + slf: *mut PyObject, + args: *mut PyObject, + wrapped: *mut c_void, + kwds: *mut PyObject, +) -> *mut PyObject; #[repr(C)] #[derive(Copy)] @@ -51,39 +56,42 @@ pub struct wrapperbase { pub wrapper: Option, pub doc: *mut c_char, pub flags: c_int, - pub name_strobj: *mut PyObject + pub name_strobj: *mut PyObject, } impl Clone for wrapperbase { - #[inline] fn clone(&self) -> wrapperbase { *self } + #[inline] + fn clone(&self) -> wrapperbase { + *self + } } -pub const PyWrapperFlag_KEYWORDS : c_int = 1; +pub const PyWrapperFlag_KEYWORDS: c_int = 1; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyWrapperDescr_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyDictProxy_Type")] + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyGetSetDescr_Type")] + #[cfg_attr(PyPy, link_name = "PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyMemberDescr_Type")] + #[cfg_attr(PyPy, link_name = "PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyProperty_Type")] + #[cfg_attr(PyPy, link_name = "PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; - pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDescr_NewClassMethod")] - 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; + pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDescr_NewClassMethod")] + 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(always)] @@ -91,10 +99,10 @@ pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int { (*Py_TYPE(d)).tp_descr_set.is_some() as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyDictProxy_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] //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; -} \ No newline at end of file + pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; +} diff --git a/src/ffi2/dictobject.rs b/src/ffi2/dictobject.rs index 0e5a05cf606..0375f9b6693 100644 --- a/src/ffi2/dictobject.rs +++ b/src/ffi2/dictobject.rs @@ -1,11 +1,12 @@ -use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; //pub enum PyDictObject { /* representation hidden */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyDict_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDict_Type")] pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -16,60 +17,61 @@ use ffi2::object::*; } #[inline(always)] -pub unsafe fn PyDict_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) } #[inline(always)] -pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyDict_Type; +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" { - #[cfg_attr(PyPy, link_name="PyPyDict_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDictProxy_New")] + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Clear")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyDict_Contains")] - pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_Copy")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Contains")] + pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; - - #[cfg_attr(PyPy, link_name="PyPyDict_GetItem")] - pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_SetItem")] - pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, - item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_DelItem")] - pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_GetItemString")] - pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_SetItemString")] - pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char, - item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_DelItemString")] - pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) - -> c_int; - - #[cfg_attr(PyPy, link_name="PyPyDict_Keys")] + + #[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")] + pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_SetItem")] + pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_DelItem")] + pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemString")] + pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_SetItemString")] + pub fn PyDict_SetItemString( + dp: *mut PyObject, + key: *const c_char, + item: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")] + pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; + + #[cfg_attr(PyPy, link_name = "PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Values")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Items")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Size")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyDict_Next")] - pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, - key: *mut *mut PyObject, value: *mut *mut PyObject) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Next")] + 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; @@ -77,13 +79,10 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { hash: c_long) -> c_int; pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/ - #[cfg_attr(PyPy, link_name="PyPyDict_Update")] - pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_Merge")] - 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; + #[cfg_attr(PyPy, link_name = "PyPyDict_Update")] + pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Merge")] + 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; -} \ No newline at end of file +} diff --git a/src/ffi2/enumobject.rs b/src/ffi2/enumobject.rs index 50424901292..a44bb6ef800 100644 --- a/src/ffi2/enumobject.rs +++ b/src/ffi2/enumobject.rs @@ -1,7 +1,7 @@ use ffi2::object::PyTypeObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyEnum_Type: PyTypeObject; pub static mut PyReversed_Type: PyTypeObject; } - diff --git a/src/ffi2/eval.rs b/src/ffi2/eval.rs index b5a980c3267..9972407e120 100644 --- a/src/ffi2/eval.rs +++ b/src/ffi2/eval.rs @@ -1,17 +1,26 @@ -use std::os::raw::c_int; -use ffi2::object::PyObject; use ffi2::code::PyCodeObject; +use ffi2::object::PyObject; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyEval_EvalCode")] - 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; -} \ No newline at end of file +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_EvalCode")] + 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; +} diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index 328b740defd..334183b326f 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -1,66 +1,69 @@ +use ffi2::object::*; use libc::{size_t, FILE}; use std::os::raw::{c_char, c_int}; -use ffi2::object::*; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyFile_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyFile_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyFile_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFile_Type) } #[inline(always)] -pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int { +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"; -pub const PY_STDIOTEXTMODE : &'static str = "b"; - -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFile_FromString")] - pub fn PyFile_FromString(arg1: *mut c_char, - arg2: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFile_SetBufSize")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFile_FromString")] + pub fn PyFile_FromString(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFile_SetBufSize")] 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; - #[cfg_attr(PyPy, link_name="PyPyFile_FromFile")] - pub fn PyFile_FromFile(arg1: *mut FILE, arg2: *mut c_char, - arg3: *mut c_char, - arg4: Option c_int>) - -> *mut PyObject; + pub fn PyFile_SetEncoding(arg1: *mut PyObject, arg2: *const c_char) -> c_int; + pub fn PyFile_SetEncodingAndErrors( + arg1: *mut PyObject, + arg2: *const c_char, + errors: *mut c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyFile_FromFile")] + pub fn PyFile_FromFile( + arg1: *mut FILE, + arg2: *mut c_char, + arg3: *mut c_char, + arg4: Option 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); - #[cfg_attr(PyPy, link_name="PyPyFile_Name")] + #[cfg_attr(PyPy, link_name = "PyPyFile_Name")] pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFile_GetLine")] - pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFile_WriteObject")] - 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; - #[cfg_attr(PyPy, link_name="PyPyFile_WriteString")] - pub fn PyFile_WriteString(arg1: *const c_char, - arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_AsFileDescriptor")] + #[cfg_attr(PyPy, link_name = "PyPyFile_GetLine")] + pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFile_WriteObject")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyFile_WriteString")] + pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsFileDescriptor")] pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int; - pub fn Py_UniversalNewlineFgets(arg1: *mut c_char, - arg2: c_int, arg3: *mut FILE, - arg4: *mut PyObject) - -> *mut c_char; - pub fn Py_UniversalNewlineFread(arg1: *mut c_char, arg2: size_t, - arg3: *mut FILE, arg4: *mut PyObject) - -> size_t; + pub fn Py_UniversalNewlineFgets( + arg1: *mut c_char, + arg2: c_int, + arg3: *mut FILE, + arg4: *mut PyObject, + ) -> *mut c_char; + pub fn Py_UniversalNewlineFread( + arg1: *mut c_char, + arg2: size_t, + arg3: *mut FILE, + arg4: *mut PyObject, + ) -> size_t; pub static mut Py_FileSystemDefaultEncoding: *const c_char; -} \ No newline at end of file +} diff --git a/src/ffi2/floatobject.rs b/src/ffi2/floatobject.rs index ad5c4ab7ae4..d1e34471a31 100644 --- a/src/ffi2/floatobject.rs +++ b/src/ffi2/floatobject.rs @@ -1,47 +1,47 @@ -use std::os::raw::{c_char, c_int, c_double}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_double, c_int}; #[repr(C)] #[derive(Copy, Clone)] struct PyFloatObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub ob_fval: c_double, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFloat_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyFloat_Check")] -pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyFloat_Check")] +pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyFloat_CheckExact")] -pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyFloat_Type; +#[cfg_attr(PyPy, link_name = "PyPyFloat_CheckExact")] +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; +pub const PyFloat_STR_PRECISION: c_int = 12; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFloat_FromString")] - pub fn PyFloat_FromString(str: *mut PyObject, - pend: *mut *mut c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFloat_FromDouble")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFloat_FromString")] + pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFloat_AsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; @@ -50,7 +50,7 @@ pub const PyFloat_STR_PRECISION : c_int = 12; pub fn PyFloat_ClearFreeList() -> c_int; } -#[cfg_attr(PyPy, link_name="PyPyFloat_AS_DOUBLE")] +#[cfg_attr(PyPy, link_name = "PyPyFloat_AS_DOUBLE")] pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double { (*(pyfloat as *mut PyFloatObject)).ob_fval -} \ No newline at end of file +} diff --git a/src/ffi2/frameobject.rs b/src/ffi2/frameobject.rs index fd361a8589c..9cbf193b9e3 100644 --- a/src/ffi2/frameobject.rs +++ b/src/ffi2/frameobject.rs @@ -1,38 +1,38 @@ -use std::os::raw::c_int; +use ffi2::code::{PyCodeObject, CO_MAXBLOCKS}; use ffi2::object::*; use ffi2::pyport::Py_ssize_t; -use ffi2::code::{PyCodeObject, CO_MAXBLOCKS}; use ffi2::pystate::PyThreadState; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTryBlock { - pub b_type : c_int, - pub b_handler : c_int, - pub b_level : c_int, + 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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 */ + 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. */ + 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_trace: *mut PyObject, /* Trace function */ pub f_exc_type: *mut PyObject, pub f_exc_value: *mut PyObject, @@ -40,25 +40,26 @@ pub struct PyFrameObject { pub f_tstate: *mut PyThreadState, - pub f_lasti: c_int, /* Last instruction if called */ + 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 */ + 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 */ + pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyFrame_Type: PyTypeObject; } #[inline] pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { - ((*op).ob_type == &mut PyFrame_Type) as c_int + ((*op).ob_type == &mut PyFrame_Type) as c_int } //#[inline] @@ -66,17 +67,27 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { // ((*f).f_builtins != (*(*(*f).f_tstate).interp).builtins) as c_int //} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFrame_New")] - pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, - globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFrame_New")] + pub fn PyFrame_New( + tstate: *mut PyThreadState, + code: *mut PyCodeObject, + globals: *mut PyObject, + locals: *mut PyObject, + ) -> *mut PyFrameObject; - pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int) -> (); + pub fn PyFrame_BlockSetup( + f: *mut PyFrameObject, + _type: c_int, + handler: c_int, + level: c_int, + ) -> (); pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock; pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> (); pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> (); - + pub fn PyFrame_ClearFreeList() -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; } diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index c5dc7b2b15b..ee0b17c16fe 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -1,39 +1,37 @@ -use std::os::raw::c_int; use ffi2::object::*; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFunction_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFunction_Type")] pub static mut PyFunction_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyFunction_Check")] -pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyFunction_Type; +#[cfg_attr(PyPy, link_name = "PyPyFunction_Check")] +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; - #[cfg_attr(PyPy, link_name="PyPyFunction_GetCode")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFunction_GetCode")] pub fn PyFunction_GetCode(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetGlobals(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetModule(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetDefaults(f: *mut PyObject) -> *mut PyObject; - pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) - -> c_int; + pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) -> c_int; pub fn PyFunction_GetClosure(f: *mut PyObject) -> *mut PyObject; - pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) - -> c_int; - + pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) -> c_int; + pub static mut PyClassMethod_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyStaticMethod_Type")] + #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_Type")] pub static mut PyStaticMethod_Type: PyTypeObject; - - #[cfg_attr(PyPy, link_name="PyPyClassMethod_New")] + + #[cfg_attr(PyPy, link_name = "PyPyClassMethod_New")] pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyStaticMethod_New")] + #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_New")] pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; -} \ No newline at end of file +} diff --git a/src/ffi2/genobject.rs b/src/ffi2/genobject.rs index ded528accb6..d93ce210629 100644 --- a/src/ffi2/genobject.rs +++ b/src/ffi2/genobject.rs @@ -1,40 +1,42 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; use ffi2::frameobject::PyFrameObject; +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyGenObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub gi_weakreflist: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyGen_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyGen_Check")] +#[cfg_attr(PyPy, link_name = "PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { - PyObject_TypeCheck(op, &mut PyGen_Type) + PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyGen_CheckExact")] +#[cfg_attr(PyPy, link_name = "PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyGen_Type) as c_int + (Py_TYPE(op) == &mut PyGen_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject; pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int; -} \ No newline at end of file +} diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index eaf8a0e2694..3d1593a334d 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -1,5 +1,5 @@ -use std::os::raw::{c_char, c_uchar, c_int, c_long}; use ffi2::object::*; +use std::os::raw::{c_char, c_int, c_long, c_uchar}; #[repr(C)] #[derive(Copy)] @@ -9,7 +9,10 @@ pub struct PyImport_Struct_inittab { } impl Clone for PyImport_Struct_inittab { - #[inline] fn clone(&self) -> PyImport_Struct_inittab { *self } + #[inline] + fn clone(&self) -> PyImport_Struct_inittab { + *self + } } #[repr(C)] @@ -21,74 +24,75 @@ pub struct PyImport_Struct_frozen { } #[inline] -pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, - globals: *mut PyObject, - locals: *mut PyObject, - fromlist: *mut PyObject) -> *mut PyObject { +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" { - #[cfg_attr(PyPy, link_name="PyPyImport_ImportModule")] - pub fn PyImport_ImportModule(name: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleNoBlock")] - 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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")] + pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")] + 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; - #[cfg_attr(PyPy, link_name="PyPyImport_ReloadModule")] + #[cfg_attr(PyPy, link_name = "PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_AddModule")] + #[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModule")] - pub fn PyImport_ExecCodeModule(name: *mut c_char, - co: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModuleEx")] - pub fn PyImport_ExecCodeModuleEx(name: *mut c_char, - co: *mut PyObject, - pathname: *mut c_char) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModule")] + pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModuleEx")] + 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; - #[cfg_attr(PyPy, link_name="PyPyImport_GetModuleDict")] + #[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")] 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) - -> c_int; - pub fn PyImport_ExtendInittab(newtab: *mut PyImport_Struct_inittab) - -> c_int; - + pub fn PyImport_ImportFrozenModule(name: *mut c_char) -> c_int; + + pub fn PyImport_AppendInittab( + name: *const c_char, + initfunc: Option, + ) -> 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(); - #[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_AcquireLock")] - pub fn _PyImport_AcquireLock(); - #[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_ReleaseLock")] - 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;*/ -} \ No newline at end of file + +/*for internal use only: +pub fn PyImport_Cleanup(); +#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_AcquireLock")] +pub fn _PyImport_AcquireLock(); +#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_ReleaseLock")] +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;*/ +} diff --git a/src/ffi2/intobject.rs b/src/ffi2/intobject.rs index 1cb26f646ef..254611328f4 100644 --- a/src/ffi2/intobject.rs +++ b/src/ffi2/intobject.rs @@ -1,43 +1,46 @@ +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; use libc::size_t; use std::os::raw::{c_char, c_int, c_long, c_ulong, c_ulonglong}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyIntObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub ob_ival: c_long, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyInt_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyInt_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyInt_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS) } #[inline(always)] -pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyInt_Type; +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 ::ffi2::unicodeobject::Py_UNICODE, - length: Py_ssize_t, - base: c_int) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyInt_FromString(str: *mut c_char, pend: *mut *mut c_char, base: c_int) + -> *mut PyObject; + #[cfg(py_sys_config = "Py_USING_UNICODE")] + pub fn PyInt_FromUnicode( + u: *mut ::ffi2::unicodeobject::Py_UNICODE, + 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; @@ -45,8 +48,7 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { pub fn PyInt_AsSsize_t(io: *mut PyObject) -> Py_ssize_t; fn _PyInt_AsInt(io: *mut PyObject) -> c_int; pub fn PyInt_AsUnsignedLongMask(io: *mut PyObject) -> c_ulong; - pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) - -> c_ulonglong; + pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) -> c_ulonglong; pub fn PyInt_GetMax() -> c_long; //fn PyOS_strtoul(arg1: *mut c_char, // arg2: *mut *mut c_char, arg3: c_int) @@ -55,15 +57,14 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { // 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; +//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 } - diff --git a/src/ffi2/iterobject.rs b/src/ffi2/iterobject.rs index 86f0a8a43e9..81c1e315f4a 100644 --- a/src/ffi2/iterobject.rs +++ b/src/ffi2/iterobject.rs @@ -1,15 +1,15 @@ -use std::os::raw::c_int; use ffi2::object::*; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPySeqIter_New")] + #[cfg_attr(PyPy, link_name = "PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCallIter_New")] - pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCallIter_New")] + pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } #[inline(always)] @@ -20,4 +20,4 @@ pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int { #[inline(always)] pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCallIter_Type) as c_int -} \ No newline at end of file +} diff --git a/src/ffi2/listobject.rs b/src/ffi2/listobject.rs index 96661ec1db1..85df94a6c82 100644 --- a/src/ffi2/listobject.rs +++ b/src/ffi2/listobject.rs @@ -1,13 +1,13 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyListObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -16,73 +16,73 @@ pub struct PyListObject { pub allocated: Py_ssize_t, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyList_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyList_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyList_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) } #[inline(always)] -pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyList_Type; +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(always)] -#[cfg_attr(PyPy, link_name="PyPyList_GET_ITEM")] +#[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] 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) + *(*(op as *mut PyListObject)).ob_item.offset(i as isize) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyList_GET_SIZE")] +#[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] 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(always)] -#[cfg_attr(PyPy, link_name="PyPyList_SET_ITEM")] +#[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")] 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; + *(*(op as *mut PyListObject)).ob_item.offset(i as isize) = v; } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyList_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyList_Size")] + #[cfg_attr(PyPy, link_name = "PyPyList_Size")] pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyList_GetItem")] - pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyList_SetItem")] - pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, - item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Insert")] - pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, - item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Append")] - pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_GetSlice")] - pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, - high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyList_SetSlice")] - pub fn PyList_SetSlice(list: *mut PyObject, low: Py_ssize_t, - high: Py_ssize_t, itemlist: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Sort")] + #[cfg_attr(PyPy, link_name = "PyPyList_GetItem")] + pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyList_SetItem")] + pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Insert")] + pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Append")] + pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_GetSlice")] + pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) + -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyList_SetSlice")] + pub fn PyList_SetSlice( + list: *mut PyObject, + low: Py_ssize_t, + high: Py_ssize_t, + itemlist: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Sort")] pub fn PyList_Sort(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Reverse")] + #[cfg_attr(PyPy, link_name = "PyPyList_Reverse")] pub fn PyList_Reverse(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_AsTuple")] + #[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")] pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject; - //fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) - //-> *mut PyObject; -} \ No newline at end of file +//fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) +//-> *mut PyObject; +} diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 26f82fc08fa..127675e3090 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -1,107 +1,106 @@ -use std::os::raw::{c_void, c_char, c_int, c_long, c_ulong, c_longlong, c_ulonglong, c_double}; -use libc::size_t; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use libc::size_t; +use std::os::raw::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_void}; //enum PyLongObject { /* representation hidden */ } - -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyLong_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyLong_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyLong_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) } #[inline(always)] -pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyLong_Type; +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" { - #[cfg_attr(PyPy, link_name="PyPyLong_FromLong")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyLong_FromLong")] pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromSsize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromSize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromLongLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLongLong")] - pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromDouble")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLongLong")] + pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromDouble")] pub fn PyLong_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromString")] - 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")] - #[cfg_attr(PyPy, link_name="PyPyLong_FromUnicode")] - pub fn PyLong_FromUnicode(u: *mut ::ffi2::unicodeobject::Py_UNICODE, - length: Py_ssize_t, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromVoidPtr")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromString")] + 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")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnicode")] + pub fn PyLong_FromUnicode( + u: *mut ::ffi2::unicodeobject::Py_UNICODE, + length: Py_ssize_t, + base: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject; - - #[cfg_attr(PyPy, link_name="PyPyLong_AsLong")] + + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLong")] pub fn PyLong_AsLong(pylong: *mut PyObject) -> c_long; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLongAndOverflow")] - pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, - overflow: *mut c_int) - -> c_long; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLongAndOverflow")] - pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, - overflow: *mut c_int) - -> c_longlong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsSsize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongAndOverflow")] + pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLongAndOverflow")] + pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLong")] - pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) - -> c_ulonglong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongMask")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLong")] + pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLongMask")] - pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) - -> c_ulonglong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLongMask")] + pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsDouble")] pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="PyPyLong_AsVoidPtr")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void; - + pub fn PyLong_GetInfo() -> *mut PyObject; - - /* - pub fn _PyLong_AsInt(arg1: *mut PyObject) -> c_int; - pub fn _PyLong_Frexp(a: *mut PyLongObject, e: *mut Py_ssize_t) - -> c_double; - - #[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_Sign")] - pub fn _PyLong_Sign(v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_NumBits")] - pub fn _PyLong_NumBits(v: *mut PyObject) -> size_t; - #[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_FromByteArray")] - 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: *mut c_uchar, n: size_t, - little_endian: c_int, - is_signed: c_int) -> c_int; - pub fn _PyLong_Format(aa: *mut PyObject, base: c_int, - addL: c_int, newstyle: c_int) - -> *mut PyObject; - pub fn _PyLong_FormatAdvanced(obj: *mut PyObject, - format_spec: *mut c_char, - format_spec_len: Py_ssize_t) - -> *mut PyObject;*/ -} \ No newline at end of file + +/* +pub fn _PyLong_AsInt(arg1: *mut PyObject) -> c_int; +pub fn _PyLong_Frexp(a: *mut PyLongObject, e: *mut Py_ssize_t) + -> c_double; + +#[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_Sign")] +pub fn _PyLong_Sign(v: *mut PyObject) -> c_int; +#[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_NumBits")] +pub fn _PyLong_NumBits(v: *mut PyObject) -> size_t; +#[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_FromByteArray")] +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: *mut c_uchar, n: size_t, + little_endian: c_int, + is_signed: c_int) -> c_int; +pub fn _PyLong_Format(aa: *mut PyObject, base: c_int, + addL: c_int, newstyle: c_int) + -> *mut PyObject; +pub fn _PyLong_FormatAdvanced(obj: *mut PyObject, + format_spec: *mut c_char, + format_spec_len: Py_ssize_t) + -> *mut PyObject;*/ +} diff --git a/src/ffi2/memoryobject.rs b/src/ffi2/memoryobject.rs index de58612c151..1027f1c822b 100644 --- a/src/ffi2/memoryobject.rs +++ b/src/ffi2/memoryobject.rs @@ -1,49 +1,52 @@ -use std::os::raw::{c_int, c_char}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMemoryView_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyMemoryView_Check")] -pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyMemoryView_Type; +#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Check")] +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(always)] -pub unsafe fn PyMemoryView_GET_BUFFER(op : *mut PyObject) -> *mut Py_buffer { +pub unsafe fn PyMemoryView_GET_BUFFER(op: *mut PyObject) -> *mut Py_buffer { &mut (*(op as *mut PyMemoryViewObject)).view } #[inline(always)] -pub unsafe fn PyMemoryView_GET_BASE(op : *mut PyObject) -> *mut PyObject { +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; - #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyMemoryView_GetContiguous( + base: *mut PyObject, + buffertype: c_int, + fort: c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromBuffer")] + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromBuffer")] 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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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, -} \ No newline at end of file +} diff --git a/src/ffi2/methodobject.rs b/src/ffi2/methodobject.rs index 3b991374c70..027a1950a32 100644 --- a/src/ffi2/methodobject.rs +++ b/src/ffi2/methodobject.rs @@ -1,39 +1,40 @@ -use std::ptr; -use std::os::raw::{c_char, c_int}; use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; +use std::os::raw::{c_char, c_int}; +use std::ptr; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCFunction_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyCFunction_Check")] -pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyCFunction_Type; +#[cfg_attr(PyPy, link_name = "PyPyCFunction_Check")] +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" { - #[cfg_attr(PyPy, link_name="PyPyCFunction_GetFunction")] + 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" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; - pub fn PyCFunction_Call(f: *mut PyObject, args: *mut PyObject, - kwds: *mut PyObject) -> *mut PyObject; + pub fn PyCFunction_Call( + f: *mut PyObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; } #[repr(C)] @@ -45,7 +46,7 @@ pub struct PyMethodDef { pub ml_doc: *const c_char, } -pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { +pub const PyMethodDef_INIT: PyMethodDef = PyMethodDef { ml_name: ::std::ptr::null(), ml_meth: None, ml_flags: 0, @@ -53,30 +54,32 @@ pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { }; impl Clone for PyMethodDef { - #[inline] fn clone(&self) -> PyMethodDef { *self } + #[inline] + fn clone(&self) -> PyMethodDef { + *self + } } /* Flag passed to newmethodobject */ -pub const METH_OLDARGS : c_int = 0x0000; -pub const METH_VARARGS : c_int = 0x0001; -pub const METH_KEYWORDS : c_int = 0x0002; +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; +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; +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; +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)] @@ -101,19 +104,29 @@ struct PyCFunctionObject { } */ -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPy_FindMethod")] - pub fn Py_FindMethod(methods: *mut PyMethodDef, slf: *mut PyObject, - name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCFunction_NewEx")] - pub fn PyCFunction_NewEx(ml: *mut PyMethodDef, slf: *mut PyObject, - module: *mut PyObject) -> *mut PyObject; - pub fn Py_FindMethodInChain(chain: *mut PyMethodChain, slf: *mut PyObject, - name: *const c_char) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPy_FindMethod")] + pub fn Py_FindMethod( + methods: *mut PyMethodDef, + slf: *mut PyObject, + name: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")] + 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(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { PyCFunction_NewEx(ml, slf, ptr::null_mut()) -} \ No newline at end of file +} diff --git a/src/ffi2/mod.rs b/src/ffi2/mod.rs index 2b9c627f475..0aa335a7d3d 100644 --- a/src/ffi2/mod.rs +++ b/src/ffi2/mod.rs @@ -5,95 +5,95 @@ use std::os::raw::c_int; -pub use self::pyport::*; -pub use self::pymem::*; -pub use self::object::*; -pub use self::objimpl::*; -pub use self::pydebug::*; -#[cfg(py_sys_config="Py_USING_UNICODE")] -pub use self::unicodeobject::*; -pub use self::intobject::*; pub use self::boolobject::*; -pub use self::longobject::*; -pub use self::floatobject::*; -pub use self::complexobject::*; -pub use self::rangeobject::*; -pub use self::memoryobject::*; pub use self::bufferobject::*; -pub use self::stringobject::*; -pub use self::bytesobject::*; pub use self::bytearrayobject::*; -pub use self::tupleobject::*; -pub use self::listobject::*; +pub use self::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::setobject::*; -pub use self::pyerrors::*; -pub use self::pystate::*; -pub use self::pystate::PyGILState_STATE::*; +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::funcobject::*; -pub use self::classobject::*; -pub use self::fileobject::*; -pub use self::cobject::*; +pub use self::object::*; +pub use self::objectabstract::*; +pub use self::objimpl::*; +pub use self::pyarena::*; pub use self::pycapsule::*; -pub use self::traceback::*; +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::cellobject::*; -pub use self::iterobject::*; -pub use self::genobject::*; -pub use self::descrobject::*; +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::*; -pub use self::pyarena::*; -pub use self::modsupport::*; -pub use self::pythonrun::*; -pub use self::ceval::*; -pub use self::import::*; -pub use self::objectabstract::*; -pub use self::code::*; -pub use self::compile::*; -pub use self::eval::*; -pub use self::structmember::PyMemberDef; -pub use self::frameobject::PyFrameObject; -mod pyport; -mod pymem; -mod object; -mod objimpl; -mod pydebug; -#[cfg(py_sys_config="Py_USING_UNICODE")] -mod unicodeobject; // TODO: incomplete -mod intobject; mod boolobject; -mod longobject; -mod floatobject; -mod complexobject; -mod rangeobject; -mod stringobject; -mod memoryobject; mod bufferobject; -mod bytesobject; mod bytearrayobject; -mod tupleobject; -mod listobject; +mod bytesobject; +mod cellobject; +mod classobject; +mod cobject; +mod complexobject; +mod descrobject; mod dictobject; mod enumobject; -mod setobject; +mod fileobject; +mod floatobject; +mod funcobject; +mod genobject; +mod intobject; +mod iterobject; +mod listobject; +mod longobject; +mod memoryobject; mod methodobject; mod moduleobject; -mod funcobject; -mod classobject; -mod fileobject; -mod cobject; +mod object; +mod objimpl; mod pycapsule; -mod traceback; +mod pydebug; +mod pymem; +mod pyport; +mod rangeobject; +mod setobject; mod sliceobject; -mod cellobject; -mod iterobject; -mod genobject; -mod descrobject; +mod stringobject; +mod traceback; +mod tupleobject; +#[cfg(py_sys_config = "Py_USING_UNICODE")] +mod unicodeobject; // TODO: incomplete mod warnings; mod weakrefobject; @@ -102,10 +102,10 @@ mod pyerrors; mod pystate; -mod pyarena; +mod ceval; mod modsupport; +mod pyarena; mod pythonrun; -mod ceval; // mod sysmodule; // TODO: incomplete // mod intrcheck; // TODO: incomplete mod import; @@ -124,19 +124,23 @@ mod eval; // mod pyfpe; // TODO: incomplete // Additional headers that are not exported by Python.h -pub mod structmember; pub mod frameobject; +pub mod structmember; pub const Py_single_input: c_int = 256; pub const Py_file_input: c_int = 257; pub const Py_eval_input: c_int = 258; -#[cfg(not(py_sys_config="Py_USING_UNICODE"))] +#[cfg(not(py_sys_config = "Py_USING_UNICODE"))] #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyUnicode_Check")] -pub fn PyUnicode_Check(op : *mut PyObject) -> libc::c_int { 0 } +#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] +pub fn PyUnicode_Check(op: *mut PyObject) -> libc::c_int { + 0 +} -#[cfg(not(py_sys_config="Py_USING_UNICODE"))] +#[cfg(not(py_sys_config = "Py_USING_UNICODE"))] #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyUnicode_CheckExact")] -pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 } \ No newline at end of file +#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] +pub fn PyUnicode_CheckExact(op: *mut PyObject) -> libc::c_int { + 0 +} diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index 05212aba0b7..e062205e130 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -1,105 +1,150 @@ -use std::ptr; -use std::os::raw::{c_char, c_int, c_long}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::PyObject; use ffi2::methodobject::PyMethodDef; +use ffi2::object::PyObject; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_long}; +use std::ptr; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyArg_Parse")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyArg_Parse")] pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyArg_ParseTuple")] - pub fn PyArg_ParseTuple(args: *mut PyObject, - format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyArg_ParseTupleAndKeywords")] - pub fn PyArg_ParseTupleAndKeywords(args: *mut PyObject, - kw: *mut PyObject, - format: *const c_char, - keywords: *mut *mut c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyArg_UnpackTuple")] - pub fn PyArg_UnpackTuple(args: *mut PyObject, name: *const c_char, - min: Py_ssize_t, max: Py_ssize_t, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_BuildValue")] + #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTuple")] + pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTupleAndKeywords")] + pub fn PyArg_ParseTupleAndKeywords( + args: *mut PyObject, + kw: *mut PyObject, + format: *const c_char, + keywords: *mut *mut c_char, + ... + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyArg_UnpackTuple")] + pub fn PyArg_UnpackTuple( + args: *mut PyObject, + name: *const c_char, + min: Py_ssize_t, + max: Py_ssize_t, + ... + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_BuildValue")] pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPy_BuildValue_SizeT")] + #[cfg_attr(PyPy, link_name = "_PyPy_BuildValue_SizeT")] //fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyArg_NoKeywords")] + #[cfg_attr(PyPy, link_name = "_PyPyArg_NoKeywords")] //fn _PyArg_NoKeywords(funcname: *const c_char, // kw: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyModule_AddObject")] - pub fn PyModule_AddObject(module: *mut PyObject, - name: *const c_char, - value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyModule_AddIntConstant")] - pub fn PyModule_AddIntConstant(module: *mut PyObject, - name: *const c_char, - value: c_long) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyModule_AddStringConstant")] - pub fn PyModule_AddStringConstant(module: *mut PyObject, - name: *const c_char, - value: *const c_char) -> c_int; - + #[cfg_attr(PyPy, link_name = "PyPyModule_AddObject")] + pub fn PyModule_AddObject( + module: *mut PyObject, + name: *const c_char, + value: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddIntConstant")] + pub fn PyModule_AddIntConstant( + module: *mut PyObject, + name: *const c_char, + value: c_long, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddStringConstant")] + 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")))] - #[cfg_attr(PyPy, link_name="_PyPy_InitPyPyModule")] - fn Py_InitModule4_64(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPy_InitPyPyModule")] + 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; + 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; + 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; + 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; +pub const PYTHON_API_VERSION: c_int = 1013; #[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))] #[inline(always)] -pub unsafe fn Py_InitModule4(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject { +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(always)] -pub unsafe fn Py_InitModule4(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject { +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(always)] -pub unsafe fn Py_InitModule4(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject { +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(always)] pub unsafe fn Py_InitModule(name: *const c_char, methods: *mut PyMethodDef) -> *mut PyObject { - Py_InitModule4(name, methods, ptr::null(), ptr::null_mut(), PYTHON_API_VERSION) + Py_InitModule4( + name, + methods, + ptr::null(), + ptr::null_mut(), + PYTHON_API_VERSION, + ) } #[inline(always)] -pub unsafe fn Py_InitModule3(name: *const c_char, methods: *mut PyMethodDef, doc : *const c_char) -> *mut PyObject { +pub unsafe fn Py_InitModule3( + name: *const c_char, + methods: *mut PyMethodDef, + doc: *const c_char, +) -> *mut PyObject { Py_InitModule4(name, methods, doc, ptr::null_mut(), PYTHON_API_VERSION) -} \ No newline at end of file +} diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index a802c82fab1..05c9ab0ab78 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -1,28 +1,30 @@ -use std::os::raw::{c_char, c_int, c_void}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; use ffi2::methodobject::PyMethodDef; +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyModule_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyModule_Check")] -pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyModule_Check")] +pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } #[inline(always)] -pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyModule_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyModule_GetDict")] + #[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")] 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; @@ -43,14 +45,16 @@ pub struct PyModuleDef_Base { pub m_copy: *mut PyObject, } impl Clone for PyModuleDef_Base { - fn clone(&self) -> PyModuleDef_Base { *self } + fn clone(&self) -> PyModuleDef_Base { + *self + } } pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base { ob_base: PyObject_HEAD_INIT, m_init: None, m_index: 0, - m_copy: ::std::ptr::null_mut() + m_copy: ::std::ptr::null_mut(), }; #[repr(C)] @@ -60,11 +64,13 @@ pub struct PyModuleDef_Slot { pub value: *mut c_void, } impl Clone for PyModuleDef_Slot { - fn clone(&self) -> PyModuleDef_Slot { *self } + fn clone(&self) -> PyModuleDef_Slot { + *self + } } -pub const Py_mod_create : c_int = 1; -pub const Py_mod_exec : c_int = 2; +pub const Py_mod_create: c_int = 1; +pub const Py_mod_exec: c_int = 2; #[repr(C)] #[derive(Copy)] @@ -80,7 +86,9 @@ pub struct PyModuleDef { pub m_free: Option, } impl Clone for PyModuleDef { - fn clone(&self) -> PyModuleDef { *self } + fn clone(&self) -> PyModuleDef { + *self + } } pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { @@ -92,5 +100,5 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { m_slots: ::std::ptr::null_mut(), m_traverse: None, m_clear: None, - m_free: None -}; \ No newline at end of file + m_free: None, +}; diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 7d11584d8b3..20ff3c53184 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -1,9 +1,9 @@ -use std::ptr; -use std::os::raw::{c_void, c_int, c_uint, c_long, c_char, c_double}; -use libc::FILE; use ffi2; -use ffi2::pyport::{Py_ssize_t, Py_hash_t}; use ffi2::methodobject::PyMethodDef; +use ffi2::pyport::{Py_hash_t, Py_ssize_t}; +use libc::FILE; +use std::os::raw::{c_char, c_double, c_int, c_long, c_uint, c_void}; +use std::ptr; #[repr(C)] #[derive(Copy, Clone, Debug)] @@ -82,60 +82,64 @@ pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t { (*(ob as *mut PyVarObject)).ob_size } -pub type unaryfunc = -unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +pub type unaryfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type binaryfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; -pub type ternaryfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; -pub type inquiry = -unsafe extern "C" fn(arg1: *mut PyObject) -> c_int; -pub type lenfunc = -unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *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; + 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; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub type ssizessizeargfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t) -> *mut PyObject; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; pub type intobjargproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut PyObject) -> c_int; -pub type intintobjargproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, - arg3: c_int, arg4: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *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; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; +pub type ssizessizeobjargproc = unsafe extern "C" fn( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: Py_ssize_t, + arg4: *mut PyObject, +) -> c_int; pub type objobjargproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; pub type getreadbufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, - arg3: *mut *mut c_void) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int; pub type getwritebufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, - arg3: *mut *mut c_void) -> c_int; -pub type getsegcountproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_int) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int; +pub type getsegcountproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_int) -> c_int; pub type getcharbufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_char) -> c_int; -pub type readbufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_void) -> Py_ssize_t; -pub type writebufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_void) -> Py_ssize_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: 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; + 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)] @@ -155,10 +159,8 @@ pub struct Py_buffer { } pub type getbufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer, - arg3: c_int) -> c_int; -pub type releasebufferproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer); + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer, arg3: c_int) -> c_int; +pub type releasebufferproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer); // flags: pub const PyBUF_SIMPLE: c_int = 0; @@ -188,14 +190,10 @@ pub const PyBUF_READ: c_int = 0x100; pub const PyBUF_WRITE: c_int = 0x200; pub const PyBUF_SHADOW: c_int = 0x400; - -pub type objobjproc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type visitproc = -unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int; +pub type objobjproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type visitproc = unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int; pub type traverseproc = -unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; - + unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; #[repr(C)] #[derive(Copy)] @@ -243,7 +241,9 @@ pub struct PyNumberMethods { impl Clone for PyNumberMethods { #[inline] - fn clone(&self) -> PyNumberMethods { *self } + fn clone(&self) -> PyNumberMethods { + *self + } } pub const PyNumberMethods_INIT: PyNumberMethods = PyNumberMethods { @@ -305,7 +305,9 @@ pub struct PySequenceMethods { impl Clone for PySequenceMethods { #[inline] - fn clone(&self) -> PySequenceMethods { *self } + fn clone(&self) -> PySequenceMethods { + *self + } } pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods { @@ -331,7 +333,9 @@ pub struct PyMappingMethods { impl Clone for PyMappingMethods { #[inline] - fn clone(&self) -> PyMappingMethods { *self } + fn clone(&self) -> PyMappingMethods { + *self + } } pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods { @@ -353,7 +357,9 @@ pub struct PyBufferProcs { impl Clone for PyBufferProcs { #[inline] - fn clone(&self) -> PyBufferProcs { *self } + fn clone(&self) -> PyBufferProcs { + *self + } } pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { @@ -365,49 +371,41 @@ pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { bf_releasebuffer: None, }; -pub type freefunc = -unsafe extern "C" fn(arg1: *mut c_void); -pub type destructor = -unsafe extern "C" fn(arg1: *mut PyObject); +pub type freefunc = unsafe extern "C" fn(arg1: *mut c_void); +pub type destructor = unsafe extern "C" fn(arg1: *mut PyObject); pub type printfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut FILE, arg3: c_int) -> c_int; + 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; + 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; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub type setattrfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, arg3: *mut PyObject) -> c_int; pub type setattrofunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; -pub type cmpfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type reprfunc = -unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type hashfunc = -unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; +pub type cmpfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type reprfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +pub type hashfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; pub type richcmpfunc = -unsafe extern "C" fn(arg1: *mut PyObject, - arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; -pub type getiterfunc = -unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type iternextfunc = -unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type descrgetfunc = -unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: 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; + 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; + 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; + unsafe extern "C" fn(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject; #[repr(C)] #[derive(Copy)] @@ -465,7 +463,9 @@ pub struct PyTypeObject { impl Clone for PyTypeObject { #[inline] - fn clone(&self) -> PyTypeObject { *self } + fn clone(&self) -> PyTypeObject { + *self + } } #[cfg(py_sys_config = "Py_TRACE_REFS")] @@ -590,12 +590,16 @@ pub struct PyHeapTypeObject { impl Clone for PyHeapTypeObject { #[inline] - fn clone(&self) -> PyHeapTypeObject { *self } + fn clone(&self) -> PyHeapTypeObject { + *self + } } // access macro to the members which are floating "behind" the object #[inline] -pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2::structmember::PyMemberDef { +pub unsafe fn PyHeapType_GET_MEMBERS( + etype: *mut PyHeapTypeObject, +) -> *mut ffi2::structmember::PyMemberDef { let basicsize = (*Py_TYPE(etype as *mut PyObject)).tp_basicsize; (etype as *mut u8).offset(basicsize as isize) as *mut ffi2::structmember::PyMemberDef } @@ -612,9 +616,9 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyType_Type")] + #[cfg_attr(PyPy, link_name = "PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyBaseObject_Type")] + #[cfg_attr(PyPy, link_name = "PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; } @@ -631,34 +635,38 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyType_Ready")] + #[cfg_attr(PyPy, link_name = "PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyType_GenericNew")] - pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, - kwds: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyType_Lookup")] + #[cfg_attr(PyPy, link_name = "PyPyType_GenericNew")] + pub fn PyType_GenericNew( + t: *mut PyTypeObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyType_Lookup")] 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; + fn _PyObject_LookupSpecial( + arg1: *mut PyObject, + arg2: *mut c_char, + arg3: *mut *mut PyObject, + ) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; - #[cfg_attr(PyPy, link_name="PyPyType_Modified")] + #[cfg_attr(PyPy, link_name = "PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); - #[cfg_attr(PyPy, link_name="PyPyObject_Print")] - pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, - flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Print")] + pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int; fn _PyObject_Dump(o: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyObject_Repr")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Str")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Str")] fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyObject_Bytes")] +#[cfg_attr(PyPy, link_name = "PyPyObject_Bytes")] pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { PyObject_Str(o) } @@ -666,77 +674,86 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(py_sys_config = "Py_USING_UNICODE")] - #[cfg_attr(PyPy, link_name="PyPyObject_Unicode")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Unicode")] pub fn PyObject_Unicode(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Compare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_RichCompare")] - pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_RichCompareBool")] - pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_GetAttrString")] - pub fn PyObject_GetAttrString(arg1: *mut PyObject, - arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_SetAttrString")] - pub fn PyObject_SetAttrString(arg1: *mut PyObject, - arg2: *const c_char, - arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_HasAttrString")] - pub fn PyObject_HasAttrString(arg1: *mut PyObject, - arg2: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_GetAttr")] + #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompare")] + pub fn PyObject_RichCompare( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompareBool")] + pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) + -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttrString")] + pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttrString")] + pub fn PyObject_SetAttrString( + arg1: *mut PyObject, + arg2: *const c_char, + arg3: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")] + pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttr")] pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_SetAttr")] - pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_HasAttr")] + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] + pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) + -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttr")] pub fn PyObject_HasAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="_PyPyObject_GetDictPtr")] + #[cfg_attr(PyPy, link_name = "_PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_SelfIter")] + #[cfg_attr(PyPy, link_name = "PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_GenericGetAttr")] + #[cfg_attr(PyPy, link_name = "PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_GenericSetAttr")] - pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_Hash")] + #[cfg_attr(PyPy, link_name = "PyPyObject_GenericSetAttr")] + pub fn PyObject_GenericSetAttr( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="PyPyObject_HashNotImplemented")] + #[cfg_attr(PyPy, link_name = "PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="PyPyObject_IsTrue")] + #[cfg_attr(PyPy, link_name = "PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_Not")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCallable_Check")] + #[cfg_attr(PyPy, link_name = "PyPyCallable_Check")] 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; - #[cfg_attr(PyPy, link_name="PyPyObject_ClearWeakRefs")] + pub fn PyNumber_CoerceEx(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_ClearWeakRefs")] 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; - #[cfg_attr(PyPy, link_name="PyPyObject_Dir")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_Dir")] 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); - #[cfg_attr(PyPy, link_name="_PyPy_HashDouble")] + #[cfg_attr(PyPy, link_name = "_PyPy_HashDouble")] fn _Py_HashDouble(arg1: c_double) -> c_long; - #[cfg_attr(PyPy, link_name="_PyPy_HashPointer")] + #[cfg_attr(PyPy, link_name = "_PyPy_HashPointer")] 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. +pub const Py_PRINT_RAW: c_int = 1; // No string quotes etc. // PyBufferProcs contains bf_getcharbuffer pub const Py_TPFLAGS_HAVE_GETCHARBUFFER: c_long = (1 << 0); @@ -804,17 +821,16 @@ pub const Py_TPFLAGS_DICT_SUBCLASS: c_long = (1 << 29); pub const Py_TPFLAGS_BASE_EXC_SUBCLASS: c_long = (1 << 30); pub const Py_TPFLAGS_TYPE_SUBCLASS: c_long = (1 << 31); -pub const Py_TPFLAGS_DEFAULT: c_long = ( - Py_TPFLAGS_HAVE_GETCHARBUFFER | - Py_TPFLAGS_HAVE_SEQUENCE_IN | - Py_TPFLAGS_HAVE_INPLACEOPS | - Py_TPFLAGS_HAVE_RICHCOMPARE | - Py_TPFLAGS_HAVE_WEAKREFS | - Py_TPFLAGS_HAVE_ITER | - Py_TPFLAGS_HAVE_CLASS | - Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | - Py_TPFLAGS_HAVE_INDEX | - 0); +pub const Py_TPFLAGS_DEFAULT: c_long = (Py_TPFLAGS_HAVE_GETCHARBUFFER + | Py_TPFLAGS_HAVE_SEQUENCE_IN + | Py_TPFLAGS_HAVE_INPLACEOPS + | Py_TPFLAGS_HAVE_RICHCOMPARE + | Py_TPFLAGS_HAVE_WEAKREFS + | Py_TPFLAGS_HAVE_ITER + | Py_TPFLAGS_HAVE_CLASS + | Py_TPFLAGS_HAVE_STACKLESS_EXTENSION + | Py_TPFLAGS_HAVE_INDEX + | 0); #[inline(always)] pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_long) -> c_int { @@ -829,7 +845,7 @@ pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_long) -> c_int { // Reference counting macros. #[inline(always)] pub unsafe fn Py_INCREF(op: *mut PyObject) { - if cfg!(py_sys_config="Py_REF_DEBUG") { + if cfg!(py_sys_config = "Py_REF_DEBUG") { Py_IncRef(op) } else { (*op).ob_refcnt += 1 @@ -838,7 +854,7 @@ pub unsafe fn Py_INCREF(op: *mut PyObject) { #[inline(always)] pub unsafe fn Py_DECREF(op: *mut PyObject) { - if cfg!(py_sys_config="Py_REF_DEBUG") || cfg!(py_sys_config="COUNT_ALLOCS") { + if cfg!(py_sys_config = "Py_REF_DEBUG") || cfg!(py_sys_config = "COUNT_ALLOCS") { Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -876,9 +892,9 @@ extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); - #[cfg_attr(PyPy, link_name="_PyPy_NoneStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; - #[cfg_attr(PyPy, link_name="_PyPy_NotImplementedStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } @@ -935,4 +951,4 @@ pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { } else { _PyTrash_thread_deposit_object(op) } -} \ No newline at end of file +} diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index af8e5497e72..99803a94562 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -1,351 +1,335 @@ -use std::ptr; -use std::os::raw::{c_void, c_char, c_int}; use ffi2; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_void}; +use std::ptr; #[inline] -#[cfg_attr(PyPy, link_name="PyPyObject_DelAttrString")] +#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name="PyPyObject_DelAttr")] +#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttr")] 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; - #[cfg_attr(PyPy, link_name="PyPyObject_Call")] - pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, - kw: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallObject")] - pub fn PyObject_CallObject(callable_object: *mut PyObject, - args: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallFunction")] - pub fn PyObject_CallFunction(callable_object: *mut PyObject, - format: *mut c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallMethod")] - pub fn PyObject_CallMethod(o: *mut PyObject, m: *mut c_char, - format: *mut c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyObject_CallFunction_SizeT")] - fn _PyObject_CallFunction_SizeT(callable: *mut PyObject, - format: *mut c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyObject_CallMethod_SizeT")] - fn _PyObject_CallMethod_SizeT(o: *mut PyObject, - name: *mut c_char, - format: *mut c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallFunctionObjArgs")] - pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallMethodObjArgs")] - pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject, result: *mut c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Call")] + pub fn PyObject_Call( + callable_object: *mut PyObject, + args: *mut PyObject, + kw: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallObject")] + pub fn PyObject_CallObject( + callable_object: *mut PyObject, + args: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] + pub fn PyObject_CallFunction( + callable_object: *mut PyObject, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethod")] + pub fn PyObject_CallMethod( + o: *mut PyObject, + m: *mut c_char, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyObject_CallFunction_SizeT")] + fn _PyObject_CallFunction_SizeT( + callable: *mut PyObject, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyObject_CallMethod_SizeT")] + fn _PyObject_CallMethod_SizeT( + o: *mut PyObject, + name: *mut c_char, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")] + pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")] + pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Size")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyObject_LengthHint")] - pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyObject_GetItem")] - pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_SetItem")] - 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; - #[cfg_attr(PyPy, link_name="PyPyObject_AsCharBuffer")] - pub fn PyObject_AsCharBuffer(obj: *mut PyObject, - buffer: *mut *const c_char, - buffer_len: *mut Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_CheckReadBuffer")] + #[cfg_attr(PyPy, link_name = "PyPyObject_LengthHint")] + pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetItem")] + pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetItem")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsCharBuffer")] + pub fn PyObject_AsCharBuffer( + obj: *mut PyObject, + buffer: *mut *const c_char, + buffer_len: *mut Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_AsReadBuffer")] - pub fn PyObject_AsReadBuffer(obj: *mut PyObject, - buffer: *mut *const c_void, - buffer_len: *mut Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_AsWriteBuffer")] - pub fn PyObject_AsWriteBuffer(obj: *mut PyObject, - buffer: *mut *mut c_void, - buffer_len: *mut Py_ssize_t) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsReadBuffer")] + pub fn PyObject_AsReadBuffer( + obj: *mut PyObject, + buffer: *mut *const c_void, + buffer_len: *mut Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsWriteBuffer")] + pub fn PyObject_AsWriteBuffer( + obj: *mut PyObject, + buffer: *mut *mut c_void, + buffer_len: *mut Py_ssize_t, + ) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_GetBuffer")] - pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, - flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetBuffer")] + pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyBuffer_GetPointer")] - pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyBuffer_ToContiguous")] - pub fn PyBuffer_ToContiguous(buf: *mut c_void, - view: *mut Py_buffer, len: Py_ssize_t, - fort: c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyBuffer_FromContiguous")] - 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; - #[cfg_attr(PyPy, link_name="PyPyBuffer_IsContiguous")] - 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); - #[cfg_attr(PyPy, link_name="PyPyBuffer_FillInfo")] - 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; - #[cfg_attr(PyPy, link_name="PyPyBuffer_Release")] + #[cfg_attr(PyPy, link_name = "PyPyBuffer_GetPointer")] + pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_ToContiguous")] + pub fn PyBuffer_ToContiguous( + buf: *mut c_void, + view: *mut Py_buffer, + len: Py_ssize_t, + fort: c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromContiguous")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_IsContiguous")] + 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, + ); + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FillInfo")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); - #[cfg_attr(PyPy, link_name="PyPyObject_Format")] - pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_GetIter")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Format")] + pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyIter_Next")] + #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Check")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyNumber_Add")] - pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Subtract")] - pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Multiply")] - pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Divide")] - pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_FloorDivide")] - pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_TrueDivide")] - pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Remainder")] - pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Divmod")] - pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Power")] - pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, - o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Negative")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Add")] + pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Subtract")] + pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Multiply")] + pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Divide")] + pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_FloorDivide")] + pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_TrueDivide")] + pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Remainder")] + pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Divmod")] + pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Power")] + pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) + -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Positive")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Absolute")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Invert")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Lshift")] - pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Rshift")] - pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_And")] - pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Xor")] - pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Or")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Lshift")] + pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Rshift")] + pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_And")] + pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Xor")] + pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Index")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_AsSsize_t")] - 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; + #[cfg_attr(PyPy, link_name = "PyPyNumber_AsSsize_t")] + 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; - #[cfg_attr(PyPy, link_name="PyPyNumber_Long")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Float")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAdd")] - pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceSubtract")] - pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceMultiply")] - pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceDivide")] - pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceFloorDivide")] - pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceTrueDivide")] - pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRemainder")] - pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlacePower")] - pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject, - o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceLshift")] - pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRshift")] - pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAnd")] - pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceXor")] - pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceOr")] - pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_Check")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAdd")] + pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceSubtract")] + pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceMultiply")] + pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceDivide")] + pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceFloorDivide")] + pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceTrueDivide")] + pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRemainder")] + pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlacePower")] + pub fn PyNumber_InPlacePower( + o1: *mut PyObject, + o2: *mut PyObject, + o3: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceLshift")] + pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRshift")] + pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAnd")] + pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceXor")] + pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceOr")] + pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_Size")] + #[cfg_attr(PyPy, link_name = "PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySequence_Length")] + #[cfg_attr(PyPy, link_name = "PyPySequence_Length")] pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySequence_Concat")] - pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_Repeat")] - pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_GetItem")] - pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_GetSlice")] - pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, - i2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_SetItem")] - pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, - v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_DelItem")] - pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_SetSlice")] - pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t, - i2: Py_ssize_t, v: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_DelSlice")] - pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, - i2: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_Tuple")] + #[cfg_attr(PyPy, link_name = "PyPySequence_Concat")] + pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_Repeat")] + pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_GetItem")] + pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_GetSlice")] + pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_SetItem")] + pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_DelItem")] + pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_SetSlice")] + pub fn PySequence_SetSlice( + o: *mut PyObject, + i1: Py_ssize_t, + i2: Py_ssize_t, + v: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_DelSlice")] + pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_List")] + #[cfg_attr(PyPy, link_name = "PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_Fast")] - 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; - #[cfg_attr(PyPy, link_name="PyPySequence_Contains")] - 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; - #[cfg_attr(PyPy, link_name="PyPySequence_Index")] - pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceConcat")] - pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceRepeat")] - pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_Check")] + #[cfg_attr(PyPy, link_name = "PyPySequence_Fast")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySequence_Contains")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySequence_Index")] + pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceConcat")] + pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceRepeat")] + pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyMapping_Size")] + #[cfg_attr(PyPy, link_name = "PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyMapping_Length")] + #[cfg_attr(PyPy, link_name = "PyPyMapping_Length")] pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyMapping_HasKeyString")] - pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyMapping_HasKey")] - pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyMapping_GetItemString")] - pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_SetItemString")] - pub fn PyMapping_SetItemString(o: *mut PyObject, key: *mut c_char, - value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_IsInstance")] - pub fn PyObject_IsInstance(object: *mut PyObject, - typeorclass: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_IsSubclass")] - pub fn PyObject_IsSubclass(object: *mut PyObject, - typeorclass: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKeyString")] + pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKey")] + pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_GetItemString")] + pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMapping_SetItemString")] + pub fn PyMapping_SetItemString( + o: *mut PyObject, + key: *mut c_char, + value: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsInstance")] + pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsSubclass")] + pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } - #[inline] pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let b = (*t).tp_as_buffer; - (!b.is_null() && - (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) && - ((*b).bf_getbuffer.is_some())) as c_int + (!b.is_null() + && (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) + && ((*b).bf_getbuffer.is_some())) as c_int } - #[inline] -#[cfg_attr(PyPy, link_name="PyPyIter_Check")] +#[cfg_attr(PyPy, link_name = "PyPyIter_Check")] 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 + (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] -#[cfg_attr(PyPy, link_name="PyPyIndex_Check")] +#[cfg_attr(PyPy, link_name = "PyPyIndex_Check")] pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let n = (*t).tp_as_number; - (!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) as c_int + (!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) + as c_int } #[inline] -#[cfg_attr(PyPy, link_name="PyPySequence_Fast_GET_SIZE")] -pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { +#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_SIZE")] +pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name="PyPyList_GET_SIZE")] + #[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] ffi2::listobject::PyList_GET_SIZE(o) } else { ffi2::tupleobject::PyTuple_GET_SIZE(o) @@ -353,10 +337,10 @@ pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { } #[inline] -#[cfg_attr(PyPy, link_name="PyPySequence_Fast_GET_ITEM")] -pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_ITEM")] +pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name="PyPyList_GET_ITEM")] + #[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] ffi2::listobject::PyList_GET_ITEM(o, i) } else { ffi2::tupleobject::PyTuple_GET_ITEM(o, i) @@ -364,49 +348,53 @@ pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mu } #[inline] -#[cfg_attr(PyPy, link_name="PyPySequence_Fast_ITEMS")] -pub unsafe fn PySequence_Fast_ITEMS(o : *mut PyObject) -> *mut *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_ITEMS")] +pub unsafe fn PySequence_Fast_ITEMS(o: *mut PyObject) -> *mut *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { (*(o as *mut ffi2::listobject::PyListObject)).ob_item } else { - (*(o as *mut ffi2::tupleobject::PyTupleObject)).ob_item.as_mut_ptr() + (*(o as *mut ffi2::tupleobject::PyTupleObject)) + .ob_item + .as_mut_ptr() } } #[inline] -#[cfg_attr(PyPy, link_name="PyPySequence_ITEM")] -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) +#[cfg_attr(PyPy, link_name = "PyPySequence_ITEM")] +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; +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 { +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 { +pub unsafe fn PyMapping_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int { PyObject_DelItem(o, key) } #[inline] -#[cfg_attr(PyPy, link_name="PyPyMapping_Keys")] -pub unsafe fn PyMapping_Keys(o : *mut PyObject) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPyMapping_Keys")] +pub unsafe fn PyMapping_Keys(o: *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "keys\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name="PyPyMapping_Values")] -pub unsafe fn PyMapping_Values(o : *mut PyObject) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPyMapping_Values")] +pub unsafe fn PyMapping_Values(o: *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "values\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name="PyPyMapping_Items")] -pub unsafe fn PyMapping_Items(o : *mut PyObject) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPyMapping_Items")] +pub unsafe fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "items\0".as_ptr() as *mut i8, ptr::null_mut()) -} \ No newline at end of file +} diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index 3472cd5f7f0..87e953fca11 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -1,32 +1,31 @@ -use std::os::raw::{c_void, c_char, c_int}; -use libc::size_t; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use libc::size_t; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyObject_Malloc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyObject_Malloc")] pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyObject_Realloc")] - pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) - -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyObject_Realloc")] + pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; pub fn PyObject_Free(arg1: *mut c_void); - pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) - -> *mut PyObject; - pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject, - arg3: Py_ssize_t) -> *mut PyVarObject; + pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject; + pub fn PyObject_InitVar( + arg1: *mut PyVarObject, + arg2: *mut PyTypeObject, + arg3: Py_ssize_t, + ) -> *mut PyVarObject; pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject; - pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) - -> *mut PyVarObject; + pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; // GC Support pub fn PyGC_Collect() -> Py_ssize_t; - pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) - -> *mut PyVarObject; + pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn _PyObject_GC_Malloc(arg1: size_t) -> *mut PyObject; pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject; - pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) - -> *mut PyVarObject; + pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn PyObject_GC_Track(arg1: *mut c_void); pub fn PyObject_GC_UnTrack(arg1: *mut c_void); pub fn PyObject_GC_Del(arg1: *mut c_void); @@ -35,30 +34,29 @@ use ffi2::object::*; /// Test if a type has a GC head #[inline(always)] #[allow(unused_parens)] -pub unsafe fn PyType_IS_GC(t : *mut PyTypeObject) -> c_int { +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(always)] -pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int { - (PyType_IS_GC(Py_TYPE(o)) != 0 && - match (*Py_TYPE(o)).tp_is_gc { - Some(tp_is_gc) => tp_is_gc(o) != 0, - None => true - }) as c_int +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(always)] #[allow(unused_parens)] -pub unsafe fn PyType_SUPPORTS_WEAKREFS(t : *mut PyTypeObject) -> c_int { - (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) != 0 - && ((*t).tp_weaklistoffset > 0)) as c_int +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(always)] -pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o : *mut PyObject) -> *mut *mut PyObject { +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 -} \ No newline at end of file +} diff --git a/src/ffi2/pyarena.rs b/src/ffi2/pyarena.rs index d7429d0de35..2715a33f653 100644 --- a/src/ffi2/pyarena.rs +++ b/src/ffi2/pyarena.rs @@ -1,11 +1,12 @@ -use libc::size_t; -use std::os::raw::{c_void, c_int}; use ffi2::object::PyObject; +use libc::size_t; +use std::os::raw::{c_int, c_void}; #[allow(missing_copy_implementations)] -pub enum PyArena { } +pub enum PyArena {} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyArena_New() -> *mut PyArena; pub fn PyArena_Free(arg1: *mut PyArena); pub fn PyArena_Malloc(arg1: *mut PyArena, size: size_t) -> *mut c_void; diff --git a/src/ffi2/pycapsule.rs b/src/ffi2/pycapsule.rs index eec17cbf776..6655b1de474 100644 --- a/src/ffi2/pycapsule.rs +++ b/src/ffi2/pycapsule.rs @@ -1,8 +1,9 @@ -use std::os::raw::{c_void, c_char, c_int}; use ffi2::object::*; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCapsule_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -13,36 +14,35 @@ 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" { - #[cfg_attr(PyPy, link_name="PyPyCapsule_New")] - pub fn PyCapsule_New(pointer: *mut c_void, - name: *const c_char, - destructor: Option) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetPointer")] - pub fn PyCapsule_GetPointer(capsule: *mut PyObject, - name: *const c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetDestructor")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCapsule_New")] + pub fn PyCapsule_New( + pointer: *mut c_void, + name: *const c_char, + destructor: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetPointer")] + pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetName")] + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetContext")] + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCapsule_IsValid")] - pub fn PyCapsule_IsValid(capsule: *mut PyObject, - name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetPointer")] - pub fn PyCapsule_SetPointer(capsule: *mut PyObject, - pointer: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetDestructor")] - pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, - destructor: Option) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetName")] - pub fn PyCapsule_SetName(capsule: *mut PyObject, - name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetContext")] - pub fn PyCapsule_SetContext(capsule: *mut PyObject, - context: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_Import")] - pub fn PyCapsule_Import(name: *const c_char, - no_block: c_int) -> *mut c_void; -} \ No newline at end of file + #[cfg_attr(PyPy, link_name = "PyPyCapsule_IsValid")] + pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetPointer")] + pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetDestructor")] + pub fn PyCapsule_SetDestructor( + capsule: *mut PyObject, + destructor: Option, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetName")] + pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetContext")] + pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_Import")] + pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; +} diff --git a/src/ffi2/pydebug.rs b/src/ffi2/pydebug.rs index 27d4f04fef8..52d6d86bff0 100644 --- a/src/ffi2/pydebug.rs +++ b/src/ffi2/pydebug.rs @@ -1,43 +1,44 @@ use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPy_DebugFlag")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_VerboseFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_InteractiveFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_InspectFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_OptimizeFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_NoSiteFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_BytesWarningFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_UseClassExceptionsFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_FrozenFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_TabcheckFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_TabcheckFlag")] pub static mut Py_TabcheckFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_UnicodeFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_UnicodeFlag")] pub static mut Py_UnicodeFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_IgnoreEnvironmentFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_DivisionWarningFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_DivisionWarningFlag")] pub static mut Py_DivisionWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_DontWriteBytecodeFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_NoUserSiteDirectory")] + #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; - #[cfg_attr(PyPy, link_name="_PyPy_QnewFlag")] + #[cfg_attr(PyPy, link_name = "_PyPy_QnewFlag")] pub static mut _Py_QnewFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_Py3kWarningFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_Py3kWarningFlag")] pub static mut Py_Py3kWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_HashRandomizationFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_FatalError")] + #[cfg_attr(PyPy, link_name = "PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char); -} \ No newline at end of file +} diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index 459a4743870..be4cdbd52ad 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -1,49 +1,55 @@ -use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; use ffi2::classobject::*; +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; use ffi2::stringobject::PyString_AS_STRING; -#[cfg(py_sys_config="Py_USING_UNICODE")] +#[cfg(py_sys_config = "Py_USING_UNICODE")] use ffi2::unicodeobject::Py_UNICODE; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyErr_SetNone")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyErr_SetObject")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyErr_SetString")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetString")] pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); - #[cfg_attr(PyPy, link_name="PyPyErr_Occurred")] + #[cfg_attr(PyPy, link_name = "PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_Clear")] + #[cfg_attr(PyPy, link_name = "PyPyErr_Clear")] pub fn PyErr_Clear(); - #[cfg_attr(PyPy, link_name="PyPyErr_Fetch")] - pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyErr_Restore")] - pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyErr_GivenExceptionMatches")] - pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, - arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_ExceptionMatches")] + #[cfg_attr(PyPy, link_name = "PyPyErr_Fetch")] + pub fn PyErr_Fetch( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ); + #[cfg_attr(PyPy, link_name = "PyPyErr_Restore")] + pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyErr_GivenExceptionMatches")] + pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_NormalizeException")] - pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyErr_NormalizeException")] + pub fn PyErr_NormalizeException( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ); } #[inline] pub unsafe fn PyExceptionClass_Check(x: *mut PyObject) -> c_int { - (PyClass_Check(x) != 0 || (PyType_Check(x) != 0 && - PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) as c_int + (PyClass_Check(x) != 0 + || (PyType_Check(x) != 0 + && PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) + as c_int } #[inline] pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { - (PyInstance_Check(x) != 0 || - PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int + (PyInstance_Check(x) != 0 + || PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int } #[inline] @@ -56,7 +62,7 @@ pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char { } #[inline] -#[cfg_attr(PyPy, link_name="PyPyExceptionInstance_Class")] +#[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { if PyInstance_Check(x) != 0 { (*(x as *mut PyInstanceObject)).in_class as *mut PyObject @@ -65,220 +71,199 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyExc_BaseException")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_Exception")] + #[cfg_attr(PyPy, link_name = "PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_StopIteration")] + #[cfg_attr(PyPy, link_name = "PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_GeneratorExit")] + #[cfg_attr(PyPy, link_name = "PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; pub static mut PyExc_StandardError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ArithmeticError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_LookupError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_AssertionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_AttributeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_EOFError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_FloatingPointError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_OSError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ImportError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_IndexError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_KeyError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_KeyboardInterrupt")] + #[cfg_attr(PyPy, link_name = "PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_MemoryError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_NameError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_OverflowError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_NotImplementedError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_IndentationError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_TabError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ReferenceError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SystemError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SystemExit")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_TypeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnboundLocalError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeEncodeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeDecodeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeTranslateError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ValueError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ZeroDivisionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; - #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_BufferError")] + #[cfg(windows)] + pub static mut PyExc_WindowsError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; pub static mut PyExc_MemoryErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_RecursionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_RecursionError")] pub static mut PyExc_RecursionErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_Warning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UserWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_DeprecationWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_PendingDeprecationWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_FutureWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ImportWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_BytesWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - - #[cfg_attr(PyPy, link_name="PyPyErr_BadArgument")] + + #[cfg_attr(PyPy, link_name = "PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_NoMemory")] + #[cfg_attr(PyPy, link_name = "PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrno")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrnoWithFilenameObject")] - pub fn PyErr_SetFromErrnoWithFilenameObject(arg1: *mut PyObject, - arg2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrnoWithFilename")] - pub fn PyErr_SetFromErrnoWithFilename(arg1: *mut PyObject, - arg2: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_Format")] - pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_BadInternalCall")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilenameObject")] + pub fn PyErr_SetFromErrnoWithFilenameObject( + arg1: *mut PyObject, + arg2: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilename")] + pub fn PyErr_SetFromErrnoWithFilename( + arg1: *mut PyObject, + arg2: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_Format")] + pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall(); - pub fn _PyErr_BadInternalCall(filename: *mut c_char, - lineno: c_int); - #[cfg_attr(PyPy, link_name="PyPyErr_NewException")] - pub fn PyErr_NewException(name: *mut c_char, base: *mut PyObject, - dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_NewExceptionWithDoc")] - pub fn PyErr_NewExceptionWithDoc(name: *mut c_char, - doc: *mut c_char, - base: *mut PyObject, dict: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_WriteUnraisable")] + pub fn _PyErr_BadInternalCall(filename: *mut c_char, lineno: c_int); + #[cfg_attr(PyPy, link_name = "PyPyErr_NewException")] + pub fn PyErr_NewException( + name: *mut c_char, + base: *mut PyObject, + dict: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_NewExceptionWithDoc")] + pub fn PyErr_NewExceptionWithDoc( + name: *mut c_char, + doc: *mut c_char, + base: *mut PyObject, + dict: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPyErr_CheckSignals")] + #[cfg_attr(PyPy, link_name = "PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_SetInterrupt")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; - pub fn PyErr_SyntaxLocation(arg1: *const c_char, - arg2: c_int); - pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) - -> *mut PyObject; + pub fn PyErr_SyntaxLocation(arg1: *const c_char, arg2: c_int); + pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) -> *mut PyObject; } -#[cfg(py_sys_config="Py_USING_UNICODE")] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyUnicodeDecodeError_Create(arg1: *const c_char, - 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; -} \ No newline at end of file +#[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; +} diff --git a/src/ffi2/pymem.rs b/src/ffi2/pymem.rs index cb15a9a8835..dabd9a874b9 100644 --- a/src/ffi2/pymem.rs +++ b/src/ffi2/pymem.rs @@ -1,8 +1,9 @@ use libc::{c_void, size_t}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMem_Malloc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMem_Malloc")] 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); -} \ No newline at end of file +} diff --git a/src/ffi2/pyport.rs b/src/ffi2/pyport.rs index cbfa8e6bc13..5ee20a83ed8 100644 --- a/src/ffi2/pyport.rs +++ b/src/ffi2/pyport.rs @@ -1,9 +1,8 @@ - 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; +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; diff --git a/src/ffi2/pystate.rs b/src/ffi2/pystate.rs index f4abbcd050c..24279519117 100644 --- a/src/ffi2/pystate.rs +++ b/src/ffi2/pystate.rs @@ -1,22 +1,24 @@ -use std::os::raw::{c_int, c_long}; -use ffi2::object::PyObject; use ffi2::frameobject::PyFrameObject; +use ffi2::object::PyObject; +use std::os::raw::{c_int, c_long}; -pub enum PyInterpreterState { } +pub enum PyInterpreterState {} -pub type Py_tracefunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyFrameObject, - arg3: c_int, arg4: *mut PyObject) - -> c_int; +pub type Py_tracefunc = unsafe extern "C" fn( + arg1: *mut PyObject, + arg2: *mut PyFrameObject, + arg3: c_int, + arg4: *mut PyObject, +) -> c_int; /* The following values are used for 'what' for tracefunc functions: */ -pub const PyTrace_CALL : c_int = 0; -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; +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)] @@ -47,69 +49,66 @@ pub struct PyThreadState { } impl Clone for PyThreadState { - #[inline] fn clone(&self) -> PyThreadState { *self } + #[inline] + fn clone(&self) -> PyThreadState { + *self + } } #[repr(C)] #[derive(Copy, Clone)] pub enum PyGILState_STATE { PyGILState_LOCKED, - PyGILState_UNLOCKED + PyGILState_UNLOCKED, } - -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyThreadState_Get")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Get")] //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); - #[cfg_attr(PyPy, link_name="PyPyThreadState_New")] - pub fn PyThreadState_New(arg1: *mut PyInterpreterState) - -> *mut PyThreadState; - pub fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) - -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyThreadState_New")] + 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); - #[cfg_attr(PyPy, link_name="PyPyThreadState_Clear")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name="PyPyThreadState_Delete")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState); - #[cfg(py_sys_config="WITH_THREAD")] - #[cfg_attr(PyPy, link_name="PyPyThreadState_DeleteCurrent")] + #[cfg(py_sys_config = "WITH_THREAD")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent(); pub fn PyThreadState_Get() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyThreadState_Swap")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyThreadState_GetDict")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; - pub fn PyThreadState_SetAsyncExc(arg1: c_long, - arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyGILState_Ensure")] + pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; - #[cfg_attr(PyPy, link_name="PyPyGILState_Release")] + #[cfg_attr(PyPy, link_name = "PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; fn _PyThread_CurrentFrames() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyInterpreterState_Head")] + #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; - #[cfg_attr(PyPy, link_name="PyPyInterpreterState_Next")] - pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) - -> *mut PyInterpreterState; - pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) - -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")] + 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")] +#[cfg(py_sys_config = "Py_DEBUG")] #[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { PyThreadState_Get() } -#[cfg(not(py_sys_config="Py_DEBUG"))] +#[cfg(not(py_sys_config = "Py_DEBUG"))] #[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { _PyThreadState_Current -} \ No newline at end of file +} diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index a5276d633c4..09b52940f59 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -1,121 +1,147 @@ -use libc::{c_char, c_int, FILE}; -use ffi2::object::*; use ffi2::code::*; -use ffi2::pystate::PyThreadState; +use ffi2::object::*; use ffi2::pyarena::PyArena; +use ffi2::pystate::PyThreadState; +use libc::{c_char, c_int, FILE}; -pub const PyCF_MASK : c_int = (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | - CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | - CO_FUTURE_UNICODE_LITERALS); -pub const PyCF_MASK_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; +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 + cf_flags: c_int, } #[allow(missing_copy_implementations)] -pub enum Struct__mod { } +pub enum Struct__mod {} #[allow(missing_copy_implementations)] -pub enum Struct__node { } +pub enum Struct__node {} #[allow(missing_copy_implementations)] -pub enum Struct_symtable { } +pub enum Struct_symtable {} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); - #[cfg_attr(PyPy, link_name="PyPy_GetProgramName")] + #[cfg_attr(PyPy, link_name = "PyPy_GetProgramName")] 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(); - #[cfg_attr(PyPy, link_name="PyPy_IsInitialized")] + #[cfg_attr(PyPy, link_name = "PyPy_IsInitialized")] 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; - #[cfg_attr(PyPy, link_name="PyPyRun_StringFlags")] - 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; - #[cfg_attr(PyPy, link_name="PyPy_CompileStringFlags")] - 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; - #[cfg_attr(PyPy, link_name="PyPyErr_Print")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] + 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; + #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyErr_Print")] pub fn PyErr_Print(); - #[cfg_attr(PyPy, link_name="PyPyErr_PrintEx")] + #[cfg_attr(PyPy, link_name = "PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int); - #[cfg_attr(PyPy, link_name="PyPyErr_Display")] - pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name="PyPy_AtExit")] - pub fn Py_AtExit(func: Option) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_Display")] + pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPy_AtExit")] + pub fn Py_AtExit(func: Option) -> c_int; pub fn Py_Exit(arg1: c_int); - pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) - -> c_int; - pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) - -> c_int; + pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) -> c_int; + pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) -> c_int; pub fn Py_GetProgramFullPath() -> *mut c_char; pub fn Py_GetPrefix() -> *mut c_char; pub fn Py_GetExecPrefix() -> *mut c_char; pub fn Py_GetPath() -> *mut c_char; - #[cfg_attr(PyPy, link_name="PyPy_GetVersion")] + #[cfg_attr(PyPy, link_name = "PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; @@ -126,4 +152,4 @@ pub enum Struct_symtable { } pub fn Py_SubversionShortBranch() -> *const c_char; fn _Py_hgidentifier() -> *const c_char; fn _Py_hgversion() -> *const c_char; -} \ No newline at end of file +} diff --git a/src/ffi2/rangeobject.rs b/src/ffi2/rangeobject.rs index 0266225ac82..cc5fa28ccd9 100644 --- a/src/ffi2/rangeobject.rs +++ b/src/ffi2/rangeobject.rs @@ -1,13 +1,14 @@ -use std::os::raw::c_int; use ffi2::object::*; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyRange_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyRange_Type; +pub unsafe fn PyRange_Check(op: *mut PyObject) -> c_int { + let u: *mut PyTypeObject = &mut PyRange_Type; (Py_TYPE(op) == u) as c_int } diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index 49194c0245e..ae608c2fe0c 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -1,77 +1,77 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; //enum PySetObject { /* representation hidden */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySet_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyFrozenSet_Type")] + #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name="PyPyFrozenSet_CheckExact")] -pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { - let f : *mut PyTypeObject = &mut PyFrozenSet_Type; +#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_CheckExact")] +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] -#[cfg_attr(PyPy, link_name="PyPyAnySet_CheckExact")] -pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { - let s : *mut PyTypeObject = &mut PySet_Type; - let f : *mut PyTypeObject = &mut PyFrozenSet_Type; +#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")] +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] -#[cfg_attr(PyPy, link_name="PyPyAnySet_Check")] -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 +#[cfg_attr(PyPy, link_name = "PyPyAnySet_Check")] +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] -#[cfg_attr(PyPy, link_name="PyPySet_Check")] -pub unsafe fn PySet_Check(ob : *mut PyObject) -> c_int { - let s : *mut PyTypeObject = &mut PySet_Type; +#[cfg_attr(PyPy, link_name = "PyPySet_Check")] +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] -#[cfg_attr(PyPy, link_name="PyPyFrozenSet_Check")] -pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int { - let f : *mut PyTypeObject = &mut PyFrozenSet_Type; +#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Check")] +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" { - #[cfg_attr(PyPy, link_name="PyPySet_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySet_New")] pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFrozenSet_New")] + #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_New")] pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySet_Size")] + #[cfg_attr(PyPy, link_name = "PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySet_Clear")] + #[cfg_attr(PyPy, link_name = "PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Contains")] - pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Discard")] - pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Add")] + #[cfg_attr(PyPy, link_name = "PyPySet_Contains")] + pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySet_Discard")] + pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySet_Add")] 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; - #[cfg_attr(PyPy, link_name="PyPySet_Pop")] + #[cfg_attr(PyPy, link_name = "PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; - //pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) - // -> c_int; -} \ No newline at end of file +//pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) +// -> c_int; +} diff --git a/src/ffi2/sliceobject.rs b/src/ffi2/sliceobject.rs index 1fec20c44d5..ff1a8ea7f84 100644 --- a/src/ffi2/sliceobject.rs +++ b/src/ffi2/sliceobject.rs @@ -1,9 +1,10 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="_PyPy_EllipsisObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -15,41 +16,53 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PySliceObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub step: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySlice_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPySlice_Check")] +#[cfg_attr(PyPy, link_name = "PyPySlice_Check")] pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PySlice_Type) as c_int + (Py_TYPE(op) == &mut PySlice_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySlice_New")] - pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject, - step: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySlice_GetIndices")] - 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; - #[cfg_attr(PyPy, link_name="PyPySlice_GetIndicesEx")] - 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; -} \ No newline at end of file +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySlice_New")] + pub fn PySlice_New( + start: *mut PyObject, + stop: *mut PyObject, + step: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndices")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndicesEx")] + 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; +} diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index 4164bf13a54..5dc10adf78c 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -1,13 +1,13 @@ -use std::os::raw::{c_char, c_int, c_long}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_long}; #[repr(C)] #[allow(missing_copy_implementations)] pub struct PyStringObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -17,122 +17,136 @@ pub struct PyStringObject { pub ob_sval: [c_char; 1], } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyBaseString_Type: PyTypeObject; pub static mut PyString_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyString_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyString_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS) } #[inline(always)] -pub unsafe fn PyBaseString_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyBaseString_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass( - Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS) + Py_TYPE(op), + Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS, + ) } #[inline(always)] -pub unsafe fn PyString_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyString_Type; +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(always)] -pub unsafe fn PyString_GET_SIZE(op : *mut PyObject) -> Py_ssize_t { +pub unsafe fn PyString_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { (*(op as *mut PyStringObject)).ob_size } #[inline(always)] -pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { +pub unsafe fn PyString_AS_STRING(op: *mut PyObject) -> *mut c_char { (*(op as *mut PyStringObject)).ob_sval.as_mut_ptr() } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyString_FromString")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyString_FromString")] pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyString_FromStringAndSize")] - pub fn PyString_FromStringAndSize(v: *const c_char, - len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyString_FromFormat")] + #[cfg_attr(PyPy, link_name = "PyPyString_FromStringAndSize")] + pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyString_FromFormat")] pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyString_Size")] + #[cfg_attr(PyPy, link_name = "PyPyString_Size")] pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyString_AsString")] + #[cfg_attr(PyPy, link_name = "PyPyString_AsString")] 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_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_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; - #[cfg_attr(PyPy, link_name="PyPyString_AsDecodedObject")] - 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; - #[cfg_attr(PyPy, link_name="PyPyString_AsEncodedObject")] - 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_Decode( + s: *const c_char, + size: Py_ssize_t, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyString_AsDecodedObject")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyString_AsEncodedObject")] + 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;*/ +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;*/ } diff --git a/src/ffi2/structmember.rs b/src/ffi2/structmember.rs index 20097a015d4..e93aba70e8f 100644 --- a/src/ffi2/structmember.rs +++ b/src/ffi2/structmember.rs @@ -1,6 +1,6 @@ -use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::PyObject; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] @@ -9,52 +9,50 @@ pub struct PyMemberDef { pub type_code: c_int, pub offset: Py_ssize_t, pub flags: c_int, - pub doc: *mut c_char + pub doc: *mut c_char, } /* Types */ -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; +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 */ +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; +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; +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_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_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 */ +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 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; } - diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index 3f0b90f8535..891cc222e4a 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -1,36 +1,36 @@ -use std::os::raw::c_int; +use ffi2::frameobject::PyFrameObject; use ffi2::object::*; use ffi2::pyport::Py_ssize_t; -use ffi2::frameobject::PyFrameObject; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTracebackObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub tb_lineno: c_int, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyTraceBack_Here")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyTraceBack_Print")] - pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) - -> c_int; - - #[cfg_attr(PyPy, link_name="PyPyTraceBack_Type")] + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Print")] + pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyTraceBack_Check")] -pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Check")] +pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int -} \ No newline at end of file +} diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index e7aa1ae94d1..e44598ca357 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -1,13 +1,13 @@ -use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTupleObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -15,27 +15,30 @@ pub struct PyTupleObject { pub ob_item: [*mut PyObject; 1], } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyTuple_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyTuple_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyTuple_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) } #[inline(always)] -pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyTuple_Type; +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(always)] pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { - *(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i as isize) + *(*(op as *mut PyTupleObject)) + .ob_item + .as_ptr() + .offset(i as isize) } #[inline(always)] @@ -46,25 +49,27 @@ pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { /// Macro, *only* to be used to fill in brand new tuples #[inline(always)] pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { - *(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i as isize) = v; + *(*(op as *mut PyTupleObject)) + .ob_item + .as_mut_ptr() + .offset(i as isize) = v; } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyTuple_Size")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_Size")] pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyTuple_GetItem")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_GetItem")] pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyTuple_SetItem")] - pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, - o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyTuple_GetSlice")] - pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, - high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyTuple_Resize")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_SetItem")] + pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyTuple_GetSlice")] + pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyTuple_Resize")] pub fn _PyTuple_Resize(p: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyTuple_Pack")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; //pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject); pub fn PyTuple_ClearFreeList() -> c_int; -} \ No newline at end of file +} diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index 6ece4ead29c..130dd6a3e4b 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -1,26 +1,26 @@ -use libc::wchar_t; -use std::os::raw::{c_char, c_int, c_long, c_double}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use libc::wchar_t; +use std::os::raw::{c_char, c_double, c_int, c_long}; -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -pub const Py_UNICODE_SIZE : Py_ssize_t = 4; -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] -pub const Py_UNICODE_SIZE : Py_ssize_t = 2; +#[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")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] pub type Py_UNICODE = u32; -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] +#[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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -30,21 +30,22 @@ pub struct PyUnicodeObject { pub defenc: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyUnicode_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyUnicode_Check")] -pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] +pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyUnicode_CheckExact")] -pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyUnicode_Type; +#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] +pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int { + let u: *mut PyTypeObject = &mut PyUnicode_Type; (Py_TYPE(op) == u) as c_int } @@ -68,219 +69,319 @@ 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; - +pub const Py_UNICODE_REPLACEMENT_CHARACTER: Py_UNICODE = 0xFFFD; #[allow(dead_code)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromUnicode")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] - fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, - size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromString")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] + fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicode")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetMax")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] fn PyUnicodeUCS4_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Resize")] - fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, - length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] - fn PyUnicodeUCS4_FromEncodedObject(obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromObject")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] + fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] + fn PyUnicodeUCS4_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideChar")] - fn PyUnicodeUCS4_AsWideChar(unicode: *mut PyUnicodeObject, - w: *mut wchar_t, size: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromOrdinal")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] + fn PyUnicodeUCS4_AsWideChar( + unicode: *mut PyUnicodeObject, + w: *mut wchar_t, + size: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS4_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS4_ClearFreelist() -> c_int; - #[cfg_attr(PyPy, link_name="_PyPyUnicode_AsDefaultEncodedString")] - fn _PyUnicodeUCS4_AsDefaultEncodedString(arg1: *mut PyObject, arg2: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetDefaultEncoding")] + #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] + fn _PyUnicodeUCS4_AsDefaultEncodedString( + arg1: *mut PyObject, + arg2: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS4_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS4_SetDefaultEncoding(encoding: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedObject")] - fn PyUnicodeUCS4_AsEncodedObject(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedString")] - fn PyUnicodeUCS4_AsEncodedString(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] + fn PyUnicodeUCS4_AsEncodedObject( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] + fn PyUnicodeUCS4_AsEncodedString( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF8")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS4_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeUTF8")] - fn PyUnicodeUCS4_EncodeUTF8(data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF32")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF32String")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] + fn PyUnicodeUCS4_EncodeUTF8( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF16")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF16String")] + fn PyUnicodeUCS4_EncodeUTF32( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + byteorder: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeEscapeString")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] 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_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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeLatin1")] - fn PyUnicodeUCS4_DecodeLatin1(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsLatin1String")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] + fn PyUnicodeUCS4_DecodeLatin1( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS4_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeLatin1")] - fn PyUnicodeUCS4_EncodeLatin1(data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeASCII")] - fn PyUnicodeUCS4_DecodeASCII(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsASCIIString")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] + fn PyUnicodeUCS4_EncodeLatin1( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] + fn PyUnicodeUCS4_DecodeASCII( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS4_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeASCII")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeDecimal")] - fn PyUnicodeUCS4_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, - output: *mut c_char, - errors: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Concat")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] + fn PyUnicodeUCS4_EncodeDecimal( + s: *mut Py_UNICODE, + length: Py_ssize_t, + output: *mut c_char, + errors: *const c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] fn PyUnicodeUCS4_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Split")] - fn PyUnicodeUCS4_Split(s: *mut PyObject, sep: *mut PyObject, - maxsplit: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Splitlines")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] + fn PyUnicodeUCS4_Split( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Join")] - fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Tailmatch")] - fn PyUnicodeUCS4_Tailmatch(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Find")] - fn PyUnicodeUCS4_Find(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Count")] - fn PyUnicodeUCS4_Count(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Replace")] - fn PyUnicodeUCS4_Replace(str: *mut PyObject, substr: *mut PyObject, - replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Compare")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] + fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] + fn PyUnicodeUCS4_Tailmatch( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] + fn PyUnicodeUCS4_Find( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] + fn PyUnicodeUCS4_Count( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] + fn PyUnicodeUCS4_Replace( + str: *mut PyObject, + substr: *mut PyObject, + replstr: *mut PyObject, + maxcount: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Format")] + fn PyUnicodeUCS4_RichCompare( + left: *mut PyObject, + right: *mut PyObject, + op: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] fn PyUnicodeUCS4_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_Contains(container: *mut PyObject, element: *mut PyObject) -> c_int; - fn _PyUnicode_XStrip(_self: *mut PyUnicodeObject, - striptype: c_int, sepobj: *mut PyObject) -> *mut PyObject; + fn _PyUnicode_XStrip( + _self: *mut PyUnicodeObject, + striptype: c_int, + sepobj: *mut PyObject, + ) -> *mut PyObject; fn _PyUnicodeUCS4_IsLowercase(ch: Py_UNICODE) -> c_int; fn _PyUnicodeUCS4_IsUppercase(ch: Py_UNICODE) -> c_int; fn _PyUnicodeUCS4_IsTitlecase(ch: Py_UNICODE) -> c_int; @@ -299,232 +400,315 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; } #[allow(dead_code)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromUnicode")] - fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] - fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, - size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromString")] - fn PyUnicodeUCS2_FromString(u: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicode")] +#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] + fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] + fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] + fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS2_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS2_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetMax")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] fn PyUnicodeUCS2_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Resize")] - fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, - length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] - fn PyUnicodeUCS2_FromEncodedObject(obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromObject")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] + fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] + fn PyUnicodeUCS2_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideChar")] - fn PyUnicodeUCS2_AsWideChar(unicode: *mut PyUnicodeObject, - w: *mut wchar_t, size: Py_ssize_t) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromOrdinal")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] + fn PyUnicodeUCS2_AsWideChar( + unicode: *mut PyUnicodeObject, + w: *mut wchar_t, + size: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS2_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS2_ClearFreelist() -> c_int; - #[cfg_attr(PyPy, link_name="_PyPyUnicode_AsDefaultEncodedString")] - fn _PyUnicodeUCS2_AsDefaultEncodedString(arg1: *mut PyObject, - arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetDefaultEncoding")] + #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] + fn _PyUnicodeUCS2_AsDefaultEncodedString( + arg1: *mut PyObject, + arg2: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS2_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS2_SetDefaultEncoding(encoding: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedObject")] - fn PyUnicodeUCS2_AsEncodedObject(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedString")] - fn PyUnicodeUCS2_AsEncodedString(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] + fn PyUnicodeUCS2_AsEncodedObject( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] + 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF8")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS2_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeUTF8")] - fn PyUnicodeUCS2_EncodeUTF8(data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF32")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF32String")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] + fn PyUnicodeUCS2_EncodeUTF8( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF16")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF16String")] + fn PyUnicodeUCS2_EncodeUTF32( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + byteorder: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeEscapeString")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] 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_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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeLatin1")] - fn PyUnicodeUCS2_DecodeLatin1(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsLatin1String")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] + fn PyUnicodeUCS2_DecodeLatin1( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS2_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeLatin1")] - fn PyUnicodeUCS2_EncodeLatin1(data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeASCII")] - fn PyUnicodeUCS2_DecodeASCII(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsASCIIString")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] + fn PyUnicodeUCS2_EncodeLatin1( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] + fn PyUnicodeUCS2_DecodeASCII( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS2_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeASCII")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeDecimal")] - fn PyUnicodeUCS2_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, - output: *mut c_char, - errors: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Concat")] - fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Split")] - fn PyUnicodeUCS2_Split(s: *mut PyObject, sep: *mut PyObject, - maxsplit: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Splitlines")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Join")] - fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Tailmatch")] - fn PyUnicodeUCS2_Tailmatch(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Find")] - fn PyUnicodeUCS2_Find(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Count")] - fn PyUnicodeUCS2_Count(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Replace")] - fn PyUnicodeUCS2_Replace(str: *mut PyObject, substr: *mut PyObject, - replstr: *mut PyObject, maxcount: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Compare")] - 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; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Format")] - 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] + fn PyUnicodeUCS2_EncodeDecimal( + s: *mut Py_UNICODE, + length: Py_ssize_t, + output: *mut c_char, + errors: *const c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] + fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] + fn PyUnicodeUCS2_Split( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] + fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] + fn PyUnicodeUCS2_Tailmatch( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] + fn PyUnicodeUCS2_Find( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] + fn PyUnicodeUCS2_Count( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] + fn PyUnicodeUCS2_Replace( + str: *mut PyObject, + substr: *mut PyObject, + replstr: *mut PyObject, + maxcount: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] + 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; @@ -543,44 +727,48 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; } #[inline(always)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject { PyUnicodeUCS4_FromStringAndSize(u, size) } #[inline(always)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] +#[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(always)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS4_AsUTF8String(u) } #[inline(always)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] +#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS2_AsUTF8String(u) } #[inline(always)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] -pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject { +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] +pub unsafe fn PyUnicode_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, +) -> *mut PyObject { PyUnicodeUCS4_FromEncodedObject(obj, encoding, errors) } #[inline(always)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] -pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject { +#[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) -} \ No newline at end of file +} diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index 0b9d8c9fe40..403d5089839 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -1,21 +1,27 @@ -use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::PyObject; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyErr_WarnEx")] - 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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyErr_WarnEx")] + 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] -#[cfg_attr(PyPy, link_name="PyPyErr_Warn")] +#[cfg_attr(PyPy, link_name = "PyPyErr_Warn")] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) -} \ No newline at end of file +} diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index 44167c9f26c..6e7b3b045dc 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -1,13 +1,13 @@ -use std::os::raw::{c_int, c_long}; -use ffi2::pyport::Py_ssize_t; use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_int, c_long}; #[repr(C)] #[derive(Copy, Clone)] pub struct PyWeakReference { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -15,32 +15,33 @@ pub struct PyWeakReference { pub wr_callback: *mut PyObject, pub hash: c_long, pub wr_prev: *mut PyWeakReference, - pub wr_next: *mut PyWeakReference + pub wr_next: *mut PyWeakReference, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { static mut _PyWeakref_RefType: PyTypeObject; static mut _PyWeakref_ProxyType: PyTypeObject; static mut _PyWeakref_CallableProxyType: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRef")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRefExact")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckProxy")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckProxy")] pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int { - ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) || - (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int + ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) + || (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int } #[inline(always)] @@ -48,23 +49,26 @@ 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" { - #[cfg_attr(PyPy, link_name="PyPyWeakref_NewRef")] - pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyWeakref_NewProxy")] - pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyWeakref_GetObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")] + pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")] + pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")] 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(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_GET_OBJECT")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_GET_OBJECT")] 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() } -} \ No newline at end of file + if Py_REFCNT(obj) > 0 { + obj + } else { + Py_None() + } +} diff --git a/src/ffi3/bltinmodule.rs b/src/ffi3/bltinmodule.rs index a995c7992b0..b4c69a51190 100644 --- a/src/ffi3/bltinmodule.rs +++ b/src/ffi3/bltinmodule.rs @@ -1,6 +1,7 @@ use ffi3::object::PyTypeObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyFilter_Type: PyTypeObject; pub static mut PyMap_Type: PyTypeObject; pub static mut PyZip_Type: PyTypeObject; diff --git a/src/ffi3/boolobject.rs b/src/ffi3/boolobject.rs index 294c10c7269..7d368d80cd9 100644 --- a/src/ffi3/boolobject.rs +++ b/src/ffi3/boolobject.rs @@ -1,22 +1,23 @@ -use std::os::raw::{c_int, c_long}; -use ffi3::object::*; use ffi3::longobject::PyLongObject; +use ffi3::object::*; +use std::os::raw::{c_int, c_long}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyBool_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; // define Py_False ((PyObject *) &_Py_ZeroStruct) - #[cfg_attr(PyPy, link_name="_PyPy_ZeroStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_ZeroStruct")] static mut _Py_FalseStruct: PyLongObject; - #[cfg_attr(PyPy, link_name="_PyPy_TrueStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyLongObject; - #[cfg_attr(PyPy, link_name="PyPyBool_FromLong")] + #[cfg_attr(PyPy, link_name = "PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyBool_Check")] -pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyBool_Check")] +pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyBool_Type) as c_int } @@ -28,4 +29,4 @@ pub unsafe fn Py_False() -> *mut PyObject { #[inline(always)] pub unsafe fn Py_True() -> *mut PyObject { &mut _Py_TrueStruct as *mut PyLongObject as *mut PyObject -} \ No newline at end of file +} diff --git a/src/ffi3/bytearrayobject.rs b/src/ffi3/bytearrayobject.rs index 733fa2476eb..8f04791c261 100644 --- a/src/ffi3/bytearrayobject.rs +++ b/src/ffi3/bytearrayobject.rs @@ -1,40 +1,39 @@ -use std::os::raw::{c_char, c_int}; use ffi3::object::*; use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyByteArray_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyByteArray_Check")] -pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { - #[cfg_attr(PyPy, link_name="PyPyObject_Type")] +#[cfg_attr(PyPy, link_name = "PyPyByteArray_Check")] +pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int { + #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] PyObject_TypeCheck(op, &mut PyByteArray_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyByteArray_CheckExact")] -pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyByteArray_CheckExact")] +pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyByteArray_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyByteArray_FromObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyByteArray_Concat")] - pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyByteArray_FromStringAndSize")] - pub fn PyByteArray_FromStringAndSize(string: *const c_char, - len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyByteArray_Size")] + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Concat")] + pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromStringAndSize")] + pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyByteArray_AsString")] + #[cfg_attr(PyPy, link_name = "PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name="PyPyByteArray_Resize")] - pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) - -> c_int; -} \ No newline at end of file + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Resize")] + pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; +} diff --git a/src/ffi3/bytesobject.rs b/src/ffi3/bytesobject.rs index 495fa33b9eb..b9fbdaa6e9f 100644 --- a/src/ffi3/bytesobject.rs +++ b/src/ffi3/bytesobject.rs @@ -1,53 +1,56 @@ -use std::os::raw::{c_char, c_int}; use ffi3::object::*; use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyBytes_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBytes_Type")] pub static mut PyBytes_Type: PyTypeObject; pub static mut PyBytesIter_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyBytes_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyBytes_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) } #[inline(always)] -pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyBytes_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyBytes_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyBytes_FromStringAndSize")] - pub fn PyBytes_FromStringAndSize(arg1: *const c_char, - arg2: Py_ssize_t) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBytes_FromStringAndSize")] + pub fn PyBytes_FromStringAndSize(arg1: *const c_char, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBytes_FromObject")] + #[cfg_attr(PyPy, link_name = "PyPyBytes_FromObject")] pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBytes_FromFormat")] - #[cfg_attr(PyPy, link_name="PyPyBytes_FromFormatV")] + #[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormat")] + #[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormatV")] //pub fn PyBytes_FromFormatV(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; - pub fn PyBytes_FromFormat(arg1: *const c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBytes_Size")] + pub fn PyBytes_FromFormat(arg1: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBytes_Size")] pub fn PyBytes_Size(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyBytes_AsString")] + #[cfg_attr(PyPy, link_name = "PyPyBytes_AsString")] pub fn PyBytes_AsString(arg1: *mut PyObject) -> *mut c_char; - pub fn PyBytes_Repr(arg1: *mut PyObject, arg2: c_int) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBytes_Concat")] - pub fn PyBytes_Concat(arg1: *mut *mut PyObject, arg2: *mut PyObject) - -> (); - #[cfg_attr(PyPy, link_name="PyPyBytes_ConcatAndDel")] - pub fn PyBytes_ConcatAndDel(arg1: *mut *mut PyObject, arg2: *mut PyObject) - -> (); - pub fn PyBytes_DecodeEscape(arg1: *const c_char, arg2: Py_ssize_t, - arg3: *const c_char, arg4: Py_ssize_t, - arg5: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyBytes_AsStringAndSize")] - pub fn PyBytes_AsStringAndSize(obj: *mut PyObject, - s: *mut *mut c_char, - len: *mut Py_ssize_t) -> c_int; -} \ No newline at end of file + pub fn PyBytes_Repr(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBytes_Concat")] + pub fn PyBytes_Concat(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name = "PyPyBytes_ConcatAndDel")] + pub fn PyBytes_ConcatAndDel(arg1: *mut *mut PyObject, arg2: *mut PyObject) -> (); + pub fn PyBytes_DecodeEscape( + arg1: *const c_char, + arg2: Py_ssize_t, + arg3: *const c_char, + arg4: Py_ssize_t, + arg5: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBytes_AsStringAndSize")] + pub fn PyBytes_AsStringAndSize( + obj: *mut PyObject, + s: *mut *mut c_char, + len: *mut Py_ssize_t, + ) -> c_int; +} diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 51f16694131..32a31dec3fd 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -1,15 +1,17 @@ -use std::os::raw::{c_void, c_char, c_int}; -use ffi3::object::PyObject; -use ffi3::pystate::PyThreadState; #[cfg(Py_3_6)] use ffi3::code::FreeFunc; +use ffi3::object::PyObject; +use ffi3::pystate::PyThreadState; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyEval_CallObjectWithKeywords")] - pub fn PyEval_CallObjectWithKeywords(func: *mut PyObject, - obj: *mut PyObject, - kwargs: *mut PyObject) - -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_CallObjectWithKeywords")] + pub fn PyEval_CallObjectWithKeywords( + func: *mut PyObject, + obj: *mut PyObject, + kwargs: *mut PyObject, + ) -> *mut PyObject; } #[inline] @@ -17,71 +19,73 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut PyEval_CallObjectWithKeywords(func, arg, ::std::ptr::null_mut()) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyEval_CallFunction")] - pub fn PyEval_CallFunction(obj: *mut PyObject, - format: *const c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_CallMethod")] - pub fn PyEval_CallMethod(obj: *mut PyObject, - methodname: *const c_char, - format: *const c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_GetBuiltins")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_CallFunction")] + pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_CallMethod")] + pub fn PyEval_CallMethod( + obj: *mut PyObject, + methodname: *const c_char, + format: *const c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_GetGlobals")] + #[cfg_attr(PyPy, link_name = "PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_GetLocals")] + #[cfg_attr(PyPy, link_name = "PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut ::ffi3::PyFrameObject; - #[cfg_attr(PyPy, link_name="PyPy_AddPendingCall")] - pub fn Py_AddPendingCall(func: Option c_int>, - arg: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_MakePendingCalls")] + #[cfg_attr(PyPy, link_name = "PyPy_AddPendingCall")] + pub fn Py_AddPendingCall( + func: Option c_int>, + arg: *mut c_void, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_SetRecursionLimit")] + #[cfg_attr(PyPy, link_name = "PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int) -> (); - #[cfg_attr(PyPy, link_name="PyPy_GetRecursionLimit")] + #[cfg_attr(PyPy, link_name = "PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; static mut _Py_CheckRecursionLimit: c_int; } -#[cfg_attr(PyPy, link_name="PyPy_EnterRecursiveCall")] +#[cfg_attr(PyPy, link_name = "PyPy_EnterRecursiveCall")] // TODO: Py_EnterRecursiveCall etc. - #[cfg(Py_3_6)] pub type _PyFrameEvalFunction = extern "C" fn(*mut ::ffi3::PyFrameObject, c_int) -> *mut PyObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyEval_GetFuncName(arg1: *mut PyObject) -> *const c_char; pub fn PyEval_GetFuncDesc(arg1: *mut PyObject) -> *const c_char; pub fn PyEval_GetCallStats(arg1: *mut PyObject) -> *mut PyObject; pub fn PyEval_EvalFrame(arg1: *mut ::ffi3::PyFrameObject) -> *mut PyObject; #[cfg(Py_3_6)] - pub fn _PyEval_EvalFrameDefault(arg1: *mut ::ffi3::PyFrameObject, - exc: c_int) -> *mut PyObject; + pub fn _PyEval_EvalFrameDefault(arg1: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; #[cfg(Py_3_6)] pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int; - pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyEval_SaveThread")] + pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyEval_RestoreThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState) -> (); } #[cfg(py_sys_config = "WITH_THREAD")] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyEval_ThreadsInitialized")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyEval_InitThreads")] + #[cfg_attr(PyPy, link_name = "PyPyEval_InitThreads")] pub fn PyEval_InitThreads() -> (); pub fn PyEval_AcquireLock() -> (); pub fn PyEval_ReleaseLock() -> (); - #[cfg_attr(PyPy, link_name="PyPyEval_AcquireThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState) -> (); - #[cfg_attr(PyPy, link_name="PyPyEval_ReleaseThread")] + #[cfg_attr(PyPy, link_name = "PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState) -> (); pub fn PyEval_ReInitThreads() -> (); -} \ No newline at end of file +} diff --git a/src/ffi3/code.rs b/src/ffi3/code.rs index 818fa07405c..a344d20a8bd 100644 --- a/src/ffi3/code.rs +++ b/src/ffi3/code.rs @@ -1,6 +1,6 @@ -use std::os::raw::{c_void, c_uchar, c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_uchar, c_void}; #[repr(C)] #[derive(Copy, Clone)] @@ -32,78 +32,97 @@ pub struct PyCodeObject { } impl Default for PyCodeObject { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } /* Masks for co_flags */ -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; +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_NOFREE: c_int = 0x0040; /* The CO_COROUTINE flag is set for coroutine functions (defined with - ``async def`` keywords) */ -pub const CO_COROUTINE : c_int = 0x0080; -pub const CO_ITERABLE_COROUTINE : c_int = 0x0100; -pub const CO_ASYNC_GENERATOR : c_int = 0x0200; +``async def`` keywords) */ +pub const CO_COROUTINE: c_int = 0x0080; +pub const CO_ITERABLE_COROUTINE: c_int = 0x0100; +pub const CO_ASYNC_GENERATOR: c_int = 0x0200; -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_FUTURE_BARRY_AS_BDFL : c_int = 0x4_0000; -pub const CO_FUTURE_GENERATOR_STOP : c_int = 0x8_0000; +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_FUTURE_BARRY_AS_BDFL: c_int = 0x4_0000; +pub const CO_FUTURE_GENERATOR_STOP: c_int = 0x8_0000; pub const CO_MAXBLOCKS: usize = 20; #[cfg(Py_3_6)] pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyCode_Type: PyTypeObject; #[cfg(Py_3_6)] - pub fn _PyCode_GetExtra(code: *mut PyObject, index: Py_ssize_t, - extra: *const *mut c_void) -> c_int; + pub fn _PyCode_GetExtra( + code: *mut PyObject, + index: Py_ssize_t, + extra: *const *mut c_void, + ) -> c_int; #[cfg(Py_3_6)] - pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, - extra: *mut c_void) -> c_int; + pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCode_New")] - pub fn PyCode_New(arg1: c_int, arg2: c_int, - arg3: c_int, arg4: c_int, - arg5: c_int, arg6: *mut PyObject, - arg7: *mut PyObject, arg8: *mut PyObject, - arg9: *mut PyObject, arg10: *mut PyObject, - arg11: *mut PyObject, arg12: *mut PyObject, - arg13: *mut PyObject, arg14: c_int, - arg15: *mut PyObject) -> *mut PyCodeObject; - #[cfg_attr(PyPy, link_name="PyPyCode_NewEmpty")] - pub fn PyCode_NewEmpty(filename: *const c_char, - funcname: *const c_char, - firstlineno: c_int) -> *mut PyCodeObject; - pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) - -> c_int; - pub fn PyCode_Optimize(code: *mut PyObject, consts: *mut PyObject, - names: *mut PyObject, lnotab: *mut PyObject) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCode_New")] + pub fn PyCode_New( + arg1: c_int, + arg2: c_int, + arg3: c_int, + arg4: c_int, + arg5: c_int, + arg6: *mut PyObject, + arg7: *mut PyObject, + arg8: *mut PyObject, + arg9: *mut PyObject, + arg10: *mut PyObject, + arg11: *mut PyObject, + arg12: *mut PyObject, + arg13: *mut PyObject, + arg14: c_int, + arg15: *mut PyObject, + ) -> *mut PyCodeObject; + #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] + pub fn PyCode_NewEmpty( + filename: *const c_char, + funcname: *const c_char, + firstlineno: c_int, + ) -> *mut PyCodeObject; + pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int; + pub fn PyCode_Optimize( + code: *mut PyObject, + consts: *mut PyObject, + names: *mut PyObject, + lnotab: *mut PyObject, + ) -> *mut PyObject; } #[inline] -#[cfg_attr(PyPy, link_name="PyPyCode_Check")] -pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyCode_Check")] +pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCode_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name="PyPyCode_GetNumFree")] -pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { +#[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")] +pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { ::ffi3::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) -} \ No newline at end of file +} diff --git a/src/ffi3/codecs.rs b/src/ffi3/codecs.rs index 187e26922ca..339f27c4c80 100644 --- a/src/ffi3/codecs.rs +++ b/src/ffi3/codecs.rs @@ -1,43 +1,47 @@ -use std::os::raw::{c_char, c_int}; use ffi3::object::PyObject; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] +#[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub fn PyCodec_Register(search_function: *mut PyObject) -> c_int; - pub fn PyCodec_KnownEncoding(encoding: *const c_char) - -> c_int; - pub fn PyCodec_Encode(object: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - pub fn PyCodec_Decode(object: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; + pub fn PyCodec_KnownEncoding(encoding: *const c_char) -> c_int; + pub fn PyCodec_Encode( + object: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyCodec_Decode( + object: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; pub fn PyCodec_Encoder(encoding: *const c_char) -> *mut PyObject; pub fn PyCodec_Decoder(encoding: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCodec_IncrementalEncoder")] - pub fn PyCodec_IncrementalEncoder(encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCodec_IncrementalDecoder")] - pub fn PyCodec_IncrementalDecoder(encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; - pub fn PyCodec_StreamReader(encoding: *const c_char, - stream: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; - pub fn PyCodec_StreamWriter(encoding: *const c_char, - stream: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; - pub fn PyCodec_RegisterError(name: *const c_char, - error: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCodec_IncrementalEncoder")] + pub fn PyCodec_IncrementalEncoder( + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCodec_IncrementalDecoder")] + pub fn PyCodec_IncrementalDecoder( + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyCodec_StreamReader( + encoding: *const c_char, + stream: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyCodec_StreamWriter( + encoding: *const c_char, + stream: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyCodec_RegisterError(name: *const c_char, error: *mut PyObject) -> c_int; pub fn PyCodec_LookupError(name: *const c_char) -> *mut PyObject; pub fn PyCodec_StrictErrors(exc: *mut PyObject) -> *mut PyObject; pub fn PyCodec_IgnoreErrors(exc: *mut PyObject) -> *mut PyObject; pub fn PyCodec_ReplaceErrors(exc: *mut PyObject) -> *mut PyObject; - pub fn PyCodec_XMLCharRefReplaceErrors(exc: *mut PyObject) - -> *mut PyObject; - pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject) - -> *mut PyObject; -} \ No newline at end of file + pub fn PyCodec_XMLCharRefReplaceErrors(exc: *mut PyObject) -> *mut PyObject; + pub fn PyCodec_BackslashReplaceErrors(exc: *mut PyObject) -> *mut PyObject; +} diff --git a/src/ffi3/compile.rs b/src/ffi3/compile.rs index 50fbeab2d0f..2dc87179078 100644 --- a/src/ffi3/compile.rs +++ b/src/ffi3/compile.rs @@ -1,8 +1,8 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::object::PyObject; -use ffi3::pythonrun::*; use ffi3::code::*; +use ffi3::object::PyObject; use ffi3::pyarena::*; +use ffi3::pythonrun::*; +use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] @@ -13,47 +13,55 @@ pub struct PyFutureFeatures { } #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_NESTED_SCOPES : &str = "nested_scopes"; +pub const FUTURE_NESTED_SCOPES: &str = "nested_scopes"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_GENERATORS : &str = "generators"; +pub const FUTURE_GENERATORS: &str = "generators"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_DIVISION : &str = "division"; +pub const FUTURE_DIVISION: &str = "division"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_ABSOLUTE_IMPORT : &str = "absolute_import"; +pub const FUTURE_ABSOLUTE_IMPORT: &str = "absolute_import"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_WITH_STATEMENT : &str = "with_statement"; +pub const FUTURE_WITH_STATEMENT: &str = "with_statement"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_PRINT_FUNCTION : &str = "print_function"; +pub const FUTURE_PRINT_FUNCTION: &str = "print_function"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_UNICODE_LITERALS : &str = "unicode_literals"; +pub const FUTURE_UNICODE_LITERALS: &str = "unicode_literals"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_BARRY_AS_BDFL : &str = "barry_as_FLUFL"; +pub const FUTURE_BARRY_AS_BDFL: &str = "barry_as_FLUFL"; #[cfg(not(Py_LIMITED_API))] -pub const FUTURE_GENERATOR_STOP : &str = "generator_stop"; +pub const FUTURE_GENERATOR_STOP: &str = "generator_stop"; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyNode_Compile(arg1: *mut _node, arg2: *const c_char) -> *mut PyCodeObject; - pub fn PyAST_CompileEx(_mod: *mut _mod, - filename: *const c_char, - flags: *mut PyCompilerFlags, - optimize: c_int, arena: *mut PyArena) -> *mut PyCodeObject; + pub fn PyAST_CompileEx( + _mod: *mut _mod, + filename: *const c_char, + flags: *mut PyCompilerFlags, + optimize: c_int, + arena: *mut PyArena, + ) -> *mut PyCodeObject; - pub fn PyAST_CompileObject(_mod: *mut _mod, - filename: *mut PyObject, - flags: *mut PyCompilerFlags, - optimize: c_int, arena: *mut PyArena) -> *mut PyCodeObject; + pub fn PyAST_CompileObject( + _mod: *mut _mod, + filename: *mut PyObject, + flags: *mut PyCompilerFlags, + optimize: c_int, + arena: *mut PyArena, + ) -> *mut PyCodeObject; pub fn PyFuture_FromAST(_mod: *mut _mod, filename: *const c_char) -> *mut PyFutureFeatures; - pub fn PyFuture_FromASTObject(_mod: *mut _mod, filename: *mut PyObject) -> *mut PyFutureFeatures; + pub fn PyFuture_FromASTObject( + _mod: *mut _mod, + filename: *mut PyObject, + ) -> *mut PyFutureFeatures; - pub fn PyCompile_OpcodeStackEffect( - opcode: c_int, oparg: c_int) -> c_int; + pub fn PyCompile_OpcodeStackEffect(opcode: c_int, oparg: c_int) -> c_int; } pub const Py_single_input: c_int = 256; pub const Py_file_input: c_int = 257; pub const Py_eval_input: c_int = 258; - diff --git a/src/ffi3/complexobject.rs b/src/ffi3/complexobject.rs index fcde0dd227a..3c4866eb62a 100644 --- a/src/ffi3/complexobject.rs +++ b/src/ffi3/complexobject.rs @@ -1,29 +1,30 @@ -use std::os::raw::{c_double, c_int}; use ffi3::object::*; +use std::os::raw::{c_double, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyComplex_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyComplex_Check")] -pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyComplex_Check")] +pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyComplex_CheckExact")] -pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyComplex_CheckExact")] +pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyComplex_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyComplex_FromDoubles")] - pub fn PyComplex_FromDoubles(real: c_double, - imag: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyComplex_RealAsDouble")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")] + pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="PyPyComplex_ImagAsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; -} \ No newline at end of file +} diff --git a/src/ffi3/descrobject.rs b/src/ffi3/descrobject.rs index bec2de4a246..cfc115760ab 100644 --- a/src/ffi3/descrobject.rs +++ b/src/ffi3/descrobject.rs @@ -1,11 +1,10 @@ -use std::ptr; -use std::os::raw::{c_void, c_char, c_int}; +use ffi3::methodobject::PyMethodDef; use ffi3::object::{PyObject, PyTypeObject}; use ffi3::structmember::PyMemberDef; -use ffi3::methodobject::PyMethodDef; +use std::os::raw::{c_char, c_int, c_void}; +use std::ptr; -pub type getter = - unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; +pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; pub type setter = unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int; @@ -20,7 +19,7 @@ pub struct PyGetSetDef { pub closure: *mut c_void, } -pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { +pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef { name: ptr::null_mut(), get: None, set: None, @@ -28,30 +27,31 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { closure: ptr::null_mut(), }; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyClassMethodDescr_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyClassMethodDescr_Type")] pub static mut PyClassMethodDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyGetSetDescr_Type")] + #[cfg_attr(PyPy, link_name = "PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyMemberDescr_Type")] + #[cfg_attr(PyPy, link_name = "PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyMethodDescr_Type")] + #[cfg_attr(PyPy, link_name = "PyPyMethodDescr_Type")] pub static mut PyMethodDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyWrapperDescr_Type")] + #[cfg_attr(PyPy, link_name = "PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyDictProxy_Type")] + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDescr_NewClassMethod")] - pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject, - arg2: *mut PyMethodDef) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDescr_NewClassMethod")] + 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; - #[cfg_attr(PyPy, link_name="PyPyDictProxy_New")] + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject; pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyProperty_Type")] + #[cfg_attr(PyPy, link_name = "PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; -} \ No newline at end of file +} diff --git a/src/ffi3/dictobject.rs b/src/ffi3/dictobject.rs index 9efa244997c..e37e1515405 100644 --- a/src/ffi3/dictobject.rs +++ b/src/ffi3/dictobject.rs @@ -1,8 +1,9 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -13,72 +14,80 @@ use ffi3::object::*; } #[inline(always)] -pub unsafe fn PyDict_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) } #[inline(always)] -pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyDict_Type) as c_int } #[inline(always)] -pub unsafe fn PyDictKeys_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyDictKeys_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyDictKeys_Type) as c_int } #[inline(always)] -pub unsafe fn PyDictItems_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyDictItems_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyDictItems_Type) as c_int } #[inline(always)] -pub unsafe fn PyDictValues_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyDictValues_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyDictValues_Type) as c_int } #[inline(always)] -pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyDictViewSet_Check(op: *mut PyObject) -> c_int { (PyDictKeys_Check(op) != 0 || PyDictItems_Check(op) != 0) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyDict_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_GetItem")] + #[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_SetItem")] + #[cfg_attr(PyPy, link_name = "PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_DelItem")] + #[cfg_attr(PyPy, link_name = "PyPyDict_DelItem")] pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_Clear")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyDict_Next")] - pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, - key: *mut *mut PyObject, value: *mut *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_Keys")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Next")] + pub fn PyDict_Next( + mp: *mut PyObject, + pos: *mut Py_ssize_t, + key: *mut *mut PyObject, + value: *mut *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Values")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Items")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Size")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyDict_Copy")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_Contains")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Contains")] pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_Update")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Update")] pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_Merge")] + #[cfg_attr(PyPy, link_name = "PyPyDict_Merge")] 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; - #[cfg_attr(PyPy, link_name="PyPyDict_GetItemString")] + #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemString")] pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyDict_SetItemString")] - pub fn PyDict_SetItemString(dp: *mut PyObject, key: *const c_char, - item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyDict_DelItemString")] + #[cfg_attr(PyPy, link_name = "PyPyDict_SetItemString")] + pub fn PyDict_SetItemString( + dp: *mut PyObject, + key: *const c_char, + item: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")] pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; -} \ No newline at end of file +} diff --git a/src/ffi3/enumobject.rs b/src/ffi3/enumobject.rs index 21b554fa383..08401f12801 100644 --- a/src/ffi3/enumobject.rs +++ b/src/ffi3/enumobject.rs @@ -1,7 +1,7 @@ use ffi3::object::PyTypeObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyEnum_Type: PyTypeObject; pub static mut PyReversed_Type: PyTypeObject; } - diff --git a/src/ffi3/eval.rs b/src/ffi3/eval.rs index 3ee9ecdecc8..2df15eedb20 100644 --- a/src/ffi3/eval.rs +++ b/src/ffi3/eval.rs @@ -1,14 +1,25 @@ -use std::os::raw::c_int; use ffi3::object::PyObject; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyEval_EvalCode")] - pub fn PyEval_EvalCode(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; - pub fn PyEval_EvalCodeEx(co: *mut PyObject, globals: *mut PyObject, - locals: *mut PyObject, args: *mut *mut PyObject, - argc: c_int, kwds: *mut *mut PyObject, - kwdc: c_int, defs: *mut *mut PyObject, - defc: c_int, kwdefs: *mut PyObject, - closure: *mut PyObject) -> *mut PyObject; -} \ No newline at end of file +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_EvalCode")] + pub fn PyEval_EvalCode( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> *mut PyObject; + pub fn PyEval_EvalCodeEx( + co: *mut PyObject, + globals: *mut PyObject, + locals: *mut PyObject, + args: *mut *mut PyObject, + argc: c_int, + kwds: *mut *mut PyObject, + kwdc: c_int, + defs: *mut *mut PyObject, + defc: c_int, + kwdefs: *mut PyObject, + closure: *mut PyObject, + ) -> *mut PyObject; +} diff --git a/src/ffi3/fileobject.rs b/src/ffi3/fileobject.rs index db9011d2b26..ffadceddba5 100644 --- a/src/ffi3/fileobject.rs +++ b/src/ffi3/fileobject.rs @@ -1,27 +1,29 @@ -use std::os::raw::{c_char, c_int}; use ffi3::object::PyObject; +use std::os::raw::{c_char, c_int}; + +pub const PY_STDIOTEXTMODE: &str = "b"; -pub const PY_STDIOTEXTMODE : &str = "b"; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyFile_FromFd( + arg1: c_int, + arg2: *const c_char, + arg3: *const c_char, + arg4: c_int, + arg5: *const c_char, + arg6: *const c_char, + arg7: *const c_char, + arg8: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFile_GetLine")] + pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFile_WriteObject")] + pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyFile_WriteString")] + pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyFile_FromFd(arg1: c_int, arg2: *const c_char, - arg3: *const c_char, arg4: c_int, - arg5: *const c_char, - arg6: *const c_char, - arg7: *const c_char, arg8: c_int) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFile_GetLine")] - pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFile_WriteObject")] - pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyFile_WriteString")] - pub fn PyFile_WriteString(arg1: *const c_char, - arg2: *mut PyObject) -> c_int; - pub static mut Py_FileSystemDefaultEncoding: *const c_char; #[cfg(Py_3_6)] pub static mut Py_FileSystemDefaultEncodeErrors: *const c_char; pub static mut Py_HasFileSystemDefaultEncoding: c_int; -} \ No newline at end of file +} diff --git a/src/ffi3/floatobject.rs b/src/ffi3/floatobject.rs index a9c574d90ef..4a84d435fbd 100644 --- a/src/ffi3/floatobject.rs +++ b/src/ffi3/floatobject.rs @@ -1,31 +1,33 @@ -use std::os::raw::{c_int, c_double}; use ffi3::object::*; +use std::os::raw::{c_double, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFloat_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyFloat_Check")] -pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyFloat_Check")] +pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyFloat_CheckExact")] -pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyFloat_CheckExact")] +pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFloat_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyFloat_GetMax() -> c_double; pub fn PyFloat_GetMin() -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFloat_FromString")] + #[cfg_attr(PyPy, link_name = "PyPyFloat_FromString")] pub fn PyFloat_FromString(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFloat_FromDouble")] + #[cfg_attr(PyPy, link_name = "PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(arg1: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFloat_AsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(arg1: *mut PyObject) -> c_double; -} \ No newline at end of file +} diff --git a/src/ffi3/frameobject.rs b/src/ffi3/frameobject.rs index e3c411ed998..884c2e081e2 100644 --- a/src/ffi3/frameobject.rs +++ b/src/ffi3/frameobject.rs @@ -1,71 +1,82 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::object::*; use ffi3::code::{PyCodeObject, CO_MAXBLOCKS}; +use ffi3::object::*; use ffi3::pystate::PyThreadState; +use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTryBlock { - pub b_type : c_int, - pub b_handler : c_int, - pub b_level : c_int, + pub b_type: c_int, + pub b_handler: c_int, + pub b_level: c_int, } #[repr(C)] #[derive(Copy, Clone)] pub struct PyFrameObject { pub ob_base: PyVarObject, - 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 */ + 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. */ + 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_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_gen: *mut PyObject, - pub f_lasti: c_int, /* Last instruction if called */ + 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_executing: c_char, /* whether the frame is still executing */ + 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_executing: c_char, /* whether the frame is still executing */ pub f_blockstack: [PyTryBlock; CO_MAXBLOCKS], /* for try and loop blocks */ - pub f_localsplus: [*mut PyObject; 1] /* locals+stack, dynamically sized */ + pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyFrame_Type: PyTypeObject; } #[inline] pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyFrame_Type) as c_int + (Py_TYPE(op) == &mut PyFrame_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyFrame_New")] - pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, - globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFrame_New")] + pub fn PyFrame_New( + tstate: *mut PyThreadState, + code: *mut PyCodeObject, + globals: *mut PyObject, + locals: *mut PyObject, + ) -> *mut PyFrameObject; - pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int) -> (); + pub fn PyFrame_BlockSetup( + f: *mut PyFrameObject, + _type: c_int, + handler: c_int, + level: c_int, + ) -> (); pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock; pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> (); pub fn PyFrame_FastToLocalsWithError(f: *mut PyFrameObject) -> c_int; pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> (); - + pub fn PyFrame_ClearFreeList() -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; -} \ No newline at end of file +} diff --git a/src/ffi3/genobject.rs b/src/ffi3/genobject.rs index ad236fb041b..7e623b92bc1 100644 --- a/src/ffi3/genobject.rs +++ b/src/ffi3/genobject.rs @@ -1,55 +1,59 @@ -use std::os::raw::c_int; -use ffi3::pyport::Py_ssize_t; -use ffi3::object::*; use ffi3::frameobject::PyFrameObject; +use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[derive(Copy, Clone)] pub struct PyGenObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub gi_weakreflist: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyGen_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyGen_Check")] +#[cfg_attr(PyPy, link_name = "PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { - PyObject_TypeCheck(op, &mut PyGen_Type) + PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyGen_CheckExact")] +#[cfg_attr(PyPy, link_name = "PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyGen_Type) as c_int + (Py_TYPE(op) == &mut PyGen_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject; pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int; } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyCoro_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyCoro_Check")] +#[cfg_attr(PyPy, link_name = "PyPyCoro_Check")] pub unsafe fn PyCoro_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyCoro_Type) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut _PyCoroWrapper_Type: PyTypeObject; } @@ -59,7 +63,8 @@ pub unsafe fn PyCoroWrapper_Check(op: *mut PyObject) -> c_int { } #[cfg(Py_3_6)] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyAsyncGen_Type: PyTypeObject; } @@ -73,4 +78,4 @@ pub unsafe fn PyAsyncGen_Check(op: *mut PyObject) -> c_int { #[inline(always)] pub unsafe fn PyAsyncGen_Check(_op: *mut PyObject) -> c_int { 0 -} \ No newline at end of file +} diff --git a/src/ffi3/import.rs b/src/ffi3/import.rs index 9801c577a16..6f2365f26a2 100644 --- a/src/ffi3/import.rs +++ b/src/ffi3/import.rs @@ -1,76 +1,79 @@ -use std::os::raw::{c_char, c_int, c_long}; use ffi3::object::PyObject; +use std::os::raw::{c_char, c_int, c_long}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyImport_GetMagicNumber() -> c_long; pub fn PyImport_GetMagicTag() -> *const c_char; - #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModule")] - pub fn PyImport_ExecCodeModule(name: *const c_char, - co: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ExecCodeModuleEx")] - pub fn PyImport_ExecCodeModuleEx(name: *const c_char, - co: *mut PyObject, - pathname: *const c_char) - -> *mut PyObject; - pub fn PyImport_ExecCodeModuleWithPathnames(name: *const c_char, - co: *mut PyObject, - pathname: - *const c_char, - cpathname: - *const c_char) - -> *mut PyObject; - pub fn PyImport_ExecCodeModuleObject(name: *mut PyObject, - co: *mut PyObject, - pathname: *mut PyObject, - cpathname: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_GetModuleDict")] + #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModule")] + pub fn PyImport_ExecCodeModule(name: *const c_char, co: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModuleEx")] + pub fn PyImport_ExecCodeModuleEx( + name: *const c_char, + co: *mut PyObject, + pathname: *const c_char, + ) -> *mut PyObject; + pub fn PyImport_ExecCodeModuleWithPathnames( + name: *const c_char, + co: *mut PyObject, + pathname: *const c_char, + cpathname: *const c_char, + ) -> *mut PyObject; + pub fn PyImport_ExecCodeModuleObject( + name: *mut PyObject, + co: *mut PyObject, + pathname: *mut PyObject, + cpathname: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_AddModule")] + #[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ImportModule")] - pub fn PyImport_ImportModule(name: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleNoBlock")] - pub fn PyImport_ImportModuleNoBlock(name: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleLevel")] - pub fn PyImport_ImportModuleLevel(name: *const c_char, - globals: *mut PyObject, - locals: *mut PyObject, - fromlist: *mut PyObject, - level: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ImportModuleLevelObject")] - pub fn PyImport_ImportModuleLevelObject(name: *mut PyObject, - globals: *mut PyObject, - locals: *mut PyObject, - fromlist: *mut PyObject, - level: c_int) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")] + pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")] + pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleLevel")] + pub fn PyImport_ImportModuleLevel( + name: *const c_char, + globals: *mut PyObject, + locals: *mut PyObject, + fromlist: *mut PyObject, + level: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleLevelObject")] + pub fn PyImport_ImportModuleLevelObject( + name: *mut PyObject, + globals: *mut PyObject, + locals: *mut PyObject, + fromlist: *mut PyObject, + level: c_int, + ) -> *mut PyObject; } #[inline] -pub unsafe fn PyImport_ImportModuleEx(name: *const c_char, - globals: *mut PyObject, - locals: *mut PyObject, - fromlist: *mut PyObject) - -> *mut PyObject { +pub unsafe fn PyImport_ImportModuleEx( + name: *const c_char, + globals: *mut PyObject, + locals: *mut PyObject, + fromlist: *mut PyObject, +) -> *mut PyObject { PyImport_ImportModuleLevel(name, globals, locals, fromlist, 0) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyImport_ReloadModule")] + #[cfg_attr(PyPy, link_name = "PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; pub fn PyImport_Cleanup() -> (); - pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) - -> c_int; - pub fn PyImport_ImportFrozenModule(name: *const c_char) - -> c_int; + pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) -> c_int; + pub fn PyImport_ImportFrozenModule(name: *const c_char) -> c_int; - pub fn PyImport_AppendInittab(name: *const c_char, - initfunc: Option *mut PyObject>) - -> c_int; -} \ No newline at end of file + pub fn PyImport_AppendInittab( + name: *const c_char, + initfunc: Option *mut PyObject>, + ) -> c_int; +} diff --git a/src/ffi3/intrcheck.rs b/src/ffi3/intrcheck.rs index 0dc2a0d9f42..4e1e30881af 100644 --- a/src/ffi3/intrcheck.rs +++ b/src/ffi3/intrcheck.rs @@ -1,9 +1,10 @@ use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyOS_InterruptOccurred")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyOS_InterruptOccurred")] pub fn PyOS_InterruptOccurred() -> c_int; pub fn PyOS_InitInterrupts() -> (); - #[cfg_attr(PyPy, link_name="PyPyOS_AfterFork")] + #[cfg_attr(PyPy, link_name = "PyPyOS_AfterFork")] pub fn PyOS_AfterFork() -> (); -} \ No newline at end of file +} diff --git a/src/ffi3/iterobject.rs b/src/ffi3/iterobject.rs index f0f04c1f91a..16e57a46a79 100644 --- a/src/ffi3/iterobject.rs +++ b/src/ffi3/iterobject.rs @@ -1,15 +1,15 @@ -use std::os::raw::c_int; use ffi3::object::*; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPySeqIter_New")] + #[cfg_attr(PyPy, link_name = "PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCallIter_New")] - pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCallIter_New")] + pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } #[inline(always)] diff --git a/src/ffi3/listobject.rs b/src/ffi3/listobject.rs index 48f3a520608..65057b98f87 100644 --- a/src/ffi3/listobject.rs +++ b/src/ffi3/listobject.rs @@ -1,47 +1,56 @@ -use std::os::raw::c_int; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyList_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; pub static mut PyListIter_Type: PyTypeObject; pub static mut PyListRevIter_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyList_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyList_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) } #[inline(always)] -pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyList_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyList_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyList_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyList_Size")] + #[cfg_attr(PyPy, link_name = "PyPyList_Size")] pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyList_GetItem")] + #[cfg_attr(PyPy, link_name = "PyPyList_GetItem")] pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyList_SetItem")] + #[cfg_attr(PyPy, link_name = "PyPyList_SetItem")] pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Insert")] + #[cfg_attr(PyPy, link_name = "PyPyList_Insert")] pub fn PyList_Insert(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Append")] + #[cfg_attr(PyPy, link_name = "PyPyList_Append")] pub fn PyList_Append(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_GetSlice")] - pub fn PyList_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyList_SetSlice")] - pub fn PyList_SetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Sort")] + #[cfg_attr(PyPy, link_name = "PyPyList_GetSlice")] + pub fn PyList_GetSlice( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyList_SetSlice")] + pub fn PyList_SetSlice( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: Py_ssize_t, + arg4: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Sort")] pub fn PyList_Sort(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_Reverse")] + #[cfg_attr(PyPy, link_name = "PyPyList_Reverse")] pub fn PyList_Reverse(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyList_AsTuple")] + #[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")] pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject; -} \ No newline at end of file +} diff --git a/src/ffi3/longobject.rs b/src/ffi3/longobject.rs index 3a20b4eba84..211a4d29be7 100644 --- a/src/ffi3/longobject.rs +++ b/src/ffi3/longobject.rs @@ -1,82 +1,75 @@ -use libc::size_t; -use std::os::raw::{c_void, c_char, c_int, c_long, c_ulong, c_longlong, c_ulonglong, c_double}; use ffi3::object::*; use ffi3::pyport::Py_ssize_t; +use libc::size_t; +use std::os::raw::{c_char, c_double, c_int, c_long, c_longlong, c_ulong, c_ulonglong, c_void}; pub enum PyLongObject {} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyLong_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyLong_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyLong_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) } #[inline(always)] -pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyLong_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyLong_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyLong_FromLong")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyLong_FromLong")] pub fn PyLong_FromLong(arg1: c_long) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(arg1: c_ulong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromSize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(arg1: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromSsize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(arg1: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromDouble")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromDouble")] pub fn PyLong_FromDouble(arg1: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLong")] pub fn PyLong_AsLong(arg1: *mut PyObject) -> c_long; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLongAndOverflow")] - pub fn PyLong_AsLongAndOverflow(arg1: *mut PyObject, - arg2: *mut c_int) - -> c_long; - #[cfg_attr(PyPy, link_name="PyPyLong_AsSsize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongAndOverflow")] + pub fn PyLong_AsLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_long; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyLong_AsSize_t")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsSize_t")] pub fn PyLong_AsSize_t(arg1: *mut PyObject) -> size_t; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(arg1: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongMask")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(arg1: *mut PyObject) -> c_ulong; pub fn PyLong_GetInfo() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_AsDouble")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsDouble")] pub fn PyLong_AsDouble(arg1: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name="PyPyLong_FromVoidPtr")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(arg1: *mut c_void) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_AsVoidPtr")] + #[cfg_attr(PyPy, link_name = "PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyLong_FromLongLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(arg1: c_longlong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_FromUnsignedLongLong")] - pub fn PyLong_FromUnsignedLongLong(arg1: c_ulonglong) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLong")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLongLong")] + pub fn PyLong_FromUnsignedLongLong(arg1: c_ulonglong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(arg1: *mut PyObject) -> c_longlong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLong")] - pub fn PyLong_AsUnsignedLongLong(arg1: *mut PyObject) - -> c_ulonglong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsUnsignedLongLongMask")] - pub fn PyLong_AsUnsignedLongLongMask(arg1: *mut PyObject) - -> c_ulonglong; - #[cfg_attr(PyPy, link_name="PyPyLong_AsLongLongAndOverflow")] - pub fn PyLong_AsLongLongAndOverflow(arg1: *mut PyObject, - arg2: *mut c_int) - -> c_longlong; - #[cfg_attr(PyPy, link_name="PyPyLong_FromString")] - pub fn PyLong_FromString(arg1: *const c_char, - arg2: *mut *mut c_char, - arg3: c_int) -> *mut PyObject; - pub fn PyOS_strtoul(arg1: *const c_char, - arg2: *mut *mut c_char, arg3: c_int) - -> c_ulong; - pub fn PyOS_strtol(arg1: *const c_char, - arg2: *mut *mut c_char, arg3: c_int) - -> c_long; -} \ No newline at end of file + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLong")] + pub fn PyLong_AsUnsignedLongLong(arg1: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLongMask")] + pub fn PyLong_AsUnsignedLongLongMask(arg1: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLongAndOverflow")] + pub fn PyLong_AsLongLongAndOverflow(arg1: *mut PyObject, arg2: *mut c_int) -> c_longlong; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromString")] + pub fn PyLong_FromString( + arg1: *const c_char, + arg2: *mut *mut c_char, + arg3: c_int, + ) -> *mut PyObject; + pub fn PyOS_strtoul(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> c_ulong; + pub fn PyOS_strtol(arg1: *const c_char, arg2: *mut *mut c_char, arg3: c_int) -> c_long; +} diff --git a/src/ffi3/memoryobject.rs b/src/ffi3/memoryobject.rs index f37bec6a672..0fbff0a6d68 100644 --- a/src/ffi3/memoryobject.rs +++ b/src/ffi3/memoryobject.rs @@ -1,25 +1,32 @@ -use std::os::raw::{c_int, c_char}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMemoryView_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyMemoryView_Check")] -pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Check")] +pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyMemoryView_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMemoryView_FromMemory")] - pub fn PyMemoryView_FromMemory(mem: *mut c_char, size: Py_ssize_t, - flags: c_int) -> *mut PyObject; - pub fn PyMemoryView_GetContiguous(base: *mut PyObject, - buffertype: c_int, - order: c_char) -> *mut PyObject; -} \ No newline at end of file + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromMemory")] + pub fn PyMemoryView_FromMemory( + mem: *mut c_char, + size: Py_ssize_t, + flags: c_int, + ) -> *mut PyObject; + pub fn PyMemoryView_GetContiguous( + base: *mut PyObject, + buffertype: c_int, + order: c_char, + ) -> *mut PyObject; +} diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index 203a2f207df..e6dd18783a8 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -1,44 +1,49 @@ +use ffi3::object::{PyObject, PyTypeObject, Py_TYPE}; use std::os::raw::{c_char, c_int}; use std::{mem, ptr}; -use ffi3::object::{PyObject, PyTypeObject, Py_TYPE}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCFunction_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyCFunction_Check")] -pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyCFunction_Check")] +pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCFunction_Type) as c_int } pub type PyCFunction = - unsafe extern "C" fn (slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject; + unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject) -> *mut PyObject; #[cfg(all(Py_3_6, not(Py_LIMITED_API)))] -pub type _PyCFunctionFast = - unsafe extern "C" fn (slf: *mut PyObject, - args: *mut *mut PyObject, - nargs: ::ffi3::pyport::Py_ssize_t, - kwnames: *mut PyObject) -> *mut PyObject; - -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" { - #[cfg_attr(PyPy, link_name="PyPyCFunction_GetFunction")] +pub type _PyCFunctionFast = unsafe extern "C" fn( + slf: *mut PyObject, + args: *mut *mut PyObject, + nargs: ::ffi3::pyport::Py_ssize_t, + kwnames: *mut PyObject, +) -> *mut PyObject; + +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" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; - pub fn PyCFunction_Call(f: *mut PyObject, - args: *mut PyObject, - kwds: *mut PyObject) -> *mut PyObject; + pub fn PyCFunction_Call( + f: *mut PyObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; } #[repr(C)] @@ -50,7 +55,7 @@ pub struct PyMethodDef { pub ml_doc: *const c_char, } -pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { +pub const PyMethodDef_INIT: PyMethodDef = PyMethodDef { ml_name: ::std::ptr::null(), ml_meth: None, ml_flags: 0, @@ -58,44 +63,51 @@ pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { }; impl Default for PyMethodDef { - fn default() -> PyMethodDef { unsafe { mem::zeroed() } } + fn default() -> PyMethodDef { + unsafe { mem::zeroed() } + } } #[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { - #[cfg_attr(PyPy, link_name="PyPyCFunction_NewEx")] + #[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")] PyCFunction_NewEx(ml, slf, ptr::null_mut()) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCFunction_NewEx")] - pub fn PyCFunction_NewEx(arg1: *mut PyMethodDef, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")] + pub fn PyCFunction_NewEx( + arg1: *mut PyMethodDef, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> *mut PyObject; } /* Flag passed to newmethodobject */ -pub const METH_VARARGS : c_int = 0x0001; -pub const METH_KEYWORDS : c_int = 0x0002; +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; +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; +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. */ +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; +pub const METH_COEXIST: c_int = 0x0040; #[cfg(all(Py_3_6, not(Py_LIMITED_API)))] -pub const METHOD_FASTCALL : c_int = 0x0080; +pub const METHOD_FASTCALL: c_int = 0x0080; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyCFunction_ClearFreeList() -> c_int; -} \ No newline at end of file +} diff --git a/src/ffi3/mod.rs b/src/ffi3/mod.rs index 7f4b264034c..257db621b08 100644 --- a/src/ffi3/mod.rs +++ b/src/ffi3/mod.rs @@ -3,66 +3,67 @@ #![cfg_attr(Py_LIMITED_API, allow(unused_imports))] #![cfg_attr(feature="cargo-clippy", allow(inline_always))] -pub use self::pyport::*; pub use self::pymem::*; +pub use self::pyport::*; pub use self::object::*; pub use self::objimpl::*; -pub use self::typeslots::*; pub use self::pyhash::*; +pub use self::typeslots::*; pub use self::pydebug::*; +pub use self::boolobject::*; pub use self::bytearrayobject::*; pub use self::bytesobject::*; -pub use self::unicodeobject::*; -pub use self::longobject::*; -pub use self::boolobject::*; -pub use self::floatobject::*; pub use self::complexobject::*; -pub use self::rangeobject::*; -pub use self::memoryobject::*; -pub use self::tupleobject::*; -pub use self::listobject::*; +pub use self::descrobject::*; pub use self::dictobject::*; pub use self::enumobject::*; -pub use self::setobject::*; +pub use self::fileobject::*; +pub use self::floatobject::*; +pub use self::genobject::*; +pub use self::iterobject::*; +pub use self::listobject::*; +pub use self::longobject::*; +pub use self::memoryobject::*; pub use self::methodobject::*; pub use self::moduleobject::*; -pub use self::fileobject::*; pub use self::pycapsule::*; -pub use self::traceback::*; +pub use self::rangeobject::*; +pub use self::setobject::*; pub use self::sliceobject::*; -pub use self::iterobject::*; -pub use self::descrobject::*; +pub use self::structseq::*; +pub use self::traceback::*; +pub use self::tupleobject::*; +pub use self::unicodeobject::*; pub use self::warnings::*; pub use self::weakrefobject::*; -pub use self::structseq::*; -pub use self::genobject::*; pub use self::codecs::*; pub use self::pyerrors::*; pub use self::pystate::*; -pub use self::pyarena::*; +pub use self::ceval::*; +pub use self::import::*; +pub use self::intrcheck::*; pub use self::modsupport::*; +#[cfg(Py_3_6)] +pub use self::osmodule::*; +pub use self::pyarena::*; pub use self::pythonrun::*; -pub use self::ceval::*; pub use self::sysmodule::*; -#[cfg(Py_3_6)] pub use self::osmodule::*; -pub use self::intrcheck::*; -pub use self::import::*; -pub use self::objectabstract::*; pub use self::bltinmodule::*; +pub use self::objectabstract::*; pub use self::code::*; pub use self::compile::*; pub use self::eval::*; -pub use self::pystrtod::*; pub use self::frameobject::PyFrameObject; +pub use self::pystrtod::*; mod pyport; // mod pymacro; contains nothing of interest for Rust @@ -76,74 +77,79 @@ mod pymem; mod object; mod objimpl; -mod typeslots; -mod pyhash; mod pydebug; +mod pyhash; +mod typeslots; mod bytearrayobject; mod bytesobject; -mod unicodeobject; -mod longobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -// mod longintrepr; TODO excluded by PEP-384 +mod longobject; +mod unicodeobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 + // mod longintrepr; TODO excluded by PEP-384 mod boolobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod floatobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 mod complexobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod rangeobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod memoryobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod tupleobject; +mod dictobject; +mod floatobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 mod listobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod dictobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -// mod odictobject; TODO new in 3.5 +mod memoryobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +mod rangeobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +mod tupleobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 + // mod odictobject; TODO new in 3.5 mod enumobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod setobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 mod methodobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod moduleobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -// mod funcobject; TODO excluded by PEP-384 -// mod classobject; TODO excluded by PEP-384 +mod moduleobject; +mod setobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 + // mod funcobject; TODO excluded by PEP-384 + // mod classobject; TODO excluded by PEP-384 mod fileobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 mod pycapsule; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod traceback; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod sliceobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -// mod cellobject; TODO excluded by PEP-384 -mod iterobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod genobject; // TODO excluded by PEP-384 +mod sliceobject; +mod traceback; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 + // mod cellobject; TODO excluded by PEP-384 mod descrobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +mod genobject; // TODO excluded by PEP-384 +mod iterobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +mod structseq; mod warnings; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod weakrefobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod structseq; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -// mod namespaceobject; TODO +mod weakrefobject; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 + // mod namespaceobject; TODO mod codecs; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 mod pyerrors; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 mod pystate; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -#[cfg(Py_LIMITED_API)] mod pyarena {} -#[cfg(not(Py_LIMITED_API))] mod pyarena; // TODO: incomplete +#[cfg(Py_LIMITED_API)] +mod pyarena {} mod modsupport; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +#[cfg(not(Py_LIMITED_API))] +mod pyarena; // TODO: incomplete mod pythonrun; // TODO some functions need to be moved to pylifecycle -//mod pylifecycle; // TODO new in 3.5 + //mod pylifecycle; // TODO new in 3.5 mod ceval; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod sysmodule; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -#[cfg(Py_3_6)] mod osmodule; +mod import; mod intrcheck; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod import; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +#[cfg(Py_3_6)] +mod osmodule; +mod sysmodule; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -mod objectabstract; -mod bltinmodule; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 +mod bltinmodule; +mod objectabstract; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -#[cfg(Py_LIMITED_API)] mod code {} -#[cfg(not(Py_LIMITED_API))] mod code; +#[cfg(Py_LIMITED_API)] +mod code {} +#[cfg(not(Py_LIMITED_API))] +mod code; mod compile; // TODO: incomplete mod eval; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 // mod pyctype; TODO excluded by PEP-384 mod pystrtod; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 -// mod pystrcmp; TODO nothing interesting for Rust? -// mod dtoa; TODO excluded by PEP-384 -// mod fileutils; TODO no public functions? -// mod pyfpe; TODO probably not interesting for rust + // mod pystrcmp; TODO nothing interesting for Rust? + // mod dtoa; TODO excluded by PEP-384 + // mod fileutils; TODO no public functions? + // mod pyfpe; TODO probably not interesting for rust // Additional headers that are not exported by Python.h pub mod structmember; // TODO supports PEP-384 only; needs adjustment for Python 3.3 and 3.5 @@ -154,4 +160,3 @@ pub mod frameobject; pub mod frameobject { pub enum PyFrameObject {} } - diff --git a/src/ffi3/modsupport.rs b/src/ffi3/modsupport.rs index 2f2205261f1..e8fdf23def1 100644 --- a/src/ffi3/modsupport.rs +++ b/src/ffi3/modsupport.rs @@ -1,46 +1,56 @@ -use std::os::raw::{c_char, c_int, c_long}; -use ffi3::pyport::Py_ssize_t; -use ffi3::object::PyObject; -use ffi3::moduleobject::PyModuleDef; use ffi3::methodobject::PyMethodDef; +use ffi3::moduleobject::PyModuleDef; +use ffi3::object::PyObject; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_long}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyArg_Parse")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyArg_Parse")] pub fn PyArg_Parse(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyArg_ParseTuple")] - pub fn PyArg_ParseTuple(arg1: *mut PyObject, - arg2: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyArg_ParseTupleAndKeywords")] - pub fn PyArg_ParseTupleAndKeywords(arg1: *mut PyObject, - arg2: *mut PyObject, - arg3: *const c_char, - arg4: *mut *mut c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTuple")] + pub fn PyArg_ParseTuple(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTupleAndKeywords")] + pub fn PyArg_ParseTupleAndKeywords( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *const c_char, + arg4: *mut *mut c_char, + ... + ) -> c_int; pub fn PyArg_ValidateKeywordArguments(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyArg_UnpackTuple")] - pub fn PyArg_UnpackTuple(arg1: *mut PyObject, arg2: *const c_char, - arg3: Py_ssize_t, arg4: Py_ssize_t, ...) -> c_int; - #[cfg_attr(PyPy, link_name="PyPy_BuildValue")] + #[cfg_attr(PyPy, link_name = "PyPyArg_UnpackTuple")] + pub fn PyArg_UnpackTuple( + arg1: *mut PyObject, + arg2: *const c_char, + arg3: Py_ssize_t, + arg4: Py_ssize_t, + ... + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_BuildValue")] pub fn Py_BuildValue(arg1: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPy_BuildValue_SizeT")] + #[cfg_attr(PyPy, link_name = "_PyPy_BuildValue_SizeT")] //pub fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPy_VaBuildValue")] + #[cfg_attr(PyPy, link_name = "PyPy_VaBuildValue")] //pub fn Py_VaBuildValue(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyModule_AddObject")] - pub fn PyModule_AddObject(arg1: *mut PyObject, - arg2: *const c_char, - arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyModule_AddIntConstant")] - pub fn PyModule_AddIntConstant(arg1: *mut PyObject, - arg2: *const c_char, - arg3: c_long) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyModule_AddStringConstant")] - pub fn PyModule_AddStringConstant(arg1: *mut PyObject, - arg2: *const c_char, - arg3: *const c_char) -> c_int; - pub fn PyModule_SetDocString(arg1: *mut PyObject, - arg2: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddObject")] + pub fn PyModule_AddObject( + arg1: *mut PyObject, + arg2: *const c_char, + arg3: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddIntConstant")] + pub fn PyModule_AddIntConstant(arg1: *mut PyObject, arg2: *const c_char, arg3: c_long) + -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddStringConstant")] + pub fn PyModule_AddStringConstant( + arg1: *mut PyObject, + arg2: *const c_char, + arg3: *const c_char, + ) -> c_int; + pub fn PyModule_SetDocString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; pub fn PyModule_AddFunctions(arg1: *mut PyObject, arg2: *mut PyMethodDef) -> c_int; pub fn PyModule_ExecDef(module: *mut PyObject, def: *mut PyModuleDef) -> c_int; } @@ -50,49 +60,68 @@ pub const Py_CLEANUP_SUPPORTED: i32 = 0x2_0000; pub const PYTHON_API_VERSION: i32 = 1013; pub const PYTHON_ABI_VERSION: i32 = 3; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg(not(py_sys_config="Py_TRACE_REFS"))] - #[cfg_attr(PyPy, link_name="PyPyModule_Create2")] - pub fn PyModule_Create2(module: *mut PyModuleDef, - apiver: c_int) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg(not(py_sys_config = "Py_TRACE_REFS"))] + #[cfg_attr(PyPy, link_name = "PyPyModule_Create2")] + pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; - #[cfg(py_sys_config="Py_TRACE_REFS")] - fn PyModule_Create2TraceRefs(module: *mut PyModuleDef, - apiver: c_int) -> *mut PyObject; + #[cfg(py_sys_config = "Py_TRACE_REFS")] + fn PyModule_Create2TraceRefs(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; - #[cfg(not(py_sys_config="Py_TRACE_REFS"))] - pub fn PyModule_FromDefAndSpec2(def: *mut PyModuleDef, - spec: *mut PyObject, - module_api_version: c_int) -> *mut PyObject; + #[cfg(not(py_sys_config = "Py_TRACE_REFS"))] + pub fn PyModule_FromDefAndSpec2( + def: *mut PyModuleDef, + spec: *mut PyObject, + module_api_version: c_int, + ) -> *mut PyObject; - #[cfg(py_sys_config="Py_TRACE_REFS")] - fn PyModule_FromDefAndSpec2TraceRefs(def: *mut PyModuleDef, - spec: *mut PyObject, - module_api_version: c_int) -> *mut PyObject; + #[cfg(py_sys_config = "Py_TRACE_REFS")] + fn PyModule_FromDefAndSpec2TraceRefs( + def: *mut PyModuleDef, + spec: *mut PyObject, + module_api_version: c_int, + ) -> *mut PyObject; } -#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(py_sys_config = "Py_TRACE_REFS")] #[inline] -#[cfg_attr(PyPy, link_name="PyPyModule_Create2")] -pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, - apiver: c_int) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPyModule_Create2")] +pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { PyModule_Create2TraceRefs(module, apiver) } -#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(py_sys_config = "Py_TRACE_REFS")] #[inline] -pub unsafe fn PyModule_FromDefAndSpec2(def: *mut PyModuleDef, - spec: *mut PyObject, - module_api_version: c_int) -> *mut PyObject { +pub unsafe fn PyModule_FromDefAndSpec2( + def: *mut PyModuleDef, + spec: *mut PyObject, + module_api_version: c_int, +) -> *mut PyObject { PyModule_FromDefAndSpec2TraceRefs(def, spec, module_api_version) } #[inline] pub unsafe fn PyModule_Create(module: *mut PyModuleDef) -> *mut PyObject { - PyModule_Create2(module, if cfg!(Py_LIMITED_API) { PYTHON_ABI_VERSION } else { PYTHON_API_VERSION }) + PyModule_Create2( + module, + if cfg!(Py_LIMITED_API) { + PYTHON_ABI_VERSION + } else { + PYTHON_API_VERSION + }, + ) } #[inline] pub unsafe fn PyModule_FromDefAndSpec(def: *mut PyModuleDef, spec: *mut PyObject) -> *mut PyObject { - PyModule_FromDefAndSpec2(def, spec, if cfg!(Py_LIMITED_API) { PYTHON_ABI_VERSION } else { PYTHON_API_VERSION }) -} \ No newline at end of file + PyModule_FromDefAndSpec2( + def, + spec, + if cfg!(Py_LIMITED_API) { + PYTHON_ABI_VERSION + } else { + PYTHON_API_VERSION + }, + ) +} diff --git a/src/ffi3/moduleobject.rs b/src/ffi3/moduleobject.rs index 6650505451f..fd6b45642c9 100644 --- a/src/ffi3/moduleobject.rs +++ b/src/ffi3/moduleobject.rs @@ -1,38 +1,40 @@ -use std::os::raw::{c_char, c_int, c_void}; -use ffi3::pyport::Py_ssize_t; -use ffi3::object::*; use ffi3::methodobject::PyMethodDef; +use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyModule_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyModule_Check")] -pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyModule_Check")] +pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } #[inline(always)] -pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyModule_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyModule_GetDict")] + #[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")] 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; - #[cfg_attr(PyPy, link_name="PyPyModule_GetDef")] + #[cfg_attr(PyPy, link_name = "PyPyModule_GetDef")] pub fn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef; - #[cfg_attr(PyPy, link_name="PyPyModule_GetState")] + #[cfg_attr(PyPy, link_name = "PyPyModule_GetState")] pub fn PyModule_GetState(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyModuleDef_Init")] + #[cfg_attr(PyPy, link_name = "PyPyModuleDef_Init")] pub fn PyModuleDef_Init(arg1: *mut PyModuleDef) -> *mut PyObject; pub static mut PyModuleDef_Type: PyTypeObject; } @@ -50,7 +52,7 @@ pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base { ob_base: PyObject_HEAD_INIT, m_init: None, m_index: 0, - m_copy: ::std::ptr::null_mut() + m_copy: ::std::ptr::null_mut(), }; #[repr(C)] @@ -60,8 +62,8 @@ pub struct PyModuleDef_Slot { pub value: *mut c_void, } -pub const Py_mod_create : c_int = 1; -pub const Py_mod_exec : c_int = 2; +pub const Py_mod_create: c_int = 1; +pub const Py_mod_exec: c_int = 2; #[repr(C)] #[derive(Copy, Clone)] @@ -86,5 +88,5 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { m_slots: ::std::ptr::null_mut(), m_traverse: None, m_clear: None, - m_free: None -}; \ No newline at end of file + m_free: None, +}; diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 2848c72e751..f63a6a78c86 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -1,15 +1,15 @@ -use std::ptr; -use std::os::raw::{c_void, c_int, c_uint, c_ulong, c_char}; -use ffi3::pyport::{Py_ssize_t, Py_hash_t}; use ffi3::pyerrors::{PyErr_Format, PyExc_TypeError}; +use ffi3::pyport::{Py_hash_t, Py_ssize_t}; +use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; +use std::ptr; #[repr(C)] #[derive(Copy, Clone, Debug)] #[cfg(not(PyPy))] pub struct PyObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -24,38 +24,38 @@ pub struct PyObject { pub ob_type: *mut PyTypeObject, } -#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(py_sys_config = "Py_TRACE_REFS")] #[cfg(not(PyPy))] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), }; -#[cfg(not(py_sys_config="Py_TRACE_REFS"))] +#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] #[cfg(not(PyPy))] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), }; -#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(py_sys_config = "Py_TRACE_REFS")] #[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, ob_pypy_link: 0, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), }; -#[cfg(not(py_sys_config="Py_TRACE_REFS"))] +#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] #[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, ob_pypy_link: 0, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), }; #[repr(C)] @@ -66,7 +66,7 @@ pub struct PyVarObject { } #[inline(always)] -pub unsafe fn Py_REFCNT(ob : *mut PyObject) -> Py_ssize_t { +pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { if ob.is_null() { panic!(); } @@ -84,59 +84,61 @@ macro_rules! cstr( #[cfg(PyPy)] pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { - return PyErr_Format(PyExc_TypeError, cstr!("'%.200s' object is not iterable").as_ptr(), - Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject)) + return PyErr_Format( + PyExc_TypeError, + cstr!("'%.200s' object is not iterable").as_ptr(), + Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), + ); } #[inline(always)] -pub unsafe fn Py_TYPE(ob : *mut PyObject) -> *mut PyTypeObject { +pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject { (*ob).ob_type } #[inline(always)] -pub unsafe fn Py_SIZE(ob : *mut PyObject) -> Py_ssize_t { +pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t { (*(ob as *mut PyVarObject)).ob_size } -pub type unaryfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +pub type unaryfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type binaryfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; -pub type ternaryfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; +pub type 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 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 lenfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t; pub type ssizeargfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub type ssizessizeargfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t) -> *mut PyObject; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; pub type ssizeobjargproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; -pub type ssizessizeobjargproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; +pub type ssizessizeobjargproc = unsafe extern "C" fn( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: Py_ssize_t, + arg4: *mut PyObject, +) -> c_int; pub type objobjargproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; #[cfg(not(Py_LIMITED_API))] mod bufferinfo { - use std::os::raw::{c_void, c_int, c_char}; use ffi3::pyport::Py_ssize_t; + use std::os::raw::{c_char, c_int, c_void}; #[repr(C)] #[derive(Copy, Clone)] @@ -155,64 +157,61 @@ mod bufferinfo { } impl Default for Py_buffer { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } - pub type getbufferproc = - unsafe extern "C" fn(arg1: *mut ::ffi3::PyObject, - arg2: *mut Py_buffer, - arg3: c_int) - -> c_int; + pub type getbufferproc = unsafe extern "C" fn( + arg1: *mut ::ffi3::PyObject, + arg2: *mut Py_buffer, + arg3: c_int, + ) -> c_int; pub type releasebufferproc = - unsafe extern "C" fn(arg1: *mut ::ffi3::PyObject, - arg2: *mut Py_buffer) -> (); + unsafe extern "C" fn(arg1: *mut ::ffi3::PyObject, arg2: *mut Py_buffer) -> (); /// Maximum number of dimensions - pub const PyBUF_MAX_NDIM : c_int = 64; + pub const PyBUF_MAX_NDIM: c_int = 64; /* Flags for getting buffers */ - pub const PyBUF_SIMPLE : c_int = 0; - pub const PyBUF_WRITABLE : c_int = 0x0001; + pub const PyBUF_SIMPLE: c_int = 0; + pub const PyBUF_WRITABLE: c_int = 0x0001; /* we used to include an E, backwards compatible alias */ - pub const PyBUF_WRITEABLE : c_int = PyBUF_WRITABLE; - 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_WRITEABLE: c_int = PyBUF_WRITABLE; + 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_STRIDED : c_int = (PyBUF_STRIDES | PyBUF_WRITABLE); - pub const PyBUF_STRIDED_RO : c_int = (PyBUF_STRIDES); + pub const PyBUF_CONTIG: c_int = (PyBUF_ND | PyBUF_WRITABLE); + pub const PyBUF_CONTIG_RO: c_int = (PyBUF_ND); - 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_STRIDED: c_int = (PyBUF_STRIDES | PyBUF_WRITABLE); + pub const PyBUF_STRIDED_RO: c_int = (PyBUF_STRIDES); - pub const PyBUF_FULL : c_int = (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT); - pub const PyBUF_FULL_RO : c_int = (PyBUF_INDIRECT | PyBUF_FORMAT); + 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); - pub const PyBUF_READ : c_int = 0x100; - pub const PyBUF_WRITE : c_int = 0x200; + pub const PyBUF_READ: c_int = 0x100; + pub const PyBUF_WRITE: c_int = 0x200; } #[cfg(not(Py_LIMITED_API))] pub use self::bufferinfo::*; -pub type objobjproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type visitproc = - unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int; +pub type objobjproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type visitproc = unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int; pub type traverseproc = unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; -pub type freefunc = - unsafe extern "C" fn(arg1: *mut c_void); -pub type destructor = - unsafe extern "C" fn(arg1: *mut PyObject); +pub type freefunc = unsafe extern "C" fn(arg1: *mut c_void); +pub type destructor = unsafe extern "C" fn(arg1: *mut PyObject); #[cfg(not(Py_LIMITED_API))] pub type printfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut ::libc::FILE, arg3: c_int) -> c_int; @@ -221,44 +220,40 @@ pub type getattrfunc = pub type getattrofunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub type setattrfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, arg3: *mut PyObject) -> c_int; pub type setattrofunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; -pub type reprfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type hashfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; +pub type 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 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; + 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; + 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; #[cfg(Py_LIMITED_API)] -pub enum PyTypeObject { } +pub enum PyTypeObject {} #[cfg(not(Py_LIMITED_API))] mod typeobject { - use ffi3::{self, object}; - use std::os::raw::{c_void, c_char, c_ulong, c_uint}; use ffi3::pyport::Py_ssize_t; + use ffi3::{self, object}; + use std::os::raw::{c_char, c_uint, c_ulong, c_void}; #[repr(C)] #[derive(Copy, Clone)] @@ -302,9 +297,16 @@ mod typeobject { } impl Default for PyNumberMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } + } + macro_rules! as_expr { + ($e:expr) => { + $e + }; } - macro_rules! as_expr { ($e:expr) => {$e} } macro_rules! py_number_methods_init { ($($tail:tt)*) => { @@ -371,9 +373,12 @@ mod typeobject { } impl Default for PySequenceMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } - pub const PySequenceMethods_INIT : PySequenceMethods = PySequenceMethods { + pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods { sq_length: None, sq_concat: None, sq_repeat: None, @@ -394,9 +399,12 @@ mod typeobject { } impl Default for PyMappingMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } - pub const PyMappingMethods_INIT : PyMappingMethods = PyMappingMethods { + pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods { mp_length: None, mp_subscript: None, mp_ass_subscript: None, @@ -410,9 +418,12 @@ mod typeobject { } impl Default for PyAsyncMethods { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } - pub const PyAsyncMethods_INIT : PyAsyncMethods = PyAsyncMethods { + pub const PyAsyncMethods_INIT: PyAsyncMethods = PyAsyncMethods { am_await: None, am_aiter: None, am_anext: None, @@ -425,9 +436,12 @@ mod typeobject { } impl Default for PyBufferProcs { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } - pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs { + pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { bf_getbuffer: None, bf_releasebuffer: None, }; @@ -483,15 +497,15 @@ mod typeobject { pub tp_del: Option, pub tp_version_tag: c_uint, pub tp_finalize: Option, - #[cfg(py_sys_config="COUNT_ALLOCS")] + #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_allocs: Py_ssize_t, - #[cfg(py_sys_config="COUNT_ALLOCS")] + #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_frees: Py_ssize_t, - #[cfg(py_sys_config="COUNT_ALLOCS")] + #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_maxalloc: Py_ssize_t, - #[cfg(py_sys_config="COUNT_ALLOCS")] + #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_prev: *mut PyTypeObject, - #[cfg(py_sys_config="COUNT_ALLOCS")] + #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_next: *mut PyTypeObject, } @@ -555,7 +569,7 @@ mod typeobject { } } - #[cfg(py_sys_config="COUNT_ALLOCS")] + #[cfg(py_sys_config = "COUNT_ALLOCS")] macro_rules! py_type_object_init_with_count_allocs { ($tp_as_async:ident, $($tail:tt)*) => { py_type_object_init!($tp_as_async, @@ -569,17 +583,15 @@ mod typeobject { } } - #[cfg(not(py_sys_config="COUNT_ALLOCS"))] + #[cfg(not(py_sys_config = "COUNT_ALLOCS"))] macro_rules! py_type_object_init_with_count_allocs { ($tp_as_async:ident, $($tail:tt)*) => { py_type_object_init!($tp_as_async, $($tail)*) } } - pub const PyTypeObject_INIT: PyTypeObject = py_type_object_init_with_count_allocs!( - tp_as_async, - tp_finalize: None, - ); + pub const PyTypeObject_INIT: PyTypeObject = + py_type_object_init_with_count_allocs!(tp_as_async, tp_finalize: None,); #[repr(C)] #[derive(Copy, Clone)] @@ -597,13 +609,18 @@ mod typeobject { } impl Default for PyHeapTypeObject { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[inline] - pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi3::structmember::PyMemberDef { + pub unsafe fn PyHeapType_GET_MEMBERS( + etype: *mut PyHeapTypeObject, + ) -> *mut ffi3::structmember::PyMemberDef { (etype as *mut c_char).offset( - (*ffi3::object::Py_TYPE(etype as *mut ffi3::object::PyObject)).tp_basicsize as isize + (*ffi3::object::Py_TYPE(etype as *mut ffi3::object::PyObject)).tp_basicsize as isize, ) as *mut ffi3::structmember::PyMemberDef } } @@ -618,7 +635,9 @@ pub struct PyType_Slot { } impl Default for PyType_Slot { - fn default() -> PyType_Slot { unsafe { ::std::mem::zeroed() } } + fn default() -> PyType_Slot { + unsafe { ::std::mem::zeroed() } + } } #[repr(C)] @@ -632,22 +651,25 @@ pub struct PyType_Spec { } impl Default for PyType_Spec { - fn default() -> PyType_Spec { unsafe { ::std::mem::zeroed() } } + fn default() -> PyType_Spec { + unsafe { ::std::mem::zeroed() } + } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyType_FromSpec")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyType_FromSpec")] pub fn PyType_FromSpec(arg1: *mut PyType_Spec) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyType_FromSpecWithBases")] - pub fn PyType_FromSpecWithBases(arg1: *mut PyType_Spec, arg2: *mut PyObject) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyType_FromSpecWithBases")] + pub fn PyType_FromSpecWithBases(arg1: *mut PyType_Spec, arg2: *mut PyObject) -> *mut PyObject; pub fn PyType_GetSlot(arg1: *mut PyTypeObject, arg2: c_int) -> *mut c_void; } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyType_IsSubtype")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyType_IsSubtype")] pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } @@ -656,12 +678,13 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ (Py_TYPE(ob) == tp || PyType_IsSubtype(Py_TYPE(ob), tp) != 0) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { /// built-in 'type' - #[cfg_attr(PyPy, link_name="PyPyType_Type")] + #[cfg_attr(PyPy, link_name = "PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; /// built-in 'object' - #[cfg_attr(PyPy, link_name="PyPyBaseObject_Type")] + #[cfg_attr(PyPy, link_name = "PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; /// built-in 'super' pub static mut PySuper_Type: PyTypeObject; @@ -679,157 +702,171 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyType_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyType_Ready")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyType_GenericAlloc")] + #[cfg_attr(PyPy, link_name = "PyPyType_GenericAlloc")] pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyType_GenericNew")] - pub fn PyType_GenericNew(t: *mut PyTypeObject, args: *mut PyObject, - kwds: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyType_GenericNew")] + pub fn PyType_GenericNew( + t: *mut PyTypeObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; - #[cfg_attr(PyPy, link_name="PyPyType_Modified")] + #[cfg_attr(PyPy, link_name = "PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyObject_Print")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut ::libc::FILE, flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_Repr")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Str")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Str")] pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_ASCII")] + #[cfg_attr(PyPy, link_name = "PyPyObject_ASCII")] pub fn PyObject_ASCII(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Bytes")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Bytes")] pub fn PyObject_Bytes(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_RichCompare")] - pub fn PyObject_RichCompare(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_RichCompareBool")] - pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_GetAttrString")] - pub fn PyObject_GetAttrString(arg1: *mut PyObject, - arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_SetAttrString")] - pub fn PyObject_SetAttrString(arg1: *mut PyObject, - arg2: *const c_char, - arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_HasAttrString")] + #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompare")] + pub fn PyObject_RichCompare( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompareBool")] + pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) + -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttrString")] + pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttrString")] + pub fn PyObject_SetAttrString( + arg1: *mut PyObject, + arg2: *const c_char, + arg3: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")] 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; - #[cfg_attr(PyPy, link_name="PyPyObject_SetAttr")] - pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] + 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; - #[cfg_attr(PyPy, link_name="PyPyObject_SelfIter")] + #[cfg_attr(PyPy, link_name = "PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] #[cfg(not(PyPy))] pub fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_GenericGetAttr")] - pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_GenericSetAttr")] - pub fn PyObject_GenericSetAttr(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; - pub fn PyObject_GenericSetDict(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_Hash")] + #[cfg_attr(PyPy, link_name = "PyPyObject_GenericGetAttr")] + pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_GenericSetAttr")] + pub fn PyObject_GenericSetAttr( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> c_int; + pub fn PyObject_GenericSetDict( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut c_void, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="PyPyObject_HashNotImplemented")] + #[cfg_attr(PyPy, link_name = "PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name="PyPyObject_IsTrue")] + #[cfg_attr(PyPy, link_name = "PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_Not")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCallable_Check")] + #[cfg_attr(PyPy, link_name = "PyPyCallable_Check")] pub fn PyCallable_Check(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_ClearWeakRefs")] + #[cfg_attr(PyPy, link_name = "PyPyObject_ClearWeakRefs")] pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject) -> (); #[cfg(not(Py_LIMITED_API))] pub fn PyObject_CallFinalizer(arg1: *mut PyObject) -> (); #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyObject_CallFinalizerFromDealloc")] + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFinalizerFromDealloc")] pub fn PyObject_CallFinalizerFromDealloc(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_Dir")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Dir")] 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) -> (); } // Flag bits for printing: -pub const Py_PRINT_RAW : c_int = 1; // No string quotes etc. +pub const Py_PRINT_RAW: c_int = 1; // No string quotes etc. /// Set if the type object is dynamically allocated -pub const Py_TPFLAGS_HEAPTYPE : c_ulong = (1<<9); +pub const Py_TPFLAGS_HEAPTYPE: c_ulong = (1 << 9); /// Set if the type allows subclassing -pub const Py_TPFLAGS_BASETYPE : c_ulong = (1<<10); +pub const Py_TPFLAGS_BASETYPE: c_ulong = (1 << 10); /// Set if the type is 'ready' -- fully initialized -pub const Py_TPFLAGS_READY : c_ulong = (1<<12); +pub const Py_TPFLAGS_READY: c_ulong = (1 << 12); /// Set while the type is being 'readied', to prevent recursive ready calls -pub const Py_TPFLAGS_READYING : c_ulong = (1<<13); +pub const Py_TPFLAGS_READYING: c_ulong = (1 << 13); /// Objects support garbage collection (see objimp.h) -pub const Py_TPFLAGS_HAVE_GC : c_ulong = (1<<14); +pub const Py_TPFLAGS_HAVE_GC: c_ulong = (1 << 14); -const Py_TPFLAGS_HAVE_STACKLESS_EXTENSION : c_ulong = 0; +const Py_TPFLAGS_HAVE_STACKLESS_EXTENSION: c_ulong = 0; /// Objects support type attribute cache -pub const Py_TPFLAGS_HAVE_VERSION_TAG : c_ulong = (1<<18); -pub const Py_TPFLAGS_VALID_VERSION_TAG : c_ulong = (1<<19); +pub const Py_TPFLAGS_HAVE_VERSION_TAG: c_ulong = (1 << 18); +pub const Py_TPFLAGS_VALID_VERSION_TAG: c_ulong = (1 << 19); /* Type is abstract and cannot be instantiated */ -pub const Py_TPFLAGS_IS_ABSTRACT : c_ulong = (1<<20); +pub const Py_TPFLAGS_IS_ABSTRACT: c_ulong = (1 << 20); /* These flags are used to determine if a type is a subclass. */ -pub const Py_TPFLAGS_LONG_SUBCLASS : c_ulong = (1<<24); -pub const Py_TPFLAGS_LIST_SUBCLASS : c_ulong = (1<<25); -pub const Py_TPFLAGS_TUPLE_SUBCLASS : c_ulong = (1<<26); -pub const Py_TPFLAGS_BYTES_SUBCLASS : c_ulong = (1<<27); -pub const Py_TPFLAGS_UNICODE_SUBCLASS : c_ulong = (1<<28); -pub const Py_TPFLAGS_DICT_SUBCLASS : c_ulong = (1<<29); -pub const Py_TPFLAGS_BASE_EXC_SUBCLASS : c_ulong = (1<<30); -pub const Py_TPFLAGS_TYPE_SUBCLASS : c_ulong = (1<<31); - -pub const Py_TPFLAGS_DEFAULT : c_ulong = +pub const Py_TPFLAGS_LONG_SUBCLASS: c_ulong = (1 << 24); +pub const Py_TPFLAGS_LIST_SUBCLASS: c_ulong = (1 << 25); +pub const Py_TPFLAGS_TUPLE_SUBCLASS: c_ulong = (1 << 26); +pub const Py_TPFLAGS_BYTES_SUBCLASS: c_ulong = (1 << 27); +pub const Py_TPFLAGS_UNICODE_SUBCLASS: c_ulong = (1 << 28); +pub const Py_TPFLAGS_DICT_SUBCLASS: c_ulong = (1 << 29); +pub const Py_TPFLAGS_BASE_EXC_SUBCLASS: c_ulong = (1 << 30); +pub const Py_TPFLAGS_TYPE_SUBCLASS: c_ulong = (1 << 31); + +pub const Py_TPFLAGS_DEFAULT: c_ulong = Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | Py_TPFLAGS_HAVE_VERSION_TAG; -pub const Py_TPFLAGS_HAVE_FINALIZE : c_ulong = 1; +pub const Py_TPFLAGS_HAVE_FINALIZE: c_ulong = 1; #[inline(always)] #[cfg(Py_LIMITED_API)] -pub unsafe fn PyType_HasFeature(t : *mut PyTypeObject, f : c_ulong) -> c_int { +pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_ulong) -> c_int { ((PyType_GetFlags(t) & f) != 0) as c_int } #[inline(always)] #[cfg(not(Py_LIMITED_API))] -pub unsafe fn PyType_HasFeature(t : *mut PyTypeObject, f : c_ulong) -> c_int { +pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_ulong) -> c_int { (((*t).tp_flags & f) != 0) as c_int } #[inline(always)] -pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { +pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_ulong) -> c_int { PyType_HasFeature(t, f) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="_PyPy_Dealloc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPy_Dealloc")] pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } // Reference counting macros. #[inline(always)] -pub unsafe fn Py_INCREF(op : *mut PyObject) { - if cfg!(py_sys_config="Py_REF_DEBUG") { - #[cfg_attr(PyPy, link_name="PyPy_IncRef")] +pub unsafe fn Py_INCREF(op: *mut PyObject) { + if cfg!(py_sys_config = "Py_REF_DEBUG") { + #[cfg_attr(PyPy, link_name = "PyPy_IncRef")] Py_IncRef(op) } else { (*op).ob_refcnt += 1 @@ -838,8 +875,8 @@ pub unsafe fn Py_INCREF(op : *mut PyObject) { #[inline(always)] pub unsafe fn Py_DECREF(op: *mut PyObject) { - if cfg!(py_sys_config="Py_REF_DEBUG") { - #[cfg_attr(PyPy, link_name="PyPy_DecRef")] + if cfg!(py_sys_config = "Py_REF_DEBUG") { + #[cfg_attr(PyPy, link_name = "PyPy_DecRef")] Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -859,26 +896,27 @@ pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) { } #[inline(always)] -pub unsafe fn Py_XINCREF(op : *mut PyObject) { +pub unsafe fn Py_XINCREF(op: *mut PyObject) { if !op.is_null() { Py_INCREF(op) } } #[inline(always)] -pub unsafe fn Py_XDECREF(op : *mut PyObject) { +pub unsafe fn Py_XDECREF(op: *mut PyObject) { if !op.is_null() { Py_DECREF(op) } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); - #[cfg_attr(PyPy, link_name="_PyPy_NoneStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; - #[cfg_attr(PyPy, link_name="_PyPy_NotImplementedStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } @@ -893,12 +931,12 @@ pub unsafe fn Py_NotImplemented() -> *mut PyObject { } /* 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; +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 { @@ -908,4 +946,4 @@ pub fn PyObject_Check(_arg1: *mut PyObject) -> c_int { #[inline] pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int { 0 -} \ No newline at end of file +} diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index 05d4549ce3b..4f88740642e 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -1,12 +1,12 @@ -use std::ptr; -use std::os::raw::{c_void, c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int, c_void}; +use std::ptr; #[inline] -#[cfg_attr(PyPy, link_name="PyPyObject_DelAttrString")] +#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { - #[cfg_attr(PyPy, link_name="PyPyObject_SetAttr")] + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } @@ -15,34 +15,45 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ PyObject_SetAttr(o, attr_name, ptr::null_mut()) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyObject_Call")] - pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, - kw: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallObject")] - pub fn PyObject_CallObject(callable_object: *mut PyObject, - args: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallFunction")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyObject_Call")] + pub fn PyObject_Call( + callable_object: *mut PyObject, + args: *mut PyObject, + kw: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallObject")] + pub fn PyObject_CallObject( + callable_object: *mut PyObject, + args: *mut PyObject, + ) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] - pub fn PyObject_CallFunction(callable_object: *mut PyObject, - format: *const c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallMethod")] - pub fn PyObject_CallMethod(o: *mut PyObject, - method: *const c_char, - format: *const c_char, ...) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] + pub fn PyObject_CallFunction( + callable_object: *mut PyObject, + format: *const c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethod")] + pub fn PyObject_CallMethod( + o: *mut PyObject, + method: *const c_char, + format: *const c_char, + ... + ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallFunctionObjArgs")] - pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_CallMethodObjArgs")] - pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, - method: *mut PyObject, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Type")] + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")] + pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")] + pub fn PyObject_CallMethodObjArgs( + o: *mut PyObject, + method: *mut PyObject, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_Size")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; } @@ -51,40 +62,38 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { PyObject_Size(o) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyObject_LengthHint")] - pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) - -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyObject_LengthHint")] + pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyObject_GetItem")] - pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_SetItem")] - pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, - v: *mut PyObject) -> c_int; - pub fn PyObject_DelItemString(o: *mut PyObject, - key: *const c_char) - -> c_int; - pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_AsCharBuffer")] - pub fn PyObject_AsCharBuffer(obj: *mut PyObject, - buffer: *mut *const c_char, - buffer_len: *mut Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_CheckReadBuffer")] + #[cfg_attr(PyPy, link_name = "PyPyObject_GetItem")] + pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetItem")] + pub fn PyObject_SetItem(o: *mut PyObject, key: *mut PyObject, v: *mut PyObject) -> c_int; + pub fn PyObject_DelItemString(o: *mut PyObject, key: *const c_char) -> c_int; + pub fn PyObject_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsCharBuffer")] + pub fn PyObject_AsCharBuffer( + obj: *mut PyObject, + buffer: *mut *const c_char, + buffer_len: *mut Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_AsReadBuffer")] - pub fn PyObject_AsReadBuffer(obj: *mut PyObject, - buffer: *mut *const c_void, - buffer_len: *mut Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_AsWriteBuffer")] - pub fn PyObject_AsWriteBuffer(obj: *mut PyObject, - buffer: *mut *mut c_void, - buffer_len: *mut Py_ssize_t) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsReadBuffer")] + pub fn PyObject_AsReadBuffer( + obj: *mut PyObject, + buffer: *mut *const c_void, + buffer_len: *mut Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsWriteBuffer")] + pub fn PyObject_AsWriteBuffer( + obj: *mut PyObject, + buffer: *mut *mut c_void, + buffer_len: *mut Py_ssize_t, + ) -> c_int; } #[cfg(not(Py_LIMITED_API))] @@ -95,226 +104,211 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { } #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyObject_GetBuffer")] - pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, - flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyBuffer_GetPointer")] - pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyBuffer_ToContiguous")] - pub fn PyBuffer_ToContiguous(buf: *mut c_void, - view: *mut Py_buffer, len: Py_ssize_t, - order: c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyBuffer_FromContiguous")] - pub fn PyBuffer_FromContiguous(view: *mut Py_buffer, - buf: *mut c_void, len: Py_ssize_t, - order: c_char) -> c_int; - pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyBuffer_IsContiguous")] - pub fn PyBuffer_IsContiguous(view: *const 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) -> (); - #[cfg_attr(PyPy, link_name="PyPyBuffer_FillInfo")] - 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; - #[cfg_attr(PyPy, link_name="PyPyBuffer_Release")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyObject_GetBuffer")] + pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_GetPointer")] + pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_ToContiguous")] + pub fn PyBuffer_ToContiguous( + buf: *mut c_void, + view: *mut Py_buffer, + len: Py_ssize_t, + order: c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromContiguous")] + pub fn PyBuffer_FromContiguous( + view: *mut Py_buffer, + buf: *mut c_void, + len: Py_ssize_t, + order: c_char, + ) -> c_int; + pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_IsContiguous")] + pub fn PyBuffer_IsContiguous(view: *const 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, + ) -> (); + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FillInfo")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer) -> (); } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyObject_Format")] - pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_GetIter")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyObject_Format")] + pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name="PyPyIter_Check")] +#[cfg_attr(PyPy, link_name = "PyPyIter_Check")] pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { (match (*(*o).ob_type).tp_iternext { - Some(tp_iternext) => tp_iternext as *const c_void != ::ffi3::object::_PyObject_NextNotImplemented as *const c_void, - None => false + Some(tp_iternext) => { + tp_iternext as *const c_void + != ::ffi3::object::_PyObject_NextNotImplemented as *const c_void + } + None => false, }) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyIter_Next")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; - - #[cfg_attr(PyPy, link_name="PyPyNumber_Check")] + + #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyNumber_Add")] - pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Subtract")] - pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Multiply")] - pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_MatrixMultiply")] - pub fn PyNumber_MatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_FloorDivide")] - pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_TrueDivide")] - pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Remainder")] - pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Divmod")] - pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Power")] - pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, - o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Negative")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Add")] + pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Subtract")] + pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Multiply")] + pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_MatrixMultiply")] + pub fn PyNumber_MatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_FloorDivide")] + pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_TrueDivide")] + pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Remainder")] + pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Divmod")] + pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Power")] + pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) + -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Positive")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Absolute")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Invert")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Lshift")] - pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Rshift")] - pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_And")] - pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Xor")] - pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Or")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Lshift")] + pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Rshift")] + pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_And")] + pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Xor")] + pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name="PyPyIndex_Check")] +#[cfg_attr(PyPy, link_name = "PyPyIndex_Check")] pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { let tp_as_number = (*(*o).ob_type).tp_as_number; (!tp_as_number.is_null() && (*tp_as_number).nb_index.is_some()) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyNumber_Index")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_AsSsize_t")] - pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyNumber_Long")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_AsSsize_t")] + pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_Float")] + #[cfg_attr(PyPy, link_name = "PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAdd")] - pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceSubtract")] - pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceMultiply")] - pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceMatrixMultiply")] - pub fn PyNumber_InPlaceMatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceFloorDivide")] - pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceTrueDivide")] - pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRemainder")] - pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlacePower")] - pub fn PyNumber_InPlacePower(o1: *mut PyObject, o2: *mut PyObject, - o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceLshift")] - pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceRshift")] - pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceAnd")] - pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceXor")] - pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyNumber_InPlaceOr")] - pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAdd")] + pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceSubtract")] + pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceMultiply")] + pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceMatrixMultiply")] + pub fn PyNumber_InPlaceMatrixMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceFloorDivide")] + pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceTrueDivide")] + pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRemainder")] + pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlacePower")] + pub fn PyNumber_InPlacePower( + o1: *mut PyObject, + o2: *mut PyObject, + o3: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceLshift")] + pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRshift")] + pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAnd")] + pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceXor")] + pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceOr")] + pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_Check")] + #[cfg_attr(PyPy, link_name = "PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_Size")] + #[cfg_attr(PyPy, link_name = "PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; } #[inline] -#[cfg_attr(PyPy, link_name="PyPySequence_Length")] +#[cfg_attr(PyPy, link_name = "PyPySequence_Length")] pub unsafe fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t { PySequence_Size(o) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySequence_Concat")] - pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_Repeat")] - pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_GetItem")] - pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_GetSlice")] - pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, - i2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_SetItem")] - pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, - v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_DelItem")] - pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_SetSlice")] - pub fn PySequence_SetSlice(o: *mut PyObject, i1: Py_ssize_t, - i2: Py_ssize_t, v: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_DelSlice")] - pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, - i2: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySequence_Tuple")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySequence_Concat")] + pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_Repeat")] + pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_GetItem")] + pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_GetSlice")] + pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_SetItem")] + pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_DelItem")] + pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_SetSlice")] + pub fn PySequence_SetSlice( + o: *mut PyObject, + i1: Py_ssize_t, + i2: Py_ssize_t, + v: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_DelSlice")] + pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_List")] + #[cfg_attr(PyPy, link_name = "PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_Fast")] - pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_Fast")] + pub fn PySequence_Fast(o: *mut PyObject, m: *const c_char) -> *mut PyObject; // TODO: PySequence_Fast macros - pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySequence_Contains")] - pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) - -> c_int; + pub fn PySequence_Count(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPySequence_Contains")] + pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) -> c_int; } #[inline] @@ -322,63 +316,57 @@ pub unsafe fn PySequence_In(o: *mut PyObject, value: *mut PyObject) -> c_int { PySequence_Contains(o, value) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySequence_Index")] - pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) - -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceConcat")] - pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySequence_InPlaceRepeat")] - pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_Check")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySequence_Index")] + pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceConcat")] + pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceRepeat")] + pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyMapping_Size")] + #[cfg_attr(PyPy, link_name = "PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; } #[inline] -#[cfg_attr(PyPy, link_name="PyPyMapping_Length")] +#[cfg_attr(PyPy, link_name = "PyPyMapping_Length")] pub unsafe fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t { PyMapping_Size(o) } #[inline] -pub unsafe fn PyMapping_DelItemString(o : *mut PyObject, key : *mut c_char) -> c_int { +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 { +pub unsafe fn PyMapping_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int { PyObject_DelItem(o, key) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMapping_HasKeyString")] - pub fn PyMapping_HasKeyString(o: *mut PyObject, - key: *const c_char) - -> c_int; - pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyMapping_Keys")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKeyString")] + pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *const c_char) -> c_int; + pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_Keys")] pub fn PyMapping_Keys(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_Values")] + #[cfg_attr(PyPy, link_name = "PyPyMapping_Values")] pub fn PyMapping_Values(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_Items")] + #[cfg_attr(PyPy, link_name = "PyPyMapping_Items")] pub fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_GetItemString")] - pub fn PyMapping_GetItemString(o: *mut PyObject, - key: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyMapping_SetItemString")] - pub fn PyMapping_SetItemString(o: *mut PyObject, - key: *const c_char, - value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_IsInstance")] - pub fn PyObject_IsInstance(object: *mut PyObject, - typeorclass: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyObject_IsSubclass")] - pub fn PyObject_IsSubclass(object: *mut PyObject, - typeorclass: *mut PyObject) -> c_int; -} \ No newline at end of file + #[cfg_attr(PyPy, link_name = "PyPyMapping_GetItemString")] + pub fn PyMapping_GetItemString(o: *mut PyObject, key: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMapping_SetItemString")] + pub fn PyMapping_SetItemString( + o: *mut PyObject, + key: *const c_char, + value: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsInstance")] + pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsSubclass")] + pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; +} diff --git a/src/ffi3/objimpl.rs b/src/ffi3/objimpl.rs index 8b7a50b41a6..b76c8d026cc 100644 --- a/src/ffi3/objimpl.rs +++ b/src/ffi3/objimpl.rs @@ -1,27 +1,31 @@ -use libc::size_t; -use std::os::raw::{c_void, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use libc::size_t; +use std::os::raw::{c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyObject_Malloc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyObject_Malloc")] pub fn PyObject_Malloc(size: size_t) -> *mut c_void; pub fn PyObject_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyObject_Realloc")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Realloc")] pub fn PyObject_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyObject_Free")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Free")] pub fn PyObject_Free(ptr: *mut c_void) -> (); #[cfg(not(Py_LIMITED_API))] pub fn _Py_GetAllocatedBlocks() -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyObject_Init")] + #[cfg_attr(PyPy, link_name = "PyPyObject_Init")] pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyObject_InitVar")] - pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject, - arg3: Py_ssize_t) -> *mut PyVarObject; - #[cfg_attr(PyPy, link_name="_PyPyObject_New")] + #[cfg_attr(PyPy, link_name = "PyPyObject_InitVar")] + pub fn PyObject_InitVar( + arg1: *mut PyVarObject, + arg2: *mut PyTypeObject, + arg3: Py_ssize_t, + ) -> *mut PyVarObject; + #[cfg_attr(PyPy, link_name = "_PyPyObject_New")] pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyObject_NewVar")] + #[cfg_attr(PyPy, link_name = "_PyPyObject_NewVar")] pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn PyGC_Collect() -> Py_ssize_t; @@ -38,10 +42,14 @@ pub struct PyObjectArenaAllocator { #[cfg(not(Py_LIMITED_API))] impl Default for PyObjectArenaAllocator { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator) -> (); pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator) -> (); } @@ -49,48 +57,49 @@ impl Default for PyObjectArenaAllocator { /// Test if a type has a GC head #[inline(always)] #[allow(unused_parens)] -pub unsafe fn PyType_IS_GC(t : *mut PyTypeObject) -> c_int { +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(always)] #[cfg(not(Py_LIMITED_API))] -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 +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 } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) -> *mut PyVarObject; #[cfg(not(Py_LIMITED_API))] pub fn _PyObject_GC_Malloc(size: size_t) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] pub fn _PyObject_GC_Calloc(size: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyObject_GC_New")] + #[cfg_attr(PyPy, link_name = "_PyPyObject_GC_New")] pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="_PyPyObject_GC_NewVar")] + #[cfg_attr(PyPy, link_name = "_PyPyObject_GC_NewVar")] 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) -> (); - #[cfg_attr(PyPy, link_name="PyPyObject_GC_Del")] + #[cfg_attr(PyPy, link_name = "PyPyObject_GC_Del")] pub fn PyObject_GC_Del(arg1: *mut c_void) -> (); } /// Test if a type supports weak references #[inline(always)] #[cfg(not(Py_LIMITED_API))] -pub unsafe fn PyType_SUPPORTS_WEAKREFS(t : *mut PyTypeObject) -> c_int { +pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int { ((*t).tp_weaklistoffset > 0) as c_int } #[inline(always)] #[cfg(not(Py_LIMITED_API))] -pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o : *mut PyObject) -> *mut *mut PyObject { +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 u8).offset(weaklistoffset) as *mut *mut PyObject -} \ No newline at end of file +} diff --git a/src/ffi3/osmodule.rs b/src/ffi3/osmodule.rs index 391fec1b5f6..fc3d114ea64 100644 --- a/src/ffi3/osmodule.rs +++ b/src/ffi3/osmodule.rs @@ -1,6 +1,7 @@ // This header is new in Python 3.6 use ffi3::object::PyObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyOS_FSPath(path: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi3/pyarena.rs b/src/ffi3/pyarena.rs index 6e50de16f2a..bfe42fdb398 100644 --- a/src/ffi3/pyarena.rs +++ b/src/ffi3/pyarena.rs @@ -1,2 +1 @@ pub enum PyArena {} - diff --git a/src/ffi3/pycapsule.rs b/src/ffi3/pycapsule.rs index 86d63fd0634..fe15f653b2e 100644 --- a/src/ffi3/pycapsule.rs +++ b/src/ffi3/pycapsule.rs @@ -1,8 +1,9 @@ -use std::os::raw::{c_void, c_char, c_int}; use ffi3::object::*; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyCapsule_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -13,42 +14,35 @@ 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" { - #[cfg_attr(PyPy, link_name="PyPyCapsule_New")] - pub fn PyCapsule_New(pointer: *mut c_void, - name: *const c_char, - destructor: Option) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetPointer")] - pub fn PyCapsule_GetPointer(capsule: *mut PyObject, - name: *const c_char) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetDestructor")] - pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) - -> Option; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetName")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCapsule_New")] + pub fn PyCapsule_New( + pointer: *mut c_void, + name: *const c_char, + destructor: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetPointer")] + pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetDestructor")] + pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; - #[cfg_attr(PyPy, link_name="PyPyCapsule_GetContext")] - pub fn PyCapsule_GetContext(capsule: *mut PyObject) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyCapsule_IsValid")] - pub fn PyCapsule_IsValid(capsule: *mut PyObject, - name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetPointer")] - pub fn PyCapsule_SetPointer(capsule: *mut PyObject, - pointer: *mut c_void) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetDestructor")] - pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, - destructor: Option) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetName")] - pub fn PyCapsule_SetName(capsule: *mut PyObject, - name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_SetContext")] - pub fn PyCapsule_SetContext(capsule: *mut PyObject, - context: *mut c_void) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyCapsule_Import")] - pub fn PyCapsule_Import(name: *const c_char, - no_block: c_int) -> *mut c_void; -} \ No newline at end of file + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetContext")] + pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_IsValid")] + pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetPointer")] + pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetDestructor")] + pub fn PyCapsule_SetDestructor( + capsule: *mut PyObject, + destructor: Option, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetName")] + pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetContext")] + pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_Import")] + pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; +} diff --git a/src/ffi3/pydebug.rs b/src/ffi3/pydebug.rs index 068e718efdf..6422716d9ca 100644 --- a/src/ffi3/pydebug.rs +++ b/src/ffi3/pydebug.rs @@ -1,36 +1,37 @@ use std::os::raw::c_int; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPy_DebugFlag")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_VerboseFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; pub static mut Py_QuietFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_InteractiveFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_InspectFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_OptimizeFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_NoSiteFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_BytesWarningFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_UseClassExceptionsFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_FrozenFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_IgnoreEnvironmentFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_DontWriteBytecodeFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_NoUserSiteDirectory")] + #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; pub static mut Py_UnbufferedStdioFlag: c_int; - #[cfg_attr(PyPy, link_name="PyPy_HashRandomizationFlag")] + #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; pub static mut Py_IsolatedFlag: c_int; #[cfg(all(Py_3_6, windows))] pub static mut Py_LegacyWindowsStdioFlag: c_int; -} \ No newline at end of file +} diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 5f83fd8df7c..30cb404a429 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -1,64 +1,66 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyErr_SetNone")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_SetObject")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_SetString")] - pub fn PyErr_SetString(exception: *mut PyObject, - string: *const c_char) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_Occurred")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetString")] + pub fn PyErr_SetString(exception: *mut PyObject, string: *const c_char) -> (); + #[cfg_attr(PyPy, link_name = "PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_Clear")] + #[cfg_attr(PyPy, link_name = "PyPyErr_Clear")] pub fn PyErr_Clear() -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_Fetch")] - pub fn PyErr_Fetch(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_Restore")] - pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_GetExcInfo")] - pub fn PyErr_GetExcInfo(arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_SetExcInfo")] - pub fn PyErr_SetExcInfo(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPy_FatalError")] + #[cfg_attr(PyPy, link_name = "PyPyErr_Fetch")] + pub fn PyErr_Fetch( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ) -> (); + #[cfg_attr(PyPy, link_name = "PyPyErr_Restore")] + pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name = "PyPyErr_GetExcInfo")] + pub fn PyErr_GetExcInfo( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ) -> (); + #[cfg_attr(PyPy, link_name = "PyPyErr_SetExcInfo")] + pub fn PyErr_SetExcInfo(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name = "PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char) -> !; - #[cfg_attr(PyPy, link_name="PyPyErr_GivenExceptionMatches")] - pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, - arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_ExceptionMatches")] + #[cfg_attr(PyPy, link_name = "PyPyErr_GivenExceptionMatches")] + pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_NormalizeException")] - pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyException_SetTraceback")] - pub fn PyException_SetTraceback(arg1: *mut PyObject, arg2: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyException_GetTraceback")] + #[cfg_attr(PyPy, link_name = "PyPyErr_NormalizeException")] + pub fn PyErr_NormalizeException( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ) -> (); + #[cfg_attr(PyPy, link_name = "PyPyException_SetTraceback")] + pub fn PyException_SetTraceback(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyException_GetTraceback")] pub fn PyException_GetTraceback(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyException_GetCause")] + #[cfg_attr(PyPy, link_name = "PyPyException_GetCause")] pub fn PyException_GetCause(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyException_SetCause")] - pub fn PyException_SetCause(arg1: *mut PyObject, arg2: *mut PyObject) - -> (); - #[cfg_attr(PyPy, link_name="PyPyException_GetContext")] + #[cfg_attr(PyPy, link_name = "PyPyException_SetCause")] + pub fn PyException_SetCause(arg1: *mut PyObject, arg2: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name = "PyPyException_GetContext")] pub fn PyException_GetContext(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyException_SetContext")] - pub fn PyException_SetContext(arg1: *mut PyObject, arg2: *mut PyObject) - -> (); + #[cfg_attr(PyPy, link_name = "PyPyException_SetContext")] + pub fn PyException_SetContext(arg1: *mut PyObject, arg2: *mut PyObject) -> (); } #[inline] pub unsafe fn PyExceptionClass_Check(x: *mut PyObject) -> c_int { - (PyType_Check(x) != 0 && - PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int + (PyType_Check(x) != 0 + && PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) + as c_int } #[inline] @@ -67,235 +69,242 @@ pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name="PyPyExceptionInstance_Class")] +#[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { (*x).ob_type as *mut PyObject } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyExc_BaseException")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_Exception")] + #[cfg_attr(PyPy, link_name = "PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_StopAsyncIteration")] + #[cfg_attr(PyPy, link_name = "PyPyExc_StopAsyncIteration")] pub static mut PyExc_StopAsyncIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_StopIteration")] + #[cfg_attr(PyPy, link_name = "PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_GeneratorExit")] + #[cfg_attr(PyPy, link_name = "PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ArithmeticError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_LookupError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_AssertionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_AttributeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_BufferError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_EOFError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_FloatingPointError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_OSError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ImportError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; #[cfg(Py_3_6)] pub static mut PyExc_ModuleNotFoundError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_IndexError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_KeyError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_KeyboardInterrupt")] + #[cfg_attr(PyPy, link_name = "PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_MemoryError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_NameError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_OverflowError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_RecursionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_RecursionError")] pub static mut PyExc_RecursionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_NotImplementedError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_IndentationError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_TabError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ReferenceError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SystemError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SystemExit")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_TypeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnboundLocalError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeEncodeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeDecodeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeTranslateError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ValueError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ZeroDivisionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_BlockingIOError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_BlockingIOError")] pub static mut PyExc_BlockingIOError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_BrokenPipeError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_BrokenPipeError")] pub static mut PyExc_BrokenPipeError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ChildProcessError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ChildProcessError")] pub static mut PyExc_ChildProcessError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ConnectionError")] pub static mut PyExc_ConnectionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionAbortedError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ConnectionAbortedError")] pub static mut PyExc_ConnectionAbortedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionRefusedError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ConnectionRefusedError")] pub static mut PyExc_ConnectionRefusedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ConnectionResetError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ConnectionResetError")] pub static mut PyExc_ConnectionResetError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_FileExistsError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_FileExistsError")] pub static mut PyExc_FileExistsError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_FileNotFoundError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_FileNotFoundError")] pub static mut PyExc_FileNotFoundError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_InterruptedError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_InterruptedError")] pub static mut PyExc_InterruptedError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_IsADirectoryError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_IsADirectoryError")] pub static mut PyExc_IsADirectoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_NotADirectoryError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_NotADirectoryError")] pub static mut PyExc_NotADirectoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_PermissionError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_PermissionError")] pub static mut PyExc_PermissionError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ProcessLookupError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ProcessLookupError")] pub static mut PyExc_ProcessLookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_TimeoutError")] + #[cfg_attr(PyPy, link_name = "PyPyExc_TimeoutError")] pub static mut PyExc_TimeoutError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; - #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; + #[cfg(windows)] + pub static mut PyExc_WindowsError: *mut PyObject; pub static mut PyExc_RecursionErrorInst: *mut PyObject; /* Predefined warning categories */ - #[cfg_attr(PyPy, link_name="PyPyExc_Warning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UserWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_DeprecationWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_PendingDeprecationWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_SyntaxWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_RuntimeWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_FutureWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ImportWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_UnicodeWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_BytesWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyExc_ResourceWarning")] + #[cfg_attr(PyPy, link_name = "PyPyExc_ResourceWarning")] pub static mut PyExc_ResourceWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_BadArgument")] + #[cfg_attr(PyPy, link_name = "PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_NoMemory")] + #[cfg_attr(PyPy, link_name = "PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrno")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_SetFromErrnoWithFilenameObject")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject( - arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + arg1: *mut PyObject, + arg2: *mut PyObject, + ) -> *mut PyObject; pub fn PyErr_SetFromErrnoWithFilenameObjects( - arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> *mut PyObject; pub fn PyErr_SetFromErrnoWithFilename( - exc: *mut PyObject, filename: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_Format")] - pub fn PyErr_Format( - exception: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + exc: *mut PyObject, + filename: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_Format")] + pub fn PyErr_Format(exception: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; #[cfg(Py_3_6)] pub fn PyErr_SetImportErrorSubclass( - arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject, arg4: *mut PyObject) -> *mut PyObject; - pub fn PyErr_SetImportError(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_BadInternalCall")] + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + arg4: *mut PyObject, + ) -> *mut PyObject; + pub fn PyErr_SetImportError( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall() -> (); - pub fn _PyErr_BadInternalCall(filename: *const c_char, - lineno: c_int) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_NewException")] - pub fn PyErr_NewException(name: *const c_char, - base: *mut PyObject, dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_NewExceptionWithDoc")] - pub fn PyErr_NewExceptionWithDoc(name: *const c_char, - doc: *const c_char, - base: *mut PyObject, dict: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyErr_WriteUnraisable")] + pub fn _PyErr_BadInternalCall(filename: *const c_char, lineno: c_int) -> (); + #[cfg_attr(PyPy, link_name = "PyPyErr_NewException")] + pub fn PyErr_NewException( + name: *const c_char, + base: *mut PyObject, + dict: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_NewExceptionWithDoc")] + pub fn PyErr_NewExceptionWithDoc( + name: *const c_char, + doc: *const c_char, + base: *mut PyObject, + dict: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_CheckSignals")] + #[cfg_attr(PyPy, link_name = "PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_SetInterrupt")] + #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt() -> (); pub fn PyErr_SyntaxLocation(filename: *const c_char, lineno: c_int) -> (); - pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, - col_offset: c_int) -> (); + pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, col_offset: c_int) -> (); pub fn PyErr_ProgramText(filename: *const c_char, lineno: c_int) -> *mut PyObject; - pub fn PyUnicodeDecodeError_Create(encoding: *const c_char, - object: *const c_char, - length: Py_ssize_t, start: Py_ssize_t, - end: Py_ssize_t, - reason: *const c_char) -> *mut PyObject; + pub fn PyUnicodeDecodeError_Create( + encoding: *const c_char, + object: *const c_char, + length: Py_ssize_t, + start: Py_ssize_t, + end: Py_ssize_t, + reason: *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_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 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(exc: *mut PyObject, - reason: *const c_char) -> c_int; - pub fn PyUnicodeDecodeError_SetReason(exc: *mut PyObject, - reason: *const c_char) -> c_int; - pub fn PyUnicodeTranslateError_SetReason(exc: *mut PyObject, - reason: *const c_char) -> c_int; -} \ No newline at end of file + pub fn PyUnicodeEncodeError_SetReason(exc: *mut PyObject, reason: *const c_char) -> c_int; + pub fn PyUnicodeDecodeError_SetReason(exc: *mut PyObject, reason: *const c_char) -> c_int; + pub fn PyUnicodeTranslateError_SetReason(exc: *mut PyObject, reason: *const c_char) -> c_int; +} diff --git a/src/ffi3/pyhash.rs b/src/ffi3/pyhash.rs index c2df4f01d5e..10091771c44 100644 --- a/src/ffi3/pyhash.rs +++ b/src/ffi3/pyhash.rs @@ -1,21 +1,23 @@ -use std::os::raw::{c_void, c_char, c_int}; -use ffi3::pyport::{Py_ssize_t, Py_hash_t}; +use ffi3::pyport::{Py_hash_t, Py_ssize_t}; +use std::os::raw::{c_char, c_int, c_void}; #[repr(C)] #[derive(Copy, Clone)] pub struct PyHash_FuncDef { - pub hash: Option Py_hash_t>, + pub hash: Option Py_hash_t>, pub name: *const c_char, pub hash_bits: c_int, pub seed_bits: c_int, } impl Default for PyHash_FuncDef { - #[inline] fn default() -> Self { unsafe { ::std::mem::zeroed() } } + #[inline] + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef; -} \ No newline at end of file +} diff --git a/src/ffi3/pymem.rs b/src/ffi3/pymem.rs index 6e0925352cc..5bb517f2752 100644 --- a/src/ffi3/pymem.rs +++ b/src/ffi3/pymem.rs @@ -1,29 +1,28 @@ -use std::os::raw::c_void; use libc::size_t; +use std::os::raw::c_void; #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMem_RawMalloc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMem_RawMalloc")] pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyMem_RawCalloc")] - pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyMem_RawRealloc")] - pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyMem_RawFree")] + #[cfg_attr(PyPy, link_name = "PyPyMem_RawCalloc")] + pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyMem_RawRealloc")] + pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyMem_RawFree")] pub fn PyMem_RawFree(ptr: *mut c_void) -> (); } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyMem_Malloc")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMem_Malloc")] pub fn PyMem_Malloc(size: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyMem_Calloc")] + #[cfg_attr(PyPy, link_name = "PyPyMem_Calloc")] pub fn PyMem_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyMem_Realloc")] - pub fn PyMem_Realloc(ptr: *mut c_void, new_size: size_t) - -> *mut c_void; - #[cfg_attr(PyPy, link_name="PyPyMem_Free")] + #[cfg_attr(PyPy, link_name = "PyPyMem_Realloc")] + pub fn PyMem_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyMem_Free")] pub fn PyMem_Free(ptr: *mut c_void) -> (); } @@ -33,7 +32,7 @@ use libc::size_t; pub enum PyMemAllocatorDomain { PYMEM_DOMAIN_RAW, PYMEM_DOMAIN_MEM, - PYMEM_DOMAIN_OBJ + PYMEM_DOMAIN_OBJ, } #[repr(C)] @@ -41,27 +40,20 @@ pub enum PyMemAllocatorDomain { #[cfg(not(Py_LIMITED_API))] pub struct PyMemAllocatorEx { pub ctx: *mut c_void, - pub malloc: Option *mut c_void>, - pub calloc: Option *mut c_void>, - pub realloc: Option *mut c_void>, - pub free: Option ()>, + pub malloc: Option *mut c_void>, + pub calloc: + Option *mut c_void>, + pub realloc: + Option *mut c_void>, + pub free: Option ()>, } #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, - allocator: *mut PyMemAllocatorEx) -> (); - pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, - allocator: *mut PyMemAllocatorEx) -> (); +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx) + -> (); + pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx) + -> (); pub fn PyMem_SetupDebugHooks() -> (); -} \ No newline at end of file +} diff --git a/src/ffi3/pyport.rs b/src/ffi3/pyport.rs index ab3410af29b..37faf32fbe9 100644 --- a/src/ffi3/pyport.rs +++ b/src/ffi3/pyport.rs @@ -1,4 +1,3 @@ - pub type Py_uintptr_t = ::libc::uintptr_t; pub type Py_intptr_t = ::libc::intptr_t; pub type Py_ssize_t = ::libc::ssize_t; @@ -6,5 +5,5 @@ 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; +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; diff --git a/src/ffi3/pystate.rs b/src/ffi3/pystate.rs index 0ee99caee33..ce64e17ca32 100644 --- a/src/ffi3/pystate.rs +++ b/src/ffi3/pystate.rs @@ -1,8 +1,8 @@ -use std::os::raw::{c_int, c_long}; -use ffi3::object::PyObject; -use ffi3::moduleobject::PyModuleDef; #[cfg(Py_3_6)] use ffi3::ceval::_PyFrameEvalFunction; +use ffi3::moduleobject::PyModuleDef; +use ffi3::object::PyObject; +use std::os::raw::{c_int, c_long}; #[cfg(Py_3_6)] pub const MAX_CO_EXTRA_USERS: c_int = 255; @@ -17,52 +17,52 @@ pub struct PyInterpreterState { #[repr(C)] #[derive(Copy, Clone)] -pub struct PyThreadState { +pub struct PyThreadState { pub ob_base: PyObject, pub interp: *mut PyInterpreterState, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyInterpreterState_New() -> *mut PyInterpreterState; pub fn PyInterpreterState_Clear(arg1: *mut PyInterpreterState) -> (); pub fn PyInterpreterState_Delete(arg1: *mut PyInterpreterState) -> (); //fn _PyState_AddModule(arg1: *mut PyObject, // arg2: *mut PyModuleDef) -> c_int; pub fn PyState_FindModule(arg1: *mut PyModuleDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyThreadState_New")] - pub fn PyThreadState_New(arg1: *mut PyInterpreterState) - -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyThreadState_New")] + pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState; //fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) // -> *mut PyThreadState; //fn _PyThreadState_Init(arg1: *mut PyThreadState) -> (); - #[cfg_attr(PyPy, link_name="PyPyThreadState_Clear")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState) -> (); - #[cfg_attr(PyPy, link_name="PyPyThreadState_Delete")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState) -> (); - #[cfg(py_sys_config="WITH_THREAD")] - #[cfg_attr(PyPy, link_name="PyPyThreadState_DeleteCurrent")] + #[cfg(py_sys_config = "WITH_THREAD")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent() -> (); - #[cfg_attr(PyPy, link_name="PyPyThreadState_Get")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Get")] pub fn PyThreadState_Get() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyThreadState_Swap")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name="PyPyThreadState_GetDict")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; - pub fn PyThreadState_SetAsyncExc(arg1: c_long, - arg2: *mut PyObject) -> c_int; + pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; } #[repr(C)] #[derive(Copy, Clone, Debug)] pub enum PyGILState_STATE { PyGILState_LOCKED, - PyGILState_UNLOCKED + PyGILState_UNLOCKED, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyGILState_Ensure")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; - #[cfg_attr(PyPy, link_name="PyPyGILState_Release")] + #[cfg_attr(PyPy, link_name = "PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE) -> (); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; } @@ -70,4 +70,4 @@ pub enum PyGILState_STATE { #[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { PyThreadState_Get() -} \ No newline at end of file +} diff --git a/src/ffi3/pystrtod.rs b/src/ffi3/pystrtod.rs index e93abba8b2a..866a0d63378 100644 --- a/src/ffi3/pystrtod.rs +++ b/src/ffi3/pystrtod.rs @@ -1,27 +1,30 @@ -use std::os::raw::{c_char, c_int, c_double}; use ffi3::object::PyObject; +use std::os::raw::{c_char, c_double, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyOS_string_to_double")] - pub fn PyOS_string_to_double(str: *const c_char, - endptr: *mut *mut c_char, - overflow_exception: *mut PyObject) - -> c_double; - #[cfg_attr(PyPy, link_name="PyPyOS_double_to_string")] - pub fn PyOS_double_to_string(val: c_double, - format_code: c_char, - precision: c_int, - flags: c_int, - _type: *mut c_int) - -> *mut c_char; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyOS_string_to_double")] + pub fn PyOS_string_to_double( + str: *const c_char, + endptr: *mut *mut c_char, + overflow_exception: *mut PyObject, + ) -> c_double; + #[cfg_attr(PyPy, link_name = "PyPyOS_double_to_string")] + pub fn PyOS_double_to_string( + val: c_double, + format_code: c_char, + precision: c_int, + flags: c_int, + _type: *mut c_int, + ) -> *mut c_char; } /* PyOS_double_to_string's "flags" parameter can be set to 0 or more of: */ -pub const Py_DTSF_SIGN : c_int = 0x01; /* always add the sign */ -pub const Py_DTSF_ADD_DOT_0 : c_int = 0x02; /* if the result is an integer add ".0" */ -pub const Py_DTSF_ALT : c_int = 0x04; /* "alternate" formatting. it's format_code specific */ +pub const Py_DTSF_SIGN: c_int = 0x01; /* always add the sign */ +pub const Py_DTSF_ADD_DOT_0: c_int = 0x02; /* if the result is an integer add ".0" */ +pub const Py_DTSF_ALT: c_int = 0x04; /* "alternate" formatting. it's format_code specific */ /* PyOS_double_to_string's "type", if non-NULL, will be set to one of: */ pub const Py_DTST_FINITE: c_int = 0; pub const Py_DTST_INFINITE: c_int = 1; -pub const Py_DTST_NAN: c_int = 2; \ No newline at end of file +pub const Py_DTST_NAN: c_int = 2; diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index f307748c80c..73bf601b62d 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -1,23 +1,25 @@ -use std::os::raw::{c_char, c_int}; -use std::ptr; -use libc::{wchar_t, FILE}; use ffi3::object::*; -use ffi3::pystate::PyThreadState; #[cfg(not(Py_LIMITED_API))] use ffi3::pyarena::PyArena; +use ffi3::pystate::PyThreadState; +use libc::{wchar_t, FILE}; +use std::os::raw::{c_char, c_int}; +use std::ptr; // TODO: PyCF_MASK etc. constants -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { // TODO: these moved to pylifecycle.h +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + // TODO: these moved to pylifecycle.h pub fn Py_SetProgramName(arg1: *mut wchar_t) -> (); - #[cfg_attr(PyPy, link_name="PyPy_GetProgramName")] + #[cfg_attr(PyPy, link_name = "PyPy_GetProgramName")] pub fn Py_GetProgramName() -> *mut wchar_t; pub fn Py_SetPythonHome(arg1: *mut wchar_t) -> (); pub fn Py_GetPythonHome() -> *mut wchar_t; pub fn Py_Initialize() -> (); pub fn Py_InitializeEx(arg1: c_int) -> (); pub fn Py_Finalize() -> (); - #[cfg_attr(PyPy, link_name="PyPy_IsInitialized")] + #[cfg_attr(PyPy, link_name = "PyPy_IsInitialized")] pub fn Py_IsInitialized() -> c_int; pub fn Py_NewInterpreter() -> *mut PyThreadState; pub fn Py_EndInterpreter(arg1: *mut PyThreadState) -> (); @@ -27,68 +29,84 @@ use ffi3::pyarena::PyArena; #[derive(Copy, Clone)] #[cfg(not(Py_LIMITED_API))] pub struct PyCompilerFlags { - pub cf_flags : c_int + pub cf_flags: c_int, } #[cfg(not(Py_LIMITED_API))] pub enum _mod {} #[cfg(not(Py_LIMITED_API))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyRun_SimpleStringFlags(arg1: *const c_char, - arg2: *mut PyCompilerFlags) - -> c_int; - pub fn PyRun_AnyFileFlags(arg1: *mut FILE, arg2: *const c_char, - arg3: *mut PyCompilerFlags) -> c_int; - pub fn PyRun_AnyFileExFlags(fp: *mut FILE, - filename: *const c_char, - closeit: c_int, - flags: *mut PyCompilerFlags) -> c_int; - pub fn PyRun_SimpleFileExFlags(fp: *mut FILE, - filename: *const c_char, - closeit: c_int, - flags: *mut PyCompilerFlags) - -> c_int; - pub fn PyRun_InteractiveOneFlags(fp: *mut FILE, - filename: *const c_char, - flags: *mut PyCompilerFlags) - -> c_int; - pub fn PyRun_InteractiveOneObject(fp: *mut FILE, filename: *mut PyObject, - flags: *mut PyCompilerFlags) - -> c_int; - pub fn PyRun_InteractiveLoopFlags(fp: *mut FILE, - filename: *const c_char, - flags: *mut PyCompilerFlags) - -> c_int; - pub fn PyParser_ASTFromString(s: *const c_char, - filename: *const c_char, - start: c_int, - flags: *mut PyCompilerFlags, - arena: *mut PyArena) -> *mut _mod; - pub fn PyParser_ASTFromStringObject(s: *const c_char, - filename: *mut PyObject, - start: c_int, - flags: *mut PyCompilerFlags, - arena: *mut PyArena) - -> *mut _mod; - pub fn PyParser_ASTFromFile(fp: *mut FILE, - filename: *const c_char, - enc: *const c_char, - start: c_int, - ps1: *const c_char, - ps2: *const c_char, - flags: *mut PyCompilerFlags, - errcode: *mut c_int, - arena: *mut PyArena) -> *mut _mod; - pub fn PyParser_ASTFromFileObject(fp: *mut FILE, filename: *mut PyObject, - enc: *const c_char, - start: c_int, - ps1: *const c_char, - ps2: *const c_char, - flags: *mut PyCompilerFlags, - errcode: *mut c_int, - arena: *mut PyArena) - -> *mut _mod; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int; + pub fn PyRun_AnyFileFlags( + arg1: *mut FILE, + arg2: *const c_char, + arg3: *mut PyCompilerFlags, + ) -> c_int; + pub fn PyRun_AnyFileExFlags( + fp: *mut FILE, + filename: *const c_char, + closeit: c_int, + flags: *mut PyCompilerFlags, + ) -> c_int; + pub fn PyRun_SimpleFileExFlags( + fp: *mut FILE, + filename: *const c_char, + closeit: c_int, + flags: *mut PyCompilerFlags, + ) -> c_int; + pub fn PyRun_InteractiveOneFlags( + fp: *mut FILE, + filename: *const c_char, + flags: *mut PyCompilerFlags, + ) -> c_int; + pub fn PyRun_InteractiveOneObject( + fp: *mut FILE, + filename: *mut PyObject, + flags: *mut PyCompilerFlags, + ) -> c_int; + pub fn PyRun_InteractiveLoopFlags( + fp: *mut FILE, + filename: *const c_char, + flags: *mut PyCompilerFlags, + ) -> c_int; + pub fn PyParser_ASTFromString( + s: *const c_char, + filename: *const c_char, + start: c_int, + flags: *mut PyCompilerFlags, + arena: *mut PyArena, + ) -> *mut _mod; + pub fn PyParser_ASTFromStringObject( + s: *const c_char, + filename: *mut PyObject, + start: c_int, + flags: *mut PyCompilerFlags, + arena: *mut PyArena, + ) -> *mut _mod; + pub fn PyParser_ASTFromFile( + fp: *mut FILE, + filename: *const c_char, + enc: *const c_char, + start: c_int, + ps1: *const c_char, + ps2: *const c_char, + flags: *mut PyCompilerFlags, + errcode: *mut c_int, + arena: *mut PyArena, + ) -> *mut _mod; + pub fn PyParser_ASTFromFileObject( + fp: *mut FILE, + filename: *mut PyObject, + enc: *const c_char, + start: c_int, + ps1: *const c_char, + ps2: *const c_char, + flags: *mut PyCompilerFlags, + errcode: *mut c_int, + arena: *mut PyArena, + ) -> *mut _mod; } pub enum symtable {} @@ -105,38 +123,47 @@ pub unsafe fn PyParser_SimpleParseFile(fp: *mut FILE, s: *const c_char, b: c_int PyParser_SimpleParseFileFlags(fp, s, b, 0) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyParser_SimpleParseStringFlags(arg1: *const c_char, - arg2: c_int, - arg3: c_int) - -> *mut _node; - pub fn PyParser_SimpleParseStringFlagsFilename(arg1: - *const c_char, - arg2: - *const c_char, - arg3: c_int, - arg4: c_int) - -> *mut _node; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyParser_SimpleParseStringFlags( + arg1: *const c_char, + arg2: c_int, + arg3: c_int, + ) -> *mut _node; + pub fn PyParser_SimpleParseStringFlagsFilename( + arg1: *const c_char, + arg2: *const c_char, + arg3: c_int, + arg4: c_int, + ) -> *mut _node; #[cfg(not(Py_LIMITED_API))] - pub fn PyParser_SimpleParseFileFlags(arg1: *mut FILE, - arg2: *const c_char, - arg3: c_int, - arg4: c_int) - -> *mut _node; + pub fn PyParser_SimpleParseFileFlags( + arg1: *mut FILE, + arg2: *const c_char, + arg3: c_int, + arg4: c_int, + ) -> *mut _node; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyRun_StringFlags")] - pub fn PyRun_StringFlags(arg1: *const c_char, arg2: c_int, - arg3: *mut PyObject, arg4: *mut PyObject, - arg5: *mut PyCompilerFlags) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] + pub fn PyRun_StringFlags( + arg1: *const c_char, + arg2: c_int, + arg3: *mut PyObject, + arg4: *mut PyObject, + arg5: *mut PyCompilerFlags, + ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyRun_FileExFlags(fp: *mut FILE, filename: *const c_char, - start: c_int, globals: *mut PyObject, - locals: *mut PyObject, closeit: c_int, - flags: *mut PyCompilerFlags) -> *mut PyObject; + pub fn PyRun_FileExFlags( + fp: *mut FILE, + filename: *const c_char, + start: c_int, + globals: *mut PyObject, + locals: *mut PyObject, + closeit: c_int, + flags: *mut PyCompilerFlags, + ) -> *mut PyObject; #[cfg(Py_LIMITED_API)] - pub fn Py_CompileString(string: *const c_char, - p: *const c_char, s: c_int) - -> *mut PyObject; + pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] @@ -145,56 +172,66 @@ pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name="PyPy_CompileStringFlags")] -pub unsafe fn Py_CompileStringFlags(string: *const c_char, p: *const c_char, s: c_int, f: *mut PyCompilerFlags) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] +pub unsafe fn Py_CompileStringFlags( + string: *const c_char, + p: *const c_char, + s: c_int, + f: *mut PyCompilerFlags, +) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, f, -1) } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { #[cfg(not(Py_LIMITED_API))] - pub fn Py_CompileStringExFlags(str: *const c_char, - filename: *const c_char, - start: c_int, - flags: *mut PyCompilerFlags, - optimize: c_int) -> *mut PyObject; + pub fn Py_CompileStringExFlags( + str: *const c_char, + filename: *const c_char, + start: c_int, + flags: *mut PyCompilerFlags, + optimize: c_int, + ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn Py_CompileStringObject(str: *const c_char, - filename: *mut PyObject, - start: c_int, - flags: *mut PyCompilerFlags, - optimize: c_int) -> *mut PyObject; - pub fn Py_SymtableString(str: *const c_char, - filename: *const c_char, - start: c_int) -> *mut symtable; + pub fn Py_CompileStringObject( + str: *const c_char, + filename: *mut PyObject, + start: c_int, + flags: *mut PyCompilerFlags, + optimize: c_int, + ) -> *mut PyObject; + pub fn Py_SymtableString( + str: *const c_char, + filename: *const c_char, + start: c_int, + ) -> *mut symtable; #[cfg(not(Py_LIMITED_API))] - pub fn Py_SymtableStringObject(str: *const c_char, - filename: *mut PyObject, - start: c_int) - -> *mut symtable; + pub fn Py_SymtableStringObject( + str: *const c_char, + filename: *mut PyObject, + start: c_int, + ) -> *mut symtable; - #[cfg_attr(PyPy,link_name="PyPyErr_Print")] + #[cfg_attr(PyPy, link_name = "PyPyErr_Print")] pub fn PyErr_Print() -> (); - #[cfg_attr(PyPy,link_name="PyPyErr_PrintEx")] + #[cfg_attr(PyPy, link_name = "PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int) -> (); - #[cfg_attr(PyPy, link_name="PyPyErr_Display")] - pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name = "PyPyErr_Display")] + pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> (); // TODO: these moved to pylifecycle.h - #[cfg_attr(PyPy, link_name="PyPy_AtExit")] - pub fn Py_AtExit(func: Option ()>) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_AtExit")] + pub fn Py_AtExit(func: Option ()>) -> c_int; pub fn Py_Exit(arg1: c_int) -> (); - pub fn Py_Main(argc: c_int, argv: *mut *mut wchar_t) - -> c_int; + pub fn Py_Main(argc: c_int, argv: *mut *mut wchar_t) -> c_int; pub fn Py_GetProgramFullPath() -> *mut wchar_t; pub fn Py_GetPrefix() -> *mut wchar_t; pub fn Py_GetExecPrefix() -> *mut wchar_t; pub fn Py_GetPath() -> *mut wchar_t; pub fn Py_SetPath(arg1: *const wchar_t) -> (); - #[cfg_attr(PyPy, link_name="PyPy_GetVersion")] + #[cfg_attr(PyPy, link_name = "PyPy_GetVersion")] 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; -} \ No newline at end of file +} diff --git a/src/ffi3/rangeobject.rs b/src/ffi3/rangeobject.rs index fb8ee8d3abb..dc412f78190 100644 --- a/src/ffi3/rangeobject.rs +++ b/src/ffi3/rangeobject.rs @@ -1,14 +1,15 @@ -use std::os::raw::c_int; use ffi3::object::*; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyRange_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; pub static mut PyRangeIter_Type: PyTypeObject; pub static mut PyLongRangeIter_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyRange_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyRange_Type) as c_int } diff --git a/src/ffi3/setobject.rs b/src/ffi3/setobject.rs index 5a3fbce1474..fd5665ae3b9 100644 --- a/src/ffi3/setobject.rs +++ b/src/ffi3/setobject.rs @@ -1,62 +1,63 @@ -use std::os::raw::c_int; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySet_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name="PyPyFrozenSet_Type")] + #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; pub static mut PySetIter_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name="PyPyFrozenSet_CheckExact")] -pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_CheckExact")] +pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PyFrozenSet_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name="PyPyAnySet_CheckExact")] -pub unsafe fn PyAnySet_CheckExact(ob : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")] +pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || Py_TYPE(ob) == &mut PyFrozenSet_Type) 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 +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] -#[cfg_attr(PyPy, link_name="PyPySet_Check")] -pub unsafe fn PySet_Check(ob : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPySet_Check")] +pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0) as c_int } #[inline] -pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int { - (Py_TYPE(ob) == &mut PyFrozenSet_Type || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int +pub unsafe fn PyFrozenSet_Check(ob: *mut PyObject) -> c_int { + (Py_TYPE(ob) == &mut PyFrozenSet_Type + || PyType_IsSubtype(Py_TYPE(ob), &mut PyFrozenSet_Type) != 0) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySet_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySet_New")] pub fn PySet_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyFrozenSet_New")] + #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_New")] pub fn PyFrozenSet_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySet_Size")] + #[cfg_attr(PyPy, link_name = "PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPySet_Clear")] + #[cfg_attr(PyPy, link_name = "PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Contains")] - pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Discard")] - pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Add")] + #[cfg_attr(PyPy, link_name = "PyPySet_Contains")] + pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySet_Discard")] + pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySet_Add")] pub fn PySet_Add(set: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPySet_Pop")] + #[cfg_attr(PyPy, link_name = "PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; -} \ No newline at end of file +} diff --git a/src/ffi3/sliceobject.rs b/src/ffi3/sliceobject.rs index 8279d4e3f5d..d81096a8611 100644 --- a/src/ffi3/sliceobject.rs +++ b/src/ffi3/sliceobject.rs @@ -1,9 +1,10 @@ -use std::os::raw::c_int; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="_PyPy_EllipsisObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -12,30 +13,42 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { &mut _Py_EllipsisObject } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySlice_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPySlice_Check")] +#[cfg_attr(PyPy, link_name = "PyPySlice_Check")] pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PySlice_Type) as c_int + (Py_TYPE(op) == &mut PySlice_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPySlice_New")] - pub fn PySlice_New(start: *mut PyObject, stop: *mut PyObject, - step: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySlice_GetIndices")] - 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; - #[cfg_attr(PyPy, link_name="PyPySlice_GetIndicesEx")] - 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; -} \ No newline at end of file +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySlice_New")] + pub fn PySlice_New( + start: *mut PyObject, + stop: *mut PyObject, + step: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndices")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndicesEx")] + 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; +} diff --git a/src/ffi3/structmember.rs b/src/ffi3/structmember.rs index cc0c895e4ca..c0e19f66ef4 100644 --- a/src/ffi3/structmember.rs +++ b/src/ffi3/structmember.rs @@ -1,6 +1,6 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::PyObject; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] @@ -9,50 +9,50 @@ pub struct PyMemberDef { pub type_code: c_int, pub offset: Py_ssize_t, pub flags: c_int, - pub doc: *mut c_char + pub doc: *mut c_char, } /* Types */ -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; +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 */ +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; +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; +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_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_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_LONGLONG: c_int = 17; +pub const T_ULONGLONG: c_int = 18; -pub const T_PYSSIZET : c_int = 19; /* Py_ssize_t */ -pub const T_NONE : c_int = 20; /* Value is always None */ +pub const T_PYSSIZET: c_int = 19; /* Py_ssize_t */ +pub const T_NONE: c_int = 20; /* Value is always None */ /* Flags */ -pub const READONLY : c_int = 1; -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); +pub const READONLY: c_int = 1; +pub const READ_RESTRICTED: c_int = 2; +pub const PY_WRITE_RESTRICTED: c_int = 4; +pub const RESTRICTED: c_int = (READ_RESTRICTED | PY_WRITE_RESTRICTED); -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyMember_GetOne(addr: *const c_char, l: *mut PyMemberDef) -> *mut PyObject; pub fn PyMember_SetOne(addr: *mut c_char, l: *mut PyMemberDef, value: *mut PyObject) -> c_int; } - diff --git a/src/ffi3/structseq.rs b/src/ffi3/structseq.rs index 0fb54cccf0d..06c3ecb376a 100644 --- a/src/ffi3/structseq.rs +++ b/src/ffi3/structseq.rs @@ -1,6 +1,6 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::{PyObject, PyTypeObject}; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::{c_char, c_int}; #[repr(C)] #[derive(Copy, Clone)] @@ -18,12 +18,14 @@ pub struct PyStructSequence_Desc { pub n_in_sequence: c_int, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) - -> *mut PyTypeObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) -> *mut PyTypeObject; pub fn PyStructSequence_New(_type: *mut PyTypeObject) -> *mut PyObject; - pub fn PyStructSequence_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut PyObject) -> (); - pub fn PyStructSequence_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) - -> *mut PyObject; -} \ No newline at end of file + pub fn PyStructSequence_SetItem( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: *mut PyObject, + ) -> (); + pub fn PyStructSequence_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; +} diff --git a/src/ffi3/sysmodule.rs b/src/ffi3/sysmodule.rs index d45f0fab35d..2c0ffe66934 100644 --- a/src/ffi3/sysmodule.rs +++ b/src/ffi3/sysmodule.rs @@ -1,22 +1,21 @@ -use std::os::raw::{c_char, c_int}; -use libc::wchar_t; use ffi3::object::PyObject; use ffi3::pyport::Py_ssize_t; +use libc::wchar_t; +use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn Py_DecodeLocale(arg1: *const c_char, arg2: Py_ssize_t) -> *mut wchar_t; - #[cfg_attr(PyPy, link_name="PyPySys_GetObject")] + #[cfg_attr(PyPy, link_name = "PyPySys_GetObject")] pub fn PySys_GetObject(arg1: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPySys_SetObject")] - pub fn PySys_SetObject(arg1: *const c_char, arg2: *mut PyObject) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySys_SetObject")] + pub fn PySys_SetObject(arg1: *const c_char, arg2: *mut PyObject) -> c_int; pub fn PySys_SetArgv(arg1: c_int, arg2: *mut *mut wchar_t) -> (); - pub fn PySys_SetArgvEx(arg1: c_int, arg2: *mut *mut wchar_t, - arg3: c_int) -> (); + pub fn PySys_SetArgvEx(arg1: c_int, arg2: *mut *mut wchar_t, arg3: c_int) -> (); pub fn PySys_SetPath(arg1: *const wchar_t) -> (); - #[cfg_attr(PyPy, link_name="PyPySys_WriteStdout")] + #[cfg_attr(PyPy, link_name = "PyPySys_WriteStdout")] pub fn PySys_WriteStdout(format: *const c_char, ...) -> (); - #[cfg_attr(PyPy, link_name="PyPySys_WriteStderr")] + #[cfg_attr(PyPy, link_name = "PyPySys_WriteStderr")] pub fn PySys_WriteStderr(format: *const c_char, ...) -> (); pub fn PySys_FormatStdout(format: *const c_char, ...) -> (); pub fn PySys_FormatStderr(format: *const c_char, ...) -> (); @@ -26,4 +25,4 @@ use ffi3::pyport::Py_ssize_t; pub fn PySys_HasWarnOptions() -> c_int; pub fn PySys_AddXOption(arg1: *const wchar_t) -> (); pub fn PySys_GetXOptions() -> *mut PyObject; -} \ No newline at end of file +} diff --git a/src/ffi3/traceback.rs b/src/ffi3/traceback.rs index 67ec25db6c3..a86231a1323 100644 --- a/src/ffi3/traceback.rs +++ b/src/ffi3/traceback.rs @@ -1,17 +1,18 @@ -use std::os::raw::c_int; use ffi3::object::*; +use std::os::raw::c_int; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyTraceBack_Here")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut ::ffi3::PyFrameObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyTraceBack_Print")] + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyTraceBack_Type")] + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyTraceBack_Check")] -pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Check")] +pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int -} \ No newline at end of file +} diff --git a/src/ffi3/tupleobject.rs b/src/ffi3/tupleobject.rs index f442748f1b2..a3f8d81f06e 100644 --- a/src/ffi3/tupleobject.rs +++ b/src/ffi3/tupleobject.rs @@ -1,6 +1,6 @@ -use std::os::raw::c_int; -use ffi3::pyport::Py_ssize_t; use ffi3::object::*; +use ffi3::pyport::Py_ssize_t; +use std::os::raw::c_int; #[repr(C)] #[cfg(not(Py_LIMITED_API))] @@ -9,36 +9,40 @@ pub struct PyTupleObject { pub ob_item: [*mut PyObject; 1], } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyTuple_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; pub static mut PyTupleIter_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyTuple_Check(op : *mut PyObject) -> c_int { +pub unsafe fn PyTuple_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) } #[inline(always)] -pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { +pub unsafe fn PyTuple_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTuple_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyTuple_New")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTuple_New")] pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyTuple_Size")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_Size")] pub fn PyTuple_Size(arg1: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyTuple_GetItem")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_GetItem")] pub fn PyTuple_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyTuple_SetItem")] - pub fn PyTuple_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyTuple_GetSlice")] - pub fn PyTuple_GetSlice(arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyTuple_Pack")] + #[cfg_attr(PyPy, link_name = "PyPyTuple_SetItem")] + pub fn PyTuple_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyTuple_GetSlice")] + pub fn PyTuple_GetSlice( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyTuple_Pack")] pub fn PyTuple_Pack(arg1: Py_ssize_t, ...) -> *mut PyObject; pub fn PyTuple_ClearFreeList() -> c_int; } @@ -47,7 +51,10 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { #[inline(always)] #[cfg(not(Py_LIMITED_API))] pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { - *(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i as isize) + *(*(op as *mut PyTupleObject)) + .ob_item + .as_ptr() + .offset(i as isize) } #[inline(always)] @@ -60,5 +67,8 @@ pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { #[inline(always)] #[cfg(not(Py_LIMITED_API))] 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; -} \ No newline at end of file + *(*(op as *mut PyTupleObject)) + .ob_item + .as_mut_ptr() + .offset(i as isize) = v; +} diff --git a/src/ffi3/typeslots.rs b/src/ffi3/typeslots.rs index 9525356cf03..d214ba08a7c 100644 --- a/src/ffi3/typeslots.rs +++ b/src/ffi3/typeslots.rs @@ -1,80 +1,80 @@ use std::os::raw::c_int; -pub const Py_mp_ass_subscript : c_int = 3; -pub const Py_mp_length : c_int = 4; -pub const Py_mp_subscript : c_int = 5; -pub const Py_nb_absolute : c_int = 6; -pub const Py_nb_add : c_int = 7; -pub const Py_nb_and : c_int = 8; -pub const Py_nb_bool : c_int = 9; -pub const Py_nb_divmod : c_int = 10; -pub const Py_nb_float : c_int = 11; -pub const Py_nb_floor_divide : c_int = 12; -pub const Py_nb_index : c_int = 13; -pub const Py_nb_inplace_add : c_int = 14; -pub const Py_nb_inplace_and : c_int = 15; -pub const Py_nb_inplace_floor_divide : c_int = 16; -pub const Py_nb_inplace_lshift : c_int = 17; -pub const Py_nb_inplace_multiply : c_int = 18; -pub const Py_nb_inplace_or : c_int = 19; -pub const Py_nb_inplace_power : c_int = 20; -pub const Py_nb_inplace_remainder : c_int = 21; -pub const Py_nb_inplace_rshift : c_int = 22; -pub const Py_nb_inplace_subtract : c_int = 23; -pub const Py_nb_inplace_true_divide : c_int = 24; -pub const Py_nb_inplace_xor : c_int = 25; -pub const Py_nb_int : c_int = 26; -pub const Py_nb_invert : c_int = 27; -pub const Py_nb_lshift : c_int = 28; -pub const Py_nb_multiply : c_int = 29; -pub const Py_nb_negative : c_int = 30; -pub const Py_nb_or : c_int = 31; -pub const Py_nb_positive : c_int = 32; -pub const Py_nb_power : c_int = 33; -pub const Py_nb_remainder : c_int = 34; -pub const Py_nb_rshift : c_int = 35; -pub const Py_nb_subtract : c_int = 36; -pub const Py_nb_true_divide : c_int = 37; -pub const Py_nb_xor : c_int = 38; -pub const Py_sq_ass_item : c_int = 39; -pub const Py_sq_concat : c_int = 40; -pub const Py_sq_contains : c_int = 41; -pub const Py_sq_inplace_concat : c_int = 42; -pub const Py_sq_inplace_repeat : c_int = 43; -pub const Py_sq_item : c_int = 44; -pub const Py_sq_length : c_int = 45; -pub const Py_sq_repeat : c_int = 46; -pub const Py_tp_alloc : c_int = 47; -pub const Py_tp_base : c_int = 48; -pub const Py_tp_bases : c_int = 49; -pub const Py_tp_call : c_int = 50; -pub const Py_tp_clear : c_int = 51; -pub const Py_tp_dealloc : c_int = 52; -pub const Py_tp_del : c_int = 53; -pub const Py_tp_descr_get : c_int = 54; -pub const Py_tp_descr_set : c_int = 55; -pub const Py_tp_doc : c_int = 56; -pub const Py_tp_getattr : c_int = 57; -pub const Py_tp_getattro : c_int = 58; -pub const Py_tp_hash : c_int = 59; -pub const Py_tp_init : c_int = 60; -pub const Py_tp_is_gc : c_int = 61; -pub const Py_tp_iter : c_int = 62; -pub const Py_tp_iternext : c_int = 63; -pub const Py_tp_methods : c_int = 64; -pub const Py_tp_new : c_int = 65; -pub const Py_tp_repr : c_int = 66; -pub const Py_tp_richcompare : c_int = 67; -pub const Py_tp_setattr : c_int = 68; -pub const Py_tp_setattro : c_int = 69; -pub const Py_tp_str : c_int = 70; -pub const Py_tp_traverse : c_int = 71; -pub const Py_tp_members : c_int = 72; -pub const Py_tp_getset : c_int = 73; -pub const Py_tp_free : c_int = 74; -pub const Py_nb_matrix_multiply : c_int = 75; -pub const Py_nb_inplace_matrix_multiply : c_int = 76; -pub const Py_am_await : c_int = 77; -pub const Py_am_aiter : c_int = 78; -pub const Py_am_anext : c_int = 79; -pub const Py_tp_finalize : c_int = 80; +pub const Py_mp_ass_subscript: c_int = 3; +pub const Py_mp_length: c_int = 4; +pub const Py_mp_subscript: c_int = 5; +pub const Py_nb_absolute: c_int = 6; +pub const Py_nb_add: c_int = 7; +pub const Py_nb_and: c_int = 8; +pub const Py_nb_bool: c_int = 9; +pub const Py_nb_divmod: c_int = 10; +pub const Py_nb_float: c_int = 11; +pub const Py_nb_floor_divide: c_int = 12; +pub const Py_nb_index: c_int = 13; +pub const Py_nb_inplace_add: c_int = 14; +pub const Py_nb_inplace_and: c_int = 15; +pub const Py_nb_inplace_floor_divide: c_int = 16; +pub const Py_nb_inplace_lshift: c_int = 17; +pub const Py_nb_inplace_multiply: c_int = 18; +pub const Py_nb_inplace_or: c_int = 19; +pub const Py_nb_inplace_power: c_int = 20; +pub const Py_nb_inplace_remainder: c_int = 21; +pub const Py_nb_inplace_rshift: c_int = 22; +pub const Py_nb_inplace_subtract: c_int = 23; +pub const Py_nb_inplace_true_divide: c_int = 24; +pub const Py_nb_inplace_xor: c_int = 25; +pub const Py_nb_int: c_int = 26; +pub const Py_nb_invert: c_int = 27; +pub const Py_nb_lshift: c_int = 28; +pub const Py_nb_multiply: c_int = 29; +pub const Py_nb_negative: c_int = 30; +pub const Py_nb_or: c_int = 31; +pub const Py_nb_positive: c_int = 32; +pub const Py_nb_power: c_int = 33; +pub const Py_nb_remainder: c_int = 34; +pub const Py_nb_rshift: c_int = 35; +pub const Py_nb_subtract: c_int = 36; +pub const Py_nb_true_divide: c_int = 37; +pub const Py_nb_xor: c_int = 38; +pub const Py_sq_ass_item: c_int = 39; +pub const Py_sq_concat: c_int = 40; +pub const Py_sq_contains: c_int = 41; +pub const Py_sq_inplace_concat: c_int = 42; +pub const Py_sq_inplace_repeat: c_int = 43; +pub const Py_sq_item: c_int = 44; +pub const Py_sq_length: c_int = 45; +pub const Py_sq_repeat: c_int = 46; +pub const Py_tp_alloc: c_int = 47; +pub const Py_tp_base: c_int = 48; +pub const Py_tp_bases: c_int = 49; +pub const Py_tp_call: c_int = 50; +pub const Py_tp_clear: c_int = 51; +pub const Py_tp_dealloc: c_int = 52; +pub const Py_tp_del: c_int = 53; +pub const Py_tp_descr_get: c_int = 54; +pub const Py_tp_descr_set: c_int = 55; +pub const Py_tp_doc: c_int = 56; +pub const Py_tp_getattr: c_int = 57; +pub const Py_tp_getattro: c_int = 58; +pub const Py_tp_hash: c_int = 59; +pub const Py_tp_init: c_int = 60; +pub const Py_tp_is_gc: c_int = 61; +pub const Py_tp_iter: c_int = 62; +pub const Py_tp_iternext: c_int = 63; +pub const Py_tp_methods: c_int = 64; +pub const Py_tp_new: c_int = 65; +pub const Py_tp_repr: c_int = 66; +pub const Py_tp_richcompare: c_int = 67; +pub const Py_tp_setattr: c_int = 68; +pub const Py_tp_setattro: c_int = 69; +pub const Py_tp_str: c_int = 70; +pub const Py_tp_traverse: c_int = 71; +pub const Py_tp_members: c_int = 72; +pub const Py_tp_getset: c_int = 73; +pub const Py_tp_free: c_int = 74; +pub const Py_nb_matrix_multiply: c_int = 75; +pub const Py_nb_inplace_matrix_multiply: c_int = 76; +pub const Py_am_await: c_int = 77; +pub const Py_am_aiter: c_int = 78; +pub const Py_am_anext: c_int = 79; +pub const Py_tp_finalize: c_int = 80; diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index ac87ab9fd8e..b5d01175367 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -1,7 +1,7 @@ -use libc::wchar_t; -use std::os::raw::{c_void, c_char, c_int}; use ffi3::object::*; use ffi3::pyport::Py_ssize_t; +use libc::wchar_t; +use std::os::raw::{c_char, c_int, c_void}; #[cfg(not(Py_LIMITED_API))] pub type Py_UNICODE = wchar_t; @@ -10,378 +10,453 @@ pub type Py_UCS4 = u32; pub type Py_UCS2 = u16; pub type Py_UCS1 = u8; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name="PyPyUnicode_Type")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; pub static mut PyUnicodeIter_Type: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyUnicode_Check")] -pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] +pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyUnicode_CheckExact")] -pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] +pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyUnicode_Type) as c_int } -pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; +pub const Py_UNICODE_REPLACEMENT_CHARACTER: Py_UCS4 = 0xFFFD; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; - + #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_CopyCharacters(to: *mut PyObject, to_start: Py_ssize_t, - from: *mut PyObject, - from_start: Py_ssize_t, - how_many: Py_ssize_t) -> Py_ssize_t; + pub fn PyUnicode_CopyCharacters( + to: *mut PyObject, + to_start: Py_ssize_t, + from: *mut PyObject, + from_start: Py_ssize_t, + how_many: Py_ssize_t, + ) -> Py_ssize_t; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_Fill(unicode: *mut PyObject, start: Py_ssize_t, - length: Py_ssize_t, fill_char: Py_UCS4) - -> Py_ssize_t; + pub fn PyUnicode_Fill( + unicode: *mut PyObject, + start: Py_ssize_t, + length: Py_ssize_t, + fill_char: Py_UCS4, + ) -> Py_ssize_t; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromUnicode")] - pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] + pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromStringAndSize")] - pub fn PyUnicode_FromStringAndSize(u: *const c_char, - size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] + pub fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; pub fn PyUnicode_FromString(u: *const c_char) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_FromKindAndData(kind: c_int, - buffer: *const c_void, - size: Py_ssize_t) -> *mut PyObject; + pub fn PyUnicode_FromKindAndData( + kind: c_int, + buffer: *const c_void, + size: Py_ssize_t, + ) -> *mut PyObject; - pub fn PyUnicode_Substring(str: *mut PyObject, start: Py_ssize_t, - end: Py_ssize_t) -> *mut PyObject; - pub fn PyUnicode_AsUCS4(unicode: *mut PyObject, buffer: *mut Py_UCS4, - buflen: Py_ssize_t, copy_null: c_int) - -> *mut Py_UCS4; + pub fn PyUnicode_Substring( + str: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + ) -> *mut PyObject; + pub fn PyUnicode_AsUCS4( + unicode: *mut PyObject, + buffer: *mut Py_UCS4, + buflen: Py_ssize_t, + copy_null: c_int, + ) -> *mut Py_UCS4; pub fn PyUnicode_AsUCS4Copy(unicode: *mut PyObject) -> *mut Py_UCS4; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicode")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeAndSize")] - pub fn PyUnicode_AsUnicodeAndSize(unicode: *mut PyObject, - size: *mut Py_ssize_t) - -> *mut Py_UNICODE; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetLength")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeAndSize")] + pub fn PyUnicode_AsUnicodeAndSize( + unicode: *mut PyObject, + size: *mut Py_ssize_t, + ) -> *mut Py_UNICODE; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetLength")] pub fn PyUnicode_GetLength(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetSize")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetSize")] pub fn PyUnicode_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - pub fn PyUnicode_ReadChar(unicode: *mut PyObject, index: Py_ssize_t) - -> Py_UCS4; - pub fn PyUnicode_WriteChar(unicode: *mut PyObject, index: Py_ssize_t, - character: Py_UCS4) -> c_int; + pub fn PyUnicode_ReadChar(unicode: *mut PyObject, index: Py_ssize_t) -> Py_UCS4; + pub fn PyUnicode_WriteChar( + unicode: *mut PyObject, + index: Py_ssize_t, + character: Py_UCS4, + ) -> c_int; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetMax")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] pub fn PyUnicode_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Resize")] - pub fn PyUnicode_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromEncodedObject")] - pub fn PyUnicode_FromEncodedObject(obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromObject")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] + pub fn PyUnicode_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] + pub fn PyUnicode_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] pub fn PyUnicode_FromObject(obj: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromFormat")] - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromFormatV")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormat")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromFormatV")] //pub fn PyUnicode_FromFormatV(format: *const c_char, // vargs: va_list) -> *mut PyObject; - pub fn PyUnicode_FromFormat(format: *const c_char, ...) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_InternInPlace")] + pub fn PyUnicode_FromFormat(format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_InternInPlace")] pub fn PyUnicode_InternInPlace(arg1: *mut *mut PyObject) -> (); pub fn PyUnicode_InternImmortal(arg1: *mut *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyUnicode_InternFromString")] - pub fn PyUnicode_InternFromString(u: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromWideChar")] - pub fn PyUnicode_FromWideChar(w: *const wchar_t, size: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideChar")] - pub fn PyUnicode_AsWideChar(unicode: *mut PyObject, w: *mut wchar_t, - size: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsWideCharString")] - pub fn PyUnicode_AsWideCharString(unicode: *mut PyObject, - size: *mut Py_ssize_t) -> *mut wchar_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FromOrdinal")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_InternFromString")] + pub fn PyUnicode_InternFromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromWideChar")] + pub fn PyUnicode_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] + pub fn PyUnicode_AsWideChar( + unicode: *mut PyObject, + w: *mut wchar_t, + size: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideCharString")] + pub fn PyUnicode_AsWideCharString( + unicode: *mut PyObject, + size: *mut Py_ssize_t, + ) -> *mut wchar_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8AndSize")] - pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, - size: *mut Py_ssize_t) - -> *mut c_char; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8AndSize")] + pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut c_char; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8")] pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name="PyPyUnicode_GetDefaultEncoding")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] pub fn PyUnicode_GetDefaultEncoding() -> *const c_char; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Decode")] - pub fn PyUnicode_Decode(s: *const c_char, size: Py_ssize_t, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - pub fn PyUnicode_AsDecodedObject(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_AsDecodedUnicode(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + pub fn PyUnicode_Decode( + s: *const c_char, + size: Py_ssize_t, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_AsDecodedObject( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_AsDecodedUnicode( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_Encode(s: *const Py_UNICODE, size: Py_ssize_t, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedObject")] - pub fn PyUnicode_AsEncodedObject(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsEncodedString")] - pub fn PyUnicode_AsEncodedString(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_AsEncodedUnicode(unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) - -> *mut PyObject; + pub fn PyUnicode_Encode( + s: *const Py_UNICODE, + size: Py_ssize_t, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] + pub fn PyUnicode_AsEncodedObject( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] + pub fn PyUnicode_AsEncodedString( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_AsEncodedUnicode( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; pub fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject; - pub fn PyUnicode_DecodeUTF7(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_DecodeUTF7Stateful(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - consumed: *mut Py_ssize_t) - -> *mut PyObject; + pub fn PyUnicode_DecodeUTF7( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeUTF7Stateful( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + consumed: *mut Py_ssize_t, + ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_EncodeUTF7(data: *const Py_UNICODE, length: Py_ssize_t, - base64SetO: c_int, - base64WhiteSpace: c_int, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF8")] - pub fn PyUnicode_DecodeUTF8(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_DecodeUTF8Stateful(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - consumed: *mut Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF8String")] + pub fn PyUnicode_EncodeUTF7( + data: *const Py_UNICODE, + length: Py_ssize_t, + base64SetO: c_int, + base64WhiteSpace: c_int, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] + pub fn PyUnicode_DecodeUTF8( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeUTF8Stateful( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + consumed: *mut Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] pub fn PyUnicode_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeUTF8")] - pub fn PyUnicode_EncodeUTF8(data: *const Py_UNICODE, length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF32")] - pub fn PyUnicode_DecodeUTF32(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - byteorder: *mut c_int) - -> *mut PyObject; - pub fn PyUnicode_DecodeUTF32Stateful(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - byteorder: *mut c_int, - consumed: *mut Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF32String")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] + pub fn PyUnicode_EncodeUTF8( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] + pub fn PyUnicode_DecodeUTF32( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + byteorder: *mut c_int, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeUTF32Stateful( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + byteorder: *mut c_int, + consumed: *mut Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] pub fn PyUnicode_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_EncodeUTF32(data: *const Py_UNICODE, length: Py_ssize_t, - errors: *const c_char, - byteorder: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeUTF16")] - pub fn PyUnicode_DecodeUTF16(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - byteorder: *mut c_int) - -> *mut PyObject; - pub fn PyUnicode_DecodeUTF16Stateful(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - byteorder: *mut c_int, - consumed: *mut Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUTF16String")] + pub fn PyUnicode_EncodeUTF32( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + byteorder: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] + pub fn PyUnicode_DecodeUTF16( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + byteorder: *mut c_int, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeUTF16Stateful( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + byteorder: *mut c_int, + consumed: *mut Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] pub fn PyUnicode_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_EncodeUTF16(data: *const Py_UNICODE, length: Py_ssize_t, - errors: *const c_char, - byteorder: c_int) -> *mut PyObject; - pub fn PyUnicode_DecodeUnicodeEscape(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsUnicodeEscapeString")] - pub fn PyUnicode_AsUnicodeEscapeString(unicode: *mut PyObject) - -> *mut PyObject; + pub fn PyUnicode_EncodeUTF16( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + byteorder: c_int, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeUnicodeEscape( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] + pub fn PyUnicode_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_EncodeUnicodeEscape(data: *const Py_UNICODE, - length: Py_ssize_t) -> *mut PyObject; - pub fn PyUnicode_DecodeRawUnicodeEscape(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_AsRawUnicodeEscapeString(unicode: *mut PyObject) - -> *mut PyObject; + pub fn PyUnicode_EncodeUnicodeEscape( + data: *const Py_UNICODE, + length: Py_ssize_t, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeRawUnicodeEscape( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_AsRawUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_EncodeRawUnicodeEscape(data: *const Py_UNICODE, - length: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeLatin1")] - pub fn PyUnicode_DecodeLatin1(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsLatin1String")] + pub fn PyUnicode_EncodeRawUnicodeEscape( + data: *const Py_UNICODE, + length: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] + pub fn PyUnicode_DecodeLatin1( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] pub fn PyUnicode_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeLatin1")] - pub fn PyUnicode_EncodeLatin1(data: *const Py_UNICODE, length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeASCII")] - pub fn PyUnicode_DecodeASCII(string: *const c_char, - length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_AsASCIIString")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] + pub fn PyUnicode_EncodeLatin1( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] + pub fn PyUnicode_DecodeASCII( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] pub fn PyUnicode_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeASCII")] - pub fn PyUnicode_EncodeASCII(data: *const Py_UNICODE, length: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_DecodeCharmap(string: *const c_char, - length: Py_ssize_t, mapping: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_AsCharmapString(unicode: *mut PyObject, - mapping: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] + pub fn PyUnicode_EncodeASCII( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeCharmap( + string: *const c_char, + length: Py_ssize_t, + mapping: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_AsCharmapString( + unicode: *mut PyObject, + mapping: *mut PyObject, + ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_EncodeCharmap(data: *const Py_UNICODE, - length: Py_ssize_t, mapping: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; + pub fn PyUnicode_EncodeCharmap( + data: *const Py_UNICODE, + length: Py_ssize_t, + mapping: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; #[cfg(not(Py_LIMITED_API))] - pub fn PyUnicode_TranslateCharmap(data: *const Py_UNICODE, - length: Py_ssize_t, - table: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; - + pub fn PyUnicode_TranslateCharmap( + data: *const Py_UNICODE, + length: Py_ssize_t, + table: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeDecimal")] - pub fn PyUnicode_EncodeDecimal(s: *mut Py_UNICODE, length: Py_ssize_t, - output: *mut c_char, - errors: *const c_char) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] + pub fn PyUnicode_EncodeDecimal( + s: *mut Py_UNICODE, + length: Py_ssize_t, + output: *mut c_char, + errors: *const c_char, + ) -> c_int; #[cfg(not(Py_LIMITED_API))] - #[cfg_attr(PyPy, link_name="PyPyUnicode_TransformDecimalToASCII")] - pub fn PyUnicode_TransformDecimalToASCII(s: *mut Py_UNICODE, - length: Py_ssize_t) - -> *mut PyObject; - pub fn PyUnicode_DecodeLocaleAndSize(str: *const c_char, - len: Py_ssize_t, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_DecodeLocale(str: *const c_char, - errors: *const c_char) - -> *mut PyObject; - pub fn PyUnicode_EncodeLocale(unicode: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FSConverter")] - pub fn PyUnicode_FSConverter(arg1: *mut PyObject, - arg2: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_FSDecoder")] - pub fn PyUnicode_FSDecoder(arg1: *mut PyObject, arg2: *mut c_void) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeFSDefault")] - pub fn PyUnicode_DecodeFSDefault(s: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_DecodeFSDefaultAndSize")] - pub fn PyUnicode_DecodeFSDefaultAndSize(s: *const c_char, - size: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_EncodeFSDefault")] + #[cfg_attr(PyPy, link_name = "PyPyUnicode_TransformDecimalToASCII")] + pub fn PyUnicode_TransformDecimalToASCII( + s: *mut Py_UNICODE, + length: Py_ssize_t, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeLocaleAndSize( + str: *const c_char, + len: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + pub fn PyUnicode_DecodeLocale(str: *const c_char, errors: *const c_char) -> *mut PyObject; + pub fn PyUnicode_EncodeLocale(unicode: *mut PyObject, errors: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FSConverter")] + pub fn PyUnicode_FSConverter(arg1: *mut PyObject, arg2: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FSDecoder")] + pub fn PyUnicode_FSDecoder(arg1: *mut PyObject, arg2: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeFSDefault")] + pub fn PyUnicode_DecodeFSDefault(s: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeFSDefaultAndSize")] + pub fn PyUnicode_DecodeFSDefaultAndSize(s: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeFSDefault")] pub fn PyUnicode_EncodeFSDefault(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Concat")] - pub fn PyUnicode_Concat(left: *mut PyObject, right: *mut PyObject) - -> *mut PyObject; - pub fn PyUnicode_Append(pleft: *mut *mut PyObject, right: *mut PyObject) - -> (); - pub fn PyUnicode_AppendAndDel(pleft: *mut *mut PyObject, - right: *mut PyObject) -> (); - #[cfg_attr(PyPy, link_name="PyPyUnicode_Split")] - pub fn PyUnicode_Split(s: *mut PyObject, sep: *mut PyObject, - maxsplit: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Splitlines")] - pub fn PyUnicode_Splitlines(s: *mut PyObject, keepends: c_int) - -> *mut PyObject; - pub fn PyUnicode_Partition(s: *mut PyObject, sep: *mut PyObject) - -> *mut PyObject; - pub fn PyUnicode_RPartition(s: *mut PyObject, sep: *mut PyObject) - -> *mut PyObject; - pub fn PyUnicode_RSplit(s: *mut PyObject, sep: *mut PyObject, - maxsplit: Py_ssize_t) -> *mut PyObject; - pub fn PyUnicode_Translate(str: *mut PyObject, table: *mut PyObject, - errors: *const c_char) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Join")] - pub fn PyUnicode_Join(separator: *mut PyObject, seq: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Tailmatch")] - pub fn PyUnicode_Tailmatch(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Find")] - pub fn PyUnicode_Find(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - pub fn PyUnicode_FindChar(str: *mut PyObject, ch: Py_UCS4, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Count")] - pub fn PyUnicode_Count(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Replace")] - pub fn PyUnicode_Replace(str: *mut PyObject, substr: *mut PyObject, - replstr: *mut PyObject, maxcount: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Compare")] - pub fn PyUnicode_Compare(left: *mut PyObject, right: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name="PyPyUnicode_CompareWithASCIIString")] - pub fn PyUnicode_CompareWithASCIIString(left: *mut PyObject, - right: *const c_char) - -> c_int; - pub fn PyUnicode_RichCompare(left: *mut PyObject, right: *mut PyObject, - op: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyUnicode_Format")] - pub fn PyUnicode_Format(format: *mut PyObject, args: *mut PyObject) - -> *mut PyObject; - pub fn PyUnicode_Contains(container: *mut PyObject, - element: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] + pub fn PyUnicode_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; + pub fn PyUnicode_Append(pleft: *mut *mut PyObject, right: *mut PyObject) -> (); + pub fn PyUnicode_AppendAndDel(pleft: *mut *mut PyObject, right: *mut PyObject) -> (); + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] + pub fn PyUnicode_Split( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] + pub fn PyUnicode_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject; + pub fn PyUnicode_Partition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject; + pub fn PyUnicode_RPartition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject; + pub fn PyUnicode_RSplit( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + pub fn PyUnicode_Translate( + str: *mut PyObject, + table: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] + pub fn PyUnicode_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] + pub fn PyUnicode_Tailmatch( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] + pub fn PyUnicode_Find( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + pub fn PyUnicode_FindChar( + str: *mut PyObject, + ch: Py_UCS4, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] + pub fn PyUnicode_Count( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] + pub fn PyUnicode_Replace( + str: *mut PyObject, + substr: *mut PyObject, + replstr: *mut PyObject, + maxcount: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] + pub fn PyUnicode_Compare(left: *mut PyObject, right: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_CompareWithASCIIString")] + pub fn PyUnicode_CompareWithASCIIString(left: *mut PyObject, right: *const c_char) -> c_int; + pub fn PyUnicode_RichCompare( + left: *mut PyObject, + right: *mut PyObject, + op: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] + pub fn PyUnicode_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; + pub fn PyUnicode_Contains(container: *mut PyObject, element: *mut PyObject) -> c_int; pub fn PyUnicode_IsIdentifier(s: *mut PyObject) -> c_int; #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_AsUnicodeCopy(unicode: *mut PyObject) -> *mut Py_UNICODE; -} \ No newline at end of file +} diff --git a/src/ffi3/warnings.rs b/src/ffi3/warnings.rs index a7aa9f5175d..4494ce0c016 100644 --- a/src/ffi3/warnings.rs +++ b/src/ffi3/warnings.rs @@ -1,23 +1,34 @@ -use std::os::raw::{c_char, c_int}; -use ffi3::pyport::Py_ssize_t; use ffi3::object::PyObject; +use ffi3::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, - message: *const c_char, - stack_level: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name="PyPyErr_WarnFormat")] - pub fn PyErr_WarnFormat(category: *mut PyObject, stack_level: Py_ssize_t, - format: *const c_char, ...) - -> c_int; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyErr_WarnEx( + category: *mut PyObject, + message: *const c_char, + stack_level: Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_WarnFormat")] + pub fn PyErr_WarnFormat( + category: *mut PyObject, + stack_level: Py_ssize_t, + format: *const c_char, + ... + ) -> c_int; #[cfg(Py_3_6)] pub fn PyErr_ResourceWarning( - source: *mut PyObject, stack_level: Py_ssize_t, - format: *const c_char, ...) -> c_int; - pub fn PyErr_WarnExplicit(category: *mut PyObject, - message: *const c_char, - filename: *const c_char, - lineno: c_int, - module: *const c_char, - registry: *mut PyObject) -> c_int; -} \ No newline at end of file + source: *mut PyObject, + stack_level: Py_ssize_t, + format: *const c_char, + ... + ) -> c_int; + pub fn PyErr_WarnExplicit( + category: *mut PyObject, + message: *const c_char, + filename: *const c_char, + lineno: c_int, + module: *const c_char, + registry: *mut PyObject, + ) -> c_int; +} diff --git a/src/ffi3/weakrefobject.rs b/src/ffi3/weakrefobject.rs index 0e8e45a2441..e65ab08326d 100644 --- a/src/ffi3/weakrefobject.rs +++ b/src/ffi3/weakrefobject.rs @@ -1,31 +1,32 @@ -use std::os::raw::c_int; use ffi3::object::*; +use std::os::raw::c_int; pub enum PyWeakReference {} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { static mut _PyWeakref_RefType: PyTypeObject; static mut _PyWeakref_ProxyType: PyTypeObject; static mut _PyWeakref_CallableProxyType: PyTypeObject; } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRef")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckRefExact")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline(always)] -#[cfg_attr(PyPy, link_name="PyPyWeakref_CheckProxy")] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckProxy")] pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int { - ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) || - (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int + ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) + || (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int } #[inline(always)] @@ -33,13 +34,12 @@ 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" { - #[cfg_attr(PyPy, link_name="PyPyWeakref_NewRef")] - pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyWeakref_NewProxy")] - pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name="PyPyWeakref_GetObject")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")] + pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")] + pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")] pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject; -} \ No newline at end of file +} diff --git a/src/freelist.rs b/src/freelist.rs index e8c9cb65043..5dbf0bd5505 100644 --- a/src/freelist.rs +++ b/src/freelist.rs @@ -3,18 +3,16 @@ //! Free allocation list use std; -use ffi; use err::PyResult; +use ffi; use python::Python; -use typeob::{PyTypeInfo, PyObjectAlloc}; +use typeob::{PyObjectAlloc, PyTypeInfo}; /// Implementing this trait for custom class adds free allocation list to class. /// The performance improvement applies to types that are often created and deleted in a row, /// so that they can benefit from a freelist. pub trait PyObjectWithFreeList: PyTypeInfo { - fn get_free_list() -> &'static mut FreeList<*mut ffi::PyObject>; - } pub enum Slot { @@ -29,7 +27,6 @@ pub struct FreeList { } impl FreeList { - /// Create new `FreeList` instance with specified capacity pub fn with_capacity(capacity: usize) -> FreeList { let entries = (0..capacity).map(|_| Slot::Empty).collect::>(); @@ -47,12 +44,12 @@ impl FreeList { if idx == 0 { None } else { - match std::mem::replace(&mut self.entries[idx-1], Slot::Empty) { + match std::mem::replace(&mut self.entries[idx - 1], Slot::Empty) { Slot::Filled(v) => { self.split = idx - 1; Some(v) } - _ => panic!("FreeList is corrupt") + _ => panic!("FreeList is corrupt"), } } } @@ -70,9 +67,10 @@ impl FreeList { } } - -impl PyObjectAlloc for T where T: PyObjectWithFreeList { - +impl PyObjectAlloc for T +where + T: PyObjectWithFreeList, +{ unsafe fn alloc(_py: Python) -> PyResult<*mut ffi::PyObject> { let obj = if let Some(obj) = ::get_free_list().pop() { ffi::PyObject_Init(obj, ::type_object()); @@ -89,7 +87,7 @@ impl PyObjectAlloc for T where T: PyObjectWithFreeList { Self::drop(py, obj); if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 { - return + return; } if let Some(obj) = ::get_free_list().insert(obj) { diff --git a/src/instance.rs b/src/instance.rs index b1a9f3941df..18744940781 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1,24 +1,22 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use std; -use std::rc::Rc; use std::marker::PhantomData; +use std::rc::Rc; +use conversion::{FromPyObject, IntoPyObject, ToPyObject}; +use err::{PyErr, PyResult}; use ffi; -use pythonrun; -use err::{PyResult, PyErr}; use object::PyObject; -use objects::PyObjectRef; use objectprotocol::ObjectProtocol; -use conversion::{ToPyObject, IntoPyObject, FromPyObject}; -use python::{Python, IntoPyPointer, ToPyPointer}; +use objects::PyObjectRef; +use python::{IntoPyPointer, Python, ToPyPointer}; +use pythonrun; use typeob::{PyTypeInfo, PyTypeObject}; - pub struct PyToken(PhantomData>); impl PyToken { - pub(crate) fn new() -> PyToken { PyToken(PhantomData) } @@ -38,10 +36,8 @@ pub trait PyObjectWithToken: Sized { #[doc(hidden)] pub trait PyNativeType: PyObjectWithToken {} - /// Trait implements object reference extraction from python managed pointer. pub trait AsPyRef: Sized { - /// Return reference to object. fn as_ref(&self, py: Python) -> &T; @@ -50,7 +46,9 @@ pub trait AsPyRef: Sized { fn as_mut(&self, py: Python) -> &mut T; /// Acquire python gil and call closure with object reference. - fn with(&self, f: F) -> R where F: FnOnce(Python, &T) -> R + fn with(&self, f: F) -> R + where + F: FnOnce(Python, &T) -> R, { let gil = Python::acquire_gil(); let py = gil.python(); @@ -59,7 +57,9 @@ pub trait AsPyRef: Sized { } /// Acquire python gil and call closure with mutable object reference. - fn with_mut(&self, f: F) -> R where F: FnOnce(Python, &mut T) -> R + fn with_mut(&self, f: F) -> R + where + F: FnOnce(Python, &mut T) -> R, { let gil = Python::acquire_gil(); let py = gil.python(); @@ -68,7 +68,9 @@ pub trait AsPyRef: Sized { } fn into_py(self, f: F) -> R - where Self: IntoPyPointer, F: FnOnce(Python, &T) -> R + where + Self: IntoPyPointer, + F: FnOnce(Python, &T) -> R, { let gil = Python::acquire_gil(); let py = gil.python(); @@ -79,7 +81,9 @@ pub trait AsPyRef: Sized { } fn into_mut_py(self, f: F) -> R - where Self: IntoPyPointer, F: FnOnce(Python, &mut T) -> R + where + Self: IntoPyPointer, + F: FnOnce(Python, &mut T) -> R, { let gil = Python::acquire_gil(); let py = gil.python(); @@ -98,15 +102,16 @@ pub struct Py(pub *mut ffi::PyObject, std::marker::PhantomData); unsafe impl Send for Py {} unsafe impl Sync for Py {} - impl Py { /// Creates a `Py` instance for the given FFI pointer. /// This moves ownership over the pointer into the `Py`. /// Undefined behavior if the pointer is NULL or invalid. #[inline] pub unsafe fn from_owned_ptr(ptr: *mut ffi::PyObject) -> Py { - debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, - format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr))); + debug_assert!( + !ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, + format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr)) + ); Py(ptr, std::marker::PhantomData) } @@ -114,8 +119,7 @@ impl Py { /// Panics if the pointer is `null`. /// Undefined behavior if the pointer is invalid. #[inline] - pub unsafe fn from_owned_ptr_or_panic(ptr: *mut ffi::PyObject) -> Py - { + pub unsafe fn from_owned_ptr_or_panic(ptr: *mut ffi::PyObject) -> Py { if ptr.is_null() { ::err::panic_after_error(); } else { @@ -127,8 +131,7 @@ impl Py { /// returns a new reference (owned pointer). /// Returns `Err(PyErr)` if the pointer is `null`. /// Unsafe because the pointer might be invalid. - pub unsafe fn from_owned_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) -> PyResult> - { + pub unsafe fn from_owned_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) -> PyResult> { if ptr.is_null() { Err(PyErr::fetch(py)) } else { @@ -141,8 +144,10 @@ impl Py { /// Undefined behavior if the pointer is NULL or invalid. #[inline] pub unsafe fn from_borrowed_ptr(ptr: *mut ffi::PyObject) -> Py { - debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, - format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr))); + debug_assert!( + !ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, + format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr)) + ); ffi::Py_INCREF(ptr); Py::from_owned_ptr(ptr) } @@ -160,56 +165,55 @@ impl Py { } } - -impl Py where T: PyTypeInfo, +impl Py +where + T: PyTypeInfo, { /// Create new instance of T and move it under python management /// Returns `Py`. pub fn new(py: Python, f: F) -> PyResult> - where F: FnOnce(::PyToken) -> T, - T: PyTypeObject + PyTypeInfo + where + F: FnOnce(::PyToken) -> T, + T: PyTypeObject + PyTypeInfo, { let ob = ::create(py)?; ob.init(f)?; - let ob = unsafe { - Py::from_owned_ptr(ob.into_ptr()) - }; + let ob = unsafe { Py::from_owned_ptr(ob.into_ptr()) }; Ok(ob) } /// Create new instance of `T` and move it under python management. /// Returns references to `T` pub fn new_ref(py: Python, f: F) -> PyResult<&T> - where F: FnOnce(::PyToken) -> T, - T: PyTypeObject + PyTypeInfo + where + F: FnOnce(::PyToken) -> T, + T: PyTypeObject + PyTypeInfo, { let ob = ::create(py)?; ob.init(f)?; - unsafe { - Ok(py.from_owned_ptr(ob.into_ptr())) - } + unsafe { Ok(py.from_owned_ptr(ob.into_ptr())) } } /// Create new instance of `T` and move it under python management. /// Returns mutable references to `T` pub fn new_mut(py: Python, f: F) -> PyResult<&mut T> - where F: FnOnce(::PyToken) -> T, - T: PyTypeObject + PyTypeInfo + where + F: FnOnce(::PyToken) -> T, + T: PyTypeObject + PyTypeInfo, { let ob = ::create(py)?; ob.init(f)?; - unsafe { - Ok(py.mut_from_owned_ptr(ob.into_ptr())) - } + unsafe { Ok(py.mut_from_owned_ptr(ob.into_ptr())) } } - } -impl AsPyRef for Py where T: PyTypeInfo { - +impl AsPyRef for Py +where + T: PyTypeInfo, +{ #[inline] default fn as_ref(&self, _py: Python) -> &T { unsafe { @@ -226,11 +230,13 @@ impl AsPyRef for Py where T: PyTypeInfo { } } -impl AsPyRef for Py where T: PyTypeInfo + PyNativeType { - +impl AsPyRef for Py +where + T: PyTypeInfo + PyNativeType, +{ #[inline] fn as_ref(&self, _py: Python) -> &T { - unsafe {std::mem::transmute(self)} + unsafe { std::mem::transmute(self) } } #[inline] fn as_mut(&self, _py: Python) -> &mut T { @@ -241,9 +247,7 @@ impl AsPyRef for Py where T: PyTypeInfo + PyNativeType { impl ToPyObject for Py { /// Converts `Py` instance -> PyObject. fn to_object(&self, py: Python) -> PyObject { - unsafe { - PyObject::from_borrowed_ptr(py, self.as_ptr()) - } + unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) } } } @@ -284,22 +288,23 @@ impl PartialEq for Py { /// Dropping a `Py` instance decrements the reference count on the object by 1. impl Drop for Py { - fn drop(&mut self) { - unsafe { pythonrun::register_pointer(self.0); } + unsafe { + pythonrun::register_pointer(self.0); + } } } - impl std::convert::From> for PyObject { #[inline] fn from(ob: Py) -> Self { - unsafe {std::mem::transmute(ob)} + unsafe { std::mem::transmute(ob) } } } impl<'a, T> std::convert::From<&'a T> for Py - where T: ToPyPointer +where + T: ToPyPointer, { fn from(ob: &'a T) -> Self { unsafe { Py::from_borrowed_ptr(ob.as_ptr()) } @@ -307,7 +312,8 @@ impl<'a, T> std::convert::From<&'a T> for Py } impl<'a, T> std::convert::From<&'a mut T> for Py - where T: ToPyPointer +where + T: ToPyPointer, { fn from(ob: &'a mut T) -> Self { unsafe { Py::from_borrowed_ptr(ob.as_ptr()) } @@ -315,7 +321,8 @@ impl<'a, T> std::convert::From<&'a mut T> for Py } impl<'a, T> std::convert::From<&'a T> for PyObject - where T: ToPyPointer, +where + T: ToPyPointer, { fn from(ob: &'a T) -> Self { unsafe { Py::::from_borrowed_ptr(ob.as_ptr()) }.into() @@ -323,7 +330,8 @@ impl<'a, T> std::convert::From<&'a T> for PyObject } impl<'a, T> std::convert::From<&'a mut T> for PyObject - where T: ToPyPointer, +where + T: ToPyPointer, { fn from(ob: &'a mut T) -> Self { unsafe { Py::::from_borrowed_ptr(ob.as_ptr()) }.into() @@ -331,13 +339,15 @@ impl<'a, T> std::convert::From<&'a mut T> for PyObject } impl<'a, T> FromPyObject<'a> for Py - where T: ToPyPointer, &'a T: 'a + FromPyObject<'a> +where + T: ToPyPointer, + &'a T: 'a + FromPyObject<'a>, { /// Extracts `Self` from the source `PyObject`. - fn extract(ob: &'a PyObjectRef) -> PyResult - { + fn extract(ob: &'a PyObjectRef) -> PyResult { unsafe { - ob.extract::<&T>().map(|val| Py::from_borrowed_ptr(val.as_ptr())) + ob.extract::<&T>() + .map(|val| Py::from_borrowed_ptr(val.as_ptr())) } } } diff --git a/src/lib.rs b/src/lib.rs index c3e2d75b612..6038df6d74f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,7 +123,7 @@ //! cp ./target/debug/libhello.so ./hello.so //! ``` //! -//! (Note: on macOS you will have to rename `libhello.dynlib` to `libhello.so`. +//! (Note: on macOS you will have to rename `libhello.dynlib` to `libhello.so`. //! To build on macOS, use `-C link-arg=-undefined -C link-arg=dynamic_lookup` //! is required to build the library. //! `setuptools-rust` includes this by default. @@ -138,9 +138,10 @@ //! ``` extern crate libc; -extern crate spin; extern crate pyo3cls; -#[macro_use] extern crate log; +extern crate spin; +#[macro_use] +extern crate log; #[macro_use] extern crate pretty_assertions; @@ -160,23 +161,24 @@ pub mod ffi { pub use ffi3::*; } -pub use err::{PyErr, PyErrValue, PyResult, PyDowncastError, PyErrArguments}; -pub use objects::*; -pub use objectprotocol::ObjectProtocol; -pub use object::PyObject; +pub use conversion::{ + FromPyObject, IntoPyObject, IntoPyTuple, PyTryFrom, PyTryInto, ToBorrowedObject, ToPyObject, +}; +pub use err::{PyDowncastError, PyErr, PyErrArguments, PyErrValue, PyResult}; +pub use instance::{AsPyRef, Py, PyNativeType, PyObjectWithToken, PyToken}; pub use noargs::NoArgs; -pub use typeob::{PyTypeInfo, PyRawObject, PyObjectAlloc}; -pub use python::{Python, ToPyPointer, IntoPyPointer, IntoPyDictPointer}; -pub use pythonrun::{GILGuard, GILPool, prepare_freethreaded_python, prepare_pyo3_library}; -pub use instance::{PyToken, PyObjectWithToken, AsPyRef, Py, PyNativeType}; -pub use conversion::{FromPyObject, PyTryFrom, PyTryInto, - ToPyObject, ToBorrowedObject, IntoPyObject, IntoPyTuple}; +pub use object::PyObject; +pub use objectprotocol::ObjectProtocol; +pub use objects::*; +pub use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; +pub use pythonrun::{prepare_freethreaded_python, prepare_pyo3_library, GILGuard, GILPool}; +pub use typeob::{PyObjectAlloc, PyRawObject, PyTypeInfo}; pub mod class; pub use class::*; /// Procedural macros pub mod py { - pub use pyo3cls::{proto, class, methods}; + pub use pyo3cls::{class, methods, proto}; #[cfg(Py_3)] pub use pyo3cls::mod3init as modinit; @@ -195,23 +197,23 @@ macro_rules! cstr( ); ); -mod python; -mod err; +#[doc(hidden)] +pub mod argparse; +pub mod buffer; +#[doc(hidden)] +pub mod callback; mod conversion; +mod err; +pub mod freelist; mod instance; +mod noargs; mod object; -mod objects; mod objectprotocol; -mod noargs; +mod objects; +pub mod prelude; +mod python; mod pythonrun; -#[doc(hidden)] -pub mod callback; pub mod typeob; -#[doc(hidden)] -pub mod argparse; -pub mod buffer; -pub mod freelist; -pub mod prelude; // re-export for simplicity #[doc(hidden)] diff --git a/src/noargs.rs b/src/noargs.rs index d0e010ba0a7..c798dbeb7bc 100644 --- a/src/noargs.rs +++ b/src/noargs.rs @@ -2,12 +2,12 @@ use std; +use conversion::{IntoPyObject, IntoPyTuple, ToPyObject}; use ffi; use instance::Py; -use python::{Python, IntoPyDictPointer}; -use conversion::{ToPyObject, IntoPyObject, IntoPyTuple}; use object::PyObject; use objects::PyTuple; +use python::{IntoPyDictPointer, Python}; /// An empty struct that represents the empty argument list. /// Corresponds to the empty tuple `()` in Python. @@ -24,7 +24,6 @@ pub struct NoArgs; /// Converts `NoArgs` to an empty Python tuple. impl IntoPyTuple for NoArgs { - fn into_tuple(self, py: Python) -> Py { PyTuple::empty(py) } @@ -32,7 +31,6 @@ impl IntoPyTuple for NoArgs { /// Converts `()` to an empty Python tuple. impl IntoPyTuple for () { - fn into_tuple(self, py: Python) -> Py { PyTuple::empty(py) } @@ -40,7 +38,6 @@ impl IntoPyTuple for () { /// Converts `NoArgs` to an empty Python tuple. impl ToPyObject for NoArgs { - fn to_object(&self, py: Python) -> PyObject { PyTuple::empty(py).into() } @@ -48,7 +45,6 @@ impl ToPyObject for NoArgs { /// Converts `NoArgs` to an empty Python tuple. impl IntoPyObject for NoArgs { - fn into_object(self, py: Python) -> PyObject { PyTuple::empty(py).into() } @@ -56,7 +52,6 @@ impl IntoPyObject for NoArgs { /// Converts `NoArgs` to an null pointer. impl IntoPyDictPointer for NoArgs { - fn into_dict_ptr(self, _: Python) -> *mut ffi::PyObject { std::ptr::null_mut() } @@ -64,7 +59,6 @@ impl IntoPyDictPointer for NoArgs { /// Converts `()` to an null pointer. impl IntoPyDictPointer for () { - fn into_dict_ptr(self, _: Python) -> *mut ffi::PyObject { std::ptr::null_mut() } diff --git a/src/object.rs b/src/object.rs index 59f00dfce23..6e0f5a05b06 100644 --- a/src/object.rs +++ b/src/object.rs @@ -2,15 +2,15 @@ use std; +use conversion::{ + FromPyObject, IntoPyObject, IntoPyTuple, PyTryFrom, ToBorrowedObject, ToPyObject, +}; +use err::{PyDowncastError, PyErr, PyResult}; use ffi; -use pythonrun; -use err::{PyErr, PyResult, PyDowncastError}; use instance::{AsPyRef, PyObjectWithToken}; -use objects::{PyTuple, PyObjectRef}; -use conversion::{ToPyObject, ToBorrowedObject, - IntoPyObject, IntoPyTuple, FromPyObject, PyTryFrom}; -use python::{Python, ToPyPointer, IntoPyPointer, IntoPyDictPointer}; - +use objects::{PyObjectRef, PyTuple}; +use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; +use pythonrun; /// Safe wrapper around unsafe `*mut ffi::PyObject` pointer. #[derive(Debug)] @@ -20,15 +20,16 @@ pub struct PyObject(*mut ffi::PyObject); unsafe impl Send for PyObject {} unsafe impl Sync for PyObject {} - impl PyObject { /// Creates a `PyObject` instance for the given FFI pointer. /// This moves ownership over the pointer into the `PyObject`. /// Undefined behavior if the pointer is NULL or invalid. #[inline] pub unsafe fn from_owned_ptr(_py: Python, ptr: *mut ffi::PyObject) -> PyObject { - debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, - format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr))); + debug_assert!( + !ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, + format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr)) + ); PyObject(ptr) } @@ -36,8 +37,7 @@ impl PyObject { /// Panics if the pointer is `null`. /// Undefined behavior if the pointer is invalid. #[inline] - pub unsafe fn from_owned_ptr_or_panic(py: Python, ptr: *mut ffi::PyObject) -> PyObject - { + pub unsafe fn from_owned_ptr_or_panic(py: Python, ptr: *mut ffi::PyObject) -> PyObject { if ptr.is_null() { ::err::panic_after_error(); } else { @@ -48,9 +48,7 @@ impl PyObject { /// Construct `PyObject` from the result of a Python FFI call that /// returns a new reference (owned pointer). /// Returns `Err(PyErr)` if the pointer is `null`. - pub unsafe fn from_owned_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) - -> PyResult - { + pub unsafe fn from_owned_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) -> PyResult { if ptr.is_null() { Err(PyErr::fetch(py)) } else { @@ -61,8 +59,7 @@ impl PyObject { /// Construct `PyObject` from the result of a Python FFI call that /// returns a new reference (owned pointer). /// Returns `None` if the pointer is `null`. - pub unsafe fn from_owned_ptr_or_opt(py: Python, ptr: *mut ffi::PyObject) -> Option - { + pub unsafe fn from_owned_ptr_or_opt(py: Python, ptr: *mut ffi::PyObject) -> Option { if ptr.is_null() { None } else { @@ -75,8 +72,10 @@ impl PyObject { /// Undefined behavior if the pointer is NULL or invalid. #[inline] pub unsafe fn from_borrowed_ptr(_py: Python, ptr: *mut ffi::PyObject) -> PyObject { - debug_assert!(!ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, - format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr))); + debug_assert!( + !ptr.is_null() && ffi::Py_REFCNT(ptr) > 0, + format!("REFCNT: {:?} - {:?}", ptr, ffi::Py_REFCNT(ptr)) + ); ffi::Py_INCREF(ptr); PyObject(ptr) } @@ -84,9 +83,10 @@ impl PyObject { /// Creates a `PyObject` instance for the given Python FFI pointer. /// Calls Py_INCREF() on the ptr. /// Returns `Err(PyErr)` if the pointer is `null`. - pub unsafe fn from_borrowed_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) - -> PyResult - { + pub unsafe fn from_borrowed_ptr_or_err( + py: Python, + ptr: *mut ffi::PyObject, + ) -> PyResult { if ptr.is_null() { Err(PyErr::fetch(py)) } else { @@ -97,9 +97,10 @@ impl PyObject { /// Creates a `PyObject` instance for the given Python FFI pointer. /// Calls Py_INCREF() on the ptr. /// Returns `None` if the pointer is `null`. - pub unsafe fn from_borrowed_ptr_or_opt(py: Python, ptr: *mut ffi::PyObject) - -> Option - { + pub unsafe fn from_borrowed_ptr_or_opt( + py: Python, + ptr: *mut ffi::PyObject, + ) -> Option { if ptr.is_null() { None } else { @@ -114,9 +115,7 @@ impl PyObject { /// Clone self, Calls Py_INCREF() on the ptr. pub fn clone_ref(&self, py: Python) -> Self { - unsafe { - PyObject::from_borrowed_ptr(py, self.as_ptr()) - } + unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) } } /// Returns whether the object is considered to be None. @@ -138,14 +137,17 @@ impl PyObject { /// Casts the PyObject to a concrete Python object type. pub fn cast_as(&self, py: Python) -> Result<&D, ::Error> - where D: PyTryFrom + where + D: PyTryFrom, { D::try_from(self.as_ref(py)) } /// Extracts some type from the Python object. /// This is a wrapper function around `FromPyObject::extract()`. - pub fn extract<'p, D>(&'p self, py: Python) -> PyResult where D: FromPyObject<'p> + pub fn extract<'p, D>(&'p self, py: Python) -> PyResult + where + D: FromPyObject<'p>, { FromPyObject::extract(self.as_ref(py)) } @@ -153,25 +155,25 @@ impl PyObject { /// Retrieves an attribute value. /// This is equivalent to the Python expression 'self.attr_name'. pub fn getattr(&self, py: Python, attr_name: N) -> PyResult - where N: ToPyObject + where + N: ToPyObject, { attr_name.with_borrowed_ptr(py, |attr_name| unsafe { - PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_GetAttr(self.as_ptr(), attr_name)) + PyObject::from_owned_ptr_or_err(py, ffi::PyObject_GetAttr(self.as_ptr(), attr_name)) }) } /// Calls the object. /// This is equivalent to the Python expression: 'self(*args, **kwargs)' pub fn call(&self, py: Python, args: A, kwargs: K) -> PyResult - where A: IntoPyTuple, - K: IntoPyDictPointer + where + A: IntoPyTuple, + K: IntoPyDictPointer, { let args = args.into_tuple(py).into_ptr(); let kwargs = kwargs.into_dict_ptr(py); let result = unsafe { - PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_Call(self.as_ptr(), args, kwargs)) + PyObject::from_owned_ptr_or_err(py, ffi::PyObject_Call(self.as_ptr(), args, kwargs)) }; py.xdecref(args); py.xdecref(kwargs); @@ -180,12 +182,13 @@ impl PyObject { /// Calls the object without arguments. /// This is equivalent to the Python expression: 'self()' - pub fn call0(&self, py: Python) -> PyResult - { + pub fn call0(&self, py: Python) -> PyResult { let args = PyTuple::empty(py).into_ptr(); let result = unsafe { PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_Call(self.as_ptr(), args, std::ptr::null_mut())) + py, + ffi::PyObject_Call(self.as_ptr(), args, std::ptr::null_mut()), + ) }; py.xdecref(args); result @@ -194,12 +197,15 @@ impl PyObject { /// Calls the object. /// This is equivalent to the Python expression: 'self(*args)' pub fn call1(&self, py: Python, args: A) -> PyResult - where A: IntoPyTuple + where + A: IntoPyTuple, { let args = args.into_tuple(py).into_ptr(); let result = unsafe { PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_Call(self.as_ptr(), args, std::ptr::null_mut())) + py, + ffi::PyObject_Call(self.as_ptr(), args, std::ptr::null_mut()), + ) }; py.xdecref(args); result @@ -207,17 +213,22 @@ impl PyObject { /// Calls a method on the object. /// This is equivalent to the Python expression: 'self.name(*args, **kwargs)' - pub fn call_method(&self, py: Python, - name: &str, args: A, kwargs: K) -> PyResult - where A: IntoPyTuple, - K: IntoPyDictPointer + pub fn call_method( + &self, + py: Python, + name: &str, + args: A, + kwargs: K, + ) -> PyResult + where + A: IntoPyTuple, + K: IntoPyDictPointer, { name.with_borrowed_ptr(py, |name| unsafe { let args = args.into_tuple(py).into_ptr(); let kwargs = kwargs.into_dict_ptr(py); let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); - let result = PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_Call(ptr, args, kwargs)); + let result = PyObject::from_owned_ptr_or_err(py, ffi::PyObject_Call(ptr, args, kwargs)); ffi::Py_DECREF(ptr); py.xdecref(args); py.xdecref(kwargs); @@ -227,13 +238,14 @@ impl PyObject { /// Calls a method on the object. /// This is equivalent to the Python expression: 'self.name()' - pub fn call_method0(&self, py: Python, name: &str) -> PyResult - { + pub fn call_method0(&self, py: Python, name: &str) -> PyResult { name.with_borrowed_ptr(py, |name| unsafe { let args = PyTuple::empty(py).into_ptr(); let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); let result = PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_Call(ptr, args, std::ptr::null_mut())); + py, + ffi::PyObject_Call(ptr, args, std::ptr::null_mut()), + ); ffi::Py_DECREF(ptr); py.xdecref(args); result @@ -243,13 +255,16 @@ impl PyObject { /// Calls a method on the object. /// This is equivalent to the Python expression: 'self.name(*args)' pub fn call_method1(&self, py: Python, name: &str, args: A) -> PyResult - where A: IntoPyTuple + where + A: IntoPyTuple, { name.with_borrowed_ptr(py, |name| unsafe { let args = args.into_tuple(py).into_ptr(); let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); let result = PyObject::from_owned_ptr_or_err( - py, ffi::PyObject_Call(ptr, args, std::ptr::null_mut())); + py, + ffi::PyObject_Call(ptr, args, std::ptr::null_mut()), + ); ffi::Py_DECREF(ptr); py.xdecref(args); result @@ -258,29 +273,28 @@ impl PyObject { } impl AsPyRef for PyObject { - #[inline] fn as_ref(&self, _py: Python) -> &PyObjectRef { - unsafe {&*(self as *const _ as *mut PyObjectRef)} + unsafe { &*(self as *const _ as *mut PyObjectRef) } } #[inline] fn as_mut(&self, _py: Python) -> &mut PyObjectRef { - unsafe {&mut *(self as *const _ as *mut PyObjectRef)} + unsafe { &mut *(self as *const _ as *mut PyObjectRef) } } } -impl ToPyObject for PyObject -{ +impl ToPyObject for PyObject { #[inline] fn to_object<'p>(&self, py: Python<'p>) -> PyObject { - unsafe {PyObject::from_borrowed_ptr(py, self.as_ptr())} + unsafe { PyObject::from_borrowed_ptr(py, self.as_ptr()) } } } impl ToBorrowedObject for PyObject { #[inline] fn with_borrowed_ptr(&self, _py: Python, f: F) -> R - where F: FnOnce(*mut ffi::PyObject) -> R + where + F: FnOnce(*mut ffi::PyObject) -> R, { f(self.as_ptr()) } @@ -320,30 +334,26 @@ impl PartialEq for PyObject { } } -impl IntoPyObject for PyObject -{ +impl IntoPyObject for PyObject { #[inline] fn into_object(self, _py: Python) -> PyObject { self } } -impl<'a> FromPyObject<'a> for PyObject -{ +impl<'a> FromPyObject<'a> for PyObject { #[inline] /// Extracts `Self` from the source `PyObject`. - fn extract(ob: &'a PyObjectRef) -> PyResult - { - unsafe { - Ok(PyObject::from_borrowed_ptr(ob.py(), ob.as_ptr())) - } + fn extract(ob: &'a PyObjectRef) -> PyResult { + unsafe { Ok(PyObject::from_borrowed_ptr(ob.py(), ob.as_ptr())) } } } /// Dropping a `PyObject` instance decrements the reference count on the object by 1. impl Drop for PyObject { - fn drop(&mut self) { - unsafe { pythonrun::register_pointer(self.0); } + unsafe { + pythonrun::register_pointer(self.0); + } } } diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index 8f39aa3d212..dfbbce75cea 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -4,37 +4,42 @@ use std; use std::cmp::Ordering; use std::os::raw::c_int; +use conversion::{FromPyObject, IntoPyTuple, PyTryFrom, ToBorrowedObject, ToPyObject}; +use err::{self, PyDowncastError, PyErr, PyResult}; use ffi; -use err::{self, PyErr, PyResult, PyDowncastError}; -use python::{Python, ToPyPointer, IntoPyPointer, IntoPyDictPointer}; -use object::PyObject; -use objects::{PyObjectRef, PyString, PyIterator, PyType, PyTuple}; -use conversion::{ToPyObject, ToBorrowedObject, - IntoPyTuple, FromPyObject, PyTryFrom}; use instance::PyObjectWithToken; +use object::PyObject; +use objects::{PyIterator, PyObjectRef, PyString, PyTuple, PyType}; +use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; use typeob::PyTypeInfo; - /// Python object model helper methods #[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))] pub trait ObjectProtocol { - /// Determines whether this object has the given attribute. /// This is equivalent to the Python expression 'hasattr(self, attr_name)'. - fn hasattr(&self, attr_name: N) -> PyResult where N: ToPyObject; + fn hasattr(&self, attr_name: N) -> PyResult + where + N: ToPyObject; /// Retrieves an attribute value. /// This is equivalent to the Python expression 'self.attr_name'. - fn getattr(&self, attr_name: N) -> PyResult<&PyObjectRef> where N: ToPyObject; + fn getattr(&self, attr_name: N) -> PyResult<&PyObjectRef> + where + N: ToPyObject; /// Sets an attribute value. /// This is equivalent to the Python expression 'self.attr_name = value'. fn setattr(&self, attr_name: N, value: V) -> PyResult<()> - where N: ToBorrowedObject, V: ToBorrowedObject; + where + N: ToBorrowedObject, + V: ToBorrowedObject; /// Deletes an attribute. /// This is equivalent to the Python expression 'del self.attr_name'. - fn delattr(&self, attr_name: N) -> PyResult<()> where N: ToPyObject; + fn delattr(&self, attr_name: N) -> PyResult<()> + where + N: ToPyObject; /// Compares two Python objects. /// @@ -51,7 +56,9 @@ pub trait ObjectProtocol { /// else: /// raise TypeError("ObjectProtocol::compare(): All comparisons returned false") /// ``` - fn compare(&self, other: O) -> PyResult where O: ToPyObject; + fn compare(&self, other: O) -> PyResult + where + O: ToPyObject; /// Compares two Python objects. /// @@ -63,7 +70,8 @@ pub trait ObjectProtocol { /// * CompareOp::Gt: `self > other` /// * CompareOp::Ge: `self >= other` fn rich_compare(&self, other: O, compare_op: ::CompareOp) -> PyResult - where O: ToPyObject; + where + O: ToPyObject; /// Compute the string representation of self. /// This is equivalent to the Python expression 'repr(self)'. @@ -79,8 +87,9 @@ pub trait ObjectProtocol { /// Calls the object. /// This is equivalent to the Python expression: 'self(*args, **kwargs)' fn call(&self, args: A, kwargs: K) -> PyResult<&PyObjectRef> - where A: IntoPyTuple, - K: IntoPyDictPointer; + where + A: IntoPyTuple, + K: IntoPyDictPointer; /// Calls the object. /// This is equivalent to the Python expression: 'self()' @@ -88,7 +97,9 @@ pub trait ObjectProtocol { /// Calls the object. /// This is equivalent to the Python expression: 'self(*args)' - fn call1(&self, args: A) -> PyResult<&PyObjectRef> where A: IntoPyTuple; + fn call1(&self, args: A) -> PyResult<&PyObjectRef> + where + A: IntoPyTuple; /// Calls a method on the object. /// This is equivalent to the Python expression: 'self.name(*args, **kwargs)' @@ -101,8 +112,9 @@ pub trait ObjectProtocol { /// let pid = obj.call_method("do_something", args, kwargs); /// ``` fn call_method(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> - where A: IntoPyTuple, - K: IntoPyDictPointer; + where + A: IntoPyTuple, + K: IntoPyDictPointer; /// Calls a method on the object. /// This is equivalent to the Python expression: 'self.name()' @@ -129,16 +141,22 @@ pub trait ObjectProtocol { fn len(&self) -> PyResult; /// This is equivalent to the Python expression: 'self[key]' - fn get_item(&self, key: K) -> PyResult<&PyObjectRef> where K: ToBorrowedObject; + fn get_item(&self, key: K) -> PyResult<&PyObjectRef> + where + K: ToBorrowedObject; /// Sets an item value. /// This is equivalent to the Python expression 'self[key] = value'. fn set_item(&self, key: K, value: V) -> PyResult<()> - where K: ToBorrowedObject, V: ToBorrowedObject; + where + K: ToBorrowedObject, + V: ToBorrowedObject; /// Deletes an item. /// This is equivalent to the Python expression 'del self[key]'. - fn del_item(&self, key: K) -> PyResult<()> where K: ToBorrowedObject; + fn del_item(&self, key: K) -> PyResult<()> + where + K: ToBorrowedObject; /// Takes an object and returns an iterator for it. /// This is typically a new iterator but if the argument @@ -149,22 +167,28 @@ pub trait ObjectProtocol { fn get_type(&self) -> &PyType; /// Gets the Python base object for this object. - fn get_base(&self) -> &::BaseType where Self: PyTypeInfo; + fn get_base(&self) -> &::BaseType + where + Self: PyTypeInfo; /// Gets the Python base object for this object. #[cfg_attr(feature = "cargo-clippy", allow(mut_from_ref))] - fn get_mut_base(&self) -> &mut ::BaseType where Self: PyTypeInfo; + fn get_mut_base(&self) -> &mut ::BaseType + where + Self: PyTypeInfo; /// Casts the PyObject to a concrete Python object type. fn cast_as<'a, D>(&'a self) -> Result<&'a D, ::Error> - where D: PyTryFrom, - &'a PyObjectRef: std::convert::From<&'a Self>; + where + D: PyTryFrom, + &'a PyObjectRef: std::convert::From<&'a Self>; /// Extracts some type from the Python object. /// This is a wrapper function around `FromPyObject::extract()`. fn extract<'a, D>(&'a self) -> PyResult - where D: FromPyObject<'a>, - &'a PyObjectRef: std::convert::From<&'a Self>; + where + D: FromPyObject<'a>, + &'a PyObjectRef: std::convert::From<&'a Self>; /// Returns reference count for python object. fn get_refcnt(&self) -> isize; @@ -172,48 +196,64 @@ pub trait ObjectProtocol { /// Gets the Python builtin value `None`. #[allow(non_snake_case)] // the Python keyword starts with uppercase fn None(&self) -> PyObject; - } - -impl ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer { - - fn hasattr(&self, attr_name: N) -> PyResult where N: ToPyObject { +impl ObjectProtocol for T +where + T: PyObjectWithToken + ToPyPointer, +{ + fn hasattr(&self, attr_name: N) -> PyResult + where + N: ToPyObject, + { attr_name.with_borrowed_ptr(self.py(), |attr_name| unsafe { Ok(ffi::PyObject_HasAttr(self.as_ptr(), attr_name) != 0) }) } - fn getattr(&self, attr_name: N) -> PyResult<&PyObjectRef> where N: ToPyObject + fn getattr(&self, attr_name: N) -> PyResult<&PyObjectRef> + where + N: ToPyObject, { attr_name.with_borrowed_ptr(self.py(), |attr_name| unsafe { - self.py().from_owned_ptr_or_err( - ffi::PyObject_GetAttr(self.as_ptr(), attr_name)) + self.py() + .from_owned_ptr_or_err(ffi::PyObject_GetAttr(self.as_ptr(), attr_name)) }) } fn setattr(&self, attr_name: N, value: V) -> PyResult<()> - where N: ToBorrowedObject, V: ToBorrowedObject + where + N: ToBorrowedObject, + V: ToBorrowedObject, { - attr_name.with_borrowed_ptr( - self.py(), move |attr_name| + attr_name.with_borrowed_ptr(self.py(), move |attr_name| { value.with_borrowed_ptr(self.py(), |value| unsafe { err::error_on_minusone( - self.py(), ffi::PyObject_SetAttr(self.as_ptr(), attr_name, value)) - })) + self.py(), + ffi::PyObject_SetAttr(self.as_ptr(), attr_name, value), + ) + }) + }) } - fn delattr(&self, attr_name: N) -> PyResult<()> where N: ToPyObject { + fn delattr(&self, attr_name: N) -> PyResult<()> + where + N: ToPyObject, + { attr_name.with_borrowed_ptr(self.py(), |attr_name| unsafe { - err::error_on_minusone(self.py(), - ffi::PyObject_DelAttr(self.as_ptr(), attr_name)) + err::error_on_minusone(self.py(), ffi::PyObject_DelAttr(self.as_ptr(), attr_name)) }) } - fn compare(&self, other: O) -> PyResult where O: ToPyObject { - unsafe fn do_compare(py: Python, - a: *mut ffi::PyObject, - b: *mut ffi::PyObject) -> PyResult { + fn compare(&self, other: O) -> PyResult + where + O: ToPyObject, + { + unsafe fn do_compare( + py: Python, + a: *mut ffi::PyObject, + b: *mut ffi::PyObject, + ) -> PyResult { let result = ffi::PyObject_RichCompareBool(a, b, ffi::Py_EQ); if result == 1 { return Ok(Ordering::Equal); @@ -233,7 +273,8 @@ impl ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer { return Err(PyErr::fetch(py)); } Err(::exc::TypeError::new( - "ObjectProtocol::compare(): All comparisons returned false")) + "ObjectProtocol::compare(): All comparisons returned false", + )) } other.with_borrowed_ptr(self.py(), |other| unsafe { @@ -241,87 +282,98 @@ impl ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer { }) } - fn rich_compare(&self, other: O, compare_op: ::CompareOp) - -> PyResult where O: ToPyObject { + fn rich_compare(&self, other: O, compare_op: ::CompareOp) -> PyResult + where + O: ToPyObject, + { unsafe { other.with_borrowed_ptr(self.py(), |other| { PyObject::from_owned_ptr_or_err( - self.py(), ffi::PyObject_RichCompare( - self.as_ptr(), other, compare_op as c_int)) + self.py(), + ffi::PyObject_RichCompare(self.as_ptr(), other, compare_op as c_int), + ) }) } } fn repr(&self) -> PyResult<&PyString> { unsafe { - self.py().from_owned_ptr_or_err(ffi::PyObject_Repr(self.as_ptr())) + self.py() + .from_owned_ptr_or_err(ffi::PyObject_Repr(self.as_ptr())) } } fn str(&self) -> PyResult<&PyString> { unsafe { - self.py().from_owned_ptr_or_err(ffi::PyObject_Str(self.as_ptr())) + self.py() + .from_owned_ptr_or_err(ffi::PyObject_Str(self.as_ptr())) } } fn is_callable(&self) -> bool { - unsafe { - ffi::PyCallable_Check(self.as_ptr()) != 0 - } + unsafe { ffi::PyCallable_Check(self.as_ptr()) != 0 } } fn call(&self, args: A, kwargs: K) -> PyResult<&PyObjectRef> - where A: IntoPyTuple, - K: IntoPyDictPointer + where + A: IntoPyTuple, + K: IntoPyDictPointer, { let args = args.into_tuple(self.py()).into_ptr(); let kw_ptr = kwargs.into_dict_ptr(self.py()); let result = unsafe { - self.py().from_owned_ptr_or_err( - ffi::PyObject_Call(self.as_ptr(), args, kw_ptr)) + self.py() + .from_owned_ptr_or_err(ffi::PyObject_Call(self.as_ptr(), args, kw_ptr)) }; self.py().xdecref(args); self.py().xdecref(kw_ptr); result } - fn call0(&self) -> PyResult<&PyObjectRef> - { + fn call0(&self) -> PyResult<&PyObjectRef> { let args = PyTuple::empty(self.py()).into_ptr(); let result = unsafe { - self.py().from_owned_ptr_or_err( - ffi::PyObject_Call(self.as_ptr(), args, std::ptr::null_mut())) + self.py().from_owned_ptr_or_err(ffi::PyObject_Call( + self.as_ptr(), + args, + std::ptr::null_mut(), + )) }; self.py().xdecref(args); result } fn call1(&self, args: A) -> PyResult<&PyObjectRef> - where A: IntoPyTuple + where + A: IntoPyTuple, { let args = args.into_tuple(self.py()).into_ptr(); let result = unsafe { - self.py().from_owned_ptr_or_err( - ffi::PyObject_Call(self.as_ptr(), args, std::ptr::null_mut())) + self.py().from_owned_ptr_or_err(ffi::PyObject_Call( + self.as_ptr(), + args, + std::ptr::null_mut(), + )) }; self.py().xdecref(args); result } - fn call_method(&self, name: &str, args: A, kwargs: K) - -> PyResult<&PyObjectRef> - where A: IntoPyTuple, - K: IntoPyDictPointer + fn call_method(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> + where + A: IntoPyTuple, + K: IntoPyDictPointer, { name.with_borrowed_ptr(self.py(), |name| unsafe { let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); if ptr.is_null() { - return Err(PyErr::fetch(self.py())) + return Err(PyErr::fetch(self.py())); } let args = args.into_tuple(self.py()).into_ptr(); let kw_ptr = kwargs.into_dict_ptr(self.py()); - let result = self.py().from_owned_ptr_or_err( - ffi::PyObject_Call(ptr, args, kw_ptr)); + let result = self + .py() + .from_owned_ptr_or_err(ffi::PyObject_Call(ptr, args, kw_ptr)); ffi::Py_DECREF(ptr); self.py().xdecref(args); self.py().xdecref(kw_ptr); @@ -329,32 +381,36 @@ impl ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer { }) } - fn call_method0(&self, name: &str) -> PyResult<&PyObjectRef> - { + fn call_method0(&self, name: &str) -> PyResult<&PyObjectRef> { name.with_borrowed_ptr(self.py(), |name| unsafe { let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); if ptr.is_null() { - return Err(PyErr::fetch(self.py())) + return Err(PyErr::fetch(self.py())); } let args = PyTuple::empty(self.py()).into_ptr(); - let result = self.py().from_owned_ptr_or_err( - ffi::PyObject_Call(ptr, args, std::ptr::null_mut())); + let result = self.py().from_owned_ptr_or_err(ffi::PyObject_Call( + ptr, + args, + std::ptr::null_mut(), + )); ffi::Py_DECREF(ptr); self.py().xdecref(args); result }) } - fn call_method1(&self, name: &str, args: A) -> PyResult<&PyObjectRef> - { + fn call_method1(&self, name: &str, args: A) -> PyResult<&PyObjectRef> { name.with_borrowed_ptr(self.py(), |name| unsafe { let ptr = ffi::PyObject_GetAttr(self.as_ptr(), name); if ptr.is_null() { - return Err(PyErr::fetch(self.py())) + return Err(PyErr::fetch(self.py())); } let args = args.into_tuple(self.py()).into_ptr(); - let result = self.py().from_owned_ptr_or_err( - ffi::PyObject_Call(ptr, args, std::ptr::null_mut())); + let result = self.py().from_owned_ptr_or_err(ffi::PyObject_Call( + ptr, + args, + std::ptr::null_mut(), + )); ffi::Py_DECREF(ptr); self.py().xdecref(args); result @@ -392,61 +448,71 @@ impl ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer { } } - fn get_item(&self, key: K) -> PyResult<&PyObjectRef> where K: ToBorrowedObject { + fn get_item(&self, key: K) -> PyResult<&PyObjectRef> + where + K: ToBorrowedObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { - self.py().from_owned_ptr_or_err( - ffi::PyObject_GetItem(self.as_ptr(), key)) + self.py() + .from_owned_ptr_or_err(ffi::PyObject_GetItem(self.as_ptr(), key)) }) } fn set_item(&self, key: K, value: V) -> PyResult<()> - where K: ToBorrowedObject, V: ToBorrowedObject + where + K: ToBorrowedObject, + V: ToBorrowedObject, { - key.with_borrowed_ptr( - self.py(), move |key| + key.with_borrowed_ptr(self.py(), move |key| { value.with_borrowed_ptr(self.py(), |value| unsafe { - err::error_on_minusone( - self.py(), ffi::PyObject_SetItem(self.as_ptr(), key, value)) - })) + err::error_on_minusone(self.py(), ffi::PyObject_SetItem(self.as_ptr(), key, value)) + }) + }) } - fn del_item(&self, key: K) -> PyResult<()> where K: ToBorrowedObject { + fn del_item(&self, key: K) -> PyResult<()> + where + K: ToBorrowedObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { - err::error_on_minusone( - self.py(), ffi::PyObject_DelItem(self.as_ptr(), key)) + err::error_on_minusone(self.py(), ffi::PyObject_DelItem(self.as_ptr(), key)) }) } fn iter(&self) -> PyResult { - Ok(PyIterator::from_object(self.py(), self)?) + Ok(PyIterator::from_object(self.py(), self)?) } fn get_type(&self) -> &PyType { - unsafe { - PyType::from_type_ptr(self.py(), (*self.as_ptr()).ob_type) - } + unsafe { PyType::from_type_ptr(self.py(), (*self.as_ptr()).ob_type) } } - fn get_base(&self) -> &::BaseType where Self: PyTypeInfo + fn get_base(&self) -> &::BaseType + where + Self: PyTypeInfo, { unsafe { self.py().from_borrowed_ptr(self.as_ptr()) } } - fn get_mut_base(&self) -> &mut ::BaseType where Self: PyTypeInfo + fn get_mut_base(&self) -> &mut ::BaseType + where + Self: PyTypeInfo, { unsafe { self.py().mut_from_borrowed_ptr(self.as_ptr()) } } fn cast_as<'a, D>(&'a self) -> Result<&'a D, ::Error> - where D: PyTryFrom, - &'a PyObjectRef: std::convert::From<&'a Self> + where + D: PyTryFrom, + &'a PyObjectRef: std::convert::From<&'a Self>, { D::try_from(self.into()) } fn extract<'a, D>(&'a self) -> PyResult - where D: FromPyObject<'a>, - &'a PyObjectRef: std::convert::From<&'a T> + where + D: FromPyObject<'a>, + &'a PyObjectRef: std::convert::From<&'a T>, { FromPyObject::extract(self.into()) } @@ -463,11 +529,11 @@ impl ObjectProtocol for T where T: PyObjectWithToken + ToPyPointer { #[cfg(test)] mod test { + use super::*; + use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; - use python::Python; - use conversion::{ToPyObject, PyTryFrom}; use objects::PyString; - use super::*; + use python::Python; #[test] fn test_debug_string() { @@ -492,7 +558,7 @@ mod test { let gil = Python::acquire_gil(); let py = gil.python(); let a = py.eval("42", None, None).unwrap(); - a.call_method0("__str__").unwrap(); // ok + a.call_method0("__str__").unwrap(); // ok assert!(a.call_method("nonexistent_method", (1,), ()).is_err()); assert!(a.call_method0("nonexistent_method").is_err()); assert!(a.call_method1("nonexistent_method", (1,)).is_err()); diff --git a/src/objects/boolobject.rs b/src/objects/boolobject.rs index 280cda8de2d..984f2d7a257 100644 --- a/src/objects/boolobject.rs +++ b/src/objects/boolobject.rs @@ -1,8 +1,8 @@ // Copyright (c) 2017-present PyO3 Project and Contributors +use conversion::{IntoPyObject, PyTryFrom, ToBorrowedObject, ToPyObject}; use ffi; use object::PyObject; use python::{Python, ToPyPointer}; -use conversion::{ToPyObject, IntoPyObject, ToBorrowedObject, PyTryFrom}; /// Represents a Python `bool`. pub struct PyBool(PyObject); @@ -10,14 +10,11 @@ pub struct PyBool(PyObject); pyobject_convert!(PyBool); pyobject_nativetype!(PyBool, PyBool_Type, PyBool_Check); - impl PyBool { /// Depending on `val`, returns `py.True()` or `py.False()`. #[inline] pub fn new(py: Python, val: bool) -> &PyBool { - unsafe { - py.from_borrowed_ptr(if val { ffi::Py_True() } else { ffi::Py_False() }) - } + unsafe { py.from_borrowed_ptr(if val { ffi::Py_True() } else { ffi::Py_False() }) } } /// Gets whether this boolean is `true`. @@ -33,7 +30,13 @@ impl ToPyObject for bool { fn to_object(&self, py: Python) -> PyObject { unsafe { PyObject::from_borrowed_ptr( - py, if *self { ffi::Py_True() } else { ffi::Py_False() }) + py, + if *self { + ffi::Py_True() + } else { + ffi::Py_False() + }, + ) } } } @@ -41,10 +44,17 @@ impl ToPyObject for bool { impl ToBorrowedObject for bool { #[inline] fn with_borrowed_ptr(&self, _py: Python, f: F) -> R - where F: FnOnce(*mut ffi::PyObject) -> R + where + F: FnOnce(*mut ffi::PyObject) -> R, { // Avoid unnecessary Py_INCREF/Py_DECREF pair - f(unsafe { if *self { ffi::Py_True() } else { ffi::Py_False() } }) + f(unsafe { + if *self { + ffi::Py_True() + } else { + ffi::Py_False() + } + }) } } @@ -62,13 +72,12 @@ pyobject_extract!(obj to bool => { Ok(::try_from(obj)?.is_true()) }); - #[cfg(test)] mod test { - use python::Python; - use objects::{PyBool, PyObjectRef}; use conversion::ToPyObject; use objectprotocol::ObjectProtocol; + use objects::{PyBool, PyObjectRef}; + use python::Python; #[test] fn test_true() { diff --git a/src/objects/bytearray.rs b/src/objects/bytearray.rs index 56a2f24efa7..bc753de8abf 100644 --- a/src/objects/bytearray.rs +++ b/src/objects/bytearray.rs @@ -1,12 +1,12 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -use std; -use std::os::raw::c_char; +use err::{PyErr, PyResult}; use ffi; -use object::PyObject; use instance::PyObjectWithToken; +use object::PyObject; use python::{Python, ToPyPointer}; -use err::{PyResult, PyErr}; +use std; +use std::os::raw::c_char; /// Represents a Python `bytearray`. pub struct PyByteArray(PyObject); @@ -22,30 +22,23 @@ impl PyByteArray { pub fn new<'p>(py: Python<'p>, src: &[u8]) -> &'p PyByteArray { let ptr = src.as_ptr() as *const c_char; let len = src.len() as ffi::Py_ssize_t; - unsafe { - py.from_owned_ptr::( - ffi::PyByteArray_FromStringAndSize(ptr, len)) - } + unsafe { py.from_owned_ptr::(ffi::PyByteArray_FromStringAndSize(ptr, len)) } } /// Creates a new Python bytearray object /// from other PyObject, that implements the buffer protocol. pub fn from<'p, I>(py: Python<'p>, src: &'p I) -> PyResult<&'p PyByteArray> - where I: ToPyPointer + where + I: ToPyPointer, { - unsafe { - py.from_owned_ptr_or_err( - ffi::PyByteArray_FromObject(src.as_ptr())) - } + unsafe { py.from_owned_ptr_or_err(ffi::PyByteArray_FromObject(src.as_ptr())) } } /// Gets the length of the bytearray. #[inline] pub fn len(&self) -> usize { // non-negative Py_ssize_t should always fit into Rust usize - unsafe { - ffi::PyByteArray_Size(self.0.as_ptr()) as usize - } + unsafe { ffi::PyByteArray_Size(self.0.as_ptr()) as usize } } /// Check if bytearray is empty. @@ -76,13 +69,12 @@ impl PyByteArray { } } - #[cfg(test)] mod test { use exc; - use python::Python; use object::PyObject; use objects::PyByteArray; + use python::Python; #[test] fn test_bytearray() { diff --git a/src/objects/dict.rs b/src/objects/dict.rs index 01339c3e23c..11742993b78 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -1,15 +1,15 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use std; -use std::{mem, collections, hash, cmp}; +use std::{cmp, collections, hash, mem}; +use conversion::{IntoPyObject, ToBorrowedObject, ToPyObject}; +use err::{self, PyErr, PyResult}; use ffi; -use object::PyObject; use instance::{Py, PyObjectWithToken}; -use python::{Python, ToPyPointer, IntoPyPointer, IntoPyDictPointer}; -use conversion::{ToPyObject, ToBorrowedObject, IntoPyObject}; -use objects::{PyObjectRef, PyList}; -use err::{self, PyResult, PyErr}; +use object::PyObject; +use objects::{PyList, PyObjectRef}; +use python::{IntoPyDictPointer, IntoPyPointer, Python, ToPyPointer}; /// Represents a Python `dict`. pub struct PyDict(PyObject); @@ -17,22 +17,20 @@ pub struct PyDict(PyObject); pyobject_convert!(PyDict); pyobject_nativetype!(PyDict, PyDict_Type, PyDict_Check); - impl PyDict { /// Creates a new empty dictionary. /// /// May panic when running out of memory. pub fn new(py: Python) -> &PyDict { - unsafe { - py.from_owned_ptr::(ffi::PyDict_New()) - } + unsafe { py.from_owned_ptr::(ffi::PyDict_New()) } } /// Return a new dictionary that contains the same key-value pairs as self. /// Corresponds to `dict(self)` in Python. pub fn copy(&self) -> PyResult<&PyDict> { unsafe { - self.py().from_owned_ptr_or_err::(ffi::PyDict_Copy(self.as_ptr())) + self.py() + .from_owned_ptr_or_err::(ffi::PyDict_Copy(self.as_ptr())) } } @@ -54,45 +52,53 @@ impl PyDict { /// Determine if the dictionary contains the specified key. /// This is equivalent to the Python expression `key in self`. - pub fn contains(&self, key: K) -> PyResult where K: ToBorrowedObject { + pub fn contains(&self, key: K) -> PyResult + where + K: ToBorrowedObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { match ffi::PyDict_Contains(self.as_ptr(), key) { 1 => Ok(true), 0 => Ok(false), - _ => Err(PyErr::fetch(self.py())) + _ => Err(PyErr::fetch(self.py())), } }) } /// Gets an item from the dictionary. /// Returns None if the item is not present, or if an error occurs. - pub fn get_item(&self, key: K) -> Option<&PyObjectRef> where K: ToBorrowedObject { + pub fn get_item(&self, key: K) -> Option<&PyObjectRef> + where + K: ToBorrowedObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { - self.py().from_borrowed_ptr_or_opt( - ffi::PyDict_GetItem(self.as_ptr(), key)) + self.py() + .from_borrowed_ptr_or_opt(ffi::PyDict_GetItem(self.as_ptr(), key)) }) } /// Sets an item value. /// This is equivalent to the Python expression `self[key] = value`. pub fn set_item(&self, key: K, value: V) -> PyResult<()> - where K: ToPyObject, V: ToPyObject + where + K: ToPyObject, + V: ToPyObject, { - key.with_borrowed_ptr( - self.py(), move |key| + key.with_borrowed_ptr(self.py(), move |key| { value.with_borrowed_ptr(self.py(), |value| unsafe { - err::error_on_minusone( - self.py(), ffi::PyDict_SetItem(self.as_ptr(), key, value)) - })) + err::error_on_minusone(self.py(), ffi::PyDict_SetItem(self.as_ptr(), key, value)) + }) + }) } /// Deletes an item. /// This is equivalent to the Python expression `del self[key]`. - pub fn del_item(&self, key: K) -> PyResult<()> where K: ToBorrowedObject + pub fn del_item(&self, key: K) -> PyResult<()> + where + K: ToBorrowedObject, { key.with_borrowed_ptr(self.py(), |key| unsafe { - err::error_on_minusone( - self.py(), ffi::PyDict_DelItem(self.as_ptr(), key)) + err::error_on_minusone(self.py(), ffi::PyDict_DelItem(self.as_ptr(), key)) }) } @@ -100,7 +106,8 @@ impl PyDict { /// This is equivalent to the python expression `list(dict.keys())`. pub fn keys(&self) -> &PyList { unsafe { - self.py().from_owned_ptr::(ffi::PyDict_Keys(self.as_ptr())) + self.py() + .from_owned_ptr::(ffi::PyDict_Keys(self.as_ptr())) } } @@ -108,7 +115,8 @@ impl PyDict { /// This is equivalent to the python expression `list(dict.values())`. pub fn values(&self) -> &PyList { unsafe { - self.py().from_owned_ptr::(ffi::PyDict_Values(self.as_ptr())) + self.py() + .from_owned_ptr::(ffi::PyDict_Values(self.as_ptr())) } } @@ -116,7 +124,8 @@ impl PyDict { /// This is equivalent to the python expression `list(dict.items())`. pub fn items(&self) -> &PyList { unsafe { - self.py().from_owned_ptr::(ffi::PyDict_Items(self.as_ptr())) + self.py() + .from_owned_ptr::(ffi::PyDict_Items(self.as_ptr())) } } @@ -130,7 +139,7 @@ impl PyDict { pub struct PyDictIterator<'a> { dict: &'a PyDict, - pos: isize + pos: isize, } impl<'a> Iterator for PyDictIterator<'a> { @@ -174,85 +183,97 @@ impl IntoPyDictPointer for Py { } } -impl ToPyObject for collections::HashMap - where K: hash::Hash+cmp::Eq+ToPyObject, - V: ToPyObject, - H: hash::BuildHasher +impl ToPyObject for collections::HashMap +where + K: hash::Hash + cmp::Eq + ToPyObject, + V: ToPyObject, + H: hash::BuildHasher, { fn to_object(&self, py: Python) -> PyObject { let dict = PyDict::new(py); for (key, value) in self { - dict.set_item(key, value).expect("Failed to set_item on dict"); - }; + dict.set_item(key, value) + .expect("Failed to set_item on dict"); + } dict.into() } } -impl ToPyObject for collections::BTreeMap - where K: cmp::Eq+ToPyObject, - V: ToPyObject +impl ToPyObject for collections::BTreeMap +where + K: cmp::Eq + ToPyObject, + V: ToPyObject, { fn to_object(&self, py: Python) -> PyObject { let dict = PyDict::new(py); for (key, value) in self { - dict.set_item(key, value).expect("Failed to set_item on dict"); - }; + dict.set_item(key, value) + .expect("Failed to set_item on dict"); + } dict.into() } } -impl IntoPyObject for collections::HashMap - where K: hash::Hash+cmp::Eq+ToPyObject, - V: ToPyObject, - H: hash::BuildHasher +impl IntoPyObject for collections::HashMap +where + K: hash::Hash + cmp::Eq + ToPyObject, + V: ToPyObject, + H: hash::BuildHasher, { fn into_object(self, py: Python) -> PyObject { let dict = PyDict::new(py); for (key, value) in self { - dict.set_item(key, value).expect("Failed to set_item on dict"); - }; + dict.set_item(key, value) + .expect("Failed to set_item on dict"); + } dict.into() } } -impl IntoPyObject for collections::BTreeMap - where K: cmp::Eq+ToPyObject, - V: ToPyObject +impl IntoPyObject for collections::BTreeMap +where + K: cmp::Eq + ToPyObject, + V: ToPyObject, { fn into_object(self, py: Python) -> PyObject { let dict = PyDict::new(py); for (key, value) in self { - dict.set_item(key, value).expect("Failed to set_item on dict"); - }; + dict.set_item(key, value) + .expect("Failed to set_item on dict"); + } dict.into() } } -impl IntoPyDictPointer for collections::HashMap - where K: hash::Hash+cmp::Eq+ToPyObject, - V: ToPyObject, - H: hash::BuildHasher +impl IntoPyDictPointer for collections::HashMap +where + K: hash::Hash + cmp::Eq + ToPyObject, + V: ToPyObject, + H: hash::BuildHasher, { #[must_use] fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject { let dict = PyDict::new(py); for (key, value) in self { - dict.set_item(key, value).expect("Failed to set_item on dict"); - }; + dict.set_item(key, value) + .expect("Failed to set_item on dict"); + } dict.into_ptr() } } -impl IntoPyDictPointer for collections::BTreeMap - where K: cmp::Eq+ToPyObject, - V: ToPyObject +impl IntoPyDictPointer for collections::BTreeMap +where + K: cmp::Eq + ToPyObject, + V: ToPyObject, { #[must_use] fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject { let dict = PyDict::new(py); for (key, value) in self { - dict.set_item(key, value).expect("Failed to set_item on dict"); - }; + dict.set_item(key, value) + .expect("Failed to set_item on dict"); + } dict.into_ptr() } } @@ -260,7 +281,8 @@ impl IntoPyDictPointer for collections::BTreeMap impl IntoPyDictPointer for (K, V) { default fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject { let dict = PyDict::new(py); - dict.set_item(self.0, self.1).expect("Failed to set_item on dict"); + dict.set_item(self.0, self.1) + .expect("Failed to set_item on dict"); dict.into_ptr() } } @@ -278,30 +300,72 @@ macro_rules! dict_conversion ({$length:expr,$(($refN:ident, $n:tt, $T1:ident, $T dict_conversion!(1, (ref0, 0, A1, A2)); dict_conversion!(2, (ref0, 0, A1, A2), (ref1, 1, B1, B2)); dict_conversion!(3, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2)); -dict_conversion!(4, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2)); -dict_conversion!(5, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2)); -dict_conversion!(6, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2)); -dict_conversion!(7, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2), (ref6, 6, G1, G2)); -dict_conversion!(8, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2), (ref6, 6, G1, G2), - (ref7, 7, H1, H2)); -dict_conversion!(9, (ref0, 0, A1, A2), (ref1, 1, B1, B2), (ref2, 2, C1, C2), - (ref3, 3, D1, D2), (ref4, 4, E1, E2), (ref5, 5, F1, F2), (ref6, 6, G1, G2), - (ref7, 7, H1, H2), (ref8, 8, I1, I2)); - +dict_conversion!( + 4, + (ref0, 0, A1, A2), + (ref1, 1, B1, B2), + (ref2, 2, C1, C2), + (ref3, 3, D1, D2) +); +dict_conversion!( + 5, + (ref0, 0, A1, A2), + (ref1, 1, B1, B2), + (ref2, 2, C1, C2), + (ref3, 3, D1, D2), + (ref4, 4, E1, E2) +); +dict_conversion!( + 6, + (ref0, 0, A1, A2), + (ref1, 1, B1, B2), + (ref2, 2, C1, C2), + (ref3, 3, D1, D2), + (ref4, 4, E1, E2), + (ref5, 5, F1, F2) +); +dict_conversion!( + 7, + (ref0, 0, A1, A2), + (ref1, 1, B1, B2), + (ref2, 2, C1, C2), + (ref3, 3, D1, D2), + (ref4, 4, E1, E2), + (ref5, 5, F1, F2), + (ref6, 6, G1, G2) +); +dict_conversion!( + 8, + (ref0, 0, A1, A2), + (ref1, 1, B1, B2), + (ref2, 2, C1, C2), + (ref3, 3, D1, D2), + (ref4, 4, E1, E2), + (ref5, 5, F1, F2), + (ref6, 6, G1, G2), + (ref7, 7, H1, H2) +); +dict_conversion!( + 9, + (ref0, 0, A1, A2), + (ref1, 1, B1, B2), + (ref2, 2, C1, C2), + (ref3, 3, D1, D2), + (ref4, 4, E1, E2), + (ref5, 5, F1, F2), + (ref6, 6, G1, G2), + (ref7, 7, H1, H2), + (ref8, 8, I1, I2) +); #[cfg(test)] mod test { - use std::collections::{BTreeMap, HashMap}; - use python::{Python, IntoPyDictPointer}; + use conversion::{IntoPyObject, PyTryFrom, ToPyObject}; use instance::AsPyRef; - use conversion::{PyTryFrom, ToPyObject, IntoPyObject}; use objects::{PyDict, PyTuple}; - use {PyObject, ObjectProtocol}; + use python::{IntoPyDictPointer, Python}; + use std::collections::{BTreeMap, HashMap}; + use {ObjectProtocol, PyObject}; #[test] fn test_new() { @@ -373,8 +437,14 @@ mod test { let dict = ::try_from(ob.as_ref(py)).unwrap(); assert!(dict.set_item(7i32, 42i32).is_ok()); // change assert!(dict.set_item(8i32, 123i32).is_ok()); // insert - assert_eq!(42i32, dict.get_item(7i32).unwrap().extract::().unwrap()); - assert_eq!(123i32, dict.get_item(8i32).unwrap().extract::().unwrap()); + assert_eq!( + 42i32, + dict.get_item(7i32).unwrap().extract::().unwrap() + ); + assert_eq!( + 123i32, + dict.get_item(8i32).unwrap().extract::().unwrap() + ); } #[test] @@ -586,7 +656,7 @@ mod test { map.insert(1, 1); let m = map.into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; + let ob = unsafe { PyObject::from_owned_ptr(py, m) }; let py_map = ::try_from(ob.as_ref(py)).unwrap(); assert!(py_map.len() == 1); @@ -617,7 +687,7 @@ mod test { map.insert(1, 1); let m = map.into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; + let ob = unsafe { PyObject::from_owned_ptr(py, m) }; let py_map = ::try_from(ob.as_ref(py)).unwrap(); assert!(py_map.len() == 1); @@ -630,14 +700,14 @@ mod test { let py = gil.python(); let m = ((1, 1),).into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; + let ob = unsafe { PyObject::from_owned_ptr(py, m) }; let py_map = ::try_from(ob.as_ref(py)).unwrap(); assert!(py_map.len() == 1); - assert!( py_map.get_item(1).unwrap().extract::().unwrap() == 1); + assert!(py_map.get_item(1).unwrap().extract::().unwrap() == 1); let m = ((1, 1), (2, 3)).into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; + let ob = unsafe { PyObject::from_owned_ptr(py, m) }; let py_map = ::try_from(ob.as_ref(py)).unwrap(); assert!(py_map.len() == 2); @@ -651,7 +721,7 @@ mod test { let py = gil.python(); let m = (1, 1).into_dict_ptr(py); - let ob = unsafe{PyObject::from_owned_ptr(py, m)}; + let ob = unsafe { PyObject::from_owned_ptr(py, m) }; let py_map = ::try_from(ob.as_ref(py)).unwrap(); assert!(py_map.len() == 1); diff --git a/src/objects/exc.rs b/src/objects/exc.rs index db6c80840c8..0d53a5b8e11 100644 --- a/src/objects/exc.rs +++ b/src/objects/exc.rs @@ -2,17 +2,17 @@ //! This module contains the standard python exception types. +use std::ffi::CStr; use std::os::raw::c_char; use std::{self, mem, ops}; -use std::ffi::CStr; +use conversion::ToPyObject; +use err::{PyErr, PyResult}; use ffi; use instance::Py; -use err::{PyErr, PyResult}; +use objects::{PyObjectRef, PyTuple, PyType}; use python::{Python, ToPyPointer}; -use objects::{PyTuple, PyType, PyObjectRef}; use typeob::PyTypeObject; -use conversion::ToPyObject; macro_rules! exc_type( ($name:ident, $exc_name:ident) => ( @@ -127,46 +127,56 @@ exc_type!(TimeoutError, PyExc_TimeoutError); exc_type!(EnvironmentError, PyExc_EnvironmentError); exc_type!(IOError, PyExc_IOError); -#[cfg(target_os="windows")] +#[cfg(target_os = "windows")] exc_type!(WindowsError, PyExc_WindowsError); - impl UnicodeDecodeError { - #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] - pub fn new_err<'p>(py: Python<'p>, encoding: &CStr, input: &[u8], - range: ops::Range, reason: &CStr) -> PyResult<&'p PyObjectRef> { + pub fn new_err<'p>( + py: Python<'p>, + encoding: &CStr, + input: &[u8], + range: ops::Range, + reason: &CStr, + ) -> PyResult<&'p PyObjectRef> { unsafe { let input: &[c_char] = mem::transmute(input); - py.from_owned_ptr_or_err( - ffi::PyObject_CallFunction( - ffi::PyExc_UnicodeDecodeError, - cstr!("sy#nns").as_ptr() as *mut i8, - encoding.as_ptr(), - input.as_ptr(), - input.len() as ffi::Py_ssize_t, - range.start as ffi::Py_ssize_t, - range.end as ffi::Py_ssize_t, - reason.as_ptr())) + py.from_owned_ptr_or_err(ffi::PyObject_CallFunction( + ffi::PyExc_UnicodeDecodeError, + cstr!("sy#nns").as_ptr() as *mut i8, + encoding.as_ptr(), + input.as_ptr(), + input.len() as ffi::Py_ssize_t, + range.start as ffi::Py_ssize_t, + range.end as ffi::Py_ssize_t, + reason.as_ptr(), + )) } } - pub fn new_utf8<'p>(py: Python<'p>, input: &[u8], err: std::str::Utf8Error) - -> PyResult<&'p PyObjectRef> - { + pub fn new_utf8<'p>( + py: Python<'p>, + input: &[u8], + err: std::str::Utf8Error, + ) -> PyResult<&'p PyObjectRef> { let pos = err.valid_up_to(); UnicodeDecodeError::new_err( - py, cstr!("utf-8"), input, pos .. pos+1, cstr!("invalid utf-8")) + py, + cstr!("utf-8"), + input, + pos..pos + 1, + cstr!("invalid utf-8"), + ) } } - impl StopIteration { - pub fn stop_iteration(_py: Python, args: &PyTuple) { unsafe { ffi::PyErr_SetObject( - ffi::PyExc_StopIteration as *mut ffi::PyObject, args.as_ptr()); + ffi::PyExc_StopIteration as *mut ffi::PyObject, + args.as_ptr(), + ); } } } diff --git a/src/objects/exc_impl.rs b/src/objects/exc_impl.rs index 2b9e422c434..3f384af9867 100644 --- a/src/objects/exc_impl.rs +++ b/src/objects/exc_impl.rs @@ -104,8 +104,8 @@ macro_rules! import_exception { #[cfg(test)] mod test { - use {PyErr, Python}; use objects::PyDict; + use {PyErr, Python}; import_exception!(socket, gaierror); import_exception!(email.errors, MessageError); @@ -116,11 +116,18 @@ mod test { let py = gil.python(); let err: PyErr = gaierror.into(); - let socket = py.import("socket").map_err(|e| e.print(py)).expect("could not import socket"); + let socket = py + .import("socket") + .map_err(|e| e.print(py)) + .expect("could not import socket"); let d = PyDict::new(py); - d.set_item("socket", socket).map_err(|e| e.print(py)).expect("could not setitem"); - d.set_item("exc", err).map_err(|e| e.print(py)).expect("could not setitem"); + d.set_item("socket", socket) + .map_err(|e| e.print(py)) + .expect("could not setitem"); + d.set_item("exc", err) + .map_err(|e| e.print(py)) + .expect("could not setitem"); py.run("assert isinstance(exc, socket.gaierror)", None, Some(d)) .map_err(|e| e.print(py)) @@ -133,14 +140,25 @@ mod test { let py = gil.python(); let err: PyErr = MessageError.into(); - let email = py.import("email").map_err(|e| e.print(py)).expect("could not import email"); + let email = py + .import("email") + .map_err(|e| e.print(py)) + .expect("could not import email"); let d = PyDict::new(py); - d.set_item("email", email).map_err(|e| e.print(py)).expect("could not setitem"); - d.set_item("exc", err).map_err(|e| e.print(py)).expect("could not setitem"); - - py.run("assert isinstance(exc, email.errors.MessageError)", None, Some(d)) + d.set_item("email", email) .map_err(|e| e.print(py)) - .expect("assertion failed"); + .expect("could not setitem"); + d.set_item("exc", err) + .map_err(|e| e.print(py)) + .expect("could not setitem"); + + py.run( + "assert isinstance(exc, email.errors.MessageError)", + None, + Some(d), + ) + .map_err(|e| e.print(py)) + .expect("assertion failed"); } } diff --git a/src/objects/floatob.rs b/src/objects/floatob.rs index 5f14ad8b2a7..14be51a11e1 100644 --- a/src/objects/floatob.rs +++ b/src/objects/floatob.rs @@ -4,12 +4,12 @@ use std::os::raw::c_double; -use ffi; -use object::PyObject; -use python::{ToPyPointer, Python}; +use conversion::{IntoPyObject, ToPyObject}; use err::PyErr; +use ffi; use instance::{Py, PyObjectWithToken}; -use conversion::{ToPyObject, IntoPyObject}; +use object::PyObject; +use python::{Python, ToPyPointer}; /// Represents a Python `float` object. /// @@ -22,13 +22,10 @@ pub struct PyFloat(PyObject); pyobject_convert!(PyFloat); pyobject_nativetype!(PyFloat, PyFloat_Type, PyFloat_Check); - impl PyFloat { /// Creates a new Python `float` object. pub fn new(_py: Python, val: c_double) -> Py { - unsafe { - Py::from_owned_ptr_or_panic(ffi::PyFloat_FromDouble(val)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyFloat_FromDouble(val)) } } /// Gets the value of this float. @@ -77,11 +74,10 @@ pyobject_extract!(obj to f32 => { Ok(obj.extract::()? as f32) }); - #[cfg(test)] mod test { - use python::Python; use conversion::ToPyObject; + use python::Python; macro_rules! num_to_py_object_and_back ( ($func_name:ident, $t1:ty, $t2:ty) => ( diff --git a/src/objects/iterator.rs b/src/objects/iterator.rs index d0eabcaa345..e18d493710e 100644 --- a/src/objects/iterator.rs +++ b/src/objects/iterator.rs @@ -2,11 +2,11 @@ // // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython +use err::{PyDowncastError, PyErr, PyResult}; use ffi; +use instance::PyObjectWithToken; use objects::PyObjectRef; use python::{Python, ToPyPointer}; -use instance::PyObjectWithToken; -use err::{PyErr, PyResult, PyDowncastError}; /// A python iterator object. /// @@ -14,11 +14,11 @@ use err::{PyErr, PyResult, PyDowncastError}; /// so that `PyIterator` can implement the rust `Iterator` trait. pub struct PyIterator<'p>(&'p PyObjectRef); - -impl <'p> PyIterator<'p> { +impl<'p> PyIterator<'p> { /// Constructs a `PyIterator` from a Python iterator object. pub fn from_object(py: Python<'p>, obj: &T) -> Result, PyDowncastError> - where T: ToPyPointer + where + T: ToPyPointer, { unsafe { let ptr = ffi::PyObject_GetIter(obj.as_ptr()); @@ -44,9 +44,7 @@ impl<'p> Iterator for PyIterator<'p> { fn next(&mut self) -> Option { let py = self.0.py(); - match unsafe { - py.from_owned_ptr_or_opt(ffi::PyIter_Next(self.0.as_ptr())) } - { + match unsafe { py.from_owned_ptr_or_opt(ffi::PyIter_Next(self.0.as_ptr())) } { Some(obj) => Some(Ok(obj)), None => { if PyErr::occurred(py) { @@ -61,7 +59,6 @@ impl<'p> Iterator for PyIterator<'p> { /// Dropping a `PyIterator` instance decrements the reference count on the object by 1. impl<'p> Drop for PyIterator<'p> { - fn drop(&mut self) { unsafe { ffi::Py_DECREF(self.0.as_ptr()) } } @@ -69,12 +66,12 @@ impl<'p> Drop for PyIterator<'p> { #[cfg(test)] mod tests { + use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; + use objectprotocol::ObjectProtocol; + use objects::{PyList, PyObjectRef}; use python::Python; use pythonrun::GILPool; - use conversion::{PyTryFrom, ToPyObject}; - use objects::{PyObjectRef, PyList}; - use objectprotocol::ObjectProtocol; #[test] fn vec_iter() { diff --git a/src/objects/list.rs b/src/objects/list.rs index dea2e49367e..57a2faf9d38 100644 --- a/src/objects/list.rs +++ b/src/objects/list.rs @@ -4,13 +4,13 @@ use std; +use conversion::{IntoPyObject, ToBorrowedObject, ToPyObject}; use err::{self, PyResult}; use ffi::{self, Py_ssize_t}; use instance::PyObjectWithToken; use object::PyObject; use objects::PyObjectRef; -use python::{Python, ToPyPointer, IntoPyPointer}; -use conversion::{ToPyObject, IntoPyObject, ToBorrowedObject}; +use python::{IntoPyPointer, Python, ToPyPointer}; /// Represents a Python `list`. pub struct PyList(PyObject); @@ -33,17 +33,13 @@ impl PyList { /// Construct a new empty list. pub fn empty(py: Python) -> &PyList { - unsafe { - py.from_owned_ptr::(ffi::PyList_New(0)) - } + unsafe { py.from_owned_ptr::(ffi::PyList_New(0)) } } /// Gets the length of the list. pub fn len(&self) -> usize { // non-negative Py_ssize_t should always fit into Rust usize - unsafe { - ffi::PyList_Size(self.as_ptr()) as usize - } + unsafe { ffi::PyList_Size(self.as_ptr()) as usize } } /// Check if list is empty. @@ -56,8 +52,8 @@ impl PyList { /// Panics if the index is out of range. pub fn get_item(&self, index: isize) -> &PyObjectRef { unsafe { - self.py().from_borrowed_ptr( - ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t)) + self.py() + .from_borrowed_ptr(ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t)) } } @@ -67,44 +63,55 @@ impl PyList { pub fn get_parked_item(&self, index: isize) -> PyObject { unsafe { PyObject::from_borrowed_ptr( - self.py(), ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t)) + self.py(), + ffi::PyList_GetItem(self.as_ptr(), index as Py_ssize_t), + ) } } /// Sets the item at the specified index. /// /// Panics if the index is out of range. - pub fn set_item(&self, index: isize, item: I) -> PyResult<()> where I: ToPyObject { + pub fn set_item(&self, index: isize, item: I) -> PyResult<()> + where + I: ToPyObject, + { unsafe { err::error_on_minusone( - self.py(), ffi::PyList_SetItem(self.as_ptr(), index, - item.to_object(self.py()).into_ptr())) + self.py(), + ffi::PyList_SetItem(self.as_ptr(), index, item.to_object(self.py()).into_ptr()), + ) } } /// Appends an item at the list. - pub fn append(&self, item: I) -> PyResult<()> where I: ToBorrowedObject + pub fn append(&self, item: I) -> PyResult<()> + where + I: ToBorrowedObject, { item.with_borrowed_ptr(self.py(), |item| unsafe { - err::error_on_minusone( - self.py(), ffi::PyList_Append(self.as_ptr(), item)) + err::error_on_minusone(self.py(), ffi::PyList_Append(self.as_ptr(), item)) }) } /// Inserts an item at the specified index. /// /// Panics if the index is out of range. - pub fn insert(&self, index: isize, item: I) -> PyResult<()> where I: ToBorrowedObject + pub fn insert(&self, index: isize, item: I) -> PyResult<()> + where + I: ToBorrowedObject, { item.with_borrowed_ptr(self.py(), |item| unsafe { - err::error_on_minusone( - self.py(), ffi::PyList_Insert(self.as_ptr(), index, item)) + err::error_on_minusone(self.py(), ffi::PyList_Insert(self.as_ptr(), index, item)) }) } /// Returns an iterator over the tuple items. pub fn iter(&self) -> PyListIterator { - PyListIterator { list: self, index: 0 } + PyListIterator { + list: self, + index: 0, + } } } @@ -138,8 +145,10 @@ impl<'a> std::iter::IntoIterator for &'a PyList { } } -impl ToPyObject for [T] where T: ToPyObject { - +impl ToPyObject for [T] +where + T: ToPyObject, +{ fn to_object<'p>(&self, py: Python<'p>) -> PyObject { unsafe { let ptr = ffi::PyList_New(self.len() as Py_ssize_t); @@ -152,16 +161,19 @@ impl ToPyObject for [T] where T: ToPyObject { } } -impl ToPyObject for Vec where T: ToPyObject { - +impl ToPyObject for Vec +where + T: ToPyObject, +{ fn to_object<'p>(&self, py: Python<'p>) -> PyObject { self.as_slice().to_object(py) } - } -impl IntoPyObject for Vec where T: IntoPyObject + ToPyObject { - +impl IntoPyObject for Vec +where + T: IntoPyObject + ToPyObject, +{ fn into_object(self, py: Python) -> PyObject { unsafe { let ptr = ffi::PyList_New(self.len() as Py_ssize_t); @@ -176,11 +188,11 @@ impl IntoPyObject for Vec where T: IntoPyObject + ToPyObject { #[cfg(test)] mod test { + use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; - use python::Python; - use conversion::{ToPyObject, PyTryFrom}; - use objects::PyList; use objectprotocol::ObjectProtocol; + use objects::PyList; + use python::Python; #[test] fn test_new() { @@ -198,7 +210,7 @@ mod test { fn test_len() { let gil = Python::acquire_gil(); let py = gil.python(); - let v = vec![1,2,3,4]; + let v = vec![1, 2, 3, 4]; let ob = v.to_object(py); let list = ::try_from(ob.as_ref(py)).unwrap(); assert_eq!(4, list.len()); diff --git a/src/objects/mod.rs b/src/objects/mod.rs index d91735f7c65..d27dad1b77e 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -1,20 +1,21 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -#[macro_use] mod exc_impl; +#[macro_use] +mod exc_impl; -pub use self::typeobject::PyType; -pub use self::module::PyModule; -pub use self::iterator::PyIterator; pub use self::boolobject::PyBool; pub use self::bytearray::PyByteArray; -pub use self::tuple::PyTuple; pub use self::dict::PyDict; -pub use self::list::PyList; pub use self::floatob::PyFloat; +pub use self::iterator::PyIterator; +pub use self::list::PyList; +pub use self::module::PyModule; pub use self::sequence::PySequence; +pub use self::set::{PyFrozenSet, PySet}; pub use self::slice::{PySlice, PySliceIndices}; -pub use self::set::{PySet, PyFrozenSet}; pub use self::stringdata::PyStringData; +pub use self::tuple::PyTuple; +pub use self::typeobject::PyType; #[cfg(Py_3)] pub use self::string::{PyBytes, PyString}; @@ -30,7 +31,6 @@ pub use self::num3::PyLong as PyInt; #[cfg(not(Py_3))] pub use self::num2::{PyInt, PyLong}; - macro_rules! pyobject_downcast( ($name: ident, $checkfunction: ident) => ( impl<'a> $crate::FromPyObject<'a> for &'a $name @@ -195,28 +195,27 @@ macro_rules! pyobject_extract( } ); - use python::ToPyPointer; /// Represents general python instance. pub struct PyObjectRef(::PyObject); pyobject_nativetype!(PyObjectRef, PyBaseObject_Type, PyObject_Check); -mod typeobject; -mod module; -mod dict; -mod iterator; mod boolobject; mod bytearray; -mod tuple; -mod list; +mod dict; +pub mod exc; mod floatob; +mod iterator; +mod list; +mod module; mod sequence; +mod set; mod slice; mod stringdata; mod stringutils; -mod set; -pub mod exc; +mod tuple; +mod typeobject; #[cfg(Py_3)] mod num3; diff --git a/src/objects/module.rs b/src/objects/module.rs index 517f25cbadc..95040af3afe 100644 --- a/src/objects/module.rs +++ b/src/objects/module.rs @@ -3,19 +3,18 @@ // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython use std; -use std::os::raw::c_char; use std::ffi::{CStr, CString}; +use std::os::raw::c_char; +use conversion::{IntoPyTuple, ToPyObject}; +use err::{PyErr, PyResult}; use ffi; -use typeob::{PyTypeInfo, initialize_type}; -use conversion::{ToPyObject, IntoPyTuple}; +use instance::PyObjectWithToken; use object::PyObject; -use python::{Python, ToPyPointer, IntoPyDictPointer}; -use objects::{PyObjectRef, PyDict, PyType, exc}; use objectprotocol::ObjectProtocol; -use instance::PyObjectWithToken; -use err::{PyResult, PyErr}; - +use objects::{exc, PyDict, PyObjectRef, PyType}; +use python::{IntoPyDictPointer, Python, ToPyPointer}; +use typeob::{initialize_type, PyTypeInfo}; /// Represents a Python `module` object. pub struct PyModule(PyObject); @@ -23,32 +22,25 @@ pub struct PyModule(PyObject); pyobject_convert!(PyModule); pyobject_nativetype!(PyModule, PyModule_Type, PyModule_Check); - impl PyModule { /// Create a new module object with the `__name__` attribute set to name. pub fn new<'p>(py: Python<'p>, name: &str) -> PyResult<&'p PyModule> { let name = CString::new(name)?; - unsafe { - py.from_owned_ptr_or_err( - ffi::PyModule_New(name.as_ptr())) - } + unsafe { py.from_owned_ptr_or_err(ffi::PyModule_New(name.as_ptr())) } } /// Import the Python module with the specified name. pub fn import<'p>(py: Python<'p>, name: &str) -> PyResult<&'p PyModule> { let name = CString::new(name)?; - unsafe { - py.from_owned_ptr_or_err( - ffi::PyImport_ImportModule(name.as_ptr())) - } + unsafe { py.from_owned_ptr_or_err(ffi::PyImport_ImportModule(name.as_ptr())) } } /// Return the dictionary object that implements module's namespace; /// this object is the same as the `__dict__` attribute of the module object. pub fn dict(&self) -> &PyDict { unsafe { - self.py().from_owned_ptr::( - ffi::PyModule_GetDict(self.as_ptr())) + self.py() + .from_owned_ptr::(ffi::PyModule_GetDict(self.as_ptr())) } } @@ -59,8 +51,11 @@ impl PyModule { let slice = CStr::from_ptr(ptr).to_bytes(); match std::str::from_utf8(slice) { Ok(s) => Ok(s), - Err(e) => Err(PyErr::from_instance( - exc::UnicodeDecodeError::new_utf8(self.py(), slice, e)?)) + Err(e) => Err(PyErr::from_instance(exc::UnicodeDecodeError::new_utf8( + self.py(), + slice, + e, + )?)), } } } @@ -82,38 +77,41 @@ impl PyModule { /// Calls a function in the module. /// This is equivalent to the Python expression: `getattr(module, name)(*args, **kwargs)` pub fn call(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> - where A: IntoPyTuple, - K: IntoPyDictPointer + where + A: IntoPyTuple, + K: IntoPyDictPointer, { self.getattr(name)?.call(args, kwargs) } /// Calls a function in the module. /// This is equivalent to the Python expression: `getattr(module, name)()` - pub fn call0(&self, name: &str) -> PyResult<&PyObjectRef> - { + pub fn call0(&self, name: &str) -> PyResult<&PyObjectRef> { self.getattr(name)?.call0() } /// Calls a function in the module. /// This is equivalent to the Python expression: `getattr(module, name)(*args)` pub fn call1(&self, name: &str, args: A) -> PyResult<&PyObjectRef> - where A: IntoPyTuple + where + A: IntoPyTuple, { self.getattr(name)?.call1(args) } /// Gets a member from the module. /// This is equivalent to the Python expression: `getattr(module, name)` - pub fn get(&self, name: &str) -> PyResult<&PyObjectRef> - { + pub fn get(&self, name: &str) -> PyResult<&PyObjectRef> { self.getattr(name) } /// Adds a member to the module. /// /// This is a convenience function which can be used from the module's initialization function. - pub fn add(&self, name: &str, value: V) -> PyResult<()> where V: ToPyObject { + pub fn add(&self, name: &str, value: V) -> PyResult<()> + where + V: ToPyObject, + { self.setattr(name, value) } @@ -122,7 +120,9 @@ impl PyModule { /// This is a convenience function that initializes the `class`, /// sets `new_type.__module__` to this module's name, /// and adds the type to this module. - pub fn add_class(&self) -> PyResult<()> where T: PyTypeInfo + pub fn add_class(&self) -> PyResult<()> + where + T: PyTypeInfo, { let ty = unsafe { let ty = ::type_object(); @@ -131,9 +131,9 @@ impl PyModule { PyType::new::() } else { // automatically initialize the class - initialize_type::(self.py(), Some(self.name()?)) - .expect( - format!("An error occurred while initializing class {}", T::NAME).as_ref()); + initialize_type::(self.py(), Some(self.name()?)).expect( + format!("An error occurred while initializing class {}", T::NAME).as_ref(), + ); PyType::new::() } }; diff --git a/src/objects/num2.rs b/src/objects/num2.rs index 4cac1dd0c8d..67aaa662a57 100644 --- a/src/objects/num2.rs +++ b/src/objects/num2.rs @@ -7,13 +7,13 @@ use std::os::raw::c_long; extern crate num_traits; use self::num_traits::cast::cast; +use conversion::{FromPyObject, IntoPyObject, ToPyObject}; +use err::{PyErr, PyResult}; use ffi; -use object::PyObject; -use python::{ToPyPointer, IntoPyPointer, Python}; -use err::{PyResult, PyErr}; use instance::{Py, PyObjectWithToken}; +use object::PyObject; use objects::{exc, PyObjectRef}; -use conversion::{ToPyObject, IntoPyObject, FromPyObject}; +use python::{IntoPyPointer, Python, ToPyPointer}; /// Represents a Python `int` object. /// @@ -47,9 +47,7 @@ impl PyInt { /// 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 { - unsafe { - Py::from_owned_ptr_or_panic(ffi::PyLong_FromLong(val)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyLong_FromLong(val)) } } /// Gets the value of this integer. @@ -92,7 +90,6 @@ macro_rules! int_fits_c_long( ) ); - macro_rules! int_fits_larger_int( ($rust_type:ty, $larger_type:ty) => ( impl ToPyObject for $rust_type { @@ -116,10 +113,11 @@ macro_rules! int_fits_larger_int( ) ); - -fn err_if_invalid_value<'p, T: PartialEq> - (py: Python, invalid_value: T, actual_value: T) -> PyResult -{ +fn err_if_invalid_value<'p, T: PartialEq>( + py: Python, + invalid_value: T, + actual_value: T, +) -> PyResult { if actual_value == invalid_value && PyErr::occurred(py) { Err(PyErr::fetch(py)) } else { @@ -176,7 +174,6 @@ macro_rules! int_convert_u64_or_i64 ( ) ); - int_fits_c_long!(i8); int_fits_c_long!(u8); int_fits_c_long!(i16); @@ -184,34 +181,37 @@ 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")))] +#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))] int_fits_c_long!(u32); -#[cfg(any(target_pointer_width="32", target_os="windows"))] +#[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")))] +#[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"))] +#[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")))] +#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))] int_fits_c_long!(isize); -#[cfg(any(target_pointer_width="32", target_os="windows"))] +#[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_u64_or_i64!( + u64, + ffi::PyLong_FromUnsignedLongLong, + ffi::PyLong_AsUnsignedLongLong +); #[cfg(test)] mod test { - use std; - use python::{Python}; use conversion::ToPyObject; + use python::Python; + use std; macro_rules! num_to_py_object_and_back ( ($func_name:ident, $t1:ty, $t2:ty) => ( @@ -228,8 +228,8 @@ mod test { 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_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); @@ -254,7 +254,7 @@ mod test { assert_eq!(v as u64, obj.extract::(py).unwrap()); assert!(obj.extract::(py).is_err()); } - + #[test] fn test_i64_max() { let gil = Python::acquire_gil(); @@ -265,7 +265,7 @@ mod test { assert_eq!(v as u64, obj.extract::(py).unwrap()); assert!(obj.extract::(py).is_err()); } - + #[test] fn test_i64_min() { let gil = Python::acquire_gil(); @@ -276,7 +276,7 @@ mod test { assert!(obj.extract::(py).is_err()); assert!(obj.extract::(py).is_err()); } - + #[test] fn test_u64_max() { let gil = Python::acquire_gil(); diff --git a/src/objects/num3.rs b/src/objects/num3.rs index c6180ae0357..214054cf8bb 100644 --- a/src/objects/num3.rs +++ b/src/objects/num3.rs @@ -7,13 +7,13 @@ use std::os::raw::c_long; extern crate num_traits; use self::num_traits::cast::cast; +use conversion::{FromPyObject, IntoPyObject, ToPyObject}; +use err::{PyErr, PyResult}; use ffi; +use instance::PyObjectWithToken; use object::PyObject; -use python::{ToPyPointer, Python}; -use err::{PyResult, PyErr}; use objects::{exc, PyObjectRef}; -use instance::PyObjectWithToken; -use conversion::{ToPyObject, IntoPyObject, FromPyObject}; +use python::{Python, ToPyPointer}; /// Represents a Python `int` object. /// @@ -26,7 +26,6 @@ pub struct PyLong(PyObject); pyobject_convert!(PyLong); pyobject_nativetype!(PyLong, PyLong_Type, PyLong_Check); - macro_rules! int_fits_c_long( ($rust_type:ty) => ( impl ToPyObject for $rust_type { @@ -65,7 +64,6 @@ macro_rules! int_fits_c_long( ) ); - macro_rules! int_fits_larger_int( ($rust_type:ty, $larger_type:ty) => ( impl ToPyObject for $rust_type { @@ -89,12 +87,12 @@ macro_rules! int_fits_larger_int( ) ); - - #[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] -fn err_if_invalid_value - (py: Python, invalid_value: T, actual_value: T) -> PyResult -{ +fn err_if_invalid_value( + py: Python, + invalid_value: T, + actual_value: T, +) -> PyResult { if actual_value == invalid_value && PyErr::occurred(py) { Err(PyErr::fetch(py)) } else { @@ -139,7 +137,6 @@ macro_rules! int_convert_u64_or_i64 ( ) ); - int_fits_c_long!(i8); int_fits_c_long!(u8); int_fits_c_long!(i16); @@ -147,34 +144,37 @@ 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")))] +#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))] int_fits_c_long!(u32); -#[cfg(any(target_pointer_width="32", target_os="windows"))] +#[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")))] +#[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"))] +#[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")))] +#[cfg(all(target_pointer_width = "64", not(target_os = "windows")))] int_fits_c_long!(isize); -#[cfg(any(target_pointer_width="32", target_os="windows"))] +#[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_u64_or_i64!( + u64, + ffi::PyLong_FromUnsignedLongLong, + ffi::PyLong_AsUnsignedLongLong +); #[cfg(test)] mod test { - use std; - use python::Python; use conversion::ToPyObject; + use python::Python; + use std; macro_rules! test_common ( ($test_mod_name:ident, $t:ty) => ( diff --git a/src/objects/sequence.rs b/src/objects/sequence.rs index 0ecf87416bd..c99b7a30e78 100644 --- a/src/objects/sequence.rs +++ b/src/objects/sequence.rs @@ -3,15 +3,14 @@ use std; use buffer; +use conversion::{FromPyObject, PyTryFrom, ToBorrowedObject}; +use err::{self, PyDowncastError, PyErr, PyResult}; use ffi::{self, Py_ssize_t}; -use err::{self, PyErr, PyResult, PyDowncastError}; -use object::PyObject; use instance::PyObjectWithToken; -use python::ToPyPointer; -use conversion::{FromPyObject, ToBorrowedObject, PyTryFrom}; -use objects::{PyObjectRef, PyList, PyTuple}; +use object::PyObject; use objectprotocol::ObjectProtocol; - +use objects::{PyList, PyObjectRef, PyTuple}; +use python::ToPyPointer; /// Represents a reference to a python object supporting the sequence protocol. pub struct PySequence(PyObject); @@ -19,7 +18,6 @@ pub struct PySequence(PyObject); pyobject_nativetype!(PySequence); pyobject_downcast!(PySequence, PySequence_Check); - #[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))] impl PySequence { /// Returns the number of objects in sequence. This is equivalent to Python `len()`. @@ -37,8 +35,12 @@ impl PySequence { #[inline] pub fn concat(&self, other: &PySequence) -> PyResult<&PySequence> { unsafe { - let ptr = self.py().from_owned_ptr_or_err::( - ffi::PySequence_Concat(self.as_ptr(), other.as_ptr()))?; + let ptr = self + .py() + .from_owned_ptr_or_err::(ffi::PySequence_Concat( + self.as_ptr(), + other.as_ptr(), + ))?; Ok(std::mem::transmute(ptr)) } } @@ -49,8 +51,12 @@ impl PySequence { #[inline] pub fn repeat(&self, count: isize) -> PyResult<&PySequence> { unsafe { - let ptr = self.py().from_owned_ptr_or_err::( - ffi::PySequence_Repeat(self.as_ptr(), count as Py_ssize_t))?; + let ptr = self + .py() + .from_owned_ptr_or_err::(ffi::PySequence_Repeat( + self.as_ptr(), + count as Py_ssize_t, + ))?; Ok(std::mem::transmute(ptr)) } } @@ -87,8 +93,8 @@ impl PySequence { #[inline] pub fn get_item(&self, index: isize) -> PyResult<&PyObjectRef> { unsafe { - self.py().from_owned_ptr_or_err( - ffi::PySequence_GetItem(self.as_ptr(), index as Py_ssize_t)) + self.py() + .from_owned_ptr_or_err(ffi::PySequence_GetItem(self.as_ptr(), index as Py_ssize_t)) } } @@ -97,20 +103,27 @@ impl PySequence { #[inline] pub fn get_slice(&self, begin: isize, end: isize) -> PyResult<&PyObjectRef> { unsafe { - self.py().from_owned_ptr_or_err( - ffi::PySequence_GetSlice( - self.as_ptr(), begin as Py_ssize_t, end as Py_ssize_t)) + self.py().from_owned_ptr_or_err(ffi::PySequence_GetSlice( + self.as_ptr(), + begin as Py_ssize_t, + end as Py_ssize_t, + )) } } /// Assign object v to the ith element of o. /// Equivalent to Python statement `o[i] = v` #[inline] - pub fn set_item(&self, i: isize, item: I) -> PyResult<()> where I: ToBorrowedObject { + pub fn set_item(&self, i: isize, item: I) -> PyResult<()> + where + I: ToBorrowedObject, + { unsafe { item.with_borrowed_ptr(self.py(), |item| { err::error_on_minusone( - self.py(), ffi::PySequence_SetItem(self.as_ptr(), i as Py_ssize_t, item)) + self.py(), + ffi::PySequence_SetItem(self.as_ptr(), i as Py_ssize_t, item), + ) }) } } @@ -121,7 +134,9 @@ impl PySequence { pub fn del_item(&self, i: isize) -> PyResult<()> { unsafe { err::error_on_minusone( - self.py(), ffi::PySequence_DelItem(self.as_ptr(), i as Py_ssize_t)) + self.py(), + ffi::PySequence_DelItem(self.as_ptr(), i as Py_ssize_t), + ) } } @@ -131,8 +146,14 @@ impl PySequence { pub fn set_slice(&self, i1: isize, i2: isize, v: &PyObjectRef) -> PyResult<()> { unsafe { err::error_on_minusone( - self.py(), ffi::PySequence_SetSlice( - self.as_ptr(), i1 as Py_ssize_t, i2 as Py_ssize_t, v.as_ptr())) + self.py(), + ffi::PySequence_SetSlice( + self.as_ptr(), + i1 as Py_ssize_t, + i2 as Py_ssize_t, + v.as_ptr(), + ), + ) } } @@ -143,14 +164,17 @@ impl PySequence { unsafe { err::error_on_minusone( self.py(), - ffi::PySequence_DelSlice(self.as_ptr(), i1 as Py_ssize_t, i2 as Py_ssize_t)) + ffi::PySequence_DelSlice(self.as_ptr(), i1 as Py_ssize_t, i2 as Py_ssize_t), + ) } } /// Return the number of occurrences of value in o, that is, return the number of keys for /// which `o[key] == value` #[inline] - pub fn count(&self, value: V) -> PyResult where V: ToBorrowedObject + pub fn count(&self, value: V) -> PyResult + where + V: ToBorrowedObject, { let r = value.with_borrowed_ptr(self.py(), |ptr| unsafe { ffi::PySequence_Count(self.as_ptr(), ptr) @@ -164,7 +188,9 @@ impl PySequence { /// Determine if o contains value. this is equivalent to the Python expression `value in o` #[inline] - pub fn contains(&self, value: V) -> PyResult where V: ToBorrowedObject + pub fn contains(&self, value: V) -> PyResult + where + V: ToBorrowedObject, { let r = value.with_borrowed_ptr(self.py(), |ptr| unsafe { ffi::PySequence_Contains(self.as_ptr(), ptr) @@ -172,14 +198,16 @@ impl PySequence { match r { 0 => Ok(false), 1 => Ok(true), - _ => Err(PyErr::fetch(self.py())) + _ => Err(PyErr::fetch(self.py())), } } /// Return the first index i for which o[i] == value. /// This is equivalent to the Python expression `o.index(value)` #[inline] - pub fn index(&self, value: V) -> PyResult where V: ToBorrowedObject + pub fn index(&self, value: V) -> PyResult + where + V: ToBorrowedObject, { let r = value.with_borrowed_ptr(self.py(), |ptr| unsafe { ffi::PySequence_Index(self.as_ptr(), ptr) @@ -195,7 +223,8 @@ impl PySequence { #[inline] pub fn list(&self) -> PyResult<&PyList> { unsafe { - self.py().from_owned_ptr_or_err(ffi::PySequence_List(self.as_ptr())) + self.py() + .from_owned_ptr_or_err(ffi::PySequence_List(self.as_ptr())) } } @@ -203,21 +232,24 @@ impl PySequence { #[inline] pub fn tuple(&self) -> PyResult<&PyTuple> { unsafe { - self.py().from_owned_ptr_or_err(ffi::PySequence_Tuple(self.as_ptr())) + self.py() + .from_owned_ptr_or_err(ffi::PySequence_Tuple(self.as_ptr())) } } } - -impl<'a, T> FromPyObject<'a> for Vec where T: FromPyObject<'a> +impl<'a, T> FromPyObject<'a> for Vec +where + T: FromPyObject<'a>, { default fn extract(obj: &'a PyObjectRef) -> PyResult { extract_sequence(obj) } } -impl <'source, T> FromPyObject<'source> for Vec - where for<'a> T: FromPyObject<'a> + buffer::Element + Copy +impl<'source, T> FromPyObject<'source> for Vec +where + for<'a> T: FromPyObject<'a> + buffer::Element + Copy, { fn extract(obj: &'source PyObjectRef) -> PyResult { // first try buffer protocol @@ -235,7 +267,9 @@ impl <'source, T> FromPyObject<'source> for Vec } } -fn extract_sequence<'s, T>(obj: &'s PyObjectRef) -> PyResult> where T: FromPyObject<'s> +fn extract_sequence<'s, T>(obj: &'s PyObjectRef) -> PyResult> +where + T: FromPyObject<'s>, { let seq = ::try_from(obj)?; let mut v = Vec::with_capacity(seq.len().unwrap_or(0) as usize); @@ -245,8 +279,7 @@ fn extract_sequence<'s, T>(obj: &'s PyObjectRef) -> PyResult> where T: Fr Ok(v) } -impl PyTryFrom for PySequence -{ +impl PyTryFrom for PySequence { type Error = PyDowncastError; fn try_from(value: &PyObjectRef) -> Result<&PySequence, Self::Error> { @@ -280,14 +313,13 @@ impl PyTryFrom for PySequence } } - #[cfg(test)] mod test { - use instance::AsPyRef; - use python::Python; use conversion::{PyTryFrom, ToPyObject}; - use objects::PySequence; + use instance::AsPyRef; use objectprotocol::ObjectProtocol; + use objects::PySequence; + use python::Python; #[test] fn test_numbers_are_not_sequences() { @@ -308,7 +340,7 @@ mod test { fn test_seq_empty() { let gil = Python::acquire_gil(); let py = gil.python(); - let v : Vec = vec![]; + let v: Vec = vec![]; let ob = v.to_object(py); let seq = ob.cast_as::(py).unwrap(); assert_eq!(0, seq.len().unwrap()); @@ -340,7 +372,7 @@ mod test { fn test_seq_get_item() { let gil = Python::acquire_gil(); let py = gil.python(); - let v : Vec = vec![1, 1, 2, 3, 5, 8]; + let v: Vec = vec![1, 1, 2, 3, 5, 8]; let ob = v.to_object(py); let seq = ob.cast_as::(py).unwrap(); assert_eq!(1, seq.get_item(0).unwrap().extract::().unwrap()); @@ -482,12 +514,12 @@ mod test { fn test_seq_concat() { let gil = Python::acquire_gil(); let py = gil.python(); - let v : Vec = vec![1, 2, 3]; + let v: Vec = vec![1, 2, 3]; let ob = v.to_object(py); let seq = ob.cast_as::(py).unwrap(); let concat_seq = seq.concat(&seq).unwrap(); assert_eq!(6, concat_seq.len().unwrap()); - let concat_v : Vec = vec![1, 2, 3, 1, 2, 3]; + let concat_v: Vec = vec![1, 2, 3, 1, 2, 3]; for (el, cc) in concat_seq.iter().unwrap().zip(concat_v) { assert_eq!(cc, el.unwrap().extract::().unwrap()); } @@ -575,7 +607,11 @@ mod test { fn test_extract_range_to_vec() { let gil = Python::acquire_gil(); let py = gil.python(); - let v: Vec = py.eval("range(1, 5)", None, None).unwrap().extract().unwrap(); + let v: Vec = py + .eval("range(1, 5)", None, None) + .unwrap() + .extract() + .unwrap(); assert!(v == [1, 2, 3, 4]); } @@ -583,7 +619,11 @@ mod test { fn test_extract_bytearray_to_vec() { let gil = Python::acquire_gil(); let py = gil.python(); - let v: Vec = py.eval("bytearray(b'abc')", None, None).unwrap().extract().unwrap(); + let v: Vec = py + .eval("bytearray(b'abc')", None, None) + .unwrap() + .extract() + .unwrap(); assert!(v == b"abc"); } } diff --git a/src/objects/set.rs b/src/objects/set.rs index 598ed45eb6f..fdf1d2f9a48 100644 --- a/src/objects/set.rs +++ b/src/objects/set.rs @@ -1,14 +1,13 @@ // Copyright (c) 2017-present PyO3 Project and Contributors // -use std::{hash, collections}; +use conversion::{ToBorrowedObject, ToPyObject}; +use err::{self, PyErr, PyResult}; use ffi; -use python::{Python, ToPyPointer}; -use object::PyObject; -use conversion::{ToPyObject, ToBorrowedObject}; use instance::{AsPyRef, Py, PyObjectWithToken}; -use err::{self, PyResult, PyErr}; - +use object::PyObject; +use python::{Python, ToPyPointer}; +use std::{collections, hash}; /// Represents a Python `set` pub struct PySet(PyObject); @@ -27,15 +26,15 @@ impl PySet { /// May panic when running out of memory. pub fn new(py: Python, elements: &[T]) -> Py { let list = elements.to_object(py); - unsafe { - Py::from_owned_ptr_or_panic(ffi::PySet_New(list.as_ptr())) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PySet_New(list.as_ptr())) } } /// Remove all elements from the set. #[inline] pub fn clear(&self) { - unsafe { ffi::PySet_Clear(self.as_ptr()); } + unsafe { + ffi::PySet_Clear(self.as_ptr()); + } } /// Return the number of items in the set. @@ -52,25 +51,34 @@ impl PySet { /// Determine if the set contains the specified key. /// This is equivalent to the Python expression `key in self`. - pub fn contains(&self, key: K) -> PyResult where K: ToPyObject { + pub fn contains(&self, key: K) -> PyResult + where + K: ToPyObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { match ffi::PySet_Contains(self.as_ptr(), key) { 1 => Ok(true), 0 => Ok(false), - _ => Err(PyErr::fetch(self.py())) + _ => Err(PyErr::fetch(self.py())), } }) } /// Remove element from the set if it is present. - pub fn discard(&self, key: K) where K: ToPyObject { + pub fn discard(&self, key: K) + where + K: ToPyObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { ffi::PySet_Discard(self.as_ptr(), key); }) } /// Add element to the set. - pub fn add(&self, key: K) -> PyResult<()> where K: ToPyObject { + pub fn add(&self, key: K) -> PyResult<()> + where + K: ToPyObject, + { key.with_borrowed_ptr(self.py(), move |key| unsafe { err::error_on_minusone(self.py(), ffi::PySet_Add(self.as_ptr(), key)) }) @@ -78,14 +86,13 @@ impl PySet { /// Remove and return an arbitrary element from the set pub fn pop(&self) -> Option { - unsafe { - PyObject::from_owned_ptr_or_opt(self.py(), ffi::PySet_Pop(self.as_ptr())) - } + unsafe { PyObject::from_owned_ptr_or_opt(self.py(), ffi::PySet_Pop(self.as_ptr())) } } } impl ToPyObject for collections::HashSet - where T: hash::Hash + Eq + ToPyObject +where + T: hash::Hash + Eq + ToPyObject, { fn to_object(&self, py: Python) -> PyObject { let set = PySet::new::(py, &[]); @@ -100,7 +107,8 @@ impl ToPyObject for collections::HashSet } impl ToPyObject for collections::BTreeSet - where T: hash::Hash + Eq + ToPyObject +where + T: hash::Hash + Eq + ToPyObject, { fn to_object(&self, py: Python) -> PyObject { let set = PySet::new::(py, &[]); @@ -120,9 +128,7 @@ impl PyFrozenSet { /// May panic when running out of memory. pub fn new(py: Python, elements: &[T]) -> Py { let list = elements.to_object(py); - unsafe { - Py::from_owned_ptr_or_panic(ffi::PyFrozenSet_New(list.as_ptr())) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyFrozenSet_New(list.as_ptr())) } } /// Return the number of items in the set. @@ -139,12 +145,15 @@ impl PyFrozenSet { /// Determine if the set contains the specified key. /// This is equivalent to the Python expression `key in self`. - pub fn contains(&self, key: K) -> PyResult where K: ToBorrowedObject { + pub fn contains(&self, key: K) -> PyResult + where + K: ToBorrowedObject, + { key.with_borrowed_ptr(self.py(), |key| unsafe { match ffi::PySet_Contains(self.as_ptr(), key) { 1 => Ok(true), 0 => Ok(false), - _ => Err(PyErr::fetch(self.py())) + _ => Err(PyErr::fetch(self.py())), } }) } @@ -152,12 +161,12 @@ impl PyFrozenSet { #[cfg(test)] mod test { - use std::collections::{HashSet}; - use super::{PySet, PyFrozenSet}; - use python::Python; - use conversion::{ToPyObject, PyTryFrom}; - use objectprotocol::ObjectProtocol; + use super::{PyFrozenSet, PySet}; + use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; + use objectprotocol::ObjectProtocol; + use python::Python; + use std::collections::HashSet; #[test] fn test_set_new() { @@ -220,7 +229,7 @@ mod test { let py = gil.python(); let ob = PySet::new(py, &[1, 2]); let set = ob.as_ref(py); - set.add(1).unwrap(); // Add a dupliated element + set.add(1).unwrap(); // Add a dupliated element assert!(set.contains(1).unwrap()); } diff --git a/src/objects/slice.rs b/src/objects/slice.rs index 2846bfdc418..966ddea8970 100644 --- a/src/objects/slice.rs +++ b/src/objects/slice.rs @@ -2,12 +2,12 @@ use std::os::raw::c_long; -use object::PyObject; -use python::{ToPyPointer, Python}; +use conversion::ToPyObject; use err::{PyErr, PyResult}; use ffi::{self, Py_ssize_t}; use instance::PyObjectWithToken; -use conversion::ToPyObject; +use object::PyObject; +use python::{Python, ToPyPointer}; /// Represents a Python `slice`. /// @@ -17,7 +17,6 @@ pub struct PySlice(PyObject); pyobject_convert!(PySlice); pyobject_nativetype!(PySlice, PySlice_Type, PySlice_Check); - /// Represents a Python `slice` indices pub struct PySliceIndices { pub start: isize, @@ -37,15 +36,15 @@ impl PySliceIndices { } } - impl PySlice { - /// Construct a new slice with the given elements. pub fn new(py: Python, start: isize, stop: isize, step: isize) -> &PySlice { unsafe { - let ptr = ffi::PySlice_New(ffi::PyLong_FromLong(start as c_long), - ffi::PyLong_FromLong(stop as c_long), - ffi::PyLong_FromLong(step as c_long)); + let ptr = ffi::PySlice_New( + ffi::PyLong_FromLong(start as c_long), + ffi::PyLong_FromLong(stop as c_long), + ffi::PyLong_FromLong(step as c_long), + ); py.from_owned_ptr(ptr) } } @@ -60,12 +59,14 @@ impl PySlice { let stop: isize = 0; let step: isize = 0; let r = ffi::PySlice_GetIndicesEx( - self.as_ptr(), length as Py_ssize_t, + self.as_ptr(), + length as Py_ssize_t, &start as *const _ as *mut _, &stop as *const _ as *mut _, &step as *const _ as *mut _, - &slicelen as *const _ as *mut _); - if r == 0{ + &slicelen as *const _ as *mut _, + ); + if r == 0 { Ok(PySliceIndices { start: start, stop: stop, diff --git a/src/objects/string.rs b/src/objects/string.rs index 9b907f5e658..2cc29c31972 100644 --- a/src/objects/string.rs +++ b/src/objects/string.rs @@ -1,17 +1,17 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use std; -use std::{mem, str}; use std::borrow::Cow; use std::os::raw::c_char; +use std::{mem, str}; +use super::PyStringData; +use err::{PyErr, PyResult}; use ffi; use instance::{Py, PyObjectWithToken}; use object::PyObject; use objects::PyObjectRef; -use python::{ToPyPointer, Python}; -use err::{PyResult, PyErr}; -use super::PyStringData; +use python::{Python, ToPyPointer}; /// Represents a Python `string`. pub struct PyString(PyObject); @@ -29,29 +29,28 @@ pub struct PyBytes(PyObject); pyobject_convert!(PyBytes); pyobject_nativetype!(PyBytes, PyBytes_Type, PyBytes_Check); - impl PyString { - /// Creates a new Python string object. /// /// Panics if out of memory. pub fn new(_py: Python, s: &str) -> Py { 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)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyUnicode_FromStringAndSize(ptr, len)) } } - pub fn from_object<'p>(src: &'p PyObjectRef, encoding: &str, errors: &str) - -> PyResult<&'p PyString> - { + pub fn from_object<'p>( + src: &'p PyObjectRef, + encoding: &str, + errors: &str, + ) -> PyResult<&'p PyString> { unsafe { - src.py().from_owned_ptr_or_err::( - ffi::PyUnicode_FromEncodedObject( + src.py() + .from_owned_ptr_or_err::(ffi::PyUnicode_FromEncodedObject( src.as_ptr(), encoding.as_ptr() as *const c_char, - errors.as_ptr() as *const c_char)) + errors.as_ptr() as *const c_char, + )) } } @@ -87,7 +86,6 @@ impl PyString { } } - impl PyBytes { /// Creates a new Python byte string object. /// The byte string is initialized by copying the data from the `&[u8]`. @@ -96,17 +94,17 @@ impl PyBytes { pub fn new(_py: Python, s: &[u8]) -> Py { 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)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyBytes_FromStringAndSize(ptr, len)) } } /// Creates a new Python byte string object from raw pointer. /// /// Panics if out of memory. pub unsafe fn from_ptr(_py: Python, ptr: *const u8, len: usize) -> Py { - Py::from_owned_ptr_or_panic( - ffi::PyBytes_FromStringAndSize(ptr as *const _, len as isize)) + Py::from_owned_ptr_or_panic(ffi::PyBytes_FromStringAndSize( + ptr as *const _, + len as isize, + )) } /// Gets the Python string data as byte slice. @@ -119,12 +117,11 @@ impl PyBytes { } } - #[cfg(test)] mod test { - use python::Python; - use instance::AsPyRef; use conversion::{FromPyObject, ToPyObject}; + use instance::AsPyRef; + use python::Python; #[test] fn test_non_bmp() { diff --git a/src/objects/string2.rs b/src/objects/string2.rs index c647b627ffc..edd5aa2f274 100644 --- a/src/objects/string2.rs +++ b/src/objects/string2.rs @@ -3,17 +3,17 @@ // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython use std; -use std::str; use std::borrow::Cow; use std::os::raw::c_char; +use std::str; -use ffi; +use super::{PyObjectRef, PyStringData}; use err::PyResult; -use object::PyObject; +use ffi; use instance::{Py, PyObjectWithToken}; -use python::{Python, ToPyPointer}; +use object::PyObject; use objectprotocol::ObjectProtocol; -use super::{PyObjectRef, PyStringData}; +use python::{Python, ToPyPointer}; /// Represents a Python `string`. pub struct PyString(PyObject); @@ -33,7 +33,6 @@ pub struct PyBytes(PyObject); pyobject_convert!(PyBytes); pyobject_nativetype!(PyBytes, PyBaseString_Type, PyString_Check); - impl PyString { /// Creates a new Python string object. /// @@ -53,11 +52,13 @@ impl PyString { pub fn from_object(src: &PyObjectRef, encoding: &str, errors: &str) -> PyResult> { unsafe { Ok(Py::from_owned_ptr_or_err( - src.py(), ffi::PyUnicode_FromEncodedObject( + src.py(), + ffi::PyUnicode_FromEncodedObject( src.as_ptr(), encoding.as_ptr() as *const c_char, - errors.as_ptr() as *const c_char))? - ) + errors.as_ptr() as *const c_char, + ), + )?) } } @@ -108,9 +109,7 @@ impl PyBytes { pub fn new(_py: Python, s: &[u8]) -> Py { 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)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyBytes_FromStringAndSize(ptr, len)) } } /// Gets the Python string data as byte slice. @@ -121,7 +120,6 @@ impl PyBytes { std::slice::from_raw_parts(buffer, length) } } - } impl PyUnicode { @@ -131,19 +129,19 @@ impl PyUnicode { pub fn new(_py: Python, s: &str) -> Py { 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)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyUnicode_FromStringAndSize(ptr, len)) } } - pub fn from_object(src: &PyObjectRef, encoding: &str, errors: &str) -> PyResult> - { + pub fn from_object(src: &PyObjectRef, encoding: &str, errors: &str) -> PyResult> { unsafe { Ok(Py::from_owned_ptr_or_err( - src.py(), ffi::PyUnicode_FromEncodedObject( + src.py(), + ffi::PyUnicode_FromEncodedObject( src.as_ptr(), encoding.as_ptr() as *const c_char, - errors.as_ptr() as *const c_char))?) + errors.as_ptr() as *const c_char, + ), + )?) } } @@ -176,7 +174,7 @@ impl PyUnicode { impl std::convert::From> for Py { #[inline] fn from(ob: Py) -> Py { - unsafe{std::mem::transmute(ob)} + unsafe { std::mem::transmute(ob) } } } @@ -184,16 +182,15 @@ impl std::convert::From> for Py { impl std::convert::From> for Py { #[inline] fn from(ob: Py) -> Py { - unsafe{std::mem::transmute(ob)} + unsafe { std::mem::transmute(ob) } } } - #[cfg(test)] mod test { - use python::Python; + use conversion::{FromPyObject, ToPyObject}; use instance::AsPyRef; - use conversion::{ToPyObject, FromPyObject}; + use python::Python; #[test] fn test_non_bmp() { diff --git a/src/objects/stringdata.rs b/src/objects/stringdata.rs index a3d82e1b879..029232fc2fa 100644 --- a/src/objects/stringdata.rs +++ b/src/objects/stringdata.rs @@ -2,12 +2,12 @@ // // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython -use std::{mem, str, char}; use std::borrow::Cow; +use std::{char, mem, str}; -use python::Python; use err::{PyErr, PyResult}; use objects::exc; +use python::Python; /// Enum of possible Python string representations. #[derive(Clone, Copy, Debug)] @@ -15,31 +15,31 @@ pub enum PyStringData<'a> { Latin1(&'a [u8]), Utf8(&'a [u8]), Utf16(&'a [u16]), - Utf32(&'a [u32]) + Utf32(&'a [u32]), } -impl <'a> From<&'a str> for PyStringData<'a> { +impl<'a> From<&'a str> for PyStringData<'a> { #[inline] fn from(val: &'a str) -> PyStringData<'a> { - PyStringData::Utf8(val.as_bytes()) -} + PyStringData::Utf8(val.as_bytes()) + } } -impl <'a> From<&'a [u16]> for PyStringData<'a> { +impl<'a> From<&'a [u16]> for PyStringData<'a> { #[inline] fn from(val: &'a [u16]) -> PyStringData<'a> { PyStringData::Utf16(val) } } -impl <'a> From<&'a [u32]> for PyStringData<'a> { +impl<'a> From<&'a [u32]> for PyStringData<'a> { #[inline] fn from(val: &'a [u32]) -> PyStringData<'a> { PyStringData::Utf32(val) } } -impl <'a> PyStringData<'a> { +impl<'a> PyStringData<'a> { /// Convert the Python string data to a Rust string. /// /// For UTF-8 and ASCII-only latin-1, returns a borrow into the original string data. @@ -48,44 +48,47 @@ impl <'a> PyStringData<'a> { /// Fails with UnicodeDecodeError if the string data isn't valid in its encoding. pub fn to_string(self, py: Python) -> PyResult> { match self { - PyStringData::Utf8(data) => { - match str::from_utf8(data) { - Ok(s) => Ok(Cow::Borrowed(s)), - Err(e) => Err(PyErr::from_instance( - exc::UnicodeDecodeError::new_utf8(py, data, e)?)) - } - } + PyStringData::Utf8(data) => match str::from_utf8(data) { + Ok(s) => Ok(Cow::Borrowed(s)), + Err(e) => Err(PyErr::from_instance(exc::UnicodeDecodeError::new_utf8( + py, data, e, + )?)), + }, PyStringData::Latin1(data) => { if data.iter().all(|&b| b.is_ascii()) { Ok(Cow::Borrowed(unsafe { str::from_utf8_unchecked(data) })) } else { Ok(Cow::Owned(data.iter().map(|&b| b as char).collect())) } - }, + } PyStringData::Utf16(data) => { fn utf16_bytes(input: &[u16]) -> &[u8] { unsafe { mem::transmute(input) } } match String::from_utf16(data) { Ok(s) => Ok(Cow::Owned(s)), - Err(_) => Err(PyErr::from_instance( - exc::UnicodeDecodeError::new_err( - py, cstr!("utf-16"), - utf16_bytes(data), 0 .. 2*data.len(), cstr!("invalid utf-16"))?) - ) + Err(_) => Err(PyErr::from_instance(exc::UnicodeDecodeError::new_err( + py, + cstr!("utf-16"), + utf16_bytes(data), + 0..2 * data.len(), + cstr!("invalid utf-16"), + )?)), } - }, + } PyStringData::Utf32(data) => { fn utf32_bytes(input: &[u32]) -> &[u8] { unsafe { mem::transmute(input) } } match data.iter().map(|&u| char::from_u32(u)).collect() { Some(s) => Ok(Cow::Owned(s)), - None => Err(PyErr::from_instance( - exc::UnicodeDecodeError::new_err( - py, cstr!("utf-32"), - utf32_bytes(data), 0 .. 4*data.len(), cstr!("invalid utf-32"))?) - ) + None => Err(PyErr::from_instance(exc::UnicodeDecodeError::new_err( + py, + cstr!("utf-32"), + utf32_bytes(data), + 0..4 * data.len(), + cstr!("invalid utf-32"), + )?)), } } } @@ -106,15 +109,13 @@ impl <'a> PyStringData<'a> { } else { Cow::Owned(data.iter().map(|&b| b as char).collect()) } - }, - PyStringData::Utf16(data) => { - Cow::Owned(String::from_utf16_lossy(data)) - }, - PyStringData::Utf32(data) => { - Cow::Owned(data.iter() - .map(|&u| char::from_u32(u).unwrap_or('\u{FFFD}')) - .collect()) } + PyStringData::Utf16(data) => Cow::Owned(String::from_utf16_lossy(data)), + PyStringData::Utf32(data) => Cow::Owned( + data.iter() + .map(|&u| char::from_u32(u).unwrap_or('\u{FFFD}')) + .collect(), + ), } } } diff --git a/src/objects/stringutils.rs b/src/objects/stringutils.rs index 9f778f21fd1..def967b6f8b 100644 --- a/src/objects/stringutils.rs +++ b/src/objects/stringutils.rs @@ -1,12 +1,12 @@ // Copyright (c) 2017-present PyO3 Project and Contributors use std::borrow::Cow; +use conversion::{IntoPyObject, PyTryFrom, ToPyObject}; use err::PyResult; -use python::Python; +use instance::PyObjectWithToken; use object::PyObject; use objects::{PyObjectRef, PyString}; -use instance::PyObjectWithToken; -use conversion::{ToPyObject, IntoPyObject, PyTryFrom}; +use python::Python; /// Converts Rust `str` to Python object. /// See `PyString::new` for details on the conversion. diff --git a/src/objects/tuple.rs b/src/objects/tuple.rs index 51f563c70fa..e4fb58ccb22 100644 --- a/src/objects/tuple.rs +++ b/src/objects/tuple.rs @@ -3,14 +3,14 @@ use std; use std::slice; -use ffi::{self, Py_ssize_t}; +use super::exc; +use conversion::{FromPyObject, IntoPyObject, IntoPyTuple, PyTryFrom, ToPyObject}; use err::{PyErr, PyResult}; -use instance::{Py, PyObjectWithToken, AsPyRef}; +use ffi::{self, Py_ssize_t}; +use instance::{AsPyRef, Py, PyObjectWithToken}; use object::PyObject; use objects::PyObjectRef; -use python::{Python, ToPyPointer, IntoPyPointer}; -use conversion::{FromPyObject, ToPyObject, IntoPyTuple, IntoPyObject, PyTryFrom}; -use super::exc; +use python::{IntoPyPointer, Python, ToPyPointer}; /// Represents a Python `tuple` object. pub struct PyTuple(PyObject); @@ -18,9 +18,7 @@ pub struct PyTuple(PyObject); pyobject_convert!(PyTuple); pyobject_nativetype!(PyTuple, PyTuple_Type, PyTuple_Check); - impl PyTuple { - /// Construct a new tuple with the given elements. pub fn new(py: Python, elements: &[T]) -> Py { unsafe { @@ -35,9 +33,7 @@ impl PyTuple { /// Retrieves the empty tuple. pub fn empty(_py: Python) -> Py { - unsafe { - Py::from_owned_ptr_or_panic(ffi::PyTuple_New(0)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyTuple_New(0)) } } /// Gets the length of the tuple. @@ -55,17 +51,14 @@ impl PyTuple { /// Take a slice of the tuple pointed to by p from low to high and return it as a new tuple. pub fn slice(&self, low: isize, high: isize) -> Py { - unsafe { - Py::from_owned_ptr_or_panic( - ffi::PyTuple_GetSlice(self.as_ptr(), low, high)) - } + unsafe { Py::from_owned_ptr_or_panic(ffi::PyTuple_GetSlice(self.as_ptr(), low, high)) } } /// Take a slice of the tuple pointed to by p from low and return it as a new tuple. pub fn split_from(&self, low: isize) -> Py { unsafe { - let ptr = ffi::PyTuple_GetSlice( - self.as_ptr(), low, ffi::PyTuple_GET_SIZE(self.as_ptr())); + let ptr = + ffi::PyTuple_GetSlice(self.as_ptr(), low, ffi::PyTuple_GET_SIZE(self.as_ptr())); Py::from_owned_ptr_or_panic(ptr) } } @@ -78,8 +71,8 @@ impl PyTuple { // It's quite inconsistent that this method takes `Python` when `len()` does not. assert!(index < self.len()); unsafe { - self.py().from_borrowed_ptr( - ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t)) + self.py() + .from_borrowed_ptr(ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t)) } } @@ -89,16 +82,17 @@ impl PyTuple { // (We don't even need a Python token, thanks to immutability) unsafe { let ptr = self.as_ptr() as *mut ffi::PyTupleObject; - std::mem::transmute( - slice::from_raw_parts( - (*ptr).ob_item.as_ptr(), self.len() - )) + std::mem::transmute(slice::from_raw_parts((*ptr).ob_item.as_ptr(), self.len())) } } /// Returns an iterator over the tuple items. pub fn iter(&self) -> PyTupleIterator { - PyTupleIterator{ py: self.py(), slice: self.as_slice(), index: 0 } + PyTupleIterator { + py: self.py(), + slice: self.as_slice(), + index: 0, + } } } @@ -156,8 +150,11 @@ impl<'a> IntoPyTuple for &'a str { } fn wrong_tuple_length(t: &PyTuple, expected_length: usize) -> PyErr { - let msg = format!("Expected tuple of length {}, but got tuple of length {}.", - expected_length, t.len()); + let msg = format!( + "Expected tuple of length {}, but got tuple of length {}.", + expected_length, + t.len() + ); exc::ValueError::new(msg) } @@ -211,26 +208,65 @@ tuple_conversion!(1, (ref0, 0, A)); tuple_conversion!(2, (ref0, 0, A), (ref1, 1, B)); tuple_conversion!(3, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C)); tuple_conversion!(4, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D)); -tuple_conversion!(5, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D), - (ref4, 4, E)); -tuple_conversion!(6, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D), - (ref4, 4, E), (ref5, 5, F)); -tuple_conversion!(7, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D), - (ref4, 4, E), (ref5, 5, F), (ref6, 6, G)); -tuple_conversion!(8, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D), - (ref4, 4, E), (ref5, 5, F), (ref6, 6, G), (ref7, 7, H)); -tuple_conversion!(9, (ref0, 0, A), (ref1, 1, B), (ref2, 2, C), (ref3, 3, D), - (ref4, 4, E), (ref5, 5, F), (ref6, 6, G), (ref7, 7, H), (ref8, 8, I)); - +tuple_conversion!( + 5, + (ref0, 0, A), + (ref1, 1, B), + (ref2, 2, C), + (ref3, 3, D), + (ref4, 4, E) +); +tuple_conversion!( + 6, + (ref0, 0, A), + (ref1, 1, B), + (ref2, 2, C), + (ref3, 3, D), + (ref4, 4, E), + (ref5, 5, F) +); +tuple_conversion!( + 7, + (ref0, 0, A), + (ref1, 1, B), + (ref2, 2, C), + (ref3, 3, D), + (ref4, 4, E), + (ref5, 5, F), + (ref6, 6, G) +); +tuple_conversion!( + 8, + (ref0, 0, A), + (ref1, 1, B), + (ref2, 2, C), + (ref3, 3, D), + (ref4, 4, E), + (ref5, 5, F), + (ref6, 6, G), + (ref7, 7, H) +); +tuple_conversion!( + 9, + (ref0, 0, A), + (ref1, 1, B), + (ref2, 2, C), + (ref3, 3, D), + (ref4, 4, E), + (ref5, 5, F), + (ref6, 6, G), + (ref7, 7, H), + (ref8, 8, I) +); #[cfg(test)] mod test { - use PyTuple; + use conversion::{PyTryFrom, ToPyObject}; use instance::AsPyRef; - use python::Python; - use conversion::{ToPyObject, PyTryFrom}; - use objects::PyObjectRef; use objectprotocol::ObjectProtocol; + use objects::PyObjectRef; + use python::Python; + use PyTuple; #[test] fn test_new() { diff --git a/src/objects/typeobject.rs b/src/objects/typeobject.rs index b3a05f53824..a219d03b989 100644 --- a/src/objects/typeobject.rs +++ b/src/objects/typeobject.rs @@ -2,14 +2,14 @@ // // based on Daniel Grunwald's https://github.com/dgrunwald/rust-cpython -use std::ffi::CStr; use std::borrow::Cow; +use std::ffi::CStr; +use err::{PyErr, PyResult}; use ffi; +use instance::{Py, PyObjectWithToken}; use object::PyObject; use python::{Python, ToPyPointer}; -use err::{PyErr, PyResult}; -use instance::{Py, PyObjectWithToken}; use typeob::{PyTypeInfo, PyTypeObject}; /// Represents a reference to a Python `type object`. @@ -18,13 +18,10 @@ pub struct PyType(PyObject); pyobject_convert!(PyType); pyobject_nativetype!(PyType, PyType_Type, PyType_Check); - impl PyType { #[inline] pub fn new() -> Py { - unsafe { - Py::from_borrowed_ptr(T::type_object() as *const _ as *mut ffi::PyObject) - } + unsafe { Py::from_borrowed_ptr(T::type_object() as *const _ as *mut ffi::PyObject) } } /// Retrieves the underlying FFI pointer associated with this Python object. @@ -37,25 +34,21 @@ impl PyType { /// This increments the reference count on the type object. /// Undefined behavior if the pointer is NULL or invalid. #[inline] - pub unsafe fn from_type_ptr(py: Python, p: *mut ffi::PyTypeObject) -> &PyType - { + pub unsafe fn from_type_ptr(py: Python, p: *mut ffi::PyTypeObject) -> &PyType { py.from_borrowed_ptr::(p as *mut ffi::PyObject) } /// Gets the name of the PyType. pub fn name(&self) -> Cow { - unsafe { - CStr::from_ptr((*self.as_type_ptr()).tp_name).to_string_lossy() - } + unsafe { CStr::from_ptr((*self.as_type_ptr()).tp_name).to_string_lossy() } } /// Check whether `self` is subclass of type `T` like Python `issubclass` function pub fn is_subclass(&self) -> PyResult - where T: PyTypeObject + where + T: PyTypeObject, { - let result = unsafe { - ffi::PyObject_IsSubclass(self.as_ptr(), T::type_object().as_ptr()) - }; + let result = unsafe { ffi::PyObject_IsSubclass(self.as_ptr(), T::type_object().as_ptr()) }; if result == -1 { Err(PyErr::fetch(self.py())) } else if result == 1 { @@ -67,9 +60,7 @@ impl PyType { // Check whether `obj` is an instance of `self` pub fn is_instance(&self, obj: &T) -> PyResult { - let result = unsafe { - ffi::PyObject_IsInstance(obj.as_ptr(), self.as_ptr()) - }; + let result = unsafe { ffi::PyObject_IsInstance(obj.as_ptr(), self.as_ptr()) }; if result == -1 { Err(PyErr::fetch(self.py())) } else if result == 1 { diff --git a/src/prelude.rs b/src/prelude.rs index bef998c0784..a9ca2544d38 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -12,14 +12,15 @@ pub use super::py; pub use class::*; -pub use objects::*; -pub use objectprotocol::ObjectProtocol; -pub use object::PyObject; +pub use conversion::{ + FromPyObject, IntoPyObject, IntoPyTuple, PyTryFrom, PyTryInto, ToBorrowedObject, ToPyObject, +}; +pub use err::{PyDowncastError, PyErr, PyErrArguments, PyErrValue, PyResult}; +pub use instance::{AsPyRef, Py, PyNativeType, PyObjectWithToken, PyToken}; pub use noargs::NoArgs; -pub use python::{Python, ToPyPointer, IntoPyPointer}; -pub use err::{PyErr, PyErrValue, PyResult, PyDowncastError, PyErrArguments}; +pub use object::PyObject; +pub use objectprotocol::ObjectProtocol; +pub use objects::*; +pub use python::{IntoPyPointer, Python, ToPyPointer}; pub use pythonrun::GILGuard; pub use typeob::PyRawObject; -pub use instance::{PyToken, PyObjectWithToken, AsPyRef, Py, PyNativeType}; -pub use conversion::{FromPyObject, PyTryFrom, PyTryInto, - ToPyObject, ToBorrowedObject, IntoPyObject, IntoPyTuple}; diff --git a/src/python.rs b/src/python.rs index 2a0cfbc8058..e11effdf56c 100644 --- a/src/python.rs +++ b/src/python.rs @@ -7,15 +7,14 @@ use std::ffi::CString; use std::marker::PhantomData; use std::os::raw::c_int; +use conversion::PyTryFrom; +use err::{PyDowncastError, PyErr, PyResult}; use ffi; -use typeob::{PyTypeInfo, PyTypeObject, PyObjectAlloc}; -use instance::{Py, PyToken, AsPyRef}; +use instance::{AsPyRef, Py, PyToken}; use object::PyObject; -use objects::{PyObjectRef, PyType, PyDict, PyModule}; -use err::{PyErr, PyResult, PyDowncastError}; -use conversion::PyTryFrom; +use objects::{PyDict, PyModule, PyObjectRef, PyType}; use pythonrun::{self, GILGuard}; - +use typeob::{PyObjectAlloc, PyTypeInfo, PyTypeObject}; /// Marker type that indicates that the GIL is currently held. /// @@ -46,41 +45,50 @@ pub trait IntoPyPointer { /// Conversion trait that allows various objects to be converted into `PyDict` object pointer. /// Primary use case for this trait is `call` and `call_method` methods as keywords argument. pub trait IntoPyDictPointer { - /// Converts self into a `PyDict` object pointer. Whether pointer owned or borrowed /// depends on implementation. fn into_dict_ptr(self, py: Python) -> *mut ffi::PyObject; - } /// Convert `None` into a null pointer. -impl<'p, T> ToPyPointer for Option<&'p T> where T: ToPyPointer { +impl<'p, T> ToPyPointer for Option<&'p T> +where + T: ToPyPointer, +{ #[inline] default fn as_ptr(&self) -> *mut ffi::PyObject { match *self { Some(t) => t.as_ptr(), - None => std::ptr::null_mut() + None => std::ptr::null_mut(), } } } /// Convert `None` into a null pointer. -impl IntoPyPointer for Option where T: IntoPyPointer { +impl IntoPyPointer for Option +where + T: IntoPyPointer, +{ #[inline] fn into_ptr(self) -> *mut ffi::PyObject { match self { Some(t) => t.into_ptr(), - None => std::ptr::null_mut() + None => std::ptr::null_mut(), } } } /// Gets the underlying FFI pointer, returns a borrowed pointer. -impl<'a, T> IntoPyPointer for &'a T where T: ToPyPointer { +impl<'a, T> IntoPyPointer for &'a T +where + T: ToPyPointer, +{ #[inline] default fn into_ptr(self) -> *mut ffi::PyObject { let ptr = self.as_ptr(); - unsafe { ffi::Py_INCREF(ptr); } + unsafe { + ffi::Py_INCREF(ptr); + } ptr } } @@ -107,7 +115,10 @@ impl<'p> Python<'p> { } /// Temporarily releases the `GIL`, thus allowing other Python threads to run. - pub fn allow_threads(self, f: F) -> T where F : Send + FnOnce() -> T { + pub fn allow_threads(self, f: F) -> T + where + F: Send + FnOnce() -> T, + { // The `Send` bound on the closure prevents the user from // transferring the `Python` token into the closure. unsafe { @@ -122,8 +133,12 @@ impl<'p> Python<'p> { /// /// If `globals` is `None`, it defaults to Python module `__main__`. /// If `locals` is `None`, it defaults to the value of `globals`. - pub fn eval(self, code: &str, globals: Option<&PyDict>, - locals: Option<&PyDict>) -> PyResult<&'p PyObjectRef> { + pub fn eval( + self, + code: &str, + globals: Option<&PyDict>, + locals: Option<&PyDict>, + ) -> PyResult<&'p PyObjectRef> { self.run_code(code, ffi::Py_eval_input, globals, locals) } @@ -131,8 +146,12 @@ impl<'p> Python<'p> { /// /// If `globals` is `None`, it defaults to Python module `__main__`. /// If `locals` is `None`, it defaults to the value of `globals`. - pub fn run(self, code: &str, globals: Option<&PyDict>, - locals: Option<&PyDict>) -> PyResult<()> { + pub fn run( + self, + code: &str, + globals: Option<&PyDict>, + locals: Option<&PyDict>, + ) -> PyResult<()> { let _ = self.run_code(code, ffi::Py_file_input, globals, locals)?; Ok(()) } @@ -143,8 +162,13 @@ impl<'p> Python<'p> { /// /// If `globals` is `None`, it defaults to Python module `__main__`. /// If `locals` is `None`, it defaults to the value of `globals`. - fn run_code(self, code: &str, start: c_int, - globals: Option<&PyDict>, locals: Option<&PyDict>) -> PyResult<&'p PyObjectRef> { + fn run_code( + self, + code: &str, + start: c_int, + globals: Option<&PyDict>, + locals: Option<&PyDict>, + ) -> PyResult<&'p PyObjectRef> { let code = CString::new(code)?; unsafe { @@ -153,20 +177,29 @@ impl<'p> Python<'p> { return Err(PyErr::fetch(self)); } - let globals = globals.map(|g| g.as_ptr()) + let globals = globals + .map(|g| g.as_ptr()) .unwrap_or_else(|| ffi::PyModule_GetDict(mptr)); let locals = locals.map(|l| l.as_ptr()).unwrap_or(globals); - let res_ptr = ffi::PyRun_StringFlags(code.as_ptr(), - start, globals, locals, ::std::ptr::null_mut()); + let res_ptr = ffi::PyRun_StringFlags( + code.as_ptr(), + start, + globals, + locals, + ::std::ptr::null_mut(), + ); self.from_owned_ptr_or_err(res_ptr) } } /// Gets the Python type object for type `T`. - pub fn get_type(self) -> &'p PyType where T: PyTypeObject { - unsafe{ self.from_borrowed_ptr(T::type_object().into_ptr()) } + pub fn get_type(self) -> &'p PyType + where + T: PyTypeObject, + { + unsafe { self.from_borrowed_ptr(T::type_object().into_ptr()) } } /// Import the Python module with the specified name. @@ -181,8 +214,9 @@ impl<'p> Python<'p> { /// Check whether type `T` is subclass of type `U` like Python `issubclass` function pub fn is_subclass(self) -> PyResult - where T: PyTypeObject, - U: PyTypeObject + where + T: PyTypeObject, + U: PyTypeObject, { T::type_object().as_ref(self).is_subclass::() } @@ -203,13 +237,13 @@ impl<'p> Python<'p> { } impl<'p> Python<'p> { - /// Create new instance of `T` and move it under python management. /// Returns `Py`. #[inline] pub fn init(self, f: F) -> PyResult> - where F: FnOnce(PyToken) -> T, - T: PyTypeInfo + PyObjectAlloc + where + F: FnOnce(PyToken) -> T, + T: PyTypeInfo + PyObjectAlloc, { Py::new(self, f) } @@ -218,8 +252,9 @@ impl<'p> Python<'p> { /// Created object get registered in release pool. Returns references to `T` #[inline] pub fn init_ref(self, f: F) -> PyResult<&'p T> - where F: FnOnce(PyToken) -> T, - T: PyTypeInfo + PyObjectAlloc + where + F: FnOnce(PyToken) -> T, + T: PyTypeInfo + PyObjectAlloc, { Py::new_ref(self, f) } @@ -228,17 +263,16 @@ impl<'p> Python<'p> { /// Created object get registered in release pool. Returns mutable references to `T` #[inline] pub fn init_mut(self, f: F) -> PyResult<&'p mut T> - where F: FnOnce(PyToken) -> T, - T: PyTypeInfo + PyObjectAlloc + where + F: FnOnce(PyToken) -> T, + T: PyTypeInfo + PyObjectAlloc, { Py::new_mut(self, f) } } impl<'p> Python<'p> { - - unsafe fn unchecked_downcast(self, ob: &PyObjectRef) -> &'p T - { + unsafe fn unchecked_downcast(self, ob: &PyObjectRef) -> &'p T { if T::OFFSET == 0 { &*(ob as *const _ as *const T) } else { @@ -247,8 +281,7 @@ impl<'p> Python<'p> { } } - unsafe fn unchecked_mut_downcast(self, ob: &PyObjectRef) -> &'p mut T - { + unsafe fn unchecked_mut_downcast(self, ob: &PyObjectRef) -> &'p mut T { if T::OFFSET == 0 { &mut *(ob as *const _ as *mut T) } else { @@ -259,7 +292,8 @@ impl<'p> Python<'p> { /// Register object in release pool, and try to downcast to specific type. pub fn checked_cast_as(self, obj: PyObject) -> Result<&'p T, PyDowncastError> - where T: PyTypeInfo + where + T: PyTypeInfo, { unsafe { let p = pythonrun::register_owned(self, obj.into_ptr()); @@ -269,7 +303,8 @@ impl<'p> Python<'p> { /// Register object in release pool, and do unchecked downcast to specific type. pub unsafe fn cast_as(self, obj: PyObject) -> &'p T - where T: PyTypeInfo + where + T: PyTypeInfo, { let p = pythonrun::register_owned(self, obj.into_ptr()); self.unchecked_downcast(p) @@ -277,8 +312,7 @@ impl<'p> Python<'p> { /// Register `ffi::PyObject` pointer in release pool #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] - pub unsafe fn from_borrowed_ptr_to_obj(self, ptr: *mut ffi::PyObject) -> &'p PyObjectRef - { + pub unsafe fn from_borrowed_ptr_to_obj(self, ptr: *mut ffi::PyObject) -> &'p PyObjectRef { if ptr.is_null() { ::err::panic_after_error(); } else { @@ -290,7 +324,8 @@ impl<'p> Python<'p> { /// and do unchecked downcast to specific type. #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub unsafe fn from_owned_ptr(self, ptr: *mut ffi::PyObject) -> &'p T - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { ::err::panic_after_error(); @@ -303,7 +338,8 @@ impl<'p> Python<'p> { /// Register `ffi::PyObject` pointer in release pool, /// Do unchecked downcast to specific type. Returns mutable reference. pub unsafe fn mut_from_owned_ptr(self, ptr: *mut ffi::PyObject) -> &'p mut T - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { ::err::panic_after_error(); @@ -318,7 +354,8 @@ impl<'p> Python<'p> { /// do unchecked downcast to specific type. #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub unsafe fn from_owned_ptr_or_err(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T> - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { Err(PyErr::fetch(self)) @@ -333,7 +370,8 @@ impl<'p> Python<'p> { /// do unchecked downcast to specific type. #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub unsafe fn from_owned_ptr_or_opt(self, ptr: *mut ffi::PyObject) -> Option<&'p T> - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { None @@ -348,7 +386,8 @@ impl<'p> Python<'p> { /// do unchecked downcast to specific type. #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub unsafe fn from_borrowed_ptr(self, ptr: *mut ffi::PyObject) -> &'p T - where T: PyTypeInfo + where + T: PyTypeInfo, { let p = pythonrun::register_borrowed(self, ptr); self.unchecked_downcast(p) @@ -358,7 +397,8 @@ impl<'p> Python<'p> { /// Panics if the pointer is `null`. /// do unchecked downcast to specific type. pub unsafe fn mut_from_borrowed_ptr(self, ptr: *mut ffi::PyObject) -> &'p mut T - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { ::err::panic_after_error(); @@ -373,7 +413,8 @@ impl<'p> Python<'p> { /// do unchecked downcast to specific type. #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub unsafe fn from_borrowed_ptr_or_err(self, ptr: *mut ffi::PyObject) -> PyResult<&'p T> - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { Err(PyErr::fetch(self)) @@ -388,7 +429,8 @@ impl<'p> Python<'p> { /// do unchecked downcast to specific `T`. #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] pub unsafe fn from_borrowed_ptr_or_opt(self, ptr: *mut ffi::PyObject) -> Option<&'p T> - where T: PyTypeInfo + where + T: PyTypeInfo, { if ptr.is_null() { None @@ -407,7 +449,10 @@ impl<'p> Python<'p> { /// Release PyObject reference. #[inline] - pub fn release(self, ob: T) where T: IntoPyPointer { + pub fn release(self, ob: T) + where + T: IntoPyPointer, + { unsafe { let ptr = ob.into_ptr(); if !ptr.is_null() { @@ -422,16 +467,16 @@ impl<'p> Python<'p> { #[cfg_attr(feature = "cargo-clippy", allow(not_unsafe_ptr_arg_deref))] pub fn xdecref(self, ptr: *mut ffi::PyObject) { if !ptr.is_null() { - unsafe {ffi::Py_DECREF(ptr)}; + unsafe { ffi::Py_DECREF(ptr) }; } } } #[cfg(test)] mod test { - use Python; use objectprotocol::ObjectProtocol; - use objects::{PyObjectRef, PyBool, PyList, PyInt, PyDict}; + use objects::{PyBool, PyDict, PyInt, PyList, PyObjectRef}; + use Python; #[test] fn test_eval() { @@ -439,23 +484,39 @@ mod test { let py = gil.python(); // Make sure builtin names are accessible - let v: i32 = py.eval("min(1, 2)", None, None) - .map_err(|e| e.print(py)).unwrap().extract().unwrap(); + let v: i32 = py + .eval("min(1, 2)", None, None) + .map_err(|e| e.print(py)) + .unwrap() + .extract() + .unwrap(); assert_eq!(v, 1); let d = PyDict::new(py); d.set_item("foo", 13).unwrap(); // Inject our own global namespace - let v: i32 = py.eval("foo + 29", Some(d), None).unwrap().extract().unwrap(); + let v: i32 = py + .eval("foo + 29", Some(d), None) + .unwrap() + .extract() + .unwrap(); assert_eq!(v, 42); // Inject our own local namespace - let v: i32 = py.eval("foo + 29", None, Some(d)).unwrap().extract().unwrap(); + let v: i32 = py + .eval("foo + 29", None, Some(d)) + .unwrap() + .extract() + .unwrap(); assert_eq!(v, 42); // Make sure builtin names are still accessible when using a local namespace - let v: i32 = py.eval("min(foo, 2)", None, Some(d)).unwrap().extract().unwrap(); + let v: i32 = py + .eval("min(foo, 2)", None, Some(d)) + .unwrap() + .extract() + .unwrap(); assert_eq!(v, 2); } @@ -463,7 +524,9 @@ mod test { fn test_is_instance() { let gil = Python::acquire_gil(); let py = gil.python(); - assert!(py.is_instance::(PyBool::new(py, true).into()).unwrap()); + assert!(py + .is_instance::(PyBool::new(py, true).into()) + .unwrap()); let list = PyList::new(py, &[1, 2, 3, 4]); assert!(!py.is_instance::(list.as_ref()).unwrap()); assert!(py.is_instance::(list.as_ref()).unwrap()); diff --git a/src/pythonrun.rs b/src/pythonrun.rs index 1cf1d4213dd..7f72eb076a4 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -1,10 +1,10 @@ // Copyright (c) 2017-present PyO3 Project and Contributors -use std::{any, sync, rc, marker, mem}; use spin; +use std::{any, marker, mem, rc, sync}; use ffi; -use python::Python; use objects::PyObjectRef; +use python::Python; static START: sync::Once = sync::ONCE_INIT; static START_PYO3: sync::Once = sync::ONCE_INIT; @@ -65,7 +65,6 @@ pub fn prepare_freethreaded_python() { }); } - #[doc(hidden)] pub fn prepare_pyo3_library() { START_PYO3.call_once(|| unsafe { @@ -92,7 +91,7 @@ pub struct GILGuard { gstate: ffi::PyGILState_STATE, // hack to opt out of Send on stable rust, which doesn't // have negative impls - no_send: marker::PhantomData> + no_send: marker::PhantomData>, } /// The Drop implementation for `GILGuard` will release the GIL. @@ -107,7 +106,6 @@ impl Drop for GILGuard { } } - /// Release pool struct ReleasePool { owned: Vec<*mut ffi::PyObject>, @@ -135,7 +133,7 @@ impl ReleasePool { let ptr = *v; let vec: &'static mut Vec<*mut ffi::PyObject> = &mut *ptr; if vec.is_empty() { - return + return; } // switch vectors @@ -186,10 +184,12 @@ impl Default for GILPool { #[inline] fn default() -> GILPool { let p: &'static mut ReleasePool = unsafe { &mut *POOL }; - GILPool {owned: p.owned.len(), - borrowed: p.borrowed.len(), - pointers: true, - no_send: marker::PhantomData} + GILPool { + owned: p.owned.len(), + borrowed: p.borrowed.len(), + pointers: true, + no_send: marker::PhantomData, + } } } @@ -201,10 +201,12 @@ impl GILPool { #[inline] pub fn new_no_pointers() -> GILPool { let p: &'static mut ReleasePool = unsafe { &mut *POOL }; - GILPool {owned: p.owned.len(), - borrowed: p.borrowed.len(), - pointers: false, - no_send: marker::PhantomData} + GILPool { + owned: p.owned.len(), + borrowed: p.borrowed.len(), + pointers: false, + no_send: marker::PhantomData, + } } } @@ -217,16 +219,19 @@ impl Drop for GILPool { } } -pub unsafe fn register_any<'p, T: 'static>(obj: T) -> &'p T -{ +pub unsafe fn register_any<'p, T: 'static>(obj: T) -> &'p T { let pool: &'static mut ReleasePool = &mut *POOL; pool.obj.push(Box::new(obj)); - pool.obj.last().unwrap().as_ref().downcast_ref::().unwrap() + pool.obj + .last() + .unwrap() + .as_ref() + .downcast_ref::() + .unwrap() } -pub unsafe fn register_pointer(obj: *mut ffi::PyObject) -{ +pub unsafe fn register_pointer(obj: *mut ffi::PyObject) { let pool: &'static mut ReleasePool = &mut *POOL; let mut v = pool.p.lock(); @@ -234,18 +239,16 @@ pub unsafe fn register_pointer(obj: *mut ffi::PyObject) pool.push(obj); } -pub unsafe fn register_owned(_py: Python, obj: *mut ffi::PyObject) -> &PyObjectRef -{ +pub unsafe fn register_owned(_py: Python, obj: *mut ffi::PyObject) -> &PyObjectRef { let pool: &'static mut ReleasePool = &mut *POOL; pool.owned.push(obj); - mem::transmute(&pool.owned[pool.owned.len()-1]) + mem::transmute(&pool.owned[pool.owned.len() - 1]) } -pub unsafe fn register_borrowed(_py: Python, obj: *mut ffi::PyObject) -> &PyObjectRef -{ +pub unsafe fn register_borrowed(_py: Python, obj: *mut ffi::PyObject) -> &PyObjectRef { let pool: &'static mut ReleasePool = &mut *POOL; pool.borrowed.push(obj); - mem::transmute(&pool.borrowed[pool.borrowed.len()-1]) + mem::transmute(&pool.borrowed[pool.borrowed.len() - 1]) } impl GILGuard { @@ -259,10 +262,12 @@ impl GILGuard { unsafe { let gstate = ffi::PyGILState_Ensure(); // acquire GIL let pool: &'static mut ReleasePool = &mut *POOL; - GILGuard { owned: pool.owned.len(), - borrowed: pool.borrowed.len(), - gstate: gstate, - no_send: marker::PhantomData } + GILGuard { + owned: pool.owned.len(), + borrowed: pool.borrowed.len(), + gstate: gstate, + no_send: marker::PhantomData, + } } } @@ -275,10 +280,10 @@ impl GILGuard { #[cfg(test)] mod test { - use {ffi, pythonrun}; - use python::Python; - use object::PyObject; use super::{GILPool, ReleasePool, POOL}; + use object::PyObject; + use python::Python; + use {ffi, pythonrun}; #[test] fn test_owned() { diff --git a/src/typeob.rs b/src/typeob.rs index 0a4184db291..ecb3ab9f778 100644 --- a/src/typeob.rs +++ b/src/typeob.rs @@ -3,17 +3,16 @@ //! Python type object information use std; -use std::mem; -use std::ffi::{CStr, CString}; use std::collections::HashMap; +use std::ffi::{CStr, CString}; +use std::mem; -use {ffi, class, pythonrun}; +use class::methods::PyMethodDefType; use err::{PyErr, PyResult}; use instance::{Py, PyObjectWithToken, PyToken}; -use python::{Python, IntoPyPointer}; use objects::PyType; -use class::methods::PyMethodDefType; - +use python::{IntoPyPointer, Python}; +use {class, ffi, pythonrun}; /// Python type information. pub trait PyTypeInfo { @@ -44,33 +43,32 @@ pub trait PyTypeInfo { /// Check if `*mut ffi::PyObject` is instance of this type #[cfg_attr(feature = "cargo-clippy", allow(not_unsafe_ptr_arg_deref))] fn is_instance(ptr: *mut ffi::PyObject) -> bool { - unsafe {ffi::PyObject_TypeCheck(ptr, Self::type_object()) != 0} + unsafe { ffi::PyObject_TypeCheck(ptr, Self::type_object()) != 0 } } /// Check if `*mut ffi::PyObject` is exact instance of this type #[cfg_attr(feature = "cargo-clippy", allow(not_unsafe_ptr_arg_deref))] fn is_exact_instance(ptr: *mut ffi::PyObject) -> bool { - unsafe { - (*ptr).ob_type == Self::type_object() - } + unsafe { (*ptr).ob_type == Self::type_object() } } } - /// type object supports python GC pub const PY_TYPE_FLAG_GC: usize = 1; /// Type object supports python weak references -pub const PY_TYPE_FLAG_WEAKREF: usize = 1<<1; +pub const PY_TYPE_FLAG_WEAKREF: usize = 1 << 1; /// Type object can be used as the base type of another type -pub const PY_TYPE_FLAG_BASETYPE: usize = 1<<2; +pub const PY_TYPE_FLAG_BASETYPE: usize = 1 << 2; /// The instances of this type have a dictionary containing instance variables -pub const PY_TYPE_FLAG_DICT: usize = 1<<3; +pub const PY_TYPE_FLAG_DICT: usize = 1 << 3; - -impl<'a, T: ?Sized> PyTypeInfo for &'a T where T: PyTypeInfo { +impl<'a, T: ?Sized> PyTypeInfo for &'a T +where + T: PyTypeInfo, +{ type Type = T::Type; type BaseType = T::BaseType; const NAME: &'static str = T::NAME; @@ -133,9 +131,11 @@ pub struct PyRawObject { impl PyRawObject { #[must_use] - pub unsafe fn new(py: Python, - tp_ptr: *mut ffi::PyTypeObject, - curr_ptr: *mut ffi::PyTypeObject) -> PyResult { + pub unsafe fn new( + py: Python, + tp_ptr: *mut ffi::PyTypeObject, + curr_ptr: *mut ffi::PyTypeObject, + ) -> PyResult { let alloc = (*curr_ptr).tp_alloc.unwrap_or(ffi::PyType_GenericAlloc); let ptr = alloc(curr_ptr, 0); @@ -152,10 +152,12 @@ impl PyRawObject { } #[must_use] - pub unsafe fn new_with_ptr(py: Python, - ptr: *mut ffi::PyObject, - tp_ptr: *mut ffi::PyTypeObject, - curr_ptr: *mut ffi::PyTypeObject) -> PyResult { + pub unsafe fn new_with_ptr( + py: Python, + ptr: *mut ffi::PyObject, + tp_ptr: *mut ffi::PyTypeObject, + curr_ptr: *mut ffi::PyTypeObject, + ) -> PyResult { if !ptr.is_null() { Ok(PyRawObject { ptr: ptr, @@ -169,8 +171,9 @@ impl PyRawObject { } pub fn init(&self, f: F) -> PyResult<()> - where F: FnOnce(PyToken) -> T, - T: PyTypeInfo + where + F: FnOnce(PyToken) -> T, + T: PyTypeInfo, { let value = f(PyToken::new()); @@ -183,7 +186,7 @@ impl PyRawObject { /// Type object pub fn type_object(&self) -> &PyType { - unsafe {PyType::from_type_ptr(self.py(), self.curr_ptr)} + unsafe { PyType::from_type_ptr(self.py(), self.curr_ptr) } } /// Return reference to object. @@ -214,7 +217,6 @@ impl PyObjectWithToken for PyRawObject { /// A Python object allocator that is usable as a base type for #[class] pub trait PyObjectAlloc { - /// Allocates a new object (usually by calling ty->tp_alloc), unsafe fn alloc(py: Python) -> PyResult<*mut ffi::PyObject>; @@ -227,8 +229,10 @@ pub trait PyObjectAlloc { unsafe fn drop(_py: Python, _obj: *mut ffi::PyObject) {} } -impl PyObjectAlloc for T where T : PyTypeInfo { - +impl PyObjectAlloc for T +where + T: PyTypeInfo, +{ #[allow(unconditional_recursion)] /// Calls the rust destructor for the object. default unsafe fn drop(py: Python, obj: *mut ffi::PyObject) { @@ -256,7 +260,7 @@ impl PyObjectAlloc for T where T : PyTypeInfo { Self::drop(py, obj); if ffi::PyObject_CallFinalizerFromDealloc(obj) < 0 { - return + return; } match (*T::type_object()).tp_free { @@ -304,7 +308,6 @@ impl PyObjectAlloc for T where T : PyTypeInfo { /// Trait implemented by Python object types that have a corresponding type object. pub trait PyTypeObject { - /// Initialize type object fn init_type(); @@ -314,22 +317,27 @@ pub trait PyTypeObject { /// Create PyRawObject which can be initialized with rust value #[must_use] fn create(py: Python) -> PyResult - where Self: Sized + PyObjectAlloc + PyTypeInfo + where + Self: Sized + PyObjectAlloc + PyTypeInfo, { ::init_type(); unsafe { let ptr = >::alloc(py)?; PyRawObject::new_with_ptr( - py, ptr, + py, + ptr, ::type_object(), - ::type_object()) + ::type_object(), + ) } } } -impl PyTypeObject for T where T: PyObjectAlloc + PyTypeInfo { - +impl PyTypeObject for T +where + T: PyObjectAlloc + PyTypeInfo, +{ #[inline] default fn init_type() { unsafe { @@ -339,7 +347,8 @@ impl PyTypeObject for T where T: PyObjectAlloc + PyTypeInfo { let py = gil.python(); initialize_type::(py, None).expect( - format!("An error occurred while initializing class {}", T::NAME).as_ref()); + format!("An error occurred while initializing class {}", T::NAME).as_ref(), + ); } } } @@ -351,22 +360,23 @@ impl PyTypeObject for T where T: PyObjectAlloc + PyTypeInfo { } } - /// Register new type in python object system. pub fn initialize_type<'p, T>(py: Python<'p>, module_name: Option<&str>) -> PyResult<()> - where T: PyObjectAlloc + PyTypeInfo +where + T: PyObjectAlloc + PyTypeInfo, { // type name let name = match module_name { Some(module_name) => CString::new(format!("{}.{}", module_name, T::NAME)), - None => CString::new(T::NAME) + None => CString::new(T::NAME), }; - let name = name.expect( - "Module name/type name must not contain NUL byte").into_raw(); + let name = name + .expect("Module name/type name must not contain NUL byte") + .into_raw(); - let type_object: &mut ffi::PyTypeObject = unsafe{&mut *T::type_object()}; - let base_type_object: &mut ffi::PyTypeObject = unsafe { - &mut *::type_object() }; + let type_object: &mut ffi::PyTypeObject = unsafe { &mut *T::type_object() }; + let base_type_object: &mut ffi::PyTypeObject = + unsafe { &mut *::type_object() }; type_object.tp_name = name; type_object.tp_doc = T::DESCRIPTION.as_ptr() as *const _; @@ -443,7 +453,10 @@ pub fn initialize_type<'p, T>(py: Python<'p>, module_name: Option<&str>) -> PyRe } if let (None, Some(_)) = (new, init) { - panic!("{}.__new__ method is required if __init__ method defined", T::NAME); + panic!( + "{}.__new__ method is required if __init__ method defined", + T::NAME + ); } // __new__ method @@ -463,8 +476,9 @@ pub fn initialize_type<'p, T>(py: Python<'p>, module_name: Option<&str>) -> PyRe // set type flags py_class_flags::(type_object); - if type_object.tp_base != - unsafe{&ffi::PyBaseObject_Type as *const ffi::PyTypeObject as *mut ffi::PyTypeObject} { + if type_object.tp_base + != unsafe { &ffi::PyBaseObject_Type as *const ffi::PyTypeObject as *mut ffi::PyTypeObject } + { type_object.tp_flags |= ffi::Py_TPFLAGS_HEAPTYPE } @@ -491,10 +505,14 @@ fn async_methods(type_info: &mut ffi::PyTypeObject) { fn async_methods(_type_info: &mut ffi::PyTypeObject) {} unsafe extern "C" fn tp_dealloc_callback(obj: *mut ffi::PyObject) - where T: PyObjectAlloc +where + T: PyObjectAlloc, { - debug!("DEALLOC: {:?} - {:?}", obj, - CStr::from_ptr((*(*obj).ob_type).tp_name).to_string_lossy()); + debug!( + "DEALLOC: {:?} - {:?}", + obj, + CStr::from_ptr((*(*obj).ob_type).tp_name).to_string_lossy() + ); let _pool = pythonrun::GILPool::new_no_pointers(); let py = Python::assume_gil_acquired(); >::dealloc(py, obj) @@ -502,41 +520,45 @@ unsafe extern "C" fn tp_dealloc_callback(obj: *mut ffi::PyObject) #[cfg(Py_3)] fn py_class_flags(type_object: &mut ffi::PyTypeObject) { - if type_object.tp_traverse != None || type_object.tp_clear != None || - T::FLAGS & PY_TYPE_FLAG_GC != 0 + 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_HAVE_GC; + type_object.tp_flags = ffi::Py_TPFLAGS_DEFAULT | ffi::Py_TPFLAGS_HAVE_GC; } else { type_object.tp_flags = ffi::Py_TPFLAGS_DEFAULT; } - if T::FLAGS & PY_TYPE_FLAG_BASETYPE != 0 { + if T::FLAGS & PY_TYPE_FLAG_BASETYPE != 0 { type_object.tp_flags |= ffi::Py_TPFLAGS_BASETYPE; } } #[cfg(not(Py_3))] fn py_class_flags(type_object: &mut ffi::PyTypeObject) { - if type_object.tp_traverse != None || type_object.tp_clear != None || - T::FLAGS & PY_TYPE_FLAG_GC != 0 + 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; + 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 = type_object.tp_flags | ffi::Py_TPFLAGS_HAVE_NEWBUFFER; } - if T::FLAGS & PY_TYPE_FLAG_BASETYPE != 0 { + if T::FLAGS & PY_TYPE_FLAG_BASETYPE != 0 { type_object.tp_flags |= ffi::Py_TPFLAGS_BASETYPE; } } #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] -fn py_class_method_defs() -> PyResult<(Option, - Option, - Option, - Vec)> -{ +fn py_class_method_defs() -> PyResult<( + Option, + Option, + Option, + Vec, +)> { let mut defs = Vec::new(); let mut call = None; let mut new = None; @@ -550,7 +572,7 @@ fn py_class_method_defs() -> PyResult<(Option, if let class::methods::PyMethodType::PyNewFunc(meth) = def.ml_meth { new = Some(meth) } - }, + } PyMethodDefType::Call(ref def) => { if let class::methods::PyMethodType::PyCFunctionWithKeywords(meth) = def.ml_meth { call = Some(meth) @@ -565,9 +587,9 @@ fn py_class_method_defs() -> PyResult<(Option, panic!("Method type is not supoorted by tp_init slot") } } - PyMethodDefType::Method(ref def) | - PyMethodDefType::Class(ref def) | - PyMethodDefType::Static(ref def) => { + PyMethodDefType::Method(ref def) + | PyMethodDefType::Class(ref def) + | PyMethodDefType::Static(ref def) => { defs.push(def.as_method_def()); } _ => (), @@ -609,7 +631,8 @@ fn py_class_properties() -> Vec { let mut defs = HashMap::new(); for def in ::py_methods() - .iter().chain(::py_methods().iter()) + .iter() + .chain(::py_methods().iter()) { match *def { PyMethodDefType::Getter(ref getter) => { @@ -619,7 +642,7 @@ fn py_class_properties() -> Vec { } let def = defs.get_mut(&name).expect("Failed to call get_mut"); getter.copy_to(def); - }, + } PyMethodDefType::Setter(ref setter) => { let name = setter.name.to_string(); if !defs.contains_key(&name) { @@ -627,7 +650,7 @@ fn py_class_properties() -> Vec { } let def = defs.get_mut(&name).expect("Failed to call get_mut"); setter.copy_to(def); - }, + } _ => (), } } diff --git a/tests/common.rs b/tests/common.rs index 74787a46a22..ed5aa3de6ea 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -3,13 +3,17 @@ macro_rules! py_run { ($py:expr, $val:ident, $code:expr) => {{ let d = PyDict::new($py); d.set_item(stringify!($val), &$val).unwrap(); - $py.run($code, None, Some(d)).map_err(|e| e.print($py)).expect($code); - }} + $py.run($code, None, Some(d)) + .map_err(|e| e.print($py)) + .expect($code); + }}; } #[macro_export] macro_rules! py_assert { - ($py:expr, $val:ident, $assertion:expr) => { py_run!($py, $val, concat!("assert ", $assertion)) }; + ($py:expr, $val:ident, $assertion:expr) => { + py_run!($py, $val, concat!("assert ", $assertion)) + }; } #[macro_export] @@ -22,5 +26,5 @@ macro_rules! py_expect_exception { if !err.matches($py, $py.get_type::()) { panic!(format!("Expected {} but got {:?}", stringify!($err), err)) } - }} + }}; } diff --git a/tests/test_arithmetics.rs b/tests/test_arithmetics.rs index 05ae3fce2ff..801587dc2c3 100644 --- a/tests/test_arithmetics.rs +++ b/tests/test_arithmetics.rs @@ -7,16 +7,16 @@ use pyo3::prelude::*; use pyo3::py::class as pyclass; use pyo3::py::proto as pyproto; - #[macro_use] mod common; #[pyclass] -struct UnaryArithmetic {token: PyToken} +struct UnaryArithmetic { + token: PyToken, +} #[pyproto] impl PyNumberProtocol for UnaryArithmetic { - fn __neg__(&self) -> PyResult<&'static str> { Ok("neg") } @@ -39,17 +39,16 @@ fn unary_arithmetic() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| UnaryArithmetic{token: t}).unwrap(); + let c = py.init(|t| UnaryArithmetic { token: t }).unwrap(); py_run!(py, c, "assert -c == 'neg'"); py_run!(py, c, "assert +c == 'pos'"); py_run!(py, c, "assert abs(c) == 'abs'"); py_run!(py, c, "assert ~c == 'invert'"); } - #[pyclass] struct BinaryArithmetic { - token: PyToken + token: PyToken, } #[pyproto] @@ -59,7 +58,6 @@ impl PyObjectProtocol for BinaryArithmetic { } } - #[pyclass] struct InPlaceOperations { value: u32, @@ -121,29 +119,92 @@ fn inplace_operations() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| InPlaceOperations{value: 0, token: t}).unwrap(); - py_run!(py, c, "d = c; c += 1; assert repr(c) == repr(d) == 'IPO(1)'"); - - let c = py.init(|t| InPlaceOperations{value:10, token: t}).unwrap(); - py_run!(py, c, "d = c; c -= 1; assert repr(c) == repr(d) == 'IPO(9)'"); - - let c = py.init(|t| InPlaceOperations{value: 3, token: t}).unwrap(); - py_run!(py, c, "d = c; c *= 3; assert repr(c) == repr(d) == 'IPO(9)'"); - - let c = py.init(|t| InPlaceOperations{value: 3, token: t}).unwrap(); - py_run!(py, c, "d = c; c <<= 2; assert repr(c) == repr(d) == 'IPO(12)'"); - - let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap(); - py_run!(py, c, "d = c; c >>= 2; assert repr(c) == repr(d) == 'IPO(3)'"); - - let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap(); - py_run!(py, c, "d = c; c &= 10; assert repr(c) == repr(d) == 'IPO(8)'"); - - let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap(); - py_run!(py, c, "d = c; c |= 3; assert repr(c) == repr(d) == 'IPO(15)'"); - - let c = py.init(|t| InPlaceOperations{value: 12, token: t}).unwrap(); - py_run!(py, c, "d = c; c ^= 5; assert repr(c) == repr(d) == 'IPO(9)'"); + let c = py + .init(|t| InPlaceOperations { value: 0, token: t }) + .unwrap(); + py_run!( + py, + c, + "d = c; c += 1; assert repr(c) == repr(d) == 'IPO(1)'" + ); + + let c = py + .init(|t| InPlaceOperations { + value: 10, + token: t, + }) + .unwrap(); + py_run!( + py, + c, + "d = c; c -= 1; assert repr(c) == repr(d) == 'IPO(9)'" + ); + + let c = py + .init(|t| InPlaceOperations { value: 3, token: t }) + .unwrap(); + py_run!( + py, + c, + "d = c; c *= 3; assert repr(c) == repr(d) == 'IPO(9)'" + ); + + let c = py + .init(|t| InPlaceOperations { value: 3, token: t }) + .unwrap(); + py_run!( + py, + c, + "d = c; c <<= 2; assert repr(c) == repr(d) == 'IPO(12)'" + ); + + let c = py + .init(|t| InPlaceOperations { + value: 12, + token: t, + }) + .unwrap(); + py_run!( + py, + c, + "d = c; c >>= 2; assert repr(c) == repr(d) == 'IPO(3)'" + ); + + let c = py + .init(|t| InPlaceOperations { + value: 12, + token: t, + }) + .unwrap(); + py_run!( + py, + c, + "d = c; c &= 10; assert repr(c) == repr(d) == 'IPO(8)'" + ); + + let c = py + .init(|t| InPlaceOperations { + value: 12, + token: t, + }) + .unwrap(); + py_run!( + py, + c, + "d = c; c |= 3; assert repr(c) == repr(d) == 'IPO(15)'" + ); + + let c = py + .init(|t| InPlaceOperations { + value: 12, + token: t, + }) + .unwrap(); + py_run!( + py, + c, + "d = c; c ^= 5; assert repr(c) == repr(d) == 'IPO(9)'" + ); } #[pyproto] @@ -186,7 +247,7 @@ fn binary_arithmetic() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| BinaryArithmetic{token: t}).unwrap(); + let c = py.init(|t| BinaryArithmetic { token: t }).unwrap(); py_run!(py, c, "assert c + c == 'BA + BA'"); py_run!(py, c, "assert c + 1 == 'BA + 1'"); py_run!(py, c, "assert 1 + c == '1 + BA'"); @@ -207,10 +268,9 @@ fn binary_arithmetic() { py_run!(py, c, "assert 1 | c == '1 | BA'"); } - #[pyclass] struct RichComparisons { - token: PyToken + token: PyToken, } #[pyproto] @@ -226,14 +286,14 @@ impl PyObjectProtocol for RichComparisons { CompareOp::Eq => Ok(format!("{} == {:?}", self.__repr__().unwrap(), other)), CompareOp::Ne => Ok(format!("{} != {:?}", self.__repr__().unwrap(), other)), CompareOp::Gt => Ok(format!("{} > {:?}", self.__repr__().unwrap(), other)), - CompareOp::Ge => Ok(format!("{} >= {:?}", self.__repr__().unwrap(), other)) + CompareOp::Ge => Ok(format!("{} >= {:?}", self.__repr__().unwrap(), other)), } } } #[pyclass] struct RichComparisons2 { - py: PyToken + py: PyToken, } #[pyproto] @@ -246,7 +306,7 @@ impl PyObjectProtocol for RichComparisons2 { match op { CompareOp::Eq => Ok(true.to_object(self.py())), CompareOp::Ne => Ok(false.to_object(self.py())), - _ => Ok(self.py().NotImplemented()) + _ => Ok(self.py().NotImplemented()), } } } @@ -256,7 +316,7 @@ fn rich_comparisons() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| RichComparisons{token: t}).unwrap(); + let c = py.init(|t| RichComparisons { token: t }).unwrap(); py_run!(py, c, "assert (c < c) == 'RC < RC'"); py_run!(py, c, "assert (c < 1) == 'RC < 1'"); py_run!(py, c, "assert (1 < c) == 'RC > 1'"); @@ -283,7 +343,7 @@ fn rich_comparisons_python_3_type_error() { let gil = Python::acquire_gil(); let py = gil.python(); - let c2 = py.init(|t| RichComparisons2{py: t}).unwrap(); + let c2 = py.init(|t| RichComparisons2 { py: t }).unwrap(); py_expect_exception!(py, c2, "c2 < c2", TypeError); py_expect_exception!(py, c2, "c2 < 1", TypeError); py_expect_exception!(py, c2, "1 < c2", TypeError); @@ -302,4 +362,4 @@ fn rich_comparisons_python_3_type_error() { py_expect_exception!(py, c2, "c2 >= c2", TypeError); py_expect_exception!(py, c2, "c2 >= 1", TypeError); py_expect_exception!(py, c2, "1 >= c2", TypeError); -} \ No newline at end of file +} diff --git a/tests/test_buffer_protocol.rs b/tests/test_buffer_protocol.rs index 24e9e64cadd..11d031bc76a 100644 --- a/tests/test_buffer_protocol.rs +++ b/tests/test_buffer_protocol.rs @@ -2,16 +2,15 @@ extern crate pyo3; -use std::ptr; use std::os::raw::{c_int, c_void}; +use std::ptr; -use pyo3::prelude::*; use pyo3::ffi; +use pyo3::prelude::*; use pyo3::py::class as pyclass; use pyo3::py::proto as pyproto; - #[pyclass] struct TestClass { vec: Vec, @@ -20,10 +19,9 @@ struct TestClass { #[pyproto] impl PyBufferProtocol for TestClass { - fn bf_getbuffer(&self, view: *mut ffi::Py_buffer, flags: c_int) -> PyResult<()> { if view.is_null() { - return Err(PyErr::new::("View is null")) + return Err(PyErr::new::("View is null")); } unsafe { @@ -31,7 +29,7 @@ impl PyBufferProtocol for TestClass { } if (flags & ffi::PyBUF_WRITABLE) == ffi::PyBUF_WRITABLE { - return Err(PyErr::new::("Object is not writable")) + return Err(PyErr::new::("Object is not writable")); } let bytes = &self.vec; @@ -67,14 +65,18 @@ impl PyBufferProtocol for TestClass { } } - #[cfg(Py_3)] #[test] fn test_buffer() { let gil = Python::acquire_gil(); let py = gil.python(); - let t = py.init(|t| TestClass{vec: vec![b' ', b'2', b'3'], token: t}).unwrap(); + let t = py + .init(|t| TestClass { + vec: vec![b' ', b'2', b'3'], + token: t, + }) + .unwrap(); let d = PyDict::new(py); d.set_item("ob", t).unwrap(); @@ -87,9 +89,15 @@ fn test_buffer() { let gil = Python::acquire_gil(); let py = gil.python(); - let t = py.init(|t| TestClass{vec: vec![b' ', b'2', b'3'], token: t}).unwrap(); + let t = py + .init(|t| TestClass { + vec: vec![b' ', b'2', b'3'], + token: t, + }) + .unwrap(); let d = PyDict::new(py); d.set_item("ob", t).unwrap(); - py.run("assert memoryview(ob).tobytes() == ' 23'", None, Some(d)).unwrap(); + py.run("assert memoryview(ob).tobytes() == ' 23'", None, Some(d)) + .unwrap(); } diff --git a/tests/test_class_basics.rs b/tests/test_class_basics.rs index 24d77310329..c98783bff62 100644 --- a/tests/test_class_basics.rs +++ b/tests/test_class_basics.rs @@ -10,7 +10,7 @@ use pyo3::py::class as pyclass; mod common; #[pyclass] -struct EmptyClass { } +struct EmptyClass {} #[test] fn empty_class() { @@ -28,7 +28,7 @@ fn empty_class() { /// Line3 // this is not doc string #[pyclass] -struct ClassWithDocs { } +struct ClassWithDocs {} #[test] fn class_with_docstr() { @@ -36,12 +36,16 @@ fn class_with_docstr() { let gil = Python::acquire_gil(); let py = gil.python(); let typeobj = py.get_type::(); - py_run!(py, typeobj, "assert typeobj.__doc__ == 'Line1\\nLine2\\n Line3'"); + py_run!( + py, + typeobj, + "assert typeobj.__doc__ == 'Line1\\nLine2\\n Line3'" + ); } } #[pyclass(name=CustomName)] -struct EmptyClass2 { } +struct EmptyClass2 {} #[test] fn custom_class_name() { @@ -52,7 +56,7 @@ fn custom_class_name() { } #[pyclass] -struct EmptyClassInModule { } +struct EmptyClassInModule {} #[test] fn empty_class_in_module() { @@ -62,6 +66,15 @@ fn empty_class_in_module() { module.add_class::().unwrap(); let ty = module.getattr("EmptyClassInModule").unwrap(); - assert_eq!(ty.getattr("__name__").unwrap().extract::().unwrap(), "EmptyClassInModule"); - assert_eq!(ty.getattr("__module__").unwrap().extract::().unwrap(), "test_module.nested"); + assert_eq!( + ty.getattr("__name__").unwrap().extract::().unwrap(), + "EmptyClassInModule" + ); + assert_eq!( + ty.getattr("__module__") + .unwrap() + .extract::() + .unwrap(), + "test_module.nested" + ); } diff --git a/tests/test_class_new.rs b/tests/test_class_new.rs index 8fa81f7fb5a..b4538cb7063 100644 --- a/tests/test_class_new.rs +++ b/tests/test_class_new.rs @@ -9,14 +9,14 @@ use pyo3::py::methods as pymethods; #[pyclass] struct EmptyClassWithNew { - token: PyToken + token: PyToken, } #[pymethods] impl EmptyClassWithNew { #[__new__] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|t| EmptyClassWithNew{token: t}) + obj.init(|t| EmptyClassWithNew { token: t }) } } @@ -25,20 +25,27 @@ fn empty_class_with_new() { let gil = Python::acquire_gil(); let py = gil.python(); let typeobj = py.get_type::(); - assert!(typeobj.call(NoArgs, NoArgs).unwrap().cast_as::().is_ok()); + assert!(typeobj + .call(NoArgs, NoArgs) + .unwrap() + .cast_as::() + .is_ok()); } #[pyclass] struct NewWithOneArg { _data: i32, - token: PyToken + token: PyToken, } #[pymethods] impl NewWithOneArg { #[new] fn __new__(obj: &PyRawObject, arg: i32) -> PyResult<()> { - obj.init(|t| NewWithOneArg{_data: arg, token: t}) + obj.init(|t| NewWithOneArg { + _data: arg, + token: t, + }) } } @@ -57,15 +64,18 @@ struct NewWithTwoArgs { _data1: i32, _data2: i32, - token: PyToken + token: PyToken, } #[pymethods] impl NewWithTwoArgs { #[new] - fn __new__(obj: &PyRawObject, arg1: i32, arg2: i32) -> PyResult<()> - { - obj.init(|t| NewWithTwoArgs{_data1: arg1, _data2: arg2, token: t}) + fn __new__(obj: &PyRawObject, arg1: i32, arg2: i32) -> PyResult<()> { + obj.init(|t| NewWithTwoArgs { + _data1: arg1, + _data2: arg2, + token: t, + }) } } @@ -74,8 +84,11 @@ fn new_with_two_args() { let gil = Python::acquire_gil(); let py = gil.python(); let typeobj = py.get_type::(); - let wrp = typeobj.call((10, 20), NoArgs).map_err(|e| e.print(py)).unwrap(); + let wrp = typeobj + .call((10, 20), NoArgs) + .map_err(|e| e.print(py)) + .unwrap(); let obj = wrp.cast_as::().unwrap(); assert_eq!(obj._data1, 10); assert_eq!(obj._data2, 20); -} \ No newline at end of file +} diff --git a/tests/test_doc.rs b/tests/test_doc.rs index 6290af52636..a2e0ab77ff3 100644 --- a/tests/test_doc.rs +++ b/tests/test_doc.rs @@ -1,12 +1,16 @@ extern crate docmatic; -use std::path::{Path, PathBuf}; use std::default::Default; +use std::path::{Path, PathBuf}; fn assert_file>(path: P) { let mut doc = docmatic::Assert::default(); if cfg!(windows) { - doc.library_path(option_env!("PYTHON").map(|py| PathBuf::from(py).join("libs")).unwrap()); + doc.library_path( + option_env!("PYTHON") + .map(|py| PathBuf::from(py).join("libs")) + .unwrap(), + ); } doc.test_file(path.as_ref()) } diff --git a/tests/test_gc.rs b/tests/test_gc.rs index e0ca25532ff..9076ecb0f9a 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -2,11 +2,11 @@ extern crate pyo3; +use pyo3::ffi; use pyo3::prelude::*; -use std::sync::Arc; use std::cell::RefCell; use std::sync::atomic::{AtomicBool, Ordering}; -use pyo3::ffi; +use std::sync::Arc; use pyo3::py::class as pyclass; use pyo3::py::methods as pymethods; @@ -15,9 +15,10 @@ use pyo3::py::proto as pyproto; #[macro_use] mod common; - -#[pyclass(freelist=2)] -struct ClassWithFreelist{token: PyToken} +#[pyclass(freelist = 2)] +struct ClassWithFreelist { + token: PyToken, +} #[test] fn class_with_freelist() { @@ -26,8 +27,8 @@ fn class_with_freelist() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new(py, |t| ClassWithFreelist{token: t}).unwrap(); - let _inst2 = Py::new(py, |t| ClassWithFreelist{token: t}).unwrap(); + let inst = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap(); + let _inst2 = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap(); ptr = inst.as_ptr(); drop(inst); } @@ -36,16 +37,16 @@ fn class_with_freelist() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst3 = Py::new(py, |t| ClassWithFreelist{token: t}).unwrap(); + let inst3 = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap(); assert_eq!(ptr, inst3.as_ptr()); - let inst4 = Py::new(py, |t| ClassWithFreelist{token: t}).unwrap(); + let inst4 = Py::new(py, |t| ClassWithFreelist { token: t }).unwrap(); assert_ne!(ptr, inst4.as_ptr()) } } struct TestDropCall { - drop_called: Arc + drop_called: Arc, } impl Drop for TestDropCall { fn drop(&mut self) { @@ -69,11 +70,17 @@ fn data_is_dropped() { { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = py.init(|t| DataIsDropped{ - member1: TestDropCall { drop_called: Arc::clone(&drop_called1) }, - member2: TestDropCall { drop_called: Arc::clone(&drop_called2) }, - token: t - }).unwrap(); + let inst = py + .init(|t| DataIsDropped { + member1: TestDropCall { + drop_called: Arc::clone(&drop_called1), + }, + member2: TestDropCall { + drop_called: Arc::clone(&drop_called2), + }, + token: t, + }) + .unwrap(); assert!(!drop_called1.load(Ordering::Relaxed)); assert!(!drop_called2.load(Ordering::Relaxed)); drop(inst); @@ -112,20 +119,20 @@ fn create_pointers_in_drop() { let empty = PyTuple::empty(py); ptr = empty.as_ptr(); cnt = empty.get_refcnt() - 1; - let inst = py.init(|t| ClassWithDrop{token: t}).unwrap(); + let inst = py.init(|t| ClassWithDrop { token: t }).unwrap(); drop(inst); } // empty1 and empty2 are still alive (stored in pointers list) { let _gil = Python::acquire_gil(); - assert_eq!(cnt + 2, unsafe {ffi::Py_REFCNT(ptr)}); + assert_eq!(cnt + 2, unsafe { ffi::Py_REFCNT(ptr) }); } // empty1 and empty2 should be released { let _gil = Python::acquire_gil(); - assert_eq!(cnt, unsafe {ffi::Py_REFCNT(ptr)}); + assert_eq!(cnt, unsafe { ffi::Py_REFCNT(ptr) }); } } @@ -155,10 +162,14 @@ fn gc_integration() { { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new_ref(py, |t| GCIntegration{ + let inst = Py::new_ref(py, |t| GCIntegration { self_ref: RefCell::new(py.None()), - dropped: TestDropCall { drop_called: Arc::clone(&drop_called) }, - token: t}).unwrap(); + dropped: TestDropCall { + drop_called: Arc::clone(&drop_called), + }, + token: t, + }) + .unwrap(); *inst.self_ref.borrow_mut() = inst.into(); } @@ -177,7 +188,7 @@ struct GCIntegration2 { fn gc_integration2() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new_ref(py, |t| GCIntegration2{token: t}).unwrap(); + let inst = Py::new_ref(py, |t| GCIntegration2 { token: t }).unwrap(); py_run!(py, inst, "import gc; assert inst in gc.get_objects()"); } @@ -189,8 +200,12 @@ struct WeakRefSupport { fn weakref_support() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new_ref(py, |t| WeakRefSupport{token: t}).unwrap(); - py_run!(py, inst, "import weakref; assert weakref.ref(inst)() is inst"); + let inst = Py::new_ref(py, |t| WeakRefSupport { token: t }).unwrap(); + py_run!( + py, + inst, + "import weakref; assert weakref.ref(inst)() is inst" + ); } #[pyclass] @@ -203,7 +218,10 @@ struct BaseClassWithDrop { impl BaseClassWithDrop { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|t| BaseClassWithDrop{token: t, data: None}) + obj.init(|t| BaseClassWithDrop { + token: t, + data: None, + }) } } @@ -225,7 +243,10 @@ struct SubClassWithDrop { impl SubClassWithDrop { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|t| SubClassWithDrop{token: t, data: None})?; + obj.init(|t| SubClassWithDrop { + token: t, + data: None, + })?; BaseClassWithDrop::__new__(obj) } } diff --git a/tests/test_getter_setter.rs b/tests/test_getter_setter.rs index b7dfa874f71..5c145471d7b 100644 --- a/tests/test_getter_setter.rs +++ b/tests/test_getter_setter.rs @@ -11,7 +11,6 @@ use pyo3::py::methods as pymethods; #[macro_use] mod common; - #[pyclass] struct ClassWithProperties { num: i32, @@ -20,7 +19,6 @@ struct ClassWithProperties { #[pymethods] impl ClassWithProperties { - fn get_num(&self) -> PyResult { Ok(self.num) } @@ -41,7 +39,9 @@ fn class_with_properties() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = py.init(|t| ClassWithProperties{num: 10, token: t}).unwrap(); + let inst = py + .init(|t| ClassWithProperties { num: 10, token: t }) + .unwrap(); py_run!(py, inst, "assert inst.get_num() == 10"); py_run!(py, inst, "assert inst.get_num() == inst.DATA"); @@ -54,12 +54,11 @@ fn class_with_properties() { struct GetterSetter { #[prop(get, set)] num: i32, - token: PyToken + token: PyToken, } #[pymethods] impl GetterSetter { - fn get_num2(&self) -> PyResult { Ok(self.num) } @@ -70,7 +69,7 @@ fn getter_setter_autogen() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = py.init(|t| GetterSetter{num: 10, token: t}).unwrap(); + let inst = py.init(|t| GetterSetter { num: 10, token: t }).unwrap(); py_run!(py, inst, "assert inst.num == 10"); py_run!(py, inst, "inst.num = 20; assert inst.num == 20"); diff --git a/tests/test_inheritance.rs b/tests/test_inheritance.rs index 9b27c77c829..c9af3373d92 100644 --- a/tests/test_inheritance.rs +++ b/tests/test_inheritance.rs @@ -11,14 +11,12 @@ use pyo3::py::methods as pymethods; #[macro_use] mod common; - #[pyclass] struct BaseClass { #[prop(get)] val1: usize, } - #[pyclass(subclass)] struct SubclassAble {} @@ -28,17 +26,22 @@ fn subclass() { let py = gil.python(); let d = PyDict::new(py); - d.set_item("SubclassAble", py.get_type::()).unwrap(); - py.run("class A(SubclassAble): pass\nassert issubclass(A, SubclassAble)", None, Some(d)) - .map_err(|e| e.print(py)) - .unwrap(); + d.set_item("SubclassAble", py.get_type::()) + .unwrap(); + py.run( + "class A(SubclassAble): pass\nassert issubclass(A, SubclassAble)", + None, + Some(d), + ) + .map_err(|e| e.print(py)) + .unwrap(); } #[pymethods] impl BaseClass { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|_| BaseClass{val1: 10}) + obj.init(|_| BaseClass { val1: 10 }) } } @@ -52,7 +55,7 @@ struct SubClass { impl SubClass { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|_| SubClass{val2: 5})?; + obj.init(|_| SubClass { val2: 5 })?; BaseClass::__new__(obj) } } @@ -65,4 +68,4 @@ fn inheritance_with_new_methods() { let typeobj = py.get_type::(); let inst = typeobj.call(NoArgs, NoArgs).unwrap(); py_run!(py, inst, "assert inst.val1 == 10; assert inst.val2 == 5"); -} \ No newline at end of file +} diff --git a/tests/test_methods.rs b/tests/test_methods.rs index e65ba47cc68..2cf615ca3c7 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -13,7 +13,7 @@ mod common; #[pyclass] struct InstanceMethod { member: i32, - token: PyToken + token: PyToken, } #[pymethods] @@ -29,18 +29,24 @@ fn instance_method() { let gil = Python::acquire_gil(); let py = gil.python(); - let obj = py.init_ref(|t| InstanceMethod{member: 42, token: t}).unwrap(); + let obj = py + .init_ref(|t| InstanceMethod { + member: 42, + token: t, + }) + .unwrap(); assert!(obj.method().unwrap() == 42); let d = PyDict::new(py); d.set_item("obj", obj).unwrap(); py.run("assert obj.method() == 42", None, Some(d)).unwrap(); - py.run("assert obj.method.__doc__ == 'Test method'", None, Some(d)).unwrap(); + py.run("assert obj.method.__doc__ == 'Test method'", None, Some(d)) + .unwrap(); } #[pyclass] struct InstanceMethodWithArgs { member: i32, - token: PyToken + token: PyToken, } #[pymethods] @@ -55,23 +61,30 @@ fn instance_method_with_args() { let gil = Python::acquire_gil(); let py = gil.python(); - let obj = py.init_ref(|t| InstanceMethodWithArgs{member: 7, token: t}).unwrap(); + let obj = py + .init_ref(|t| InstanceMethodWithArgs { + member: 7, + token: t, + }) + .unwrap(); assert!(obj.method(6).unwrap() == 42); let d = PyDict::new(py); d.set_item("obj", obj).unwrap(); py.run("assert obj.method(3) == 21", None, Some(d)).unwrap(); - py.run("assert obj.method(multiplier=6) == 42", None, Some(d)).unwrap(); + py.run("assert obj.method(multiplier=6) == 42", None, Some(d)) + .unwrap(); } - #[pyclass] -struct ClassMethod {token: PyToken} +struct ClassMethod { + token: PyToken, +} #[pymethods] impl ClassMethod { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|t| ClassMethod{token: t}) + obj.init(|t| ClassMethod { token: t }) } #[classmethod] @@ -87,13 +100,24 @@ fn class_method() { let d = PyDict::new(py); d.set_item("C", py.get_type::()).unwrap(); - py.run("assert C.method() == 'ClassMethod.method()!'", None, Some(d)).unwrap(); - py.run("assert C().method() == 'ClassMethod.method()!'", None, Some(d)).unwrap(); + py.run( + "assert C.method() == 'ClassMethod.method()!'", + None, + Some(d), + ) + .unwrap(); + py.run( + "assert C().method() == 'ClassMethod.method()!'", + None, + Some(d), + ) + .unwrap(); } - #[pyclass] -struct ClassMethodWithArgs{token: PyToken} +struct ClassMethodWithArgs { + token: PyToken, +} #[pymethods] impl ClassMethodWithArgs { @@ -109,20 +133,26 @@ fn class_method_with_args() { let py = gil.python(); let d = PyDict::new(py); - d.set_item("C", py.get_type::()).unwrap(); - py.run("assert C.method('abc') == 'ClassMethodWithArgs.method(abc)'", None, Some(d)).unwrap(); + d.set_item("C", py.get_type::()) + .unwrap(); + py.run( + "assert C.method('abc') == 'ClassMethodWithArgs.method(abc)'", + None, + Some(d), + ) + .unwrap(); } #[pyclass] struct StaticMethod { - token: PyToken + token: PyToken, } #[pymethods] impl StaticMethod { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { - obj.init(|t| StaticMethod{token: t}) + obj.init(|t| StaticMethod { token: t }) } #[staticmethod] @@ -139,16 +169,27 @@ fn static_method() { assert_eq!(StaticMethod::method(py).unwrap(), "StaticMethod.method()!"); let d = PyDict::new(py); d.set_item("C", py.get_type::()).unwrap(); - py.run("assert C.method() == 'StaticMethod.method()!'", None, Some(d)).unwrap(); - py.run("assert C().method() == 'StaticMethod.method()!'", None, Some(d)).unwrap(); + py.run( + "assert C.method() == 'StaticMethod.method()!'", + None, + Some(d), + ) + .unwrap(); + py.run( + "assert C().method() == 'StaticMethod.method()!'", + None, + Some(d), + ) + .unwrap(); } #[pyclass] -struct StaticMethodWithArgs{token: PyToken} +struct StaticMethodWithArgs { + token: PyToken, +} #[pymethods] impl StaticMethodWithArgs { - #[staticmethod] fn method(_py: Python, input: i32) -> PyResult { Ok(format!("0x{:x}", input)) @@ -163,27 +204,28 @@ fn static_method_with_args() { assert_eq!(StaticMethodWithArgs::method(py, 1234).unwrap(), "0x4d2"); let d = PyDict::new(py); - d.set_item("C", py.get_type::()).unwrap(); - py.run("assert C.method(1337) == '0x539'", None, Some(d)).unwrap(); + d.set_item("C", py.get_type::()) + .unwrap(); + py.run("assert C.method(1337) == '0x539'", None, Some(d)) + .unwrap(); } #[pyclass] struct MethArgs { - token: PyToken + token: PyToken, } #[pymethods] impl MethArgs { - - #[args(test="10")] + #[args(test = "10")] fn get_default(&self, test: i32) -> PyResult { Ok(test) } - #[args("*", test=10)] + #[args("*", test = 10)] fn get_kwarg(&self, test: i32) -> PyResult { Ok(test) } - #[args(args="*", kwargs="**")] + #[args(args = "*", kwargs = "**")] fn get_kwargs(&self, args: &PyTuple, kwargs: Option<&PyDict>) -> PyResult { Ok([args.into(), kwargs.to_object(self.py())].to_object(self.py())) } @@ -193,7 +235,7 @@ impl MethArgs { fn meth_args() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = py.init(|t| MethArgs{token: t}).unwrap(); + let inst = py.init(|t| MethArgs { token: t }).unwrap(); py_run!(py, inst, "assert inst.get_default() == 10"); py_run!(py, inst, "assert inst.get_default(100) == 100"); @@ -202,7 +244,15 @@ fn meth_args() { py_run!(py, inst, "assert inst.get_kwarg(test=100) == 100"); py_run!(py, inst, "assert inst.get_kwargs() == [(), None]"); py_run!(py, inst, "assert inst.get_kwargs(1,2,3) == [(1,2,3), None]"); - py_run!(py, inst, "assert inst.get_kwargs(t=1,n=2) == [(), {'t': 1, 'n': 2}]"); - py_run!(py, inst, "assert inst.get_kwargs(1,2,3,t=1,n=2) == [(1,2,3), {'t': 1, 'n': 2}]"); + py_run!( + py, + inst, + "assert inst.get_kwargs(t=1,n=2) == [(), {'t': 1, 'n': 2}]" + ); + py_run!( + py, + inst, + "assert inst.get_kwargs(1,2,3,t=1,n=2) == [(1,2,3), {'t': 1, 'n': 2}]" + ); // py_expect_exception!(py, inst, "inst.get_kwarg(100)", TypeError); -} \ No newline at end of file +} diff --git a/tests/test_module.rs b/tests/test_module.rs index 1542065441d..4b258ed3511 100644 --- a/tests/test_module.rs +++ b/tests/test_module.rs @@ -5,7 +5,6 @@ extern crate pyo3; use pyo3::prelude::*; use pyo3::py::{class, modinit}; - #[class] struct EmptyClass {} @@ -41,10 +40,34 @@ fn test_module_with_functions() { let py = gil.python(); let d = PyDict::new(py); - d.set_item("module_with_functions", unsafe { PyObject::from_owned_ptr(py, PyInit_module_with_functions()) }).unwrap(); - py.run("assert module_with_functions.__doc__.strip() == 'This module is implemented in Rust.'", None, Some(d)).unwrap(); - py.run("assert module_with_functions.sum_as_string(1, 2) == '3'", None, Some(d)).unwrap(); - py.run("assert module_with_functions.no_parameters() == 42", None, Some(d)).unwrap(); - py.run("assert module_with_functions.foo == 'bar'", None, Some(d)).unwrap(); - py.run("assert module_with_functions.EmptyClass != None", None, Some(d)).unwrap(); + d.set_item("module_with_functions", unsafe { + PyObject::from_owned_ptr(py, PyInit_module_with_functions()) + }) + .unwrap(); + py.run( + "assert module_with_functions.__doc__.strip() == 'This module is implemented in Rust.'", + None, + Some(d), + ) + .unwrap(); + py.run( + "assert module_with_functions.sum_as_string(1, 2) == '3'", + None, + Some(d), + ) + .unwrap(); + py.run( + "assert module_with_functions.no_parameters() == 42", + None, + Some(d), + ) + .unwrap(); + py.run("assert module_with_functions.foo == 'bar'", None, Some(d)) + .unwrap(); + py.run( + "assert module_with_functions.EmptyClass != None", + None, + Some(d), + ) + .unwrap(); } diff --git a/tests/test_underscore_methods.rs b/tests/test_underscore_methods.rs index e93d7a95b01..f1233e076af 100644 --- a/tests/test_underscore_methods.rs +++ b/tests/test_underscore_methods.rs @@ -2,19 +2,17 @@ extern crate pyo3; +use pyo3::ffi; use pyo3::prelude::*; use std::{isize, iter}; -use pyo3::ffi; use pyo3::py::class as pyclass; use pyo3::py::methods as pymethods; use pyo3::py::proto as pyproto; - #[macro_use] mod common; - #[pyclass] pub struct Len { l: usize, @@ -33,20 +31,24 @@ fn len() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new(py, |t| Len{l: 10, token: t}).unwrap(); + let inst = Py::new(py, |t| Len { l: 10, token: t }).unwrap(); py_assert!(py, inst, "len(inst) == 10"); unsafe { assert_eq!(ffi::PyObject_Size(inst.as_ptr()), 10); assert_eq!(ffi::PyMapping_Size(inst.as_ptr()), 10); } - let inst = Py::new(py, |t| Len{l: (isize::MAX as usize) + 1, token: t}).unwrap(); + let inst = Py::new(py, |t| Len { + l: (isize::MAX as usize) + 1, + token: t, + }) + .unwrap(); py_expect_exception!(py, inst, "len(inst)", OverflowError); } #[pyclass] -struct Iterator{ - iter: Box + Send>, +struct Iterator { + iter: Box + Send>, token: PyToken, } @@ -66,13 +68,19 @@ fn iterator() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new(py, |t| Iterator{iter: Box::new(5..8), token: t}).unwrap(); + let inst = Py::new(py, |t| Iterator { + iter: Box::new(5..8), + token: t, + }) + .unwrap(); py_assert!(py, inst, "iter(inst) is inst"); py_assert!(py, inst, "list(inst) == [5, 6, 7]"); } #[pyclass] -struct StringMethods {token: PyToken} +struct StringMethods { + token: PyToken, +} #[pyproto] impl<'p> PyObjectProtocol<'p> for StringMethods { @@ -103,7 +111,7 @@ fn string_methods() { let gil = Python::acquire_gil(); let py = gil.python(); - let obj = Py::new(py, |t| StringMethods{token: t}).unwrap(); + let obj = Py::new(py, |t| StringMethods { token: t }).unwrap(); py_assert!(py, obj, "str(obj) == 'str'"); py_assert!(py, obj, "repr(obj) == 'repr'"); py_assert!(py, obj, "'{0:x}'.format(obj) == 'format(x)'"); @@ -116,14 +124,13 @@ fn string_methods() { let gil = Python::acquire_gil(); let py = gil.python(); - let obj = Py::new(py, |t| StringMethods{token: t}).unwrap(); + let obj = Py::new(py, |t| StringMethods { token: t }).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, @@ -140,16 +147,15 @@ impl PyObjectProtocol for Comparisons { } } - #[test] fn comparisons() { let gil = Python::acquire_gil(); let py = gil.python(); - let zero = Py::new(py, |t| Comparisons{val: 0, token: t}).unwrap(); - let one = Py::new(py, |t| Comparisons{val: 1, token: t}).unwrap(); - let ten = Py::new(py, |t| Comparisons{val: 10, token: t}).unwrap(); - let minus_one = Py::new(py, |t| Comparisons{val: -1, token: t}).unwrap(); + let zero = Py::new(py, |t| Comparisons { val: 0, token: t }).unwrap(); + let one = Py::new(py, |t| Comparisons { val: 1, token: t }).unwrap(); + let ten = Py::new(py, |t| Comparisons { val: 10, token: t }).unwrap(); + let minus_one = Py::new(py, |t| Comparisons { val: -1, token: t }).unwrap(); py_assert!(py, one, "hash(one) == 1"); py_assert!(py, ten, "hash(ten) == 10"); py_assert!(py, minus_one, "hash(minus_one) == -2"); @@ -158,10 +164,9 @@ fn comparisons() { py_assert!(py, zero, "not zero"); } - #[pyclass] struct Sequence { - token: PyToken + token: PyToken, } #[pyproto] @@ -183,18 +188,18 @@ fn sequence() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| Sequence{token: t}).unwrap(); + let c = py.init(|t| Sequence { token: t }).unwrap(); py_assert!(py, c, "list(c) == [0, 1, 2, 3, 4]"); py_expect_exception!(py, c, "c['abc']", TypeError); } - #[pyclass] -struct Callable {token: PyToken} +struct Callable { + token: PyToken, +} #[pymethods] impl Callable { - #[__call__] fn __call__(&self, arg: i32) -> PyResult { Ok(arg * 6) @@ -206,11 +211,11 @@ fn callable() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| Callable{token: t}).unwrap(); + let c = py.init(|t| Callable { token: t }).unwrap(); py_assert!(py, c, "callable(c)"); py_assert!(py, c, "c(7) == 42"); - let nc = py.init(|t| Comparisons{val: 0, token: t}).unwrap(); + let nc = py.init(|t| Comparisons { val: 0, token: t }).unwrap(); py_assert!(py, nc, "not callable(nc)"); } @@ -235,7 +240,13 @@ fn setitem() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init_ref(|t| SetItem{key: 0, val: 0, token: t}).unwrap(); + let c = py + .init_ref(|t| SetItem { + key: 0, + val: 0, + token: t, + }) + .unwrap(); py_run!(py, c, "c[1] = 2"); assert_eq!(c.key, 1); assert_eq!(c.val, 2); @@ -261,7 +272,7 @@ fn delitem() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init_ref(|t| DelItem{key:0, token:t}).unwrap(); + let c = py.init_ref(|t| DelItem { key: 0, token: t }).unwrap(); py_run!(py, c, "del c[1]"); assert_eq!(c.key, 1); py_expect_exception!(py, c, "c[1] = 2", NotImplementedError); @@ -291,7 +302,12 @@ fn setdelitem() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init_ref(|t| SetDelItem{val: None, token: t}).unwrap(); + let c = py + .init_ref(|t| SetDelItem { + val: None, + token: t, + }) + .unwrap(); py_run!(py, c, "c[1] = 2"); assert_eq!(c.val, Some(2)); py_run!(py, c, "del c[1]"); @@ -299,10 +315,12 @@ fn setdelitem() { } #[pyclass] -struct Reversed {token: PyToken} +struct Reversed { + token: PyToken, +} #[pyproto] -impl PyMappingProtocol for Reversed{ +impl PyMappingProtocol for Reversed { fn __reversed__(&self) -> PyResult<&'static str> { Ok("I am reversed") } @@ -313,12 +331,14 @@ fn reversed() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| Reversed{token: t}).unwrap(); + let c = py.init(|t| Reversed { token: t }).unwrap(); py_run!(py, c, "assert reversed(c) == 'I am reversed'"); } #[pyclass] -struct Contains {token: PyToken} +struct Contains { + token: PyToken, +} #[pyproto] impl PySequenceProtocol for Contains { @@ -332,13 +352,12 @@ fn contains() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init(|t| Contains{token: t}).unwrap(); + let c = py.init(|t| Contains { token: t }).unwrap(); py_run!(py, c, "assert 1 in c"); py_run!(py, c, "assert -1 not in c"); py_expect_exception!(py, c, "assert 'wrong type' not in c", TypeError); } - #[pyclass] struct ContextManager { exit_called: bool, @@ -347,15 +366,16 @@ struct ContextManager { #[pyproto] impl<'p> PyContextProtocol<'p> for ContextManager { - fn __enter__(&mut self) -> PyResult { Ok(42) } - fn __exit__(&mut self, - ty: Option<&'p PyType>, - _value: Option<&'p PyObjectRef>, - _traceback: Option<&'p PyObjectRef>) -> PyResult { + fn __exit__( + &mut self, + ty: Option<&'p PyType>, + _value: Option<&'p PyObjectRef>, + _traceback: Option<&'p PyObjectRef>, + ) -> PyResult { self.exit_called = true; if ty == Some(self.py().get_type::()) { Ok(true) @@ -370,7 +390,12 @@ fn context_manager() { let gil = Python::acquire_gil(); let py = gil.python(); - let c = py.init_mut(|t| ContextManager{exit_called: false, token: t}).unwrap(); + let c = py + .init_mut(|t| ContextManager { + exit_called: false, + token: t, + }) + .unwrap(); py_run!(py, c, "with c as x:\n assert x == 42"); assert!(c.exit_called); @@ -380,11 +405,14 @@ fn context_manager() { c.exit_called = false; py_expect_exception!( - py, c, "with c as x:\n raise NotImplementedError", NotImplementedError); + py, + c, + "with c as x:\n raise NotImplementedError", + NotImplementedError + ); assert!(c.exit_called); } - #[test] fn test_basics() { let gil = Python::acquire_gil(); @@ -400,22 +428,20 @@ fn test_basics() { #[pyclass] struct Test { - token: PyToken + token: PyToken, } #[pyproto] -impl<'p> PyMappingProtocol<'p> for Test -{ +impl<'p> PyMappingProtocol<'p> for Test { fn __getitem__(&self, idx: &PyObjectRef) -> PyResult { if let Ok(slice) = idx.cast_as::() { let indices = slice.indices(1000)?; if indices.start == 100 && indices.stop == 200 && indices.step == 1 { - return Ok("slice".into_object(self.py())) + return Ok("slice".into_object(self.py())); } - } - else if let Ok(idx) = idx.extract::() { + } else if let Ok(idx) = idx.extract::() { if idx == 1 { - return Ok("int".into_object(self.py())) + return Ok("int".into_object(self.py())); } } Err(PyErr::new::("error")) @@ -427,10 +453,11 @@ fn test_cls_impl() { let gil = Python::acquire_gil(); let py = gil.python(); - let ob = py.init(|t| Test{token: t}).unwrap(); + let ob = py.init(|t| Test { token: t }).unwrap(); let d = PyDict::new(py); d.set_item("ob", ob).unwrap(); py.run("assert ob[1] == 'int'", None, Some(d)).unwrap(); - py.run("assert ob[100:200:1] == 'slice'", None, Some(d)).unwrap(); + py.run("assert ob[100:200:1] == 'slice'", None, Some(d)) + .unwrap(); } diff --git a/tests/test_various.rs b/tests/test_various.rs index 0539d0844a5..8dbedfd476a 100644 --- a/tests/test_various.rs +++ b/tests/test_various.rs @@ -11,7 +11,6 @@ use pyo3::py::methods as pymethods; #[macro_use] mod common; - #[pyclass(dict)] struct DunderDictSupport { token: PyToken, @@ -21,7 +20,7 @@ struct DunderDictSupport { fn dunder_dict_support() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new_ref(py, |t| DunderDictSupport{token: t}).unwrap(); + let inst = Py::new_ref(py, |t| DunderDictSupport { token: t }).unwrap(); py_run!(py, inst, "inst.a = 1; assert inst.a == 1"); } @@ -34,11 +33,14 @@ struct WeakRefDunderDictSupport { fn weakref_dunder_dict_support() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst = Py::new_ref(py, |t| WeakRefDunderDictSupport{token: t}).unwrap(); - py_run!(py, inst, "import weakref; assert weakref.ref(inst)() is inst; inst.a = 1; assert inst.a == 1"); + let inst = Py::new_ref(py, |t| WeakRefDunderDictSupport { token: t }).unwrap(); + py_run!( + py, + inst, + "import weakref; assert weakref.ref(inst)() is inst; inst.a = 1; assert inst.a == 1" + ); } - #[pyclass] struct MutRefArg { n: i32, @@ -47,7 +49,6 @@ struct MutRefArg { #[pymethods] impl MutRefArg { - fn get(&self) -> PyResult { Ok(self.n) } @@ -61,8 +62,8 @@ impl MutRefArg { fn mut_ref_arg() { let gil = Python::acquire_gil(); let py = gil.python(); - let inst1 = py.init(|t| MutRefArg{token: t, n: 0}).unwrap(); - let inst2 = py.init(|t| MutRefArg{token: t, n: 0}).unwrap(); + let inst1 = py.init(|t| MutRefArg { token: t, n: 0 }).unwrap(); + let inst2 = py.init(|t| MutRefArg { token: t, n: 0 }).unwrap(); let d = PyDict::new(py); d.set_item("inst1", &inst1).unwrap(); From 26e964bff0ad6d0ddfa3e50d43d5d51e2449b234 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 28 Dec 2018 16:03:51 +0200 Subject: [PATCH 040/138] small merge fixes --- Cargo.toml | 6 +- build.rs | 485 +-------------------------------------------- src/class/basic.rs | 89 ++++----- src/ffi3/object.rs | 3 +- 4 files changed, 57 insertions(+), 526 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a18282d6e94..256309a6963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,17 +27,15 @@ num-complex = { version = "0.2.1", optional = true } mashup = "0.1.9" [build-dependencies] -regex = "0.2" -version_check = "0.1" +version_check = "0.1.5" pretty_assertions = "0.5.1" pyo3-build-utils = {version = "*", path="pyo3build"} regex = "1.0.5" -version_check = "0.1.5" + [dev-dependencies] pretty_assertions = "0.5.1" docmatic = "^0.1.2" assert_approx_eq = "1.0.0" -docmatic = "0.1.2" indoc = "0.3.1" [features] diff --git a/build.rs b/build.rs index 5abeb85eda1..4bd4f7fe0d6 100644 --- a/build.rs +++ b/build.rs @@ -1,469 +1,12 @@ extern crate pyo3_build_utils; -use regex::Regex; -use std::collections::HashMap; -use std::env; -use std::fmt; -use std::process::Command; -use std::process::Stdio; -use version_check::{is_min_date, is_min_version, supports_features}; - -// Specifies the minimum nightly version needed to compile pyo3. -// This requirement is due to https://github.com/rust-lang/rust/issues/55380 -const MIN_DATE: &'static str = "2018-11-02"; -const MIN_VERSION: &'static str = "1.32.0-nightly"; - -#[derive(Debug)] -struct PythonVersion { - major: u8, - // minor == None means any minor version will do - minor: Option, -} - -impl PartialEq for PythonVersion { - fn eq(&self, o: &PythonVersion) -> bool { - self.major == o.major && (self.minor.is_none() || self.minor == o.minor) - } -} - -impl fmt::Display for PythonVersion { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - self.major.fmt(f)?; - f.write_str(".")?; - match self.minor { - Some(minor) => minor.fmt(f)?, - None => f.write_str("*")?, - }; - Ok(()) - } -} - -const PY3_MIN_MINOR: u8 = 5; - -const CFG_KEY: &'static str = "py_sys_config"; - -/// A list of python interpreter compile-time preprocessor defines that -/// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; -/// this allows using them conditional cfg attributes in the .rs files, so -/// -/// #[cfg(py_sys_config="{varname}"] -/// -/// is the equivalent of #ifdef {varname} name in C. -/// -/// see Misc/SpecialBuilds.txt in the python source for what these mean. -/// -/// (hrm, this is sort of re-implementing what distutils does, except -/// by passing command line args instead of referring to a python.h) -#[cfg(not(target_os = "windows"))] -static SYSCONFIG_FLAGS: [&'static str; 7] = [ - "Py_USING_UNICODE", - "Py_UNICODE_WIDE", - "WITH_THREAD", - "Py_DEBUG", - "Py_REF_DEBUG", - "Py_TRACE_REFS", - "COUNT_ALLOCS", -]; - -static SYSCONFIG_VALUES: [&'static str; 1] = [ - // cfg doesn't support flags with values, just bools - so flags - // below are translated into bools as {varname}_{val} - // - // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 - "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide -]; - -/// Examine python's compile flags to pass to cfg by launching -/// the interpreter and printing variables of interest from -/// sysconfig.get_config_vars. -#[cfg(not(target_os = "windows"))] -fn get_config_vars(python_path: &String) -> Result, String> { - // FIXME: We can do much better here using serde: - // import json, sysconfig; print(json.dumps({k:str(v) for k, v in sysconfig.get_config_vars().items()})) - - let mut script = "import sysconfig; \ - config = sysconfig.get_config_vars();" - .to_owned(); - - for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!( - "print(config.get('{}', {}));", - k, - if is_value(k) { "None" } else { "0" } - )); - } - - let stdout = run_python_script(python_path, &script)?; - let split_stdout: Vec<&str> = stdout.trim_end().lines().collect(); - if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { - return Err(format!( - "python stdout len didn't return expected number of lines: {}", - split_stdout.len() - )); - } - let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); - let mut all_vars = all_vars.zip(split_stdout.iter()).fold( - HashMap::new(), - |mut memo: HashMap, (&k, &v)| { - if !(v.to_owned() == "None" && is_value(k)) { - memo.insert(k.to_owned(), v.to_owned()); - } - memo - }, - ); - - let debug = Some(&"1".to_string()) == all_vars.get("Py_DEBUG"); - if debug { - all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); - } - - Ok(all_vars) -} - -#[cfg(target_os = "windows")] -fn get_config_vars(_: &String) -> Result, String> { - // sysconfig is missing all the flags on windows, so we can't actually - // query the interpreter directly for its build flags. - // - // For the time being, this is the flags as defined in the python source's - // PC\pyconfig.h. This won't work correctly if someone has built their - // python with a modified pyconfig.h - sorry if that is you, you will have - // to comment/uncomment the lines below. - let mut map: HashMap = HashMap::new(); - map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); - map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); - - // This is defined #ifdef _DEBUG. The visual studio build seems to produce - // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the - // Debug configuration, which this script doesn't currently support anyway. - // map.insert("Py_DEBUG", "1"); - - // Uncomment these manually if your python was built with these and you want - // the cfg flags to be set in rust. - // - // map.insert("Py_REF_DEBUG", "1"); - // map.insert("Py_TRACE_REFS", "1"); - // map.insert("COUNT_ALLOCS", 1"); - Ok(map) -} - -fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() -} - -fn cfg_line_for_var(key: &str, val: &str) -> Option { - if is_value(key) { - // is a value; suffix the key name with the value - Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) - } else if val != "0" { - // is a flag that isn't zero - Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) - } else { - // is a flag that is zero - None - } -} - -/// Run a python script using the specified interpreter binary. -fn run_python_script(interpreter: &str, script: &str) -> Result { - let out = Command::new(interpreter) - .args(&["-c", script]) - .stderr(Stdio::inherit()) - .output() - .map_err(|e| { - format!( - "Failed to run the python interpreter at {}: {}", - interpreter, e - ) - })?; - - if !out.status.success() { - return Err(format!("python script failed")); - } - - Ok(String::from_utf8(out.stdout).unwrap()) -} - -#[cfg(not(target_os = "macos"))] -#[cfg(not(target_os = "windows"))] -fn get_rustc_link_lib( - _: &PythonVersion, - ld_version: &str, - enable_shared: bool, -) -> Result { - if enable_shared { - Ok(format!("cargo:rustc-link-lib=python{}", ld_version)) - } else { - Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) - } -} - -#[cfg(target_os = "macos")] -fn get_macos_linkmodel() -> Result { - let script = r#" -import sysconfig - -if sysconfig.get_config_var("PYTHONFRAMEWORK"): - print("framework") -elif sysconfig.get_config_var("Py_ENABLE_SHARED"): - print("shared") -else: - print("static") -"#; - let out = run_python_script("python", script).unwrap(); - Ok(out.trim_end().to_owned()) -} - -#[cfg(target_os = "macos")] -fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, _: bool) -> Result { - // os x can be linked to a framework or static or dynamic, and - // Py_ENABLE_SHARED is wrong; framework means shared library - match get_macos_linkmodel().unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - other => Err(format!("unknown linkmodel {}", other)), - } -} - -/// Parse string as interpreter version. -fn get_interpreter_version(line: &str) -> Result { - let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); - match version_re.captures(&line) { - Some(cap) => Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), - }), - None => Err(format!("Unexpected response to version query {}", line)), - } -} - -#[cfg(target_os = "windows")] -fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result { - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!( - "cargo:rustc-link-lib=pythonXY:python{}{}", - version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned(), - } - )) -} - -/// Locate a suitable python interpreter and extract config from it. -/// -/// The following locations are checked in the order listed: -/// -/// 1. If `PYTHON_SYS_EXECUTABLE` is set, this intepreter is used and an error is raised if the -/// version doesn't match. -/// 2. `python` -/// 3. `python{major version}` -/// 4. `python{major version}.{minor version}` -/// -/// If none of the above works, an error is returned -fn find_interpreter_and_get_config( - expected_version: &PythonVersion, -) -> Result<(PythonVersion, String, Vec), String> { - if let Some(sys_executable) = env::var_os("PYTHON_SYS_EXECUTABLE") { - let interpreter_path = sys_executable - .to_str() - .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); - let (interpreter_version, lines) = get_config_from_interpreter(interpreter_path)?; - - if expected_version == &interpreter_version { - return Ok((interpreter_version, interpreter_path.to_owned(), lines)); - } else { - return Err(format!( - "Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ - \tmin version {} != found {}", - interpreter_path, expected_version, interpreter_version - )); - } - } - // check default python - let interpreter_path = "python"; - let (interpreter_version, lines) = get_config_from_interpreter(interpreter_path)?; - if expected_version == &interpreter_version { - return Ok((interpreter_version, interpreter_path.to_owned(), lines)); - } - - let major_interpreter_path = &format!("python{}", expected_version.major); - let (interpreter_version, lines) = get_config_from_interpreter(major_interpreter_path)?; - if expected_version == &interpreter_version { - return Ok(( - interpreter_version, - major_interpreter_path.to_owned(), - lines, - )); - } - - if let Some(minor) = expected_version.minor { - let minor_interpreter_path = &format!("python{}.{}", expected_version.major, minor); - let (interpreter_version, lines) = get_config_from_interpreter(minor_interpreter_path)?; - if expected_version == &interpreter_version { - return Ok(( - interpreter_version, - minor_interpreter_path.to_owned(), - lines, - )); - } - } - - Err(format!("No python interpreter found")) -} - -/// Extract compilation vars from the specified interpreter. -fn get_config_from_interpreter(interpreter: &str) -> Result<(PythonVersion, Vec), String> { - let script = r#" -import sys -import sysconfig - -print(sys.version_info[0:2]) -print(sysconfig.get_config_var('LIBDIR')) -print(sysconfig.get_config_var('Py_ENABLE_SHARED')) -print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')) -print(sys.exec_prefix) -"#; - let out = run_python_script(interpreter, script)?; - let lines: Vec = out.lines().map(|line| line.to_owned()).collect(); - let interpreter_version = get_interpreter_version(&lines[0])?; - Ok((interpreter_version, lines)) -} - -/// Deduce configuration from the 'python' in the current PATH and print -/// cargo vars to stdout. -/// -/// Note that if the python doesn't satisfy expected_version, this will error. -fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, String), String> { - let (interpreter_version, interpreter_path, lines) = - find_interpreter_and_get_config(expected_version)?; - - let libpath: &str = &lines[1]; - let enable_shared: &str = &lines[2]; - let ld_version: &str = &lines[3]; - let exec_prefix: &str = &lines[4]; - - let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - if !is_extension_module || cfg!(target_os = "windows") { - println!( - "{}", - get_rustc_link_lib(&interpreter_version, ld_version, enable_shared == "1").unwrap() - ); - if libpath != "None" { - println!("cargo:rustc-link-search=native={}", libpath); - } else if cfg!(target_os = "windows") { - println!("cargo:rustc-link-search=native={}\\libs", exec_prefix); - } - } - - let mut flags = String::new(); - - if let PythonVersion { - major: 3, - minor: some_minor, - } = interpreter_version - { - if env::var_os("CARGO_FEATURE_ABI3").is_some() { - println!("cargo:rustc-cfg=Py_LIMITED_API"); - } - if let Some(minor) = some_minor { - if minor < PY3_MIN_MINOR { - return Err(format!( - "Python 3 required version is 3.{}, current version is 3.{}", - PY3_MIN_MINOR, minor - )); - } - for i in 5..(minor + 1) { - 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(); - } - return Ok((interpreter_path, flags)); -} - -/// Determine the python version we're supposed to be building -/// from the features passed via the environment. -/// -/// The environment variable can choose to omit a minor -/// version if the user doesn't care. -fn version_from_env() -> Result { - let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); - // sort env::vars so we get more explicit version specifiers first - // so if the user passes e.g. the python-3 feature and the python-3-5 - // feature, python-3-5 takes priority. - let mut vars = env::vars().collect::>(); - vars.sort_by(|a, b| b.cmp(a)); - for (key, _) in vars { - match re.captures(&key) { - Some(cap) => { - return Ok(PythonVersion { - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: match cap.get(3) { - Some(s) => Some(s.as_str().parse().unwrap()), - None => None, - }, - }); - } - None => (), - } - } - - Err( - "Python version feature was not found. At least one python version \ - feature must be enabled." - .to_owned(), - ) -} - -fn check_rustc_version() { - let ok_channel = supports_features(); - let ok_version = is_min_version(MIN_VERSION); - let ok_date = is_min_date(MIN_DATE); - - let print_version_err = |version: &str, date: &str| { - eprintln!( - "Installed version is: {} ({}). Minimum required: {} ({}).", - version, date, MIN_VERSION, MIN_DATE - ); - }; - - match (ok_channel, ok_version, ok_date) { - (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { - if !ok_channel { - eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - - if !ok_version || !ok_date { - eprintln!("Error: pyo3 requires a more recent version of rustc."); - eprintln!("Use `rustup update` or your preferred method to update Rust"); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - } - _ => { - println!( - "cargo:warning={}", - "pyo3 was unable to check rustc compatibility." - ); - println!( - "cargo:warning={}", - "Build may fail due to incompatible rustc version." - ); - } - } -} +use pyo3_build_utils::{ + py_interpreter::{ + cfg_line_for_var, emit_cargo_vars_from_configuration, find_interpreter, get_config_vars, + is_value, version_from_env, InterpreterConfig, PythonVersion, + }, + rustc_version::check_rustc_version, +}; fn main() { check_rustc_version(); @@ -482,6 +25,7 @@ fn main() { Err(_) => PythonVersion { major: 3, minor: None, + kind: None, }, }; @@ -518,8 +62,9 @@ fn main() { // VAL indicates it can take on any value // // rust-cypthon/build.rs contains an example of how to unpack this data - // into cfg flags that replicate the ones present in this library, so + // into cfg flags that replicate theones present in this library, so // you can use the same cfg syntax. + //let mut flags = flags; let flags: String = config_map.iter().fold("".to_owned(), |memo, (key, val)| { if is_value(key) { memo + format!("VAL_{}={},", key, val).as_ref() @@ -538,14 +83,4 @@ fn main() { "" } ); - - if env::var_os("TARGET") == Some("x86_64-apple-darwin".into()) { - // TODO: Find out how we can set -undefined dynamic_lookup here (if this is possible) - } - - let env_vars = ["LD_LIBRARY_PATH", "PATH", "PYTHON_SYS_EXECUTABLE", "LIB"]; - - for var in env_vars.iter() { - println!("cargo:rerun-if-env-changed={}", var); - } } diff --git a/src/class/basic.rs b/src/class/basic.rs index 099b0d5b520..a16de6499f8 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -26,79 +26,79 @@ use crate::CompareOp; #[allow(unused_variables)] pub trait PyObjectProtocol<'p>: PyTypeInfo { fn __getattr__(&'p self, name: Self::Name) -> Self::Result - where - Self: PyObjectGetAttrProtocol<'p>, + where + Self: PyObjectGetAttrProtocol<'p>, { unimplemented!() } fn __setattr__(&'p mut self, name: Self::Name, value: Self::Value) -> Self::Result - where - Self: PyObjectSetAttrProtocol<'p>, + where + Self: PyObjectSetAttrProtocol<'p>, { unimplemented!() } fn __delattr__(&'p mut self, name: Self::Name) -> Self::Result - where - Self: PyObjectDelAttrProtocol<'p>, + where + Self: PyObjectDelAttrProtocol<'p>, { unimplemented!() } fn __str__(&'p self) -> Self::Result - where - Self: PyObjectStrProtocol<'p>, + where + Self: PyObjectStrProtocol<'p>, { unimplemented!() } fn __repr__(&'p self) -> Self::Result - where - Self: PyObjectReprProtocol<'p>, + where + Self: PyObjectReprProtocol<'p>, { unimplemented!() } fn __format__(&'p self, format_spec: Self::Format) -> Self::Result - where - Self: PyObjectFormatProtocol<'p>, + where + Self: PyObjectFormatProtocol<'p>, { unimplemented!() } fn __hash__(&'p self) -> Self::Result - where - Self: PyObjectHashProtocol<'p>, + where + Self: PyObjectHashProtocol<'p>, { unimplemented!() } fn __bool__(&'p self) -> Self::Result - where - Self: PyObjectBoolProtocol<'p>, + where + Self: PyObjectBoolProtocol<'p>, { unimplemented!() } fn __bytes__(&'p self) -> Self::Result - where - Self: PyObjectBytesProtocol<'p>, + where + Self: PyObjectBytesProtocol<'p>, { unimplemented!() } /// This method is used by Python2 only. fn __unicode__(&'p self) -> Self::Result - where - Self: PyObjectUnicodeProtocol<'p>, + where + Self: PyObjectUnicodeProtocol<'p>, { unimplemented!() } fn __richcmp__(&'p self, other: Self::Other, op: CompareOp) -> Self::Result - where - Self: PyObjectRichcmpProtocol<'p>, + where + Self: PyObjectRichcmpProtocol<'p>, { unimplemented!() } @@ -165,8 +165,8 @@ pub trait PyObjectProtocolImpl { impl PyObjectProtocolImpl for T {} impl<'p, T> PyObjectProtocolImpl for T -where - T: PyObjectProtocol<'p>, + where + T: PyObjectProtocol<'p>, { fn methods() -> Vec { let mut methods = Vec::new(); @@ -204,8 +204,8 @@ trait GetAttrProtocolImpl { impl<'p, T> GetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl GetAttrProtocolImpl for T -where - T: for<'p> PyObjectGetAttrProtocol<'p>, + where + T: for<'p> PyObjectGetAttrProtocol<'p>, { fn tp_getattro() -> Option { py_binary_func!( @@ -242,7 +242,6 @@ mod tp_setattro_impl { None } } -} trait SetAttr { fn set_attr() -> Option { @@ -253,8 +252,8 @@ mod tp_setattro_impl { impl<'p, T: PyObjectProtocol<'p>> SetAttr for T {} impl SetAttr for T - where - T: for<'p> PyObjectSetAttrProtocol<'p>, + where + T: for<'p> PyObjectSetAttrProtocol<'p>, { fn set_attr() -> Option { py_func_set!(PyObjectSetAttrProtocol, T, __setattr__) @@ -270,8 +269,8 @@ mod tp_setattro_impl { impl<'p, T> DelAttr for T where T: PyObjectProtocol<'p> {} impl DelAttr for T - where - T: for<'p> PyObjectDelAttrProtocol<'p>, + where + T: for<'p> PyObjectDelAttrProtocol<'p>, { fn del_attr() -> Option { py_func_del!(PyObjectDelAttrProtocol, T, __delattr__) @@ -287,8 +286,8 @@ mod tp_setattro_impl { impl<'p, T> SetDelAttr for T where T: PyObjectProtocol<'p> {} impl SetDelAttr for T - where - T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, + where + T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, { fn set_del_attr() -> Option { py_func_set_del!( @@ -309,8 +308,8 @@ trait StrProtocolImpl { } impl<'p, T> StrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl StrProtocolImpl for T -where - T: for<'p> PyObjectStrProtocol<'p>, + where + T: for<'p> PyObjectStrProtocol<'p>, { fn tp_str() -> Option { py_unary_func!( @@ -329,8 +328,8 @@ trait ReprProtocolImpl { } impl<'p, T> ReprProtocolImpl for T where T: PyObjectProtocol<'p> {} impl ReprProtocolImpl for T -where - T: for<'p> PyObjectReprProtocol<'p>, + where + T: for<'p> PyObjectReprProtocol<'p>, { fn tp_repr() -> Option { py_unary_func!( @@ -373,8 +372,8 @@ trait HashProtocolImpl { } impl<'p, T> HashProtocolImpl for T where T: PyObjectProtocol<'p> {} impl HashProtocolImpl for T -where - T: for<'p> PyObjectHashProtocol<'p>, + where + T: for<'p> PyObjectHashProtocol<'p>, { fn tp_hash() -> Option { py_unary_func!( @@ -394,8 +393,8 @@ trait BoolProtocolImpl { } impl<'p, T> BoolProtocolImpl for T where T: PyObjectProtocol<'p> {} impl BoolProtocolImpl for T -where - T: for<'p> PyObjectBoolProtocol<'p>, + where + T: for<'p> PyObjectBoolProtocol<'p>, { fn nb_bool() -> Option { py_unary_func!( @@ -415,8 +414,8 @@ trait RichcmpProtocolImpl { } impl<'p, T> RichcmpProtocolImpl for T where T: PyObjectProtocol<'p> {} impl RichcmpProtocolImpl for T -where - T: for<'p> PyObjectRichcmpProtocol<'p>, + where + T: for<'p> PyObjectRichcmpProtocol<'p>, { fn tp_richcompare() -> Option { unsafe extern "C" fn wrap( @@ -424,8 +423,8 @@ where arg: *mut ffi::PyObject, op: c_int, ) -> *mut ffi::PyObject - where - T: for<'p> PyObjectRichcmpProtocol<'p>, + where + T: for<'p> PyObjectRichcmpProtocol<'p>, { let _pool = crate::GILPool::new(); let py = Python::assume_gil_acquired(); diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 4f761493e81..8d3ae88b288 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -165,9 +165,8 @@ mod bufferinfo { } pub type getbufferproc = - -> c_int; + unsafe extern "C" fn(arg1: *mut crate::ffi3::PyObject, arg2: *mut Py_buffer, arg3: c_int) -> c_int; pub type releasebufferproc = - unsafe extern "C" fn(arg1: *mut crate::ffi3::PyObject, arg2: *mut Py_buffer, arg3: c_int) unsafe extern "C" fn(arg1: *mut crate::ffi3::PyObject, arg2: *mut Py_buffer) -> (); /// Maximum number of dimensions From c5525c4822b88da48244c7be2126f60c28b34c94 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 28 Dec 2018 16:07:25 +0200 Subject: [PATCH 041/138] use newer build version --- Cargo.toml | 1 + pyo3build/src/rustc_version.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 256309a6963..cda78b3e5eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,5 +63,6 @@ extension-module = [] members = [ "pyo3cls", "pyo3-derive-backend", + "pyo3-build", "examples/*" ] diff --git a/pyo3build/src/rustc_version.rs b/pyo3build/src/rustc_version.rs index d3021b0964c..afa2968892c 100644 --- a/pyo3build/src/rustc_version.rs +++ b/pyo3build/src/rustc_version.rs @@ -2,8 +2,8 @@ extern crate version_check; use self::version_check::{is_min_date, is_min_version, supports_features}; // Specifies the minimum nightly version needed to compile pyo3. -const MIN_DATE: &'static str = "2017-11-07"; -const MIN_VERSION: &'static str = "1.23.0-nightly"; +const MIN_DATE: &'static str = "2018-11-02"; +const MIN_VERSION: &'static str = "1.32.0-nightly"; pub fn check_rustc_version() { let ok_channel = supports_features(); From 2b7c1e1f7ce17d628da7d659a06829a76d87872a Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 28 Dec 2018 16:08:19 +0200 Subject: [PATCH 042/138] whoops --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cda78b3e5eb..af2dbc3c9a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,6 @@ extension-module = [] members = [ "pyo3cls", "pyo3-derive-backend", - "pyo3-build", + "pyo3build", "examples/*" ] From 729a2dd03a9dfa9c76cb8a158990c6525243b531 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Fri, 8 Mar 2019 18:47:35 +0200 Subject: [PATCH 043/138] fix build script --- Cargo.toml | 6 +- build.rs | 27 +- pyo3build/src/lib.rs | 4 + pyo3build/src/py_interpreter.rs | 976 ++++++++++++-------------------- pyo3build/src/python_version.rs | 147 +++++ pyo3build/src/utils.rs | 45 ++ 6 files changed, 565 insertions(+), 640 deletions(-) create mode 100644 pyo3build/src/python_version.rs create mode 100644 pyo3build/src/utils.rs diff --git a/Cargo.toml b/Cargo.toml index 79c37f65146..e6c724d6c57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,13 +44,13 @@ indoc = "0.3.1" default = [] # Use this feature when building python2 binding. - python2 = [] +#python2 = [] # Use this feature when building python3 binding. -#python3 = [] +python3 = [] # Use this feature when building pypy binding. - pypy = [] +pypy = [] # Use this feature when building an extension module. # It tells the linker to keep the python symbols unresolved, # so that the module can also be used with statically linked python interpreters. diff --git a/build.rs b/build.rs index 4bd4f7fe0d6..beea482c4ae 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,8 @@ extern crate pyo3_build_utils; use pyo3_build_utils::{ - py_interpreter::{ - cfg_line_for_var, emit_cargo_vars_from_configuration, find_interpreter, get_config_vars, - is_value, version_from_env, InterpreterConfig, PythonVersion, - }, + py_interpreter::{cfg_line_for_var, find_interpreter, is_value, InterpreterConfig}, + python_version::PythonVersion, rustc_version::check_rustc_version, }; @@ -20,22 +18,17 @@ fn main() { // If you have troubles with your shell accepting '.' in a var name, // try using 'env' (sorry but this isn't our fault - it just has to // match the pkg-config package name, which is going to have a . in it). - let version = match version_from_env() { - Ok(v) => v, - Err(_) => PythonVersion { - major: 3, - minor: None, - kind: None, - }, - }; + let version = PythonVersion::from_env().unwrap_or_default(); - let interpreter_configuration: InterpreterConfig = find_interpreter(&version).unwrap(); + let interpreter_configuration: InterpreterConfig = + find_interpreter(&version).expect("Failed to locate interpreter"); - let flags = emit_cargo_vars_from_configuration(&interpreter_configuration).unwrap(); + let flags = interpreter_configuration + .emit_cargo_vars(); - let mut config_map = get_config_vars(&interpreter_configuration).unwrap(); - - config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + let mut config_map = interpreter_configuration + .get_config_vars() + .expect("Failed to load config variables"); // WITH_THREAD is always on for 3.7 if interpreter_configuration.version.major == 3 diff --git a/pyo3build/src/lib.rs b/pyo3build/src/lib.rs index a50bb61917b..a655a93db8e 100644 --- a/pyo3build/src/lib.rs +++ b/pyo3build/src/lib.rs @@ -1,2 +1,6 @@ +extern crate regex; + pub mod py_interpreter; pub mod rustc_version; +pub mod python_version; +mod utils; diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index d87dd4a814b..0474bc28aeb 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -1,128 +1,50 @@ +extern crate regex; +use self::regex::Regex; + use std::env; use std::fmt; use std::path::{Path, PathBuf}; use std::process::Command; -extern crate regex; - -use self::regex::Regex; - +use python_version::{PythonInterpreterKind, PythonVersion}; use std::collections::HashMap; use std::string::String; +use utils::{canonicalize_executable, run_python_script}; -// Code copied from python wheel package -const GET_ABI_TAG: &'static str = " -from sysconfig import get_config_var -import platform -import sys - -def get_impl_ver(): - impl_ver = get_config_var('py_version_nodot') - if not impl_ver or get_abbr_impl() == 'pp': - impl_ver = ''.join(map(str, get_impl_version_info())) - return impl_ver - -def get_flag(var, fallback, expected=True, warn=True): - val = get_config_var(var) - if val is None: - if warn: - warnings.warn('Config variable {0} is unset, Python ABI tag may ' - 'be incorrect'.format(var), RuntimeWarning, 2) - return fallback() - return val == expected - - -def get_abbr_impl(): - impl = platform.python_implementation() - if impl == 'PyPy': - return 'pp' - elif impl == 'Jython': - return 'jy' - elif impl == 'IronPython': - return 'ip' - elif impl == 'CPython': - return 'cp' - - raise LookupError('Unknown Python implementation: ' + impl) - -def get_abi_tag(): - soabi = get_config_var('SOABI') - impl = get_abbr_impl() - if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'): - d = '' - m = '' - u = '' - if get_flag('Py_DEBUG', - lambda: hasattr(sys, 'gettotalrefcount'), - warn=(impl == 'cp')): - d = 'd' - if get_flag('WITH_PYMALLOC', - lambda: impl == 'cp', - warn=(impl == 'cp')): - m = 'm' - if get_flag('Py_UNICODE_SIZE', - lambda: sys.maxunicode == 0x10ffff, - expected=4, - warn=(impl == 'cp' and - sys.version_info < (3, 3))) \ - and sys.version_info < (3, 3): - u = 'u' - abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u) - elif soabi and soabi.startswith('cpython-'): - abi = 'cp' + soabi.split('-')[1] - elif soabi: - abi = soabi.replace('.', '_').replace('-', '_') - else: - abi = None - return abi - -print(get_abi_tag()) -"; - -pub fn canonicalize_executable

(exe_name: P) -> Option - where - P: AsRef, -{ - env::var_os("PATH").and_then(|paths| { - env::split_paths(&paths) - .filter_map(|dir| { - let full_path = dir.join(&exe_name); - if full_path.is_file() { - Some(full_path) - } else { - None - } - }) - .next() - }) -} +const PY3_MIN_MINOR: u8 = 5; -#[derive(Debug, Clone)] -pub struct PythonVersion { - pub major: u8, - // minor == None means any minor version will do - pub minor: Option, - // kind = "pypy" or "cpython" are supported, default to cpython - pub kind: Option, -} +const CFG_KEY: &'static str = "py_sys_config"; -impl PartialEq for PythonVersion { - fn eq(&self, o: &PythonVersion) -> bool { - self.major == o.major && (self.minor.is_none() || self.minor == o.minor) - } -} +static SYSCONFIG_VALUES: [&'static str; 1] = [ + // cfg doesn't support flags with values, just bools - so flags + // below are translated into bools as {varname}_{val} + // + // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 + "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide +]; -impl fmt::Display for PythonVersion { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(self.major.fmt(f)); - try!(f.write_str(".")); - match self.minor { - Some(minor) => try!(minor.fmt(f)), - None => try!(f.write_str("*")), - }; - Ok(()) - } -} +// A list of python interpreter compile-time preprocessor defines that +// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; +// this allows using them conditional cfg attributes in the .rs files, so +// +// #[cfg(py_sys_config="{varname}"] +// +// is the equivalent of #ifdef {varname} name in C. +// +// see Misc/SpecialBuilds.txt in the python source for what these mean. +// +// (hrm, this is sort of re-implementing what distutils does, except +// by passing command line args instead of referring to a python.h) +#[cfg(not(target_os = "windows"))] +static SYSCONFIG_FLAGS: [&'static str; 7] = [ + "Py_USING_UNICODE", + "Py_UNICODE_WIDE", + "WITH_THREAD", + "Py_DEBUG", + "Py_REF_DEBUG", + "Py_TRACE_REFS", + "COUNT_ALLOCS", +]; #[derive(Debug, PartialEq)] pub struct InterpreterConfig { @@ -136,54 +58,13 @@ pub struct InterpreterConfig { } impl InterpreterConfig { - fn new(interpreter: PathBuf) -> Result { - let script = "import sys; print('__pypy__' in sys.builtin_module_names)"; - let is_pypy: bool = run_python_script(&interpreter, script) - .unwrap() - .to_lowercase() - .trim_right() - .parse() - .unwrap(); - - if is_pypy { - return InterpreterConfig::from_pypy(interpreter); - } else { - return InterpreterConfig::from_cpython(interpreter); - } - } - fn from_cpython(interpreter: PathBuf) -> Result { - let script = "import sys; import sysconfig;\ - print(sys.version_info[0:2]); \ - print(sysconfig.get_config_var('LIBDIR')); \ - print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ - print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ - print(sys.exec_prefix);"; - - let out = try!(run_python_script(&interpreter, script)); - let lines: Vec<&str> = out.lines().collect(); + /// Tries to read interpreter configuration from path to interpreter. + pub fn from_path(interpreter: impl AsRef) -> Result { + let version = PythonVersion::from_interpreter(&interpreter)?; - let abi_tag = try!(run_python_script(&interpreter, GET_ABI_TAG)) - .trim_right() - .to_string(); - - let (major, minor) = try!(parse_interpreter_version(&lines[0])); - - Ok(InterpreterConfig { - version: PythonVersion { - major, - minor: Some(minor), - kind: Some("cpython".to_string()), - }, - path: interpreter, - libpath: lines[1].to_string(), - enable_shared: lines[2] == "1", - ld_version: lines[3].to_string(), - abi_version: abi_tag, - exec_prefix: lines[4].to_string(), - }) - } - fn from_pypy(interpreter: PathBuf) -> Result { - let script = "\ + match version.kind { + PythonInterpreterKind::PyPy => { + let script = "\ import sysconfig import sys import os @@ -196,303 +77,298 @@ def get_pypy_link_lib(): return os.path.dirname(os.path.join(r, f)) raise Exception('cannot locate libpypy') -print(sys.version_info[0:2]) print(get_pypy_link_lib()) print(sys.exec_prefix) "; - let out = try!(run_python_script(&interpreter, script)); - let lines: Vec<&str> = out.lines().collect(); - - let abi_tag = try!(run_python_script(&interpreter, GET_ABI_TAG)) - .trim_right() - .to_string(); + let out = run_python_script(&interpreter, script)?; + let lines: Vec<&str> = out.lines().collect(); + + let abi_tag = run_python_script(&interpreter, GET_ABI_TAG)? + .trim_end() + .to_string(); + + Ok(InterpreterConfig { + version: version.clone(), + path: interpreter.as_ref().to_owned(), + libpath: lines[0].to_string(), + enable_shared: true, + ld_version: format!( + "{}.{}", + &version.major, + &version.minor.expect( + "Interpreter config was loaded from path, above, so this will be set" + ) + ) + .to_string(), + exec_prefix: lines[1].to_string(), + abi_version: abi_tag, + }) + } + PythonInterpreterKind::CPython => { + let script = "import sys; import sysconfig;\ + print(sysconfig.get_config_var('LIBDIR')); \ + print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ + print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ + print(sys.exec_prefix);"; - let (major, minor) = try!(parse_interpreter_version(&lines[0])); + let out = run_python_script(&interpreter, script)?; + let lines: Vec<&str> = out.lines().collect(); + + let abi_tag = run_python_script(&interpreter, GET_ABI_TAG)? + .trim_end() + .to_string(); + + Ok(InterpreterConfig { + version: version.clone(), + path: interpreter.as_ref().to_owned(), + libpath: lines[0].to_string(), + enable_shared: lines[1] == "1", + ld_version: lines[2].to_string(), + abi_version: abi_tag, + exec_prefix: lines[3].to_string(), + }) + } + } + } - Ok(InterpreterConfig { - version: PythonVersion { - major, - minor: Some(minor), - kind: Some("pypy".to_string()), - }, - path: interpreter, - libpath: lines[1].to_string(), - enable_shared: true, - ld_version: format!("{}.{}", major, minor).to_string(), - exec_prefix: lines[2].to_string(), - abi_version: abi_tag, - }) + /// Checks if interpreter is supported by PyO3 + fn assert_python_version_is_supported(&self) -> Result<(), String> { + match (self.version.major, self.version.minor) { + (3, Some(minor)) if minor < PY3_MIN_MINOR => Err(format!( + "Python 3 required version is 3.{}, current version is 3.{}", + PY3_MIN_MINOR, minor + )), + _ => Ok(()), + } } fn is_pypy(&self) -> bool { match self.version.kind { - Some(ref kind) => match kind.as_ref() { - "pypy" => true, - _ => false - }, - None => false + PythonInterpreterKind::PyPy => true, + _ => false, } } -} -const CFG_KEY: &'static str = "py_sys_config"; - -static SYSCONFIG_VALUES: [&'static str; 1] = [ - // cfg doesn't support flags with values, just bools - so flags - // below are translated into bools as {varname}_{val} - // - // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 - "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide -]; + fn is_py3(&self) -> bool { + self.version.major == 3 + } + /// Examine python's compile flags to pass to cfg by launching + /// the interpreter and printing variables of interest from + /// sysconfig.get_config_vars. + #[cfg(not(target_os = "windows"))] + pub fn get_config_vars(&self) -> Result, String> { + let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); + + for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { + script.push_str(&format!( + "print(config.get('{}', {}))", + k, + if is_value(k) { "None" } else { "0" } + )); + script.push_str(";"); + } -pub fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() -} + let out = try!(run_python_script(&self.path, &script)); -pub fn cfg_line_for_var(key: &str, val: &str) -> Option { - if is_value(key) { - // is a value; suffix the key name with the value - Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) - } else if val != "0" { - // is a flag that isn't zero - Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) - } else { - // is a flag that is zero - None - } -} + let split_stdout: Vec<&str> = out.trim_end().lines().collect(); + if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { + return Err(format!( + "python stdout len didn't return expected number of lines: {}", + split_stdout.len() + ) + .to_string()); + } + let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); + // let var_map: HashMap = HashMap::new(); + let mut all_vars = all_vars.zip(split_stdout.iter()).fold( + HashMap::new(), + |mut memo: HashMap, (&k, &v)| { + if !(v.to_owned() == "None" && is_value(k)) { + memo.insert(k.to_owned(), v.to_owned()); + } + memo + }, + ); -const PY3_MIN_MINOR: u8 = 5; + if self.is_pypy() { + all_vars.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + all_vars.insert("Py_UNICODE_SIZE".to_owned(), "4".to_owned()); + all_vars.insert("Py_UNICODE_WIDE".to_owned(), "1".to_owned()); + }; -// A list of python interpreter compile-time preprocessor defines that -// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; -// this allows using them conditional cfg attributes in the .rs files, so -// -// #[cfg(py_sys_config="{varname}"] -// -// is the equivalent of #ifdef {varname} name in C. -// -// see Misc/SpecialBuilds.txt in the python source for what these mean. -// -// (hrm, this is sort of re-implementing what distutils does, except -// by passing command line args instead of referring to a python.h) -#[cfg(not(target_os = "windows"))] -static SYSCONFIG_FLAGS: [&'static str; 7] = [ - "Py_USING_UNICODE", - "Py_UNICODE_WIDE", - "WITH_THREAD", - "Py_DEBUG", - "Py_REF_DEBUG", - "Py_TRACE_REFS", - "COUNT_ALLOCS", -]; + let debug = if let Some(val) = all_vars.get("Py_DEBUG") { + val == "1" + } else { + false + }; + if debug { + all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); + all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); + all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + } -/// Examine python's compile flags to pass to cfg by launching -/// the interpreter and printing variables of interest from -/// sysconfig.get_config_vars. -#[cfg(not(target_os = "windows"))] -pub fn get_config_vars(interpreter_config: &InterpreterConfig) -> Result, String> { - let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); - - for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!( - "print(config.get('{}', {}))", - k, - if is_value(k) { "None" } else { "0" } - )); - script.push_str(";"); + Ok(all_vars) } - let out = try!(run_python_script(&interpreter_config.path, &script)); - - let split_stdout: Vec<&str> = out.trim_right().lines().collect(); - if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { - return Err(format!( - "python stdout len didn't return expected number of lines: {}", - split_stdout.len() - ).to_string()); - } - let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); - // let var_map: HashMap = HashMap::new(); - let mut all_vars = all_vars.zip(split_stdout.iter()).fold( - HashMap::new(), - |mut memo: HashMap, (&k, &v)| { - if !(v.to_owned() == "None" && is_value(k)) { - memo.insert(k.to_owned(), v.to_owned()); - } - memo - }, - ); - - if interpreter_config.is_pypy() { - all_vars.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - all_vars.insert("Py_UNICODE_SIZE".to_owned(), "4".to_owned()); - all_vars.insert("Py_UNICODE_WIDE".to_owned(), "1".to_owned()); - }; - - let debug = if let Some(val) = all_vars.get("Py_DEBUG") { - val == "1" - } else { - false - }; - if debug { - all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + #[cfg(target_os = "windows")] + pub fn get_config_vars(&self) -> Result, String> { + // sysconfig is missing all the flags on windows, so we can't actually + // query the interpreter directly for its build flags. + // + // For the time being, this is the flags as defined in the python source's + // PC\pyconfig.h. This won't work correctly if someone has built their + // python with a modified pyconfig.h - sorry if that is you, you will have + // to comment/uncomment the lines below. + let mut map: HashMap = HashMap::new(); + map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); + map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); + + // This is defined #ifdef _DEBUG. The visual studio build seems to produce + // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the + // Debug configuration, which this script doesn't currently support anyway. + // map.insert("Py_DEBUG", "1"); + + // Uncomment these manually if your python was built with these and you want + // the cfg flags to be set in rust. + // + // map.insert("Py_REF_DEBUG", "1"); + // map.insert("Py_TRACE_REFS", "1"); + // map.insert("COUNT_ALLOCS", 1"); + Ok(map) } - Ok(all_vars) -} + fn get_pypy_link_library_flag(&self) -> String { + let library_name = if self.is_py3() { "pypy3-c" } else { "pypy-c" }; -#[cfg(target_os = "windows")] -pub fn get_config_vars(_: &InterpreterConfig) -> Result, String> { - // sysconfig is missing all the flags on windows, so we can't actually - // query the interpreter directly for its build flags. - // - // For the time being, this is the flags as defined in the python source's - // PC\pyconfig.h. This won't work correctly if someone has built their - // python with a modified pyconfig.h - sorry if that is you, you will have - // to comment/uncomment the lines below. - let mut map: HashMap = HashMap::new(); - map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); - map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); - - // This is defined #ifdef _DEBUG. The visual studio build seems to produce - // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the - // Debug configuration, which this script doesn't currently support anyway. - // map.insert("Py_DEBUG", "1"); - - // Uncomment these manually if your python was built with these and you want - // the cfg flags to be set in rust. - // - // map.insert("Py_REF_DEBUG", "1"); - // map.insert("Py_TRACE_REFS", "1"); - // map.insert("COUNT_ALLOCS", 1"); - Ok(map) -} - - -/// Run a python script using the specified interpreter binary. -fn run_python_script(interpreter_path: &PathBuf, script: &str) -> Result { - let mut cmd = Command::new(interpreter_path); - cmd.arg("-c").arg(script); - - let out = try!( - cmd.output() - .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e)) - ); - - if !out.status.success() { - let stderr = String::from_utf8(out.stderr).unwrap(); - let mut msg = format!("python script failed with stderr:\n\n"); - msg.push_str(&stderr); - return Err(msg); + // All modern PyPy versions with cpyext are compiled as shared libraries. + format!("cargo:rustc-link-lib={}", library_name) } - let out = String::from_utf8(out.stdout).unwrap(); - return Ok(out); -} + #[cfg(not(target_os = "macos"))] + #[cfg(not(target_os = "windows"))] + fn get_rustc_link_lib(&self) -> Result { + if self.is_pypy() { + return Ok(self.get_pypy_link_library_flag()); + } -#[cfg(not(target_os = "macos"))] -#[cfg(not(target_os = "windows"))] -fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { - if interpreter_config.is_pypy() { - let link_library_name = match interpreter_config.version.major { - 2 => "pypy-c", - 3 => "pypy3-c", - _ => unreachable!(), - }; - // All modern PyPy versions with cpyext are compiled as shared libraries. - return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + if self.enable_shared { + Ok(format!( + "cargo:rustc-link-lib=python{}", + interpreter_config.ld_version + )) + } else { + Ok(format!( + "cargo:rustc-link-lib=static=python{}", + self.ld_version + )) + } } - if interpreter_config.enable_shared { - Ok(format!( - "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version - )) - } else { + #[cfg(target_os = "windows")] + fn get_rustc_link_lib(&self) -> Result { + if self.is_pypy() { + return Ok(self.get_pypy_link_library_flag()); + } + + // Py_ENABLE_SHARED doesn't seem to be present on windows. Ok(format!( - "cargo:rustc-link-lib=static=python{}", - interpreter_config.ld_version + "cargo:rustc-link-lib=pythonXY:python{}{}", + version.major, + match version.minor { + Some(minor) => minor.to_string(), + None => "".to_owned(), + } )) } -} -#[cfg(target_os = "windows")] -fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { - if interpreter_config.is_pypy() { - let link_library_name = match interpreter_config.version.major { - 2 => "pypy-c", - 3 => "pypy3-c", - _ => unreachable!(), - }; - // All modern PyPy versions with cpyext are compiled as shared libraries. - return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); + #[cfg(target_os = "macos")] + fn get_macos_linkmodel(&self) -> Result { + let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; + let out = run_python_script(&self.path, script).unwrap(); + Ok(out.trim_end().to_owned()) } - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!( - "cargo:rustc-link-lib=pythonXY:python{}{}", - version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned(), + #[cfg(target_os = "macos")] + fn get_rustc_link_lib(&self) -> Result { + if self.is_pypy() { + return Ok(self.get_pypy_link_library_flag()); } - )) -} - -#[cfg(target_os = "macos")] -fn get_rustc_link_lib(interpreter_config: &InterpreterConfig) -> Result { - if interpreter_config.is_pypy() { - let link_library_name = match interpreter_config.version.major { - 2 => "pypy-c", - 3 => "pypy3-c", - _ => unreachable!(), - }; - // All modern PyPy versions with cpyext are compiled as shared libraries. - return Ok(format!("cargo:rustc-link-lib={}", link_library_name)); - } - // os x can be linked to a framework or static or dynamic, and - // Py_ENABLE_SHARED is wrong; framework means shared library - match get_macos_linkmodel(&interpreter_config.path) - .unwrap() - .as_ref() - { + // os x can be linked to a framework or static or dynamic, and + // Py_ENABLE_SHARED is wrong; framework means shared library + match self.get_macos_linkmodel().unwrap().as_ref() { "static" => Ok(format!( "cargo:rustc-link-lib=static=python{}", - interpreter_config.ld_version - )), - "shared" => Ok(format!( - "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version - )), - "framework" => Ok(format!( - "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version + self.ld_version )), + "shared" => Ok(format!("cargo:rustc-link-lib=python{}", self.ld_version)), + "framework" => Ok(format!("cargo:rustc-link-lib=python{}", self.ld_version)), other => Err(format!("unknown linkmodel {}", other)), } + } + + /// print cargo vars to stdout. + pub fn emit_cargo_vars(&self) -> String { + let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); + + println!("cargo:rustc-cfg={}", self.abi_version); + + if !is_extension_module || cfg!(target_os = "windows") { + println!("{}", self.get_rustc_link_lib().unwrap()); + + if self.libpath != "None" { + println!("cargo:rustc-link-search=native={}", self.libpath); + } else if cfg!(target_os = "windows") { + println!("cargo:rustc-link-search=native={}\\libs", self.exec_prefix); + } + } + + let mut flags = String::new(); + + if self.is_pypy() { + println!("cargo:rustc-cfg=PyPy"); + flags += format!("CFG_PyPy").as_ref(); + }; + + if self.is_py3() { + if env::var_os("CARGO_FEATURE_PEP_384").is_some() { + println!("cargo:rustc-cfg=Py_LIMITED_API"); + } + println!("cargo:rustc-cfg=Py_3"); + flags += "CFG_Py_3,"; + + if let Some(minor) = self.version.minor { + for i in 5..(minor + 1) { + println!("cargo:rustc-cfg=Py_3_{}", i); + flags += format!("CFG_Py_3_{},", i).as_ref(); + } + } + } else { + println!("cargo:rustc-cfg=Py_2"); + flags += format!("CFG_Py_2,").as_ref(); + } + + return flags; + } } -#[cfg(target_os = "macos")] -fn get_macos_linkmodel(interpreter_path: &PathBuf) -> Result { - let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; - let out = run_python_script(interpreter_path, script).unwrap(); - Ok(out.trim_right().to_owned()) +pub fn is_value(key: &str) -> bool { + SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() } -/// Parse string as interpreter version. -fn parse_interpreter_version(line: &str) -> Result<(u8, u8), String> { - let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); - match version_re.captures(&line) { - Some(cap) => Ok((cap.get(1).unwrap().as_str().parse().unwrap(), - cap.get(2).unwrap().as_str().parse().unwrap())), - None => Err(format!("Unexpected response to version query {}", line)), +pub fn cfg_line_for_var(key: &str, val: &str) -> Option { + if is_value(key) { + // is a value; suffix the key name with the value + Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) + } else if val != "0" { + // is a flag that isn't zero + Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) + } else { + // is a flag that is zero + None } } @@ -506,7 +382,7 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result Result Result match kind.as_ref() { - "pypy" => "pypy", - "cpython" => "python", - other => return Err(format!("Unsupported interpreter {}", other)) - }, - None => "python" - }; - - let mut possible_python_paths = vec![ - interpreter_binary_name.to_string(), - format!("{}{}", &interpreter_binary_name, expected_version.major), - ]; - if let Some(minor) = expected_version.minor { - possible_python_paths.push(format!("{}{}.{}", &interpreter_binary_name, expected_version.major, minor)) - } + let possible_python_paths = expected_version.possible_binary_names(); for possible_path in possible_python_paths { let interpreter_path = canonicalize_executable(&possible_path); - if interpreter_path.is_some() { - let interpreter_config = try!(InterpreterConfig::new(interpreter_path.unwrap())); + if let Some(path) = interpreter_path { + let interpreter_config = InterpreterConfig::from_path(path)?; + if expected_version == &interpreter_config.version { return Ok(interpreter_config); } @@ -557,197 +419,71 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result Result { - let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - - println!("cargo:rustc-cfg={}", interpreter_config.abi_version); - - if !is_extension_module || cfg!(target_os = "windows") { - println!("{}", get_rustc_link_lib(&interpreter_config).unwrap()); - - if interpreter_config.libpath != "None" { - println!( - "cargo:rustc-link-search=native={}", - interpreter_config.libpath - ); - } else if cfg!(target_os = "windows") { - println!( - "cargo:rustc-link-search=native={}\\libs", - interpreter_config.exec_prefix - ); - } - } - - let mut flags = String::new(); - - if let PythonVersion { - major: 3, - minor: some_minor, - kind: ref _some_kind, - } = interpreter_config.version - { - if env::var_os("CARGO_FEATURE_PEP_384").is_some() { - println!("cargo:rustc-cfg=Py_LIMITED_API"); - } - - if let Some(minor) = some_minor { - if minor < PY3_MIN_MINOR { - return Err(format!( - "Python 3 required version is 3.{}, current version is 3.{}", - PY3_MIN_MINOR, minor - )); - } - for i in 5..(minor + 1) { - 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(); - } - - if interpreter_config.is_pypy() { - println!("cargo:rustc-cfg=PyPy"); - }; - - return Ok(flags); -} - -/// Determine the python version we're supposed to be building -/// from the features passed via the environment. -/// -/// The environment variable can choose to omit a minor -/// version if the user doesn't care. -pub fn version_from_env() -> Result { - let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); - - let interpreter_kind; - - if cfg!(feature="pypy") { - interpreter_kind = "pypy".to_string() - } else { - interpreter_kind = "cpython".to_string() - } - - // sort env::vars so we get more explicit version specifiers first - // so if the user passes e.g. the python-3 feature and the python-3-5 - // feature, python-3-5 takes priority. - let mut vars = env::vars().collect::>(); - - vars.sort_by(|a, b| b.cmp(a)); - for (key, _) in vars { - match re.captures(&key) { - Some(cap) => { - return Ok(PythonVersion { - kind: Some(interpreter_kind), - major: cap.get(1).unwrap().as_str().parse().unwrap(), - minor: match cap.get(3) { - Some(s) => Some(s.as_str().parse().unwrap()), - None => None, - }, - }); - } - None => (), - } - } - - Err( - "Python version feature was not found. At least one python version \ - feature must be enabled." - .to_owned(), - ) -} - - -#[cfg(test)] -mod test { - use py_interpreter::canonicalize_executable; - use py_interpreter::{find_interpreter, run_python_script, InterpreterConfig, PythonVersion}; - use std::env; - use py_interpreter::GET_ABI_TAG; - - #[test] - fn test_correctly_detects_cpython() { - let python_version_major_only = PythonVersion { - major: 3, - minor: None, - kind: None, - }; - let expected_config = InterpreterConfig { - version: PythonVersion { - major: 3, - minor: Some(6), - kind: Some("cpython".to_string()), - }, - path: (canonicalize_executable("python").unwrap()), - libpath: String::from("some_path"), - enable_shared: true, - ld_version: String::from("3.6m"), - exec_prefix: String::from("some_path"), - abi_version: String::from("cp36m"), - }; - - let interpreter = find_interpreter(&python_version_major_only).unwrap(); - - println!("{:?}", interpreter); - - assert_eq!(interpreter.version, expected_config.version); - assert_eq!(interpreter.enable_shared, expected_config.enable_shared); - assert_eq!(interpreter.ld_version, expected_config.ld_version); - assert_eq!(interpreter.abi_version, expected_config.abi_version); - } - - #[test] - fn test_correctly_detects_python_from_envvar() { - let test_path = - canonicalize_executable("pypy3").expect("pypy3 not found in PATH, cannot test"); +// Code copied from python wheel package +const GET_ABI_TAG: &'static str = " +from sysconfig import get_config_var +import platform +import sys - env::set_var( - "PYTHON_SYS_EXECUTABLE", - test_path.clone().into_os_string().into_string().unwrap(), - ); +def get_impl_ver(): + impl_ver = get_config_var('py_version_nodot') + if not impl_ver or get_abbr_impl() == 'pp': + impl_ver = ''.join(map(str, get_impl_version_info())) + return impl_ver - let python_version_major_only = PythonVersion { - major: 3, - minor: None, - kind: None, - }; +def get_flag(var, fallback, expected=True, warn=True): + val = get_config_var(var) + if val is None: + if warn: + warnings.warn('Config variable {0} is unset, Python ABI tag may ' + 'be incorrect'.format(var), RuntimeWarning, 2) + return fallback() + return val == expected - let interpreter = find_interpreter(&python_version_major_only).unwrap(); - env::set_var("PYTHON_SYS_EXECUTABLE", ""); - let abi_tag = run_python_script(&test_path, GET_ABI_TAG) - .unwrap() - .trim_right() - .to_string(); +def get_abbr_impl(): + impl = platform.python_implementation() + if impl == 'PyPy': + return 'pp' + elif impl == 'Jython': + return 'jy' + elif impl == 'IronPython': + return 'ip' + elif impl == 'CPython': + return 'cp' + raise LookupError('Unknown Python implementation: ' + impl) - let expected_config = InterpreterConfig { - version: PythonVersion { - major: 3, - minor: Some(5), - kind: Some("pypy".to_string()), - }, - // We can't reliably test this unless we make some assumptions - path: (canonicalize_executable("python").unwrap()), - libpath: String::from("some_path"), - enable_shared: true, - ld_version: String::from("3.5"), - exec_prefix: String::from("some_path"), - abi_version: String::from(abi_tag), - }; +def get_abi_tag(): + soabi = get_config_var('SOABI') + impl = get_abbr_impl() + if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'): + d = '' + m = '' + u = '' + if get_flag('Py_DEBUG', + lambda: hasattr(sys, 'gettotalrefcount'), + warn=(impl == 'cp')): + d = 'd' + if get_flag('WITH_PYMALLOC', + lambda: impl == 'cp', + warn=(impl == 'cp')): + m = 'm' + if get_flag('Py_UNICODE_SIZE', + lambda: sys.maxunicode == 0x10ffff, + expected=4, + warn=(impl == 'cp' and + sys.version_info < (3, 3))) \ + and sys.version_info < (3, 3): + u = 'u' + abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u) + elif soabi and soabi.startswith('cpython-'): + abi = 'cp' + soabi.split('-')[1] + elif soabi: + abi = soabi.replace('.', '_').replace('-', '_') + else: + abi = None + return abi - assert_eq!(interpreter.version, expected_config.version); - assert_eq!(interpreter.enable_shared, expected_config.enable_shared); - assert_eq!(interpreter.ld_version, expected_config.ld_version); - assert_eq!(interpreter.abi_version, expected_config.abi_version); - } -} +print(get_abi_tag()) +"; diff --git a/pyo3build/src/python_version.rs b/pyo3build/src/python_version.rs new file mode 100644 index 00000000000..9de2d8accbf --- /dev/null +++ b/pyo3build/src/python_version.rs @@ -0,0 +1,147 @@ +use regex::Regex; +use std::env; +use std::fmt::{self, Display}; +use std::path::Path; +use utils::run_python_script; + +#[derive(Debug, Clone)] +pub enum PythonInterpreterKind { + CPython, + PyPy, +} + +#[derive(Debug, Clone)] +pub struct PythonVersion { + pub major: u8, + // minor == None means any minor version will do + pub minor: Option, + // kind = "pypy" or "cpython" are supported, default to cpython + pub kind: PythonInterpreterKind, +} + +impl PartialEq for PythonVersion { + fn eq(&self, o: &PythonVersion) -> bool { + self.major == o.major && (self.minor.is_none() || self.minor == o.minor) + } +} + +impl fmt::Display for PythonVersion { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + try!(self.major.fmt(f)); + try!(f.write_str(".")); + match self.minor { + Some(minor) => try!(minor.fmt(f)), + None => try!(f.write_str("*")), + }; + Ok(()) + } +} + +impl Default for PythonVersion { + fn default() -> Self { + PythonVersion { + major: 3, + minor: None, + kind: PythonInterpreterKind::CPython, + } + } +} + +impl PythonVersion { + /// Determine the python version we're supposed to be building + /// from the features passed via the environment. + /// + /// The environment variable can choose to omit a minor + /// version if the user doesn't care. + pub fn from_env() -> Result { + let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").expect("This is a valid regex"); + + let interpreter_kind = if cfg!(feature = "pypy") { + PythonInterpreterKind::PyPy + } else { + PythonInterpreterKind::CPython + }; + + // sort env::vars so we get more explicit version specifiers first + // so if the user passes e.g. the python-3 feature and the python-3-5 + // feature, python-3-5 takes priority. + let mut vars = env::vars().collect::>(); + + vars.sort_by(|a, b| b.cmp(&a)); + for (key, _) in vars { + match re.captures(&key) { + Some(cap) => { + return Ok(PythonVersion { + kind: interpreter_kind, + major: cap.get(1).expect("must match").as_str().parse().unwrap(), + minor: match cap.get(3) { + Some(s) => Some(s.as_str().parse().unwrap()), + None => None, + }, + }); + } + None => (), + } + } + + Err( + "Python version feature was not found. At least one python version \ + feature must be enabled." + .to_owned(), + ) + } + + /// Returns a name of possible python binary names. + /// Ex. vec![python, python3, python3.5] + pub fn possible_binary_names(&self) -> Vec { + let mut possible_names = vec![]; + + let binary_name = format!("{:?}", self.kind).to_ascii_lowercase(); + + possible_names.push(binary_name.clone()); + possible_names.push(format!("{}{}", &binary_name, self.major)); + + if let Some(minor) = self.minor { + possible_names.push(format!("{}{}.{}", &binary_name, self.major, minor)); + } + + possible_names + } + + pub fn from_interpreter(interpreter_path: impl AsRef) -> Result { + let script = "import sys;\ + print('__pypy__' in sys.builtin_module_names);\ + print(sys.version_info[0:2]);"; + + let out = run_python_script(interpreter_path.as_ref(), script)?; + let lines: Vec<&str> = out.lines().collect(); + + let is_pypy: bool = lines[0] + .to_ascii_lowercase() + .parse() + .expect("Should print a bool"); + let (major, minor) = PythonVersion::parse_interpreter_version(lines[1])?; + + Ok(Self { + major, + minor: Some(minor), + kind: if is_pypy { + PythonInterpreterKind::PyPy + } else { + PythonInterpreterKind::CPython + }, + }) + } + + /// Parse string as interpreter version. + fn parse_interpreter_version(line: &str) -> Result<(u8, u8), String> { + let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); + match version_re.captures(&line) { + Some(cap) => Ok(( + cap.get(1).unwrap().as_str().parse().unwrap(), + cap.get(2).unwrap().as_str().parse().unwrap(), + )), + None => Err(format!("Unexpected response to version query {}", line)), + } + } +} diff --git a/pyo3build/src/utils.rs b/pyo3build/src/utils.rs new file mode 100644 index 00000000000..dcc227fe001 --- /dev/null +++ b/pyo3build/src/utils.rs @@ -0,0 +1,45 @@ +use std::env; +use std::path::{Path, PathBuf}; +use std::process::Command; + +pub fn canonicalize_executable

(exe_name: P) -> Option +where + P: AsRef, +{ + env::var_os("PATH").and_then(|paths| { + env::split_paths(&paths) + .filter_map(|dir| { + let full_path = dir.join(&exe_name); + if full_path.is_file() { + Some(full_path) + } else { + None + } + }) + .next() + }) +} + +/// Run a python script using the specified interpreter binary. +/// Returns an error if python printer anything to stderr. +pub fn run_python_script( + interpreter_path: impl AsRef, + script: &str, +) -> Result { + let mut cmd = Command::new(interpreter_path.as_ref()); + cmd.arg("-c").arg(script); + + let out = cmd + .output() + .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e))?; + + if !out.status.success() { + let stderr = String::from_utf8(out.stderr).unwrap(); + let mut msg = format!("python script failed with stderr:\n\n"); + msg.push_str(&stderr); + return Err(msg); + } + + let out = String::from_utf8(out.stdout).unwrap(); + return Ok(out); +} From d362b08f94c63d077da18d98eabb558a9b97d5f6 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 12:04:33 +0200 Subject: [PATCH 044/138] more build hacks --- build.rs | 134 +++++++------------------------- pyo3build/src/py_interpreter.rs | 67 ++++++++++++++-- pyo3build/src/python_version.rs | 21 ++++- pyo3build/src/utils.rs | 38 +++++++++ 4 files changed, 147 insertions(+), 113 deletions(-) diff --git a/build.rs b/build.rs index 1a9e33dbc3e..d672509aeb8 100644 --- a/build.rs +++ b/build.rs @@ -5,76 +5,12 @@ use pyo3_build_utils::{ python_version::PythonVersion, rustc_version::check_rustc_version, }; -fn load_cross_compile_info() -> Result<(PythonVersion, HashMap, Vec), String> -{ - let python_include_dir = env::var("PYO3_CROSS_INCLUDE_DIR").unwrap(); - let python_include_dir = Path::new(&python_include_dir); - - let patchlevel_defines = parse_header_defines(python_include_dir.join("patchlevel.h"))?; - let major = patchlevel_defines - - .get("PY_MAJOR_VERSION") - .and_then(|major| major.parse::().ok()) - .expect("PY_MAJOR_VERSION undefined"); - - .get("PY_MINOR_VERSION") - let minor = patchlevel_defines - .and_then(|minor| minor.parse::().ok()) - - .expect("PY_MINOR_VERSION undefined"); - let python_version = PythonVersion { - major, - minor: Some(minor), - }; - - let config_map = parse_header_defines(python_include_dir.join("pyconfig.h"))?; - - let config_lines = vec![ - "".to_owned(), // compatibility, not used when cross compiling. - config_map - env::var("PYO3_CROSS_LIB_DIR").unwrap(), - .get("Py_ENABLE_SHARED") - .expect("Py_ENABLE_SHARED undefined") - .to_owned(), - format!("{}.{}", major, minor), - "".to_owned(), // compatibility, not used when cross compiling. - ]; - - Ok((python_version, fix_config_map(config_map), config_lines)) -} -/// Attempts to parse the header at the given path, returning a map of definitions to their values. -/// Each entry in the map directly corresponds to a `#define` in the given header. -fn parse_header_defines>(header_path: P) -> Result, String> { - // value. e.g. for the line `#define Py_DEBUG 1`, this regex will capture `Py_DEBUG` into - // This regex picks apart a C style, single line `#define` statement into an identifier and a - // `ident` and `1` into `value`. - let define_regex = - Regex::new(r"^\s*#define\s+(?P[a-zA-Z0-9_]+)\s+(?P.+)\s*$").unwrap(); - - let header_file = File::open(header_path.as_ref()).map_err(|e| e.to_string())?; - let header_reader = BufReader::new(&header_file); - - let definitions = header_reader - .lines() - .filter_map(|maybe_line| { - let line = maybe_line.unwrap_or_else(|err| { - panic!("failed to read {}: {}", header_path.as_ref().display(), err); - }); - let captures = define_regex.captures(&line)?; - - if captures.name("ident").is_some() && captures.name("value").is_some() { - Some(( - captures.name("ident").unwrap().as_str().to_owned(), - captures.name("value").unwrap().as_str().to_owned(), - } else { - )) - } - None - }) - .collect(); - -} - Ok(definitions) +use regex::Regex; +use std::collections::HashMap; +use std::env; +use std::fs::File; +use std::io::{BufRead, BufReader}; +use std::path::Path; fn main() { check_rustc_version(); @@ -88,44 +24,21 @@ fn main() { // If you have troubles with your shell accepting '.' in a var name, // try using 'env' (sorry but this isn't our fault - it just has to // match the pkg-config package name, which is going to have a . in it). - let version = PythonVersion::from_env().unwrap_or_default(); - - let interpreter_configuration: InterpreterConfig = - find_interpreter(&version).expect("Failed to locate interpreter"); - - let flags = interpreter_configuration - .emit_cargo_vars(); - - let mut config_map = interpreter_configuration - .get_config_vars() - .expect("Failed to load config variables"); - - // WITH_THREAD is always on for 3.7 - if interpreter_configuration.version.major == 3 - && interpreter_configuration.version.minor.unwrap_or(0) >= 7 - { let cross_compiling = env::var("PYO3_CROSS_INCLUDE_DIR").is_ok() && env::var("PYO3_CROSS_LIB_DIR").is_ok(); - let (interpreter_version, mut config_map, lines) = if cross_compiling { - load_cross_compile_info() - } else { - find_interpreter_and_get_config() - } - .unwrap(); - let flags = configure(&interpreter_version, lines).unwrap(); - - // WITH_THREAD is always on for 3.7 - if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { - config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - } + let interpreter_config = if cross_compiling { + InterpreterConfig::from_cross_compile_info() + .expect("Error when loading cross compile settings.") + } else { + let version = PythonVersion::from_env().unwrap_or_default(); + find_interpreter(&version).expect("Interpreter not found.") + }; - for (key, val) in &config_map { - match cfg_line_for_var(key, val) { - Some(line) => println!("{}", line), - None => (), - } - } + let config_map = interpreter_config + .get_config_vars() + .expect("Failed to load configuration variables"); + let flags = interpreter_config.emit_cargo_vars(); // 2. Export python interpreter compilation flags as cargo variables that // will be visible to dependents. All flags will be available to dependent @@ -138,9 +51,8 @@ fn main() { // VAL indicates it can take on any value // // rust-cypthon/build.rs contains an example of how to unpack this data - // into cfg flags that replicate theones present in this library, so + // into cfg flags that replicate the ones present in this library, so // you can use the same cfg syntax. - //let mut flags = flags; let flags: String = config_map.iter().fold("".to_owned(), |memo, (key, val)| { if is_value(key) { memo + format!("VAL_{}={},", key, val).as_ref() @@ -159,4 +71,14 @@ fn main() { "" } ); + + if env::var_os("TARGET") == Some("x86_64-apple-darwin".into()) { + // TODO: Find out how we can set -undefined dynamic_lookup here (if this is possible) + } + + let env_vars = ["LD_LIBRARY_PATH", "PATH", "PYTHON_SYS_EXECUTABLE", "LIB"]; + + for var in env_vars.iter() { + println!("cargo:rerun-if-env-changed={}", var); + } } diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 0474bc28aeb..3b6491f59ec 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -9,7 +9,7 @@ use std::process::Command; use python_version::{PythonInterpreterKind, PythonVersion}; use std::collections::HashMap; use std::string::String; -use utils::{canonicalize_executable, run_python_script}; +use utils::{canonicalize_executable, parse_header_defines, run_python_script}; const PY3_MIN_MINOR: u8 = 5; @@ -131,6 +131,46 @@ print(sys.exec_prefix) } } + pub fn from_cross_compile_info() -> Result { + let python_include_dir = env::var("PYO3_CROSS_INCLUDE_DIR") + .map_err(|e| "Need to define `PYO3_CROSS_INCLUDE_DIR`")?; + + let python_include_dir = Path::new(&python_include_dir); + let patchlevel_defines = parse_header_defines(python_include_dir.join("patchlevel.h"))?; + + let version = PythonVersion::from_cross_env(&patchlevel_defines)?; + + let config_map = parse_header_defines(python_include_dir.join("pyconfig.h"))?; + + let enable_shared: bool = config_map + .get("Py_ENABLE_SHARED") + .ok_or("Py_ENABLE_SHARED undefined".to_string())? + .parse() + .map_err(|e| "Failed to `Py_ENABLE_SHARED`".to_string())?; + + let libpath = env::var("PYO3_CROSS_LIB_DIR") + .map_err(|e| "PYO3_CROSS_LIB_DIR undefined".to_string())?; + + Ok(Self { + version: version.clone(), + // compatibility, not used when cross compiling. + path: PathBuf::new(), + libpath, + enable_shared, + ld_version: format!( + "{}.{}", + &version.major, + &version + .minor + .expect("Interpreter config was loaded from path, above, so this will be set") + ), + // compatibility, not used when cross compiling + exec_prefix: "".to_string(), + // compatibility, not used when cross compiling + abi_version: "".to_string(), + }) + } + /// Checks if interpreter is supported by PyO3 fn assert_python_version_is_supported(&self) -> Result<(), String> { match (self.version.major, self.version.minor) { @@ -353,6 +393,16 @@ print(sys.exec_prefix) return flags; } + + fn fix_config_map(mut config_map: HashMap) -> HashMap { + if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) { + config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); + config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); + config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + } + + config_map + } } pub fn is_value(key: &str) -> bool { @@ -373,11 +423,16 @@ pub fn cfg_line_for_var(key: &str, val: &str) -> Option { } /// Locate a suitable python interpreter and extract config from it. -/// If the environment variable `PYTHON_SYS_EXECUTABLE`, use the provided -/// path a Python executable, and raises an error if the version doesn't match. -/// Else tries to execute the interpreter as "python", "python{major version}", -/// "python{major version}.{minor version}" in order until one -/// is of the version we are expecting. +/// +/// The following locations are checked in the order listed: +/// +/// 1. If `PYTHON_SYS_EXECUTABLE` is set, this intepreter is used and an error is raised if the +/// version doesn't match. +/// 2. `python` +/// 3. `python{major version}` +/// 4. `python{major version}.{minor version}` +/// +/// If none of the above works, an error is returned pub fn find_interpreter(expected_version: &PythonVersion) -> Result { if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { let interpreter_path_or_executable = interpreter_from_env diff --git a/pyo3build/src/python_version.rs b/pyo3build/src/python_version.rs index 9de2d8accbf..d42928feddb 100644 --- a/pyo3build/src/python_version.rs +++ b/pyo3build/src/python_version.rs @@ -1,8 +1,9 @@ use regex::Regex; +use std::collections::HashMap; use std::env; use std::fmt::{self, Display}; use std::path::Path; -use utils::run_python_script; +use utils::{parse_header_defines, run_python_script}; #[derive(Debug, Clone)] pub enum PythonInterpreterKind { @@ -91,6 +92,24 @@ impl PythonVersion { ) } + pub fn from_cross_env(header_defines: &HashMap) -> Result { + let major = header_defines + .get("PY_MAJOR_VERSION") + .and_then(|major| major.parse::().ok()) + .ok_or("PY_MAJOR_VERSION undefined".to_string())?; + + let minor = header_defines + .get("PY_MINOR_VERSION") + .and_then(|minor| minor.parse::().ok()) + .ok_or("PY_MINOR_VERSION undefined".to_string())?; + + Ok(PythonVersion { + major, + minor: Some(minor), + kind: PythonInterpreterKind::CPython, + }) + } + /// Returns a name of possible python binary names. /// Ex. vec![python, python3, python3.5] pub fn possible_binary_names(&self) -> Vec { diff --git a/pyo3build/src/utils.rs b/pyo3build/src/utils.rs index dcc227fe001..eb62fbc799b 100644 --- a/pyo3build/src/utils.rs +++ b/pyo3build/src/utils.rs @@ -1,6 +1,10 @@ use std::env; use std::path::{Path, PathBuf}; use std::process::Command; +use std::collections::HashMap; +use regex::Regex; +use std::fs::File; +use std::io::{BufReader, BufRead}; pub fn canonicalize_executable

(exe_name: P) -> Option where @@ -20,6 +24,40 @@ where }) } +/// Attempts to parse the header at the given path, returning a map of definitions to their values. +/// Each entry in the map directly corresponds to a `#define` in the given header. +pub fn parse_header_defines>(header_path: P) -> Result, String> { + // This regex picks apart a C style, single line `#define` statement into an identifier and a + // value. e.g. for the line `#define Py_DEBUG 1`, this regex will capture `Py_DEBUG` into + // `ident` and `1` into `value`. + let define_regex = + Regex::new(r"^\s*#define\s+(?P[a-zA-Z0-9_]+)\s+(?P.+)\s*$").unwrap(); + + let header_file = File::open(header_path.as_ref()).map_err(|e| e.to_string())?; + let header_reader = BufReader::new(&header_file); + + let definitions = header_reader + .lines() + .filter_map(|maybe_line| { + let line = maybe_line.unwrap_or_else(|err| { + panic!("failed to read {}: {}", header_path.as_ref().display(), err); + }); + let captures = define_regex.captures(&line)?; + + if captures.name("ident").is_some() && captures.name("value").is_some() { + Some(( + captures.name("ident").unwrap().as_str().to_owned(), + captures.name("value").unwrap().as_str().to_owned(), + )) + } else { + None + } + }) + .collect(); + + Ok(definitions) +} + /// Run a python script using the specified interpreter binary. /// Returns an error if python printer anything to stderr. pub fn run_python_script( From dd5ed857c0c2c02ae6e172bb530cc4d57477d666 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 12:04:44 +0200 Subject: [PATCH 045/138] some random hiccups --- src/ffi3/ceval.rs | 4 ++-- src/ffi3/code.rs | 2 +- src/ffi3/complexobject.rs | 1 - src/ffi3/object.rs | 4 +++- src/ffi3/objectabstract.rs | 3 +-- src/ffi3/traceback.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 872391a094f..5e2e1382a79 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -36,7 +36,7 @@ extern "C" { pub fn PyEval_GetGlobals() -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; - pub fn PyEval_GetFrame() -> *mut ::ffi3::PyFrameObject; + pub fn PyEval_GetFrame() -> *mut crate::ffi3::PyFrameObject; #[cfg_attr(PyPy, link_name = "PyPy_AddPendingCall")] pub fn Py_AddPendingCall( func: Option c_int>, @@ -68,7 +68,7 @@ extern "C" { pub fn _PyEval_EvalFrameDefault(arg1: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; #[cfg(Py_3_6)] pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int; - pub fn PyEval_EvalFrameEx(f: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; + pub fn PyEval_EvalFrameEx(f: *mut crate::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; #[cfg_attr(PyPy, link_name = "PyPyEval_RestoreThread")] diff --git a/src/ffi3/code.rs b/src/ffi3/code.rs index d066b7b7a30..71ad0376425 100644 --- a/src/ffi3/code.rs +++ b/src/ffi3/code.rs @@ -124,5 +124,5 @@ pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { #[inline] #[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")] pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { - ::ffi3::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) + crate::ffi3::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } diff --git a/src/ffi3/complexobject.rs b/src/ffi3/complexobject.rs index 991d75d0186..4afb3105134 100644 --- a/src/ffi3/complexobject.rs +++ b/src/ffi3/complexobject.rs @@ -1,4 +1,3 @@ -use ffi3::object::*; use crate::ffi3::object::*; use std::os::raw::{c_double, c_int}; diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index aab6bb7df56..e9df79c865b 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -65,7 +65,7 @@ pub struct PyVarObject { pub ob_size: Py_ssize_t, } -#[inline(always)] +#[inline] pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { if ob.is_null() { panic!(); @@ -162,6 +162,7 @@ mod bufferinfo { fn default() -> Self { unsafe { mem::zeroed() } } + } pub type getbufferproc = unsafe extern "C" fn( arg1: *mut crate::ffi3::PyObject, @@ -631,6 +632,7 @@ mod typeobject { // The exported types depend on whether Py_LIMITED_API is set pub use self::typeobject::*; +use crate::ffi3::pyerrors::{PyErr_Format, PyExc_TypeError}; #[repr(C)] #[derive(Copy, Clone)] diff --git a/src/ffi3/objectabstract.rs b/src/ffi3/objectabstract.rs index c181a33bc30..a95bc6e3680 100644 --- a/src/ffi3/objectabstract.rs +++ b/src/ffi3/objectabstract.rs @@ -29,7 +29,6 @@ extern "C" { args: *mut PyObject, ) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] - #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] pub fn PyObject_CallFunction( callable_object: *mut PyObject, format: *const c_char, @@ -162,7 +161,7 @@ pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { (match (*(*o).ob_type).tp_iternext { Some(tp_iternext) => { tp_iternext as *const c_void - != ::ffi3::object::_PyObject_NextNotImplemented as *const c_void + != crate::ffi3::object::_PyObject_NextNotImplemented as *const c_void } None => false, }) as c_int diff --git a/src/ffi3/traceback.rs b/src/ffi3/traceback.rs index 156b5f917b5..8bd12bf361e 100644 --- a/src/ffi3/traceback.rs +++ b/src/ffi3/traceback.rs @@ -4,7 +4,7 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Here")] - pub fn PyTraceBack_Here(arg1: *mut ::ffi3::PyFrameObject) -> c_int; + pub fn PyTraceBack_Here(arg1: *mut crate::ffi3::PyFrameObject) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")] From b87338f611de0ebc5d3ed7528db435878fcf5658 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 12:18:12 +0200 Subject: [PATCH 046/138] small fixes --- build.rs | 1 + pyo3build/src/py_interpreter.rs | 28 ++++++++++++++++------------ pyo3build/src/python_version.rs | 11 +++++++---- src/ffi3/ceval.rs | 2 +- src/ffi3/methodobject.rs | 2 +- src/ffi3/object.rs | 1 - 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index d672509aeb8..5f55c9670c4 100644 --- a/build.rs +++ b/build.rs @@ -38,6 +38,7 @@ fn main() { let config_map = interpreter_config .get_config_vars() .expect("Failed to load configuration variables"); + let flags = interpreter_config.emit_cargo_vars(); // 2. Export python interpreter compilation flags as cargo variables that diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 3b6491f59ec..1399f1eea2c 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -23,18 +23,18 @@ static SYSCONFIG_VALUES: [&'static str; 1] = [ "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide ]; -// A list of python interpreter compile-time preprocessor defines that -// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; -// this allows using them conditional cfg attributes in the .rs files, so -// -// #[cfg(py_sys_config="{varname}"] -// -// is the equivalent of #ifdef {varname} name in C. -// -// see Misc/SpecialBuilds.txt in the python source for what these mean. -// -// (hrm, this is sort of re-implementing what distutils does, except -// by passing command line args instead of referring to a python.h) +/// A list of python interpreter compile-time preprocessor defines that +/// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; +/// this allows using them conditional cfg attributes in the .rs files, so +/// +/// #[cfg(py_sys_config="{varname}"] +/// +/// is the equivalent of #ifdef {varname} name in C. +/// +/// see Misc/SpecialBuilds.txt in the python source for what these mean. +/// +/// (hrm, this is sort of re-implementing what distutils does, except +/// by passing command line args instead of referring to a python.h) #[cfg(not(target_os = "windows"))] static SYSCONFIG_FLAGS: [&'static str; 7] = [ "Py_USING_UNICODE", @@ -370,6 +370,7 @@ print(sys.exec_prefix) if self.is_pypy() { println!("cargo:rustc-cfg=PyPy"); + println!("cargo:rustc-cfg=py_sys_config=\"WITH_THREAD\""); flags += format!("CFG_PyPy").as_ref(); }; @@ -460,8 +461,11 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result Vec { let mut possible_names = vec![]; - let binary_name = format!("{:?}", self.kind).to_ascii_lowercase(); + let binary_name = match self.kind { + PythonInterpreterKind::CPython => "python", + PythonInterpreterKind::PyPy => "pypy" + }; - possible_names.push(binary_name.clone()); - possible_names.push(format!("{}{}", &binary_name, self.major)); + possible_names.push(binary_name.to_owned()); + possible_names.push(format!("{}{}", binary_name, self.major)); if let Some(minor) = self.minor { - possible_names.push(format!("{}{}.{}", &binary_name, self.major, minor)); + possible_names.push(format!("{}{}.{}", binary_name, self.major, minor)); } possible_names diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 5e2e1382a79..8e78df874be 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -65,7 +65,7 @@ extern "C" { pub fn PyEval_GetCallStats(arg1: *mut PyObject) -> *mut PyObject; pub fn PyEval_EvalFrame(arg1: *mut crate::ffi3::PyFrameObject) -> *mut PyObject; #[cfg(Py_3_6)] - pub fn _PyEval_EvalFrameDefault(arg1: *mut ::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; + pub fn _PyEval_EvalFrameDefault(arg1: *mut crate::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; #[cfg(Py_3_6)] pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int; pub fn PyEval_EvalFrameEx(f: *mut crate::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index b22c84770fa..b7a0a194ced 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -20,7 +20,7 @@ pub type PyCFunction = pub type _PyCFunctionFast = unsafe extern "C" fn( slf: *mut PyObject, args: *mut *mut PyObject, - nargs: ::ffi3::pyport::Py_ssize_t, + nargs: crate::ffi3::pyport::Py_ssize_t, kwnames: *mut PyObject, ) -> *mut PyObject; diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index e9df79c865b..fc590f025bc 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -632,7 +632,6 @@ mod typeobject { // The exported types depend on whether Py_LIMITED_API is set pub use self::typeobject::*; -use crate::ffi3::pyerrors::{PyErr_Format, PyExc_TypeError}; #[repr(C)] #[derive(Copy, Clone)] From dbd1501a5a7f28787556d9430cd7faec2868e1e0 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 12:32:09 +0200 Subject: [PATCH 047/138] it builds! --- build.rs | 7 +++++++ pyo3build/src/py_interpreter.rs | 13 ++----------- src/ffi3/object.rs | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/build.rs b/build.rs index 5f55c9670c4..51c039cee7d 100644 --- a/build.rs +++ b/build.rs @@ -41,6 +41,13 @@ fn main() { let flags = interpreter_config.emit_cargo_vars(); + for (key, val) in &config_map { + match cfg_line_for_var(key, val) { + Some(line) => println!("{}", line), + None => (), + } + } + // 2. Export python interpreter compilation flags as cargo variables that // will be visible to dependents. All flags will be available to dependent // build scripts in the environment variable DEP_PYTHON27_PYTHON_FLAGS as diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 1399f1eea2c..f78511d4146 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -232,6 +232,7 @@ print(sys.exec_prefix) ); if self.is_pypy() { + all_vars.insert("WITH_THREAD".to_owned(), "1".to_owned()); all_vars.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); all_vars.insert("Py_UNICODE_SIZE".to_owned(), "4".to_owned()); all_vars.insert("Py_UNICODE_WIDE".to_owned(), "1".to_owned()); @@ -242,6 +243,7 @@ print(sys.exec_prefix) } else { false }; + if debug { all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); @@ -370,7 +372,6 @@ print(sys.exec_prefix) if self.is_pypy() { println!("cargo:rustc-cfg=PyPy"); - println!("cargo:rustc-cfg=py_sys_config=\"WITH_THREAD\""); flags += format!("CFG_PyPy").as_ref(); }; @@ -394,16 +395,6 @@ print(sys.exec_prefix) return flags; } - - fn fix_config_map(mut config_map: HashMap) -> HashMap { - if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) { - config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); - } - - config_map - } } pub fn is_value(key: &str) -> bool { diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index fc590f025bc..a3a18c46973 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -84,8 +84,8 @@ macro_rules! cstr( #[cfg(PyPy)] pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { - return PyErr_Format( - PyExc_TypeError, + return crate::ffi3::pyerrors::PyErr_Format( + crate::ffi3::pyerrors::PyExc_TypeError, cstr!("'%.200s' object is not iterable").as_ptr(), Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), ); From 15d9e58e1743a9df2dd193e6e4911305f491728d Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 13:22:38 +0200 Subject: [PATCH 048/138] it builds and runs --- pyo3build/src/py_interpreter.rs | 10 ++++++---- src/ffi3/object.rs | 9 +-------- src/ffi3/pyerrors.rs | 23 +++++++++++++++++++++++ src/lib.rs | 9 +-------- src/macros.rs | 9 +++++++++ 5 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 src/macros.rs diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index f78511d4146..8aa5445d46f 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -61,6 +61,7 @@ impl InterpreterConfig { /// Tries to read interpreter configuration from path to interpreter. pub fn from_path(interpreter: impl AsRef) -> Result { let version = PythonVersion::from_interpreter(&interpreter)?; + InterpreterConfig::ensure_python_version_is_supported(&version)?; match version.kind { PythonInterpreterKind::PyPy => { @@ -139,12 +140,13 @@ print(sys.exec_prefix) let patchlevel_defines = parse_header_defines(python_include_dir.join("patchlevel.h"))?; let version = PythonVersion::from_cross_env(&patchlevel_defines)?; + InterpreterConfig::ensure_python_version_is_supported(&version)?; let config_map = parse_header_defines(python_include_dir.join("pyconfig.h"))?; let enable_shared: bool = config_map .get("Py_ENABLE_SHARED") - .ok_or("Py_ENABLE_SHARED undefined".to_string())? + .ok_or_else(|| "Py_ENABLE_SHARED undefined".to_string())? .parse() .map_err(|e| "Failed to `Py_ENABLE_SHARED`".to_string())?; @@ -172,8 +174,8 @@ print(sys.exec_prefix) } /// Checks if interpreter is supported by PyO3 - fn assert_python_version_is_supported(&self) -> Result<(), String> { - match (self.version.major, self.version.minor) { + fn ensure_python_version_is_supported(version: &PythonVersion) -> Result<(), String> { + match (version.major, version.minor) { (3, Some(minor)) if minor < PY3_MIN_MINOR => Err(format!( "Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor @@ -398,7 +400,7 @@ print(sys.exec_prefix) } pub fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() + SYSCONFIG_VALUES.iter().any(|x| *x == key) } pub fn cfg_line_for_var(key: &str, val: &str) -> Option { diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index a3a18c46973..1a17f80ddfd 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -73,14 +73,6 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { (*ob).ob_refcnt } -macro_rules! cstr( - ($s: tt) => ( - // TODO: verify that $s is a string literal without nuls - unsafe { - ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) - } - ); -); #[cfg(PyPy)] pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { @@ -754,6 +746,7 @@ extern "C" { ) -> c_int; #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")] pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttr")] pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index e175972710d..91305366e9c 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -1,4 +1,5 @@ use crate::ffi3::object::*; +use crate::ffi3::objectabstract::PyObject_CallFunction; use crate::ffi3::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; @@ -74,6 +75,27 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { (*x).ob_type as *mut PyObject } +// ported from cpython exception.c (line 2096) +#[cfg(PyPy)] +pub unsafe fn PyUnicodeDecodeError_Create( + encoding: *const c_char, + object: *const c_char, + length: Py_ssize_t, + start: Py_ssize_t, + end: Py_ssize_t, + reason: *const c_char, +) -> *mut PyObject { + return PyObject_CallFunction( + PyExc_UnicodeDecodeError, + cstr!("sy#nns").as_ptr(), + encoding, + object, + length, + start, + end, + ); +} + #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")] @@ -276,6 +298,7 @@ extern "C" { pub fn PyErr_SyntaxLocation(filename: *const c_char, lineno: c_int) -> (); pub fn PyErr_SyntaxLocationEx(filename: *const c_char, lineno: c_int, col_offset: c_int) -> (); pub fn PyErr_ProgramText(filename: *const c_char, lineno: c_int) -> *mut PyObject; + #[cfg(not(PyPy))] pub fn PyUnicodeDecodeError_Create( encoding: *const c_char, object: *const c_char, diff --git a/src/lib.rs b/src/lib.rs index 87559330094..64a757a6fc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,6 +118,7 @@ //! } //! ``` +#[macro_use] mod macros; pub use crate::class::*; pub use crate::conversion::{ AsPyPointer, FromPy, FromPyObject, IntoPy, IntoPyObject, IntoPyPointer, PyTryFrom, PyTryInto, @@ -149,14 +150,6 @@ mod ffi3; pub mod class; -/// Constructs a `&'static CStr` literal. -macro_rules! cstr { - ($s: tt) => { - // TODO: verify that $s is a string literal without nuls - unsafe { ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) } - }; -} - pub mod buffer; #[doc(hidden)] pub mod callback; diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 00000000000..a55ce5a032c --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,9 @@ + +#[macro_export] +/// Constructs a `&'static CStr` literal. +macro_rules! cstr { + ($s: tt) => { + // TODO: verify that $s is a string literal without nuls + unsafe { ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) } + }; +} From 30d02b373280ff5b1d67f8f40742f5f7c5eeb806 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 13:24:57 +0200 Subject: [PATCH 049/138] revert everything in FFI2 --- src/ffi2/boolobject.rs | 21 +- src/ffi2/bufferobject.rs | 45 +- src/ffi2/bytearrayobject.rs | 38 +- src/ffi2/bytesobject.rs | 32 +- src/ffi2/cellobject.rs | 25 +- src/ffi2/ceval.rs | 68 +-- src/ffi2/classobject.rs | 85 ++-- src/ffi2/cobject.rs | 35 +- src/ffi2/code.rs | 96 ++-- src/ffi2/compile.rs | 38 +- src/ffi2/complexobject.rs | 52 +- src/ffi2/descrobject.rs | 91 ++-- src/ffi2/dictobject.rs | 87 ++-- src/ffi2/enumobject.rs | 6 +- src/ffi2/eval.rs | 36 +- src/ffi2/fileobject.rs | 84 ++-- src/ffi2/floatobject.rs | 42 +- src/ffi2/frameobject.rs | 79 ++- src/ffi2/funcobject.rs | 35 +- src/ffi2/genobject.rs | 29 +- src/ffi2/import.rs | 118 ++--- src/ffi2/intobject.rs | 57 ++- src/ffi2/iterobject.rs | 14 +- src/ffi2/listobject.rs | 80 ++- src/ffi2/longobject.rs | 128 ++--- src/ffi2/memoryobject.rs | 44 +- src/ffi2/methodobject.rs | 110 ++-- src/ffi2/mod.rs | 162 +++--- src/ffi2/modsupport.rs | 174 +++---- src/ffi2/moduleobject.rs | 43 +- src/ffi2/object.rs | 597 ++++++++++------------ src/ffi2/objectabstract.rs | 506 ++++++++----------- src/ffi2/objimpl.rs | 64 +-- src/ffi2/pyarena.rs | 9 +- src/ffi2/pycapsule.rs | 54 +- src/ffi2/pydebug.rs | 23 +- src/ffi2/pyerrors.rs | 291 +++++------ src/ffi2/pymem.rs | 4 +- src/ffi2/pyport.rs | 5 +- src/ffi2/pystate.rs | 80 ++- src/ffi2/pythonrun.rs | 196 +++----- src/ffi2/rangeobject.rs | 13 +- src/ffi2/setobject.rs | 62 +-- src/ffi2/sliceobject.rs | 62 +-- src/ffi2/stringobject.rs | 194 ++++---- src/ffi2/structmember.rs | 66 +-- src/ffi2/traceback.rs | 29 +- src/ffi2/tupleobject.rs | 56 +-- src/ffi2/unicodeobject.rs | 969 +++++++++++++----------------------- src/ffi2/warnings.rs | 30 +- src/ffi2/weakrefobject.rs | 52 +- 51 files changed, 2172 insertions(+), 3144 deletions(-) diff --git a/src/ffi2/boolobject.rs b/src/ffi2/boolobject.rs index 145a0a3b222..1ea79af49b5 100644 --- a/src/ffi2/boolobject.rs +++ b/src/ffi2/boolobject.rs @@ -1,33 +1,28 @@ -use crate::ffi2::intobject::PyIntObject; -use crate::ffi2::object::*; use std::os::raw::{c_int, c_long}; +use ffi2::object::*; +use ffi2::intobject::PyIntObject; pub type PyBoolObject = PyIntObject; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyBool_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "_PyPy_ZeroStruct")] static mut _Py_ZeroStruct: PyIntObject; - #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyIntObject; - #[cfg_attr(PyPy, link_name = "PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } -#[cfg_attr(PyPy, link_name = "PyPyBool_Check")] -pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyBool_Type; +#[inline(always)] +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] +#[inline(always)] pub unsafe fn Py_False() -> *mut PyObject { &mut _Py_ZeroStruct as *mut PyBoolObject as *mut PyObject } -#[inline] +#[inline(always)] pub unsafe fn Py_True() -> *mut PyObject { &mut _Py_TrueStruct as *mut PyBoolObject as *mut PyObject } diff --git a/src/ffi2/bufferobject.rs b/src/ffi2/bufferobject.rs index 8e01ea1aad0..868ef0d3e71 100644 --- a/src/ffi2/bufferobject.rs +++ b/src/ffi2/bufferobject.rs @@ -1,37 +1,28 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; -use std::os::raw::{c_int, c_void}; +use std::os::raw::{c_void, c_int}; +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyBuffer_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyBuffer_Type: PyTypeObject; } -pub unsafe fn PyBuffer_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyBuffer_Type; + +#[inline(always)] +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" { - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromObject")] - pub fn PyBuffer_FromObject( - base: *mut PyObject, - offset: Py_ssize_t, - size: Py_ssize_t, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteObject")] - pub fn PyBuffer_FromReadWriteObject( - base: *mut PyObject, - offset: Py_ssize_t, - size: Py_ssize_t, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromMemory")] - pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteMemory")] - pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_New")] +#[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; } diff --git a/src/ffi2/bytearrayobject.rs b/src/ffi2/bytearrayobject.rs index bab35e12d88..a5c529010f5 100644 --- a/src/ffi2/bytearrayobject.rs +++ b/src/ffi2/bytearrayobject.rs @@ -1,6 +1,6 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; /*#[repr(C)] #[deriving(Copy)] @@ -17,41 +17,33 @@ struct PyByteArrayObject { pub ob_bytes: *mut c_char, }*/ -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name = "PyPyByteArray_Check")] -pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int { +pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyByteArray_Type) } -#[cfg_attr(PyPy, link_name = "PyPyByteArray_CheckExact")] -pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &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" { - #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromObject")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Concat")] - pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromStringAndSize")] - pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Size")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Resize")] - pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; + pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) + -> c_int; } -#[inline] +#[inline(always)] pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char { PyByteArray_AsString(o) // #define PyByteArray_AS_STRING(self) \ @@ -59,7 +51,7 @@ pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char { // Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string) } -#[inline] +#[inline(always)] 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) diff --git a/src/ffi2/bytesobject.rs b/src/ffi2/bytesobject.rs index b27b0896169..51d4988124e 100644 --- a/src/ffi2/bytesobject.rs +++ b/src/ffi2/bytesobject.rs @@ -1,16 +1,16 @@ -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; +pub use ffi2::stringobject::PyStringObject as PyBytesObject; +pub use ffi2::stringobject::PyString_Type as PyBytes_Type; +pub use ffi2::stringobject::PyString_Check as PyBytes_Check; +pub use ffi2::stringobject::PyString_CheckExact as PyBytes_CheckExact; +pub use ffi2::stringobject::PyString_AS_STRING as PyBytes_AS_STRING; +pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; +pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; +pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; +pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString; +pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat; +pub use ffi2::stringobject::PyString_Size as PyBytes_Size; +pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString; +pub use ffi2::stringobject::PyString_Concat as PyBytes_Concat; +pub use ffi2::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel; +pub use ffi2::stringobject::PyString_Format as PyBytes_Format; +pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; diff --git a/src/ffi2/cellobject.rs b/src/ffi2/cellobject.rs index 5d13f5196e6..3edb4e5742a 100644 --- a/src/ffi2/cellobject.rs +++ b/src/ffi2/cellobject.rs @@ -1,43 +1,40 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] struct PyCellObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub ob_ref: *mut PyObject } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCell_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyCell_Type: PyTypeObject; } -#[inline] +#[inline(always)] pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyCell_Type) as c_int + (Py_TYPE(op) == &mut PyCell_Type) as c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyCell_New(obj: *mut PyObject) -> *mut PyObject; pub fn PyCell_Get(op: *mut PyObject) -> *mut PyObject; pub fn PyCell_Set(op: *mut PyObject, obj: *mut PyObject) -> c_int; } -#[inline] +#[inline(always)] pub unsafe fn PyCell_GET(op: *mut PyObject) -> *mut PyObject { (*(op as *mut PyCellObject)).ob_ref } -#[inline] +#[inline(always)] pub unsafe fn PyCell_SET(op: *mut PyObject, obj: *mut PyObject) { (*(op as *mut PyCellObject)).ob_ref = obj; } diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 05a29f3970b..316ca0a1e38 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -1,50 +1,33 @@ -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}; +use std::os::raw::{c_void, c_char, c_int}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::PyObject; +use ffi2::frameobject::PyFrameObject; +use ffi2::pystate::{PyThreadState, Py_tracefunc}; +use ffi2::pythonrun::PyCompilerFlags; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyEval_CallObjectWithKeywords")] - pub fn PyEval_CallObjectWithKeywords( - callable: *mut PyObject, - args: *mut PyObject, - kwds: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_CallFunction")] - pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_CallMethod")] - pub fn PyEval_CallMethod( - obj: *mut PyObject, - methodname: *const c_char, - format: *const c_char, - ... - ) -> *mut PyObject; +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject, + args: *mut PyObject, + kwds: *mut PyObject) -> *mut PyObject; + pub fn PyEval_CallFunction(obj: *mut PyObject, + format: *const c_char, ...) -> *mut PyObject; + pub fn PyEval_CallMethod(obj: *mut PyObject, + methodname: *const c_char, + format: *const c_char, ...) -> *mut PyObject; pub fn PyEval_SetProfile(func: Option, obj: *mut PyObject); pub fn PyEval_SetTrace(func: Option, obj: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut PyFrameObject; pub fn PyEval_GetRestricted() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyEval_MergeCompilerFlags")] pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int; pub fn Py_FlushLine() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_AddPendingCall")] - pub fn Py_AddPendingCall( - func: Option c_int>, - arg: *mut c_void, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_MakePendingCalls")] + pub fn Py_AddPendingCall(func: Option c_int>, + arg: *mut c_void) -> c_int; pub fn Py_MakePendingCalls() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int); - #[cfg_attr(PyPy, link_name = "PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; @@ -53,27 +36,20 @@ extern "C" { 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; - #[cfg_attr(PyPy, link_name = "PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState); - - #[cfg_attr(PyPy, link_name = "_PyPyEval_SliceIndex")] + 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" { - #[cfg_attr(PyPy, link_name = "PyPyEval_ThreadsInitialized")] +#[cfg(py_sys_config="WITH_THREAD")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyEval_ThreadsInitialized() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyEval_InitThreads")] pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); pub fn PyEval_ReleaseLock(); - #[cfg_attr(PyPy, link_name = "PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); - #[cfg_attr(PyPy, link_name = "PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); } + diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index d2935e5cf16..a11e49d1374 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -1,13 +1,13 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyClassObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -23,9 +23,9 @@ pub struct PyClassObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PyInstanceObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -37,9 +37,9 @@ pub struct PyInstanceObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PyMethodObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -49,76 +49,61 @@ pub struct PyMethodObject { pub im_weakreflist: *mut PyObject, } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyClass_Type: PyTypeObject; - // TODO: check why this symbol isn't exported by libpypy - #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyInstance_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyMethod_Type")] pub static mut PyMethod_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyClass_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyClass_Type; +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(always)] -pub unsafe fn PyInstance_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyInstance_Type; +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(always)] -#[cfg_attr(PyPy, link_name = "PyPyMethod_Check")] -pub unsafe fn PyMethod_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyMethod_Type; +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; - #[cfg_attr(PyPy, link_name = "PyPyMethod_New")] - pub fn PyMethod_New( - arg1: *mut PyObject, - arg2: *mut PyObject, - arg3: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMethod_Function")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyMethod_Self")] pub fn PyMethod_Self(arg1: *mut PyObject) -> *mut PyObject; pub fn PyMethod_Class(arg1: *mut PyObject) -> *mut PyObject; - fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) -> *mut PyObject; - pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) + -> *mut PyObject; + pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) + -> c_int; pub fn PyMethod_ClearFreeList() -> c_int; } -#[inline] -pub unsafe fn PyMethod_GET_FUNCTION(meth: *mut PyObject) -> *mut PyObject { +#[inline(always)] +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 { +#[inline(always)] +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 { +#[inline(always)] +pub unsafe fn PyMethod_GET_CLASS(meth : *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_class } + diff --git a/src/ffi2/cobject.rs b/src/ffi2/cobject.rs index c28d6a9cf13..b655ae39a08 100644 --- a/src/ffi2/cobject.rs +++ b/src/ffi2/cobject.rs @@ -1,36 +1,27 @@ -use crate::ffi2::object::*; -use std::os::raw::{c_char, c_int, c_void}; +use std::os::raw::{c_void, c_char, c_int}; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCObject_Type")] +#[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 { +#[inline(always)] +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" { - #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtr")] - pub fn PyCObject_FromVoidPtr( - cobj: *mut c_void, - destruct: Option, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtrAndDesc")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyCObject_FromVoidPtr(cobj: *mut c_void, + destruct: Option) + -> *mut PyObject; pub fn PyCObject_FromVoidPtrAndDesc( cobj: *mut c_void, desc: *mut c_void, - destruct: Option, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCObject_AsVoidPtr")] + destruct: Option) + -> *mut PyObject; pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCObject_GetDesc")] pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCObject_Import")] - pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCObject_SetVoidPtr")] + 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; } diff --git a/src/ffi2/code.rs b/src/ffi2/code.rs index 4a11c5a506d..0402e8ef35b 100644 --- a/src/ffi2/code.rs +++ b/src/ffi2/code.rs @@ -1,13 +1,13 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int, c_void}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyCodeObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -30,74 +30,58 @@ pub struct PyCodeObject { } /* 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; +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_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_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; +pub const CO_MAXBLOCKS : usize = 20; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyCode_Type: PyTypeObject; - - #[cfg_attr(PyPy, link_name = "PyPyCode_New")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyCode_Check")] + + 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; + 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 { +#[inline(always)] +pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCode_Type) as c_int } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")] -pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { - crate::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) +pub unsafe fn PyCode_GetNumFree(op : *mut PyCodeObject) -> Py_ssize_t { + ::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } + diff --git a/src/ffi2/compile.rs b/src/ffi2/compile.rs index 8de22215bfa..a136e8f5104 100644 --- a/src/ffi2/compile.rs +++ b/src/ffi2/compile.rs @@ -1,7 +1,7 @@ -use crate::ffi2::code::*; -use crate::ffi2::pyarena::PyArena; -use crate::ffi2::pythonrun::*; use std::os::raw::{c_char, c_int}; +use ffi2::pythonrun::*; +use ffi2::code::*; +use ffi2::pyarena::PyArena; #[repr(C)] #[derive(Copy, Clone)] @@ -10,22 +10,20 @@ pub struct PyFutureFeatures { 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"; +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; +#[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; } diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index 23da782ba10..f0d1b9d2808 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -1,16 +1,15 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_double, c_int}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct Py_complex { pub real: c_double, - pub imag: c_double, + pub imag: c_double } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn _Py_c_sum(left: Py_complex, right: Py_complex) -> Py_complex; pub fn _Py_c_diff(left: Py_complex, right: Py_complex) -> Py_complex; pub fn _Py_c_neg(complex: Py_complex) -> Py_complex; @@ -23,49 +22,42 @@ extern "C" { #[repr(C)] #[derive(Copy, Clone)] pub struct PyComplexObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub cval: Py_complex } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyComplex_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyComplex_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name = "PyPyComplex_Check")] -#[inline] -pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } -#[cfg_attr(PyPy, link_name = "PyPyComplex_CheckExact")] -#[inline] -pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyComplex_Type; +#[inline(always)] +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" { - #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")] - pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")] + pub fn PyComplex_FromDoubles(real: c_double, + imag: c_double) -> *mut PyObject; pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")] 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; + //fn _PyComplex_FormatAdvanced(obj: *mut PyObject, + // format_spec: *mut c_char, + // format_spec_len: Py_ssize_t) + // -> *mut PyObject; } + diff --git a/src/ffi2/descrobject.rs b/src/ffi2/descrobject.rs index a8c1d12ffd7..6a06c56ced5 100644 --- a/src/ffi2/descrobject.rs +++ b/src/ffi2/descrobject.rs @@ -1,13 +1,16 @@ -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; +use std::os::raw::{c_void, c_char, c_int}; +use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; +use ffi2::structmember::PyMemberDef; +use ffi2::methodobject::PyMethodDef; -pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; +pub type getter = + unsafe extern "C" fn + (slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; pub type setter = - unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int; + unsafe extern "C" fn (slf: *mut PyObject, value: *mut PyObject, + closure: *mut c_void) -> c_int; #[repr(C)] #[derive(Copy)] @@ -19,7 +22,7 @@ pub struct PyGetSetDef { pub closure: *mut c_void, } -pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef { +pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { name: ptr::null_mut(), get: None, set: None, @@ -28,24 +31,16 @@ pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef { }; impl Clone for PyGetSetDef { - #[inline] - fn clone(&self) -> PyGetSetDef { - *self - } + #[inline] fn clone(&self) -> PyGetSetDef { *self } } -pub type wrapperfunc = unsafe extern "C" fn( - slf: *mut PyObject, - args: *mut PyObject, - wrapped: *mut c_void, -) -> *mut PyObject; +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; +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)] @@ -56,53 +51,47 @@ pub struct wrapperbase { pub wrapper: Option, pub doc: *mut c_char, pub flags: c_int, - pub name_strobj: *mut PyObject, + pub name_strobj: *mut PyObject } impl Clone for wrapperbase { - #[inline] - fn clone(&self) -> wrapperbase { - *self - } + #[inline] fn clone(&self) -> wrapperbase { *self } } -pub const PyWrapperFlag_KEYWORDS: c_int = 1; +pub const PyWrapperFlag_KEYWORDS : c_int = 1; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyWrapperDescr_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyWrapperDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; - pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDescr_NewClassMethod")] - 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; + 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] +#[inline(always)] pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int { (*Py_TYPE(d)).tp_descr_set.is_some() as c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { //pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject; // PyDictProxy_New is also defined in dictobject.h - pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) + -> *mut PyObject; } + + + + diff --git a/src/ffi2/dictobject.rs b/src/ffi2/dictobject.rs index 97fdb11a1fe..57263ac2bb0 100644 --- a/src/ffi2/dictobject.rs +++ b/src/ffi2/dictobject.rs @@ -1,12 +1,10 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; //pub enum PyDictObject { /* representation hidden */ } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyDict_Type")] +#[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; @@ -16,62 +14,45 @@ extern "C" { pub static mut PyDictValues_Type: PyTypeObject; } -#[inline] -pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +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; +#[inline(always)] +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" { - #[cfg_attr(PyPy, link_name = "PyPyDict_New")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyDict_New() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyDict_Contains")] - pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_Copy")] + pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) + -> c_int; pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; - - #[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")] - pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_SetItem")] - pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_DelItem")] - pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemString")] - pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_SetItemString")] - pub fn PyDict_SetItemString( - dp: *mut PyObject, - key: *const c_char, - item: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")] - pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; - - #[cfg_attr(PyPy, link_name = "PyPyDict_Keys")] + + 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; - #[cfg_attr(PyPy, link_name = "PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyDict_Next")] - pub fn PyDict_Next( - mp: *mut PyObject, - pos: *mut Py_ssize_t, - key: *mut *mut PyObject, - value: *mut *mut PyObject, - ) -> c_int; + pub fn PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, + key: *mut *mut PyObject, value: *mut *mut PyObject) + -> c_int; /*pub fn _PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject, hash: *mut c_long) -> c_int; @@ -79,10 +60,12 @@ extern "C" { hash: c_long) -> c_int; pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/ - #[cfg_attr(PyPy, link_name = "PyPyDict_Update")] - pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_Merge")] - pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject, _override: c_int) -> c_int; - pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject, _override: c_int) -> c_int; + pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) + -> c_int; + pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject, + _override: c_int) -> c_int; + pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject, + _override: c_int) -> c_int; } + diff --git a/src/ffi2/enumobject.rs b/src/ffi2/enumobject.rs index 07e84b7a5fe..50424901292 100644 --- a/src/ffi2/enumobject.rs +++ b/src/ffi2/enumobject.rs @@ -1,7 +1,7 @@ -use crate::ffi2::object::PyTypeObject; +use ffi2::object::PyTypeObject; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyEnum_Type: PyTypeObject; pub static mut PyReversed_Type: PyTypeObject; } + diff --git a/src/ffi2/eval.rs b/src/ffi2/eval.rs index b36b28c56c0..4a2660f78e7 100644 --- a/src/ffi2/eval.rs +++ b/src/ffi2/eval.rs @@ -1,26 +1,16 @@ -use crate::ffi2::code::PyCodeObject; -use crate::ffi2::object::PyObject; use std::os::raw::c_int; +use ffi2::object::PyObject; +use ffi2::code::PyCodeObject; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyEval_EvalCode")] - pub fn PyEval_EvalCode( - arg1: *mut PyCodeObject, - arg2: *mut PyObject, - arg3: *mut PyObject, - ) -> *mut PyObject; - pub fn PyEval_EvalCodeEx( - co: *mut PyCodeObject, - globals: *mut PyObject, - locals: *mut PyObject, - args: *mut *mut PyObject, - argc: c_int, - kwds: *mut *mut PyObject, - kwdc: c_int, - defs: *mut *mut PyObject, - defc: c_int, - closure: *mut PyObject, - ) -> *mut PyObject; - fn _PyEval_CallTracing(func: *mut PyObject, args: *mut PyObject) -> *mut PyObject; +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyEval_EvalCode(arg1: *mut PyCodeObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> *mut PyObject; + pub fn PyEval_EvalCodeEx(co: *mut PyCodeObject, globals: *mut PyObject, + locals: *mut PyObject, args: *mut *mut PyObject, + argc: c_int, kwds: *mut *mut PyObject, + kwdc: c_int, defs: *mut *mut PyObject, + defc: c_int, closure: *mut PyObject) + -> *mut PyObject; + fn _PyEval_CallTracing(func: *mut PyObject, args: *mut PyObject) + -> *mut PyObject; } diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index 5fb1faf59bf..6838ca3e723 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -1,69 +1,59 @@ -use crate::ffi2::object::*; use libc::{size_t, FILE}; use std::os::raw::{c_char, c_int}; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyFile_Type: PyTypeObject; } -#[inline] -pub unsafe fn PyFile_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +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 { +#[inline(always)] +pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFile_Type) as c_int } -pub const PY_STDIOTEXTMODE: &'static str = "b"; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFile_FromString")] - pub fn PyFile_FromString(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFile_SetBufSize")] +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; - #[cfg_attr(PyPy, link_name = "PyPyFile_FromFile")] - pub fn PyFile_FromFile( - arg1: *mut FILE, - arg2: *mut c_char, - arg3: *mut c_char, - arg4: Option c_int>, - ) -> *mut PyObject; + pub fn PyFile_SetEncoding(arg1: *mut PyObject, + arg2: *const c_char) -> c_int; + pub fn PyFile_SetEncodingAndErrors(arg1: *mut PyObject, + arg2: *const c_char, + errors: *mut c_char) + -> c_int; + pub fn PyFile_FromFile(arg1: *mut FILE, arg2: *mut c_char, + arg3: *mut c_char, + arg4: Option 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); - #[cfg_attr(PyPy, link_name = "PyPyFile_Name")] pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFile_GetLine")] - pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFile_WriteObject")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyFile_WriteString")] - pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsFileDescriptor")] + pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) + -> *mut PyObject; + pub fn PyFile_WriteObject(arg1: *mut PyObject, arg2: *mut PyObject, + arg3: c_int) -> c_int; + pub fn PyFile_SoftSpace(arg1: *mut PyObject, arg2: c_int) + -> c_int; + pub fn PyFile_WriteString(arg1: *const c_char, + arg2: *mut PyObject) -> c_int; pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int; - pub fn Py_UniversalNewlineFgets( - arg1: *mut c_char, - arg2: c_int, - arg3: *mut FILE, - arg4: *mut PyObject, - ) -> *mut c_char; - pub fn Py_UniversalNewlineFread( - arg1: *mut c_char, - arg2: size_t, - arg3: *mut FILE, - arg4: *mut PyObject, - ) -> size_t; + pub fn Py_UniversalNewlineFgets(arg1: *mut c_char, + arg2: c_int, arg3: *mut FILE, + arg4: *mut PyObject) + -> *mut c_char; + pub fn Py_UniversalNewlineFread(arg1: *mut c_char, arg2: size_t, + arg3: *mut FILE, arg4: *mut PyObject) + -> size_t; pub static mut Py_FileSystemDefaultEncoding: *const c_char; } + diff --git a/src/ffi2/floatobject.rs b/src/ffi2/floatobject.rs index 9ea642f52a2..faa0688b47f 100644 --- a/src/ffi2/floatobject.rs +++ b/src/ffi2/floatobject.rs @@ -1,47 +1,41 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; -use std::os::raw::{c_char, c_double, c_int}; +use std::os::raw::{c_char, c_int, c_double}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] struct PyFloatObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub ob_fval: c_double } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFloat_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyFloat_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyFloat_Check")] -pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyFloat_CheckExact")] -pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyFloat_Type; +#[inline(always)] +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; +pub const PyFloat_STR_PRECISION : c_int = 12; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFloat_FromString")] - pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFloat_FromDouble")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; @@ -50,7 +44,7 @@ extern "C" { pub fn PyFloat_ClearFreeList() -> c_int; } -#[cfg_attr(PyPy, link_name = "PyPyFloat_AS_DOUBLE")] pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double { (*(pyfloat as *mut PyFloatObject)).ob_fval } + diff --git a/src/ffi2/frameobject.rs b/src/ffi2/frameobject.rs index 80ca7c4c2df..004b5440655 100644 --- a/src/ffi2/frameobject.rs +++ b/src/ffi2/frameobject.rs @@ -1,38 +1,38 @@ -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; +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use ffi2::code::{PyCodeObject, CO_MAXBLOCKS}; +use ffi2::pystate::PyThreadState; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTryBlock { - pub b_type: c_int, - pub b_handler: c_int, - pub b_level: c_int, + 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")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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 */ + 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. */ + 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_trace: *mut PyObject, /* Trace function */ pub f_exc_type: *mut PyObject, pub f_exc_value: *mut PyObject, @@ -40,26 +40,25 @@ pub struct PyFrameObject { pub f_tstate: *mut PyThreadState, - pub f_lasti: c_int, /* Last instruction if called */ + 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 */ + 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 */ + pub f_localsplus: [*mut PyObject; 1] /* locals+stack, dynamically sized */ } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyFrame_Type: PyTypeObject; } #[inline] pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { - ((*op).ob_type == &mut PyFrame_Type) as c_int + ((*op).ob_type == &mut PyFrame_Type) as c_int } //#[inline] @@ -67,27 +66,17 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { // ((*f).f_builtins != (*(*(*f).f_tstate).interp).builtins) as c_int //} -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFrame_New")] - pub fn PyFrame_New( - tstate: *mut PyThreadState, - code: *mut PyCodeObject, - globals: *mut PyObject, - locals: *mut PyObject, - ) -> *mut PyFrameObject; +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, + globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; - pub fn PyFrame_BlockSetup( - f: *mut PyFrameObject, - _type: c_int, - handler: c_int, - level: c_int, - ) -> (); + pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int) -> (); pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock; pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> (); pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> (); - + pub fn PyFrame_ClearFreeList() -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; } + diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index a03f964f71e..075116a32ab 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -1,37 +1,34 @@ -use crate::ffi2::object::*; use std::os::raw::c_int; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFunction_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyFunction_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyFunction_Check")] -pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyFunction_Type; +#[inline(always)] +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; - #[cfg_attr(PyPy, link_name = "PyPyFunction_GetCode")] + +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) + -> *mut PyObject; pub fn PyFunction_GetCode(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetGlobals(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetModule(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetDefaults(f: *mut PyObject) -> *mut PyObject; - pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) -> c_int; + pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) + -> c_int; pub fn PyFunction_GetClosure(f: *mut PyObject) -> *mut PyObject; - pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) -> c_int; - + pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) + -> c_int; + pub static mut PyClassMethod_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_Type")] pub static mut PyStaticMethod_Type: PyTypeObject; - - #[cfg_attr(PyPy, link_name = "PyPyClassMethod_New")] + pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_New")] pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; } + diff --git a/src/ffi2/genobject.rs b/src/ffi2/genobject.rs index 30742a9cfae..9dd8f2cc3d0 100644 --- a/src/ffi2/genobject.rs +++ b/src/ffi2/genobject.rs @@ -1,42 +1,39 @@ -use crate::ffi2::frameobject::PyFrameObject; -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; +use ffi2::frameobject::PyFrameObject; #[repr(C)] #[derive(Copy, Clone)] pub struct PyGenObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub gi_weakreflist: *mut PyObject } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyGen_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyGen_Check")] +#[inline(always)] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { - PyObject_TypeCheck(op, &mut PyGen_Type) + PyObject_TypeCheck(op, &mut PyGen_Type) } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyGen_CheckExact")] +#[inline(always)] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyGen_Type) as c_int + (Py_TYPE(op) == &mut PyGen_Type) as c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject; pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int; } + diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index 0b67d5287f9..9b0b7b9eda2 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -1,5 +1,5 @@ -use crate::ffi2::object::*; -use std::os::raw::{c_char, c_int, c_long, c_uchar}; +use std::os::raw::{c_char, c_uchar, c_int, c_long}; +use ffi2::object::*; #[repr(C)] #[derive(Copy)] @@ -9,10 +9,7 @@ pub struct PyImport_Struct_inittab { } impl Clone for PyImport_Struct_inittab { - #[inline] - fn clone(&self) -> PyImport_Struct_inittab { - *self - } + #[inline] fn clone(&self) -> PyImport_Struct_inittab { *self } } #[repr(C)] @@ -24,75 +21,66 @@ pub struct PyImport_Struct_frozen { } #[inline] -pub unsafe fn PyImport_ImportModuleEx( - name: *mut c_char, - globals: *mut PyObject, - locals: *mut PyObject, - fromlist: *mut PyObject, -) -> *mut PyObject { +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" { - #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")] - pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")] - 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; +#[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; - #[cfg_attr(PyPy, link_name = "PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModule")] - pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModuleEx")] - pub fn PyImport_ExecCodeModuleEx( - name: *mut c_char, - co: *mut PyObject, - pathname: *mut 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; - #[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")] 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, - ) -> c_int; - pub fn PyImport_ExtendInittab(newtab: *mut PyImport_Struct_inittab) -> c_int; - + pub fn PyImport_ImportFrozenModule(name: *mut c_char) + -> c_int; + + pub fn PyImport_AppendInittab(name: *const c_char, + initfunc: + Option) + -> 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(); -#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_AcquireLock")] -pub fn _PyImport_AcquireLock(); -#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_ReleaseLock")] -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;*/ + + /*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;*/ } + diff --git a/src/ffi2/intobject.rs b/src/ffi2/intobject.rs index 50b5eb355fd..1cb26f646ef 100644 --- a/src/ffi2/intobject.rs +++ b/src/ffi2/intobject.rs @@ -1,46 +1,43 @@ -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}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyIntObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub ob_ival: c_long } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyInt_Type: PyTypeObject; } -#[inline] -pub unsafe fn PyInt_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +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; +#[inline(always)] +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; +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyInt_FromString(str: *mut c_char, + pend: *mut *mut c_char, + base: c_int) -> *mut PyObject; + #[cfg(py_sys_config="Py_USING_UNICODE")] + pub fn PyInt_FromUnicode(u: *mut ::ffi2::unicodeobject::Py_UNICODE, + 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; @@ -48,7 +45,8 @@ extern "C" { pub fn PyInt_AsSsize_t(io: *mut PyObject) -> Py_ssize_t; fn _PyInt_AsInt(io: *mut PyObject) -> c_int; pub fn PyInt_AsUnsignedLongMask(io: *mut PyObject) -> c_ulong; - pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) -> c_ulonglong; + pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) + -> c_ulonglong; pub fn PyInt_GetMax() -> c_long; //fn PyOS_strtoul(arg1: *mut c_char, // arg2: *mut *mut c_char, arg3: c_int) @@ -57,14 +55,15 @@ extern "C" { // 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; + //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 } + diff --git a/src/ffi2/iterobject.rs b/src/ffi2/iterobject.rs index ece1443087c..45bd06a644b 100644 --- a/src/ffi2/iterobject.rs +++ b/src/ffi2/iterobject.rs @@ -1,23 +1,21 @@ -use crate::ffi2::object::*; use std::os::raw::c_int; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCallIter_New")] - pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; + pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) + -> *mut PyObject; } -#[inline] +#[inline(always)] pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PySeqIter_Type) as c_int } -#[inline] +#[inline(always)] pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCallIter_Type) as c_int } diff --git a/src/ffi2/listobject.rs b/src/ffi2/listobject.rs index 1a269b5b9b1..2724e4e6e36 100644 --- a/src/ffi2/listobject.rs +++ b/src/ffi2/listobject.rs @@ -1,13 +1,13 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyListObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -16,73 +16,59 @@ pub struct PyListObject { pub allocated: Py_ssize_t, } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyList_Type")] +#[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 { +#[inline(always)] +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; +#[inline(always)] +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] -#[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] + +// Macro, trading safety for speed +#[inline(always)] 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) + *(*(op as *mut PyListObject)).ob_item.offset(i as isize) } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] +#[inline(always)] 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(always)] -#[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")] 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; + *(*(op as *mut PyListObject)).ob_item.offset(i as isize) = v; } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyList_New")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyList_Size")] pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyList_GetItem")] - pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyList_SetItem")] - pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Insert")] - pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Append")] - pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_GetSlice")] - pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyList_SetSlice")] - pub fn PyList_SetSlice( - list: *mut PyObject, - low: Py_ssize_t, - high: Py_ssize_t, - itemlist: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Sort")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyList_Reverse")] pub fn PyList_Reverse(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")] pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject; -//fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) -//-> *mut PyObject; + //fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) + //-> *mut PyObject; } + diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 4c6001bdaef..3d13c58b94a 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -1,101 +1,83 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_void, c_char, c_int, c_long, c_ulong, c_longlong, c_ulonglong, c_double}; 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, -}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; -/// This is an opaque type in the python c api -#[repr(transparent)] -pub struct PyLongObject(*mut c_void); +//enum PyLongObject { /* representation hidden */ } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyLong_Type")] + +#[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 { +#[inline(always)] +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; +#[inline(always)] +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" { - #[cfg_attr(PyPy, link_name = "PyPyLong_FromLong")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLongLong")] - pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromDouble")] + pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) + -> *mut PyObject; pub fn PyLong_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromString")] - 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")] - #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnicode")] - pub fn PyLong_FromUnicode( - u: *mut crate::ffi2::unicodeobject::Py_UNICODE, - length: Py_ssize_t, - base: c_int, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromVoidPtr")] + 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 ::ffi2::unicodeobject::Py_UNICODE, + length: Py_ssize_t, base: c_int) -> *mut PyObject; pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject; - - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLong")] + pub fn PyLong_AsLong(pylong: *mut PyObject) -> c_long; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongAndOverflow")] - pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLongAndOverflow")] - pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsSsize_t")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLong")] - pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongMask")] + pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) + -> c_ulonglong; pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLongMask")] - pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsDouble")] + pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) + -> c_ulonglong; pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void; - + pub fn PyLong_GetInfo() -> *mut PyObject; - -#[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_FromByteArray")] - 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; + + /* + pub fn _PyLong_AsInt(arg1: *mut PyObject) -> c_int; + pub fn _PyLong_Frexp(a: *mut PyLongObject, e: *mut Py_ssize_t) + -> c_double; + + pub fn _PyLong_Sign(v: *mut PyObject) -> c_int; + pub fn _PyLong_NumBits(v: *mut PyObject) -> size_t; + 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: *mut c_uchar, n: size_t, + little_endian: c_int, + is_signed: c_int) -> c_int; + pub fn _PyLong_Format(aa: *mut PyObject, base: c_int, + addL: c_int, newstyle: c_int) + -> *mut PyObject; + pub fn _PyLong_FormatAdvanced(obj: *mut PyObject, + format_spec: *mut c_char, + format_spec_len: Py_ssize_t) + -> *mut PyObject;*/ } + diff --git a/src/ffi2/memoryobject.rs b/src/ffi2/memoryobject.rs index cfbd1c43a1b..4fded996378 100644 --- a/src/ffi2/memoryobject.rs +++ b/src/ffi2/memoryobject.rs @@ -1,52 +1,46 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; -use std::os::raw::{c_char, c_int}; +use std::os::raw::{c_int, c_char}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyMemoryView_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Check")] -pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyMemoryView_Type; +#[inline(always)] +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 { +#[inline(always)] +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 { +#[inline(always)] +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; - #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromObject")] + +#[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; - #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromBuffer")] 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")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, } + diff --git a/src/ffi2/methodobject.rs b/src/ffi2/methodobject.rs index 30943d649c9..282ad062b09 100644 --- a/src/ffi2/methodobject.rs +++ b/src/ffi2/methodobject.rs @@ -1,39 +1,36 @@ -use crate::ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; -use std::os::raw::{c_char, c_int}; use std::ptr; +use std::os::raw::{c_char, c_int}; +use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCFunction_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyCFunction_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyCFunction_Check")] -pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyCFunction_Type; + +#[inline(always)] +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" { - #[cfg_attr(PyPy, link_name = "PyPyCFunction_GetFunction")] + 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; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; - pub fn PyCFunction_Call( - f: *mut PyObject, - args: *mut PyObject, - kwds: *mut PyObject, - ) -> *mut PyObject; + pub fn PyCFunction_Call(f: *mut PyObject, args: *mut PyObject, + kwds: *mut PyObject) -> *mut PyObject; } #[repr(C)] @@ -45,7 +42,7 @@ pub struct PyMethodDef { pub ml_doc: *const c_char, } -pub const PyMethodDef_INIT: PyMethodDef = PyMethodDef { +pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { ml_name: ::std::ptr::null(), ml_meth: None, ml_flags: 0, @@ -53,32 +50,30 @@ pub const PyMethodDef_INIT: PyMethodDef = PyMethodDef { }; impl Clone for PyMethodDef { - #[inline] - fn clone(&self) -> PyMethodDef { - *self - } + #[inline] fn clone(&self) -> PyMethodDef { *self } } /* Flag passed to newmethodobject */ -pub const METH_OLDARGS: c_int = 0x0000; -pub const METH_VARARGS: c_int = 0x0001; -pub const METH_KEYWORDS: c_int = 0x0002; +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; +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; + 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. */ + 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; -pub const METH_COEXIST: c_int = 0x0040; #[repr(C)] #[derive(Copy, Clone)] @@ -103,29 +98,18 @@ struct PyCFunctionObject { } */ -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPy_FindMethod")] - pub fn Py_FindMethod( - methods: *mut PyMethodDef, - slf: *mut PyObject, - name: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")] - pub fn PyCFunction_NewEx( - ml: *mut PyMethodDef, - slf: *mut PyObject, - module: *mut PyObject, - ) -> *mut PyObject; - pub fn Py_FindMethodInChain( - chain: *mut PyMethodChain, - slf: *mut PyObject, - name: *const c_char, - ) -> *mut PyObject; +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn Py_FindMethod(methods: *mut PyMethodDef, slf: *mut PyObject, + name: *const c_char) -> *mut PyObject; + pub fn PyCFunction_NewEx(ml: *mut PyMethodDef, slf: *mut PyObject, + module: *mut PyObject) -> *mut PyObject; + pub fn Py_FindMethodInChain(chain: *mut PyMethodChain, slf: *mut PyObject, + name: *const c_char) -> *mut PyObject; pub fn PyCFunction_ClearFreeList() -> c_int; } -#[inline] +#[inline(always)] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { PyCFunction_NewEx(ml, slf, ptr::null_mut()) } + diff --git a/src/ffi2/mod.rs b/src/ffi2/mod.rs index 91e4f88a97c..099a33023c0 100644 --- a/src/ffi2/mod.rs +++ b/src/ffi2/mod.rs @@ -1,97 +1,99 @@ //! Rust FFI declarations for Python 2 +#![no_std] #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] +#![cfg_attr(feature="cargo-clippy", allow(inline_always))] use std::os::raw::c_int; +pub use self::pyport::*; +pub use self::pymem::*; +pub use self::object::*; +pub use self::objimpl::*; +pub use self::pydebug::*; +#[cfg(py_sys_config="Py_USING_UNICODE")] +pub use self::unicodeobject::*; +pub use self::intobject::*; pub use self::boolobject::*; +pub use self::longobject::*; +pub use self::floatobject::*; +pub use self::complexobject::*; +pub use self::rangeobject::*; +pub use self::memoryobject::*; pub use self::bufferobject::*; -pub use self::bytearrayobject::*; +pub use self::stringobject::*; 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::bytearrayobject::*; +pub use self::tupleobject::*; +pub use self::listobject::*; 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::setobject::*; +pub use self::pyerrors::*; +pub use self::pystate::*; +pub use self::pystate::PyGILState_STATE::*; 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::funcobject::*; +pub use self::classobject::*; +pub use self::fileobject::*; +pub use self::cobject::*; 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::sliceobject::*; +pub use self::cellobject::*; +pub use self::iterobject::*; +pub use self::genobject::*; +pub use self::descrobject::*; pub use self::warnings::*; pub use self::weakrefobject::*; +pub use self::pyarena::*; +pub use self::modsupport::*; +pub use self::pythonrun::*; +pub use self::ceval::*; +pub use self::import::*; +pub use self::objectabstract::*; +pub use self::code::*; +pub use self::compile::*; +pub use self::eval::*; +pub use self::structmember::PyMemberDef; +pub use self::frameobject::PyFrameObject; +mod pyport; +mod pymem; +mod object; +mod objimpl; +mod pydebug; +#[cfg(py_sys_config="Py_USING_UNICODE")] +mod unicodeobject; // TODO: incomplete +mod intobject; mod boolobject; +mod longobject; +mod floatobject; +mod complexobject; +mod rangeobject; +mod stringobject; +mod memoryobject; mod bufferobject; -mod bytearrayobject; mod bytesobject; -mod cellobject; -mod classobject; -mod cobject; -mod complexobject; -mod descrobject; +mod bytearrayobject; +mod tupleobject; +mod listobject; mod dictobject; mod enumobject; -mod fileobject; -mod floatobject; -mod funcobject; -mod genobject; -mod intobject; -mod iterobject; -mod listobject; -mod longobject; -mod memoryobject; +mod setobject; mod methodobject; mod moduleobject; -mod object; -mod objimpl; +mod funcobject; +mod classobject; +mod fileobject; +mod cobject; 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 sliceobject; +mod cellobject; +mod iterobject; +mod genobject; +mod descrobject; mod warnings; mod weakrefobject; @@ -100,10 +102,10 @@ mod pyerrors; mod pystate; -mod ceval; -mod modsupport; mod pyarena; +mod modsupport; mod pythonrun; +mod ceval; // mod sysmodule; // TODO: incomplete // mod intrcheck; // TODO: incomplete mod import; @@ -122,23 +124,17 @@ mod eval; // mod pyfpe; // TODO: incomplete // Additional headers that are not exported by Python.h -pub mod frameobject; pub mod structmember; +pub mod frameobject; 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] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] -pub fn PyUnicode_Check(op: *mut PyObject) -> libc::c_int { - 0 -} +#[cfg(not(py_sys_config="Py_USING_UNICODE"))] +#[inline(always)] +pub fn PyUnicode_Check(op : *mut PyObject) -> libc::c_int { 0 } -#[cfg(not(py_sys_config = "Py_USING_UNICODE"))] -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] -pub fn PyUnicode_CheckExact(op: *mut PyObject) -> libc::c_int { - 0 -} +#[cfg(not(py_sys_config="Py_USING_UNICODE"))] +#[inline(always)] +pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 } diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index 1e3f5994ef1..c1450dbc00a 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -1,150 +1,94 @@ -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; +use std::os::raw::{c_char, c_int, c_long}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::PyObject; +use ffi2::methodobject::PyMethodDef; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyArg_Parse")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTuple")] - pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTupleAndKeywords")] - pub fn PyArg_ParseTupleAndKeywords( - args: *mut PyObject, - kw: *mut PyObject, - format: *const c_char, - keywords: *mut *mut c_char, - ... - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyArg_UnpackTuple")] - pub fn PyArg_UnpackTuple( - args: *mut PyObject, - name: *const c_char, - min: Py_ssize_t, - max: Py_ssize_t, - ... - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_BuildValue")] + 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; - #[cfg_attr(PyPy, link_name = "_PyPy_BuildValue_SizeT")] //fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyArg_NoKeywords")] //fn _PyArg_NoKeywords(funcname: *const c_char, // kw: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyModule_AddObject")] - pub fn PyModule_AddObject( - module: *mut PyObject, - name: *const c_char, - value: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyModule_AddIntConstant")] - pub fn PyModule_AddIntConstant( - module: *mut PyObject, - name: *const c_char, - value: c_long, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyModule_AddStringConstant")] - pub fn PyModule_AddStringConstant( - module: *mut PyObject, - name: *const c_char, - value: *const c_char, - ) -> 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")))] - #[cfg_attr(PyPy, link_name = "_PyPy_InitPyPyModule")] - fn Py_InitModule4_64( - name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, - _self: *mut PyObject, - apiver: c_int, - ) -> *mut PyObject; + 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; + 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; + 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; + 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; +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 { +#[inline(always)] +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 { +#[inline(always)] +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 { +#[inline(always)] +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] +#[inline(always)] pub unsafe fn Py_InitModule(name: *const c_char, methods: *mut PyMethodDef) -> *mut PyObject { - Py_InitModule4( - name, - methods, - ptr::null(), - ptr::null_mut(), - PYTHON_API_VERSION, - ) + Py_InitModule4(name, methods, ptr::null(), ptr::null_mut(), PYTHON_API_VERSION) } -#[inline] -pub unsafe fn Py_InitModule3( - name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, -) -> *mut PyObject { +#[inline(always)] +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) } diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index 12933e4b934..14da5f46548 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -1,30 +1,25 @@ -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}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; +use ffi2::methodobject::PyMethodDef; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyModule_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyModule_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyModule_Check")] -pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +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 { +#[inline(always)] +pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyModule_Type) as c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")] 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; @@ -45,16 +40,14 @@ pub struct PyModuleDef_Base { pub m_copy: *mut PyObject, } impl Clone for PyModuleDef_Base { - fn clone(&self) -> PyModuleDef_Base { - *self - } + fn clone(&self) -> PyModuleDef_Base { *self } } pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base { ob_base: PyObject_HEAD_INIT, m_init: None, m_index: 0, - m_copy: ::std::ptr::null_mut(), + m_copy: ::std::ptr::null_mut() }; #[repr(C)] @@ -64,13 +57,11 @@ pub struct PyModuleDef_Slot { pub value: *mut c_void, } impl Clone for PyModuleDef_Slot { - fn clone(&self) -> PyModuleDef_Slot { - *self - } + fn clone(&self) -> PyModuleDef_Slot { *self } } -pub const Py_mod_create: c_int = 1; -pub const Py_mod_exec: c_int = 2; +pub const Py_mod_create : c_int = 1; +pub const Py_mod_exec : c_int = 2; #[repr(C)] #[derive(Copy)] @@ -86,9 +77,7 @@ pub struct PyModuleDef { pub m_free: Option, } impl Clone for PyModuleDef { - fn clone(&self) -> PyModuleDef { - *self - } + fn clone(&self) -> PyModuleDef { *self } } pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { @@ -100,5 +89,5 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { m_slots: ::std::ptr::null_mut(), m_traverse: None, m_clear: None, - m_free: None, + m_free: None }; diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 108c52806eb..647ef7e07d0 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -1,63 +1,33 @@ -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; +use std::os::raw::{c_void, c_int, c_uint, c_long, c_char, c_double}; +use libc::FILE; +use ffi2; +use ffi2::pyport::{Py_ssize_t, Py_hash_t}; +use ffi2::methodobject::PyMethodDef; #[repr(C)] -#[derive(Copy, Clone, Debug)] -#[cfg(not(PyPy))] -pub struct PyObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_prev: *mut PyObject, - pub ob_refcnt: Py_ssize_t, - pub ob_type: *mut PyTypeObject, -} - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -#[cfg(PyPy)] +#[derive(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_pypy_link: Py_ssize_t, pub ob_type: *mut PyTypeObject, } -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[cfg(not(PyPy))] +#[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(), + ob_type: ::std::ptr::null_mut() }; -#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] -#[cfg(not(PyPy))] +#[cfg(not(py_sys_config="Py_TRACE_REFS"))] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, - ob_type: ::std::ptr::null_mut(), -}; - -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[cfg(PyPy)] -pub const PyObject_HEAD_INIT: PyObject = PyObject { - _ob_next: ::std::ptr::null_mut(), - _ob_prev: ::std::ptr::null_mut(), - ob_refcnt: 1, - ob_pypy_link: 0, - ob_type: ::std::ptr::null_mut(), -}; - -#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] -#[cfg(PyPy)] -pub const PyObject_HEAD_INIT: PyObject = PyObject { - ob_refcnt: 1, - ob_pypy_link: 0, - ob_type: ::std::ptr::null_mut(), + ob_type: ::std::ptr::null_mut() }; #[repr(C)] @@ -67,79 +37,75 @@ pub struct PyVarObject { pub ob_size: Py_ssize_t, } -#[inline] -pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { +#[inline(always)] +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 { +#[inline(always)] +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 { +#[inline(always)] +pub unsafe fn Py_SIZE(ob : *mut PyObject) -> Py_ssize_t { (*(ob as *mut PyVarObject)).ob_size } -pub type unaryfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +pub type unaryfunc = + unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type binaryfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; -pub type ternaryfunc = unsafe extern "C" fn( - arg1: *mut PyObject, - arg2: *mut PyObject, - arg3: *mut PyObject, -) -> *mut PyObject; -pub type inquiry = unsafe extern "C" fn(arg1: *mut PyObject) -> c_int; -pub type lenfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> *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; + unsafe extern "C" fn (arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject) -> c_int; pub type ssizeargfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub type ssizessizeargfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: Py_ssize_t) -> *mut PyObject; pub type intobjargproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut PyObject) -> c_int; -pub type intintobjargproc = unsafe extern "C" fn( - arg1: *mut PyObject, - arg2: c_int, - arg3: c_int, - arg4: *mut PyObject, -) -> c_int; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, arg3: *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; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: *mut PyObject) -> c_int; +pub type ssizessizeobjargproc = + unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, + arg3: Py_ssize_t, arg4: *mut PyObject) -> c_int; pub type objobjargproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> c_int; pub type getreadbufferproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, + arg3: *mut *mut c_void) -> c_int; pub type getwritebufferproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int; -pub type getsegcountproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_int) -> c_int; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, + arg3: *mut *mut c_void) -> c_int; +pub type getsegcountproc = + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_int) -> c_int; pub type getcharbufferproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_char) -> c_int; -pub type readbufferproc = unsafe extern "C" fn( - arg1: *mut PyObject, - arg2: Py_ssize_t, - arg3: *mut *mut c_void, -) -> Py_ssize_t; -pub type writebufferproc = unsafe extern "C" fn( - arg1: *mut PyObject, - arg2: Py_ssize_t, - arg3: *mut *mut c_void, -) -> Py_ssize_t; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: 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; + 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)] @@ -159,41 +125,47 @@ pub struct Py_buffer { } pub type getbufferproc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer, arg3: c_int) -> c_int; -pub type releasebufferproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer); + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer, + arg3: c_int) -> c_int; +pub type releasebufferproc = + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer); // flags: -pub const PyBUF_SIMPLE: c_int = 0; -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_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_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_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_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); +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 const PyBUF_READ : c_int = 0x100; +pub const PyBUF_WRITE : c_int = 0x200; +pub const PyBUF_SHADOW : c_int = 0x400; + -pub type objobjproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type visitproc = unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int; +pub type objobjproc = + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type visitproc = + unsafe extern "C" fn (object: *mut PyObject, arg: *mut c_void) -> c_int; pub type traverseproc = - unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; + unsafe extern "C" fn (slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; + #[repr(C)] #[derive(Copy)] @@ -240,13 +212,10 @@ pub struct PyNumberMethods { } impl Clone for PyNumberMethods { - #[inline] - fn clone(&self) -> PyNumberMethods { - *self - } + #[inline] fn clone(&self) -> PyNumberMethods { *self } } -pub const PyNumberMethods_INIT: PyNumberMethods = PyNumberMethods { +pub const PyNumberMethods_INIT : PyNumberMethods = PyNumberMethods { nb_add: None, nb_subtract: None, nb_multiply: None, @@ -304,13 +273,10 @@ pub struct PySequenceMethods { } impl Clone for PySequenceMethods { - #[inline] - fn clone(&self) -> PySequenceMethods { - *self - } + #[inline] fn clone(&self) -> PySequenceMethods { *self } } -pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods { +pub const PySequenceMethods_INIT : PySequenceMethods = PySequenceMethods { sq_length: None, sq_concat: None, sq_repeat: None, @@ -332,13 +298,10 @@ pub struct PyMappingMethods { } impl Clone for PyMappingMethods { - #[inline] - fn clone(&self) -> PyMappingMethods { - *self - } + #[inline] fn clone(&self) -> PyMappingMethods { *self } } -pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods { +pub const PyMappingMethods_INIT : PyMappingMethods = PyMappingMethods { mp_length: None, mp_subscript: None, mp_ass_subscript: None, @@ -356,13 +319,10 @@ pub struct PyBufferProcs { } impl Clone for PyBufferProcs { - #[inline] - fn clone(&self) -> PyBufferProcs { - *self - } + #[inline] fn clone(&self) -> PyBufferProcs { *self } } -pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { +pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs { bf_getreadbuffer: None, bf_getwritebuffer: None, bf_getsegcount: None, @@ -371,44 +331,52 @@ pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { bf_releasebuffer: None, }; -pub type freefunc = unsafe extern "C" fn(arg1: *mut c_void); -pub type destructor = unsafe extern "C" fn(arg1: *mut PyObject); +pub type freefunc = + unsafe extern "C" fn(arg1: *mut c_void); +pub type destructor = + unsafe extern "C" fn(arg1: *mut PyObject); pub type printfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut FILE, arg3: c_int) -> c_int; + 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; + 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; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub type setattrfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_char, + arg3: *mut PyObject) -> c_int; pub type setattrofunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; -pub type cmpfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type reprfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type hashfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject) -> c_int; +pub type cmpfunc = + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type reprfunc = + unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +pub type hashfunc = + unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; pub type richcmpfunc = - unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; -pub type getiterfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type iternextfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type descrgetfunc = unsafe extern "C" fn( - arg1: *mut PyObject, - arg2: *mut PyObject, - arg3: *mut PyObject, -) -> *mut PyObject; + unsafe extern "C" fn (arg1: *mut PyObject, + arg2: *mut PyObject, arg3: 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; + 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; + 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; + unsafe extern "C" fn (arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject; #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy)] pub struct PyTypeObject { pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -461,8 +429,12 @@ pub struct PyTypeObject { pub tp_version_tag: c_uint, } -#[cfg(py_sys_config = "Py_TRACE_REFS")] -pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject { +impl Clone for PyTypeObject { + #[inline] fn clone(&self) -> PyTypeObject { *self } +} + +#[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, @@ -516,8 +488,8 @@ pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject { tp_version_tag: 0, }; -#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] -pub const PyTypeObject_INIT: PyTypeObject = PyTypeObject { +#[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, @@ -582,273 +554,219 @@ pub struct PyHeapTypeObject { } impl Clone for PyHeapTypeObject { - #[inline] - fn clone(&self) -> PyHeapTypeObject { - *self - } + #[inline] fn clone(&self) -> PyHeapTypeObject { *self } } // access macro to the members which are floating "behind" the object #[inline] -pub unsafe fn PyHeapType_GET_MEMBERS( - etype: *mut PyHeapTypeObject, -) -> *mut ffi2::structmember::PyMemberDef { +pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2::structmember::PyMemberDef { let basicsize = (*Py_TYPE(etype as *mut PyObject)).tp_basicsize; (etype as *mut u8).offset(basicsize as isize) as *mut ffi2::structmember::PyMemberDef } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } -#[inline] +#[inline(always)] 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" { - #[cfg_attr(PyPy, link_name = "PyPyType_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyType_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; } -#[inline] +#[inline(always)] pub unsafe fn PyType_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) } -#[inline] +#[inline(always)] pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == (&mut PyType_Type as *mut _)) as c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyType_Ready")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyType_GenericNew")] - pub fn PyType_GenericNew( - t: *mut PyTypeObject, - args: *mut PyObject, - kwds: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyType_Lookup")] + 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; + fn _PyObject_LookupSpecial(arg1: *mut PyObject, + arg2: *mut c_char, + arg3: *mut *mut PyObject) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; - #[cfg_attr(PyPy, link_name = "PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); - #[cfg_attr(PyPy, link_name = "PyPyObject_Print")] - pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int; + pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, + flags: c_int) -> c_int; fn _PyObject_Dump(o: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_Str")] fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyObject_Bytes")] +#[inline(always)] 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")] - #[cfg_attr(PyPy, link_name = "PyPyObject_Unicode")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompare")] - pub fn PyObject_RichCompare( - arg1: *mut PyObject, - arg2: *mut PyObject, - arg3: c_int, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompareBool")] - pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) - -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttrString")] - pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttrString")] - pub fn PyObject_SetAttrString( - arg1: *mut PyObject, - arg2: *const c_char, - arg3: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")] - pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttr")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] - pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) - -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttr")] + 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; - #[cfg_attr(PyPy, link_name = "_PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_GenericSetAttr")] - pub fn PyObject_GenericSetAttr( - arg1: *mut PyObject, - arg2: *mut PyObject, - arg3: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_Hash")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCallable_Check")] 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_ClearWeakRefs")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_Dir")] + 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); - #[cfg_attr(PyPy, link_name = "_PyPy_HashDouble")] fn _Py_HashDouble(arg1: c_double) -> c_long; - #[cfg_attr(PyPy, link_name = "_PyPy_HashPointer")] 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. +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); +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); +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); +pub const Py_TPFLAGS_HAVE_INPLACEOPS : c_long = (1<<3); // PyNumberMethods do their own coercion -pub const Py_TPFLAGS_CHECKTYPES: c_long = (1 << 4); +pub const Py_TPFLAGS_CHECKTYPES : c_long = (1<<4); // tp_richcompare is defined -pub const Py_TPFLAGS_HAVE_RICHCOMPARE: c_long = (1 << 5); +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); +pub const Py_TPFLAGS_HAVE_WEAKREFS : c_long = (1<<6); // tp_iter is defined -pub const Py_TPFLAGS_HAVE_ITER: c_long = (1 << 7); +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); +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); +pub const Py_TPFLAGS_HEAPTYPE : c_long = (1<<9); // Set if the type allows subclassing -pub const Py_TPFLAGS_BASETYPE: c_long = (1 << 10); +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); +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); +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); +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; +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); +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); +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); +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); +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 { +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 | + 0); + +#[inline(always)] +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 { +#[inline(always)] +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") { +#[inline(always)] +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] +#[inline(always)] pub unsafe fn Py_DECREF(op: *mut PyObject) { - if cfg!(py_sys_config = "Py_REF_DEBUG") || cfg!(py_sys_config = "COUNT_ALLOCS") { + if cfg!(py_sys_config="Py_REF_DEBUG") || cfg!(py_sys_config="COUNT_ALLOCS") { Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -858,7 +776,7 @@ pub unsafe fn Py_DECREF(op: *mut PyObject) { } } -#[inline] +#[inline(always)] pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) { let tmp = *op; if !tmp.is_null() { @@ -867,48 +785,45 @@ pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) { } } -#[inline] -pub unsafe fn Py_XINCREF(op: *mut PyObject) { +#[inline(always)] +pub unsafe fn Py_XINCREF(op : *mut PyObject) { if !op.is_null() { Py_INCREF(op) } } -#[inline] -pub unsafe fn Py_XDECREF(op: *mut PyObject) { +#[inline(always)] +pub unsafe fn Py_XDECREF(op : *mut PyObject) { if !op.is_null() { Py_DECREF(op) } } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); - #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; - #[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } -#[inline] +#[inline(always)] pub unsafe fn Py_None() -> *mut PyObject { &mut _Py_NoneStruct } -#[inline] +#[inline(always)] 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; +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 { @@ -920,16 +835,15 @@ pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int { 0 } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { fn _PyTrash_thread_deposit_object(o: *mut PyObject); fn _PyTrash_thread_destroy_chain(); } -pub const PyTrash_UNWIND_LEVEL: c_int = 50; +pub const PyTrash_UNWIND_LEVEL : c_int = 50; -#[inline] -pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { +#[inline(always)] +pub unsafe fn Py_TRASHCAN ()>(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() { @@ -946,3 +860,4 @@ pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { _PyTrash_thread_deposit_object(op) } } + diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index bbdb68110f3..96ef08ea6d6 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -1,335 +1,255 @@ -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; +use std::os::raw::{c_void, c_char, c_int}; +use ffi2; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[inline] -#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttr")] 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_Call")] - pub fn PyObject_Call( - callable_object: *mut PyObject, - args: *mut PyObject, - kw: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallObject")] - pub fn PyObject_CallObject( - callable_object: *mut PyObject, - args: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] - pub fn PyObject_CallFunction( - callable_object: *mut PyObject, - format: *mut c_char, - ... - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethod")] - pub fn PyObject_CallMethod( - o: *mut PyObject, - m: *mut c_char, - format: *mut c_char, - ... - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyObject_CallFunction_SizeT")] - fn _PyObject_CallFunction_SizeT( - callable: *mut PyObject, - format: *mut c_char, - ... - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyObject_CallMethod_SizeT")] - fn _PyObject_CallMethod_SizeT( - o: *mut PyObject, - name: *mut c_char, - format: *mut c_char, - ... - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")] - pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")] - pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_LengthHint")] - pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetItem")] - pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SetItem")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsCharBuffer")] - pub fn PyObject_AsCharBuffer( - obj: *mut PyObject, - buffer: *mut *const c_char, - buffer_len: *mut Py_ssize_t, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_CheckReadBuffer")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsReadBuffer")] - pub fn PyObject_AsReadBuffer( - obj: *mut PyObject, - buffer: *mut *const c_void, - buffer_len: *mut Py_ssize_t, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsWriteBuffer")] - pub fn PyObject_AsWriteBuffer( - obj: *mut PyObject, - buffer: *mut *mut c_void, - buffer_len: *mut Py_ssize_t, - ) -> 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetBuffer")] - pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; + pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, + flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_GetPointer")] - pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_ToContiguous")] - pub fn PyBuffer_ToContiguous( - buf: *mut c_void, - view: *mut Py_buffer, - len: Py_ssize_t, - fort: c_char, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromContiguous")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_IsContiguous")] - 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, - ); - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FillInfo")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_Release")] + 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); - #[cfg_attr(PyPy, link_name = "PyPyObject_Format")] - pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetIter")] + pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) + -> *mut PyObject; pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Add")] - pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Subtract")] - pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Multiply")] - pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Divide")] - pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_FloorDivide")] - pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_TrueDivide")] - pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Remainder")] - pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Divmod")] - pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Power")] - pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) - -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Negative")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Lshift")] - pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Rshift")] - pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_And")] - pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Xor")] - pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Or")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_AsSsize_t")] - pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) -> Py_ssize_t; - fn _PyNumber_ConvertIntegralToInt( - integral: *mut PyObject, - error_format: *const c_char, - ) -> *mut PyObject; + pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) + -> Py_ssize_t; + fn _PyNumber_ConvertIntegralToInt(integral: *mut PyObject, + error_format: *const c_char) + -> *mut PyObject; pub fn PyNumber_Int(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAdd")] - pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceSubtract")] - pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceMultiply")] - pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceDivide")] - pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceFloorDivide")] - pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceTrueDivide")] - pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRemainder")] - pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlacePower")] - pub fn PyNumber_InPlacePower( - o1: *mut PyObject, - o2: *mut PyObject, - o3: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceLshift")] - pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRshift")] - pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAnd")] - pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceXor")] - pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceOr")] - pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_Check")] + 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; - #[cfg_attr(PyPy, link_name = "PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySequence_Length")] pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySequence_Concat")] - pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_Repeat")] - pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_GetItem")] - pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_GetSlice")] - pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_SetItem")] - pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_DelItem")] - pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_SetSlice")] - pub fn PySequence_SetSlice( - o: *mut PyObject, - i1: Py_ssize_t, - i2: Py_ssize_t, - v: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_DelSlice")] - pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_Tuple")] + 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; - #[cfg_attr(PyPy, link_name = "PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_Fast")] - 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; - #[cfg_attr(PyPy, link_name = "PyPySequence_Contains")] - 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; - #[cfg_attr(PyPy, link_name = "PyPySequence_Index")] - pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceConcat")] - pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceRepeat")] - pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMapping_Check")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyMapping_Length")] pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKeyString")] - pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKey")] - pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyMapping_GetItemString")] - pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMapping_SetItemString")] - pub fn PyMapping_SetItemString( - o: *mut PyObject, - key: *mut c_char, - value: *mut PyObject, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_IsInstance")] - pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_IsSubclass")] - pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; + pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) + -> c_int; + pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) + -> c_int; + pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) + -> *mut PyObject; + pub fn PyMapping_SetItemString(o: *mut PyObject, key: *mut c_char, + value: *mut PyObject) -> c_int; + pub fn PyObject_IsInstance(object: *mut PyObject, + typeorclass: *mut PyObject) -> c_int; + pub fn PyObject_IsSubclass(object: *mut PyObject, + typeorclass: *mut PyObject) -> c_int; } + #[inline] pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let b = (*t).tp_as_buffer; - (!b.is_null() - && (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) - && ((*b).bf_getbuffer.is_some())) as c_int + (!b.is_null() && + (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) && + ((*b).bf_getbuffer.is_some())) as c_int } + #[inline] -#[cfg_attr(PyPy, link_name = "PyPyIter_Check")] 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 + (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] -#[cfg_attr(PyPy, link_name = "PyPyIndex_Check")] pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let n = (*t).tp_as_number; - (!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) - as c_int + (!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) as c_int } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_SIZE")] -pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { +pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] ffi2::listobject::PyList_GET_SIZE(o) } else { ffi2::tupleobject::PyTuple_GET_SIZE(o) @@ -337,10 +257,8 @@ pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_ITEM")] -pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { +pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] ffi2::listobject::PyList_GET_ITEM(o, i) } else { ffi2::tupleobject::PyTuple_GET_ITEM(o, i) @@ -348,52 +266,44 @@ pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_ITEMS")] -pub unsafe fn PySequence_Fast_ITEMS(o: *mut PyObject) -> *mut *mut PyObject { +pub unsafe fn PySequence_Fast_ITEMS(o : *mut PyObject) -> *mut *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { (*(o as *mut ffi2::listobject::PyListObject)).ob_item } else { - (*(o as *mut ffi2::tupleobject::PyTupleObject)) - .ob_item - .as_mut_ptr() + (*(o as *mut ffi2::tupleobject::PyTupleObject)).ob_item.as_mut_ptr() } } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_ITEM")] -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 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; +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 { +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 { +pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int { PyObject_DelItem(o, key) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyMapping_Keys")] -pub unsafe fn PyMapping_Keys(o: *mut PyObject) -> *mut PyObject { - PyObject_CallMethod(o, "keys\0".as_ptr() as *mut c_char, ptr::null_mut()) +pub unsafe fn PyMapping_Keys(o : *mut PyObject) -> *mut PyObject { + PyObject_CallMethod(o, "keys\0".as_ptr() as *mut i8, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyMapping_Values")] -pub unsafe fn PyMapping_Values(o: *mut PyObject) -> *mut PyObject { - PyObject_CallMethod(o, "values\0".as_ptr() as *mut c_char, ptr::null_mut()) +pub unsafe fn PyMapping_Values(o : *mut PyObject) -> *mut PyObject { + PyObject_CallMethod(o, "values\0".as_ptr() as *mut i8, ptr::null_mut()) } + #[inline] -#[cfg_attr(PyPy, link_name = "PyPyMapping_Items")] -pub unsafe fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject { - PyObject_CallMethod(o, "items\0".as_ptr() as *mut c_char, ptr::null_mut()) +pub unsafe fn PyMapping_Items(o : *mut PyObject) -> *mut PyObject { + PyObject_CallMethod(o, "items\0".as_ptr() as *mut i8, ptr::null_mut()) } diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index e4745a9509b..aac600257e1 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -1,63 +1,63 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; +use std::os::raw::{c_void, c_char, c_int}; use libc::size_t; -use std::os::raw::{c_char, c_int, c_void}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyObject_Malloc")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyObject_Realloc")] - pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; + pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) + -> *mut c_void; pub fn PyObject_Free(arg1: *mut c_void); - pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject; - pub fn PyObject_InitVar( - arg1: *mut PyVarObject, - arg2: *mut PyTypeObject, - arg3: Py_ssize_t, - ) -> *mut PyVarObject; + pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) + -> *mut PyObject; + pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject, + arg3: Py_ssize_t) -> *mut PyVarObject; pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject; - pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; + pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) + -> *mut PyVarObject; // GC Support pub fn PyGC_Collect() -> Py_ssize_t; - pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) -> *mut PyVarObject; + pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) + -> *mut PyVarObject; pub fn _PyObject_GC_Malloc(arg1: size_t) -> *mut PyObject; pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject; - pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; + pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) + -> *mut PyVarObject; pub fn PyObject_GC_Track(arg1: *mut c_void); pub fn PyObject_GC_UnTrack(arg1: *mut c_void); pub fn PyObject_GC_Del(arg1: *mut c_void); } /// Test if a type has a GC head -#[inline] +#[inline(always)] #[allow(unused_parens)] -pub unsafe fn PyType_IS_GC(t: *mut PyTypeObject) -> c_int { +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 +#[inline(always)] +pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int { + (PyType_IS_GC(Py_TYPE(o)) != 0 && + match (*Py_TYPE(o)).tp_is_gc { + Some(tp_is_gc) => tp_is_gc(o) != 0, + None => true + }) as c_int } /* Test if a type supports weak references */ -#[inline] +#[inline(always)] #[allow(unused_parens)] -pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int { - (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) != 0 && ((*t).tp_weaklistoffset > 0)) as c_int +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 { +#[inline(always)] +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 } + diff --git a/src/ffi2/pyarena.rs b/src/ffi2/pyarena.rs index 0b0713bebae..d7429d0de35 100644 --- a/src/ffi2/pyarena.rs +++ b/src/ffi2/pyarena.rs @@ -1,12 +1,11 @@ -use crate::ffi2::object::PyObject; use libc::size_t; -use std::os::raw::{c_int, c_void}; +use std::os::raw::{c_void, c_int}; +use ffi2::object::PyObject; #[allow(missing_copy_implementations)] -pub enum PyArena {} +pub enum PyArena { } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyArena_New() -> *mut PyArena; pub fn PyArena_Free(arg1: *mut PyArena); pub fn PyArena_Malloc(arg1: *mut PyArena, size: size_t) -> *mut c_void; diff --git a/src/ffi2/pycapsule.rs b/src/ffi2/pycapsule.rs index 94eea810322..84316530ffa 100644 --- a/src/ffi2/pycapsule.rs +++ b/src/ffi2/pycapsule.rs @@ -1,9 +1,7 @@ -use crate::ffi2::object::*; -use std::os::raw::{c_char, c_int, c_void}; +use std::os::raw::{c_void, c_char, c_int}; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCapsule_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyCapsule_Type: PyTypeObject; } @@ -14,35 +12,25 @@ 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" { - #[cfg_attr(PyPy, link_name = "PyPyCapsule_New")] - pub fn PyCapsule_New( - pointer: *mut c_void, - name: *const c_char, - destructor: Option, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetPointer")] - pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetDestructor")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { + pub fn PyCapsule_New(pointer: *mut c_void, + name: *const c_char, + destructor: Option) -> *mut PyObject; + pub fn PyCapsule_GetPointer(capsule: *mut PyObject, + name: *const c_char) -> *mut c_void; pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_IsValid")] - pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetPointer")] - pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetDestructor")] - pub fn PyCapsule_SetDestructor( - capsule: *mut PyObject, - destructor: Option, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetName")] - pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetContext")] - pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_Import")] - pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; + pub fn PyCapsule_IsValid(capsule: *mut PyObject, + name: *const c_char) -> c_int; + pub fn PyCapsule_SetPointer(capsule: *mut PyObject, + pointer: *mut c_void) -> c_int; + pub fn PyCapsule_SetDestructor(capsule: *mut PyObject, + destructor: Option) -> 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; } diff --git a/src/ffi2/pydebug.rs b/src/ffi2/pydebug.rs index 52d6d86bff0..c54f77d21d6 100644 --- a/src/ffi2/pydebug.rs +++ b/src/ffi2/pydebug.rs @@ -1,44 +1,25 @@ use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut Py_DebugFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_TabcheckFlag")] pub static mut Py_TabcheckFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_UnicodeFlag")] pub static mut Py_UnicodeFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_DivisionWarningFlag")] pub static mut Py_DivisionWarningFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; - #[cfg_attr(PyPy, link_name = "_PyPy_QnewFlag")] pub static mut _Py_QnewFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_Py3kWarningFlag")] pub static mut Py_Py3kWarningFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char); } + diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index 38278f51dbe..a613ab68dd0 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -1,55 +1,39 @@ -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}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; +use ffi2::classobject::*; +use ffi2::stringobject::PyString_AS_STRING; +#[cfg(py_sys_config="Py_USING_UNICODE")] +use ffi2::unicodeobject::Py_UNICODE; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyErr_SetNone")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyErr_SetNone(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_SetString")] pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); - #[cfg_attr(PyPy, link_name = "PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_Clear")] pub fn PyErr_Clear(); - #[cfg_attr(PyPy, link_name = "PyPyErr_Fetch")] - pub fn PyErr_Fetch( - arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject, - ); - #[cfg_attr(PyPy, link_name = "PyPyErr_Restore")] - pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_GivenExceptionMatches")] - pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_ExceptionMatches")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyErr_NormalizeException")] - pub fn PyErr_NormalizeException( - arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject, - arg3: *mut *mut PyObject, - ); + pub fn PyErr_NormalizeException(arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject); } #[inline] pub unsafe fn PyExceptionClass_Check(x: *mut PyObject) -> c_int { - (PyClass_Check(x) != 0 - || (PyType_Check(x) != 0 - && PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) - as c_int + (PyClass_Check(x) != 0 || (PyType_Check(x) != 0 && + PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) as c_int } #[inline] pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { - (PyInstance_Check(x) != 0 - || PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int + (PyInstance_Check(x) != 0 || + PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int } #[inline] @@ -62,7 +46,6 @@ pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { if PyInstance_Check(x) != 0 { (*(x as *mut PyInstanceObject)).in_class as *mut PyObject @@ -71,199 +54,163 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { } } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyExc_BaseException: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; pub static mut PyExc_StandardError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; - #[cfg(windows)] - pub static mut PyExc_WindowsError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_BufferError")] + #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; pub static mut PyExc_BufferError: *mut PyObject; pub static mut PyExc_MemoryErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_RecursionError")] pub static mut PyExc_RecursionErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - - #[cfg_attr(PyPy, link_name = "PyPyErr_BadArgument")] + pub fn PyErr_BadArgument() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilenameObject")] - pub fn PyErr_SetFromErrnoWithFilenameObject( - arg1: *mut PyObject, - arg2: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilename")] - pub fn PyErr_SetFromErrnoWithFilename( - arg1: *mut PyObject, - arg2: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_Format")] - pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_BadInternalCall")] + 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); - #[cfg_attr(PyPy, link_name = "PyPyErr_NewException")] - pub fn PyErr_NewException( - name: *mut c_char, - base: *mut PyObject, - dict: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_NewExceptionWithDoc")] - pub fn PyErr_NewExceptionWithDoc( - name: *mut c_char, - doc: *mut c_char, - base: *mut PyObject, - dict: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_WriteUnraisable")] + 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); - #[cfg_attr(PyPy, link_name = "PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; - pub fn PyErr_SyntaxLocation(arg1: *const c_char, arg2: c_int); - pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) -> *mut PyObject; + pub fn PyErr_SyntaxLocation(arg1: *const c_char, + arg2: c_int); + pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) + -> *mut PyObject; } -#[cfg(py_sys_config = "Py_USING_UNICODE")] -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - pub fn PyUnicodeDecodeError_Create( - arg1: *const c_char, - 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; +#[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; } + diff --git a/src/ffi2/pymem.rs b/src/ffi2/pymem.rs index dabd9a874b9..66db582acb3 100644 --- a/src/ffi2/pymem.rs +++ b/src/ffi2/pymem.rs @@ -1,8 +1,6 @@ use libc::{c_void, size_t}; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyMem_Malloc")] +#[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); diff --git a/src/ffi2/pyport.rs b/src/ffi2/pyport.rs index 5ee20a83ed8..cbfa8e6bc13 100644 --- a/src/ffi2/pyport.rs +++ b/src/ffi2/pyport.rs @@ -1,8 +1,9 @@ + 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; +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; diff --git a/src/ffi2/pystate.rs b/src/ffi2/pystate.rs index 3e538cc403e..7577ef8184c 100644 --- a/src/ffi2/pystate.rs +++ b/src/ffi2/pystate.rs @@ -1,24 +1,22 @@ -use crate::ffi2::frameobject::PyFrameObject; -use crate::ffi2::object::PyObject; use std::os::raw::{c_int, c_long}; +use ffi2::object::PyObject; +use ffi2::frameobject::PyFrameObject; -pub enum PyInterpreterState {} +pub enum PyInterpreterState { } -pub type Py_tracefunc = unsafe extern "C" fn( - arg1: *mut PyObject, - arg2: *mut PyFrameObject, - arg3: c_int, - arg4: *mut PyObject, -) -> c_int; +pub type Py_tracefunc = + unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyFrameObject, + arg3: c_int, arg4: *mut PyObject) + -> c_int; /* The following values are used for 'what' for tracefunc functions: */ -pub const PyTrace_CALL: c_int = 0; -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; +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)] @@ -49,66 +47,60 @@ pub struct PyThreadState { } impl Clone for PyThreadState { - #[inline] - fn clone(&self) -> PyThreadState { - *self - } + #[inline] fn clone(&self) -> PyThreadState { *self } } #[repr(C)] #[derive(Copy, Clone)] pub enum PyGILState_STATE { PyGILState_LOCKED, - PyGILState_UNLOCKED, + PyGILState_UNLOCKED } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { + +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Get")] //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); - #[cfg_attr(PyPy, link_name = "PyPyThreadState_New")] - pub fn PyThreadState_New(arg1: *mut PyInterpreterState) -> *mut PyThreadState; - pub fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) -> *mut PyThreadState; + pub fn PyThreadState_New(arg1: *mut PyInterpreterState) + -> *mut PyThreadState; + pub fn _PyThreadState_Prealloc(arg1: *mut PyInterpreterState) + -> *mut PyThreadState; pub fn _PyThreadState_Init(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState); - #[cfg(py_sys_config = "WITH_THREAD")] - #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")] + #[cfg(py_sys_config="WITH_THREAD")] pub fn PyThreadState_DeleteCurrent(); pub fn PyThreadState_Get() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; - pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyGILState_Ensure")] + pub fn PyThreadState_SetAsyncExc(arg1: c_long, + arg2: *mut PyObject) -> c_int; pub fn PyGILState_Ensure() -> PyGILState_STATE; - #[cfg_attr(PyPy, link_name = "PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; fn _PyThread_CurrentFrames() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; - #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")] - pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) -> *mut PyInterpreterState; - pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) -> *mut PyThreadState; + pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) + -> *mut PyInterpreterState; + pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) + -> *mut PyThreadState; pub fn PyThreadState_Next(arg1: *mut PyThreadState) -> *mut PyThreadState; } -#[cfg(py_sys_config = "Py_DEBUG")] -#[inline] +#[cfg(py_sys_config="Py_DEBUG")] +#[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { PyThreadState_Get() } -#[cfg(not(py_sys_config = "Py_DEBUG"))] -#[inline] +#[cfg(not(py_sys_config="Py_DEBUG"))] +#[inline(always)] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { _PyThreadState_Current } + + diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index 4a4a0545b18..e28b68ec1e6 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -1,147 +1,112 @@ -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}; +use ffi2::object::*; +use ffi2::code::*; +use ffi2::pystate::PyThreadState; +use ffi2::pyarena::PyArena; -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; +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, + cf_flags : c_int } #[allow(missing_copy_implementations)] -pub enum Struct__mod {} +pub enum Struct__mod { } #[allow(missing_copy_implementations)] -pub enum Struct__node {} +pub enum Struct__node { } #[allow(missing_copy_implementations)] -pub enum Struct_symtable {} +pub enum Struct_symtable { } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); - #[cfg_attr(PyPy, link_name = "PyPy_GetProgramName")] 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(); - #[cfg_attr(PyPy, link_name = "PyPy_IsInitialized")] 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; - #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] - 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; - #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyErr_Print")] + 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(); - #[cfg_attr(PyPy, link_name = "PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int); - #[cfg_attr(PyPy, link_name = "PyPyErr_Display")] - pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPy_AtExit")] - pub fn Py_AtExit(func: Option) -> c_int; + pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, + arg3: *mut PyObject); + pub fn Py_AtExit(func: Option) + -> c_int; pub fn Py_Exit(arg1: c_int); - pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) -> c_int; - pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) -> c_int; + pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) + -> c_int; + pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) + -> c_int; pub fn Py_GetProgramFullPath() -> *mut c_char; pub fn Py_GetPrefix() -> *mut c_char; pub fn Py_GetExecPrefix() -> *mut c_char; pub fn Py_GetPath() -> *mut c_char; - #[cfg_attr(PyPy, link_name = "PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; @@ -153,3 +118,4 @@ extern "C" { fn _Py_hgidentifier() -> *const c_char; fn _Py_hgversion() -> *const c_char; } + diff --git a/src/ffi2/rangeobject.rs b/src/ffi2/rangeobject.rs index e6992496130..6299665678b 100644 --- a/src/ffi2/rangeobject.rs +++ b/src/ffi2/rangeobject.rs @@ -1,14 +1,13 @@ -use crate::ffi2::object::*; use std::os::raw::c_int; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyRange_Type")] +#[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; +#[inline(always)] +pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int { + let u : *mut PyTypeObject = &mut PyRange_Type; (Py_TYPE(op) == u) as c_int } + diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index 4511252090d..fbd2ece25f5 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -1,77 +1,63 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; //enum PySetObject { /* representation hidden */ } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPySet_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PySet_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_CheckExact")] -pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int { - let f: *mut PyTypeObject = &mut PyFrozenSet_Type; +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] -#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")] -pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int { - let s: *mut PyTypeObject = &mut PySet_Type; - let f: *mut PyTypeObject = &mut PyFrozenSet_Type; +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] -#[cfg_attr(PyPy, link_name = "PyPyAnySet_Check")] -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 +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] -#[cfg_attr(PyPy, link_name = "PyPySet_Check")] -pub unsafe fn PySet_Check(ob: *mut PyObject) -> c_int { - let s: *mut PyTypeObject = &mut PySet_Type; +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] -#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Check")] -pub unsafe fn PyFrozenSet_Check(ob: *mut PyObject) -> c_int { - let f: *mut PyTypeObject = &mut PyFrozenSet_Type; +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" { - #[cfg_attr(PyPy, link_name = "PyPySet_New")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_New")] pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySet_Contains")] - pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySet_Discard")] - pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySet_Add")] + 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; - #[cfg_attr(PyPy, link_name = "PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; -//pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) -// -> c_int; + //pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) + // -> c_int; } + diff --git a/src/ffi2/sliceobject.rs b/src/ffi2/sliceobject.rs index 9a2b1c87699..c458fa51482 100644 --- a/src/ffi2/sliceobject.rs +++ b/src/ffi2/sliceobject.rs @@ -1,14 +1,12 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { static mut _Py_EllipsisObject: PyObject; } -#[inline] +#[inline(always)] pub unsafe fn Py_Ellipsis() -> *mut PyObject { &mut _Py_EllipsisObject } @@ -16,53 +14,37 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PySliceObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub step: *mut PyObject } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPySlice_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPySlice_Check")] +#[inline(always)] pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PySlice_Type) as c_int + (Py_TYPE(op) == &mut PySlice_Type) as c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPySlice_New")] - pub fn PySlice_New( - start: *mut PyObject, - stop: *mut PyObject, - step: *mut PyObject, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndices")] - 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; - #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndicesEx")] - 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; +#[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; } + diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index af38518a77c..a54a816f88a 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -1,13 +1,13 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int, c_long}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[allow(missing_copy_implementations)] pub struct PyStringObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -17,136 +17,116 @@ pub struct PyStringObject { pub ob_sval: [c_char; 1], } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyBaseString_Type: PyTypeObject; pub static mut PyString_Type: PyTypeObject; } -#[inline] -pub unsafe fn PyString_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +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 { +#[inline(always)] +pub unsafe fn PyBaseString_Check(op : *mut PyObject) -> c_int { PyType_FastSubclass( - Py_TYPE(op), - Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS, - ) + Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS) } -#[inline] -pub unsafe fn PyString_CheckExact(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyString_Type; +#[inline(always)] +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 { +#[inline(always)] +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 { +#[inline(always)] +pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { (*(op as *mut PyStringObject)).ob_sval.as_mut_ptr() } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyString_FromString")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_FromStringAndSize")] - pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_FromFormat")] + pub fn PyString_FromStringAndSize(v: *const c_char, + len: Py_ssize_t) -> *mut PyObject; pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_Size")] pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyString_AsString")] 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_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_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; - #[cfg_attr(PyPy, link_name = "PyPyString_AsDecodedObject")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyString_AsEncodedObject")] - pub fn PyString_AsEncodedObject( - str: *mut PyObject, - encoding: *const c_char, - errors: *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_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;*/ + 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;*/ } + diff --git a/src/ffi2/structmember.rs b/src/ffi2/structmember.rs index 9262ab74d19..20097a015d4 100644 --- a/src/ffi2/structmember.rs +++ b/src/ffi2/structmember.rs @@ -1,6 +1,6 @@ -use crate::ffi2::object::PyObject; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::PyObject; #[repr(C)] #[derive(Copy, Clone)] @@ -9,50 +9,52 @@ pub struct PyMemberDef { pub type_code: c_int, pub offset: Py_ssize_t, pub flags: c_int, - pub doc: *mut c_char, + pub doc: *mut c_char } /* Types */ -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; +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 */ +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; +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; +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_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_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_LONGLONG : c_int = 17; +pub const T_ULONGLONG : c_int = 18; + +pub const T_PYSSIZET : c_int = 19; /* Py_ssize_t */ -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 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; } + diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index 31379dc166c..71a963315ab 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -1,36 +1,33 @@ -use crate::ffi2::frameobject::PyFrameObject; -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::object::*; +use ffi2::pyport::Py_ssize_t; +use ffi2::frameobject::PyFrameObject; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTracebackObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[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, + pub tb_lineno: c_int } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Here")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Print")] - pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - - #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")] + pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) + -> c_int; + pub static mut PyTraceBack_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Check")] -pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } + diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index 7264d241f8e..277582077cf 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -1,13 +1,13 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTupleObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -15,60 +15,48 @@ pub struct PyTupleObject { pub ob_item: [*mut PyObject; 1], } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyTuple_Type")] +#[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 { +#[inline(always)] +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; +#[inline(always)] +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] + +// Macro, trading safety for speed +#[inline(always)] pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { - *(*(op as *mut PyTupleObject)) - .ob_item - .as_ptr() - .offset(i as isize) + *(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i as isize) } -#[inline] +#[inline(always)] 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] +#[inline(always)] pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { - *(*(op as *mut PyTupleObject)) - .ob_item - .as_mut_ptr() - .offset(i as isize) = v; + *(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i as isize) = v; } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyTuple_Size")] pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyTuple_GetItem")] pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyTuple_SetItem")] - pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyTuple_GetSlice")] - pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyTuple_Resize")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; //pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject); pub fn PyTuple_ClearFreeList() -> c_int; diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index f8d15263610..32503fcb0cc 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -1,26 +1,26 @@ -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}; +use std::os::raw::{c_char, c_int, c_long, c_double}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; -#[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; +#[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")] +#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] pub type Py_UNICODE = u32; -#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] +#[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")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -30,358 +30,213 @@ pub struct PyUnicodeObject { pub defenc: *mut PyObject, } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Type")] +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { pub static mut PyUnicode_Type: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] -pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int { +#[inline(always)] +pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] -pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int { - let u: *mut PyTypeObject = &mut PyUnicode_Type; +#[inline(always)] +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] +#[inline(always)] pub unsafe fn PyUnicode_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { (*(o as *mut PyUnicodeObject)).length } -#[inline] +#[inline(always)] pub unsafe fn PyUnicode_GET_DATA_SIZE(o: *mut PyObject) -> Py_ssize_t { (*(o as *mut PyUnicodeObject)).length * Py_UNICODE_SIZE } -#[inline] +#[inline(always)] pub unsafe fn PyUnicode_AS_UNICODE(o: *mut PyObject) -> *mut Py_UNICODE { (*(o as *mut PyUnicodeObject)).data } -#[inline] +#[inline(always)] 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; +pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; + #[allow(dead_code)] -#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] - fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] + fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, + size: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] fn PyUnicodeUCS4_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] - fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] - fn PyUnicodeUCS4_FromEncodedObject( - obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] - fn PyUnicodeUCS4_AsWideChar( - unicode: *mut PyUnicodeObject, - w: *mut wchar_t, - size: Py_ssize_t, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] + 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; - #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] - fn _PyUnicodeUCS4_AsDefaultEncodedString( - arg1: *mut PyObject, - arg2: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] - fn PyUnicodeUCS4_AsEncodedObject( - unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] - fn PyUnicodeUCS4_AsEncodedString( - unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, - ) -> *mut PyObject; + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] - fn PyUnicodeUCS4_EncodeUTF8( - data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] + 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_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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] - fn PyUnicodeUCS4_DecodeLatin1( - string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] - fn PyUnicodeUCS4_EncodeLatin1( - data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] - fn PyUnicodeUCS4_DecodeASCII( - string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] - fn PyUnicodeUCS4_EncodeDecimal( - s: *mut Py_UNICODE, - length: Py_ssize_t, - output: *mut c_char, - errors: *const c_char, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] - fn PyUnicodeUCS4_Split( - s: *mut PyObject, - sep: *mut PyObject, - maxsplit: Py_ssize_t, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] - fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] - fn PyUnicodeUCS4_Tailmatch( - str: *mut PyObject, - substr: *mut PyObject, - start: Py_ssize_t, - end: Py_ssize_t, - direction: c_int, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] - fn PyUnicodeUCS4_Find( - str: *mut PyObject, - substr: *mut PyObject, - start: Py_ssize_t, - end: Py_ssize_t, - direction: c_int, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] - fn PyUnicodeUCS4_Count( - str: *mut PyObject, - substr: *mut PyObject, - start: Py_ssize_t, - end: Py_ssize_t, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] - fn PyUnicodeUCS4_Replace( - str: *mut PyObject, - substr: *mut PyObject, - replstr: *mut PyObject, - maxcount: Py_ssize_t, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] + fn PyUnicodeUCS4_RichCompare(left: *mut PyObject, + right: *mut PyObject, op: c_int) -> *mut PyObject; fn PyUnicodeUCS4_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_Contains(container: *mut PyObject, element: *mut PyObject) -> c_int; - fn _PyUnicode_XStrip( - _self: *mut PyUnicodeObject, - striptype: c_int, - sepobj: *mut PyObject, - ) -> *mut PyObject; + fn _PyUnicode_XStrip(_self: *mut PyUnicodeObject, + striptype: c_int, sepobj: *mut PyObject) -> *mut PyObject; fn _PyUnicodeUCS4_IsLowercase(ch: Py_UNICODE) -> c_int; fn _PyUnicodeUCS4_IsUppercase(ch: Py_UNICODE) -> c_int; fn _PyUnicodeUCS4_IsTitlecase(ch: Py_UNICODE) -> c_int; @@ -400,315 +255,192 @@ extern "C" { } #[allow(dead_code)] -#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] - fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] - fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] - fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] +#[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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] fn PyUnicodeUCS2_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] - fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] - fn PyUnicodeUCS2_FromEncodedObject( - obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] - fn PyUnicodeUCS2_AsWideChar( - unicode: *mut PyUnicodeObject, - w: *mut wchar_t, - size: Py_ssize_t, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] + 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; - #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] - fn _PyUnicodeUCS2_AsDefaultEncodedString( - arg1: *mut PyObject, - arg2: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] - fn PyUnicodeUCS2_AsEncodedObject( - unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] - fn PyUnicodeUCS2_AsEncodedString( - unicode: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, - ) -> *mut PyObject; + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] - fn PyUnicodeUCS2_EncodeUTF8( - data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] + 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_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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] - fn PyUnicodeUCS2_DecodeLatin1( - string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] - fn PyUnicodeUCS2_EncodeLatin1( - data: *const Py_UNICODE, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] - fn PyUnicodeUCS2_DecodeASCII( - string: *const c_char, - length: Py_ssize_t, - errors: *const c_char, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] + 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] - fn PyUnicodeUCS2_EncodeDecimal( - s: *mut Py_UNICODE, - length: Py_ssize_t, - output: *mut c_char, - errors: *const c_char, - ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] - fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] - fn PyUnicodeUCS2_Split( - s: *mut PyObject, - sep: *mut PyObject, - maxsplit: Py_ssize_t, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] - fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] - fn PyUnicodeUCS2_Tailmatch( - str: *mut PyObject, - substr: *mut PyObject, - start: Py_ssize_t, - end: Py_ssize_t, - direction: c_int, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] - fn PyUnicodeUCS2_Find( - str: *mut PyObject, - substr: *mut PyObject, - start: Py_ssize_t, - end: Py_ssize_t, - direction: c_int, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] - fn PyUnicodeUCS2_Count( - str: *mut PyObject, - substr: *mut PyObject, - start: Py_ssize_t, - end: Py_ssize_t, - ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] - fn PyUnicodeUCS2_Replace( - str: *mut PyObject, - substr: *mut PyObject, - replstr: *mut PyObject, - maxcount: Py_ssize_t, - ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] - 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] - 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_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; @@ -727,48 +459,41 @@ extern "C" { } #[inline(always)] -#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] +#[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(always)] -#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] +#[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(always)] -#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] +#[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"))] +#[inline(always)] +#[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")] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] -pub unsafe fn PyUnicode_FromEncodedObject( - obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char, -) -> *mut PyObject { +#[inline(always)] +#[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 { +#[inline(always)] +#[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) } diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index 1a9777175e6..a609b0e8512 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -1,27 +1,19 @@ -use crate::ffi2::object::PyObject; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::PyObject; -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyErr_WarnEx")] - 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; +#[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] -#[cfg_attr(PyPy, link_name = "PyPyErr_Warn")] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) } diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index 3ea116b55f6..f13714d08af 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -1,13 +1,13 @@ -use crate::ffi2::object::*; -use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_int, c_long}; +use ffi2::pyport::Py_ssize_t; +use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyWeakReference { - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] + #[cfg(py_sys_config="Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -15,60 +15,50 @@ pub struct PyWeakReference { pub wr_callback: *mut PyObject, pub hash: c_long, pub wr_prev: *mut PyWeakReference, - pub wr_next: *mut PyWeakReference, + pub wr_next: *mut PyWeakReference } -#[cfg_attr(windows, link(name = "pythonXY"))] -extern "C" { +#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { static mut _PyWeakref_RefType: PyTypeObject; static mut _PyWeakref_ProxyType: PyTypeObject; static mut _PyWeakref_CallableProxyType: PyTypeObject; } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRef")] +#[inline(always)] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRefExact")] +#[inline(always)] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } -#[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckProxy")] +#[inline(always)] pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int { - ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) - || (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int + ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) || + (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int } -#[inline] +#[inline(always)] 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" { - #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")] - pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")] - pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")] +#[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] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_GET_OBJECT")] +#[inline(always)] pub unsafe fn PyWeakref_GET_OBJECT(_ref: *mut PyObject) -> *mut PyObject { let obj = (*(_ref as *mut PyWeakReference)).wr_object; - if Py_REFCNT(obj) > 0 { - obj - } else { - Py_None() - } + if Py_REFCNT(obj) > 0 { obj } else { Py_None() } } + From 550903939b1f35313aecd4b093efeafe599963d8 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 13:25:15 +0200 Subject: [PATCH 050/138] revert changes to ffi2 --- src/ffi2/boolobject.rs | 21 +- src/ffi2/bufferobject.rs | 45 +- src/ffi2/bytearrayobject.rs | 38 +- src/ffi2/bytesobject.rs | 32 +- src/ffi2/cellobject.rs | 25 +- src/ffi2/ceval.rs | 68 ++- src/ffi2/classobject.rs | 85 ++-- src/ffi2/cobject.rs | 35 +- src/ffi2/code.rs | 96 ++-- src/ffi2/compile.rs | 38 +- src/ffi2/complexobject.rs | 52 +- src/ffi2/descrobject.rs | 91 ++-- src/ffi2/dictobject.rs | 87 ++-- src/ffi2/enumobject.rs | 6 +- src/ffi2/eval.rs | 36 +- src/ffi2/fileobject.rs | 84 ++-- src/ffi2/floatobject.rs | 42 +- src/ffi2/frameobject.rs | 79 +-- src/ffi2/funcobject.rs | 35 +- src/ffi2/genobject.rs | 29 +- src/ffi2/import.rs | 118 +++-- src/ffi2/intobject.rs | 57 +-- src/ffi2/iterobject.rs | 14 +- src/ffi2/listobject.rs | 80 +-- src/ffi2/longobject.rs | 128 +++-- src/ffi2/memoryobject.rs | 44 +- src/ffi2/methodobject.rs | 110 ++-- src/ffi2/mod.rs | 162 +++--- src/ffi2/modsupport.rs | 174 ++++--- src/ffi2/moduleobject.rs | 43 +- src/ffi2/object.rs | 597 ++++++++++++---------- src/ffi2/objectabstract.rs | 506 +++++++++++-------- src/ffi2/objimpl.rs | 64 +-- src/ffi2/pyarena.rs | 9 +- src/ffi2/pycapsule.rs | 54 +- src/ffi2/pydebug.rs | 23 +- src/ffi2/pyerrors.rs | 291 ++++++----- src/ffi2/pymem.rs | 4 +- src/ffi2/pyport.rs | 5 +- src/ffi2/pystate.rs | 80 +-- src/ffi2/pythonrun.rs | 196 +++++--- src/ffi2/rangeobject.rs | 13 +- src/ffi2/setobject.rs | 62 ++- src/ffi2/sliceobject.rs | 62 ++- src/ffi2/stringobject.rs | 194 ++++---- src/ffi2/structmember.rs | 66 ++- src/ffi2/traceback.rs | 29 +- src/ffi2/tupleobject.rs | 56 ++- src/ffi2/unicodeobject.rs | 969 +++++++++++++++++++++++------------- src/ffi2/warnings.rs | 30 +- src/ffi2/weakrefobject.rs | 52 +- 51 files changed, 3144 insertions(+), 2172 deletions(-) diff --git a/src/ffi2/boolobject.rs b/src/ffi2/boolobject.rs index 1ea79af49b5..145a0a3b222 100644 --- a/src/ffi2/boolobject.rs +++ b/src/ffi2/boolobject.rs @@ -1,28 +1,33 @@ +use crate::ffi2::intobject::PyIntObject; +use crate::ffi2::object::*; use std::os::raw::{c_int, c_long}; -use ffi2::object::*; -use ffi2::intobject::PyIntObject; pub type PyBoolObject = PyIntObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "_PyPy_ZeroStruct")] static mut _Py_ZeroStruct: PyIntObject; + #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyIntObject; + #[cfg_attr(PyPy, link_name = "PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } -#[inline(always)] -pub unsafe fn PyBool_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyBool_Type; +#[cfg_attr(PyPy, link_name = "PyPyBool_Check")] +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(always)] +#[inline] pub unsafe fn Py_False() -> *mut PyObject { &mut _Py_ZeroStruct as *mut PyBoolObject as *mut PyObject } -#[inline(always)] +#[inline] pub unsafe fn Py_True() -> *mut PyObject { &mut _Py_TrueStruct as *mut PyBoolObject as *mut PyObject } diff --git a/src/ffi2/bufferobject.rs b/src/ffi2/bufferobject.rs index 868ef0d3e71..8e01ea1aad0 100644 --- a/src/ffi2/bufferobject.rs +++ b/src/ffi2/bufferobject.rs @@ -1,28 +1,37 @@ -use std::os::raw::{c_void, c_int}; -use ffi2::object::*; -use ffi2::pyport::Py_ssize_t; +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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBuffer_Type")] pub static mut PyBuffer_Type: PyTypeObject; } - -#[inline(always)] -pub unsafe fn PyBuffer_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyBuffer_Type; +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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromObject")] + pub fn PyBuffer_FromObject( + base: *mut PyObject, + offset: Py_ssize_t, + size: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteObject")] + pub fn PyBuffer_FromReadWriteObject( + base: *mut PyObject, + offset: Py_ssize_t, + size: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromMemory")] + pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteMemory")] + pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_New")] pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject; } diff --git a/src/ffi2/bytearrayobject.rs b/src/ffi2/bytearrayobject.rs index a5c529010f5..bab35e12d88 100644 --- a/src/ffi2/bytearrayobject.rs +++ b/src/ffi2/bytearrayobject.rs @@ -1,6 +1,6 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; /*#[repr(C)] #[deriving(Copy)] @@ -17,33 +17,41 @@ struct PyByteArrayObject { pub ob_bytes: *mut c_char, }*/ -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } -pub unsafe fn PyByteArray_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyByteArray_Check")] +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; +#[cfg_attr(PyPy, link_name = "PyPyByteArray_CheckExact")] +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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromObject")] 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; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Concat")] + pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromStringAndSize")] + pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyByteArray_Resize")] + pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; } -#[inline(always)] +#[inline] pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char { PyByteArray_AsString(o) // #define PyByteArray_AS_STRING(self) \ @@ -51,7 +59,7 @@ pub unsafe fn PyByteArray_AS_STRING(o: *mut PyObject) -> *mut c_char { // Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string) } -#[inline(always)] +#[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) diff --git a/src/ffi2/bytesobject.rs b/src/ffi2/bytesobject.rs index 51d4988124e..b27b0896169 100644 --- a/src/ffi2/bytesobject.rs +++ b/src/ffi2/bytesobject.rs @@ -1,16 +1,16 @@ -pub use ffi2::stringobject::PyStringObject as PyBytesObject; -pub use ffi2::stringobject::PyString_Type as PyBytes_Type; -pub use ffi2::stringobject::PyString_Check as PyBytes_Check; -pub use ffi2::stringobject::PyString_CheckExact as PyBytes_CheckExact; -pub use ffi2::stringobject::PyString_AS_STRING as PyBytes_AS_STRING; -pub use ffi2::stringobject::PyString_GET_SIZE as PyBytes_GET_SIZE; -pub use ffi2::object::Py_TPFLAGS_STRING_SUBCLASS as Py_TPFLAGS_BYTES_SUBCLASS; -pub use ffi2::stringobject::PyString_FromStringAndSize as PyBytes_FromStringAndSize; -pub use ffi2::stringobject::PyString_FromString as PyBytes_FromString; -pub use ffi2::stringobject::PyString_FromFormat as PyBytes_FromFormat; -pub use ffi2::stringobject::PyString_Size as PyBytes_Size; -pub use ffi2::stringobject::PyString_AsString as PyBytes_AsString; -pub use ffi2::stringobject::PyString_Concat as PyBytes_Concat; -pub use ffi2::stringobject::PyString_ConcatAndDel as PyBytes_ConcatAndDel; -pub use ffi2::stringobject::PyString_Format as PyBytes_Format; -pub use ffi2::stringobject::PyString_AsStringAndSize as PyBytes_AsStringAndSize; +pub use 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; diff --git a/src/ffi2/cellobject.rs b/src/ffi2/cellobject.rs index 3edb4e5742a..5d13f5196e6 100644 --- a/src/ffi2/cellobject.rs +++ b/src/ffi2/cellobject.rs @@ -1,40 +1,43 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] struct PyCellObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub ob_ref: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCell_Type")] pub static mut PyCell_Type: PyTypeObject; } -#[inline(always)] +#[inline] pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyCell_Type) as c_int + (Py_TYPE(op) == &mut PyCell_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyCell_New(obj: *mut PyObject) -> *mut PyObject; pub fn PyCell_Get(op: *mut PyObject) -> *mut PyObject; pub fn PyCell_Set(op: *mut PyObject, obj: *mut PyObject) -> c_int; } -#[inline(always)] +#[inline] pub unsafe fn PyCell_GET(op: *mut PyObject) -> *mut PyObject { (*(op as *mut PyCellObject)).ob_ref } -#[inline(always)] +#[inline] pub unsafe fn PyCell_SET(op: *mut PyObject, obj: *mut PyObject) { (*(op as *mut PyCellObject)).ob_ref = obj; } diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 316ca0a1e38..05a29f3970b 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -1,33 +1,50 @@ -use std::os::raw::{c_void, c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::PyObject; -use ffi2::frameobject::PyFrameObject; -use ffi2::pystate::{PyThreadState, Py_tracefunc}; -use ffi2::pythonrun::PyCompilerFlags; +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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_CallObjectWithKeywords")] + pub fn PyEval_CallObjectWithKeywords( + callable: *mut PyObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_CallFunction")] + pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_CallMethod")] + pub fn PyEval_CallMethod( + obj: *mut PyObject, + methodname: *const c_char, + format: *const c_char, + ... + ) -> *mut PyObject; pub fn PyEval_SetProfile(func: Option, obj: *mut PyObject); pub fn PyEval_SetTrace(func: Option, obj: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut PyFrameObject; pub fn PyEval_GetRestricted() -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyEval_MergeCompilerFlags")] pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int; pub fn Py_FlushLine() -> c_int; - pub fn Py_AddPendingCall(func: Option c_int>, - arg: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_AddPendingCall")] + pub fn Py_AddPendingCall( + func: Option c_int>, + arg: *mut c_void, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int); + #[cfg_attr(PyPy, link_name = "PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; @@ -36,20 +53,27 @@ use ffi2::pythonrun::PyCompilerFlags; 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; + #[cfg_attr(PyPy, link_name = "PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState); - + + #[cfg_attr(PyPy, link_name = "_PyPyEval_SliceIndex")] 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" { +#[cfg(py_sys_config = "WITH_THREAD")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyEval_InitThreads")] pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); pub fn PyEval_ReleaseLock(); + #[cfg_attr(PyPy, link_name = "PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); + #[cfg_attr(PyPy, link_name = "PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); } - diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index a11e49d1374..d2935e5cf16 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -1,13 +1,13 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyClassObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -23,9 +23,9 @@ pub struct PyClassObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PyInstanceObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -37,9 +37,9 @@ pub struct PyInstanceObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PyMethodObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -49,61 +49,76 @@ pub struct PyMethodObject { pub im_weakreflist: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyClass_Type: PyTypeObject; + // TODO: check why this symbol isn't exported by libpypy + #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyInstance_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyMethod_Type")] pub static mut PyMethod_Type: PyTypeObject; } #[inline(always)] -pub unsafe fn PyClass_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyClass_Type; +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(always)] -pub unsafe fn PyInstance_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyInstance_Type; +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(always)] -pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyMethod_Type; +#[cfg_attr(PyPy, link_name = "PyPyMethod_Check")] +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; +#[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; + #[cfg_attr(PyPy, link_name = "PyPyMethod_New")] + pub fn PyMethod_New( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMethod_Function")] pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMethod_Self")] pub fn PyMethod_Self(arg1: *mut PyObject) -> *mut PyObject; pub fn PyMethod_Class(arg1: *mut PyObject) -> *mut PyObject; - fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) - -> *mut PyObject; - pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) - -> c_int; + fn _PyInstance_Lookup(pinst: *mut PyObject, name: *mut PyObject) -> *mut PyObject; + pub fn PyClass_IsSubclass(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; pub fn PyMethod_ClearFreeList() -> c_int; } -#[inline(always)] -pub unsafe fn PyMethod_GET_FUNCTION(meth : *mut PyObject) -> *mut PyObject { +#[inline] +pub unsafe fn PyMethod_GET_FUNCTION(meth: *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_func } -#[inline(always)] -pub unsafe fn PyMethod_GET_SELF(meth : *mut PyObject) -> *mut PyObject { +#[inline] +pub unsafe fn PyMethod_GET_SELF(meth: *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_self } -#[inline(always)] -pub unsafe fn PyMethod_GET_CLASS(meth : *mut PyObject) -> *mut PyObject { +#[inline] +pub unsafe fn PyMethod_GET_CLASS(meth: *mut PyObject) -> *mut PyObject { (*(meth as *mut PyMethodObject)).im_class } - diff --git a/src/ffi2/cobject.rs b/src/ffi2/cobject.rs index b655ae39a08..c28d6a9cf13 100644 --- a/src/ffi2/cobject.rs +++ b/src/ffi2/cobject.rs @@ -1,27 +1,36 @@ -use std::os::raw::{c_void, c_char, c_int}; -use ffi2::object::*; +use crate::ffi2::object::*; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCObject_Type")] pub static mut PyCObject_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int { +#[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) - -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtr")] + pub fn PyCObject_FromVoidPtr( + cobj: *mut c_void, + destruct: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtrAndDesc")] pub fn PyCObject_FromVoidPtrAndDesc( cobj: *mut c_void, desc: *mut c_void, - destruct: Option) - -> *mut PyObject; + destruct: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCObject_AsVoidPtr")] pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCObject_GetDesc")] 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; + #[cfg_attr(PyPy, link_name = "PyPyCObject_Import")] + pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCObject_SetVoidPtr")] pub fn PyCObject_SetVoidPtr(_self: *mut PyObject, cobj: *mut c_void) -> c_int; } diff --git a/src/ffi2/code.rs b/src/ffi2/code.rs index 0402e8ef35b..4a11c5a506d 100644 --- a/src/ffi2/code.rs +++ b/src/ffi2/code.rs @@ -1,13 +1,13 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int, c_void}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyCodeObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -30,58 +30,74 @@ pub struct PyCodeObject { } /* 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; +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_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_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; +pub const CO_MAXBLOCKS: usize = 20; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyCode_Type: PyTypeObject; - - pub fn PyCode_New(arg1: c_int, arg2: c_int, - arg3: c_int, arg4: c_int, - arg5: *mut PyObject, arg6: *mut PyObject, - arg7: *mut PyObject, arg8: *mut PyObject, - arg9: *mut PyObject, arg10: *mut PyObject, - arg11: *mut PyObject, arg12: *mut PyObject, - arg13: c_int, arg14: *mut PyObject) - -> *mut PyCodeObject; - pub fn PyCode_NewEmpty(filename: *const c_char, - funcname: *const c_char, - firstlineno: c_int) -> *mut PyCodeObject; - pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) - -> c_int; + + #[cfg_attr(PyPy, link_name = "PyPyCode_New")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyCode_Check")] //fn _PyCode_CheckLineNumber(co: *mut PyCodeObject, // lasti: c_int, // bounds: *mut PyAddrPair) -> c_int; - pub fn PyCode_Optimize(code: *mut PyObject, consts: *mut PyObject, - names: *mut PyObject, lineno_obj: *mut PyObject) - -> *mut PyObject; + pub fn PyCode_Optimize( + code: *mut PyObject, + consts: *mut PyObject, + names: *mut PyObject, + lineno_obj: *mut PyObject, + ) -> *mut PyObject; } -#[inline(always)] -pub unsafe fn PyCode_Check(op : *mut PyObject) -> c_int { +#[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 { - ::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) +#[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")] +pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { + crate::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } - diff --git a/src/ffi2/compile.rs b/src/ffi2/compile.rs index a136e8f5104..8de22215bfa 100644 --- a/src/ffi2/compile.rs +++ b/src/ffi2/compile.rs @@ -1,7 +1,7 @@ +use crate::ffi2::code::*; +use crate::ffi2::pyarena::PyArena; +use crate::ffi2::pythonrun::*; use std::os::raw::{c_char, c_int}; -use ffi2::pythonrun::*; -use ffi2::code::*; -use ffi2::pyarena::PyArena; #[repr(C)] #[derive(Copy, Clone)] @@ -10,20 +10,22 @@ pub struct PyFutureFeatures { 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"; +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; +#[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; } diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index f0d1b9d2808..23da782ba10 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -1,15 +1,16 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_double, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct Py_complex { pub real: c_double, - pub imag: c_double + pub imag: c_double, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn _Py_c_sum(left: Py_complex, right: Py_complex) -> Py_complex; pub fn _Py_c_diff(left: Py_complex, right: Py_complex) -> Py_complex; pub fn _Py_c_neg(complex: Py_complex) -> Py_complex; @@ -22,42 +23,49 @@ pub struct Py_complex { #[repr(C)] #[derive(Copy, Clone)] pub struct PyComplexObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub cval: Py_complex, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyComplex_Check(op : *mut PyObject) -> c_int { +#[cfg_attr(PyPy, link_name = "PyPyComplex_Check")] +#[inline] +pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } -#[inline(always)] -pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyComplex_Type; +#[cfg_attr(PyPy, link_name = "PyPyComplex_CheckExact")] +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; - pub fn PyComplex_FromDoubles(real: c_double, - imag: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")] + pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")] 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; +//fn _PyComplex_FormatAdvanced(obj: *mut PyObject, +// format_spec: *mut c_char, +// format_spec_len: Py_ssize_t) +// -> *mut PyObject; } - diff --git a/src/ffi2/descrobject.rs b/src/ffi2/descrobject.rs index 6a06c56ced5..a8c1d12ffd7 100644 --- a/src/ffi2/descrobject.rs +++ b/src/ffi2/descrobject.rs @@ -1,16 +1,13 @@ +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; -use std::os::raw::{c_void, c_char, c_int}; -use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; -use ffi2::structmember::PyMemberDef; -use ffi2::methodobject::PyMethodDef; -pub type getter = - unsafe extern "C" fn - (slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; +pub type getter = unsafe extern "C" fn(slf: *mut PyObject, closure: *mut c_void) -> *mut PyObject; pub type setter = - unsafe extern "C" fn (slf: *mut PyObject, value: *mut PyObject, - closure: *mut c_void) -> c_int; + unsafe extern "C" fn(slf: *mut PyObject, value: *mut PyObject, closure: *mut c_void) -> c_int; #[repr(C)] #[derive(Copy)] @@ -22,7 +19,7 @@ pub struct PyGetSetDef { pub closure: *mut c_void, } -pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { +pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef { name: ptr::null_mut(), get: None, set: None, @@ -31,16 +28,24 @@ pub const PyGetSetDef_INIT : PyGetSetDef = PyGetSetDef { }; impl Clone for PyGetSetDef { - #[inline] fn clone(&self) -> PyGetSetDef { *self } + #[inline] + fn clone(&self) -> PyGetSetDef { + *self + } } -pub type wrapperfunc = - unsafe extern "C" fn(slf: *mut PyObject, args: *mut PyObject, - wrapped: *mut c_void) -> *mut PyObject; +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; +pub type wrapperfunc_kwds = unsafe extern "C" fn( + slf: *mut PyObject, + args: *mut PyObject, + wrapped: *mut c_void, + kwds: *mut PyObject, +) -> *mut PyObject; #[repr(C)] #[derive(Copy)] @@ -51,47 +56,53 @@ pub struct wrapperbase { pub wrapper: Option, pub doc: *mut c_char, pub flags: c_int, - pub name_strobj: *mut PyObject + pub name_strobj: *mut PyObject, } impl Clone for wrapperbase { - #[inline] fn clone(&self) -> wrapperbase { *self } + #[inline] + fn clone(&self) -> wrapperbase { + *self + } } -pub const PyWrapperFlag_KEYWORDS : c_int = 1; +pub const PyWrapperFlag_KEYWORDS: c_int = 1; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyProperty_Type")] 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; + pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDescr_NewClassMethod")] + 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(always)] +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] //pub fn PyDictProxy_New(arg1: *mut PyObject) -> *mut PyObject; // PyDictProxy_New is also defined in dictobject.h - pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) - -> *mut PyObject; + pub fn PyWrapper_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } - - - - diff --git a/src/ffi2/dictobject.rs b/src/ffi2/dictobject.rs index 57263ac2bb0..97fdb11a1fe 100644 --- a/src/ffi2/dictobject.rs +++ b/src/ffi2/dictobject.rs @@ -1,10 +1,12 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; //pub enum PyDictObject { /* representation hidden */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDict_Type")] pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -14,45 +16,62 @@ use ffi2::object::*; pub static mut PyDictValues_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyDict_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyDict_Type; +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject); - pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Contains")] + pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Copy")] 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; - + + #[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")] + pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_SetItem")] + pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_DelItem")] + pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemString")] + pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_SetItemString")] + pub fn PyDict_SetItemString( + dp: *mut PyObject, + key: *const c_char, + item: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")] + pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; + + #[cfg_attr(PyPy, link_name = "PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDict_Size")] 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; + #[cfg_attr(PyPy, link_name = "PyPyDict_Next")] + pub fn PyDict_Next( + mp: *mut PyObject, + pos: *mut Py_ssize_t, + key: *mut *mut PyObject, + value: *mut *mut PyObject, + ) -> c_int; /*pub fn _PyDict_Next(mp: *mut PyObject, pos: *mut Py_ssize_t, key: *mut *mut PyObject, value: *mut *mut PyObject, hash: *mut c_long) -> c_int; @@ -60,12 +79,10 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { hash: c_long) -> c_int; pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/ - pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) - -> c_int; - pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject, - _override: c_int) -> c_int; - pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject, - _override: c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Update")] + pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDict_Merge")] + 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; } - diff --git a/src/ffi2/enumobject.rs b/src/ffi2/enumobject.rs index 50424901292..07e84b7a5fe 100644 --- a/src/ffi2/enumobject.rs +++ b/src/ffi2/enumobject.rs @@ -1,7 +1,7 @@ -use ffi2::object::PyTypeObject; +use crate::ffi2::object::PyTypeObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyEnum_Type: PyTypeObject; pub static mut PyReversed_Type: PyTypeObject; } - diff --git a/src/ffi2/eval.rs b/src/ffi2/eval.rs index 4a2660f78e7..b36b28c56c0 100644 --- a/src/ffi2/eval.rs +++ b/src/ffi2/eval.rs @@ -1,16 +1,26 @@ +use crate::ffi2::code::PyCodeObject; +use crate::ffi2::object::PyObject; use std::os::raw::c_int; -use ffi2::object::PyObject; -use ffi2::code::PyCodeObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyEval_EvalCode(arg1: *mut PyCodeObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; - pub fn PyEval_EvalCodeEx(co: *mut PyCodeObject, globals: *mut PyObject, - locals: *mut PyObject, args: *mut *mut PyObject, - argc: c_int, kwds: *mut *mut PyObject, - kwdc: c_int, defs: *mut *mut PyObject, - defc: c_int, closure: *mut PyObject) - -> *mut PyObject; - fn _PyEval_CallTracing(func: *mut PyObject, args: *mut PyObject) - -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyEval_EvalCode")] + 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; } diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index 6838ca3e723..5fb1faf59bf 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -1,59 +1,69 @@ +use crate::ffi2::object::*; use libc::{size_t, FILE}; use std::os::raw::{c_char, c_int}; -use ffi2::object::*; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyFile_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyFile_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyFile_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFile_Type) } -#[inline(always)] -pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int { +#[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"; -pub const PY_STDIOTEXTMODE : &'static str = "b"; - -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyFile_FromString(arg1: *mut c_char, - arg2: *mut c_char) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFile_FromString")] + pub fn PyFile_FromString(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFile_SetBufSize")] 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 c_int>) - -> *mut PyObject; + pub fn PyFile_SetEncoding(arg1: *mut PyObject, arg2: *const c_char) -> c_int; + pub fn PyFile_SetEncodingAndErrors( + arg1: *mut PyObject, + arg2: *const c_char, + errors: *mut c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyFile_FromFile")] + pub fn PyFile_FromFile( + arg1: *mut FILE, + arg2: *mut c_char, + arg3: *mut c_char, + arg4: Option 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); + #[cfg_attr(PyPy, link_name = "PyPyFile_Name")] 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; + #[cfg_attr(PyPy, link_name = "PyPyFile_GetLine")] + pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFile_WriteObject")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyFile_WriteString")] + pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsFileDescriptor")] pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int; - pub fn Py_UniversalNewlineFgets(arg1: *mut c_char, - arg2: c_int, arg3: *mut FILE, - arg4: *mut PyObject) - -> *mut c_char; - pub fn Py_UniversalNewlineFread(arg1: *mut c_char, arg2: size_t, - arg3: *mut FILE, arg4: *mut PyObject) - -> size_t; + pub fn Py_UniversalNewlineFgets( + arg1: *mut c_char, + arg2: c_int, + arg3: *mut FILE, + arg4: *mut PyObject, + ) -> *mut c_char; + pub fn Py_UniversalNewlineFread( + arg1: *mut c_char, + arg2: size_t, + arg3: *mut FILE, + arg4: *mut PyObject, + ) -> size_t; pub static mut Py_FileSystemDefaultEncoding: *const c_char; } - diff --git a/src/ffi2/floatobject.rs b/src/ffi2/floatobject.rs index faa0688b47f..9ea642f52a2 100644 --- a/src/ffi2/floatobject.rs +++ b/src/ffi2/floatobject.rs @@ -1,41 +1,47 @@ -use std::os::raw::{c_char, c_int, c_double}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; +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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub ob_fval: c_double, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyFloat_Check(op : *mut PyObject) -> c_int { +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyFloat_Check")] +pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } -#[inline(always)] -pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyFloat_Type; +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyFloat_CheckExact")] +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; +pub const PyFloat_STR_PRECISION: c_int = 12; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyFloat_FromString(str: *mut PyObject, - pend: *mut *mut c_char) - -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFloat_FromString")] + pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; @@ -44,7 +50,7 @@ pub const PyFloat_STR_PRECISION : c_int = 12; pub fn PyFloat_ClearFreeList() -> c_int; } +#[cfg_attr(PyPy, link_name = "PyPyFloat_AS_DOUBLE")] pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double { (*(pyfloat as *mut PyFloatObject)).ob_fval } - diff --git a/src/ffi2/frameobject.rs b/src/ffi2/frameobject.rs index 004b5440655..80ca7c4c2df 100644 --- a/src/ffi2/frameobject.rs +++ b/src/ffi2/frameobject.rs @@ -1,38 +1,38 @@ +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; -use ffi2::object::*; -use ffi2::pyport::Py_ssize_t; -use ffi2::code::{PyCodeObject, CO_MAXBLOCKS}; -use ffi2::pystate::PyThreadState; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTryBlock { - pub b_type : c_int, - pub b_handler : c_int, - pub b_level : c_int, + 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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 */ + 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. */ + 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_trace: *mut PyObject, /* Trace function */ pub f_exc_type: *mut PyObject, pub f_exc_value: *mut PyObject, @@ -40,25 +40,26 @@ pub struct PyFrameObject { pub f_tstate: *mut PyThreadState, - pub f_lasti: c_int, /* Last instruction if called */ + 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 */ + 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 */ + pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyFrame_Type: PyTypeObject; } #[inline] pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { - ((*op).ob_type == &mut PyFrame_Type) as c_int + ((*op).ob_type == &mut PyFrame_Type) as c_int } //#[inline] @@ -66,17 +67,27 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { // ((*f).f_builtins != (*(*(*f).f_tstate).interp).builtins) as c_int //} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, - globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFrame_New")] + pub fn PyFrame_New( + tstate: *mut PyThreadState, + code: *mut PyCodeObject, + globals: *mut PyObject, + locals: *mut PyObject, + ) -> *mut PyFrameObject; - pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int) -> (); + pub fn PyFrame_BlockSetup( + f: *mut PyFrameObject, + _type: c_int, + handler: c_int, + level: c_int, + ) -> (); pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock; pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int) -> (); pub fn PyFrame_FastToLocals(f: *mut PyFrameObject) -> (); - + pub fn PyFrame_ClearFreeList() -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; } - diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index 075116a32ab..a03f964f71e 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -1,34 +1,37 @@ +use crate::ffi2::object::*; use std::os::raw::c_int; -use ffi2::object::*; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyFunction_Type")] pub static mut PyFunction_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyFunction_Type; +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyFunction_Check")] +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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFunction_GetCode")] pub fn PyFunction_GetCode(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetGlobals(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetModule(f: *mut PyObject) -> *mut PyObject; pub fn PyFunction_GetDefaults(f: *mut PyObject) -> *mut PyObject; - pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) - -> c_int; + pub fn PyFunction_SetDefaults(f: *mut PyObject, defaults: *mut PyObject) -> c_int; pub fn PyFunction_GetClosure(f: *mut PyObject) -> *mut PyObject; - pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) - -> c_int; - + pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) -> c_int; + pub static mut PyClassMethod_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_Type")] pub static mut PyStaticMethod_Type: PyTypeObject; - + + #[cfg_attr(PyPy, link_name = "PyPyClassMethod_New")] pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_New")] pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; } - diff --git a/src/ffi2/genobject.rs b/src/ffi2/genobject.rs index 9dd8f2cc3d0..30742a9cfae 100644 --- a/src/ffi2/genobject.rs +++ b/src/ffi2/genobject.rs @@ -1,39 +1,42 @@ +use crate::ffi2::frameobject::PyFrameObject; +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; -use ffi2::frameobject::PyFrameObject; #[repr(C)] #[derive(Copy, Clone)] pub struct PyGenObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub gi_weakreflist: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyGen_Type: PyTypeObject; } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { - PyObject_TypeCheck(op, &mut PyGen_Type) + PyObject_TypeCheck(op, &mut PyGen_Type) } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PyGen_Type) as c_int + (Py_TYPE(op) == &mut PyGen_Type) as c_int } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject; pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int; } - diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index 9b0b7b9eda2..0b67d5287f9 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -1,5 +1,5 @@ -use std::os::raw::{c_char, c_uchar, c_int, c_long}; -use ffi2::object::*; +use crate::ffi2::object::*; +use std::os::raw::{c_char, c_int, c_long, c_uchar}; #[repr(C)] #[derive(Copy)] @@ -9,7 +9,10 @@ pub struct PyImport_Struct_inittab { } impl Clone for PyImport_Struct_inittab { - #[inline] fn clone(&self) -> PyImport_Struct_inittab { *self } + #[inline] + fn clone(&self) -> PyImport_Struct_inittab { + *self + } } #[repr(C)] @@ -21,66 +24,75 @@ pub struct PyImport_Struct_frozen { } #[inline] -pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, - globals: *mut PyObject, - locals: *mut PyObject, - fromlist: *mut PyObject) -> *mut PyObject { +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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")] + pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")] 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; + #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModule")] + pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModuleEx")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")] 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) - -> c_int; - pub fn PyImport_ExtendInittab(newtab: *mut PyImport_Struct_inittab) - -> c_int; - + pub fn PyImport_ImportFrozenModule(name: *mut c_char) -> c_int; + + pub fn PyImport_AppendInittab( + name: *const c_char, + initfunc: Option, + ) -> 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;*/ -} +/*for internal use only: +pub fn PyImport_Cleanup(); +#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_AcquireLock")] +pub fn _PyImport_AcquireLock(); +#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_ReleaseLock")] +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;*/ +} diff --git a/src/ffi2/intobject.rs b/src/ffi2/intobject.rs index 1cb26f646ef..50b5eb355fd 100644 --- a/src/ffi2/intobject.rs +++ b/src/ffi2/intobject.rs @@ -1,43 +1,46 @@ +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}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyIntObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub ob_ival: c_long, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyInt_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyInt_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyInt_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyInt_Type; +#[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 ::ffi2::unicodeobject::Py_UNICODE, - length: Py_ssize_t, - base: c_int) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyInt_FromString(str: *mut c_char, pend: *mut *mut c_char, base: c_int) + -> *mut PyObject; + #[cfg(py_sys_config = "Py_USING_UNICODE")] + pub fn PyInt_FromUnicode( + u: *mut 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; @@ -45,8 +48,7 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { pub fn PyInt_AsSsize_t(io: *mut PyObject) -> Py_ssize_t; fn _PyInt_AsInt(io: *mut PyObject) -> c_int; pub fn PyInt_AsUnsignedLongMask(io: *mut PyObject) -> c_ulong; - pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) - -> c_ulonglong; + pub fn PyInt_AsUnsignedLongLongMask(io: *mut PyObject) -> c_ulonglong; pub fn PyInt_GetMax() -> c_long; //fn PyOS_strtoul(arg1: *mut c_char, // arg2: *mut *mut c_char, arg3: c_int) @@ -55,15 +57,14 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { // 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; +//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 } - diff --git a/src/ffi2/iterobject.rs b/src/ffi2/iterobject.rs index 45bd06a644b..ece1443087c 100644 --- a/src/ffi2/iterobject.rs +++ b/src/ffi2/iterobject.rs @@ -1,21 +1,23 @@ +use crate::ffi2::object::*; use std::os::raw::c_int; -use ffi2::object::*; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCallIter_New")] + pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } -#[inline(always)] +#[inline] pub unsafe fn PySeqIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PySeqIter_Type) as c_int } -#[inline(always)] +#[inline] pub unsafe fn PyCallIter_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCallIter_Type) as c_int } diff --git a/src/ffi2/listobject.rs b/src/ffi2/listobject.rs index 2724e4e6e36..1a269b5b9b1 100644 --- a/src/ffi2/listobject.rs +++ b/src/ffi2/listobject.rs @@ -1,13 +1,13 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyListObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -16,59 +16,73 @@ pub struct PyListObject { pub allocated: Py_ssize_t, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyList_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyList_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyList_Type; +#[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(always)] +/// Macro, trading safety for speed +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] 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) + *(*(op as *mut PyListObject)).ob_item.offset(i as isize) } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] 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(always)] +#[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")] 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; + *(*(op as *mut PyListObject)).ob_item.offset(i as isize) = v; } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyList_Size")] 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; + #[cfg_attr(PyPy, link_name = "PyPyList_GetItem")] + pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyList_SetItem")] + pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Insert")] + pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Append")] + pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_GetSlice")] + pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) + -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyList_SetSlice")] + pub fn PyList_SetSlice( + list: *mut PyObject, + low: Py_ssize_t, + high: Py_ssize_t, + itemlist: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Sort")] pub fn PyList_Sort(list: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_Reverse")] pub fn PyList_Reverse(list: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")] pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject; - //fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) - //-> *mut PyObject; +//fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) +//-> *mut PyObject; } - diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 3d13c58b94a..4c6001bdaef 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -1,83 +1,101 @@ -use std::os::raw::{c_void, c_char, c_int, c_long, c_ulong, c_longlong, c_ulonglong, c_double}; +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use libc::size_t; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; +use std::os::raw::{ + c_char, c_double, c_int, c_long, c_longlong, c_uchar, c_ulong, c_ulonglong, c_void, +}; -//enum PyLongObject { /* representation hidden */ } +/// 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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyLong_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyLong_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyLong_Type; +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyLong_FromLong")] pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject; - pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLongLong")] + pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromDouble")] 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 ::ffi2::unicodeobject::Py_UNICODE, - length: Py_ssize_t, base: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromString")] + 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")] + #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnicode")] + pub fn PyLong_FromUnicode( + u: *mut crate::ffi2::unicodeobject::Py_UNICODE, + length: Py_ssize_t, + base: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject; - + + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLong")] 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; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongAndOverflow")] + pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLongAndOverflow")] + pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; - pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) - -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLong")] + pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong; - pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) - -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLongMask")] + pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsDouble")] pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double; + #[cfg_attr(PyPy, link_name = "PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void; - + pub fn PyLong_GetInfo() -> *mut PyObject; - - /* - pub fn _PyLong_AsInt(arg1: *mut PyObject) -> c_int; - pub fn _PyLong_Frexp(a: *mut PyLongObject, e: *mut Py_ssize_t) - -> c_double; - - pub fn _PyLong_Sign(v: *mut PyObject) -> c_int; - pub fn _PyLong_NumBits(v: *mut PyObject) -> size_t; - 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: *mut c_uchar, n: size_t, - little_endian: c_int, - is_signed: c_int) -> c_int; - pub fn _PyLong_Format(aa: *mut PyObject, base: c_int, - addL: c_int, newstyle: c_int) - -> *mut PyObject; - pub fn _PyLong_FormatAdvanced(obj: *mut PyObject, - format_spec: *mut c_char, - format_spec_len: Py_ssize_t) - -> *mut PyObject;*/ -} +#[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_FromByteArray")] + 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; +} diff --git a/src/ffi2/memoryobject.rs b/src/ffi2/memoryobject.rs index 4fded996378..cfbd1c43a1b 100644 --- a/src/ffi2/memoryobject.rs +++ b/src/ffi2/memoryobject.rs @@ -1,46 +1,52 @@ -use std::os::raw::{c_int, c_char}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; +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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyMemoryView_Type; +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Check")] +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(always)] -pub unsafe fn PyMemoryView_GET_BUFFER(op : *mut PyObject) -> *mut Py_buffer { +#[inline] +pub unsafe fn PyMemoryView_GET_BUFFER(op: *mut PyObject) -> *mut Py_buffer { &mut (*(op as *mut PyMemoryViewObject)).view } -#[inline(always)] -pub unsafe fn PyMemoryView_GET_BASE(op : *mut PyObject) -> *mut PyObject { +#[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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyMemoryView_GetContiguous( + base: *mut PyObject, + buffertype: c_int, + fort: c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromBuffer")] 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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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, } - diff --git a/src/ffi2/methodobject.rs b/src/ffi2/methodobject.rs index 282ad062b09..30943d649c9 100644 --- a/src/ffi2/methodobject.rs +++ b/src/ffi2/methodobject.rs @@ -1,36 +1,39 @@ -use std::ptr; +use crate::ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; use std::os::raw::{c_char, c_int}; -use ffi2::object::{PyObject, PyTypeObject, Py_TYPE}; +use std::ptr; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } - -#[inline(always)] -pub unsafe fn PyCFunction_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyCFunction_Type; +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyCFunction_Check")] +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" { + 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" { + #[cfg_attr(PyPy, link_name = "PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; - pub fn PyCFunction_Call(f: *mut PyObject, args: *mut PyObject, - kwds: *mut PyObject) -> *mut PyObject; + pub fn PyCFunction_Call( + f: *mut PyObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; } #[repr(C)] @@ -42,7 +45,7 @@ pub struct PyMethodDef { pub ml_doc: *const c_char, } -pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { +pub const PyMethodDef_INIT: PyMethodDef = PyMethodDef { ml_name: ::std::ptr::null(), ml_meth: None, ml_flags: 0, @@ -50,30 +53,32 @@ pub const PyMethodDef_INIT : PyMethodDef = PyMethodDef { }; impl Clone for PyMethodDef { - #[inline] fn clone(&self) -> PyMethodDef { *self } + #[inline] + fn clone(&self) -> PyMethodDef { + *self + } } /* Flag passed to newmethodobject */ -pub const METH_OLDARGS : c_int = 0x0000; -pub const METH_VARARGS : c_int = 0x0001; -pub const METH_KEYWORDS : c_int = 0x0002; +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; +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; +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; +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)] @@ -98,18 +103,29 @@ struct PyCFunctionObject { } */ -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn Py_FindMethod(methods: *mut PyMethodDef, slf: *mut PyObject, - name: *const c_char) -> *mut PyObject; - pub fn PyCFunction_NewEx(ml: *mut PyMethodDef, slf: *mut PyObject, - module: *mut PyObject) -> *mut PyObject; - pub fn Py_FindMethodInChain(chain: *mut PyMethodChain, slf: *mut PyObject, - name: *const c_char) -> *mut PyObject; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPy_FindMethod")] + pub fn Py_FindMethod( + methods: *mut PyMethodDef, + slf: *mut PyObject, + name: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")] + 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(always)] +#[inline] pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyObject { PyCFunction_NewEx(ml, slf, ptr::null_mut()) } - diff --git a/src/ffi2/mod.rs b/src/ffi2/mod.rs index 099a33023c0..91e4f88a97c 100644 --- a/src/ffi2/mod.rs +++ b/src/ffi2/mod.rs @@ -1,99 +1,97 @@ //! Rust FFI declarations for Python 2 -#![no_std] #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] -#![cfg_attr(feature="cargo-clippy", allow(inline_always))] use std::os::raw::c_int; -pub use self::pyport::*; -pub use self::pymem::*; -pub use self::object::*; -pub use self::objimpl::*; -pub use self::pydebug::*; -#[cfg(py_sys_config="Py_USING_UNICODE")] -pub use self::unicodeobject::*; -pub use self::intobject::*; pub use self::boolobject::*; -pub use self::longobject::*; -pub use self::floatobject::*; -pub use self::complexobject::*; -pub use self::rangeobject::*; -pub use self::memoryobject::*; pub use self::bufferobject::*; -pub use self::stringobject::*; -pub use self::bytesobject::*; pub use self::bytearrayobject::*; -pub use self::tupleobject::*; -pub use self::listobject::*; +pub use self::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::setobject::*; -pub use self::pyerrors::*; -pub use self::pystate::*; -pub use self::pystate::PyGILState_STATE::*; +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::funcobject::*; -pub use self::classobject::*; -pub use self::fileobject::*; -pub use self::cobject::*; +pub use self::object::*; +pub use self::objectabstract::*; +pub use self::objimpl::*; +pub use self::pyarena::*; pub use self::pycapsule::*; -pub use self::traceback::*; +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::cellobject::*; -pub use self::iterobject::*; -pub use self::genobject::*; -pub use self::descrobject::*; +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::*; -pub use self::pyarena::*; -pub use self::modsupport::*; -pub use self::pythonrun::*; -pub use self::ceval::*; -pub use self::import::*; -pub use self::objectabstract::*; -pub use self::code::*; -pub use self::compile::*; -pub use self::eval::*; -pub use self::structmember::PyMemberDef; -pub use self::frameobject::PyFrameObject; -mod pyport; -mod pymem; -mod object; -mod objimpl; -mod pydebug; -#[cfg(py_sys_config="Py_USING_UNICODE")] -mod unicodeobject; // TODO: incomplete -mod intobject; mod boolobject; -mod longobject; -mod floatobject; -mod complexobject; -mod rangeobject; -mod stringobject; -mod memoryobject; mod bufferobject; -mod bytesobject; mod bytearrayobject; -mod tupleobject; -mod listobject; +mod bytesobject; +mod cellobject; +mod classobject; +mod cobject; +mod complexobject; +mod descrobject; mod dictobject; mod enumobject; -mod setobject; +mod fileobject; +mod floatobject; +mod funcobject; +mod genobject; +mod intobject; +mod iterobject; +mod listobject; +mod longobject; +mod memoryobject; mod methodobject; mod moduleobject; -mod funcobject; -mod classobject; -mod fileobject; -mod cobject; +mod object; +mod objimpl; mod pycapsule; -mod traceback; +mod pydebug; +mod pymem; +mod pyport; +mod rangeobject; +mod setobject; mod sliceobject; -mod cellobject; -mod iterobject; -mod genobject; -mod descrobject; +mod stringobject; +mod traceback; +mod tupleobject; +#[cfg(py_sys_config = "Py_USING_UNICODE")] +mod unicodeobject; // TODO: incomplete mod warnings; mod weakrefobject; @@ -102,10 +100,10 @@ mod pyerrors; mod pystate; -mod pyarena; +mod ceval; mod modsupport; +mod pyarena; mod pythonrun; -mod ceval; // mod sysmodule; // TODO: incomplete // mod intrcheck; // TODO: incomplete mod import; @@ -124,17 +122,23 @@ mod eval; // mod pyfpe; // TODO: incomplete // Additional headers that are not exported by Python.h -pub mod structmember; pub mod frameobject; +pub mod structmember; pub const Py_single_input: c_int = 256; pub const Py_file_input: c_int = 257; pub const Py_eval_input: c_int = 258; -#[cfg(not(py_sys_config="Py_USING_UNICODE"))] -#[inline(always)] -pub fn PyUnicode_Check(op : *mut PyObject) -> libc::c_int { 0 } +#[cfg(not(py_sys_config = "Py_USING_UNICODE"))] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] +pub fn PyUnicode_Check(op: *mut PyObject) -> libc::c_int { + 0 +} -#[cfg(not(py_sys_config="Py_USING_UNICODE"))] -#[inline(always)] -pub fn PyUnicode_CheckExact(op : *mut PyObject) -> libc::c_int { 0 } +#[cfg(not(py_sys_config = "Py_USING_UNICODE"))] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] +pub fn PyUnicode_CheckExact(op: *mut PyObject) -> libc::c_int { + 0 +} diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index c1450dbc00a..1e3f5994ef1 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -1,94 +1,150 @@ -use std::ptr; +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 ffi2::pyport::Py_ssize_t; -use ffi2::object::PyObject; -use ffi2::methodobject::PyMethodDef; +use std::ptr; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyArg_Parse")] 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; + #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTuple")] + pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTupleAndKeywords")] + pub fn PyArg_ParseTupleAndKeywords( + args: *mut PyObject, + kw: *mut PyObject, + format: *const c_char, + keywords: *mut *mut c_char, + ... + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyArg_UnpackTuple")] + pub fn PyArg_UnpackTuple( + args: *mut PyObject, + name: *const c_char, + min: Py_ssize_t, + max: Py_ssize_t, + ... + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPy_BuildValue")] pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPy_BuildValue_SizeT")] //fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyArg_NoKeywords")] //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_attr(PyPy, link_name = "PyPyModule_AddObject")] + pub fn PyModule_AddObject( + module: *mut PyObject, + name: *const c_char, + value: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddIntConstant")] + pub fn PyModule_AddIntConstant( + module: *mut PyObject, + name: *const c_char, + value: c_long, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyModule_AddStringConstant")] + 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_attr(PyPy, link_name = "_PyPy_InitPyPyModule")] + 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; + 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; + 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; + 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; +pub const PYTHON_API_VERSION: c_int = 1013; #[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))] -#[inline(always)] -pub unsafe fn Py_InitModule4(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject { +#[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(always)] -pub unsafe fn Py_InitModule4(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject { +#[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(always)] -pub unsafe fn Py_InitModule4(name: *const c_char, - methods: *mut PyMethodDef, - doc: *const c_char, _self: *mut PyObject, - apiver: c_int) -> *mut PyObject { +#[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(always)] +#[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) + Py_InitModule4( + name, + methods, + ptr::null(), + ptr::null_mut(), + PYTHON_API_VERSION, + ) } -#[inline(always)] -pub unsafe fn Py_InitModule3(name: *const c_char, methods: *mut PyMethodDef, doc : *const c_char) -> *mut PyObject { +#[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) } diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index 14da5f46548..12933e4b934 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -1,25 +1,30 @@ +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}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; -use ffi2::methodobject::PyMethodDef; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyModule_Check(op : *mut PyObject) -> c_int { +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyModule_Check")] +pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } -#[inline(always)] -pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { +#[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" { +#[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; + #[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")] 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; @@ -40,14 +45,16 @@ pub struct PyModuleDef_Base { pub m_copy: *mut PyObject, } impl Clone for PyModuleDef_Base { - fn clone(&self) -> PyModuleDef_Base { *self } + fn clone(&self) -> PyModuleDef_Base { + *self + } } pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base { ob_base: PyObject_HEAD_INIT, m_init: None, m_index: 0, - m_copy: ::std::ptr::null_mut() + m_copy: ::std::ptr::null_mut(), }; #[repr(C)] @@ -57,11 +64,13 @@ pub struct PyModuleDef_Slot { pub value: *mut c_void, } impl Clone for PyModuleDef_Slot { - fn clone(&self) -> PyModuleDef_Slot { *self } + fn clone(&self) -> PyModuleDef_Slot { + *self + } } -pub const Py_mod_create : c_int = 1; -pub const Py_mod_exec : c_int = 2; +pub const Py_mod_create: c_int = 1; +pub const Py_mod_exec: c_int = 2; #[repr(C)] #[derive(Copy)] @@ -77,7 +86,9 @@ pub struct PyModuleDef { pub m_free: Option, } impl Clone for PyModuleDef { - fn clone(&self) -> PyModuleDef { *self } + fn clone(&self) -> PyModuleDef { + *self + } } pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { @@ -89,5 +100,5 @@ pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { m_slots: ::std::ptr::null_mut(), m_traverse: None, m_clear: None, - m_free: None + m_free: None, }; diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 647ef7e07d0..108c52806eb 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -1,33 +1,63 @@ -use std::ptr; -use std::os::raw::{c_void, c_int, c_uint, c_long, c_char, c_double}; +use crate::ffi2; +use crate::ffi2::methodobject::PyMethodDef; +use crate::ffi2::pyport::{Py_hash_t, Py_ssize_t}; use libc::FILE; -use ffi2; -use ffi2::pyport::{Py_ssize_t, Py_hash_t}; -use ffi2::methodobject::PyMethodDef; +use std::os::raw::{c_char, c_double, c_int, c_long, c_uint, c_void}; +use std::ptr; #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] +#[cfg(not(PyPy))] +pub struct PyObject { + #[cfg(py_sys_config = "Py_TRACE_REFS")] + _ob_next: *mut PyObject, + #[cfg(py_sys_config = "Py_TRACE_REFS")] + _ob_prev: *mut PyObject, + pub ob_refcnt: Py_ssize_t, + pub ob_type: *mut PyTypeObject, +} + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[cfg(PyPy)] 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_pypy_link: Py_ssize_t, pub ob_type: *mut PyTypeObject, } -#[cfg(py_sys_config="Py_TRACE_REFS")] +#[cfg(py_sys_config = "Py_TRACE_REFS")] +#[cfg(not(PyPy))] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), }; -#[cfg(not(py_sys_config="Py_TRACE_REFS"))] +#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] +#[cfg(not(PyPy))] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, - ob_type: ::std::ptr::null_mut() + ob_type: ::std::ptr::null_mut(), +}; + +#[cfg(py_sys_config = "Py_TRACE_REFS")] +#[cfg(PyPy)] +pub const PyObject_HEAD_INIT: PyObject = PyObject { + _ob_next: ::std::ptr::null_mut(), + _ob_prev: ::std::ptr::null_mut(), + ob_refcnt: 1, + ob_pypy_link: 0, + ob_type: ::std::ptr::null_mut(), +}; + +#[cfg(not(py_sys_config = "Py_TRACE_REFS"))] +#[cfg(PyPy)] +pub const PyObject_HEAD_INIT: PyObject = PyObject { + ob_refcnt: 1, + ob_pypy_link: 0, + ob_type: ::std::ptr::null_mut(), }; #[repr(C)] @@ -37,75 +67,79 @@ pub struct PyVarObject { pub ob_size: Py_ssize_t, } -#[inline(always)] -pub unsafe fn Py_REFCNT(ob : *mut PyObject) -> Py_ssize_t { +#[inline] +pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { (*ob).ob_refcnt } -#[inline(always)] -pub unsafe fn Py_TYPE(ob : *mut PyObject) -> *mut PyTypeObject { +#[inline] +pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject { (*ob).ob_type } -#[inline(always)] -pub unsafe fn Py_SIZE(ob : *mut PyObject) -> Py_ssize_t { +#[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 unaryfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; pub type binaryfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; -pub type ternaryfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; -pub type inquiry = - unsafe extern "C" fn(arg1: *mut PyObject) -> c_int; -pub type lenfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> Py_ssize_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *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; + unsafe extern "C" fn(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int; pub type ssizeargfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub type ssizessizeargfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: Py_ssize_t) -> *mut PyObject; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: Py_ssize_t) -> *mut PyObject; pub type intobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, arg3: *mut PyObject) -> c_int; -pub type intintobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, - arg3: c_int, arg4: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *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; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int; +pub type ssizessizeobjargproc = unsafe extern "C" fn( + arg1: *mut PyObject, + arg2: Py_ssize_t, + arg3: Py_ssize_t, + arg4: *mut PyObject, +) -> c_int; pub type objobjargproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; pub type getreadbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, - arg3: *mut *mut c_void) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int; pub type getwritebufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, - arg3: *mut *mut c_void) -> c_int; -pub type getsegcountproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_int) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_void) -> c_int; +pub type getsegcountproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_int) -> c_int; pub type getcharbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: c_int, arg3: *mut *mut c_char) -> c_int; -pub type readbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_void) -> Py_ssize_t; -pub type writebufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: Py_ssize_t, - arg3: *mut *mut c_void) -> Py_ssize_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: 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; + 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)] @@ -125,47 +159,41 @@ pub struct Py_buffer { } pub type getbufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer, - arg3: c_int) -> c_int; -pub type releasebufferproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut Py_buffer); + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer, arg3: c_int) -> c_int; +pub type releasebufferproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut Py_buffer); // flags: -pub const PyBUF_SIMPLE : c_int = 0; -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_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_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_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_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); +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 const PyBUF_READ: c_int = 0x100; +pub const PyBUF_WRITE: c_int = 0x200; +pub const PyBUF_SHADOW: c_int = 0x400; -pub type objobjproc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type visitproc = - unsafe extern "C" fn (object: *mut PyObject, arg: *mut c_void) -> c_int; +pub type objobjproc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type visitproc = unsafe extern "C" fn(object: *mut PyObject, arg: *mut c_void) -> c_int; pub type traverseproc = - unsafe extern "C" fn (slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; - + unsafe extern "C" fn(slf: *mut PyObject, visit: visitproc, arg: *mut c_void) -> c_int; #[repr(C)] #[derive(Copy)] @@ -212,10 +240,13 @@ pub struct PyNumberMethods { } impl Clone for PyNumberMethods { - #[inline] fn clone(&self) -> PyNumberMethods { *self } + #[inline] + fn clone(&self) -> PyNumberMethods { + *self + } } -pub const PyNumberMethods_INIT : PyNumberMethods = PyNumberMethods { +pub const PyNumberMethods_INIT: PyNumberMethods = PyNumberMethods { nb_add: None, nb_subtract: None, nb_multiply: None, @@ -273,10 +304,13 @@ pub struct PySequenceMethods { } impl Clone for PySequenceMethods { - #[inline] fn clone(&self) -> PySequenceMethods { *self } + #[inline] + fn clone(&self) -> PySequenceMethods { + *self + } } -pub const PySequenceMethods_INIT : PySequenceMethods = PySequenceMethods { +pub const PySequenceMethods_INIT: PySequenceMethods = PySequenceMethods { sq_length: None, sq_concat: None, sq_repeat: None, @@ -298,10 +332,13 @@ pub struct PyMappingMethods { } impl Clone for PyMappingMethods { - #[inline] fn clone(&self) -> PyMappingMethods { *self } + #[inline] + fn clone(&self) -> PyMappingMethods { + *self + } } -pub const PyMappingMethods_INIT : PyMappingMethods = PyMappingMethods { +pub const PyMappingMethods_INIT: PyMappingMethods = PyMappingMethods { mp_length: None, mp_subscript: None, mp_ass_subscript: None, @@ -319,10 +356,13 @@ pub struct PyBufferProcs { } impl Clone for PyBufferProcs { - #[inline] fn clone(&self) -> PyBufferProcs { *self } + #[inline] + fn clone(&self) -> PyBufferProcs { + *self + } } -pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs { +pub const PyBufferProcs_INIT: PyBufferProcs = PyBufferProcs { bf_getreadbuffer: None, bf_getwritebuffer: None, bf_getsegcount: None, @@ -331,52 +371,44 @@ pub const PyBufferProcs_INIT : PyBufferProcs = PyBufferProcs { bf_releasebuffer: None, }; -pub type freefunc = - unsafe extern "C" fn(arg1: *mut c_void); -pub type destructor = - unsafe extern "C" fn(arg1: *mut PyObject); +pub type freefunc = unsafe extern "C" fn(arg1: *mut c_void); +pub type destructor = unsafe extern "C" fn(arg1: *mut PyObject); pub type printfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut FILE, arg3: c_int) -> c_int; + 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; + 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; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; pub type setattrfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut c_char, - arg3: *mut PyObject) -> c_int; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut c_char, arg3: *mut PyObject) -> c_int; pub type setattrofunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> c_int; -pub type cmpfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; -pub type reprfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type hashfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; +pub type cmpfunc = unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; +pub type reprfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; +pub type hashfunc = unsafe extern "C" fn(arg1: *mut PyObject) -> Py_hash_t; pub type richcmpfunc = - unsafe extern "C" fn (arg1: *mut PyObject, - arg2: *mut PyObject, arg3: c_int) -> *mut PyObject; -pub type getiterfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type iternextfunc = - unsafe extern "C" fn(arg1: *mut PyObject) -> *mut PyObject; -pub type descrgetfunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyObject, - arg3: *mut PyObject) -> *mut PyObject; + unsafe extern "C" fn(arg1: *mut PyObject, arg2: *mut PyObject, arg3: 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; + 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; + 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; + unsafe extern "C" fn(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyObject; #[repr(C)] -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct PyTypeObject { pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -429,12 +461,8 @@ pub struct PyTypeObject { pub tp_version_tag: c_uint, } -impl Clone for PyTypeObject { - #[inline] fn clone(&self) -> PyTypeObject { *self } -} - -#[cfg(py_sys_config="Py_TRACE_REFS")] -pub const PyTypeObject_INIT : PyTypeObject = PyTypeObject { +#[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, @@ -488,8 +516,8 @@ pub const PyTypeObject_INIT : PyTypeObject = PyTypeObject { tp_version_tag: 0, }; -#[cfg(not(py_sys_config="Py_TRACE_REFS"))] -pub const PyTypeObject_INIT : PyTypeObject = PyTypeObject { +#[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, @@ -554,219 +582,273 @@ pub struct PyHeapTypeObject { } impl Clone for PyHeapTypeObject { - #[inline] fn clone(&self) -> PyHeapTypeObject { *self } + #[inline] + fn clone(&self) -> PyHeapTypeObject { + *self + } } // access macro to the members which are floating "behind" the object #[inline] -pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ffi2::structmember::PyMemberDef { +pub unsafe fn PyHeapType_GET_MEMBERS( + etype: *mut PyHeapTypeObject, +) -> *mut ffi2::structmember::PyMemberDef { let basicsize = (*Py_TYPE(etype as *mut PyObject)).tp_basicsize; (etype as *mut u8).offset(basicsize as isize) as *mut ffi2::structmember::PyMemberDef } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } -#[inline(always)] +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; } -#[inline(always)] +#[inline] pub unsafe fn PyType_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) } -#[inline(always)] +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyType_Ready")] 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; + #[cfg_attr(PyPy, link_name = "PyPyType_GenericNew")] + pub fn PyType_GenericNew( + t: *mut PyTypeObject, + args: *mut PyObject, + kwds: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyType_Lookup")] 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; + fn _PyObject_LookupSpecial( + arg1: *mut PyObject, + arg2: *mut c_char, + arg3: *mut *mut PyObject, + ) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; + #[cfg_attr(PyPy, link_name = "PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); - pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, - flags: c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Print")] + pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int; fn _PyObject_Dump(o: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_Str")] fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyObject_Bytes")] 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")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg(py_sys_config = "Py_USING_UNICODE")] + #[cfg_attr(PyPy, link_name = "PyPyObject_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; + #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompare")] + pub fn PyObject_RichCompare( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompareBool")] + pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) + -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttrString")] + pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttrString")] + pub fn PyObject_SetAttrString( + arg1: *mut PyObject, + arg2: *const c_char, + arg3: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")] + pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttr")] 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] + pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) + -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttr")] pub fn PyObject_HasAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "_PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_GenericGetAttr")] 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_GenericSetAttr")] + pub fn PyObject_GenericSetAttr( + arg1: *mut PyObject, + arg2: *mut PyObject, + arg3: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; + #[cfg_attr(PyPy, link_name = "PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCallable_Check")] pub fn PyCallable_Check(arg1: *mut PyObject) -> c_int; pub fn PyNumber_Coerce(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int; - pub fn PyNumber_CoerceEx(arg1: *mut *mut PyObject, - arg2: *mut *mut PyObject) -> c_int; + pub fn PyNumber_CoerceEx(arg1: *mut *mut PyObject, arg2: *mut *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_ClearWeakRefs")] 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; + 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_Dir")] 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); + #[cfg_attr(PyPy, link_name = "_PyPy_HashDouble")] fn _Py_HashDouble(arg1: c_double) -> c_long; + #[cfg_attr(PyPy, link_name = "_PyPy_HashPointer")] 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. +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); +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); +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); +pub const Py_TPFLAGS_HAVE_INPLACEOPS: c_long = (1 << 3); // PyNumberMethods do their own coercion -pub const Py_TPFLAGS_CHECKTYPES : c_long = (1<<4); +pub const Py_TPFLAGS_CHECKTYPES: c_long = (1 << 4); // tp_richcompare is defined -pub const Py_TPFLAGS_HAVE_RICHCOMPARE : c_long = (1<<5); +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); +pub const Py_TPFLAGS_HAVE_WEAKREFS: c_long = (1 << 6); // tp_iter is defined -pub const Py_TPFLAGS_HAVE_ITER : c_long = (1<<7); +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); +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); +pub const Py_TPFLAGS_HEAPTYPE: c_long = (1 << 9); // Set if the type allows subclassing -pub const Py_TPFLAGS_BASETYPE : c_long = (1<<10); +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); +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); +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); +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; +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); +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); +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); +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); +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 | - 0); - -#[inline(always)] -pub unsafe fn PyType_HasFeature(t : *mut PyTypeObject, f : c_long) -> c_int { +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(always)] -pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_long) -> c_int { +#[inline] +pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_long) -> c_int { PyType_HasFeature(t, f) } // Reference counting macros. -#[inline(always)] -pub unsafe fn Py_INCREF(op : *mut PyObject) { - if cfg!(py_sys_config="Py_REF_DEBUG") { +#[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(always)] +#[inline] pub unsafe fn Py_DECREF(op: *mut PyObject) { - if cfg!(py_sys_config="Py_REF_DEBUG") || cfg!(py_sys_config="COUNT_ALLOCS") { + if cfg!(py_sys_config = "Py_REF_DEBUG") || cfg!(py_sys_config = "COUNT_ALLOCS") { Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -776,7 +858,7 @@ pub unsafe fn Py_DECREF(op: *mut PyObject) { } } -#[inline(always)] +#[inline] pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) { let tmp = *op; if !tmp.is_null() { @@ -785,45 +867,48 @@ pub unsafe fn Py_CLEAR(op: &mut *mut PyObject) { } } -#[inline(always)] -pub unsafe fn Py_XINCREF(op : *mut PyObject) { +#[inline] +pub unsafe fn Py_XINCREF(op: *mut PyObject) { if !op.is_null() { Py_INCREF(op) } } -#[inline(always)] -pub unsafe fn Py_XDECREF(op : *mut PyObject) { +#[inline] +pub unsafe fn Py_XDECREF(op: *mut PyObject) { if !op.is_null() { Py_DECREF(op) } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); + #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; + #[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } -#[inline(always)] +#[inline] pub unsafe fn Py_None() -> *mut PyObject { &mut _Py_NoneStruct } -#[inline(always)] +#[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; +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 { @@ -835,15 +920,16 @@ pub fn PySuper_Check(_arg1: *mut PyObject) -> c_int { 0 } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { fn _PyTrash_thread_deposit_object(o: *mut PyObject); fn _PyTrash_thread_destroy_chain(); } -pub const PyTrash_UNWIND_LEVEL : c_int = 50; +pub const PyTrash_UNWIND_LEVEL: c_int = 50; -#[inline(always)] -pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { +#[inline] +pub unsafe fn Py_TRASHCAN ()>(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() { @@ -860,4 +946,3 @@ pub unsafe fn Py_TRASHCAN ()>(op: *mut PyObject, body: F) { _PyTrash_thread_deposit_object(op) } } - diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index 96ef08ea6d6..bbdb68110f3 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -1,255 +1,335 @@ +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; -use std::os::raw::{c_void, c_char, c_int}; -use ffi2; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[inline] +#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } #[inline] +#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttr")] 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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject, result: *mut c_int) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_Call")] + pub fn PyObject_Call( + callable_object: *mut PyObject, + args: *mut PyObject, + kw: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallObject")] + pub fn PyObject_CallObject( + callable_object: *mut PyObject, + args: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] + pub fn PyObject_CallFunction( + callable_object: *mut PyObject, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethod")] + pub fn PyObject_CallMethod( + o: *mut PyObject, + m: *mut c_char, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyObject_CallFunction_SizeT")] + fn _PyObject_CallFunction_SizeT( + callable: *mut PyObject, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyObject_CallMethod_SizeT")] + fn _PyObject_CallMethod_SizeT( + o: *mut PyObject, + name: *mut c_char, + format: *mut c_char, + ... + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")] + pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")] + pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_Size")] 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_LengthHint")] + pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetItem")] + pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_SetItem")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsCharBuffer")] + pub fn PyObject_AsCharBuffer( + obj: *mut PyObject, + buffer: *mut *const c_char, + buffer_len: *mut Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_CheckReadBuffer")] 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsReadBuffer")] + pub fn PyObject_AsReadBuffer( + obj: *mut PyObject, + buffer: *mut *const c_void, + buffer_len: *mut Py_ssize_t, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_AsWriteBuffer")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetBuffer")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_GetPointer")] + pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_ToContiguous")] + pub fn PyBuffer_ToContiguous( + buf: *mut c_void, + view: *mut Py_buffer, + len: Py_ssize_t, + fort: c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromContiguous")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_IsContiguous")] + 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, + ); + #[cfg_attr(PyPy, link_name = "PyPyBuffer_FillInfo")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); - pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) - -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_Format")] + pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] 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; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Add")] + pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Subtract")] + pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Multiply")] + pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Divide")] + pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_FloorDivide")] + pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_TrueDivide")] + pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Remainder")] + pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Divmod")] + pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Power")] + pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) + -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Invert")] 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; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Lshift")] + pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Rshift")] + pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_And")] + pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Xor")] + pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Index")] 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; + #[cfg_attr(PyPy, link_name = "PyPyNumber_AsSsize_t")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_Float")] 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; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAdd")] + pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceSubtract")] + pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceMultiply")] + pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceDivide")] + pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceFloorDivide")] + pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceTrueDivide")] + pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRemainder")] + pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlacePower")] + pub fn PyNumber_InPlacePower( + o1: *mut PyObject, + o2: *mut PyObject, + o3: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceLshift")] + pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRshift")] + pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAnd")] + pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceXor")] + pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceOr")] + pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPySequence_Length")] 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; + #[cfg_attr(PyPy, link_name = "PyPySequence_Concat")] + pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_Repeat")] + pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_GetItem")] + pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_GetSlice")] + pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_SetItem")] + pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_DelItem")] + pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_SetSlice")] + pub fn PySequence_SetSlice( + o: *mut PyObject, + i1: Py_ssize_t, + i2: Py_ssize_t, + v: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_DelSlice")] + pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_List")] 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; + #[cfg_attr(PyPy, link_name = "PyPySequence_Fast")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySequence_Contains")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySequence_Index")] + pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceConcat")] + pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceRepeat")] + pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyMapping_Length")] 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; + #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKeyString")] + pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKey")] + pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyMapping_GetItemString")] + pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyMapping_SetItemString")] + pub fn PyMapping_SetItemString( + o: *mut PyObject, + key: *mut c_char, + value: *mut PyObject, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsInstance")] + pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyObject_IsSubclass")] + pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } - #[inline] pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let b = (*t).tp_as_buffer; - (!b.is_null() && - (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) && - ((*b).bf_getbuffer.is_some())) as c_int + (!b.is_null() + && (PyType_HasFeature(t, Py_TPFLAGS_HAVE_NEWBUFFER) != 0) + && ((*b).bf_getbuffer.is_some())) as c_int } - #[inline] +#[cfg_attr(PyPy, link_name = "PyPyIter_Check")] 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 + (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] +#[cfg_attr(PyPy, link_name = "PyPyIndex_Check")] pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let n = (*t).tp_as_number; - (!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) as c_int + (!n.is_null() && PyType_HasFeature(t, Py_TPFLAGS_HAVE_INDEX) != 0 && (*n).nb_index.is_some()) + as c_int } #[inline] -pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { +#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_SIZE")] +pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { if ffi2::listobject::PyList_Check(o) != 0 { + #[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] ffi2::listobject::PyList_GET_SIZE(o) } else { ffi2::tupleobject::PyTuple_GET_SIZE(o) @@ -257,8 +337,10 @@ pub unsafe fn PySequence_Fast_GET_SIZE(o : *mut PyObject) -> Py_ssize_t { } #[inline] -pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_ITEM")] +pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { + #[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] ffi2::listobject::PyList_GET_ITEM(o, i) } else { ffi2::tupleobject::PyTuple_GET_ITEM(o, i) @@ -266,44 +348,52 @@ pub unsafe fn PySequence_Fast_GET_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mu } #[inline] -pub unsafe fn PySequence_Fast_ITEMS(o : *mut PyObject) -> *mut *mut PyObject { +#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_ITEMS")] +pub unsafe fn PySequence_Fast_ITEMS(o: *mut PyObject) -> *mut *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { (*(o as *mut ffi2::listobject::PyListObject)).ob_item } else { - (*(o as *mut ffi2::tupleobject::PyTupleObject)).ob_item.as_mut_ptr() + (*(o as *mut ffi2::tupleobject::PyTupleObject)) + .ob_item + .as_mut_ptr() } } #[inline] -pub unsafe fn PySequence_ITEM(o : *mut PyObject, i : Py_ssize_t) -> *mut PyObject { - (*(*Py_TYPE(o)).tp_as_sequence).sq_item.expect("Failed to get sq_item")(o, i) +#[cfg_attr(PyPy, link_name = "PyPySequence_ITEM")] +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; +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 { +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 { +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 i8, ptr::null_mut()) +#[cfg_attr(PyPy, link_name = "PyPyMapping_Keys")] +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 i8, ptr::null_mut()) +#[cfg_attr(PyPy, link_name = "PyPyMapping_Values")] +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 i8, ptr::null_mut()) +#[cfg_attr(PyPy, link_name = "PyPyMapping_Items")] +pub unsafe fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject { + PyObject_CallMethod(o, "items\0".as_ptr() as *mut c_char, ptr::null_mut()) } diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index aac600257e1..e4745a9509b 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -1,63 +1,63 @@ -use std::os::raw::{c_void, c_char, c_int}; +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use libc::size_t; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyObject_Malloc")] pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; - pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) - -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyObject_Realloc")] + pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; pub fn PyObject_Free(arg1: *mut c_void); - pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) - -> *mut PyObject; - pub fn PyObject_InitVar(arg1: *mut PyVarObject, arg2: *mut PyTypeObject, - arg3: Py_ssize_t) -> *mut PyVarObject; + pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject; + pub fn PyObject_InitVar( + arg1: *mut PyVarObject, + arg2: *mut PyTypeObject, + arg3: Py_ssize_t, + ) -> *mut PyVarObject; pub fn _PyObject_New(arg1: *mut PyTypeObject) -> *mut PyObject; - pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) - -> *mut PyVarObject; + pub fn _PyObject_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; // GC Support pub fn PyGC_Collect() -> Py_ssize_t; - pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) - -> *mut PyVarObject; + pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn _PyObject_GC_Malloc(arg1: size_t) -> *mut PyObject; pub fn _PyObject_GC_New(arg1: *mut PyTypeObject) -> *mut PyObject; - pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) - -> *mut PyVarObject; + pub fn _PyObject_GC_NewVar(arg1: *mut PyTypeObject, arg2: Py_ssize_t) -> *mut PyVarObject; pub fn PyObject_GC_Track(arg1: *mut c_void); pub fn PyObject_GC_UnTrack(arg1: *mut c_void); pub fn PyObject_GC_Del(arg1: *mut c_void); } /// Test if a type has a GC head -#[inline(always)] +#[inline] #[allow(unused_parens)] -pub unsafe fn PyType_IS_GC(t : *mut PyTypeObject) -> c_int { +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(always)] -pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int { - (PyType_IS_GC(Py_TYPE(o)) != 0 && - match (*Py_TYPE(o)).tp_is_gc { - Some(tp_is_gc) => tp_is_gc(o) != 0, - None => true - }) as c_int +#[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(always)] +#[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 +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(always)] -pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o : *mut PyObject) -> *mut *mut PyObject { +#[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 } - diff --git a/src/ffi2/pyarena.rs b/src/ffi2/pyarena.rs index d7429d0de35..0b0713bebae 100644 --- a/src/ffi2/pyarena.rs +++ b/src/ffi2/pyarena.rs @@ -1,11 +1,12 @@ +use crate::ffi2::object::PyObject; use libc::size_t; -use std::os::raw::{c_void, c_int}; -use ffi2::object::PyObject; +use std::os::raw::{c_int, c_void}; #[allow(missing_copy_implementations)] -pub enum PyArena { } +pub enum PyArena {} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyArena_New() -> *mut PyArena; pub fn PyArena_Free(arg1: *mut PyArena); pub fn PyArena_Malloc(arg1: *mut PyArena, size: size_t) -> *mut c_void; diff --git a/src/ffi2/pycapsule.rs b/src/ffi2/pycapsule.rs index 84316530ffa..94eea810322 100644 --- a/src/ffi2/pycapsule.rs +++ b/src/ffi2/pycapsule.rs @@ -1,7 +1,9 @@ -use std::os::raw::{c_void, c_char, c_int}; -use ffi2::object::*; +use crate::ffi2::object::*; +use std::os::raw::{c_char, c_int, c_void}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -12,25 +14,35 @@ 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) -> *mut PyObject; - pub fn PyCapsule_GetPointer(capsule: *mut PyObject, - name: *const c_char) -> *mut c_void; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyCapsule_New")] + pub fn PyCapsule_New( + pointer: *mut c_void, + name: *const c_char, + destructor: Option, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetPointer")] + pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetContext")] 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) -> 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; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_IsValid")] + pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetPointer")] + pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetDestructor")] + pub fn PyCapsule_SetDestructor( + capsule: *mut PyObject, + destructor: Option, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetName")] + pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetContext")] + pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyCapsule_Import")] + pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; } diff --git a/src/ffi2/pydebug.rs b/src/ffi2/pydebug.rs index c54f77d21d6..52d6d86bff0 100644 --- a/src/ffi2/pydebug.rs +++ b/src/ffi2/pydebug.rs @@ -1,25 +1,44 @@ use std::os::raw::{c_char, c_int}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_TabcheckFlag")] pub static mut Py_TabcheckFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_UnicodeFlag")] pub static mut Py_UnicodeFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_DivisionWarningFlag")] pub static mut Py_DivisionWarningFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; + #[cfg_attr(PyPy, link_name = "_PyPy_QnewFlag")] pub static mut _Py_QnewFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_Py3kWarningFlag")] pub static mut Py_Py3kWarningFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; + #[cfg_attr(PyPy, link_name = "PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char); } - diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index a613ab68dd0..38278f51dbe 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -1,39 +1,55 @@ +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}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; -use ffi2::classobject::*; -use ffi2::stringobject::PyString_AS_STRING; -#[cfg(py_sys_config="Py_USING_UNICODE")] -use ffi2::unicodeobject::Py_UNICODE; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyErr_SetString")] pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); + #[cfg_attr(PyPy, link_name = "PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_Clear")] 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; + #[cfg_attr(PyPy, link_name = "PyPyErr_Fetch")] + pub fn PyErr_Fetch( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ); + #[cfg_attr(PyPy, link_name = "PyPyErr_Restore")] + pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyErr_GivenExceptionMatches")] + pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_ExceptionMatches")] 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); + #[cfg_attr(PyPy, link_name = "PyPyErr_NormalizeException")] + pub fn PyErr_NormalizeException( + arg1: *mut *mut PyObject, + arg2: *mut *mut PyObject, + arg3: *mut *mut PyObject, + ); } #[inline] pub unsafe fn PyExceptionClass_Check(x: *mut PyObject) -> c_int { - (PyClass_Check(x) != 0 || (PyType_Check(x) != 0 && - PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) as c_int + (PyClass_Check(x) != 0 + || (PyType_Check(x) != 0 + && PyType_FastSubclass(x as *mut PyTypeObject, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0)) + as c_int } #[inline] pub unsafe fn PyExceptionInstance_Check(x: *mut PyObject) -> c_int { - (PyInstance_Check(x) != 0 || - PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int + (PyInstance_Check(x) != 0 + || PyType_FastSubclass((*x).ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) != 0) as c_int } #[inline] @@ -46,6 +62,7 @@ pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char { } #[inline] +#[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { if PyInstance_Check(x) != 0 { (*(x as *mut PyInstanceObject)).in_class as *mut PyObject @@ -54,163 +71,199 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { } } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; pub static mut PyExc_StandardError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; - #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; + #[cfg(windows)] + pub static mut PyExc_WindowsError: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; pub static mut PyExc_MemoryErrorInst: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_RecursionError")] pub static mut PyExc_RecursionErrorInst: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - + + #[cfg_attr(PyPy, link_name = "PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrno")] 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; + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilenameObject")] + pub fn PyErr_SetFromErrnoWithFilenameObject( + arg1: *mut PyObject, + arg2: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilename")] + pub fn PyErr_SetFromErrnoWithFilename( + arg1: *mut PyObject, + arg2: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_Format")] + pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_BadInternalCall")] 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_BadInternalCall(filename: *mut c_char, lineno: c_int); + #[cfg_attr(PyPy, link_name = "PyPyErr_NewException")] + pub fn PyErr_NewException( + name: *mut c_char, + base: *mut PyObject, + dict: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_NewExceptionWithDoc")] + pub fn PyErr_NewExceptionWithDoc( + name: *mut c_char, + doc: *mut c_char, + base: *mut PyObject, + dict: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; - pub fn PyErr_SyntaxLocation(arg1: *const c_char, - arg2: c_int); - pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) - -> *mut PyObject; + pub fn PyErr_SyntaxLocation(arg1: *const c_char, arg2: c_int); + pub fn PyErr_ProgramText(arg1: *const c_char, arg2: c_int) -> *mut PyObject; } -#[cfg(py_sys_config="Py_USING_UNICODE")] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyUnicodeDecodeError_Create(arg1: *const c_char, - 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; +#[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; } - diff --git a/src/ffi2/pymem.rs b/src/ffi2/pymem.rs index 66db582acb3..dabd9a874b9 100644 --- a/src/ffi2/pymem.rs +++ b/src/ffi2/pymem.rs @@ -1,6 +1,8 @@ use libc::{c_void, size_t}; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyMem_Malloc")] 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); diff --git a/src/ffi2/pyport.rs b/src/ffi2/pyport.rs index cbfa8e6bc13..5ee20a83ed8 100644 --- a/src/ffi2/pyport.rs +++ b/src/ffi2/pyport.rs @@ -1,9 +1,8 @@ - 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; +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; diff --git a/src/ffi2/pystate.rs b/src/ffi2/pystate.rs index 7577ef8184c..3e538cc403e 100644 --- a/src/ffi2/pystate.rs +++ b/src/ffi2/pystate.rs @@ -1,22 +1,24 @@ +use crate::ffi2::frameobject::PyFrameObject; +use crate::ffi2::object::PyObject; use std::os::raw::{c_int, c_long}; -use ffi2::object::PyObject; -use ffi2::frameobject::PyFrameObject; -pub enum PyInterpreterState { } +pub enum PyInterpreterState {} -pub type Py_tracefunc = - unsafe extern "C" fn (arg1: *mut PyObject, arg2: *mut PyFrameObject, - arg3: c_int, arg4: *mut PyObject) - -> c_int; +pub type Py_tracefunc = unsafe extern "C" fn( + arg1: *mut PyObject, + arg2: *mut PyFrameObject, + arg3: c_int, + arg4: *mut PyObject, +) -> c_int; /* The following values are used for 'what' for tracefunc functions: */ -pub const PyTrace_CALL : c_int = 0; -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; +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)] @@ -47,60 +49,66 @@ pub struct PyThreadState { } impl Clone for PyThreadState { - #[inline] fn clone(&self) -> PyThreadState { *self } + #[inline] + fn clone(&self) -> PyThreadState { + *self + } } #[repr(C)] #[derive(Copy, Clone)] pub enum PyGILState_STATE { PyGILState_LOCKED, - PyGILState_UNLOCKED + PyGILState_UNLOCKED, } - -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Get")] //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; + #[cfg_attr(PyPy, link_name = "PyPyThreadState_New")] + 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); + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState); + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState); - #[cfg(py_sys_config="WITH_THREAD")] + #[cfg(py_sys_config = "WITH_THREAD")] + #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent(); pub fn PyThreadState_Get() -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; - pub fn PyThreadState_SetAsyncExc(arg1: c_long, - arg2: *mut PyObject) -> c_int; + pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; + #[cfg_attr(PyPy, link_name = "PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; fn _PyThread_CurrentFrames() -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; - pub fn PyInterpreterState_Next(arg1: *mut PyInterpreterState) - -> *mut PyInterpreterState; - pub fn PyInterpreterState_ThreadHead(arg1: *mut PyInterpreterState) - -> *mut PyThreadState; + #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")] + 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(always)] +#[cfg(py_sys_config = "Py_DEBUG")] +#[inline] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { PyThreadState_Get() } -#[cfg(not(py_sys_config="Py_DEBUG"))] -#[inline(always)] +#[cfg(not(py_sys_config = "Py_DEBUG"))] +#[inline] pub unsafe fn PyThreadState_GET() -> *mut PyThreadState { _PyThreadState_Current } - - diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index e28b68ec1e6..4a4a0545b18 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -1,112 +1,147 @@ +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}; -use ffi2::object::*; -use ffi2::code::*; -use ffi2::pystate::PyThreadState; -use ffi2::pyarena::PyArena; -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; +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 + cf_flags: c_int, } #[allow(missing_copy_implementations)] -pub enum Struct__mod { } +pub enum Struct__mod {} #[allow(missing_copy_implementations)] -pub enum Struct__node { } +pub enum Struct__node {} #[allow(missing_copy_implementations)] -pub enum Struct_symtable { } +pub enum Struct_symtable {} -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); + #[cfg_attr(PyPy, link_name = "PyPy_GetProgramName")] 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(); + #[cfg_attr(PyPy, link_name = "PyPy_IsInitialized")] 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 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; + #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] + 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; + #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyErr_Print")] pub fn PyErr_Print(); + #[cfg_attr(PyPy, link_name = "PyPyErr_PrintEx")] 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) - -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyErr_Display")] + pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPy_AtExit")] + pub fn Py_AtExit(func: Option) -> c_int; pub fn Py_Exit(arg1: c_int); - pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) - -> c_int; - pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) - -> c_int; + pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) -> c_int; + pub fn Py_Main(argc: c_int, argv: *mut *mut c_char) -> c_int; pub fn Py_GetProgramFullPath() -> *mut c_char; pub fn Py_GetPrefix() -> *mut c_char; pub fn Py_GetExecPrefix() -> *mut c_char; pub fn Py_GetPath() -> *mut c_char; + #[cfg_attr(PyPy, link_name = "PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; @@ -118,4 +153,3 @@ pub enum Struct_symtable { } fn _Py_hgidentifier() -> *const c_char; fn _Py_hgversion() -> *const c_char; } - diff --git a/src/ffi2/rangeobject.rs b/src/ffi2/rangeobject.rs index 6299665678b..e6992496130 100644 --- a/src/ffi2/rangeobject.rs +++ b/src/ffi2/rangeobject.rs @@ -1,13 +1,14 @@ +use crate::ffi2::object::*; use std::os::raw::c_int; -use ffi2::object::*; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyRange_Check(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyRange_Type; +#[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 } - diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index fbd2ece25f5..4511252090d 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -1,63 +1,77 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; //enum PySetObject { /* representation hidden */ } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; + #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; } #[inline] -pub unsafe fn PyFrozenSet_CheckExact(ob : *mut PyObject) -> c_int { - let f : *mut PyTypeObject = &mut PyFrozenSet_Type; +#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_CheckExact")] +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; +#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")] +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 +#[cfg_attr(PyPy, link_name = "PyPyAnySet_Check")] +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; +#[cfg_attr(PyPy, link_name = "PyPySet_Check")] +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; +#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Check")] +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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySet_New")] pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_New")] pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPySet_Clear")] 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; + #[cfg_attr(PyPy, link_name = "PyPySet_Contains")] + pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySet_Discard")] + pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPySet_Add")] 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; + #[cfg_attr(PyPy, link_name = "PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; - //pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) - // -> c_int; +//pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) +// -> c_int; } - diff --git a/src/ffi2/sliceobject.rs b/src/ffi2/sliceobject.rs index c458fa51482..9a2b1c87699 100644 --- a/src/ffi2/sliceobject.rs +++ b/src/ffi2/sliceobject.rs @@ -1,12 +1,14 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } -#[inline(always)] +#[inline] pub unsafe fn Py_Ellipsis() -> *mut PyObject { &mut _Py_EllipsisObject } @@ -14,37 +16,53 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { #[repr(C)] #[derive(Copy, Clone)] pub struct PySliceObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub step: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPySlice_Check")] pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int { - (Py_TYPE(op) == &mut PySlice_Type) as 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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPySlice_New")] + pub fn PySlice_New( + start: *mut PyObject, + stop: *mut PyObject, + step: *mut PyObject, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndices")] + 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; + #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndicesEx")] + 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; } - diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index a54a816f88a..af38518a77c 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -1,13 +1,13 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int, c_long}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[allow(missing_copy_implementations)] pub struct PyStringObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -17,116 +17,136 @@ pub struct PyStringObject { pub ob_sval: [c_char; 1], } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub static mut PyBaseString_Type: PyTypeObject; pub static mut PyString_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyString_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyString_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyBaseString_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyBaseString_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass( - Py_TYPE(op), Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS) + Py_TYPE(op), + Py_TPFLAGS_STRING_SUBCLASS | Py_TPFLAGS_UNICODE_SUBCLASS, + ) } -#[inline(always)] -pub unsafe fn PyString_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyString_Type; +#[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(always)] -pub unsafe fn PyString_GET_SIZE(op : *mut PyObject) -> Py_ssize_t { +#[inline] +pub unsafe fn PyString_GET_SIZE(op: *mut PyObject) -> Py_ssize_t { (*(op as *mut PyStringObject)).ob_size } -#[inline(always)] -pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { +#[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" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyString_FromString")] pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; - pub fn PyString_FromStringAndSize(v: *const c_char, - len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyString_FromStringAndSize")] + pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyString_FromFormat")] pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyString_Size")] pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyString_AsString")] 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_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_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_Decode( + s: *const c_char, + size: Py_ssize_t, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyString_AsDecodedObject")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyString_AsEncodedObject")] + pub fn PyString_AsEncodedObject( + 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;*/ -} +/* +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;*/ +} diff --git a/src/ffi2/structmember.rs b/src/ffi2/structmember.rs index 20097a015d4..9262ab74d19 100644 --- a/src/ffi2/structmember.rs +++ b/src/ffi2/structmember.rs @@ -1,6 +1,6 @@ +use crate::ffi2::object::PyObject; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::PyObject; #[repr(C)] #[derive(Copy, Clone)] @@ -9,52 +9,50 @@ pub struct PyMemberDef { pub type_code: c_int, pub offset: Py_ssize_t, pub flags: c_int, - pub doc: *mut c_char + pub doc: *mut c_char, } /* Types */ -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; +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 */ +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; +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; +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_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_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 */ +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 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; } - diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index 71a963315ab..31379dc166c 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -1,33 +1,36 @@ +use crate::ffi2::frameobject::PyFrameObject; +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::object::*; -use ffi2::pyport::Py_ssize_t; -use ffi2::frameobject::PyFrameObject; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTracebackObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[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 + pub tb_lineno: c_int, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; - pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) - -> c_int; - + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Print")] + pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; + + #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyTraceBack_Check(op : *mut PyObject) -> c_int { +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Check")] +pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } - diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index 277582077cf..7264d241f8e 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -1,13 +1,13 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::c_int; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyTupleObject { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -15,48 +15,60 @@ pub struct PyTupleObject { pub ob_item: [*mut PyObject; 1], } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyTuple_Check(op : *mut PyObject) -> c_int { +#[inline] +pub unsafe fn PyTuple_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyTuple_Type; +#[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(always)] +/// 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) + *(*(op as *mut PyTupleObject)) + .ob_item + .as_ptr() + .offset(i as isize) } -#[inline(always)] +#[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(always)] +#[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; + *(*(op as *mut PyTupleObject)) + .ob_item + .as_mut_ptr() + .offset(i as isize) = v; } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyTuple_Size")] pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyTuple_GetItem")] 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; + #[cfg_attr(PyPy, link_name = "PyPyTuple_SetItem")] + pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyTuple_GetSlice")] + pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "_PyPyTuple_Resize")] pub fn _PyTuple_Resize(p: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; //pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject); pub fn PyTuple_ClearFreeList() -> c_int; diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index 32503fcb0cc..f8d15263610 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -1,26 +1,26 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use libc::wchar_t; -use std::os::raw::{c_char, c_int, c_long, c_double}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; +use 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; +#[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")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] pub type Py_UNICODE = u32; -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] +#[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")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -30,213 +30,358 @@ pub struct PyUnicodeObject { pub defenc: *mut PyObject, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; } -#[inline(always)] -pub unsafe fn PyUnicode_Check(op : *mut PyObject) -> c_int { +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] +pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } -#[inline(always)] -pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { - let u : *mut PyTypeObject = &mut PyUnicode_Type; +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] +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(always)] +#[inline] pub unsafe fn PyUnicode_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { (*(o as *mut PyUnicodeObject)).length } -#[inline(always)] +#[inline] pub unsafe fn PyUnicode_GET_DATA_SIZE(o: *mut PyObject) -> Py_ssize_t { (*(o as *mut PyUnicodeObject)).length * Py_UNICODE_SIZE } -#[inline(always)] +#[inline] pub unsafe fn PyUnicode_AS_UNICODE(o: *mut PyObject) -> *mut Py_UNICODE { (*(o as *mut PyUnicodeObject)).data } -#[inline(always)] +#[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; - +pub const Py_UNICODE_REPLACEMENT_CHARACTER: Py_UNICODE = 0xFFFD; #[allow(dead_code)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] + fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] + fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] + fn PyUnicodeUCS4_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] 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 _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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] + fn PyUnicodeUCS4_AsWideChar( + unicode: *mut PyUnicodeObject, + w: *mut wchar_t, + size: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] 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; + #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] + fn _PyUnicodeUCS4_AsDefaultEncodedString( + arg1: *mut PyObject, + arg2: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] + fn PyUnicodeUCS4_AsEncodedObject( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] + fn PyUnicodeUCS4_EncodeUTF8( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] 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_EncodeUTF32( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + byteorder: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] 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_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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] 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_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_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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] + fn PyUnicodeUCS4_DecodeLatin1( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] + fn PyUnicodeUCS4_EncodeLatin1( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] + fn PyUnicodeUCS4_DecodeASCII( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] + fn PyUnicodeUCS4_EncodeDecimal( + s: *mut Py_UNICODE, + length: Py_ssize_t, + output: *mut c_char, + errors: *const c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] + fn PyUnicodeUCS4_Split( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] fn PyUnicodeUCS4_Splitlines(s: *mut PyObject, keepends: c_int) -> *mut PyObject; fn PyUnicodeUCS4_Partition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_RPartition(s: *mut PyObject, sep: *mut PyObject) -> *mut PyObject; - fn PyUnicodeUCS4_RSplit(s: *mut PyObject, sep: *mut PyObject, - maxsplit: Py_ssize_t) -> *mut PyObject; - fn PyUnicodeUCS4_Translate(str: *mut PyObject, table: *mut PyObject, errors: *const c_char) - -> *mut PyObject; - fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) - -> *mut PyObject; - fn PyUnicodeUCS4_Tailmatch(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - fn PyUnicodeUCS4_Find(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t, - direction: c_int) -> Py_ssize_t; - fn PyUnicodeUCS4_Count(str: *mut PyObject, substr: *mut PyObject, - start: Py_ssize_t, end: Py_ssize_t) -> Py_ssize_t; - fn PyUnicodeUCS4_Replace(str: *mut PyObject, substr: *mut PyObject, - replstr: *mut PyObject, maxcount: Py_ssize_t) -> *mut PyObject; + fn PyUnicodeUCS4_RSplit( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + fn PyUnicodeUCS4_Translate( + str: *mut PyObject, + table: *mut PyObject, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] + fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] + fn PyUnicodeUCS4_Tailmatch( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] + fn PyUnicodeUCS4_Find( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] + fn PyUnicodeUCS4_Count( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] + fn PyUnicodeUCS4_Replace( + str: *mut PyObject, + substr: *mut PyObject, + replstr: *mut PyObject, + maxcount: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] fn PyUnicodeUCS4_Compare(left: *mut PyObject, right: *mut PyObject) -> c_int; - fn PyUnicodeUCS4_RichCompare(left: *mut PyObject, - right: *mut PyObject, op: c_int) -> *mut PyObject; + fn PyUnicodeUCS4_RichCompare( + left: *mut PyObject, + right: *mut PyObject, + op: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] fn PyUnicodeUCS4_Format(format: *mut PyObject, args: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_Contains(container: *mut PyObject, element: *mut PyObject) -> c_int; - fn _PyUnicode_XStrip(_self: *mut PyUnicodeObject, - striptype: c_int, sepobj: *mut PyObject) -> *mut PyObject; + fn _PyUnicode_XStrip( + _self: *mut PyUnicodeObject, + striptype: c_int, + sepobj: *mut PyObject, + ) -> *mut PyObject; fn _PyUnicodeUCS4_IsLowercase(ch: Py_UNICODE) -> c_int; fn _PyUnicodeUCS4_IsUppercase(ch: Py_UNICODE) -> c_int; fn _PyUnicodeUCS4_IsTitlecase(ch: Py_UNICODE) -> c_int; @@ -255,192 +400,315 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; } #[allow(dead_code)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) - -> *mut PyObject; - fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, - size: Py_ssize_t) -> *mut PyObject; - fn PyUnicodeUCS2_FromString(u: *const c_char) - -> *mut PyObject; +#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] + fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] + fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] + fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS2_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS2_GetSize(unicode: *mut PyObject) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] + fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] + fn PyUnicodeUCS2_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] 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 _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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] + fn PyUnicodeUCS2_AsWideChar( + unicode: *mut PyUnicodeObject, + w: *mut wchar_t, + size: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] 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; + #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] + fn _PyUnicodeUCS2_AsDefaultEncodedString( + arg1: *mut PyObject, + arg2: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] + fn PyUnicodeUCS2_AsEncodedObject( + unicode: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] + 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 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] + fn PyUnicodeUCS2_EncodeUTF8( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] 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_EncodeUTF32( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + byteorder: c_int, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] 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_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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] 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_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_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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] + fn PyUnicodeUCS2_DecodeLatin1( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] + fn PyUnicodeUCS2_EncodeLatin1( + data: *const Py_UNICODE, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] + fn PyUnicodeUCS2_DecodeASCII( + string: *const c_char, + length: Py_ssize_t, + errors: *const c_char, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] + fn PyUnicodeUCS2_EncodeDecimal( + s: *mut Py_UNICODE, + length: Py_ssize_t, + output: *mut c_char, + errors: *const c_char, + ) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] + fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] + fn PyUnicodeUCS2_Split( + s: *mut PyObject, + sep: *mut PyObject, + maxsplit: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] + fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] + fn PyUnicodeUCS2_Tailmatch( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] + fn PyUnicodeUCS2_Find( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + direction: c_int, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] + fn PyUnicodeUCS2_Count( + str: *mut PyObject, + substr: *mut PyObject, + start: Py_ssize_t, + end: Py_ssize_t, + ) -> Py_ssize_t; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] + fn PyUnicodeUCS2_Replace( + str: *mut PyObject, + substr: *mut PyObject, + replstr: *mut PyObject, + maxcount: Py_ssize_t, + ) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] + 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; + #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] + 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; @@ -459,41 +727,48 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; } #[inline(always)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject { PyUnicodeUCS4_FromStringAndSize(u, size) } #[inline(always)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] +#[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(always)] -#[cfg(py_sys_config="Py_UNICODE_SIZE_4")] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS4_AsUTF8String(u) } -#[inline(always)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] +#[inline] +#[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS2_AsUTF8String(u) } -#[inline(always)] -#[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 { +#[inline] +#[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] +#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] +pub unsafe fn PyUnicode_FromEncodedObject( + obj: *mut PyObject, + encoding: *const c_char, + errors: *const c_char, +) -> *mut PyObject { PyUnicodeUCS4_FromEncodedObject(obj, encoding, errors) } -#[inline(always)] -#[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] -pub unsafe fn PyUnicode_FromEncodedObject(obj: *mut PyObject, - encoding: *const c_char, - errors: *const c_char) -> *mut PyObject { +#[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) } diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index a609b0e8512..1a9777175e6 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -1,19 +1,27 @@ +use crate::ffi2::object::PyObject; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::PyObject; -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { - pub fn PyErr_WarnEx(category: *mut PyObject, msg: *const c_char, - stacklevel: Py_ssize_t) -> c_int; - pub fn PyErr_WarnExplicit(arg1: *mut PyObject, - arg2: *const c_char, - arg3: *const c_char, - arg4: c_int, - arg5: *const c_char, - arg6: *mut PyObject) -> c_int; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyErr_WarnEx")] + 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] +#[cfg_attr(PyPy, link_name = "PyPyErr_Warn")] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) } diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index f13714d08af..3ea116b55f6 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -1,13 +1,13 @@ +use crate::ffi2::object::*; +use crate::ffi2::pyport::Py_ssize_t; use std::os::raw::{c_int, c_long}; -use ffi2::pyport::Py_ssize_t; -use ffi2::object::*; #[repr(C)] #[derive(Copy, Clone)] pub struct PyWeakReference { - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_next: *mut PyObject, - #[cfg(py_sys_config="Py_TRACE_REFS")] + #[cfg(py_sys_config = "Py_TRACE_REFS")] pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, @@ -15,50 +15,60 @@ pub struct PyWeakReference { pub wr_callback: *mut PyObject, pub hash: c_long, pub wr_prev: *mut PyWeakReference, - pub wr_next: *mut PyWeakReference + pub wr_next: *mut PyWeakReference, } -#[cfg_attr(windows, link(name="pythonXY"))] extern "C" { +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { static mut _PyWeakref_RefType: PyTypeObject; static mut _PyWeakref_ProxyType: PyTypeObject; static mut _PyWeakref_CallableProxyType: PyTypeObject; } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } -#[inline(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckProxy")] pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int { - ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) || - (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int + ((Py_TYPE(op) == &mut _PyWeakref_ProxyType) + || (Py_TYPE(op) == &mut _PyWeakref_CallableProxyType)) as c_int } -#[inline(always)] +#[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; +#[cfg_attr(windows, link(name = "pythonXY"))] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")] + pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")] + pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")] 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(always)] +#[inline] +#[cfg_attr(PyPy, link_name = "PyPyWeakref_GET_OBJECT")] pub unsafe fn PyWeakref_GET_OBJECT(_ref: *mut PyObject) -> *mut PyObject { let obj = (*(_ref as *mut PyWeakReference)).wr_object; - if Py_REFCNT(obj) > 0 { obj } else { Py_None() } + if Py_REFCNT(obj) > 0 { + obj + } else { + Py_None() + } } - From 160b88dd54fd3fdf82c9a41e7af4e466a6cdaaaa Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 13:27:38 +0200 Subject: [PATCH 051/138] check python3 for pypy --- pyo3build/src/py_interpreter.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 8aa5445d46f..a6d7540629e 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -175,8 +175,11 @@ print(sys.exec_prefix) /// Checks if interpreter is supported by PyO3 fn ensure_python_version_is_supported(version: &PythonVersion) -> Result<(), String> { - match (version.major, version.minor) { - (3, Some(minor)) if minor < PY3_MIN_MINOR => Err(format!( + match (version.kind, version.major, version.minor) { + (PythonInterpreterKind::PyPy, 2, _) => { + Err("PyPy cpyext bindings is only supported for Python3".to_string()) + } + (_, 3, Some(minor)) if minor < PY3_MIN_MINOR => Err(format!( "Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor )), From 4099f3ba31ef6ce08aa98e1e9ca9cdefa75666ff Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 14:57:22 +0200 Subject: [PATCH 052/138] tiny fix --- pyo3build/src/py_interpreter.rs | 2 +- src/gil.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index a6d7540629e..15dd2554f30 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -175,7 +175,7 @@ print(sys.exec_prefix) /// Checks if interpreter is supported by PyO3 fn ensure_python_version_is_supported(version: &PythonVersion) -> Result<(), String> { - match (version.kind, version.major, version.minor) { + match (&version.kind, version.major, version.minor) { (PythonInterpreterKind::PyPy, 2, _) => { Err("PyPy cpyext bindings is only supported for Python3".to_string()) } diff --git a/src/gil.rs b/src/gil.rs index 7f04b511464..3a9d3c1d511 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -53,6 +53,9 @@ pub fn prepare_freethreaded_python() { // Signal handling depends on the notion of a 'main thread', which doesn't exist in this case. // Note that the 'main thread' notion in Python isn't documented properly; // and running Python without one is not officially supported. + + // PyPy does not support the embedding API + #[cfg(not(PyPy))] ffi::Py_InitializeEx(0); ffi::PyEval_InitThreads(); // PyEval_InitThreads() will acquire the GIL, From 1e29a838f059d60b00d91391b6e552158cccf4fc Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 15:57:35 +0200 Subject: [PATCH 053/138] revert ffi2 for real --- src/ffi2/boolobject.rs | 6 +-- src/ffi2/bufferobject.rs | 8 +-- src/ffi2/bytearrayobject.rs | 9 ---- src/ffi2/cellobject.rs | 1 - src/ffi2/ceval.rs | 18 ------- src/ffi2/classobject.rs | 14 ++--- src/ffi2/cobject.rs | 7 --- src/ffi2/code.rs | 4 -- src/ffi2/complexobject.rs | 8 --- src/ffi2/descrobject.rs | 7 --- src/ffi2/dictobject.rs | 19 ------- src/ffi2/eval.rs | 1 - src/ffi2/fileobject.rs | 8 --- src/ffi2/floatobject.rs | 7 --- src/ffi2/frameobject.rs | 1 - src/ffi2/funcobject.rs | 6 --- src/ffi2/genobject.rs | 2 - src/ffi2/import.rs | 9 ---- src/ffi2/iterobject.rs | 2 - src/ffi2/listobject.rs | 17 +----- src/ffi2/longobject.rs | 23 -------- src/ffi2/memoryobject.rs | 4 -- src/ffi2/methodobject.rs | 6 +-- src/ffi2/mod.rs | 2 - src/ffi2/modsupport.rs | 11 ---- src/ffi2/moduleobject.rs | 3 -- src/ffi2/object.rs | 71 ++---------------------- src/ffi2/objectabstract.rs | 104 +----------------------------------- src/ffi2/objimpl.rs | 2 - src/ffi2/pycapsule.rs | 12 ----- src/ffi2/pydebug.rs | 19 ------- src/ffi2/pyerrors.rs | 69 ------------------------ src/ffi2/pymem.rs | 1 - src/ffi2/pystate.rs | 12 +---- src/ffi2/pythonrun.rs | 9 ---- src/ffi2/rangeobject.rs | 1 - src/ffi2/setobject.rs | 15 ------ src/ffi2/sliceobject.rs | 6 --- src/ffi2/stringobject.rs | 7 --- src/ffi2/traceback.rs | 4 -- src/ffi2/tupleobject.rs | 7 --- src/ffi2/unicodeobject.rs | 93 ++------------------------------ src/ffi2/warnings.rs | 2 - src/ffi2/weakrefobject.rs | 7 --- 44 files changed, 17 insertions(+), 627 deletions(-) diff --git a/src/ffi2/boolobject.rs b/src/ffi2/boolobject.rs index 145a0a3b222..14231041aa0 100644 --- a/src/ffi2/boolobject.rs +++ b/src/ffi2/boolobject.rs @@ -6,17 +6,13 @@ pub type PyBoolObject = PyIntObject; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "_PyPy_ZeroStruct")] static mut _Py_ZeroStruct: PyIntObject; - #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyIntObject; - #[cfg_attr(PyPy, link_name = "PyPyBool_FromLong")] pub fn PyBool_FromLong(arg1: c_long) -> *mut PyObject; } -#[cfg_attr(PyPy, link_name = "PyPyBool_Check")] +#[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 diff --git a/src/ffi2/bufferobject.rs b/src/ffi2/bufferobject.rs index 8e01ea1aad0..82e7b2723e6 100644 --- a/src/ffi2/bufferobject.rs +++ b/src/ffi2/bufferobject.rs @@ -4,9 +4,10 @@ use std::os::raw::{c_int, c_void}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyBuffer_Type")] 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 @@ -16,22 +17,17 @@ pub const Py_END_OF_BUFFER: Py_ssize_t = -1; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromObject")] pub fn PyBuffer_FromObject( base: *mut PyObject, offset: Py_ssize_t, size: Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteObject")] pub fn PyBuffer_FromReadWriteObject( base: *mut PyObject, offset: Py_ssize_t, size: Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromMemory")] pub fn PyBuffer_FromMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromReadWriteMemory")] pub fn PyBuffer_FromReadWriteMemory(ptr: *mut c_void, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_New")] pub fn PyBuffer_New(size: Py_ssize_t) -> *mut PyObject; } diff --git a/src/ffi2/bytearrayobject.rs b/src/ffi2/bytearrayobject.rs index bab35e12d88..a656e1d0571 100644 --- a/src/ffi2/bytearrayobject.rs +++ b/src/ffi2/bytearrayobject.rs @@ -19,17 +19,14 @@ struct PyByteArrayObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name = "PyPyByteArray_Check")] pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyByteArray_Type) } -#[cfg_attr(PyPy, link_name = "PyPyByteArray_CheckExact")] pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyByteArray_Type; (Py_TYPE(op) == u) as c_int @@ -37,17 +34,11 @@ pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromObject")] pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Concat")] pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_FromStringAndSize")] pub fn PyByteArray_FromStringAndSize(string: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Size")] pub fn PyByteArray_Size(bytearray: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_AsString")] pub fn PyByteArray_AsString(bytearray: *mut PyObject) -> *mut c_char; - #[cfg_attr(PyPy, link_name = "PyPyByteArray_Resize")] pub fn PyByteArray_Resize(bytearray: *mut PyObject, len: Py_ssize_t) -> c_int; } diff --git a/src/ffi2/cellobject.rs b/src/ffi2/cellobject.rs index 5d13f5196e6..30a1cb57618 100644 --- a/src/ffi2/cellobject.rs +++ b/src/ffi2/cellobject.rs @@ -16,7 +16,6 @@ struct PyCellObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCell_Type")] pub static mut PyCell_Type: PyTypeObject; } diff --git a/src/ffi2/ceval.rs b/src/ffi2/ceval.rs index 05a29f3970b..aae8a6ccdbb 100644 --- a/src/ffi2/ceval.rs +++ b/src/ffi2/ceval.rs @@ -7,15 +7,12 @@ use std::os::raw::{c_char, c_int, c_void}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyEval_CallObjectWithKeywords")] pub fn PyEval_CallObjectWithKeywords( callable: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_CallFunction")] pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_CallMethod")] pub fn PyEval_CallMethod( obj: *mut PyObject, methodname: *const c_char, @@ -24,27 +21,19 @@ extern "C" { ) -> *mut PyObject; pub fn PyEval_SetProfile(func: Option, obj: *mut PyObject); pub fn PyEval_SetTrace(func: Option, obj: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyEval_GetBuiltins")] pub fn PyEval_GetBuiltins() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_GetGlobals")] pub fn PyEval_GetGlobals() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyEval_GetLocals")] pub fn PyEval_GetLocals() -> *mut PyObject; pub fn PyEval_GetFrame() -> *mut PyFrameObject; pub fn PyEval_GetRestricted() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyEval_MergeCompilerFlags")] pub fn PyEval_MergeCompilerFlags(cf: *mut PyCompilerFlags) -> c_int; pub fn Py_FlushLine() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_AddPendingCall")] pub fn Py_AddPendingCall( func: Option c_int>, arg: *mut c_void, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_MakePendingCalls")] pub fn Py_MakePendingCalls() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_SetRecursionLimit")] pub fn Py_SetRecursionLimit(arg1: c_int); - #[cfg_attr(PyPy, link_name = "PyPy_GetRecursionLimit")] pub fn Py_GetRecursionLimit() -> c_int; fn _Py_CheckRecursiveCall(_where: *mut c_char) -> c_int; @@ -53,27 +42,20 @@ extern "C" { 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; - #[cfg_attr(PyPy, link_name = "PyPyEval_SaveThread")] pub fn PyEval_SaveThread() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyEval_RestoreThread")] pub fn PyEval_RestoreThread(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name = "_PyPyEval_SliceIndex")] 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" { - #[cfg_attr(PyPy, link_name = "PyPyEval_ThreadsInitialized")] pub fn PyEval_ThreadsInitialized() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyEval_InitThreads")] pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); pub fn PyEval_ReleaseLock(); - #[cfg_attr(PyPy, link_name = "PyPyEval_AcquireThread")] pub fn PyEval_AcquireThread(tstate: *mut PyThreadState); - #[cfg_attr(PyPy, link_name = "PyPyEval_ReleaseThread")] pub fn PyEval_ReleaseThread(tstate: *mut PyThreadState); pub fn PyEval_ReInitThreads(); } diff --git a/src/ffi2/classobject.rs b/src/ffi2/classobject.rs index d2935e5cf16..60a7da192e7 100644 --- a/src/ffi2/classobject.rs +++ b/src/ffi2/classobject.rs @@ -51,29 +51,24 @@ pub struct PyMethodObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyClass_Type: PyTypeObject; - // TODO: check why this symbol isn't exported by libpypy - #[cfg_attr(PyPy, link_name = "PyPyClass_Type")] pub static mut PyInstance_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyMethod_Type")] pub static mut PyMethod_Type: PyTypeObject; } -#[inline(always)] +#[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(always)] +#[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(always)] -#[cfg_attr(PyPy, link_name = "PyPyMethod_Check")] +#[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 @@ -92,15 +87,12 @@ extern "C" { arg3: *mut PyObject, ) -> *mut PyObject; pub fn PyInstance_NewRaw(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMethod_New")] pub fn PyMethod_New( arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMethod_Function")] pub fn PyMethod_Function(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMethod_Self")] 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; diff --git a/src/ffi2/cobject.rs b/src/ffi2/cobject.rs index c28d6a9cf13..eb1d9414ad2 100644 --- a/src/ffi2/cobject.rs +++ b/src/ffi2/cobject.rs @@ -3,7 +3,6 @@ use std::os::raw::{c_char, c_int, c_void}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCObject_Type")] pub static mut PyCObject_Type: PyTypeObject; } @@ -14,23 +13,17 @@ pub unsafe fn PyCObject_Check(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtr")] pub fn PyCObject_FromVoidPtr( cobj: *mut c_void, destruct: Option, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCObject_FromVoidPtrAndDesc")] pub fn PyCObject_FromVoidPtrAndDesc( cobj: *mut c_void, desc: *mut c_void, destruct: Option, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCObject_AsVoidPtr")] pub fn PyCObject_AsVoidPtr(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCObject_GetDesc")] pub fn PyCObject_GetDesc(arg1: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCObject_Import")] pub fn PyCObject_Import(module_name: *mut c_char, cobject_name: *mut c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCObject_SetVoidPtr")] pub fn PyCObject_SetVoidPtr(_self: *mut PyObject, cobj: *mut c_void) -> c_int; } diff --git a/src/ffi2/code.rs b/src/ffi2/code.rs index 4a11c5a506d..be166e336ce 100644 --- a/src/ffi2/code.rs +++ b/src/ffi2/code.rs @@ -55,7 +55,6 @@ pub const CO_MAXBLOCKS: usize = 20; extern "C" { pub static mut PyCode_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyCode_New")] pub fn PyCode_New( arg1: c_int, arg2: c_int, @@ -72,14 +71,12 @@ extern "C" { arg13: c_int, arg14: *mut PyObject, ) -> *mut PyCodeObject; - #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] 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; - #[cfg_attr(PyPy, link_name = "PyPyCode_Check")] //fn _PyCode_CheckLineNumber(co: *mut PyCodeObject, // lasti: c_int, // bounds: *mut PyAddrPair) -> c_int; @@ -97,7 +94,6 @@ pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyCode_GetNumFree")] pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { crate::ffi2::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) } diff --git a/src/ffi2/complexobject.rs b/src/ffi2/complexobject.rs index 23da782ba10..5576752e2bc 100644 --- a/src/ffi2/complexobject.rs +++ b/src/ffi2/complexobject.rs @@ -34,17 +34,14 @@ pub struct PyComplexObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyComplex_Type")] pub static mut PyComplex_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name = "PyPyComplex_Check")] #[inline] pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } -#[cfg_attr(PyPy, link_name = "PyPyComplex_CheckExact")] #[inline] pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyComplex_Type; @@ -53,15 +50,10 @@ pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyComplex_FromDoubles")] pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyComplex_RealAsDouble")] pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name = "PyPyComplex_ImagAsDouble")] pub fn PyComplex_ImagAsDouble(op: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")] pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex; //fn _PyComplex_FormatAdvanced(obj: *mut PyObject, diff --git a/src/ffi2/descrobject.rs b/src/ffi2/descrobject.rs index a8c1d12ffd7..06ace20f4fb 100644 --- a/src/ffi2/descrobject.rs +++ b/src/ffi2/descrobject.rs @@ -70,19 +70,13 @@ pub const PyWrapperFlag_KEYWORDS: c_int = 1; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyWrapperDescr_Type")] pub static mut PyWrapperDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyDictProxy_Type")] pub static mut PyDictProxy_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyGetSetDescr_Type")] pub static mut PyGetSetDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyMemberDescr_Type")] pub static mut PyMemberDescr_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyProperty_Type")] pub static mut PyProperty_Type: PyTypeObject; pub fn PyDescr_NewMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDescr_NewClassMethod")] pub fn PyDescr_NewClassMethod(arg1: *mut PyTypeObject, arg2: *mut PyMethodDef) -> *mut PyObject; pub fn PyDescr_NewMember(arg1: *mut PyTypeObject, arg2: *mut PyMemberDef) -> *mut PyObject; @@ -101,7 +95,6 @@ pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] //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; diff --git a/src/ffi2/dictobject.rs b/src/ffi2/dictobject.rs index 97fdb11a1fe..7415a854d28 100644 --- a/src/ffi2/dictobject.rs +++ b/src/ffi2/dictobject.rs @@ -6,7 +6,6 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyDict_Type")] pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -29,43 +28,27 @@ pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyDict_New")] pub fn PyDict_New() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDictProxy_New")] pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Clear")] pub fn PyDict_Clear(mp: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyDict_Contains")] pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_Copy")] pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")] pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_SetItem")] pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_DelItem")] pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemString")] pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_SetItemString")] pub fn PyDict_SetItemString( dp: *mut PyObject, key: *const c_char, item: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")] pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_Keys")] pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Values")] pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Items")] pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDict_Size")] pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyDict_Next")] pub fn PyDict_Next( mp: *mut PyObject, pos: *mut Py_ssize_t, @@ -79,9 +62,7 @@ extern "C" { hash: c_long) -> c_int; pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject; pub fn _PyDict_MaybeUntrack(mp: *mut PyObject);*/ - #[cfg_attr(PyPy, link_name = "PyPyDict_Update")] pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDict_Merge")] 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; diff --git a/src/ffi2/eval.rs b/src/ffi2/eval.rs index b36b28c56c0..41d72d909ee 100644 --- a/src/ffi2/eval.rs +++ b/src/ffi2/eval.rs @@ -4,7 +4,6 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyEval_EvalCode")] pub fn PyEval_EvalCode( arg1: *mut PyCodeObject, arg2: *mut PyObject, diff --git a/src/ffi2/fileobject.rs b/src/ffi2/fileobject.rs index 5fb1faf59bf..c042f95ac7b 100644 --- a/src/ffi2/fileobject.rs +++ b/src/ffi2/fileobject.rs @@ -21,9 +21,7 @@ pub const PY_STDIOTEXTMODE: &'static str = "b"; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFile_FromString")] pub fn PyFile_FromString(arg1: *mut c_char, arg2: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFile_SetBufSize")] 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( @@ -31,7 +29,6 @@ extern "C" { arg2: *const c_char, errors: *mut c_char, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyFile_FromFile")] pub fn PyFile_FromFile( arg1: *mut FILE, arg2: *mut c_char, @@ -41,16 +38,11 @@ extern "C" { pub fn PyFile_AsFile(arg1: *mut PyObject) -> *mut FILE; //pub fn PyFile_IncUseCount(arg1: *mut PyFileObject); //pub fn PyFile_DecUseCount(arg1: *mut PyFileObject); - #[cfg_attr(PyPy, link_name = "PyPyFile_Name")] pub fn PyFile_Name(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFile_GetLine")] pub fn PyFile_GetLine(arg1: *mut PyObject, arg2: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFile_WriteObject")] 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; - #[cfg_attr(PyPy, link_name = "PyPyFile_WriteString")] pub fn PyFile_WriteString(arg1: *const c_char, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsFileDescriptor")] pub fn PyObject_AsFileDescriptor(arg1: *mut PyObject) -> c_int; pub fn Py_UniversalNewlineFgets( arg1: *mut c_char, diff --git a/src/ffi2/floatobject.rs b/src/ffi2/floatobject.rs index 9ea642f52a2..ddd5de4b72f 100644 --- a/src/ffi2/floatobject.rs +++ b/src/ffi2/floatobject.rs @@ -16,18 +16,15 @@ struct PyFloatObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFloat_Type")] pub static mut PyFloat_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyFloat_Check")] pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyFloat_CheckExact")] pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyFloat_Type; (Py_TYPE(op) == u) as c_int @@ -37,11 +34,8 @@ pub const PyFloat_STR_PRECISION: c_int = 12; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFloat_FromString")] pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFloat_FromDouble")] pub fn PyFloat_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFloat_AsDouble")] pub fn PyFloat_AsDouble(pyfloat: *mut PyObject) -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; @@ -50,7 +44,6 @@ extern "C" { pub fn PyFloat_ClearFreeList() -> c_int; } -#[cfg_attr(PyPy, link_name = "PyPyFloat_AS_DOUBLE")] pub unsafe fn PyFloat_AS_DOUBLE(pyfloat: *mut PyObject) -> c_double { (*(pyfloat as *mut PyFloatObject)).ob_fval } diff --git a/src/ffi2/frameobject.rs b/src/ffi2/frameobject.rs index 80ca7c4c2df..b9060b1694c 100644 --- a/src/ffi2/frameobject.rs +++ b/src/ffi2/frameobject.rs @@ -69,7 +69,6 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFrame_New")] pub fn PyFrame_New( tstate: *mut PyThreadState, code: *mut PyCodeObject, diff --git a/src/ffi2/funcobject.rs b/src/ffi2/funcobject.rs index a03f964f71e..55a93731f52 100644 --- a/src/ffi2/funcobject.rs +++ b/src/ffi2/funcobject.rs @@ -3,12 +3,10 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyFunction_Type")] pub static mut PyFunction_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyFunction_Check")] pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyFunction_Type; (Py_TYPE(op) == u) as c_int @@ -17,7 +15,6 @@ pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFunction_GetCode")] 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; @@ -27,11 +24,8 @@ extern "C" { pub fn PyFunction_SetClosure(f: *mut PyObject, closure: *mut PyObject) -> c_int; pub static mut PyClassMethod_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_Type")] pub static mut PyStaticMethod_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyClassMethod_New")] pub fn PyClassMethod_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyStaticMethod_New")] pub fn PyStaticMethod_New(arg1: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi2/genobject.rs b/src/ffi2/genobject.rs index 30742a9cfae..b21db703e82 100644 --- a/src/ffi2/genobject.rs +++ b/src/ffi2/genobject.rs @@ -24,13 +24,11 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } diff --git a/src/ffi2/import.rs b/src/ffi2/import.rs index 0b67d5287f9..879d1a91c88 100644 --- a/src/ffi2/import.rs +++ b/src/ffi2/import.rs @@ -35,9 +35,7 @@ pub unsafe fn PyImport_ImportModuleEx( #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")] pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")] pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; pub fn PyImport_ImportModuleLevel( name: *mut c_char, @@ -48,13 +46,9 @@ extern "C" { ) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ReloadModule")] pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")] pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModule")] pub fn PyImport_ExecCodeModule(name: *mut c_char, co: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModuleEx")] pub fn PyImport_ExecCodeModuleEx( name: *mut c_char, co: *mut PyObject, @@ -62,7 +56,6 @@ extern "C" { ) -> *mut PyObject; pub fn PyImport_GetMagicNumber() -> c_long; pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")] pub fn PyImport_GetModuleDict() -> *mut PyObject; pub fn PyImport_ImportFrozenModule(name: *mut c_char) -> c_int; @@ -77,9 +70,7 @@ extern "C" { /*for internal use only: pub fn PyImport_Cleanup(); -#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_AcquireLock")] pub fn _PyImport_AcquireLock(); -#[cfg_attr(PyPy, link_name="\u{1}__PyPyImport_ReleaseLock")] pub fn _PyImport_ReleaseLock() -> c_int; pub fn _PyImport_FindModule(arg1: *const c_char, arg2: *mut PyObject, diff --git a/src/ffi2/iterobject.rs b/src/ffi2/iterobject.rs index ece1443087c..4b5a00b2d2c 100644 --- a/src/ffi2/iterobject.rs +++ b/src/ffi2/iterobject.rs @@ -6,9 +6,7 @@ extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPySeqIter_New")] pub fn PySeqIter_New(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCallIter_New")] pub fn PyCallIter_New(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; } diff --git a/src/ffi2/listobject.rs b/src/ffi2/listobject.rs index 1a269b5b9b1..e9745a478f8 100644 --- a/src/ffi2/listobject.rs +++ b/src/ffi2/listobject.rs @@ -18,7 +18,6 @@ pub struct PyListObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyList_Type")] pub static mut PyList_Type: PyTypeObject; } @@ -35,53 +34,39 @@ pub unsafe fn PyList_CheckExact(op: *mut PyObject) -> c_int { /// Macro, trading safety for speed #[inline] -#[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] 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] -#[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] 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(always)] -#[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")] +#[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" { - #[cfg_attr(PyPy, link_name = "PyPyList_New")] pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyList_Size")] pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyList_GetItem")] pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyList_SetItem")] pub fn PyList_SetItem(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Insert")] pub fn PyList_Insert(list: *mut PyObject, index: Py_ssize_t, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Append")] pub fn PyList_Append(list: *mut PyObject, item: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_GetSlice")] pub fn PyList_GetSlice(list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyList_SetSlice")] pub fn PyList_SetSlice( list: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t, itemlist: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Sort")] pub fn PyList_Sort(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_Reverse")] pub fn PyList_Reverse(list: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")] pub fn PyList_AsTuple(list: *mut PyObject) -> *mut PyObject; //fn _PyList_Extend(arg1: *mut PyListObject, arg2: *mut PyObject) //-> *mut PyObject; diff --git a/src/ffi2/longobject.rs b/src/ffi2/longobject.rs index 4c6001bdaef..59e8f80cdf3 100644 --- a/src/ffi2/longobject.rs +++ b/src/ffi2/longobject.rs @@ -11,7 +11,6 @@ pub struct PyLongObject(*mut c_void); #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } @@ -28,62 +27,40 @@ pub unsafe fn PyLong_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyLong_FromLong")] pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLong")] pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromSsize_t")] pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromSize_t")] pub fn PyLong_FromSize_t(v: size_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromLongLong")] pub fn PyLong_FromLongLong(v: c_longlong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnsignedLongLong")] pub fn PyLong_FromUnsignedLongLong(v: c_ulonglong) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromDouble")] pub fn PyLong_FromDouble(v: c_double) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromString")] 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")] - #[cfg_attr(PyPy, link_name = "PyPyLong_FromUnicode")] pub fn PyLong_FromUnicode( u: *mut crate::ffi2::unicodeobject::Py_UNICODE, length: Py_ssize_t, base: c_int, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_FromVoidPtr")] pub fn PyLong_FromVoidPtr(p: *mut c_void) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLong")] pub fn PyLong_AsLong(pylong: *mut PyObject) -> c_long; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongAndOverflow")] pub fn PyLong_AsLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_long; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLongAndOverflow")] pub fn PyLong_AsLongLongAndOverflow(pylong: *mut PyObject, overflow: *mut c_int) -> c_longlong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsSsize_t")] pub fn PyLong_AsSsize_t(pylong: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLong")] pub fn PyLong_AsUnsignedLong(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsLongLong")] pub fn PyLong_AsLongLong(pylong: *mut PyObject) -> c_longlong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLong")] pub fn PyLong_AsUnsignedLongLong(pylong: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongMask")] pub fn PyLong_AsUnsignedLongMask(pylong: *mut PyObject) -> c_ulong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsUnsignedLongLongMask")] pub fn PyLong_AsUnsignedLongLongMask(pylong: *mut PyObject) -> c_ulonglong; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsDouble")] pub fn PyLong_AsDouble(pylong: *mut PyObject) -> c_double; - #[cfg_attr(PyPy, link_name = "PyPyLong_AsVoidPtr")] pub fn PyLong_AsVoidPtr(pylong: *mut PyObject) -> *mut c_void; pub fn PyLong_GetInfo() -> *mut PyObject; -#[cfg_attr(PyPy, link_name="\u{1}__PyPyLong_FromByteArray")] pub fn _PyLong_FromByteArray( bytes: *const c_uchar, n: size_t, diff --git a/src/ffi2/memoryobject.rs b/src/ffi2/memoryobject.rs index cfbd1c43a1b..a6e95f311c2 100644 --- a/src/ffi2/memoryobject.rs +++ b/src/ffi2/memoryobject.rs @@ -4,12 +4,10 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")] pub static mut PyMemoryView_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Check")] pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyMemoryView_Type; (Py_TYPE(op) == u) as c_int @@ -32,9 +30,7 @@ extern "C" { buffertype: c_int, fort: c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromObject")] pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromBuffer")] pub fn PyMemoryView_FromBuffer(info: *mut Py_buffer) -> *mut PyObject; } diff --git a/src/ffi2/methodobject.rs b/src/ffi2/methodobject.rs index 30943d649c9..91c1b5fc95f 100644 --- a/src/ffi2/methodobject.rs +++ b/src/ffi2/methodobject.rs @@ -4,11 +4,10 @@ use std::ptr; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCFunction_Type")] pub static mut PyCFunction_Type: PyTypeObject; } + #[inline] -#[cfg_attr(PyPy, link_name = "PyPyCFunction_Check")] pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyCFunction_Type; (Py_TYPE(op) == u) as c_int @@ -25,7 +24,6 @@ pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyO #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCFunction_GetFunction")] pub fn PyCFunction_GetFunction(f: *mut PyObject) -> Option; pub fn PyCFunction_GetSelf(f: *mut PyObject) -> *mut PyObject; pub fn PyCFunction_GetFlags(f: *mut PyObject) -> c_int; @@ -105,13 +103,11 @@ struct PyCFunctionObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPy_FindMethod")] pub fn Py_FindMethod( methods: *mut PyMethodDef, slf: *mut PyObject, name: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCFunction_NewEx")] pub fn PyCFunction_NewEx( ml: *mut PyMethodDef, slf: *mut PyObject, diff --git a/src/ffi2/mod.rs b/src/ffi2/mod.rs index 91e4f88a97c..8cd39082a38 100644 --- a/src/ffi2/mod.rs +++ b/src/ffi2/mod.rs @@ -131,14 +131,12 @@ pub const Py_eval_input: c_int = 258; #[cfg(not(py_sys_config = "Py_USING_UNICODE"))] #[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] pub fn PyUnicode_Check(op: *mut PyObject) -> libc::c_int { 0 } #[cfg(not(py_sys_config = "Py_USING_UNICODE"))] #[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] pub fn PyUnicode_CheckExact(op: *mut PyObject) -> libc::c_int { 0 } diff --git a/src/ffi2/modsupport.rs b/src/ffi2/modsupport.rs index 1e3f5994ef1..9336942bf42 100644 --- a/src/ffi2/modsupport.rs +++ b/src/ffi2/modsupport.rs @@ -6,11 +6,8 @@ use std::ptr; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyArg_Parse")] pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTuple")] pub fn PyArg_ParseTuple(args: *mut PyObject, format: *const c_char, ...) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyArg_ParseTupleAndKeywords")] pub fn PyArg_ParseTupleAndKeywords( args: *mut PyObject, kw: *mut PyObject, @@ -18,7 +15,6 @@ extern "C" { keywords: *mut *mut c_char, ... ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyArg_UnpackTuple")] pub fn PyArg_UnpackTuple( args: *mut PyObject, name: *const c_char, @@ -26,27 +22,21 @@ extern "C" { max: Py_ssize_t, ... ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPy_BuildValue")] pub fn Py_BuildValue(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPy_BuildValue_SizeT")] //fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) // -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyArg_NoKeywords")] //fn _PyArg_NoKeywords(funcname: *const c_char, // kw: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyModule_AddObject")] pub fn PyModule_AddObject( module: *mut PyObject, name: *const c_char, value: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyModule_AddIntConstant")] pub fn PyModule_AddIntConstant( module: *mut PyObject, name: *const c_char, value: c_long, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyModule_AddStringConstant")] pub fn PyModule_AddStringConstant( module: *mut PyObject, name: *const c_char, @@ -54,7 +44,6 @@ extern "C" { ) -> c_int; #[cfg(all(target_pointer_width = "64", not(py_sys_config = "Py_TRACE_REFS")))] - #[cfg_attr(PyPy, link_name = "_PyPy_InitPyPyModule")] fn Py_InitModule4_64( name: *const c_char, methods: *mut PyMethodDef, diff --git a/src/ffi2/moduleobject.rs b/src/ffi2/moduleobject.rs index 12933e4b934..e6b4e217c4b 100644 --- a/src/ffi2/moduleobject.rs +++ b/src/ffi2/moduleobject.rs @@ -5,12 +5,10 @@ use std::os::raw::{c_char, c_int, c_void}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyModule_Type")] pub static mut PyModule_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyModule_Check")] pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } @@ -24,7 +22,6 @@ pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int { extern "C" { pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")] 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; diff --git a/src/ffi2/object.rs b/src/ffi2/object.rs index 108c52806eb..fbc7266689f 100644 --- a/src/ffi2/object.rs +++ b/src/ffi2/object.rs @@ -6,57 +6,27 @@ use std::os::raw::{c_char, c_double, c_int, c_long, c_uint, c_void}; use std::ptr; #[repr(C)] -#[derive(Copy, Clone, Debug)] -#[cfg(not(PyPy))] +#[derive(Debug, Copy, Clone)] pub struct PyObject { #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_next: *mut PyObject, + pub _ob_next: *mut PyObject, #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_prev: *mut PyObject, + pub _ob_prev: *mut PyObject, pub ob_refcnt: Py_ssize_t, pub ob_type: *mut PyTypeObject, } -#[repr(C)] -#[derive(Debug, Copy, Clone)] -#[cfg(PyPy)] -pub struct PyObject { - pub ob_refcnt: Py_ssize_t, - pub ob_pypy_link: Py_ssize_t, - pub ob_type: *mut PyTypeObject, -} - -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[cfg(not(PyPy))] -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"))] -#[cfg(not(PyPy))] -pub const PyObject_HEAD_INIT: PyObject = PyObject { - ob_refcnt: 1, - ob_type: ::std::ptr::null_mut(), -}; - #[cfg(py_sys_config = "Py_TRACE_REFS")] -#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { _ob_next: ::std::ptr::null_mut(), _ob_prev: ::std::ptr::null_mut(), ob_refcnt: 1, - ob_pypy_link: 0, ob_type: ::std::ptr::null_mut(), }; #[cfg(not(py_sys_config = "Py_TRACE_REFS"))] -#[cfg(PyPy)] pub const PyObject_HEAD_INIT: PyObject = PyObject { ob_refcnt: 1, - ob_pypy_link: 0, ob_type: ::std::ptr::null_mut(), }; @@ -590,6 +560,7 @@ impl Clone for PyHeapTypeObject { // 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 { @@ -609,9 +580,7 @@ pub unsafe fn PyObject_TypeCheck(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_ #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyType_Type")] pub static mut PyType_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyBaseObject_Type")] pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; } @@ -628,16 +597,13 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyType_Ready")] pub fn PyType_Ready(t: *mut PyTypeObject) -> c_int; pub fn PyType_GenericAlloc(t: *mut PyTypeObject, nitems: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyType_GenericNew")] pub fn PyType_GenericNew( t: *mut PyTypeObject, args: *mut PyObject, kwds: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyType_Lookup")] fn _PyType_Lookup(arg1: *mut PyTypeObject, arg2: *mut PyObject) -> *mut PyObject; fn _PyObject_LookupSpecial( arg1: *mut PyObject, @@ -645,21 +611,16 @@ extern "C" { arg3: *mut *mut PyObject, ) -> *mut PyObject; pub fn PyType_ClearCache() -> c_uint; - #[cfg_attr(PyPy, link_name = "PyPyType_Modified")] pub fn PyType_Modified(t: *mut PyTypeObject); - #[cfg_attr(PyPy, link_name = "PyPyObject_Print")] pub fn PyObject_Print(o: *mut PyObject, fp: *mut FILE, flags: c_int) -> c_int; fn _PyObject_Dump(o: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyObject_Repr")] pub fn PyObject_Repr(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_Str")] fn _PyObject_Str(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Str(o: *mut PyObject) -> *mut PyObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyObject_Bytes")] pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { PyObject_Str(o) } @@ -667,61 +628,42 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(py_sys_config = "Py_USING_UNICODE")] - #[cfg_attr(PyPy, link_name = "PyPyObject_Unicode")] pub fn PyObject_Unicode(o: *mut PyObject) -> *mut PyObject; pub fn PyObject_Compare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompare")] pub fn PyObject_RichCompare( arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_RichCompareBool")] pub fn PyObject_RichCompareBool(arg1: *mut PyObject, arg2: *mut PyObject, arg3: c_int) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttrString")] pub fn PyObject_GetAttrString(arg1: *mut PyObject, arg2: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttrString")] pub fn PyObject_SetAttrString( arg1: *mut PyObject, arg2: *const c_char, arg3: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttrString")] pub fn PyObject_HasAttrString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetAttr")] pub fn PyObject_GetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SetAttr")] pub fn PyObject_SetAttr(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_HasAttr")] pub fn PyObject_HasAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "_PyPyObject_GetDictPtr")] fn _PyObject_GetDictPtr(arg1: *mut PyObject) -> *mut *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SelfIter")] pub fn PyObject_SelfIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_GenericGetAttr")] pub fn PyObject_GenericGetAttr(arg1: *mut PyObject, arg2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_GenericSetAttr")] pub fn PyObject_GenericSetAttr( arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_Hash")] pub fn PyObject_Hash(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_HashNotImplemented")] pub fn PyObject_HashNotImplemented(arg1: *mut PyObject) -> Py_hash_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_IsTrue")] pub fn PyObject_IsTrue(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_Not")] pub fn PyObject_Not(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCallable_Check")] 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_ClearWeakRefs")] pub fn PyObject_ClearWeakRefs(arg1: *mut PyObject); fn _PyObject_SlotCompare(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; fn _PyObject_GenericGetAttrWithDict( @@ -735,13 +677,10 @@ extern "C" { arg3: *mut PyObject, arg4: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_Dir")] 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); - #[cfg_attr(PyPy, link_name = "_PyPy_HashDouble")] fn _Py_HashDouble(arg1: c_double) -> c_long; - #[cfg_attr(PyPy, link_name = "_PyPy_HashPointer")] fn _Py_HashPointer(arg1: *mut c_void) -> c_long; } @@ -886,9 +825,7 @@ extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); - #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] static mut _Py_NoneStruct: PyObject; - #[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")] static mut _Py_NotImplementedStruct: PyObject; } diff --git a/src/ffi2/objectabstract.rs b/src/ffi2/objectabstract.rs index bbdb68110f3..28188db493f 100644 --- a/src/ffi2/objectabstract.rs +++ b/src/ffi2/objectabstract.rs @@ -5,13 +5,11 @@ use std::os::raw::{c_char, c_int, c_void}; use std::ptr; #[inline] -#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttrString")] pub unsafe fn PyObject_DelAttrString(o: *mut PyObject, attr_name: *const c_char) -> c_int { PyObject_SetAttrString(o, attr_name, ptr::null_mut()) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyObject_DelAttr")] pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_int { PyObject_SetAttr(o, attr_name, ptr::null_mut()) } @@ -19,93 +17,72 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub fn PyObject_Cmp(o1: *mut PyObject, o2: *mut PyObject, result: *mut c_int) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_Call")] pub fn PyObject_Call( callable_object: *mut PyObject, args: *mut PyObject, kw: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallObject")] pub fn PyObject_CallObject( callable_object: *mut PyObject, args: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunction")] pub fn PyObject_CallFunction( callable_object: *mut PyObject, format: *mut c_char, ... ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethod")] pub fn PyObject_CallMethod( o: *mut PyObject, m: *mut c_char, format: *mut c_char, ... ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyObject_CallFunction_SizeT")] fn _PyObject_CallFunction_SizeT( callable: *mut PyObject, format: *mut c_char, ... ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyObject_CallMethod_SizeT")] fn _PyObject_CallMethod_SizeT( o: *mut PyObject, name: *mut c_char, format: *mut c_char, ... ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallFunctionObjArgs")] pub fn PyObject_CallFunctionObjArgs(callable: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_CallMethodObjArgs")] pub fn PyObject_CallMethodObjArgs(o: *mut PyObject, m: *mut PyObject, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] pub fn PyObject_Type(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_Size")] pub fn PyObject_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_LengthHint")] pub fn _PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetItem")] pub fn PyObject_GetItem(o: *mut PyObject, key: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_SetItem")] 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; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsCharBuffer")] pub fn PyObject_AsCharBuffer( obj: *mut PyObject, buffer: *mut *const c_char, buffer_len: *mut Py_ssize_t, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_CheckReadBuffer")] pub fn PyObject_CheckReadBuffer(obj: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsReadBuffer")] pub fn PyObject_AsReadBuffer( obj: *mut PyObject, buffer: *mut *const c_void, buffer_len: *mut Py_ssize_t, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_AsWriteBuffer")] pub fn PyObject_AsWriteBuffer( obj: *mut PyObject, buffer: *mut *mut c_void, buffer_len: *mut Py_ssize_t, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetBuffer")] pub fn PyObject_GetBuffer(obj: *mut PyObject, view: *mut Py_buffer, flags: c_int) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_GetPointer")] pub fn PyBuffer_GetPointer(view: *mut Py_buffer, indices: *mut Py_ssize_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_ToContiguous")] pub fn PyBuffer_ToContiguous( buf: *mut c_void, view: *mut Py_buffer, len: Py_ssize_t, fort: c_char, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FromContiguous")] pub fn PyBuffer_FromContiguous( view: *mut Py_buffer, buf: *mut c_void, @@ -113,7 +90,6 @@ extern "C" { fort: c_char, ) -> c_int; pub fn PyObject_CopyData(dest: *mut PyObject, src: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_IsContiguous")] pub fn PyBuffer_IsContiguous(view: *mut Py_buffer, fort: c_char) -> c_int; pub fn PyBuffer_FillContiguousStrides( ndims: c_int, @@ -122,7 +98,6 @@ extern "C" { itemsize: c_int, fort: c_char, ); - #[cfg_attr(PyPy, link_name = "PyPyBuffer_FillInfo")] pub fn PyBuffer_FillInfo( view: *mut Py_buffer, o: *mut PyObject, @@ -131,134 +106,79 @@ extern "C" { readonly: c_int, flags: c_int, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyBuffer_Release")] pub fn PyBuffer_Release(view: *mut Py_buffer); - #[cfg_attr(PyPy, link_name = "PyPyObject_Format")] pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyObject_GetIter")] pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyIter_Next")] pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Check")] pub fn PyNumber_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Add")] pub fn PyNumber_Add(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Subtract")] pub fn PyNumber_Subtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Multiply")] pub fn PyNumber_Multiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Divide")] pub fn PyNumber_Divide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_FloorDivide")] pub fn PyNumber_FloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_TrueDivide")] pub fn PyNumber_TrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Remainder")] pub fn PyNumber_Remainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Divmod")] pub fn PyNumber_Divmod(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Power")] pub fn PyNumber_Power(o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Negative")] pub fn PyNumber_Negative(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Positive")] pub fn PyNumber_Positive(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Absolute")] pub fn PyNumber_Absolute(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Invert")] pub fn PyNumber_Invert(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Lshift")] pub fn PyNumber_Lshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Rshift")] pub fn PyNumber_Rshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_And")] pub fn PyNumber_And(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Xor")] pub fn PyNumber_Xor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Or")] pub fn PyNumber_Or(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Index")] pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_AsSsize_t")] 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; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Long")] pub fn PyNumber_Long(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_Float")] pub fn PyNumber_Float(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAdd")] pub fn PyNumber_InPlaceAdd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceSubtract")] pub fn PyNumber_InPlaceSubtract(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceMultiply")] pub fn PyNumber_InPlaceMultiply(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceDivide")] pub fn PyNumber_InPlaceDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceFloorDivide")] pub fn PyNumber_InPlaceFloorDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceTrueDivide")] pub fn PyNumber_InPlaceTrueDivide(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRemainder")] pub fn PyNumber_InPlaceRemainder(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlacePower")] pub fn PyNumber_InPlacePower( o1: *mut PyObject, o2: *mut PyObject, o3: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceLshift")] pub fn PyNumber_InPlaceLshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceRshift")] pub fn PyNumber_InPlaceRshift(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceAnd")] pub fn PyNumber_InPlaceAnd(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceXor")] pub fn PyNumber_InPlaceXor(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyNumber_InPlaceOr")] pub fn PyNumber_InPlaceOr(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; pub fn PyNumber_ToBase(n: *mut PyObject, base: c_int) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_Check")] pub fn PySequence_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_Size")] pub fn PySequence_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySequence_Length")] pub fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySequence_Concat")] pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_Repeat")] pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_GetItem")] pub fn PySequence_GetItem(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_GetSlice")] pub fn PySequence_GetSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_SetItem")] pub fn PySequence_SetItem(o: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_DelItem")] pub fn PySequence_DelItem(o: *mut PyObject, i: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_SetSlice")] pub fn PySequence_SetSlice( o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t, v: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_DelSlice")] pub fn PySequence_DelSlice(o: *mut PyObject, i1: Py_ssize_t, i2: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_Tuple")] pub fn PySequence_Tuple(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_List")] pub fn PySequence_List(o: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_Fast")] 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; - #[cfg_attr(PyPy, link_name = "PyPySequence_Contains")] pub fn PySequence_Contains(seq: *mut PyObject, ob: *mut PyObject) -> c_int; pub fn _PySequence_IterSearch( seq: *mut PyObject, @@ -266,33 +186,21 @@ extern "C" { operation: c_int, ) -> Py_ssize_t; pub fn PySequence_In(o: *mut PyObject, value: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySequence_Index")] pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceConcat")] pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySequence_InPlaceRepeat")] pub fn PySequence_InPlaceRepeat(o: *mut PyObject, count: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMapping_Check")] pub fn PyMapping_Check(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyMapping_Size")] pub fn PyMapping_Size(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyMapping_Length")] pub fn PyMapping_Length(o: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKeyString")] pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *mut c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyMapping_HasKey")] pub fn PyMapping_HasKey(o: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyMapping_GetItemString")] pub fn PyMapping_GetItemString(o: *mut PyObject, key: *mut c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyMapping_SetItemString")] pub fn PyMapping_SetItemString( o: *mut PyObject, key: *mut c_char, value: *mut PyObject, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_IsInstance")] pub fn PyObject_IsInstance(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyObject_IsSubclass")] pub fn PyObject_IsSubclass(object: *mut PyObject, typeorclass: *mut PyObject) -> c_int; } @@ -306,7 +214,6 @@ pub unsafe fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyIter_Check")] pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; (PyType_HasFeature(t, Py_TPFLAGS_HAVE_ITER) != 0 @@ -317,7 +224,6 @@ pub unsafe fn PyIter_Check(obj: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyIndex_Check")] pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { let t = (*obj).ob_type; let n = (*t).tp_as_number; @@ -326,10 +232,8 @@ pub unsafe fn PyIndex_Check(obj: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_SIZE")] pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] ffi2::listobject::PyList_GET_SIZE(o) } else { ffi2::tupleobject::PyTuple_GET_SIZE(o) @@ -337,10 +241,8 @@ pub unsafe fn PySequence_Fast_GET_SIZE(o: *mut PyObject) -> Py_ssize_t { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_GET_ITEM")] pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { if ffi2::listobject::PyList_Check(o) != 0 { - #[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] ffi2::listobject::PyList_GET_ITEM(o, i) } else { ffi2::tupleobject::PyTuple_GET_ITEM(o, i) @@ -348,7 +250,6 @@ pub unsafe fn PySequence_Fast_GET_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_Fast_ITEMS")] 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 @@ -360,7 +261,6 @@ pub unsafe fn PySequence_Fast_ITEMS(o: *mut PyObject) -> *mut *mut PyObject { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySequence_ITEM")] pub unsafe fn PySequence_ITEM(o: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { (*(*Py_TYPE(o)).tp_as_sequence) .sq_item @@ -382,18 +282,16 @@ pub unsafe fn PyMapping_DelItem(o: *mut PyObject, key: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyMapping_Keys")] 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] -#[cfg_attr(PyPy, link_name = "PyPyMapping_Values")] 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] -#[cfg_attr(PyPy, link_name = "PyPyMapping_Items")] pub unsafe fn PyMapping_Items(o: *mut PyObject) -> *mut PyObject { PyObject_CallMethod(o, "items\0".as_ptr() as *mut c_char, ptr::null_mut()) } diff --git a/src/ffi2/objimpl.rs b/src/ffi2/objimpl.rs index e4745a9509b..3e0fe39f923 100644 --- a/src/ffi2/objimpl.rs +++ b/src/ffi2/objimpl.rs @@ -5,9 +5,7 @@ use std::os::raw::{c_char, c_int, c_void}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyObject_Malloc")] pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyObject_Realloc")] pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; pub fn PyObject_Free(arg1: *mut c_void); diff --git a/src/ffi2/pycapsule.rs b/src/ffi2/pycapsule.rs index 94eea810322..db8c1b06405 100644 --- a/src/ffi2/pycapsule.rs +++ b/src/ffi2/pycapsule.rs @@ -3,7 +3,6 @@ use std::os::raw::{c_char, c_int, c_void}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCapsule_Type")] pub static mut PyCapsule_Type: PyTypeObject; } @@ -16,33 +15,22 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyCapsule_New")] pub fn PyCapsule_New( pointer: *mut c_void, name: *const c_char, destructor: Option, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetPointer")] pub fn PyCapsule_GetPointer(capsule: *mut PyObject, name: *const c_char) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetDestructor")] pub fn PyCapsule_GetDestructor(capsule: *mut PyObject) -> Option; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetName")] pub fn PyCapsule_GetName(capsule: *mut PyObject) -> *const c_char; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_GetContext")] pub fn PyCapsule_GetContext(capsule: *mut PyObject) -> *mut c_void; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_IsValid")] pub fn PyCapsule_IsValid(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetPointer")] pub fn PyCapsule_SetPointer(capsule: *mut PyObject, pointer: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetDestructor")] pub fn PyCapsule_SetDestructor( capsule: *mut PyObject, destructor: Option, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetName")] pub fn PyCapsule_SetName(capsule: *mut PyObject, name: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_SetContext")] pub fn PyCapsule_SetContext(capsule: *mut PyObject, context: *mut c_void) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyCapsule_Import")] pub fn PyCapsule_Import(name: *const c_char, no_block: c_int) -> *mut c_void; } diff --git a/src/ffi2/pydebug.rs b/src/ffi2/pydebug.rs index 52d6d86bff0..086008324a3 100644 --- a/src/ffi2/pydebug.rs +++ b/src/ffi2/pydebug.rs @@ -2,43 +2,24 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPy_DebugFlag")] pub static mut Py_DebugFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_VerboseFlag")] pub static mut Py_VerboseFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_InteractiveFlag")] pub static mut Py_InteractiveFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_InspectFlag")] pub static mut Py_InspectFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_OptimizeFlag")] pub static mut Py_OptimizeFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_NoSiteFlag")] pub static mut Py_NoSiteFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_BytesWarningFlag")] pub static mut Py_BytesWarningFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_UseClassExceptionsFlag")] pub static mut Py_UseClassExceptionsFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_FrozenFlag")] pub static mut Py_FrozenFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_TabcheckFlag")] pub static mut Py_TabcheckFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_UnicodeFlag")] pub static mut Py_UnicodeFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_IgnoreEnvironmentFlag")] pub static mut Py_IgnoreEnvironmentFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_DivisionWarningFlag")] pub static mut Py_DivisionWarningFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_DontWriteBytecodeFlag")] pub static mut Py_DontWriteBytecodeFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_NoUserSiteDirectory")] pub static mut Py_NoUserSiteDirectory: c_int; - #[cfg_attr(PyPy, link_name = "_PyPy_QnewFlag")] pub static mut _Py_QnewFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_Py3kWarningFlag")] pub static mut Py_Py3kWarningFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_HashRandomizationFlag")] pub static mut Py_HashRandomizationFlag: c_int; - #[cfg_attr(PyPy, link_name = "PyPy_FatalError")] pub fn Py_FatalError(message: *const c_char); } diff --git a/src/ffi2/pyerrors.rs b/src/ffi2/pyerrors.rs index 38278f51dbe..4dae53f6f58 100644 --- a/src/ffi2/pyerrors.rs +++ b/src/ffi2/pyerrors.rs @@ -8,29 +8,19 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyErr_SetNone")] pub fn PyErr_SetNone(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_SetObject")] pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_SetString")] pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); - #[cfg_attr(PyPy, link_name = "PyPyErr_Occurred")] pub fn PyErr_Occurred() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_Clear")] pub fn PyErr_Clear(); - #[cfg_attr(PyPy, link_name = "PyPyErr_Fetch")] pub fn PyErr_Fetch( arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, arg3: *mut *mut PyObject, ); - #[cfg_attr(PyPy, link_name = "PyPyErr_Restore")] pub fn PyErr_Restore(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_GivenExceptionMatches")] pub fn PyErr_GivenExceptionMatches(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_ExceptionMatches")] pub fn PyErr_ExceptionMatches(arg1: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_NormalizeException")] pub fn PyErr_NormalizeException( arg1: *mut *mut PyObject, arg2: *mut *mut PyObject, @@ -62,7 +52,6 @@ pub unsafe fn PyExceptionClass_Name(x: *mut PyObject) -> *const c_char { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyExceptionInstance_Class")] pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { if PyInstance_Check(x) != 0 { (*(x as *mut PyInstanceObject)).in_class as *mut PyObject @@ -73,144 +62,86 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyExc_BaseException")] pub static mut PyExc_BaseException: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_Exception")] pub static mut PyExc_Exception: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_StopIteration")] pub static mut PyExc_StopIteration: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_GeneratorExit")] pub static mut PyExc_GeneratorExit: *mut PyObject; pub static mut PyExc_StandardError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ArithmeticError")] pub static mut PyExc_ArithmeticError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_LookupError")] pub static mut PyExc_LookupError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_AssertionError")] pub static mut PyExc_AssertionError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_AttributeError")] pub static mut PyExc_AttributeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_EOFError")] pub static mut PyExc_EOFError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_FloatingPointError")] pub static mut PyExc_FloatingPointError: *mut PyObject; pub static mut PyExc_EnvironmentError: *mut PyObject; pub static mut PyExc_IOError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_OSError")] pub static mut PyExc_OSError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ImportError")] pub static mut PyExc_ImportError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_IndexError")] pub static mut PyExc_IndexError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_KeyError")] pub static mut PyExc_KeyError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_KeyboardInterrupt")] pub static mut PyExc_KeyboardInterrupt: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_MemoryError")] pub static mut PyExc_MemoryError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_NameError")] pub static mut PyExc_NameError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_OverflowError")] pub static mut PyExc_OverflowError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeError")] pub static mut PyExc_RuntimeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_NotImplementedError")] pub static mut PyExc_NotImplementedError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxError")] pub static mut PyExc_SyntaxError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_IndentationError")] pub static mut PyExc_IndentationError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_TabError")] pub static mut PyExc_TabError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ReferenceError")] pub static mut PyExc_ReferenceError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SystemError")] pub static mut PyExc_SystemError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SystemExit")] pub static mut PyExc_SystemExit: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_TypeError")] pub static mut PyExc_TypeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnboundLocalError")] pub static mut PyExc_UnboundLocalError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeError")] pub static mut PyExc_UnicodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeEncodeError")] pub static mut PyExc_UnicodeEncodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeDecodeError")] pub static mut PyExc_UnicodeDecodeError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeTranslateError")] pub static mut PyExc_UnicodeTranslateError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ValueError")] pub static mut PyExc_ValueError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ZeroDivisionError")] pub static mut PyExc_ZeroDivisionError: *mut PyObject; #[cfg(windows)] pub static mut PyExc_WindowsError: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_BufferError")] pub static mut PyExc_BufferError: *mut PyObject; pub static mut PyExc_MemoryErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_RecursionError")] pub static mut PyExc_RecursionErrorInst: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_Warning")] pub static mut PyExc_Warning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UserWarning")] pub static mut PyExc_UserWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_DeprecationWarning")] pub static mut PyExc_DeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_PendingDeprecationWarning")] pub static mut PyExc_PendingDeprecationWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_SyntaxWarning")] pub static mut PyExc_SyntaxWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_RuntimeWarning")] pub static mut PyExc_RuntimeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_FutureWarning")] pub static mut PyExc_FutureWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_ImportWarning")] pub static mut PyExc_ImportWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_UnicodeWarning")] pub static mut PyExc_UnicodeWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyExc_BytesWarning")] pub static mut PyExc_BytesWarning: *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_BadArgument")] pub fn PyErr_BadArgument() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_NoMemory")] pub fn PyErr_NoMemory() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrno")] pub fn PyErr_SetFromErrno(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilenameObject")] pub fn PyErr_SetFromErrnoWithFilenameObject( arg1: *mut PyObject, arg2: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetFromErrnoWithFilename")] pub fn PyErr_SetFromErrnoWithFilename( arg1: *mut PyObject, arg2: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_Format")] pub fn PyErr_Format(arg1: *mut PyObject, arg2: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_BadInternalCall")] pub fn PyErr_BadInternalCall(); pub fn _PyErr_BadInternalCall(filename: *mut c_char, lineno: c_int); - #[cfg_attr(PyPy, link_name = "PyPyErr_NewException")] pub fn PyErr_NewException( name: *mut c_char, base: *mut PyObject, dict: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_NewExceptionWithDoc")] pub fn PyErr_NewExceptionWithDoc( name: *mut c_char, doc: *mut c_char, base: *mut PyObject, dict: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyErr_WriteUnraisable")] pub fn PyErr_WriteUnraisable(arg1: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPyErr_CheckSignals")] pub fn PyErr_CheckSignals() -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")] pub fn PyErr_SetInterrupt(); pub fn PySignal_SetWakeupFd(fd: c_int) -> c_int; pub fn PyErr_SyntaxLocation(arg1: *const c_char, arg2: c_int); diff --git a/src/ffi2/pymem.rs b/src/ffi2/pymem.rs index dabd9a874b9..57c979edb5e 100644 --- a/src/ffi2/pymem.rs +++ b/src/ffi2/pymem.rs @@ -2,7 +2,6 @@ use libc::{c_void, size_t}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyMem_Malloc")] 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); diff --git a/src/ffi2/pystate.rs b/src/ffi2/pystate.rs index 3e538cc403e..bdf6909f247 100644 --- a/src/ffi2/pystate.rs +++ b/src/ffi2/pystate.rs @@ -65,37 +65,27 @@ pub enum PyGILState_STATE { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Get")] //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); - #[cfg_attr(PyPy, link_name = "PyPyThreadState_New")] 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); - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Clear")] pub fn PyThreadState_Clear(arg1: *mut PyThreadState); - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Delete")] pub fn PyThreadState_Delete(arg1: *mut PyThreadState); #[cfg(py_sys_config = "WITH_THREAD")] - #[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")] pub fn PyThreadState_DeleteCurrent(); pub fn PyThreadState_Get() -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyThreadState_Swap")] pub fn PyThreadState_Swap(arg1: *mut PyThreadState) -> *mut PyThreadState; - #[cfg_attr(PyPy, link_name = "PyPyThreadState_GetDict")] pub fn PyThreadState_GetDict() -> *mut PyObject; pub fn PyThreadState_SetAsyncExc(arg1: c_long, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyGILState_Ensure")] pub fn PyGILState_Ensure() -> PyGILState_STATE; - #[cfg_attr(PyPy, link_name = "PyPyGILState_Release")] pub fn PyGILState_Release(arg1: PyGILState_STATE); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; fn _PyThread_CurrentFrames() -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Head")] pub fn PyInterpreterState_Head() -> *mut PyInterpreterState; - #[cfg_attr(PyPy, link_name = "PyPyInterpreterState_Next")] 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; diff --git a/src/ffi2/pythonrun.rs b/src/ffi2/pythonrun.rs index 4a4a0545b18..c2ec5fc9f51 100644 --- a/src/ffi2/pythonrun.rs +++ b/src/ffi2/pythonrun.rs @@ -30,14 +30,12 @@ pub enum Struct_symtable {} #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); - #[cfg_attr(PyPy, link_name = "PyPy_GetProgramName")] 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(); - #[cfg_attr(PyPy, link_name = "PyPy_IsInitialized")] pub fn Py_IsInitialized() -> c_int; pub fn Py_NewInterpreter() -> *mut PyThreadState; pub fn Py_EndInterpreter(arg1: *mut PyThreadState); @@ -97,7 +95,6 @@ extern "C" { arg3: c_int, arg4: c_int, ) -> *mut Struct__node; - #[cfg_attr(PyPy, link_name = "PyPyRun_StringFlags")] pub fn PyRun_StringFlags( arg1: *const c_char, arg2: c_int, @@ -114,7 +111,6 @@ extern "C" { arg6: c_int, arg7: *mut PyCompilerFlags, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] pub fn Py_CompileStringFlags( arg1: *const c_char, arg2: *const c_char, @@ -126,13 +122,9 @@ extern "C" { arg2: *const c_char, arg3: c_int, ) -> *mut Struct_symtable; - #[cfg_attr(PyPy, link_name = "PyPyErr_Print")] pub fn PyErr_Print(); - #[cfg_attr(PyPy, link_name = "PyPyErr_PrintEx")] pub fn PyErr_PrintEx(arg1: c_int); - #[cfg_attr(PyPy, link_name = "PyPyErr_Display")] pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject); - #[cfg_attr(PyPy, link_name = "PyPy_AtExit")] pub fn Py_AtExit(func: Option) -> c_int; pub fn Py_Exit(arg1: c_int); pub fn Py_FdIsInteractive(arg1: *mut FILE, arg2: *const c_char) -> c_int; @@ -141,7 +133,6 @@ extern "C" { pub fn Py_GetPrefix() -> *mut c_char; pub fn Py_GetExecPrefix() -> *mut c_char; pub fn Py_GetPath() -> *mut c_char; - #[cfg_attr(PyPy, link_name = "PyPy_GetVersion")] pub fn Py_GetVersion() -> *const c_char; pub fn Py_GetPlatform() -> *const c_char; pub fn Py_GetCopyright() -> *const c_char; diff --git a/src/ffi2/rangeobject.rs b/src/ffi2/rangeobject.rs index e6992496130..294e15e7b7d 100644 --- a/src/ffi2/rangeobject.rs +++ b/src/ffi2/rangeobject.rs @@ -3,7 +3,6 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyRange_Type")] pub static mut PyRange_Type: PyTypeObject; } diff --git a/src/ffi2/setobject.rs b/src/ffi2/setobject.rs index 4511252090d..130647f8015 100644 --- a/src/ffi2/setobject.rs +++ b/src/ffi2/setobject.rs @@ -6,21 +6,17 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPySet_Type")] pub static mut PySet_Type: PyTypeObject; - #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Type")] pub static mut PyFrozenSet_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_CheckExact")] 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] -#[cfg_attr(PyPy, link_name = "PyPyAnySet_CheckExact")] pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int { let s: *mut PyTypeObject = &mut PySet_Type; let f: *mut PyTypeObject = &mut PyFrozenSet_Type; @@ -28,7 +24,6 @@ pub unsafe fn PyAnySet_CheckExact(ob: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyAnySet_Check")] pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int { (PyAnySet_CheckExact(ob) != 0 || PyType_IsSubtype(Py_TYPE(ob), &mut PySet_Type) != 0 @@ -36,14 +31,12 @@ pub unsafe fn PyAnySet_Check(ob: *mut PyObject) -> c_int { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySet_Check")] 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] -#[cfg_attr(PyPy, link_name = "PyPyFrozenSet_Check")] 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 @@ -51,26 +44,18 @@ pub unsafe fn PyFrozenSet_Check(ob: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPySet_New")] pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyFrozenSet_New")] pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySet_Size")] pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPySet_Clear")] pub fn PySet_Clear(set: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySet_Contains")] pub fn PySet_Contains(anyset: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySet_Discard")] pub fn PySet_Discard(set: *mut PyObject, key: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySet_Add")] 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; - #[cfg_attr(PyPy, link_name = "PyPySet_Pop")] pub fn PySet_Pop(set: *mut PyObject) -> *mut PyObject; //pub fn _PySet_Update(set: *mut PyObject, iterable: *mut PyObject) // -> c_int; diff --git a/src/ffi2/sliceobject.rs b/src/ffi2/sliceobject.rs index 9a2b1c87699..0e4ac7aba24 100644 --- a/src/ffi2/sliceobject.rs +++ b/src/ffi2/sliceobject.rs @@ -4,7 +4,6 @@ use std::os::raw::c_int; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")] static mut _Py_EllipsisObject: PyObject; } @@ -29,26 +28,22 @@ pub struct PySliceObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPySlice_Type")] pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPySlice_Check")] 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" { - #[cfg_attr(PyPy, link_name = "PyPySlice_New")] pub fn PySlice_New( start: *mut PyObject, stop: *mut PyObject, step: *mut PyObject, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndices")] pub fn PySlice_GetIndices( r: *mut PyObject, length: Py_ssize_t, @@ -56,7 +51,6 @@ extern "C" { stop: *mut Py_ssize_t, step: *mut Py_ssize_t, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPySlice_GetIndicesEx")] pub fn PySlice_GetIndicesEx( r: *mut PyObject, length: Py_ssize_t, diff --git a/src/ffi2/stringobject.rs b/src/ffi2/stringobject.rs index af38518a77c..627ab3e7948 100644 --- a/src/ffi2/stringobject.rs +++ b/src/ffi2/stringobject.rs @@ -54,15 +54,10 @@ pub unsafe fn PyString_AS_STRING(op: *mut PyObject) -> *mut c_char { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyString_FromString")] pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_FromStringAndSize")] pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_FromFormat")] pub fn PyString_FromFormat(format: *const c_char, ...) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_Size")] pub fn PyString_Size(string: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyString_AsString")] pub fn PyString_AsString(string: *mut PyObject) -> *mut c_char; pub fn PyString_AsStringAndSize( obj: *mut PyObject, @@ -81,7 +76,6 @@ extern "C" { encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_AsDecodedObject")] pub fn PyString_AsDecodedObject( str: *mut PyObject, encoding: *const c_char, @@ -93,7 +87,6 @@ extern "C" { encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyString_AsEncodedObject")] pub fn PyString_AsEncodedObject( str: *mut PyObject, encoding: *const c_char, diff --git a/src/ffi2/traceback.rs b/src/ffi2/traceback.rs index 31379dc166c..84522426e6b 100644 --- a/src/ffi2/traceback.rs +++ b/src/ffi2/traceback.rs @@ -20,17 +20,13 @@ pub struct PyTracebackObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Here")] pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Print")] pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyTraceBack_Type")] pub static mut PyTraceBack_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyTraceBack_Check")] pub unsafe fn PyTraceBack_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTraceBack_Type) as c_int } diff --git a/src/ffi2/tupleobject.rs b/src/ffi2/tupleobject.rs index 7264d241f8e..f1660496545 100644 --- a/src/ffi2/tupleobject.rs +++ b/src/ffi2/tupleobject.rs @@ -17,7 +17,6 @@ pub struct PyTupleObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyTuple_Type")] pub static mut PyTuple_Type: PyTypeObject; } @@ -58,17 +57,11 @@ pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObjec #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyTuple_Size")] pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyTuple_GetItem")] pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyTuple_SetItem")] pub fn PyTuple_SetItem(p: *mut PyObject, pos: Py_ssize_t, o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyTuple_GetSlice")] pub fn PyTuple_GetSlice(p: *mut PyObject, low: Py_ssize_t, high: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "_PyPyTuple_Resize")] pub fn _PyTuple_Resize(p: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyTuple_Pack")] pub fn PyTuple_Pack(n: Py_ssize_t, ...) -> *mut PyObject; //pub fn _PyTuple_MaybeUntrack(arg1: *mut PyObject); pub fn PyTuple_ClearFreeList() -> c_int; diff --git a/src/ffi2/unicodeobject.rs b/src/ffi2/unicodeobject.rs index f8d15263610..8789a68e27e 100644 --- a/src/ffi2/unicodeobject.rs +++ b/src/ffi2/unicodeobject.rs @@ -32,18 +32,15 @@ pub struct PyUnicodeObject { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Type")] pub static mut PyUnicode_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_Check")] pub unsafe fn PyUnicode_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_CheckExact")] pub unsafe fn PyUnicode_CheckExact(op: *mut PyObject) -> c_int { let u: *mut PyTypeObject = &mut PyUnicode_Type; (Py_TYPE(op) == u) as c_int @@ -75,26 +72,18 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER: Py_UNICODE = 0xFFFD; #[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] fn PyUnicodeUCS4_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS4_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS4_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] fn PyUnicodeUCS4_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] fn PyUnicodeUCS4_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] fn PyUnicodeUCS4_FromEncodedObject( obj: *mut PyObject, encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] 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; @@ -104,24 +93,19 @@ extern "C" { format_spec_len: Py_ssize_t, ) -> *mut PyObject; fn PyUnicodeUCS4_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] fn PyUnicodeUCS4_AsWideChar( unicode: *mut PyUnicodeObject, w: *mut wchar_t, size: Py_ssize_t, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS4_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS4_ClearFreelist() -> c_int; - #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] fn _PyUnicodeUCS4_AsDefaultEncodedString( arg1: *mut PyObject, arg2: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS4_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS4_SetDefaultEncoding(encoding: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] fn PyUnicodeUCS4_Decode( s: *const c_char, size: Py_ssize_t, @@ -134,20 +118,17 @@ extern "C" { encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] fn PyUnicodeUCS4_AsEncodedObject( unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] fn PyUnicodeUCS4_AsEncodedString( unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; fn PyUnicode_BuildEncodingMap(string: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] fn PyUnicode_DecodeUTF7( string: *const c_char, length: Py_ssize_t, @@ -166,7 +147,6 @@ extern "C" { base64WhiteSpace: c_int, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] fn PyUnicodeUCS4_DecodeUTF8( string: *const c_char, length: Py_ssize_t, @@ -178,15 +158,12 @@ extern "C" { errors: *const c_char, consumed: *mut Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS4_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] fn PyUnicodeUCS4_EncodeUTF8( data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] fn PyUnicodeUCS4_DecodeUTF32( string: *const c_char, length: Py_ssize_t, @@ -200,7 +177,6 @@ extern "C" { byteorder: *mut c_int, consumed: *mut Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] fn PyUnicodeUCS4_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUTF32( data: *const Py_UNICODE, @@ -208,7 +184,6 @@ extern "C" { errors: *const c_char, byteorder: c_int, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] fn PyUnicodeUCS4_DecodeUTF16( string: *const c_char, length: Py_ssize_t, @@ -222,7 +197,6 @@ extern "C" { byteorder: *mut c_int, consumed: *mut Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] fn PyUnicodeUCS4_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUTF16( data: *const Py_UNICODE, @@ -235,7 +209,6 @@ extern "C" { length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] fn PyUnicodeUCS4_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS4_EncodeUnicodeEscape( data: *const Py_UNICODE, @@ -256,29 +229,23 @@ extern "C" { length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] fn PyUnicodeUCS4_DecodeLatin1( string: *const c_char, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS4_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] fn PyUnicodeUCS4_EncodeLatin1( data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] fn PyUnicodeUCS4_DecodeASCII( string: *const c_char, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS4_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] fn PyUnicodeUCS4_EncodeASCII( data: *const Py_UNICODE, length: Py_ssize_t, @@ -306,22 +273,18 @@ extern "C" { table: *mut PyObject, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] fn PyUnicodeUCS4_EncodeDecimal( s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] fn PyUnicodeUCS4_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] fn PyUnicodeUCS4_Split( s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] 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; @@ -335,9 +298,7 @@ extern "C" { table: *mut PyObject, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] fn PyUnicodeUCS4_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] fn PyUnicodeUCS4_Tailmatch( str: *mut PyObject, substr: *mut PyObject, @@ -345,7 +306,6 @@ extern "C" { end: Py_ssize_t, direction: c_int, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] fn PyUnicodeUCS4_Find( str: *mut PyObject, substr: *mut PyObject, @@ -353,28 +313,24 @@ extern "C" { end: Py_ssize_t, direction: c_int, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] fn PyUnicodeUCS4_Count( str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] fn PyUnicodeUCS4_Replace( str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] 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( @@ -403,26 +359,18 @@ extern "C" { #[cfg(not(py_sys_config = "Py_UNICODE_SIZE_4"))] #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromUnicode")] fn PyUnicodeUCS2_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] fn PyUnicodeUCS2_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromString")] fn PyUnicodeUCS2_FromString(u: *const c_char) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicode")] fn PyUnicodeUCS2_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE; fn PyUnicodeUCS2_GetSize(unicode: *mut PyObject) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetMax")] fn PyUnicodeUCS2_GetMax() -> Py_UNICODE; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Resize")] fn PyUnicodeUCS2_Resize(unicode: *mut *mut PyObject, length: Py_ssize_t) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] fn PyUnicodeUCS2_FromEncodedObject( obj: *mut PyObject, encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromObject")] 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; @@ -432,24 +380,19 @@ extern "C" { format_spec_len: Py_ssize_t, ) -> *mut PyObject; fn PyUnicodeUCS2_FromWideChar(w: *const wchar_t, size: Py_ssize_t) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsWideChar")] fn PyUnicodeUCS2_AsWideChar( unicode: *mut PyUnicodeObject, w: *mut wchar_t, size: Py_ssize_t, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_FromOrdinal")] fn PyUnicodeUCS2_FromOrdinal(ordinal: c_int) -> *mut PyObject; fn PyUnicodeUCS2_ClearFreelist() -> c_int; - #[cfg_attr(PyPy, link_name = "_PyPyUnicode_AsDefaultEncodedString")] fn _PyUnicodeUCS2_AsDefaultEncodedString( arg1: *mut PyObject, arg2: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] fn PyUnicodeUCS2_GetDefaultEncoding() -> *const c_char; fn PyUnicodeUCS2_SetDefaultEncoding(encoding: *const c_char) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Decode")] fn PyUnicodeUCS2_Decode( s: *const c_char, size: Py_ssize_t, @@ -462,13 +405,11 @@ extern "C" { encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedObject")] fn PyUnicodeUCS2_AsEncodedObject( unicode: *mut PyObject, encoding: *const c_char, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsEncodedString")] fn PyUnicodeUCS2_AsEncodedString( unicode: *mut PyObject, encoding: *const c_char, @@ -493,7 +434,6 @@ extern "C" { base64WhiteSpace: c_int, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF8")] fn PyUnicodeUCS2_DecodeUTF8( string: *const c_char, length: Py_ssize_t, @@ -505,15 +445,12 @@ extern "C" { errors: *const c_char, consumed: *mut Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] fn PyUnicodeUCS2_AsUTF8String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeUTF8")] fn PyUnicodeUCS2_EncodeUTF8( data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF32")] fn PyUnicodeUCS2_DecodeUTF32( string: *const c_char, length: Py_ssize_t, @@ -527,7 +464,6 @@ extern "C" { byteorder: *mut c_int, consumed: *mut Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF32String")] fn PyUnicodeUCS2_AsUTF32String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUTF32( data: *const Py_UNICODE, @@ -535,7 +471,6 @@ extern "C" { errors: *const c_char, byteorder: c_int, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeUTF16")] fn PyUnicodeUCS2_DecodeUTF16( string: *const c_char, length: Py_ssize_t, @@ -549,7 +484,6 @@ extern "C" { byteorder: *mut c_int, consumed: *mut Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF16String")] fn PyUnicodeUCS2_AsUTF16String(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUTF16( data: *const Py_UNICODE, @@ -562,7 +496,6 @@ extern "C" { length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUnicodeEscapeString")] fn PyUnicodeUCS2_AsUnicodeEscapeString(unicode: *mut PyObject) -> *mut PyObject; fn PyUnicodeUCS2_EncodeUnicodeEscape( data: *const Py_UNICODE, @@ -583,29 +516,23 @@ extern "C" { length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeLatin1")] fn PyUnicodeUCS2_DecodeLatin1( string: *const c_char, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsLatin1String")] fn PyUnicodeUCS2_AsLatin1String(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeLatin1")] fn PyUnicodeUCS2_EncodeLatin1( data: *const Py_UNICODE, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_DecodeASCII")] fn PyUnicodeUCS2_DecodeASCII( string: *const c_char, length: Py_ssize_t, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsASCIIString")] fn PyUnicodeUCS2_AsASCIIString(unicode: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeASCII")] fn PyUnicodeUCS2_EncodeASCII( data: *const Py_UNICODE, length: Py_ssize_t, @@ -633,22 +560,18 @@ extern "C" { table: *mut PyObject, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_EncodeDecimal")] fn PyUnicodeUCS2_EncodeDecimal( s: *mut Py_UNICODE, length: Py_ssize_t, output: *mut c_char, errors: *const c_char, ) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Concat")] fn PyUnicodeUCS2_Concat(left: *mut PyObject, right: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Split")] fn PyUnicodeUCS2_Split( s: *mut PyObject, sep: *mut PyObject, maxsplit: Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Splitlines")] 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; @@ -662,9 +585,7 @@ extern "C" { table: *mut PyObject, errors: *const c_char, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Join")] fn PyUnicodeUCS2_Join(separator: *mut PyObject, seq: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Tailmatch")] fn PyUnicodeUCS2_Tailmatch( str: *mut PyObject, substr: *mut PyObject, @@ -672,7 +593,6 @@ extern "C" { end: Py_ssize_t, direction: c_int, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Find")] fn PyUnicodeUCS2_Find( str: *mut PyObject, substr: *mut PyObject, @@ -680,28 +600,24 @@ extern "C" { end: Py_ssize_t, direction: c_int, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Count")] fn PyUnicodeUCS2_Count( str: *mut PyObject, substr: *mut PyObject, start: Py_ssize_t, end: Py_ssize_t, ) -> Py_ssize_t; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Replace")] fn PyUnicodeUCS2_Replace( str: *mut PyObject, substr: *mut PyObject, replstr: *mut PyObject, maxcount: Py_ssize_t, ) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Compare")] 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; - #[cfg_attr(PyPy, link_name = "PyPyUnicode_Format")] 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( @@ -726,22 +642,20 @@ extern "C" { fn _PyUnicodeUCS2_IsAlpha(ch: Py_UNICODE) -> c_int; } -#[inline(always)] +#[inline] #[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromStringAndSize")] pub unsafe fn PyUnicode_FromStringAndSize(u: *const c_char, size: Py_ssize_t) -> *mut PyObject { PyUnicodeUCS4_FromStringAndSize(u, size) } -#[inline(always)] +#[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(always)] +#[inline] #[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8String")] pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { PyUnicodeUCS4_AsUTF8String(u) } @@ -754,7 +668,6 @@ pub unsafe fn PyUnicode_AsUTF8String(u: *mut PyObject) -> *mut PyObject { #[inline] #[cfg(py_sys_config = "Py_UNICODE_SIZE_4")] -#[cfg_attr(PyPy, link_name = "PyPyUnicode_FromEncodedObject")] pub unsafe fn PyUnicode_FromEncodedObject( obj: *mut PyObject, encoding: *const c_char, diff --git a/src/ffi2/warnings.rs b/src/ffi2/warnings.rs index 1a9777175e6..8573331b703 100644 --- a/src/ffi2/warnings.rs +++ b/src/ffi2/warnings.rs @@ -4,7 +4,6 @@ use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyErr_WarnEx")] pub fn PyErr_WarnEx( category: *mut PyObject, msg: *const c_char, @@ -21,7 +20,6 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyErr_Warn")] pub unsafe fn PyErr_Warn(category: *mut PyObject, msg: *const c_char) -> c_int { PyErr_WarnEx(category, msg, 1) } diff --git a/src/ffi2/weakrefobject.rs b/src/ffi2/weakrefobject.rs index 3ea116b55f6..943efd93fef 100644 --- a/src/ffi2/weakrefobject.rs +++ b/src/ffi2/weakrefobject.rs @@ -26,19 +26,16 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRef")] pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut _PyWeakref_RefType) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckRefExact")] pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut _PyWeakref_RefType) as c_int } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_CheckProxy")] 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 @@ -51,11 +48,8 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")] pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")] pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")] pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject; pub fn _PyWeakref_GetWeakrefCount(head: *mut PyWeakReference) -> Py_ssize_t; @@ -63,7 +57,6 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyWeakref_GET_OBJECT")] pub unsafe fn PyWeakref_GET_OBJECT(_ref: *mut PyObject) -> *mut PyObject { let obj = (*(_ref as *mut PyWeakReference)).wr_object; if Py_REFCNT(obj) > 0 { From cc3da82dcda5a2d643aa2b6519d8178532336e9f Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 15:58:42 +0200 Subject: [PATCH 054/138] revert weird formatting changes --- src/class/basic.rs | 88 +++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/class/basic.rs b/src/class/basic.rs index eb6ea6bc1f2..95208d646b9 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -37,79 +37,79 @@ pub enum CompareOp { #[allow(unused_variables)] pub trait PyObjectProtocol<'p>: PyTypeInfo { fn __getattr__(&'p self, name: Self::Name) -> Self::Result - where - Self: PyObjectGetAttrProtocol<'p>, + where + Self: PyObjectGetAttrProtocol<'p>, { unimplemented!() } fn __setattr__(&'p mut self, name: Self::Name, value: Self::Value) -> Self::Result - where - Self: PyObjectSetAttrProtocol<'p>, + where + Self: PyObjectSetAttrProtocol<'p>, { unimplemented!() } fn __delattr__(&'p mut self, name: Self::Name) -> Self::Result - where - Self: PyObjectDelAttrProtocol<'p>, + where + Self: PyObjectDelAttrProtocol<'p>, { unimplemented!() } fn __str__(&'p self) -> Self::Result - where - Self: PyObjectStrProtocol<'p>, + where + Self: PyObjectStrProtocol<'p>, { unimplemented!() } fn __repr__(&'p self) -> Self::Result - where - Self: PyObjectReprProtocol<'p>, + where + Self: PyObjectReprProtocol<'p>, { unimplemented!() } fn __format__(&'p self, format_spec: Self::Format) -> Self::Result - where - Self: PyObjectFormatProtocol<'p>, + where + Self: PyObjectFormatProtocol<'p>, { unimplemented!() } fn __hash__(&'p self) -> Self::Result - where - Self: PyObjectHashProtocol<'p>, + where + Self: PyObjectHashProtocol<'p>, { unimplemented!() } fn __bool__(&'p self) -> Self::Result - where - Self: PyObjectBoolProtocol<'p>, + where + Self: PyObjectBoolProtocol<'p>, { unimplemented!() } fn __bytes__(&'p self) -> Self::Result - where - Self: PyObjectBytesProtocol<'p>, + where + Self: PyObjectBytesProtocol<'p>, { unimplemented!() } /// This method is used by Python2 only. fn __unicode__(&'p self) -> Self::Result - where - Self: PyObjectUnicodeProtocol<'p>, + where + Self: PyObjectUnicodeProtocol<'p>, { unimplemented!() } fn __richcmp__(&'p self, other: Self::Other, op: CompareOp) -> Self::Result - where - Self: PyObjectRichcmpProtocol<'p>, + where + Self: PyObjectRichcmpProtocol<'p>, { unimplemented!() } @@ -176,8 +176,8 @@ pub trait PyObjectProtocolImpl { impl PyObjectProtocolImpl for T {} impl<'p, T> PyObjectProtocolImpl for T - where - T: PyObjectProtocol<'p>, +where + T: PyObjectProtocol<'p>, { fn methods() -> Vec { let mut methods = Vec::new(); @@ -215,8 +215,8 @@ trait GetAttrProtocolImpl { impl<'p, T> GetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl GetAttrProtocolImpl for T - where - T: for<'p> PyObjectGetAttrProtocol<'p>, +where + T: for<'p> PyObjectGetAttrProtocol<'p>, { fn tp_getattro() -> Option { py_binary_func!( @@ -263,8 +263,8 @@ mod tp_setattro_impl { impl<'p, T: PyObjectProtocol<'p>> SetAttr for T {} impl SetAttr for T - where - T: for<'p> PyObjectSetAttrProtocol<'p>, + where + T: for<'p> PyObjectSetAttrProtocol<'p>, { fn set_attr() -> Option { py_func_set!(PyObjectSetAttrProtocol, T, __setattr__) @@ -280,8 +280,8 @@ mod tp_setattro_impl { impl<'p, T> DelAttr for T where T: PyObjectProtocol<'p> {} impl DelAttr for T - where - T: for<'p> PyObjectDelAttrProtocol<'p>, + where + T: for<'p> PyObjectDelAttrProtocol<'p>, { fn del_attr() -> Option { py_func_del!(PyObjectDelAttrProtocol, T, __delattr__) @@ -297,8 +297,8 @@ mod tp_setattro_impl { impl<'p, T> SetDelAttr for T where T: PyObjectProtocol<'p> {} impl SetDelAttr for T - where - T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, + where + T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, { fn set_del_attr() -> Option { py_func_set_del!( @@ -319,8 +319,8 @@ trait StrProtocolImpl { } impl<'p, T> StrProtocolImpl for T where T: PyObjectProtocol<'p> {} impl StrProtocolImpl for T - where - T: for<'p> PyObjectStrProtocol<'p>, +where + T: for<'p> PyObjectStrProtocol<'p>, { fn tp_str() -> Option { py_unary_func!( @@ -339,8 +339,8 @@ trait ReprProtocolImpl { } impl<'p, T> ReprProtocolImpl for T where T: PyObjectProtocol<'p> {} impl ReprProtocolImpl for T - where - T: for<'p> PyObjectReprProtocol<'p>, +where + T: for<'p> PyObjectReprProtocol<'p>, { fn tp_repr() -> Option { py_unary_func!( @@ -383,8 +383,8 @@ trait HashProtocolImpl { } impl<'p, T> HashProtocolImpl for T where T: PyObjectProtocol<'p> {} impl HashProtocolImpl for T - where - T: for<'p> PyObjectHashProtocol<'p>, +where + T: for<'p> PyObjectHashProtocol<'p>, { fn tp_hash() -> Option { py_unary_func!( @@ -404,8 +404,8 @@ trait BoolProtocolImpl { } impl<'p, T> BoolProtocolImpl for T where T: PyObjectProtocol<'p> {} impl BoolProtocolImpl for T - where - T: for<'p> PyObjectBoolProtocol<'p>, +where + T: for<'p> PyObjectBoolProtocol<'p>, { fn nb_bool() -> Option { py_unary_func!( @@ -425,8 +425,8 @@ trait RichcmpProtocolImpl { } impl<'p, T> RichcmpProtocolImpl for T where T: PyObjectProtocol<'p> {} impl RichcmpProtocolImpl for T - where - T: for<'p> PyObjectRichcmpProtocol<'p>, +where + T: for<'p> PyObjectRichcmpProtocol<'p>, { fn tp_richcompare() -> Option { unsafe extern "C" fn wrap( @@ -434,8 +434,8 @@ impl RichcmpProtocolImpl for T arg: *mut ffi::PyObject, op: c_int, ) -> *mut ffi::PyObject - where - T: for<'p> PyObjectRichcmpProtocol<'p>, + where + T: for<'p> PyObjectRichcmpProtocol<'p>, { let _pool = crate::GILPool::new(); let py = Python::assume_gil_acquired(); From 0960f58ee427cc854606b6517efdb9dab175c218 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 16:00:39 +0200 Subject: [PATCH 055/138] bring back missing feature --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f71a2596f43..0096f4924c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ indoc = "0.3.1" default = [] # Use this feature when building python2 binding. -#python2 = [] +python2 = [] # Use this feature when building python3 binding. python3 = [] From 547d5bd999c06c4b49ea7d6c2b834070df33815c Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 16:02:00 +0200 Subject: [PATCH 056/138] tiny error --- pyo3build/src/py_interpreter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 15dd2554f30..ab50231df88 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -304,7 +304,7 @@ print(sys.exec_prefix) if self.enable_shared { Ok(format!( "cargo:rustc-link-lib=python{}", - interpreter_config.ld_version + self.ld_version )) } else { Ok(format!( From ad0be3ab80c2952335899d90a57239238f3b3f38 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 16:27:25 +0200 Subject: [PATCH 057/138] fix py3.7 issue --- src/gil.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gil.rs b/src/gil.rs index 3a9d3c1d511..efa8908a8e9 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -57,6 +57,7 @@ pub fn prepare_freethreaded_python() { // PyPy does not support the embedding API #[cfg(not(PyPy))] ffi::Py_InitializeEx(0); + #[cfg(not(Py_3_7))] ffi::PyEval_InitThreads(); // PyEval_InitThreads() will acquire the GIL, // but we don't want to hold it at this point From 5c9858525d195aab3320aa01f947dd559ad99755 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 16:28:40 +0200 Subject: [PATCH 058/138] add pypy3.5 6.0 to travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9b10699e081..6af3dca0f01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,9 @@ matrix: python: "3.7" # Keep this synced up with build.rs env: FEATURES=python3 TRAVIS_RUST_VERSION=nightly-2019-02-07 + - name: PyPy3.5 6.0 + python: "pypy3.5-6.0" + env: FEATURES=python3 allow_failures: - python: "3.8-dev" env: FEATURES=python3 From 3333285bd0669036fd317c5a68e8252b12d78266 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 9 Mar 2019 16:44:36 +0200 Subject: [PATCH 059/138] remove dbg! --- pyo3build/src/py_interpreter.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index ab50231df88..8485748eba6 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -456,12 +456,9 @@ pub fn find_interpreter(expected_version: &PythonVersion) -> Result Date: Sat, 9 Mar 2019 17:57:44 +0200 Subject: [PATCH 060/138] another tiny fix --- src/ffi3/boolobject.rs | 2 +- src/ffi3/moduleobject.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ffi3/boolobject.rs b/src/ffi3/boolobject.rs index 9499a5f9bed..53751449a11 100644 --- a/src/ffi3/boolobject.rs +++ b/src/ffi3/boolobject.rs @@ -7,7 +7,7 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; // define Py_False ((PyObject *) &_Py_ZeroStruct) - #[cfg_attr(PyPy, link_name = "_PyPy_ZeroStruct")] + #[cfg_attr(PyPy, link_name = "_PyPy_FalseStruct")] static mut _Py_FalseStruct: PyLongObject; #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] static mut _Py_TrueStruct: PyLongObject; diff --git a/src/ffi3/moduleobject.rs b/src/ffi3/moduleobject.rs index e05d297de49..b6389f30e71 100644 --- a/src/ffi3/moduleobject.rs +++ b/src/ffi3/moduleobject.rs @@ -23,6 +23,7 @@ pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyModule_New")] pub fn PyModule_New(name: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")] pub fn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject; From fbf309e46b3f79679253f5a9b75fed29bb42dfb3 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 10:15:56 +0200 Subject: [PATCH 061/138] removed some useless annotations, and fixed inlines annotations --- src/ffi3/boolobject.rs | 1 - src/ffi3/bytesobject.rs | 2 +- src/ffi3/ceval.rs | 2 +- src/ffi3/floatobject.rs | 2 -- src/ffi3/memoryobject.rs | 1 - src/ffi3/methodobject.rs | 1 - src/ffi3/moduleobject.rs | 1 - src/ffi3/object.rs | 8 ++++---- 8 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/ffi3/boolobject.rs b/src/ffi3/boolobject.rs index 53751449a11..947d9ab0cf0 100644 --- a/src/ffi3/boolobject.rs +++ b/src/ffi3/boolobject.rs @@ -6,7 +6,6 @@ use std::os::raw::{c_int, c_long}; extern "C" { #[cfg_attr(PyPy, link_name = "PyPyBool_Type")] pub static mut PyBool_Type: PyTypeObject; - // define Py_False ((PyObject *) &_Py_ZeroStruct) #[cfg_attr(PyPy, link_name = "_PyPy_FalseStruct")] static mut _Py_FalseStruct: PyLongObject; #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] diff --git a/src/ffi3/bytesobject.rs b/src/ffi3/bytesobject.rs index b117be096b6..c91055af846 100644 --- a/src/ffi3/bytesobject.rs +++ b/src/ffi3/bytesobject.rs @@ -26,10 +26,10 @@ extern "C" { pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyBytes_FromObject")] pub fn PyBytes_FromObject(arg1: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormat")] #[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormatV")] //pub fn PyBytes_FromFormatV(arg1: *const c_char, arg2: va_list) // -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyBytes_FromFormat")] pub fn PyBytes_FromFormat(arg1: *const c_char, ...) -> *mut PyObject; #[cfg_attr(PyPy, link_name = "PyPyBytes_Size")] pub fn PyBytes_Size(arg1: *mut PyObject) -> Py_ssize_t; diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 8e78df874be..4376c6807e6 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -52,7 +52,7 @@ extern "C" { static mut _Py_CheckRecursionLimit: c_int; } -#[cfg_attr(PyPy, link_name = "PyPy_EnterRecursiveCall")] +//#[cfg_attr(PyPy, link_name = "PyPy_EnterRecursiveCall")] // TODO: Py_EnterRecursiveCall etc. #[cfg(Py_3_6)] pub type _PyFrameEvalFunction = diff --git a/src/ffi3/floatobject.rs b/src/ffi3/floatobject.rs index 85135525082..70b6d1bd3c8 100644 --- a/src/ffi3/floatobject.rs +++ b/src/ffi3/floatobject.rs @@ -8,12 +8,10 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyFloat_Check")] pub unsafe fn PyFloat_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyFloat_Type) } -#[cfg_attr(PyPy, link_name = "PyPyFloat_CheckExact")] #[inline] pub unsafe fn PyFloat_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFloat_Type) as c_int diff --git a/src/ffi3/memoryobject.rs b/src/ffi3/memoryobject.rs index 49ad24b54d0..e4879128131 100644 --- a/src/ffi3/memoryobject.rs +++ b/src/ffi3/memoryobject.rs @@ -9,7 +9,6 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyMemoryView_Check")] pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyMemoryView_Type) as c_int } diff --git a/src/ffi3/methodobject.rs b/src/ffi3/methodobject.rs index b7a0a194ced..2a949ff2010 100644 --- a/src/ffi3/methodobject.rs +++ b/src/ffi3/methodobject.rs @@ -8,7 +8,6 @@ extern "C" { pub static mut PyCFunction_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyCFunction_Check")] pub unsafe fn PyCFunction_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCFunction_Type) as c_int } diff --git a/src/ffi3/moduleobject.rs b/src/ffi3/moduleobject.rs index b6389f30e71..f1f4988785d 100644 --- a/src/ffi3/moduleobject.rs +++ b/src/ffi3/moduleobject.rs @@ -10,7 +10,6 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyModule_Check")] pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyModule_Type) } diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 1a17f80ddfd..e47510b5bfa 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -634,7 +634,7 @@ pub struct PyType_Slot { impl Default for PyType_Slot { fn default() -> PyType_Slot { - unsafe { ::std::mem::zeroed() } + unsafe { mem::zeroed() } } } @@ -850,7 +850,7 @@ pub unsafe fn PyType_HasFeature(t: *mut PyTypeObject, f: c_ulong) -> c_int { (((*t).tp_flags & f) != 0) as c_int } -#[inline(always)] +#[inline] pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_ulong) -> c_int { PyType_HasFeature(t, f) } @@ -865,7 +865,6 @@ extern "C" { #[inline] pub unsafe fn Py_INCREF(op: *mut PyObject) { if cfg!(py_sys_config = "Py_REF_DEBUG") { - #[cfg_attr(PyPy, link_name = "PyPy_IncRef")] Py_IncRef(op) } else { (*op).ob_refcnt += 1 @@ -875,7 +874,6 @@ pub unsafe fn Py_INCREF(op: *mut PyObject) { #[inline] pub unsafe fn Py_DECREF(op: *mut PyObject) { if cfg!(py_sys_config = "Py_REF_DEBUG") { - #[cfg_attr(PyPy, link_name = "PyPy_DecRef")] Py_DecRef(op) } else { (*op).ob_refcnt -= 1; @@ -910,7 +908,9 @@ pub unsafe fn Py_XDECREF(op: *mut PyObject) { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name = "PyPy_IncRef")] pub fn Py_IncRef(o: *mut PyObject); + #[cfg_attr(PyPy, link_name = "PyPy_DecRef")] pub fn Py_DecRef(o: *mut PyObject); #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] From 4c97d9f3dce57f7dabb76f1ba86e2adc18f74176 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 10:18:36 +0200 Subject: [PATCH 062/138] removed `pretty_assertions` --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fff5b8eaba..141bde132bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,12 +26,12 @@ pyo3cls = { path = "pyo3cls", version = "=0.6.0-alpha.4" } mashup = "0.1.9" num-complex = { version = "0.2.1", optional = true } inventory = "0.1.3" -pretty_assertions = "0.5.1" + [build-dependencies] version_check = "0.1.5" regex = "1.1.0" pyo3-build-utils = {version = "*", path="pyo3build"} -pretty_assertions = "0.5.1" + [dev-dependencies] assert_approx_eq = "1.1.0" docmatic = "0.1.2" From 623eaf97148556f74f448b840714b49ce46ac324 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 10:33:23 +0200 Subject: [PATCH 063/138] removed pypy feature from cargo.toml --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 141bde132bf..bbff46db7ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,8 +45,6 @@ python2 = [] # Use this feature when building python3 binding. python3 = [] -# Use this feature when building pypy binding. -pypy = [] # Use this feature when building an extension module. # It tells the linker to keep the python symbols unresolved, # so that the module can also be used with statically linked python interpreters. From b6d8abdbd96f518f0d257edbbd2a53d38ccba9c2 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 10:34:02 +0200 Subject: [PATCH 064/138] fix for Py_CompileStringFlags --- src/ffi3/pythonrun.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index be4f8e86bfc..de0a75207f9 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -164,6 +164,14 @@ extern "C" { ) -> *mut PyObject; #[cfg(Py_LIMITED_API)] pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject; + #[cfg(PyPy)] + #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] + pub fn Py_CompileStringFlags( + string: *const c_char, + p: *const c_char, + s: c_int, + f: *mut PyCompilerFlags, + ) -> *mut PyObject; } #[cfg(not(Py_LIMITED_API))] #[inline] @@ -172,7 +180,7 @@ pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int } #[cfg(not(Py_LIMITED_API))] #[inline] -#[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] +#[cfg(not(PyPy))] pub unsafe fn Py_CompileStringFlags( string: *const c_char, p: *const c_char, @@ -181,9 +189,11 @@ pub unsafe fn Py_CompileStringFlags( ) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, f, -1) } + #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { #[cfg(not(Py_LIMITED_API))] + #[cfg(not(PyPy))] pub fn Py_CompileStringExFlags( str: *const c_char, filename: *const c_char, From 51cdfd23dee2a8b71dcf4557e4dbb0c2cdf25230 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 11:13:26 +0200 Subject: [PATCH 065/138] tox runs word_count! --- .travis.yml | 2 +- ci/travis/test.sh | 7 ++++++- examples/word-count/tox.ini | 1 + src/ffi3/object.rs | 1 - src/ffi3/pythonrun.rs | 15 ++++++--------- src/gil.rs | 1 + 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index afc24a151ea..824e354c6f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ matrix: env: FEATURES=python3 TRAVIS_RUST_VERSION=nightly-2019-02-07 - name: PyPy3.5 6.0 python: "pypy3.5-6.0" - env: FEATURES=python3 + env: FEATURES="python3 pypy" allow_failures: - python: "3.8-dev" env: FEATURES=python3 diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 51011e8c44b..11772e90f9e 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -2,7 +2,12 @@ set -ex cargo clean -cargo test --features "$FEATURES num-complex" + +# run `cargo test` only if testing against cpython. +if ![[ $FEATURES == *"pypy"* ]]; then + cargo test --features "$FEATURES num-complex" +fi + if [ $TRAVIS_JOB_NAME = 'Minimum nightly' ]; then cargo fmt --all -- --check cargo clippy --features "$FEATURES num-complex" diff --git a/examples/word-count/tox.ini b/examples/word-count/tox.ini index a0e0974e66f..e09e1444a10 100644 --- a/examples/word-count/tox.ini +++ b/examples/word-count/tox.ini @@ -3,6 +3,7 @@ envlist = py27, py35, py36, py37, + pypy35 minversion = 3.4.0 skip_missing_interpreters = true diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index b14e82ad03a..a017ffc6cdf 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -858,7 +858,6 @@ pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_ulong) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { - #[cfg_attr(PyPy, link_name = "_PyPy_Dealloc")] pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index de0a75207f9..c6c629ebd81 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -163,6 +163,7 @@ extern "C" { flags: *mut PyCompilerFlags, ) -> *mut PyObject; #[cfg(Py_LIMITED_API)] + #[cfg(not(PyPy))] pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject; #[cfg(PyPy)] #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] @@ -175,19 +176,15 @@ extern "C" { } #[cfg(not(Py_LIMITED_API))] #[inline] +#[cfg(not(PyPy))] pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { Py_CompileStringExFlags(string, p, s, ptr::null_mut(), -1) } -#[cfg(not(Py_LIMITED_API))] + #[inline] -#[cfg(not(PyPy))] -pub unsafe fn Py_CompileStringFlags( - string: *const c_char, - p: *const c_char, - s: c_int, - f: *mut PyCompilerFlags, -) -> *mut PyObject { - Py_CompileStringExFlags(string, p, s, f, -1) +#[cfg(PyPy)] +pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { + Py_CompileStringFlags(string, p, s, ptr::null_mut()) } #[cfg_attr(windows, link(name = "pythonXY"))] diff --git a/src/gil.rs b/src/gil.rs index a447edfd7ab..df129c841c8 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -63,6 +63,7 @@ pub fn prepare_freethreaded_python() { // but we don't want to hold it at this point // (it's not acquired in the other code paths) // So immediately release the GIL: + #[cfg(not(PyPy))] let _thread_state = ffi::PyEval_SaveThread(); // Note that the PyThreadState returned by PyEval_SaveThread is also held in TLS by the Python runtime, // and will be restored by PyGILState_Ensure. From 5a2de19a813af048135ce8a90058c4091d3a35a8 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 11:14:58 +0200 Subject: [PATCH 066/138] __dict__ changes are not supported for PyPy --- src/ffi3/descrobject.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ffi3/descrobject.rs b/src/ffi3/descrobject.rs index 115fc6e7bfc..ce8f9d9e09f 100644 --- a/src/ffi3/descrobject.rs +++ b/src/ffi3/descrobject.rs @@ -29,6 +29,11 @@ pub const PyGetSetDef_INIT: PyGetSetDef = PyGetSetDef { closure: ptr::null_mut(), }; +#[cfg(PyPy)] +pub const PyGetSetDef_DICT: PyGetSetDef = PyGetSetDef_INIT; + +// PyPy doesn't export neither PyObject_GenericGetDict/PyObject_GenericSetDict +#[cfg(not(PyPy))] pub const PyGetSetDef_DICT: PyGetSetDef = PyGetSetDef { name: "__dict__\0".as_ptr() as *mut c_char, get: Some(PyObject_GenericGetDict), From 1b9c891073f95eb7dd9717b3def88e3d8bddce2e Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 11:46:44 +0200 Subject: [PATCH 067/138] fix 3.7 and copy comment --- src/gil.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gil.rs b/src/gil.rs index df129c841c8..0ca32063eb9 100644 --- a/src/gil.rs +++ b/src/gil.rs @@ -42,6 +42,7 @@ pub fn prepare_freethreaded_python() { if ffi::Py_IsInitialized() != 0 { // If Python is already initialized, we expect Python threading to also be initialized, // as we can't make the existing Python main thread acquire the GIL. + #[cfg(not(Py_3_7))] assert_ne!(ffi::PyEval_ThreadsInitialized(), 0); } else { // If Python isn't initialized yet, we expect that Python threading @@ -57,6 +58,9 @@ pub fn prepare_freethreaded_python() { // PyPy does not support the embedding API #[cfg(not(PyPy))] ffi::Py_InitializeEx(0); + + // > Changed in version 3.7: This function is now called by Py_Initialize(), so you don’t have + // > to call it yourself anymore. #[cfg(not(Py_3_7))] ffi::PyEval_InitThreads(); // PyEval_InitThreads() will acquire the GIL, From fd28250a25bfc3dd48bf25f9df5403092933b076 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 11:50:33 +0200 Subject: [PATCH 068/138] fix test script :flushed: --- ci/travis/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 11772e90f9e..d87edc2c055 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -4,7 +4,7 @@ set -ex cargo clean # run `cargo test` only if testing against cpython. -if ![[ $FEATURES == *"pypy"* ]]; then +if ! [[ $FEATURES == *"pypy"* ]]; then cargo test --features "$FEATURES num-complex" fi From fa5337b578200a627604e7f403a854bbd4010923 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 12:08:52 +0200 Subject: [PATCH 069/138] transfer ownership of strings to cpython when possible --- src/ffi3/object.rs | 2 +- src/ffi3/pyerrors.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index a017ffc6cdf..b31c1d38fbe 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -78,7 +78,7 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { return crate::ffi3::pyerrors::PyErr_Format( crate::ffi3::pyerrors::PyExc_TypeError, - cstr!("'%.200s' object is not iterable").as_ptr(), + CString::new("'%.200s' object is not iterable").unwrap().into_raw(), Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), ); } diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 91305366e9c..60f50e19e2f 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -87,7 +87,7 @@ pub unsafe fn PyUnicodeDecodeError_Create( ) -> *mut PyObject { return PyObject_CallFunction( PyExc_UnicodeDecodeError, - cstr!("sy#nns").as_ptr(), + CString::new("sy#nns").unwrap().into_raw(), encoding, object, length, From e38ef289b31cde801bffcc7fc79d68b4920d28c2 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 12:19:13 +0200 Subject: [PATCH 070/138] remove cstr! macro --- src/ffi3/object.rs | 2 +- src/ffi3/pyerrors.rs | 3 ++- src/lib.rs | 1 - src/macros.rs | 9 --------- 4 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 src/macros.rs diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index b31c1d38fbe..154bf5177a7 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -78,7 +78,7 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { return crate::ffi3::pyerrors::PyErr_Format( crate::ffi3::pyerrors::PyExc_TypeError, - CString::new("'%.200s' object is not iterable").unwrap().into_raw(), + CStr::from_bytes_with_nul("'%.200s' object is not iterable\0").unwrap().as_ptr(), Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), ); } diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 60f50e19e2f..5b1f8acabd6 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -2,6 +2,7 @@ use crate::ffi3::object::*; use crate::ffi3::objectabstract::PyObject_CallFunction; use crate::ffi3::pyport::Py_ssize_t; use std::os::raw::{c_char, c_int}; +use std::ffi::CStr; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { @@ -87,7 +88,7 @@ pub unsafe fn PyUnicodeDecodeError_Create( ) -> *mut PyObject { return PyObject_CallFunction( PyExc_UnicodeDecodeError, - CString::new("sy#nns").unwrap().into_raw(), + CStr::from_bytes_with_nul("sy#nns\0".as_bytes()).unwrap().as_ptr(), encoding, object, length, diff --git a/src/lib.rs b/src/lib.rs index cac1b04c875..6c41745b579 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,7 +118,6 @@ //! } //! ``` -#[macro_use] mod macros; pub use crate::class::*; pub use crate::conversion::{ AsPyPointer, FromPy, FromPyObject, IntoPy, IntoPyObject, IntoPyPointer, PyTryFrom, PyTryInto, diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index a55ce5a032c..00000000000 --- a/src/macros.rs +++ /dev/null @@ -1,9 +0,0 @@ - -#[macro_export] -/// Constructs a `&'static CStr` literal. -macro_rules! cstr { - ($s: tt) => { - // TODO: verify that $s is a string literal without nuls - unsafe { ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) } - }; -} From 45366e99fa7d560465767f2c01eb2d83fdbc1b23 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 12:26:52 +0200 Subject: [PATCH 071/138] added missing nuls --- src/buffer.rs | 2 +- src/exceptions.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index b40228ed27f..252c611e5d7 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -279,7 +279,7 @@ impl PyBuffer { #[inline] pub fn format(&self) -> &CStr { if self.0.format.is_null() { - CStr::from_bytes_with_nul("B".as_bytes()).unwrap() + CStr::from_bytes_with_nul("B\0".as_bytes()).unwrap() } else { unsafe { CStr::from_ptr(self.0.format) } } diff --git a/src/exceptions.rs b/src/exceptions.rs index 8faaac8b627..07ca87cade8 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -340,10 +340,10 @@ impl UnicodeDecodeError { let pos = err.valid_up_to(); UnicodeDecodeError::new_err( py, - CStr::from_bytes_with_nul("utf-8".as_bytes()).unwrap(), + CStr::from_bytes_with_nul("utf-8\0".as_bytes()).unwrap(), input, pos..pos + 1, - CStr::from_bytes_with_nul("invalid utf-8".as_bytes()).unwrap(), + CStr::from_bytes_with_nul("invalid utf-8\0".as_bytes()).unwrap(), ) } } From e232135b42b4f90b20e23588016ea532584119b0 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 12:28:41 +0200 Subject: [PATCH 072/138] =?UTF-8?q?as=5Fbytes()=20->=20b=E2=80=99=E2=80=99?= =?UTF-8?q?=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/buffer.rs | 2 +- src/exceptions.rs | 4 ++-- src/ffi3/object.rs | 3 ++- src/ffi3/pyerrors.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 252c611e5d7..4767d2beba3 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -279,7 +279,7 @@ impl PyBuffer { #[inline] pub fn format(&self) -> &CStr { if self.0.format.is_null() { - CStr::from_bytes_with_nul("B\0".as_bytes()).unwrap() + CStr::from_bytes_with_nul(b"B\0").unwrap() } else { unsafe { CStr::from_ptr(self.0.format) } } diff --git a/src/exceptions.rs b/src/exceptions.rs index 07ca87cade8..7e97233ed22 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -340,10 +340,10 @@ impl UnicodeDecodeError { let pos = err.valid_up_to(); UnicodeDecodeError::new_err( py, - CStr::from_bytes_with_nul("utf-8\0".as_bytes()).unwrap(), + CStr::from_bytes_with_nul(b"utf-8\0").unwrap(), input, pos..pos + 1, - CStr::from_bytes_with_nul("invalid utf-8\0".as_bytes()).unwrap(), + CStr::from_bytes_with_nul(b"invalid utf-8\0").unwrap(), ) } } diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 154bf5177a7..c641bb689cb 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -78,7 +78,7 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { return crate::ffi3::pyerrors::PyErr_Format( crate::ffi3::pyerrors::PyExc_TypeError, - CStr::from_bytes_with_nul("'%.200s' object is not iterable\0").unwrap().as_ptr(), + CStr::from_bytes_with_nul(b"'%.200s' object is not iterable\0").unwrap().as_ptr(), Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), ); } @@ -624,6 +624,7 @@ mod typeobject { // The exported types depend on whether Py_LIMITED_API is set pub use self::typeobject::*; +use std::ffi::CStr; #[repr(C)] #[derive(Copy, Clone)] diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index 5b1f8acabd6..c074b6d0bf4 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -88,7 +88,7 @@ pub unsafe fn PyUnicodeDecodeError_Create( ) -> *mut PyObject { return PyObject_CallFunction( PyExc_UnicodeDecodeError, - CStr::from_bytes_with_nul("sy#nns\0".as_bytes()).unwrap().as_ptr(), + CStr::from_bytes_with_nul(b"sy#nns\0").unwrap().as_ptr(), encoding, object, length, From bb67345ef64fe1bdda3dbc8623dd25f7732e4884 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 12:36:31 +0200 Subject: [PATCH 073/138] symbol removed by mistake --- src/ffi3/object.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index c641bb689cb..192bab9f8d0 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -859,6 +859,7 @@ pub unsafe fn PyType_FastSubclass(t: *mut PyTypeObject, f: c_ulong) -> c_int { #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPy_Dealloc")] pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } From 7fed8a2ffc5f51138c6ec7fee63339165284390b Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 15:17:34 +0200 Subject: [PATCH 074/138] properly shim pypy date time API, some tests are passing! --- src/ffi/datetime.rs | 77 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index 8785173173f..ea127872e79 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -27,12 +27,14 @@ pub struct PyDateTime_CAPI { #[cfg(Py_3_7)] pub TimeZone_UTC: *mut PyObject, + #[cfg_attr(PyPy, link_name = "_PyPyDate_FromDate")] pub Date_FromDate: unsafe extern "C" fn( year: c_int, month: c_int, day: c_int, cls: *mut PyTypeObject, ) -> *mut PyObject, + #[cfg_attr(PyPy, link_name = "_PyPyDateTime_FromDateAndTime")] pub DateTime_FromDateAndTime: unsafe extern "C" fn( year: c_int, month: c_int, @@ -44,6 +46,7 @@ pub struct PyDateTime_CAPI { tzinfo: *mut PyObject, cls: *mut PyTypeObject, ) -> *mut PyObject, + #[cfg_attr(PyPy, link_name = "_PyPyTime_FromTime")] pub Time_FromTime: unsafe extern "C" fn( hour: c_int, minute: c_int, @@ -52,6 +55,7 @@ pub struct PyDateTime_CAPI { tzinfo: *mut PyObject, cls: *mut PyTypeObject, ) -> *mut PyObject, + #[cfg_attr(PyPy, link_name = "_PyPyDelta_FromDelta")] pub Delta_FromDelta: unsafe extern "C" fn( days: c_int, seconds: c_int, @@ -62,11 +66,13 @@ pub struct PyDateTime_CAPI { #[cfg(Py_3_7)] pub TimeZone_FromTimeZone: unsafe extern "C" fn(offset: *mut PyObject, name: *mut PyObject) -> *mut PyObject, + #[cfg_attr(PyPy, link_name = "PyPyDateTime_FromTimestamp")] pub DateTime_FromTimestamp: unsafe extern "C" fn( cls: *mut PyTypeObject, args: *mut PyObject, kwargs: *mut PyObject, ) -> *mut PyObject, + #[cfg_attr(PyPy, link_name = "PyPyDate_FromTimestamp")] pub Date_FromTimestamp: unsafe extern "C" fn(cls: *mut PyTypeObject, args: *mut PyObject) -> *mut PyObject, #[cfg(Py_3_6)] @@ -147,6 +153,11 @@ pub struct PyDateTime_Delta { pub microseconds: c_int, } +#[cfg(PyPy)] +extern "C" { + pub fn _PyPyDateTime_Import() -> &'static PyDateTime_CAPI; +} + // C API Capsule // Note: This is "roll-your-own" lazy-static implementation is necessary because // of the interaction between the call_once locks and the GIL. It turns out that @@ -171,9 +182,11 @@ pub struct PyDateTime_Delta { static PY_DATETIME_API_ONCE: Once = Once::new(); static mut PY_DATETIME_API_UNSAFE_CACHE: *const PyDateTime_CAPI = ptr::null(); +#[derive(Debug)] pub struct PyDateTimeAPI { __private_field: (), } + pub static PyDateTimeAPI: PyDateTimeAPI = PyDateTimeAPI { __private_field: (), }; @@ -201,10 +214,18 @@ impl Deref for PyDateTimeAPI { /// such as if you do not want the first call to a datetime function to be /// slightly slower than subsequent calls. pub unsafe fn PyDateTime_IMPORT() -> &'static PyDateTime_CAPI { - // PyDateTime_CAPSULE_NAME is a macro in C - let PyDateTime_CAPSULE_NAME = CString::new("datetime.datetime_CAPI").unwrap(); - let capsule = PyCapsule_Import(PyDateTime_CAPSULE_NAME.as_ptr(), 1) as *const PyDateTime_CAPI; + // PyPy excepts the C-API to be initialized via PyDateTime_Import, so trying to use + // `PyCapsule_Import` will have not actually initialize the module. + let capsule = if cfg!(PyPy) { + _PyPyDateTime_Import() + } else { + // PyDateTime_CAPSULE_NAME is a macro in C + let PyDateTime_CAPSULE_NAME = CString::new("datetime.datetime_CAPI").unwrap(); + + PyCapsule_Import(PyDateTime_CAPSULE_NAME.as_ptr(), 1) as *const PyDateTime_CAPI + }; + PY_DATETIME_API_ONCE.call_once(move || { PY_DATETIME_API_UNSAFE_CACHE = capsule; @@ -286,8 +307,42 @@ macro_rules! _access_field { }; } +#[cfg(PyPy)] +extern "C" { + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_HOUR")] + pub fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MICROSECOND")] + pub fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MINUTE")] + pub fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_SECOND")] + pub fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_DAYS")] + pub fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_MICROSECONDS")] + pub fn PyDateTime_DELTA_GET_MICROSECONDS(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_SECONDS")] + pub fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_DAY")] + pub fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_MONTH")] + pub fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_YEAR")] + pub fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_HOUR")] + pub fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MICROSECOND")] + pub fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MINUTE")] + pub fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_SECOND")] + pub fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int; +} + + // Accessor functions for PyDateTime_Date and PyDateTime_DateTime #[inline] +#[cfg(not(PyPy))] /// Retrieve the year component of a `PyDateTime_Date` or `PyDateTime_DateTime`. /// Returns a signed integer greater than 0. pub unsafe fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int { @@ -297,6 +352,7 @@ pub unsafe fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the month component of a `PyDateTime_Date` or `PyDateTime_DateTime`. /// Returns a signed integer in the range `[1, 12]`. pub unsafe fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int { @@ -305,6 +361,7 @@ pub unsafe fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the day component of a `PyDateTime_Date` or `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[1, 31]`. pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int { @@ -354,6 +411,7 @@ macro_rules! _PyDateTime_GET_TZINFO { // Accessor functions for DateTime #[inline] +#[cfg(not(PyPy))] /// Retrieve the hour component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 23]` pub unsafe fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int { @@ -361,6 +419,7 @@ pub unsafe fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the minute component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 59]` pub unsafe fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int { @@ -368,6 +427,7 @@ pub unsafe fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the second component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 59]` pub unsafe fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int { @@ -375,6 +435,7 @@ pub unsafe fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the microsecond component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 999999]` pub unsafe fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int { @@ -383,6 +444,7 @@ pub unsafe fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int { #[cfg(Py_3_6)] #[inline] +#[cfg(not(PyPy))] /// Retrieve the fold component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 1]` /// @@ -392,6 +454,7 @@ pub unsafe fn PyDateTime_DATE_GET_FOLD(o: *mut PyObject) -> c_uchar { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the tzinfo component of a `PyDateTime_DateTime`. /// Returns a pointer to a `PyObject` that should be either NULL or an instance /// of a `datetime.tzinfo` subclass. @@ -401,6 +464,7 @@ pub unsafe fn PyDateTime_DATE_GET_TZINFO(o: *mut PyObject) -> *mut PyObject { // Accessor functions for Time #[inline] +#[cfg(not(PyPy))] /// Retrieve the hour component of a `PyDateTime_Time`. /// Returns a signed integer in the interval `[0, 23]` pub unsafe fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int { @@ -408,6 +472,7 @@ pub unsafe fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the minute component of a `PyDateTime_Time`. /// Returns a signed integer in the interval `[0, 59]` pub unsafe fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int { @@ -415,6 +480,7 @@ pub unsafe fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the second component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 59]` pub unsafe fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int { @@ -422,6 +488,7 @@ pub unsafe fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the microsecond component of a `PyDateTime_DateTime`. /// Returns a signed integer in the interval `[0, 999999]` pub unsafe fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int { @@ -439,6 +506,7 @@ pub unsafe fn PyDateTime_TIME_GET_FOLD(o: *mut PyObject) -> c_uchar { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the tzinfo component of a `PyDateTime_Time`. /// Returns a pointer to a `PyObject` that should be either NULL or an instance /// of a `datetime.tzinfo` subclass. @@ -454,6 +522,7 @@ macro_rules! _access_delta_field { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the days component of a `PyDateTime_Delta`. /// /// Returns a signed integer in the interval [-999999999, 999999999]. @@ -465,6 +534,7 @@ pub unsafe fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the seconds component of a `PyDateTime_Delta`. /// /// Returns a signed integer in the interval [0, 86399]. @@ -476,6 +546,7 @@ pub unsafe fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int { } #[inline] +#[cfg(not(PyPy))] /// Retrieve the seconds component of a `PyDateTime_Delta`. /// /// Returns a signed integer in the interval [0, 999999]. From 42d658270df8ead0ed33263242da85f4f392bae0 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 21:57:06 +0200 Subject: [PATCH 075/138] extension_module tests now not crashing! (some still skipped) --- examples/rustapi_module/setup.py | 4 + examples/rustapi_module/src/datetime.rs | 1 + examples/rustapi_module/src/lib.rs | 3 + examples/rustapi_module/src/othermod.rs | 2 + .../rustapi_module/tests/test_datetime.py | 11 +- .../rustapi_module/tests/test_dict_iter.py | 9 +- .../rustapi_module/tests/test_othermod.py | 8 ++ .../rustapi_module/tests/test_subclassing.py | 19 +++- examples/rustapi_module/tox.ini | 1 + src/ffi/datetime.rs | 101 ++++++++++-------- src/types/datetime.rs | 31 ++++-- 11 files changed, 128 insertions(+), 62 deletions(-) diff --git a/examples/rustapi_module/setup.py b/examples/rustapi_module/setup.py index 99baa66cab8..d76267779ea 100644 --- a/examples/rustapi_module/setup.py +++ b/examples/rustapi_module/setup.py @@ -1,4 +1,5 @@ import sys +import platform from setuptools import setup from setuptools.command.test import test as TestCommand @@ -29,6 +30,9 @@ def get_py_version_cfgs(): for minor in range(py3_min, version[1] + 1): out_cfg.append("--cfg=Py_3_%d" % minor) + if platform.python_implementation() == "PyPy": + out_cfg.append("--cfg=PyPy") + return out_cfg diff --git a/examples/rustapi_module/src/datetime.rs b/examples/rustapi_module/src/datetime.rs index e62ee882316..ce149b4d5f9 100644 --- a/examples/rustapi_module/src/datetime.rs +++ b/examples/rustapi_module/src/datetime.rs @@ -230,6 +230,7 @@ fn datetime(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(issue_219))?; + #[cfg(not(PyPy))] m.add_class::()?; Ok(()) } diff --git a/examples/rustapi_module/src/lib.rs b/examples/rustapi_module/src/lib.rs index be7fd6ed63c..d0434480182 100644 --- a/examples/rustapi_module/src/lib.rs +++ b/examples/rustapi_module/src/lib.rs @@ -1,4 +1,7 @@ pub mod datetime; + +#[cfg(not(PyPy))] pub mod dict_iter; pub mod othermod; +#[cfg(not(PyPy))] pub mod subclassing; diff --git a/examples/rustapi_module/src/othermod.rs b/examples/rustapi_module/src/othermod.rs index 34e65c6850b..e0c5055b99c 100644 --- a/examples/rustapi_module/src/othermod.rs +++ b/examples/rustapi_module/src/othermod.rs @@ -32,6 +32,8 @@ fn double(x: i32) -> i32 { #[pymodule] fn othermod(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(double))?; + + #[cfg(not(PyPy))] m.add_class::()?; m.add("USIZE_MIN", usize::min_value())?; diff --git a/examples/rustapi_module/tests/test_datetime.py b/examples/rustapi_module/tests/test_datetime.py index 8114a9250db..56472b0f431 100644 --- a/examples/rustapi_module/tests/test_datetime.py +++ b/examples/rustapi_module/tests/test_datetime.py @@ -1,5 +1,6 @@ import datetime as pdt import sys +import platform import pytest import rustapi_module.datetime as rdt @@ -44,6 +45,8 @@ def tzname(self, dt): MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6) MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6) + +PYPY = platform.python_implementation() == "PyPy" HAS_FOLD = getattr(pdt.datetime, "fold", False) # Helper functions @@ -80,7 +83,8 @@ def test_invalid_date_fails(): rdt.make_date(2017, 2, 30) -@given(d=dates()) +# Feeding this tests dates from too early will cause `get_timestamp` to raise. +@given(d=st.dates(min_value=pdt.date(1900, 1, 1))) def test_date_from_timestamp(d): ts = get_timestamp(pdt.datetime.combine(d, pdt.time(0))) assert rdt.date_from_timestamp(int(ts)) == pdt.date.fromtimestamp(ts) @@ -216,7 +220,8 @@ def test_datetime_typeerror(): rdt.make_datetime("2011", 1, 1, 0, 0, 0, 0) -@given(dt=datetimes()) +# Feeding this tests dates from too early will cause `get_timestamp` to raise. +@given(dt=st.datetimes(min_value=pdt.datetime(1900, 1, 1))) def test_datetime_from_timestamp(dt): ts = get_timestamp(dt) assert rdt.datetime_from_timestamp(ts) == pdt.datetime.fromtimestamp(ts) @@ -282,6 +287,7 @@ def test_issue_219(): rdt.issue_219() +@pytest.mark.xfail(PYPY, reason="add_class not properly working yet") def test_tz_class(): tzi = rdt.TzClass() @@ -292,6 +298,7 @@ def test_tz_class(): assert dt.dst() is None +@pytest.mark.xfail(PYPY, reason="add_class not properly working yet") def test_tz_class_introspection(): tzi = rdt.TzClass() diff --git a/examples/rustapi_module/tests/test_dict_iter.py b/examples/rustapi_module/tests/test_dict_iter.py index 98acc214fd7..a1b714f0b8e 100644 --- a/examples/rustapi_module/tests/test_dict_iter.py +++ b/examples/rustapi_module/tests/test_dict_iter.py @@ -1,7 +1,14 @@ -from rustapi_module.test_dict import DictSize +import platform + +PYPY = platform.python_implementation() == "PyPy" + +if not PYPY: + from rustapi_module.test_dict import DictSize + import pytest +@pytest.mark.xfail(PYPY, reason="classes not properly working yet") @pytest.mark.parametrize( "size", [64, 128, 256], diff --git a/examples/rustapi_module/tests/test_othermod.py b/examples/rustapi_module/tests/test_othermod.py index 8389076bd66..160a2441564 100644 --- a/examples/rustapi_module/tests/test_othermod.py +++ b/examples/rustapi_module/tests/test_othermod.py @@ -1,3 +1,6 @@ +import platform + +import pytest from hypothesis import given, assume from hypothesis import strategies as st from rustapi_module import othermod @@ -5,6 +8,8 @@ INTEGER32_ST = st.integers(min_value=(-(2 ** 31)), max_value=(2 ** 31 - 1)) USIZE_ST = st.integers(min_value=othermod.USIZE_MIN, max_value=othermod.USIZE_MAX) +PYPY = platform.python_implementation() == "PyPy" + @given(x=INTEGER32_ST) def test_double(x): @@ -13,6 +18,7 @@ def test_double(x): assert othermod.double(x) == expected +@pytest.mark.xfail(PYPY, reason="classes not properly working yet") def test_modclass(): # Test that the repr of the class itself doesn't crash anything repr(othermod.ModClass) @@ -20,6 +26,7 @@ def test_modclass(): assert isinstance(othermod.ModClass, type) +@pytest.mark.xfail(PYPY, reason="classes not properly working yet") def test_modclass_instance(): mi = othermod.ModClass() @@ -30,6 +37,7 @@ def test_modclass_instance(): assert isinstance(mi, object) +@pytest.mark.xfail(PYPY, reason="classes not properly working yet") @given(x=USIZE_ST) def test_modclas_noop(x): mi = othermod.ModClass() diff --git a/examples/rustapi_module/tests/test_subclassing.py b/examples/rustapi_module/tests/test_subclassing.py index 8c086b75dec..508e74e546c 100644 --- a/examples/rustapi_module/tests/test_subclassing.py +++ b/examples/rustapi_module/tests/test_subclassing.py @@ -1,9 +1,18 @@ -from rustapi_module.subclassing import Subclassable +import platform +import pytest -class SomeSubClass(Subclassable): - pass +PYPY = platform.python_implementation() == "PyPy" +if not PYPY: + from rustapi_module.subclassing import Subclassable -a = SomeSubClass() -_b = str(a) + repr(a) + +# should not raise +@pytest.mark.xfail(PYPY, reason="classes not properly working yet") +def test_subclassing_works(): + class SomeSubClass(Subclassable): + pass + + a = SomeSubClass() + _b = str(a) + repr(a) diff --git a/examples/rustapi_module/tox.ini b/examples/rustapi_module/tox.ini index a10ec06accc..99cd0130c7f 100644 --- a/examples/rustapi_module/tox.ini +++ b/examples/rustapi_module/tox.ini @@ -3,6 +3,7 @@ envlist = py27, py35, py36, py37, + pypy35 minversion = 2.9.0 skip_missing_interpreters = true diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index ea127872e79..6b3832b8ead 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -16,6 +16,12 @@ use std::os::raw::{c_char, c_int, c_uchar}; use std::ptr; use std::sync::Once; + +// A note regarding cpyext support: +// Some macros, like `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as separate symbols. +// For now, some symbols are exported as "private" symbols, like `_PyPyDate_FromDate`, +// which means they still adhere to the old API (expect a `cls` object in their signature) +// In the future they may be removed and become fully public symbols in cpyext. #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct PyDateTime_CAPI { @@ -26,7 +32,6 @@ pub struct PyDateTime_CAPI { pub TZInfoType: *mut PyTypeObject, #[cfg(Py_3_7)] pub TimeZone_UTC: *mut PyObject, - #[cfg_attr(PyPy, link_name = "_PyPyDate_FromDate")] pub Date_FromDate: unsafe extern "C" fn( year: c_int, @@ -66,13 +71,14 @@ pub struct PyDateTime_CAPI { #[cfg(Py_3_7)] pub TimeZone_FromTimeZone: unsafe extern "C" fn(offset: *mut PyObject, name: *mut PyObject) -> *mut PyObject, - #[cfg_attr(PyPy, link_name = "PyPyDateTime_FromTimestamp")] + + // Defined for PyPy as a separate symbol pub DateTime_FromTimestamp: unsafe extern "C" fn( cls: *mut PyTypeObject, args: *mut PyObject, kwargs: *mut PyObject, ) -> *mut PyObject, - #[cfg_attr(PyPy, link_name = "PyPyDate_FromTimestamp")] + // Defined for PyPy as a separate symbol pub Date_FromTimestamp: unsafe extern "C" fn(cls: *mut PyTypeObject, args: *mut PyObject) -> *mut PyObject, #[cfg(Py_3_6)] @@ -100,8 +106,48 @@ pub struct PyDateTime_CAPI { ) -> *mut PyObject, } -// Type struct wrappers +#[cfg(PyPy)] +extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPyDateTime_Import")] + pub fn PyDateTime_Import() -> &'static PyDateTime_CAPI; + + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_HOUR")] + pub fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MICROSECOND")] + pub fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MINUTE")] + pub fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_SECOND")] + pub fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_DAYS")] + pub fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_MICROSECONDS")] + pub fn PyDateTime_DELTA_GET_MICROSECONDS(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_SECONDS")] + pub fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_DAY")] + pub fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_MONTH")] + pub fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_YEAR")] + pub fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_HOUR")] + pub fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MICROSECOND")] + pub fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MINUTE")] + pub fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_SECOND")] + pub fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int; + #[cfg_attr(PyPy, link_name = "PyPyDate_FromTimestamp")] + pub fn PyDate_FromTimestamp(args: *mut PyObject) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyDateTime_FromTimestamp")] + pub fn PyDateTime_FromTimestamp(args: *mut PyObject) -> *mut PyObject; +} + + +// Type struct wrappers const _PyDateTime_DATE_DATASIZE: usize = 4; const _PyDateTime_TIME_DATASIZE: usize = 6; const _PyDateTime_DATETIME_DATASIZE: usize = 10; @@ -153,11 +199,6 @@ pub struct PyDateTime_Delta { pub microseconds: c_int, } -#[cfg(PyPy)] -extern "C" { - pub fn _PyPyDateTime_Import() -> &'static PyDateTime_CAPI; -} - // C API Capsule // Note: This is "roll-your-own" lazy-static implementation is necessary because // of the interaction between the call_once locks and the GIL. It turns out that @@ -216,9 +257,9 @@ impl Deref for PyDateTimeAPI { pub unsafe fn PyDateTime_IMPORT() -> &'static PyDateTime_CAPI { // PyPy excepts the C-API to be initialized via PyDateTime_Import, so trying to use - // `PyCapsule_Import` will have not actually initialize the module. - let capsule = if cfg!(PyPy) { - _PyPyDateTime_Import() + // `PyCapsule_Import` will behave unexpectedly in pypy. + let py_datetime_c_api = if cfg!(PyPy) { + PyDateTime_Import() } else { // PyDateTime_CAPSULE_NAME is a macro in C let PyDateTime_CAPSULE_NAME = CString::new("datetime.datetime_CAPI").unwrap(); @@ -228,7 +269,7 @@ pub unsafe fn PyDateTime_IMPORT() -> &'static PyDateTime_CAPI { PY_DATETIME_API_ONCE.call_once(move || { - PY_DATETIME_API_UNSAFE_CACHE = capsule; + PY_DATETIME_API_UNSAFE_CACHE = py_datetime_c_api; }); &(*PY_DATETIME_API_UNSAFE_CACHE) @@ -276,7 +317,7 @@ pub unsafe fn PyTime_CheckExact(op: *mut PyObject) -> c_int { } #[inline] -/// Check if `op` is a `PyDateTimeAPI.DetaType` or subtype. +/// Check if `op` is a `PyDateTimeAPI.DetaType` or subtype.Date_FromTimestamp pub unsafe fn PyDelta_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, PyDateTimeAPI.DeltaType) as c_int } @@ -307,38 +348,6 @@ macro_rules! _access_field { }; } -#[cfg(PyPy)] -extern "C" { - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_HOUR")] - pub fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MICROSECOND")] - pub fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MINUTE")] - pub fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_SECOND")] - pub fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_DAYS")] - pub fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_MICROSECONDS")] - pub fn PyDateTime_DELTA_GET_MICROSECONDS(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_SECONDS")] - pub fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_DAY")] - pub fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_MONTH")] - pub fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_YEAR")] - pub fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_HOUR")] - pub fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MICROSECOND")] - pub fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MINUTE")] - pub fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_SECOND")] - pub fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int; -} - // Accessor functions for PyDateTime_Date and PyDateTime_DateTime #[inline] diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 5d8e536b7a0..21ea3634086 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -7,7 +7,11 @@ use crate::err::PyResult; use crate::ffi; +use crate::ffi::datetime::PyDate_FromTimestamp; +use crate::ffi::datetime::{PyDateTime_CAPI, PyDateTime_FromTimestamp}; use crate::ffi::PyDateTimeAPI; +use crate::ffi::PyFloat_FromDouble; +use crate::ffi::Py_BuildValue; use crate::ffi::{PyDateTime_Check, PyDate_Check, PyDelta_Check, PyTZInfo_Check, PyTime_Check}; #[cfg(Py_3_6)] use crate::ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; @@ -30,6 +34,7 @@ use crate::AsPyPointer; use crate::Python; use crate::ToPyObject; use std::os::raw::c_int; +use std::os::raw::c_long; use std::ptr; /// Access traits @@ -83,11 +88,16 @@ impl PyDate { /// /// This is equivalent to `datetime.date.fromtimestamp` pub fn from_timestamp(py: Python, timestamp: i64) -> PyResult> { - let args = PyTuple::new(py, &[timestamp]); + let time_tuple = PyTuple::new(py, &[timestamp]); unsafe { - let ptr = (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, args.as_ptr()); - Py::from_owned_ptr_or_err(py, ptr) + let ptr = if cfg!(PyPy) { + PyDate_FromTimestamp(time_tuple.as_ptr()) + } else { + (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, time_tuple.as_ptr()) + }; + + unsafe { Py::from_owned_ptr_or_err(py, ptr) } } } } @@ -156,11 +166,16 @@ impl PyDateTime { let args = PyTuple::new(py, &[timestamp, time_zone_info]); unsafe { - let ptr = (PyDateTimeAPI.DateTime_FromTimestamp)( - PyDateTimeAPI.DateTimeType, - args.as_ptr(), - ptr::null_mut(), - ); + let ptr = if cfg!(PyPy) { + PyDateTime_FromTimestamp(args.as_ptr()) + } else { + (PyDateTimeAPI.DateTime_FromTimestamp)( + PyDateTimeAPI.DateTimeType, + args.as_ptr(), + ptr::null_mut(), + ) + }; + Py::from_owned_ptr_or_err(py, ptr) } } From 81edda0fae8f0bdf724f066da48315765bccad72 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:07:23 +0200 Subject: [PATCH 076/138] maybe travis has new pypy version? --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7fa8193e84b..062556dd163 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ matrix: # Keep this synced up with build.rs env: FEATURES=python3 TRAVIS_RUST_VERSION=nightly-2019-02-07 - name: PyPy3.5 6.0 - python: "pypy3.5-6.0" + python: "pypy3.6-7.0" env: FEATURES="python3 pypy" allow_failures: - python: "3.8-dev" From 31e4673ef4017124cf60cb0b1cdb2b223dd7d9a4 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:09:12 +0200 Subject: [PATCH 077/138] small error on windows (build script) --- pyo3build/src/py_interpreter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyo3build/src/py_interpreter.rs b/pyo3build/src/py_interpreter.rs index 8485748eba6..8a4de66b075 100644 --- a/pyo3build/src/py_interpreter.rs +++ b/pyo3build/src/py_interpreter.rs @@ -323,8 +323,8 @@ print(sys.exec_prefix) // Py_ENABLE_SHARED doesn't seem to be present on windows. Ok(format!( "cargo:rustc-link-lib=pythonXY:python{}{}", - version.major, - match version.minor { + self.version.major, + match self.version.minor { Some(minor) => minor.to_string(), None => "".to_owned(), } From 6ce45f208f2864402514cec7c4f746bec1a36fb4 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:17:19 +0200 Subject: [PATCH 078/138] fix conditional compilation --- src/ffi/datetime.rs | 13 +++++-------- src/types/datetime.rs | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index 6b3832b8ead..18049dc9108 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -16,7 +16,6 @@ use std::os::raw::{c_char, c_int, c_uchar}; use std::ptr; use std::sync::Once; - // A note regarding cpyext support: // Some macros, like `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as separate symbols. // For now, some symbols are exported as "private" symbols, like `_PyPyDate_FromDate`, @@ -146,7 +145,6 @@ extern "C" { pub fn PyDateTime_FromTimestamp(args: *mut PyObject) -> *mut PyObject; } - // Type struct wrappers const _PyDateTime_DATE_DATASIZE: usize = 4; const _PyDateTime_TIME_DATASIZE: usize = 6; @@ -255,19 +253,19 @@ impl Deref for PyDateTimeAPI { /// such as if you do not want the first call to a datetime function to be /// slightly slower than subsequent calls. pub unsafe fn PyDateTime_IMPORT() -> &'static PyDateTime_CAPI { - // PyPy excepts the C-API to be initialized via PyDateTime_Import, so trying to use // `PyCapsule_Import` will behave unexpectedly in pypy. - let py_datetime_c_api = if cfg!(PyPy) { - PyDateTime_Import() - } else { + #[cfg(PyPy)] + let py_datetime_c_api = PyDateTime_Import(); + + #[cfg(not(PyPy))] + let py_datetime_c_api = { // PyDateTime_CAPSULE_NAME is a macro in C let PyDateTime_CAPSULE_NAME = CString::new("datetime.datetime_CAPI").unwrap(); PyCapsule_Import(PyDateTime_CAPSULE_NAME.as_ptr(), 1) as *const PyDateTime_CAPI }; - PY_DATETIME_API_ONCE.call_once(move || { PY_DATETIME_API_UNSAFE_CACHE = py_datetime_c_api; }); @@ -348,7 +346,6 @@ macro_rules! _access_field { }; } - // Accessor functions for PyDateTime_Date and PyDateTime_DateTime #[inline] #[cfg(not(PyPy))] diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 21ea3634086..2d62193108b 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -7,8 +7,10 @@ use crate::err::PyResult; use crate::ffi; -use crate::ffi::datetime::PyDate_FromTimestamp; -use crate::ffi::datetime::{PyDateTime_CAPI, PyDateTime_FromTimestamp}; +use crate::ffi::datetime::PyDateTime_CAPI; +#[cfg(PyPy)] +use crate::ffi::datetime::{PyDateTime_FromTimestamp, PyDate_FromTimestamp}; + use crate::ffi::PyDateTimeAPI; use crate::ffi::PyFloat_FromDouble; use crate::ffi::Py_BuildValue; @@ -91,11 +93,12 @@ impl PyDate { let time_tuple = PyTuple::new(py, &[timestamp]); unsafe { - let ptr = if cfg!(PyPy) { - PyDate_FromTimestamp(time_tuple.as_ptr()) - } else { - (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, time_tuple.as_ptr()) - }; + #[cfg(PyPy)] + let ptr = PyDate_FromTimestamp(time_tuple.as_ptr()); + + #[cfg(not(PyPy))] + let ptr = + (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, time_tuple.as_ptr()); unsafe { Py::from_owned_ptr_or_err(py, ptr) } } @@ -166,9 +169,11 @@ impl PyDateTime { let args = PyTuple::new(py, &[timestamp, time_zone_info]); unsafe { - let ptr = if cfg!(PyPy) { - PyDateTime_FromTimestamp(args.as_ptr()) - } else { + #[cfg(PyPy)] + let ptr = PyDateTime_FromTimestamp(args.as_ptr()); + + #[cfg(not(PyPy))] + let ptr = { (PyDateTimeAPI.DateTime_FromTimestamp)( PyDateTimeAPI.DateTimeType, args.as_ptr(), From 75511cded0371b24398022f72e56b58dee15d358 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:26:58 +0200 Subject: [PATCH 079/138] try to make tests run on travis.. --- .travis.yml | 5 +++-- ci/travis/setup.sh | 13 +++++++++++++ ci/travis/test.sh | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 062556dd163..2f5bf57db48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,8 +29,9 @@ matrix: python: "3.7" # Keep this synced up with build.rs env: FEATURES=python3 TRAVIS_RUST_VERSION=nightly-2019-02-07 - - name: PyPy3.5 6.0 - python: "pypy3.6-7.0" + # Tested via anaconda PyPy (since travis's PyPy version is too old) + - name: PyPy3.5 7.0 + python: "3.7" env: FEATURES="python3 pypy" allow_failures: - python: "3.8-dev" diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index b7e58f42e95..b016c3c625d 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -33,3 +33,16 @@ if [ ! -f "$HOME/.cargo/bin/kcov" ]; then install src/kcov $HOME/.cargo/bin/kcov cd $TRAVIS_BUILD_DIR fi + + +### Setup PyPy ################################################################ + +wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ +/bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p $CONDA_DIR && \ +/opt/anaconda/bin/conda install --quiet --yes conda && \ +conda config --system --add channels conda-forge && \ +conda create -n pypy3 && \ +source activate pypy3 && \ +conda install pypy3.5 && \ +pypy3 -m ensurepip && \ +pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 655827aa121..a8523429837 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -14,6 +14,10 @@ if [ $TRAVIS_JOB_NAME = 'Minimum nightly' ]; then cargo clippy --features "$FEATURES num-complex" fi +if ! [[ $FEATURES == *"pypy"* ]]; then + source activate pypy3 +fi + for example_dir in examples/*; do tox -c "$example_dir/tox.ini" -e py done From fbab780559f8f766a1e30287d44ca7f5d4fee575 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:29:18 +0200 Subject: [PATCH 080/138] invert condition --- ci/travis/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/test.sh b/ci/travis/test.sh index a8523429837..1a605449079 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -14,7 +14,7 @@ if [ $TRAVIS_JOB_NAME = 'Minimum nightly' ]; then cargo clippy --features "$FEATURES num-complex" fi -if ! [[ $FEATURES == *"pypy"* ]]; then +if [[ $FEATURES == *"pypy"* ]]; then source activate pypy3 fi From 0996930a5e83acd089f221274bcca38b28ede105 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:33:30 +0200 Subject: [PATCH 081/138] added pytest-faulthandler to facilitate debugging --- examples/rustapi_module/requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/rustapi_module/requirements-dev.txt b/examples/rustapi_module/requirements-dev.txt index b1000dbbb17..1e86e726d72 100644 --- a/examples/rustapi_module/requirements-dev.txt +++ b/examples/rustapi_module/requirements-dev.txt @@ -1,3 +1,4 @@ hypothesis>=3.55 pytest>=3.5.0 setuptools-rust>=0.10.2 +pytest-faulthandler>=1.5.0 From 893c0da2ea64b228b6196b256cbfb60b269eb398 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:41:32 +0200 Subject: [PATCH 082/138] correctly name dir --- ci/travis/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index b016c3c625d..207d371aa72 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -38,7 +38,7 @@ fi ### Setup PyPy ################################################################ wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ -/bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p $CONDA_DIR && \ +/bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ conda config --system --add channels conda-forge && \ conda create -n pypy3 && \ From f20b1b1bc4822dce42829bd00adebcd994fe9c0a Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:47:58 +0200 Subject: [PATCH 083/138] use full paths --- ci/travis/setup.sh | 12 ++++++------ ci/travis/test.sh | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 207d371aa72..2751530342f 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -40,9 +40,9 @@ fi wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ -conda config --system --add channels conda-forge && \ -conda create -n pypy3 && \ -source activate pypy3 && \ -conda install pypy3.5 && \ -pypy3 -m ensurepip && \ -pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file +/opt/anaconda/bin/conda config --system --add channels conda-forge && \ +/opt/anaconda/bin/conda create -n pypy3 && \ +/opt/anaconda/bin/conda activate pypy3 && \ +/opt/anaconda/bin/conda install pypy3.5 && \ +/opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ +/opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 1a605449079..c9305595635 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -15,7 +15,7 @@ if [ $TRAVIS_JOB_NAME = 'Minimum nightly' ]; then fi if [[ $FEATURES == *"pypy"* ]]; then - source activate pypy3 + /opt/anaconda/bin/conda activate pypy3 fi for example_dir in examples/*; do From cabbde74201377ba09d59c96c2ee2721fe242b81 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 22:53:47 +0200 Subject: [PATCH 084/138] =?UTF-8?q?say=20=E2=80=94yes=20to=20conda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci/travis/setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 2751530342f..7766e33cc54 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -41,8 +41,8 @@ wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64. /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ /opt/anaconda/bin/conda config --system --add channels conda-forge && \ -/opt/anaconda/bin/conda create -n pypy3 && \ +/opt/anaconda/bin/conda create -n pypy3 -y && \ /opt/anaconda/bin/conda activate pypy3 && \ -/opt/anaconda/bin/conda install pypy3.5 && \ +/opt/anaconda/bin/conda install --quiet --yes pypy3.5 && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file From c70a1d73873e17da94956ae42eb39d53df3df5bb Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 23:06:54 +0200 Subject: [PATCH 085/138] fix --- ci/travis/setup.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 7766e33cc54..67c57e72449 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -41,8 +41,7 @@ wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64. /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ /opt/anaconda/bin/conda config --system --add channels conda-forge && \ -/opt/anaconda/bin/conda create -n pypy3 -y && \ -/opt/anaconda/bin/conda activate pypy3 && \ -/opt/anaconda/bin/conda install --quiet --yes pypy3.5 && \ +/opt/anaconda/bin/conda init bash \ +/opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file From e02643abc389f8ef0ebef1370cdf4e1fb1913f82 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 23:11:44 +0200 Subject: [PATCH 086/138] syntax error --- ci/travis/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 67c57e72449..fd529133c24 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -41,7 +41,7 @@ wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64. /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ /opt/anaconda/bin/conda config --system --add channels conda-forge && \ -/opt/anaconda/bin/conda init bash \ +/opt/anaconda/bin/conda init bash && \ /opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file From c12b5025ada25faedf8dbd9a74bca65c9fd10122 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 18 Mar 2019 23:33:19 +0200 Subject: [PATCH 087/138] change PATH --- .travis.yml | 2 +- ci/travis/test.sh | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f5bf57db48..2e8dccb7950 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ matrix: # Tested via anaconda PyPy (since travis's PyPy version is too old) - name: PyPy3.5 7.0 python: "3.7" - env: FEATURES="python3 pypy" + env: FEATURES="python3 pypy" PATH="$PATH:/opt/anaconda/envs/pypy3/bin" allow_failures: - python: "3.8-dev" env: FEATURES=python3 diff --git a/ci/travis/test.sh b/ci/travis/test.sh index c9305595635..655827aa121 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -14,10 +14,6 @@ if [ $TRAVIS_JOB_NAME = 'Minimum nightly' ]; then cargo clippy --features "$FEATURES num-complex" fi -if [[ $FEATURES == *"pypy"* ]]; then - /opt/anaconda/bin/conda activate pypy3 -fi - for example_dir in examples/*; do tox -c "$example_dir/tox.ini" -e py done From 842d3b1b5730d4baad9fd75573c2dd665ea651dd Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 19 Mar 2019 17:23:45 +0200 Subject: [PATCH 088/138] fixed a terrible bug with PyTypeObjects in PyPy --- pyo3-derive-backend/src/module.rs | 4 ++-- pyo3-derive-backend/src/utils.rs | 7 +------ src/type_object.rs | 14 ++++++++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pyo3-derive-backend/src/module.rs b/pyo3-derive-backend/src/module.rs index b583aaafbcb..ff918a4021f 100644 --- a/pyo3-derive-backend/src/module.rs +++ b/pyo3-derive-backend/src/module.rs @@ -22,7 +22,7 @@ pub fn py3_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream { /// This autogenerated function is called by the python interpreter when importing /// the module. pub unsafe extern "C" fn #cb_name() -> *mut pyo3::ffi::PyObject { - pyo3::derive_utils::make_module(concat!(stringify!(#name), "\0"), #doc, #fnname) + pyo3::derive_utils::make_module(concat!(stringify!(#name), "PyO3 Default Module"), #doc, #fnname) } } } @@ -34,7 +34,7 @@ pub fn py2_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream { #[no_mangle] #[allow(non_snake_case)] pub unsafe extern "C" fn #cb_name() { - pyo3::derive_utils::make_module(concat!(stringify!(#name), "\0"), #doc, #fnname) + pyo3::derive_utils::make_module(concat!(stringify!(#name), "PyO3 Default Module"), #doc, #fnname) } } } diff --git a/pyo3-derive-backend/src/utils.rs b/pyo3-derive-backend/src/utils.rs index 3c49efe78c3..d2f9dfbe259 100644 --- a/pyo3-derive-backend/src/utils.rs +++ b/pyo3-derive-backend/src/utils.rs @@ -35,10 +35,5 @@ pub fn get_doc(attrs: &[syn::Attribute], null_terminated: bool) -> syn::Lit { let doc = doc.join("\n"); // FIXME: add span - syn::parse_str(&if null_terminated { - format!("\"{}\0\"", doc) - } else { - format!("\"{}\"", doc) - }) - .unwrap() + syn::parse_str(&format!("\"{}\"", doc)).unwrap() } diff --git a/src/type_object.rs b/src/type_object.rs index dabcf012eb6..a247f37798d 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -13,9 +13,9 @@ use crate::Python; use crate::{class, ffi, gil}; use class::methods::PyMethodsProtocol; use std::collections::HashMap; -use std::ffi::CString; +use std::ffi::{CStr, CString}; use std::os::raw::c_void; -use std::ptr::NonNull; +use std::ptr::{self, NonNull}; /// Python type information. pub trait PyTypeInfo { @@ -26,7 +26,7 @@ pub trait PyTypeInfo { const NAME: &'static str; /// Class doc string - const DESCRIPTION: &'static str = "\0"; + const DESCRIPTION: &'static str = "A PyO3 Class"; /// Size of the rust PyObject structure (PyObject + rust structure) const SIZE: usize; @@ -304,7 +304,13 @@ where unsafe { ::type_object() }; type_object.tp_name = type_name.into_raw(); - type_object.tp_doc = T::DESCRIPTION.as_ptr() as *const _; + // PyPy will segfault if passed only a nul terminator as `tp_doc`. + // ptr::null() is OK though. + if T::DESCRIPTION.len() > 0 { + let type_docstring = CString::new(T::DESCRIPTION).expect("description must not contain NUL byte"); + type_object.tp_doc = type_docstring.into_raw(); + }; + type_object.tp_base = base_type_object; // dealloc From e9b6bf168f18c4c4b5a0b7c203c6a1ee37b6084c Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 19 Mar 2019 17:41:37 +0200 Subject: [PATCH 089/138] fix PyTypeObject defs --- src/ffi3/object.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 192bab9f8d0..87ab8e2aad2 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -446,6 +446,15 @@ mod typeobject { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct PyTypeObject { + #[cfg(PyPy)] + pub ob_refcnt: Py_ssize_t, + #[cfg(PyPy)] + pub ob_pypy_link: Py_ssize_t, + #[cfg(PyPy)] + pub ob_type: *mut PyTypeObject, + #[cfg(PyPy)] + pub ob_size: Py_ssize_t, + #[cfg(not(PyPy))] pub ob_base: object::PyVarObject, pub tp_name: *const c_char, pub tp_basicsize: Py_ssize_t, @@ -494,6 +503,8 @@ mod typeobject { pub tp_del: Option, pub tp_version_tag: c_uint, pub tp_finalize: Option, + #[cfg(PyPy)] + pub tp_pypy_flags: ::std::os::raw::c_long, #[cfg(py_sys_config = "COUNT_ALLOCS")] pub tp_allocs: Py_ssize_t, #[cfg(py_sys_config = "COUNT_ALLOCS")] @@ -506,6 +517,70 @@ mod typeobject { pub tp_next: *mut PyTypeObject, } + #[cfg(PyPy)] + macro_rules! py_type_object_init { + ($tp_as_async:ident, $($tail:tt)*) => { + as_expr! { + PyTypeObject { + ob_refcnt: 1, + ob_pypy_link: 0, + ob_type: ptr::null_mut(), +// ob_size: mem::size_of::() as isize, + ob_size: 0, + tp_name: ptr::null(), + tp_basicsize: 0, + tp_itemsize: 0, + tp_dealloc: None, + tp_print: None, + tp_getattr: None, + tp_setattr: None, + $tp_as_async: ptr::null_mut(), + tp_repr: None, + tp_as_number: ptr::null_mut(), + tp_as_sequence: ptr::null_mut(), + tp_as_mapping: ptr::null_mut(), + tp_hash: None, + tp_call: None, + tp_str: None, + tp_getattro: None, + tp_setattro: None, + tp_as_buffer: ptr::null_mut(), + tp_flags: ffi3::object::Py_TPFLAGS_DEFAULT, + tp_doc: ptr::null(), + tp_traverse: None, + tp_clear: None, + tp_richcompare: None, + tp_weaklistoffset: 0, + tp_iter: None, + tp_iternext: None, + tp_methods: ptr::null_mut(), + tp_members: ptr::null_mut(), + tp_getset: ptr::null_mut(), + tp_base: ptr::null_mut(), + tp_dict: 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: ptr::null_mut(), + tp_mro: ptr::null_mut(), + tp_cache: ptr::null_mut(), + tp_subclasses: ptr::null_mut(), + tp_weaklist: ptr::null_mut(), + tp_del: None, + tp_version_tag: 0, + tp_pypy_flags: 0, + $($tail)* + } + } + } + } + + #[cfg(not(PyPy))] macro_rules! py_type_object_init { ($tp_as_async:ident, $($tail:tt)*) => { as_expr! { From cc66fc546b4ac5691f5d0865f87102e5ee77fd18 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 19 Mar 2019 17:44:27 +0200 Subject: [PATCH 090/138] re-enabled tests! --- examples/rustapi_module/src/datetime.rs | 3 +-- examples/rustapi_module/src/lib.rs | 1 - examples/rustapi_module/src/othermod.rs | 3 +-- examples/rustapi_module/tests/test_datetime.py | 2 -- examples/rustapi_module/tests/test_othermod.py | 9 +-------- examples/rustapi_module/tests/test_subclassing.py | 10 +--------- 6 files changed, 4 insertions(+), 24 deletions(-) diff --git a/examples/rustapi_module/src/datetime.rs b/examples/rustapi_module/src/datetime.rs index ce149b4d5f9..054869552b9 100644 --- a/examples/rustapi_module/src/datetime.rs +++ b/examples/rustapi_module/src/datetime.rs @@ -229,8 +229,7 @@ fn datetime(_py: Python<'_>, m: &PyModule) -> PyResult<()> { } m.add_wrapped(wrap_pyfunction!(issue_219))?; - - #[cfg(not(PyPy))] m.add_class::()?; + Ok(()) } diff --git a/examples/rustapi_module/src/lib.rs b/examples/rustapi_module/src/lib.rs index d0434480182..c20564f5a43 100644 --- a/examples/rustapi_module/src/lib.rs +++ b/examples/rustapi_module/src/lib.rs @@ -3,5 +3,4 @@ pub mod datetime; #[cfg(not(PyPy))] pub mod dict_iter; pub mod othermod; -#[cfg(not(PyPy))] pub mod subclassing; diff --git a/examples/rustapi_module/src/othermod.rs b/examples/rustapi_module/src/othermod.rs index e0c5055b99c..de1c96904c2 100644 --- a/examples/rustapi_module/src/othermod.rs +++ b/examples/rustapi_module/src/othermod.rs @@ -32,8 +32,7 @@ fn double(x: i32) -> i32 { #[pymodule] fn othermod(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(double))?; - - #[cfg(not(PyPy))] + m.add_class::()?; m.add("USIZE_MIN", usize::min_value())?; diff --git a/examples/rustapi_module/tests/test_datetime.py b/examples/rustapi_module/tests/test_datetime.py index 56472b0f431..71cdf4181e8 100644 --- a/examples/rustapi_module/tests/test_datetime.py +++ b/examples/rustapi_module/tests/test_datetime.py @@ -287,7 +287,6 @@ def test_issue_219(): rdt.issue_219() -@pytest.mark.xfail(PYPY, reason="add_class not properly working yet") def test_tz_class(): tzi = rdt.TzClass() @@ -298,7 +297,6 @@ def test_tz_class(): assert dt.dst() is None -@pytest.mark.xfail(PYPY, reason="add_class not properly working yet") def test_tz_class_introspection(): tzi = rdt.TzClass() diff --git a/examples/rustapi_module/tests/test_othermod.py b/examples/rustapi_module/tests/test_othermod.py index 160a2441564..f47c64b737a 100644 --- a/examples/rustapi_module/tests/test_othermod.py +++ b/examples/rustapi_module/tests/test_othermod.py @@ -1,15 +1,11 @@ -import platform - -import pytest from hypothesis import given, assume from hypothesis import strategies as st + from rustapi_module import othermod INTEGER32_ST = st.integers(min_value=(-(2 ** 31)), max_value=(2 ** 31 - 1)) USIZE_ST = st.integers(min_value=othermod.USIZE_MIN, max_value=othermod.USIZE_MAX) -PYPY = platform.python_implementation() == "PyPy" - @given(x=INTEGER32_ST) def test_double(x): @@ -18,7 +14,6 @@ def test_double(x): assert othermod.double(x) == expected -@pytest.mark.xfail(PYPY, reason="classes not properly working yet") def test_modclass(): # Test that the repr of the class itself doesn't crash anything repr(othermod.ModClass) @@ -26,7 +21,6 @@ def test_modclass(): assert isinstance(othermod.ModClass, type) -@pytest.mark.xfail(PYPY, reason="classes not properly working yet") def test_modclass_instance(): mi = othermod.ModClass() @@ -37,7 +31,6 @@ def test_modclass_instance(): assert isinstance(mi, object) -@pytest.mark.xfail(PYPY, reason="classes not properly working yet") @given(x=USIZE_ST) def test_modclas_noop(x): mi = othermod.ModClass() diff --git a/examples/rustapi_module/tests/test_subclassing.py b/examples/rustapi_module/tests/test_subclassing.py index 508e74e546c..aaf27b6f3eb 100644 --- a/examples/rustapi_module/tests/test_subclassing.py +++ b/examples/rustapi_module/tests/test_subclassing.py @@ -1,15 +1,7 @@ -import platform - -import pytest - -PYPY = platform.python_implementation() == "PyPy" - -if not PYPY: - from rustapi_module.subclassing import Subclassable +from rustapi_module.subclassing import Subclassable # should not raise -@pytest.mark.xfail(PYPY, reason="classes not properly working yet") def test_subclassing_works(): class SomeSubClass(Subclassable): pass From a070f8f019c43947c942244186bc688442e5f086 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Tue, 19 Mar 2019 17:45:06 +0200 Subject: [PATCH 091/138] all tests are passing! --- examples/rustapi_module/src/lib.rs | 2 -- examples/rustapi_module/tests/test_dict_iter.py | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/examples/rustapi_module/src/lib.rs b/examples/rustapi_module/src/lib.rs index c20564f5a43..be7fd6ed63c 100644 --- a/examples/rustapi_module/src/lib.rs +++ b/examples/rustapi_module/src/lib.rs @@ -1,6 +1,4 @@ pub mod datetime; - -#[cfg(not(PyPy))] pub mod dict_iter; pub mod othermod; pub mod subclassing; diff --git a/examples/rustapi_module/tests/test_dict_iter.py b/examples/rustapi_module/tests/test_dict_iter.py index a1b714f0b8e..d5592fa4ec1 100644 --- a/examples/rustapi_module/tests/test_dict_iter.py +++ b/examples/rustapi_module/tests/test_dict_iter.py @@ -1,14 +1,6 @@ -import platform - -PYPY = platform.python_implementation() == "PyPy" - -if not PYPY: - from rustapi_module.test_dict import DictSize - import pytest +from rustapi_module.test_dict import DictSize - -@pytest.mark.xfail(PYPY, reason="classes not properly working yet") @pytest.mark.parametrize( "size", [64, 128, 256], From a73dc69a99e744feac41a15be03fe7b0cc48dc2d Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 11:38:20 +0200 Subject: [PATCH 092/138] make the fix ad-hoc for now --- pyo3-derive-backend/src/module.rs | 4 ++-- pyo3-derive-backend/src/utils.rs | 7 ++++++- src/type_object.rs | 10 ++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pyo3-derive-backend/src/module.rs b/pyo3-derive-backend/src/module.rs index ff918a4021f..b583aaafbcb 100644 --- a/pyo3-derive-backend/src/module.rs +++ b/pyo3-derive-backend/src/module.rs @@ -22,7 +22,7 @@ pub fn py3_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream { /// This autogenerated function is called by the python interpreter when importing /// the module. pub unsafe extern "C" fn #cb_name() -> *mut pyo3::ffi::PyObject { - pyo3::derive_utils::make_module(concat!(stringify!(#name), "PyO3 Default Module"), #doc, #fnname) + pyo3::derive_utils::make_module(concat!(stringify!(#name), "\0"), #doc, #fnname) } } } @@ -34,7 +34,7 @@ pub fn py2_init(fnname: &Ident, name: &Ident, doc: syn::Lit) -> TokenStream { #[no_mangle] #[allow(non_snake_case)] pub unsafe extern "C" fn #cb_name() { - pyo3::derive_utils::make_module(concat!(stringify!(#name), "PyO3 Default Module"), #doc, #fnname) + pyo3::derive_utils::make_module(concat!(stringify!(#name), "\0"), #doc, #fnname) } } } diff --git a/pyo3-derive-backend/src/utils.rs b/pyo3-derive-backend/src/utils.rs index d2f9dfbe259..3c49efe78c3 100644 --- a/pyo3-derive-backend/src/utils.rs +++ b/pyo3-derive-backend/src/utils.rs @@ -35,5 +35,10 @@ pub fn get_doc(attrs: &[syn::Attribute], null_terminated: bool) -> syn::Lit { let doc = doc.join("\n"); // FIXME: add span - syn::parse_str(&format!("\"{}\"", doc)).unwrap() + syn::parse_str(&if null_terminated { + format!("\"{}\0\"", doc) + } else { + format!("\"{}\"", doc) + }) + .unwrap() } diff --git a/src/type_object.rs b/src/type_object.rs index a247f37798d..c8ad386d0d4 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -26,7 +26,7 @@ pub trait PyTypeInfo { const NAME: &'static str; /// Class doc string - const DESCRIPTION: &'static str = "A PyO3 Class"; + const DESCRIPTION: &'static str = "\0"; /// Size of the rust PyObject structure (PyObject + rust structure) const SIZE: usize; @@ -304,11 +304,13 @@ where unsafe { ::type_object() }; type_object.tp_name = type_name.into_raw(); + // PyPy will segfault if passed only a nul terminator as `tp_doc`. // ptr::null() is OK though. - if T::DESCRIPTION.len() > 0 { - let type_docstring = CString::new(T::DESCRIPTION).expect("description must not contain NUL byte"); - type_object.tp_doc = type_docstring.into_raw(); + if T::DESCRIPTION.len() == "\0" { + type_object.tp_doc = ptr::null(); + } else { + type_object.tp_doc = T::DESCRIPTION.as_ptr() as *const _; }; type_object.tp_base = base_type_object; From 500be63a9dcd7e025e4b504a781e782a09fafaa9 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 14:58:44 +0200 Subject: [PATCH 093/138] removed build module --- Cargo.toml | 2 - build.rs | 628 +++++++++++++++++++++++++++++++- pyo3build/Cargo.toml | 14 - pyo3build/src/lib.rs | 6 - pyo3build/src/py_interpreter.rs | 541 --------------------------- pyo3build/src/python_version.rs | 169 --------- pyo3build/src/rustc_version.rs | 46 --- pyo3build/src/utils.rs | 83 ----- src/type_object.rs | 2 +- 9 files changed, 611 insertions(+), 880 deletions(-) delete mode 100644 pyo3build/Cargo.toml delete mode 100644 pyo3build/src/lib.rs delete mode 100644 pyo3build/src/py_interpreter.rs delete mode 100644 pyo3build/src/python_version.rs delete mode 100644 pyo3build/src/rustc_version.rs delete mode 100644 pyo3build/src/utils.rs diff --git a/Cargo.toml b/Cargo.toml index bbff46db7ab..bccf6c4b8de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ inventory = "0.1.3" [build-dependencies] version_check = "0.1.5" regex = "1.1.0" -pyo3-build-utils = {version = "*", path="pyo3build"} [dev-dependencies] assert_approx_eq = "1.1.0" @@ -62,6 +61,5 @@ test-doc = [] members = [ "pyo3cls", "pyo3-derive-backend", - "pyo3build", "examples/*" ] diff --git a/build.rs b/build.rs index 51c039cee7d..af546518dba 100644 --- a/build.rs +++ b/build.rs @@ -1,16 +1,602 @@ -extern crate pyo3_build_utils; - -use pyo3_build_utils::{ - py_interpreter::{cfg_line_for_var, find_interpreter, is_value, InterpreterConfig}, - python_version::PythonVersion, - rustc_version::check_rustc_version, -}; use regex::Regex; use std::collections::HashMap; +use std::convert::AsRef; use std::env; +use std::fmt; use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::Path; +use std::process::Command; +use std::process::Stdio; +use version_check::{is_min_date, is_min_version, supports_features}; + +/// Specifies the minimum nightly version needed to compile pyo3. +/// Keep this synced up with the travis ci config, +/// But note that this is the rustc version which can be lower than the nightly version +const MIN_DATE: &'static str = "2019-02-06"; +const MIN_VERSION: &'static str = "1.34.0-nightly"; + +#[derive(Debug, Clone, PartialEq)] +pub enum PythonInterpreterKind { + CPython, + PyPy, +} + +#[derive(Debug)] +struct PythonVersion { + major: u8, + // minor == None means any minor version will do + minor: Option, + implementation: PythonInterpreterKind, +} + +impl PartialEq for PythonVersion { + fn eq(&self, o: &PythonVersion) -> bool { + self.major == o.major && (self.minor.is_none() || self.minor == o.minor) + } +} + +impl fmt::Display for PythonVersion { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + self.major.fmt(f)?; + f.write_str(".")?; + match self.minor { + Some(minor) => minor.fmt(f)?, + None => f.write_str("*")?, + }; + Ok(()) + } +} + +const PY3_MIN_MINOR: u8 = 5; + +const CFG_KEY: &'static str = "py_sys_config"; + +/// A list of python interpreter compile-time preprocessor defines that +/// we will pick up and pass to rustc via --cfg=py_sys_config={varname}; +/// this allows using them conditional cfg attributes in the .rs files, so +/// +/// #[cfg(py_sys_config="{varname}"] +/// +/// is the equivalent of #ifdef {varname} name in C. +/// +/// see Misc/SpecialBuilds.txt in the python source for what these mean. +/// +/// (hrm, this is sort of re-implementing what distutils does, except +/// by passing command line args instead of referring to a python.h) +#[cfg(not(target_os = "windows"))] +static SYSCONFIG_FLAGS: [&'static str; 7] = [ + "Py_USING_UNICODE", + "Py_UNICODE_WIDE", + "WITH_THREAD", + "Py_DEBUG", + "Py_REF_DEBUG", + "Py_TRACE_REFS", + "COUNT_ALLOCS", +]; + +static SYSCONFIG_VALUES: [&'static str; 1] = [ + // cfg doesn't support flags with values, just bools - so flags + // below are translated into bools as {varname}_{val} + // + // for example, Py_UNICODE_SIZE_2 or Py_UNICODE_SIZE_4 + "Py_UNICODE_SIZE", // note - not present on python 3.3+, which is always wide +]; + +/// Attempts to parse the header at the given path, returning a map of definitions to their values. +/// Each entry in the map directly corresponds to a `#define` in the given header. +fn parse_header_defines>(header_path: P) -> Result, String> { + // This regex picks apart a C style, single line `#define` statement into an identifier and a + // value. e.g. for the line `#define Py_DEBUG 1`, this regex will capture `Py_DEBUG` into + // `ident` and `1` into `value`. + let define_regex = + Regex::new(r"^\s*#define\s+(?P[a-zA-Z0-9_]+)\s+(?P.+)\s*$").unwrap(); + + let header_file = File::open(header_path.as_ref()).map_err(|e| e.to_string())?; + let header_reader = BufReader::new(&header_file); + + let definitions = header_reader + .lines() + .filter_map(|maybe_line| { + let line = maybe_line.unwrap_or_else(|err| { + panic!("failed to read {}: {}", header_path.as_ref().display(), err); + }); + let captures = define_regex.captures(&line)?; + + if captures.name("ident").is_some() && captures.name("value").is_some() { + Some(( + captures.name("ident").unwrap().as_str().to_owned(), + captures.name("value").unwrap().as_str().to_owned(), + )) + } else { + None + } + }) + .collect(); + + Ok(definitions) +} + +fn fix_config_map(mut config_map: HashMap) -> HashMap { + if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) { + config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); + config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); + config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); + } + + config_map +} + +fn load_cross_compile_info() -> Result<(PythonVersion, HashMap, Vec), String> +{ + let python_include_dir = env::var("PYO3_CROSS_INCLUDE_DIR").unwrap(); + let python_include_dir = Path::new(&python_include_dir); + + let patchlevel_defines = parse_header_defines(python_include_dir.join("patchlevel.h"))?; + + let major = patchlevel_defines + .get("PY_MAJOR_VERSION") + .and_then(|major| major.parse::().ok()) + .expect("PY_MAJOR_VERSION undefined"); + + let minor = patchlevel_defines + .get("PY_MINOR_VERSION") + .and_then(|minor| minor.parse::().ok()) + .expect("PY_MINOR_VERSION undefined"); + + let python_version = PythonVersion { + major, + minor: Some(minor), + implementation: PythonInterpreterKind::CPython, + }; + + let config_map = parse_header_defines(python_include_dir.join("pyconfig.h"))?; + + let config_lines = vec![ + "".to_owned(), // compatibility, not used when cross compiling. + env::var("PYO3_CROSS_LIB_DIR").unwrap(), + config_map + .get("Py_ENABLE_SHARED") + .expect("Py_ENABLE_SHARED undefined") + .to_owned(), + format!("{}.{}", major, minor), + "".to_owned(), // compatibility, not used when cross compiling. + ]; + + Ok((python_version, fix_config_map(config_map), config_lines)) +} + +/// Examine python's compile flags to pass to cfg by launching +/// the interpreter and printing variables of interest from +/// sysconfig.get_config_vars. +#[cfg(not(target_os = "windows"))] +fn get_config_vars(python_path: &str) -> Result, String> { + // FIXME: We can do much better here using serde: + // import json, sysconfig; print(json.dumps({k:str(v) for k, v in sysconfig.get_config_vars().items()})) + + let mut script = "import sysconfig; \ + config = sysconfig.get_config_vars();" + .to_owned(); + + for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { + script.push_str(&format!( + "print(config.get('{}', {}));", + k, + if is_value(k) { "None" } else { "0" } + )); + } + + let stdout = run_python_script(python_path, &script)?; + let split_stdout: Vec<&str> = stdout.trim_end().lines().collect(); + if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { + return Err(format!( + "python stdout len didn't return expected number of lines: {}", + split_stdout.len() + )); + } + let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); + let all_vars = all_vars.zip(split_stdout.iter()).fold( + HashMap::new(), + |mut memo: HashMap, (&k, &v)| { + if !(v.to_owned() == "None" && is_value(k)) { + memo.insert(k.to_owned(), v.to_owned()); + } + memo + }, + ); + + Ok(fix_config_map(all_vars)) +} + +#[cfg(target_os = "windows")] +fn get_config_vars(_: &str) -> Result, String> { + // sysconfig is missing all the flags on windows, so we can't actually + // query the interpreter directly for its build flags. + // + // For the time being, this is the flags as defined in the python source's + // PC\pyconfig.h. This won't work correctly if someone has built their + // python with a modified pyconfig.h - sorry if that is you, you will have + // to comment/uncomment the lines below. + let mut map: HashMap = HashMap::new(); + map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); + map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); + + // This is defined #ifdef _DEBUG. The visual studio build seems to produce + // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the + // Debug configuration, which this script doesn't currently support anyway. + // map.insert("Py_DEBUG", "1"); + + // Uncomment these manually if your python was built with these and you want + // the cfg flags to be set in rust. + // + // map.insert("Py_REF_DEBUG", "1"); + // map.insert("Py_TRACE_REFS", "1"); + // map.insert("COUNT_ALLOCS", 1"); + Ok(map) +} + +fn is_value(key: &str) -> bool { + SYSCONFIG_VALUES.iter().find(|x| **x == key).is_some() +} + +fn cfg_line_for_var(key: &str, val: &str) -> Option { + if is_value(key) { + // is a value; suffix the key name with the value + Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) + } else if val != "0" { + // is a flag that isn't zero + Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) + } else { + // is a flag that is zero + None + } +} + +/// Run a python script using the specified interpreter binary. +fn run_python_script(interpreter: &str, script: &str) -> Result { + let out = Command::new(interpreter) + .args(&["-c", script]) + .stderr(Stdio::inherit()) + .output() + .map_err(|e| { + format!( + "Failed to run the python interpreter at {}: {}", + interpreter, e + ) + })?; + + if !out.status.success() { + return Err(format!("python script failed")); + } + + Ok(String::from_utf8(out.stdout).unwrap()) +} + +#[cfg(not(target_os = "macos"))] +#[cfg(not(target_os = "windows"))] +fn get_rustc_link_lib( + _: &PythonVersion, + ld_version: &str, + enable_shared: bool, +) -> Result { + if enable_shared { + Ok(format!("cargo:rustc-link-lib=python{}", ld_version)) + } else { + Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) + } +} + +#[cfg(target_os = "macos")] +fn get_macos_linkmodel() -> Result { + let script = r#" +import sysconfig + +if sysconfig.get_config_var("PYTHONFRAMEWORK"): + print("framework") +elif sysconfig.get_config_var("Py_ENABLE_SHARED"): + print("shared") +else: + print("static") +"#; + let out = run_python_script("python", script).unwrap(); + Ok(out.trim_end().to_owned()) +} + +#[cfg(target_os = "macos")] +fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, _: bool) -> Result { + // os x can be linked to a framework or static or dynamic, and + // Py_ENABLE_SHARED is wrong; framework means shared library + match get_macos_linkmodel().unwrap().as_ref() { + "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), + "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + other => Err(format!("unknown linkmodel {}", other)), + } +} + +/// Parse string as interpreter version. +fn get_interpreter_version(line: &str, implementation: &str) -> Result { + let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); + match version_re.captures(&line) { + Some(cap) => Ok(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: Some(cap.get(2).unwrap().as_str().parse().unwrap()), + implementation: match implementation { + "CPython" => PythonInterpreterKind::CPython, + "PyPy" => PythonInterpreterKind::PyPy, + _ => panic!(format!( + "Unsupported python implementation `{}`", + implementation + )), + }, + }), + None => Err(format!("Unexpected response to version query {}", line)), + } +} + +#[cfg(target_os = "windows")] +fn get_rustc_link_lib(version: &PythonVersion, _: &str, _: bool) -> Result { + // Py_ENABLE_SHARED doesn't seem to be present on windows. + Ok(format!( + "cargo:rustc-link-lib=pythonXY:python{}{}", + version.major, + match version.minor { + Some(minor) => minor.to_string(), + None => "".to_owned(), + } + )) +} + +/// Locate a suitable python interpreter and extract config from it. +/// +/// The following locations are checked in the order listed: +/// +/// 1. If `PYTHON_SYS_EXECUTABLE` is set, this intepreter is used and an error is raised if the +/// version doesn't match. +/// 2. `python` +/// 3. `python{major version}` +/// 4. `python{major version}.{minor version}` +/// +/// If none of the above works, an error is returned +fn find_interpreter_and_get_config( +) -> Result<(PythonVersion, HashMap, Vec), String> { + let version = version_from_env(); + + if let Some(sys_executable) = env::var_os("PYTHON_SYS_EXECUTABLE") { + let interpreter_path = sys_executable + .to_str() + .expect("Unable to get PYTHON_SYS_EXECUTABLE value"); + let (interpreter_version, lines) = get_config_from_interpreter(interpreter_path)?; + if version != None && version.as_ref().unwrap() != &interpreter_version { + panic!( + "Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ + \tmin version {} != found {}", + interpreter_path, + version.unwrap(), + interpreter_version + ); + } else { + return Ok(( + interpreter_version, + fix_config_map(get_config_vars(interpreter_path)?), + lines, + )); + } + }; + + let expected_version = version.unwrap_or(PythonVersion { + major: 3, + minor: None, + implementation: PythonInterpreterKind::CPython, + }); + + let binary_name = match expected_version.implementation { + PythonInterpreterKind::CPython => "python", + PythonInterpreterKind::PyPy => "pypy", + }; + + // check default python + let interpreter_path = binary_name; + + let (interpreter_version, lines) = get_config_from_interpreter(interpreter_path)?; + if expected_version == interpreter_version { + return Ok(( + interpreter_version, + fix_config_map(get_config_vars(interpreter_path)?), + lines, + )); + } + + let major_interpreter_path = &format!("python{}", expected_version.major); + let (interpreter_version, lines) = get_config_from_interpreter(major_interpreter_path)?; + if expected_version == interpreter_version { + return Ok(( + interpreter_version, + fix_config_map(get_config_vars(major_interpreter_path)?), + lines, + )); + } + + if let Some(minor) = expected_version.minor { + let minor_interpreter_path = &format!("python{}.{}", expected_version.major, minor); + let (interpreter_version, lines) = get_config_from_interpreter(minor_interpreter_path)?; + if expected_version == interpreter_version { + return Ok(( + interpreter_version, + fix_config_map(get_config_vars(minor_interpreter_path)?), + lines, + )); + } + } + + Err(format!("No python interpreter found")) +} + +/// Extract compilation vars from the specified interpreter. +fn get_config_from_interpreter(interpreter: &str) -> Result<(PythonVersion, Vec), String> { + let script = r#" +import sys +import sysconfig +import platform + +print(sys.version_info[0:2]) +print(sysconfig.get_config_var('LIBDIR')) +print(sysconfig.get_config_var('Py_ENABLE_SHARED')) +print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')) +print(sys.exec_prefix) +print(platform.python_implementation()) +"#; + let out = run_python_script(interpreter, script)?; + let lines: Vec = out.lines().map(|line| line.to_owned()).collect(); + let interpreter_version = get_interpreter_version(&lines[0], &lines[5])?; + Ok((interpreter_version, lines)) +} + +fn ensure_python_version_is_supported(version: &PythonVersion) -> Result<(), String> { + match (&version.implementation, version.major, version.minor) { + (PythonInterpreterKind::PyPy, 2, _) => { + Err("PyPy cpyext bindings is only supported for Python3".to_string()) + } + (_, 3, Some(minor)) if minor < PY3_MIN_MINOR => Err(format!( + "Python 3 required version is 3.{}, current version is 3.{}", + PY3_MIN_MINOR, minor + )), + _ => Ok(()), + } +} + +fn configure(interpreter_version: &PythonVersion, lines: Vec) -> Result<(String), String> { + ensure_python_version_is_supported(&interpreter_version).expect(&format!( + "Unsupported interpreter {:?}", + interpreter_version + )); + + let libpath: &str = &lines[1]; + let enable_shared: &str = &lines[2]; + let ld_version: &str = &lines[3]; + let exec_prefix: &str = &lines[4]; + + let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); + if !is_extension_module || cfg!(target_os = "windows") { + println!( + "{}", + get_rustc_link_lib(&interpreter_version, ld_version, enable_shared == "1").unwrap() + ); + if libpath != "None" { + println!("cargo:rustc-link-search=native={}", libpath); + } else if cfg!(target_os = "windows") { + println!("cargo:rustc-link-search=native={}\\libs", exec_prefix); + } + } + + let mut flags = String::new(); + + if interpreter_version.implementation == PythonInterpreterKind::PyPy { + println!("cargo:rustc-cfg=PyPy"); + flags += format!("CFG_PyPy").as_ref(); + }; + + if let PythonVersion { + major: 3, + minor: some_minor, + implementation: implementation, + } = interpreter_version + { + if env::var_os("CARGO_FEATURE_ABI3").is_some() { + println!("cargo:rustc-cfg=Py_LIMITED_API"); + } + + if let Some(minor) = some_minor { + for i in 5..(minor + 1) { + 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(); + } + return Ok(flags); +} + +/// Determine the python version we're supposed to be building +/// from the features passed via the environment. +/// +/// The environment variable can choose to omit a minor +/// version if the user doesn't care. +fn version_from_env() -> Option { + let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").unwrap(); + // sort env::vars so we get more explicit version specifiers first + // so if the user passes e.g. the python-3 feature and the python-3-5 + // feature, python-3-5 takes priority. + let interpreter_kind = if cfg!(feature = "pypy") { + PythonInterpreterKind::PyPy + } else { + PythonInterpreterKind::CPython + }; + + let mut vars = env::vars().collect::>(); + vars.sort_by(|a, b| b.cmp(a)); + for (key, _) in vars { + match re.captures(&key) { + Some(cap) => { + return Some(PythonVersion { + major: cap.get(1).unwrap().as_str().parse().unwrap(), + minor: match cap.get(3) { + Some(s) => Some(s.as_str().parse().unwrap()), + None => None, + }, + implementation: interpreter_kind, + }); + } + None => (), + } + } + None +} + +fn check_rustc_version() { + let ok_channel = supports_features(); + let ok_version = is_min_version(MIN_VERSION); + let ok_date = is_min_date(MIN_DATE); + + let print_version_err = |version: &str, date: &str| { + eprintln!( + "Installed version is: {} ({}). Minimum required: {} ({}).", + version, date, MIN_VERSION, MIN_DATE + ); + }; + + match (ok_channel, ok_version, ok_date) { + (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { + if !ok_channel { + eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); + print_version_err(&*version, &*date); + panic!("Aborting compilation due to incompatible compiler.") + } + + if !ok_version || !ok_date { + eprintln!("Error: pyo3 requires a more recent version of rustc."); + eprintln!("Use `rustup update` or your preferred method to update Rust"); + print_version_err(&*version, &*date); + panic!("Aborting compilation due to incompatible compiler.") + } + } + _ => { + println!( + "cargo:warning={}", + "pyo3 was unable to check rustc compatibility." + ); + println!( + "cargo:warning={}", + "Build may fail due to incompatible rustc version." + ); + } + } +} fn main() { check_rustc_version(); @@ -26,20 +612,26 @@ fn main() { // match the pkg-config package name, which is going to have a . in it). let cross_compiling = env::var("PYO3_CROSS_INCLUDE_DIR").is_ok() && env::var("PYO3_CROSS_LIB_DIR").is_ok(); - - let interpreter_config = if cross_compiling { - InterpreterConfig::from_cross_compile_info() - .expect("Error when loading cross compile settings.") + let (interpreter_version, mut config_map, lines) = if cross_compiling { + load_cross_compile_info() } else { - let version = PythonVersion::from_env().unwrap_or_default(); - find_interpreter(&version).expect("Interpreter not found.") - }; + find_interpreter_and_get_config() + } + .unwrap(); + + let flags = configure(&interpreter_version, lines).unwrap(); - let config_map = interpreter_config - .get_config_vars() - .expect("Failed to load configuration variables"); + if interpreter_version.implementation == PythonInterpreterKind::PyPy { + config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + config_map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); + config_map.insert("Py_UNICODE_SIZE".to_owned(), "4".to_owned()); + config_map.insert("Py_UNICODE_WIDE".to_owned(), "1".to_owned()); + } - let flags = interpreter_config.emit_cargo_vars(); + // WITH_THREAD is always on for 3.7 and PyPy + if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { + config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); + } for (key, val) in &config_map { match cfg_line_for_var(key, val) { diff --git a/pyo3build/Cargo.toml b/pyo3build/Cargo.toml deleted file mode 100644 index e07974e456e..00000000000 --- a/pyo3build/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "pyo3-build-utils" -version = "0.0.1" -description = "Build utilities from PyO3" -authors = ["PyO3 Project and Contributors ) -> Result { - let version = PythonVersion::from_interpreter(&interpreter)?; - InterpreterConfig::ensure_python_version_is_supported(&version)?; - - match version.kind { - PythonInterpreterKind::PyPy => { - let script = "\ -import sysconfig -import sys -import os - -def get_pypy_link_lib(): - data_dir = os.path.join(sysconfig.get_path('data')) - for r, dirs, files in os.walk(data_dir): - for f in files: - if 'libpypy-c' in f or 'libpypy3-c' in f: - return os.path.dirname(os.path.join(r, f)) - raise Exception('cannot locate libpypy') - -print(get_pypy_link_lib()) -print(sys.exec_prefix) -"; - let out = run_python_script(&interpreter, script)?; - let lines: Vec<&str> = out.lines().collect(); - - let abi_tag = run_python_script(&interpreter, GET_ABI_TAG)? - .trim_end() - .to_string(); - - Ok(InterpreterConfig { - version: version.clone(), - path: interpreter.as_ref().to_owned(), - libpath: lines[0].to_string(), - enable_shared: true, - ld_version: format!( - "{}.{}", - &version.major, - &version.minor.expect( - "Interpreter config was loaded from path, above, so this will be set" - ) - ) - .to_string(), - exec_prefix: lines[1].to_string(), - abi_version: abi_tag, - }) - } - PythonInterpreterKind::CPython => { - let script = "import sys; import sysconfig;\ - print(sysconfig.get_config_var('LIBDIR')); \ - print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \ - print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')); \ - print(sys.exec_prefix);"; - - let out = run_python_script(&interpreter, script)?; - let lines: Vec<&str> = out.lines().collect(); - - let abi_tag = run_python_script(&interpreter, GET_ABI_TAG)? - .trim_end() - .to_string(); - - Ok(InterpreterConfig { - version: version.clone(), - path: interpreter.as_ref().to_owned(), - libpath: lines[0].to_string(), - enable_shared: lines[1] == "1", - ld_version: lines[2].to_string(), - abi_version: abi_tag, - exec_prefix: lines[3].to_string(), - }) - } - } - } - - pub fn from_cross_compile_info() -> Result { - let python_include_dir = env::var("PYO3_CROSS_INCLUDE_DIR") - .map_err(|e| "Need to define `PYO3_CROSS_INCLUDE_DIR`")?; - - let python_include_dir = Path::new(&python_include_dir); - let patchlevel_defines = parse_header_defines(python_include_dir.join("patchlevel.h"))?; - - let version = PythonVersion::from_cross_env(&patchlevel_defines)?; - InterpreterConfig::ensure_python_version_is_supported(&version)?; - - let config_map = parse_header_defines(python_include_dir.join("pyconfig.h"))?; - - let enable_shared: bool = config_map - .get("Py_ENABLE_SHARED") - .ok_or_else(|| "Py_ENABLE_SHARED undefined".to_string())? - .parse() - .map_err(|e| "Failed to `Py_ENABLE_SHARED`".to_string())?; - - let libpath = env::var("PYO3_CROSS_LIB_DIR") - .map_err(|e| "PYO3_CROSS_LIB_DIR undefined".to_string())?; - - Ok(Self { - version: version.clone(), - // compatibility, not used when cross compiling. - path: PathBuf::new(), - libpath, - enable_shared, - ld_version: format!( - "{}.{}", - &version.major, - &version - .minor - .expect("Interpreter config was loaded from path, above, so this will be set") - ), - // compatibility, not used when cross compiling - exec_prefix: "".to_string(), - // compatibility, not used when cross compiling - abi_version: "".to_string(), - }) - } - - /// Checks if interpreter is supported by PyO3 - fn ensure_python_version_is_supported(version: &PythonVersion) -> Result<(), String> { - match (&version.kind, version.major, version.minor) { - (PythonInterpreterKind::PyPy, 2, _) => { - Err("PyPy cpyext bindings is only supported for Python3".to_string()) - } - (_, 3, Some(minor)) if minor < PY3_MIN_MINOR => Err(format!( - "Python 3 required version is 3.{}, current version is 3.{}", - PY3_MIN_MINOR, minor - )), - _ => Ok(()), - } - } - - fn is_pypy(&self) -> bool { - match self.version.kind { - PythonInterpreterKind::PyPy => true, - _ => false, - } - } - - fn is_py3(&self) -> bool { - self.version.major == 3 - } - - /// Examine python's compile flags to pass to cfg by launching - /// the interpreter and printing variables of interest from - /// sysconfig.get_config_vars. - #[cfg(not(target_os = "windows"))] - pub fn get_config_vars(&self) -> Result, String> { - let mut script = "import sysconfig; config = sysconfig.get_config_vars();".to_owned(); - - for k in SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()) { - script.push_str(&format!( - "print(config.get('{}', {}))", - k, - if is_value(k) { "None" } else { "0" } - )); - script.push_str(";"); - } - - let out = try!(run_python_script(&self.path, &script)); - - let split_stdout: Vec<&str> = out.trim_end().lines().collect(); - if split_stdout.len() != SYSCONFIG_VALUES.len() + SYSCONFIG_FLAGS.len() { - return Err(format!( - "python stdout len didn't return expected number of lines: {}", - split_stdout.len() - ) - .to_string()); - } - let all_vars = SYSCONFIG_FLAGS.iter().chain(SYSCONFIG_VALUES.iter()); - // let var_map: HashMap = HashMap::new(); - let mut all_vars = all_vars.zip(split_stdout.iter()).fold( - HashMap::new(), - |mut memo: HashMap, (&k, &v)| { - if !(v.to_owned() == "None" && is_value(k)) { - memo.insert(k.to_owned(), v.to_owned()); - } - memo - }, - ); - - if self.is_pypy() { - all_vars.insert("WITH_THREAD".to_owned(), "1".to_owned()); - all_vars.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - all_vars.insert("Py_UNICODE_SIZE".to_owned(), "4".to_owned()); - all_vars.insert("Py_UNICODE_WIDE".to_owned(), "1".to_owned()); - }; - - let debug = if let Some(val) = all_vars.get("Py_DEBUG") { - val == "1" - } else { - false - }; - - if debug { - all_vars.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); - all_vars.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); - all_vars.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); - } - - Ok(all_vars) - } - - #[cfg(target_os = "windows")] - pub fn get_config_vars(&self) -> Result, String> { - // sysconfig is missing all the flags on windows, so we can't actually - // query the interpreter directly for its build flags. - // - // For the time being, this is the flags as defined in the python source's - // PC\pyconfig.h. This won't work correctly if someone has built their - // python with a modified pyconfig.h - sorry if that is you, you will have - // to comment/uncomment the lines below. - let mut map: HashMap = HashMap::new(); - map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_WIDE".to_owned(), "0".to_owned()); - map.insert("WITH_THREAD".to_owned(), "1".to_owned()); - map.insert("Py_UNICODE_SIZE".to_owned(), "2".to_owned()); - - // This is defined #ifdef _DEBUG. The visual studio build seems to produce - // a specially named pythonXX_d.exe and pythonXX_d.dll when you build the - // Debug configuration, which this script doesn't currently support anyway. - // map.insert("Py_DEBUG", "1"); - - // Uncomment these manually if your python was built with these and you want - // the cfg flags to be set in rust. - // - // map.insert("Py_REF_DEBUG", "1"); - // map.insert("Py_TRACE_REFS", "1"); - // map.insert("COUNT_ALLOCS", 1"); - Ok(map) - } - - fn get_pypy_link_library_flag(&self) -> String { - let library_name = if self.is_py3() { "pypy3-c" } else { "pypy-c" }; - - // All modern PyPy versions with cpyext are compiled as shared libraries. - format!("cargo:rustc-link-lib={}", library_name) - } - - #[cfg(not(target_os = "macos"))] - #[cfg(not(target_os = "windows"))] - fn get_rustc_link_lib(&self) -> Result { - if self.is_pypy() { - return Ok(self.get_pypy_link_library_flag()); - } - - if self.enable_shared { - Ok(format!( - "cargo:rustc-link-lib=python{}", - self.ld_version - )) - } else { - Ok(format!( - "cargo:rustc-link-lib=static=python{}", - self.ld_version - )) - } - } - - #[cfg(target_os = "windows")] - fn get_rustc_link_lib(&self) -> Result { - if self.is_pypy() { - return Ok(self.get_pypy_link_library_flag()); - } - - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!( - "cargo:rustc-link-lib=pythonXY:python{}{}", - self.version.major, - match self.version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned(), - } - )) - } - - #[cfg(target_os = "macos")] - fn get_macos_linkmodel(&self) -> Result { - let script = "import sysconfig; print('framework' if sysconfig.get_config_var('PYTHONFRAMEWORK') else ('shared' if sysconfig.get_config_var('Py_ENABLE_SHARED') else 'static'));"; - let out = run_python_script(&self.path, script).unwrap(); - Ok(out.trim_end().to_owned()) - } - - #[cfg(target_os = "macos")] - fn get_rustc_link_lib(&self) -> Result { - if self.is_pypy() { - return Ok(self.get_pypy_link_library_flag()); - } - - // os x can be linked to a framework or static or dynamic, and - // Py_ENABLE_SHARED is wrong; framework means shared library - match self.get_macos_linkmodel().unwrap().as_ref() { - "static" => Ok(format!( - "cargo:rustc-link-lib=static=python{}", - self.ld_version - )), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", self.ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", self.ld_version)), - other => Err(format!("unknown linkmodel {}", other)), - } - } - - /// print cargo vars to stdout. - pub fn emit_cargo_vars(&self) -> String { - let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); - - println!("cargo:rustc-cfg={}", self.abi_version); - - if !is_extension_module || cfg!(target_os = "windows") { - println!("{}", self.get_rustc_link_lib().unwrap()); - - if self.libpath != "None" { - println!("cargo:rustc-link-search=native={}", self.libpath); - } else if cfg!(target_os = "windows") { - println!("cargo:rustc-link-search=native={}\\libs", self.exec_prefix); - } - } - - let mut flags = String::new(); - - if self.is_pypy() { - println!("cargo:rustc-cfg=PyPy"); - flags += format!("CFG_PyPy").as_ref(); - }; - - if self.is_py3() { - if env::var_os("CARGO_FEATURE_PEP_384").is_some() { - println!("cargo:rustc-cfg=Py_LIMITED_API"); - } - println!("cargo:rustc-cfg=Py_3"); - flags += "CFG_Py_3,"; - - if let Some(minor) = self.version.minor { - for i in 5..(minor + 1) { - println!("cargo:rustc-cfg=Py_3_{}", i); - flags += format!("CFG_Py_3_{},", i).as_ref(); - } - } - } else { - println!("cargo:rustc-cfg=Py_2"); - flags += format!("CFG_Py_2,").as_ref(); - } - - return flags; - } -} - -pub fn is_value(key: &str) -> bool { - SYSCONFIG_VALUES.iter().any(|x| *x == key) -} - -pub fn cfg_line_for_var(key: &str, val: &str) -> Option { - if is_value(key) { - // is a value; suffix the key name with the value - Some(format!("cargo:rustc-cfg={}=\"{}_{}\"\n", CFG_KEY, key, val)) - } else if val != "0" { - // is a flag that isn't zero - Some(format!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, key)) - } else { - // is a flag that is zero - None - } -} - -/// Locate a suitable python interpreter and extract config from it. -/// -/// The following locations are checked in the order listed: -/// -/// 1. If `PYTHON_SYS_EXECUTABLE` is set, this intepreter is used and an error is raised if the -/// version doesn't match. -/// 2. `python` -/// 3. `python{major version}` -/// 4. `python{major version}.{minor version}` -/// -/// If none of the above works, an error is returned -pub fn find_interpreter(expected_version: &PythonVersion) -> Result { - if let Some(interpreter_from_env) = env::var_os("PYTHON_SYS_EXECUTABLE") { - let interpreter_path_or_executable = interpreter_from_env - .to_str() - .expect("PYTHON_SYS_EXECUTABLE has non UTF-8 value"); - - let interpreter_path = - canonicalize_executable(interpreter_path_or_executable).expect(&format!( - "Could not find interpreter passed in PYTHON_SYS_EXECUTABLE={}\n", - interpreter_path_or_executable - )); - - let interpreter_config = InterpreterConfig::from_path(interpreter_path)?; - - if expected_version == &interpreter_config.version { - return Ok(interpreter_config); - } else { - return Err(format!( - "Unsupported python version in PYTHON_SYS_EXECUTABLE={}\n\ - \tmin version {} != found {}", - interpreter_path_or_executable, expected_version, interpreter_config.version - )); - } - } - - let possible_python_paths = expected_version.possible_binary_names(); - - for possible_path in possible_python_paths { - let interpreter_path = canonicalize_executable(&possible_path); - if let Some(path) = interpreter_path { - let interpreter_config = InterpreterConfig::from_path(path)?; - - if expected_version == &interpreter_config.version { - return Ok(interpreter_config); - } - } - } - - Err(format!("No python interpreter found")) -} - -// Code copied from python wheel package -const GET_ABI_TAG: &'static str = " -from sysconfig import get_config_var -import platform -import sys - -def get_impl_ver(): - impl_ver = get_config_var('py_version_nodot') - if not impl_ver or get_abbr_impl() == 'pp': - impl_ver = ''.join(map(str, get_impl_version_info())) - return impl_ver - -def get_flag(var, fallback, expected=True, warn=True): - val = get_config_var(var) - if val is None: - if warn: - warnings.warn('Config variable {0} is unset, Python ABI tag may ' - 'be incorrect'.format(var), RuntimeWarning, 2) - return fallback() - return val == expected - - -def get_abbr_impl(): - impl = platform.python_implementation() - if impl == 'PyPy': - return 'pp' - elif impl == 'Jython': - return 'jy' - elif impl == 'IronPython': - return 'ip' - elif impl == 'CPython': - return 'cp' - - raise LookupError('Unknown Python implementation: ' + impl) - -def get_abi_tag(): - soabi = get_config_var('SOABI') - impl = get_abbr_impl() - if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'): - d = '' - m = '' - u = '' - if get_flag('Py_DEBUG', - lambda: hasattr(sys, 'gettotalrefcount'), - warn=(impl == 'cp')): - d = 'd' - if get_flag('WITH_PYMALLOC', - lambda: impl == 'cp', - warn=(impl == 'cp')): - m = 'm' - if get_flag('Py_UNICODE_SIZE', - lambda: sys.maxunicode == 0x10ffff, - expected=4, - warn=(impl == 'cp' and - sys.version_info < (3, 3))) \ - and sys.version_info < (3, 3): - u = 'u' - abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u) - elif soabi and soabi.startswith('cpython-'): - abi = 'cp' + soabi.split('-')[1] - elif soabi: - abi = soabi.replace('.', '_').replace('-', '_') - else: - abi = None - return abi - -print(get_abi_tag()) -"; diff --git a/pyo3build/src/python_version.rs b/pyo3build/src/python_version.rs deleted file mode 100644 index fdbeb941e58..00000000000 --- a/pyo3build/src/python_version.rs +++ /dev/null @@ -1,169 +0,0 @@ -use regex::Regex; -use std::collections::HashMap; -use std::env; -use std::fmt::{self, Display}; -use std::path::Path; -use utils::{parse_header_defines, run_python_script}; - -#[derive(Debug, Clone)] -pub enum PythonInterpreterKind { - CPython, - PyPy, -} - -#[derive(Debug, Clone)] -pub struct PythonVersion { - pub major: u8, - // minor == None means any minor version will do - pub minor: Option, - // kind = "pypy" or "cpython" are supported, default to cpython - pub kind: PythonInterpreterKind, -} - -impl PartialEq for PythonVersion { - fn eq(&self, o: &PythonVersion) -> bool { - self.major == o.major && (self.minor.is_none() || self.minor == o.minor) - } -} - -impl fmt::Display for PythonVersion { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - try!(self.major.fmt(f)); - try!(f.write_str(".")); - match self.minor { - Some(minor) => try!(minor.fmt(f)), - None => try!(f.write_str("*")), - }; - Ok(()) - } -} - -impl Default for PythonVersion { - fn default() -> Self { - PythonVersion { - major: 3, - minor: None, - kind: PythonInterpreterKind::CPython, - } - } -} - -impl PythonVersion { - /// Determine the python version we're supposed to be building - /// from the features passed via the environment. - /// - /// The environment variable can choose to omit a minor - /// version if the user doesn't care. - pub fn from_env() -> Result { - let re = Regex::new(r"CARGO_FEATURE_PYTHON(\d+)(_(\d+))?").expect("This is a valid regex"); - - let interpreter_kind = if cfg!(feature = "pypy") { - PythonInterpreterKind::PyPy - } else { - PythonInterpreterKind::CPython - }; - - // sort env::vars so we get more explicit version specifiers first - // so if the user passes e.g. the python-3 feature and the python-3-5 - // feature, python-3-5 takes priority. - let mut vars = env::vars().collect::>(); - - vars.sort_by(|a, b| b.cmp(&a)); - for (key, _) in vars { - match re.captures(&key) { - Some(cap) => { - return Ok(PythonVersion { - kind: interpreter_kind, - major: cap.get(1).expect("must match").as_str().parse().unwrap(), - minor: match cap.get(3) { - Some(s) => Some(s.as_str().parse().unwrap()), - None => None, - }, - }); - } - None => (), - } - } - - Err( - "Python version feature was not found. At least one python version \ - feature must be enabled." - .to_owned(), - ) - } - - pub fn from_cross_env(header_defines: &HashMap) -> Result { - let major = header_defines - .get("PY_MAJOR_VERSION") - .and_then(|major| major.parse::().ok()) - .ok_or("PY_MAJOR_VERSION undefined".to_string())?; - - let minor = header_defines - .get("PY_MINOR_VERSION") - .and_then(|minor| minor.parse::().ok()) - .ok_or("PY_MINOR_VERSION undefined".to_string())?; - - Ok(PythonVersion { - major, - minor: Some(minor), - kind: PythonInterpreterKind::CPython, - }) - } - - /// Returns a name of possible python binary names. - /// Ex. vec![python, python3, python3.5] - pub fn possible_binary_names(&self) -> Vec { - let mut possible_names = vec![]; - - let binary_name = match self.kind { - PythonInterpreterKind::CPython => "python", - PythonInterpreterKind::PyPy => "pypy" - }; - - possible_names.push(binary_name.to_owned()); - possible_names.push(format!("{}{}", binary_name, self.major)); - - if let Some(minor) = self.minor { - possible_names.push(format!("{}{}.{}", binary_name, self.major, minor)); - } - - possible_names - } - - pub fn from_interpreter(interpreter_path: impl AsRef) -> Result { - let script = "import sys;\ - print('__pypy__' in sys.builtin_module_names);\ - print(sys.version_info[0:2]);"; - - let out = run_python_script(interpreter_path.as_ref(), script)?; - let lines: Vec<&str> = out.lines().collect(); - - let is_pypy: bool = lines[0] - .to_ascii_lowercase() - .parse() - .expect("Should print a bool"); - let (major, minor) = PythonVersion::parse_interpreter_version(lines[1])?; - - Ok(Self { - major, - minor: Some(minor), - kind: if is_pypy { - PythonInterpreterKind::PyPy - } else { - PythonInterpreterKind::CPython - }, - }) - } - - /// Parse string as interpreter version. - fn parse_interpreter_version(line: &str) -> Result<(u8, u8), String> { - let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); - match version_re.captures(&line) { - Some(cap) => Ok(( - cap.get(1).unwrap().as_str().parse().unwrap(), - cap.get(2).unwrap().as_str().parse().unwrap(), - )), - None => Err(format!("Unexpected response to version query {}", line)), - } - } -} diff --git a/pyo3build/src/rustc_version.rs b/pyo3build/src/rustc_version.rs deleted file mode 100644 index afa2968892c..00000000000 --- a/pyo3build/src/rustc_version.rs +++ /dev/null @@ -1,46 +0,0 @@ -extern crate version_check; -use self::version_check::{is_min_date, is_min_version, supports_features}; - -// Specifies the minimum nightly version needed to compile pyo3. -const MIN_DATE: &'static str = "2018-11-02"; -const MIN_VERSION: &'static str = "1.32.0-nightly"; - -pub fn check_rustc_version() { - let ok_channel = supports_features(); - let ok_version = is_min_version(MIN_VERSION); - let ok_date = is_min_date(MIN_DATE); - - let print_version_err = |version: &str, date: &str| { - eprintln!( - "Installed version is: {} ({}). Minimum required: {} ({}).", - version, date, MIN_VERSION, MIN_DATE - ); - }; - - match (ok_channel, ok_version, ok_date) { - (Some(ok_channel), Some((ok_version, version)), Some((ok_date, date))) => { - if !ok_channel { - eprintln!("Error: pyo3 requires a nightly or dev version of Rust."); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - - if !ok_version || !ok_date { - eprintln!("Error: pyo3 requires a more recent version of rustc."); - eprintln!("Use `rustup update` or your preferred method to update Rust"); - print_version_err(&*version, &*date); - panic!("Aborting compilation due to incompatible compiler.") - } - } - _ => { - println!( - "cargo:warning={}", - "pyo3 was unable to check rustc compatibility." - ); - println!( - "cargo:warning={}", - "Build may fail due to incompatible rustc version." - ); - } - } -} diff --git a/pyo3build/src/utils.rs b/pyo3build/src/utils.rs deleted file mode 100644 index eb62fbc799b..00000000000 --- a/pyo3build/src/utils.rs +++ /dev/null @@ -1,83 +0,0 @@ -use std::env; -use std::path::{Path, PathBuf}; -use std::process::Command; -use std::collections::HashMap; -use regex::Regex; -use std::fs::File; -use std::io::{BufReader, BufRead}; - -pub fn canonicalize_executable

(exe_name: P) -> Option -where - P: AsRef, -{ - env::var_os("PATH").and_then(|paths| { - env::split_paths(&paths) - .filter_map(|dir| { - let full_path = dir.join(&exe_name); - if full_path.is_file() { - Some(full_path) - } else { - None - } - }) - .next() - }) -} - -/// Attempts to parse the header at the given path, returning a map of definitions to their values. -/// Each entry in the map directly corresponds to a `#define` in the given header. -pub fn parse_header_defines>(header_path: P) -> Result, String> { - // This regex picks apart a C style, single line `#define` statement into an identifier and a - // value. e.g. for the line `#define Py_DEBUG 1`, this regex will capture `Py_DEBUG` into - // `ident` and `1` into `value`. - let define_regex = - Regex::new(r"^\s*#define\s+(?P[a-zA-Z0-9_]+)\s+(?P.+)\s*$").unwrap(); - - let header_file = File::open(header_path.as_ref()).map_err(|e| e.to_string())?; - let header_reader = BufReader::new(&header_file); - - let definitions = header_reader - .lines() - .filter_map(|maybe_line| { - let line = maybe_line.unwrap_or_else(|err| { - panic!("failed to read {}: {}", header_path.as_ref().display(), err); - }); - let captures = define_regex.captures(&line)?; - - if captures.name("ident").is_some() && captures.name("value").is_some() { - Some(( - captures.name("ident").unwrap().as_str().to_owned(), - captures.name("value").unwrap().as_str().to_owned(), - )) - } else { - None - } - }) - .collect(); - - Ok(definitions) -} - -/// Run a python script using the specified interpreter binary. -/// Returns an error if python printer anything to stderr. -pub fn run_python_script( - interpreter_path: impl AsRef, - script: &str, -) -> Result { - let mut cmd = Command::new(interpreter_path.as_ref()); - cmd.arg("-c").arg(script); - - let out = cmd - .output() - .map_err(|e| format!("failed to run python interpreter `{:?}`: {}", cmd, e))?; - - if !out.status.success() { - let stderr = String::from_utf8(out.stderr).unwrap(); - let mut msg = format!("python script failed with stderr:\n\n"); - msg.push_str(&stderr); - return Err(msg); - } - - let out = String::from_utf8(out.stdout).unwrap(); - return Ok(out); -} diff --git a/src/type_object.rs b/src/type_object.rs index c8ad386d0d4..7fe33e151ea 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -307,7 +307,7 @@ where // PyPy will segfault if passed only a nul terminator as `tp_doc`. // ptr::null() is OK though. - if T::DESCRIPTION.len() == "\0" { + if T::DESCRIPTION == "\0" { type_object.tp_doc = ptr::null(); } else { type_object.tp_doc = T::DESCRIPTION.as_ptr() as *const _; From f7d208cdb2d87f592acfd7e38042849fcf54c12b Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 15:45:22 +0200 Subject: [PATCH 094/138] revert changes that cause an additional GC bug --- examples/rustapi_module/tests/test_subclassing.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/rustapi_module/tests/test_subclassing.py b/examples/rustapi_module/tests/test_subclassing.py index aaf27b6f3eb..8c086b75dec 100644 --- a/examples/rustapi_module/tests/test_subclassing.py +++ b/examples/rustapi_module/tests/test_subclassing.py @@ -1,10 +1,9 @@ from rustapi_module.subclassing import Subclassable -# should not raise -def test_subclassing_works(): - class SomeSubClass(Subclassable): - pass +class SomeSubClass(Subclassable): + pass - a = SomeSubClass() - _b = str(a) + repr(a) + +a = SomeSubClass() +_b = str(a) + repr(a) From 920caa70c1bf0aa185f730e200d9fc975506c44e Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 16:04:47 +0200 Subject: [PATCH 095/138] prevented buggy test from failing pypy --- examples/rustapi_module/tests/test_subclassing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/rustapi_module/tests/test_subclassing.py b/examples/rustapi_module/tests/test_subclassing.py index 8c086b75dec..062710f6fa8 100644 --- a/examples/rustapi_module/tests/test_subclassing.py +++ b/examples/rustapi_module/tests/test_subclassing.py @@ -1,9 +1,13 @@ +import platform + from rustapi_module.subclassing import Subclassable +PYPY = platform.python_implementation() == 'PyPy' class SomeSubClass(Subclassable): pass -a = SomeSubClass() -_b = str(a) + repr(a) +if not PYPY: + a = SomeSubClass() + _b = str(a) + repr(a) \ No newline at end of file From db709d1d361319df160410c93abb33fa376f21f3 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 16:08:53 +0200 Subject: [PATCH 096/138] removed unused comment --- src/ffi3/object.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 87ab8e2aad2..afd1efd594a 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -525,7 +525,6 @@ mod typeobject { ob_refcnt: 1, ob_pypy_link: 0, ob_type: ptr::null_mut(), -// ob_size: mem::size_of::() as isize, ob_size: 0, tp_name: ptr::null(), tp_basicsize: 0, From 2a882d9a6aa9051476d256c9a9b86281b018a731 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 16:20:56 +0200 Subject: [PATCH 097/138] =?UTF-8?q?don=E2=80=99t=20run=20coverage=20on=20p?= =?UTF-8?q?ypy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci/travis/cover.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ci/travis/cover.sh b/ci/travis/cover.sh index e9981093ecb..763bd0abf4c 100755 --- a/ci/travis/cover.sh +++ b/ci/travis/cover.sh @@ -2,6 +2,12 @@ set -ex +### PyPy does not run the test suite ########################################### + +if ! [[ $FEATURES == *"pypy"* ]]; then + exit 0 +fi + ### Run kcov in parallel ####################################################### rm -f target/debug/pyo3*.d From 5d90545f78e5be0c9dd148f83b19c186279f8ece Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 20 Mar 2019 20:42:47 +0200 Subject: [PATCH 098/138] removed some erroneous symbols from function calls which are actually macros --- build.rs | 4 +++- src/ffi3/bytearrayobject.rs | 6 +++--- src/ffi3/complexobject.rs | 4 ++-- src/ffi3/genobject.rs | 3 --- src/ffi3/longobject.rs | 3 ++- src/ffi3/modsupport.rs | 1 - 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/build.rs b/build.rs index af546518dba..508a1a54d7e 100644 --- a/build.rs +++ b/build.rs @@ -621,6 +621,8 @@ fn main() { let flags = configure(&interpreter_version, lines).unwrap(); + // These flags need to be enabled manually for PyPy, because it does not expose + // them in `sysconfig.get_config_vars()` if interpreter_version.implementation == PythonInterpreterKind::PyPy { config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); config_map.insert("Py_USING_UNICODE".to_owned(), "1".to_owned()); @@ -628,7 +630,7 @@ fn main() { config_map.insert("Py_UNICODE_WIDE".to_owned(), "1".to_owned()); } - // WITH_THREAD is always on for 3.7 and PyPy + // WITH_THREAD is always on for 3.7 if interpreter_version.major == 3 && interpreter_version.minor.unwrap_or(0) >= 7 { config_map.insert("WITH_THREAD".to_owned(), "1".to_owned()); } diff --git a/src/ffi3/bytearrayobject.rs b/src/ffi3/bytearrayobject.rs index e8740626688..2b661109dd4 100644 --- a/src/ffi3/bytearrayobject.rs +++ b/src/ffi3/bytearrayobject.rs @@ -6,16 +6,16 @@ use std::os::raw::{c_char, c_int}; extern "C" { #[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")] pub static mut PyByteArray_Type: PyTypeObject; + pub static mut PyByteArrayIter_Type: PyTypeObject; } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyByteArray_Check")] pub unsafe fn PyByteArray_Check(op: *mut PyObject) -> c_int { - #[cfg_attr(PyPy, link_name = "PyPyObject_Type")] PyObject_TypeCheck(op, &mut PyByteArray_Type) } -#[cfg_attr(PyPy, link_name = "PyPyByteArray_CheckExact")] + +#[inline] pub unsafe fn PyByteArray_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyByteArray_Type) as c_int } diff --git a/src/ffi3/complexobject.rs b/src/ffi3/complexobject.rs index 4afb3105134..62fc2004938 100644 --- a/src/ffi3/complexobject.rs +++ b/src/ffi3/complexobject.rs @@ -7,13 +7,11 @@ extern "C" { pub static mut PyComplex_Type: PyTypeObject; } -#[cfg_attr(PyPy, link_name = "PyPyComplex_Check")] #[inline] pub unsafe fn PyComplex_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyComplex_Type) } -#[cfg_attr(PyPy, link_name = "PyPyComplex_CheckExact")] #[inline] pub unsafe fn PyComplex_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyComplex_Type) as c_int @@ -55,6 +53,8 @@ extern "C" { 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; + #[cfg_attr(PyPy, link_name = "PyPyComplex_FromCComplex")] pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; + #[cfg_attr(PyPy, link_name = "PyPyComplex_AsCComplex")] pub fn PyComplex_AsCComplex(op: *mut PyObject) -> Py_complex; } diff --git a/src/ffi3/genobject.rs b/src/ffi3/genobject.rs index 8194ee3c2e5..d36b5942219 100644 --- a/src/ffi3/genobject.rs +++ b/src/ffi3/genobject.rs @@ -24,13 +24,11 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyGen_Check")] pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyGen_Type) } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyGen_CheckExact")] pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } @@ -47,7 +45,6 @@ extern "C" { } #[inline] -#[cfg_attr(PyPy, link_name = "PyPyCoro_Check")] pub unsafe fn PyCoro_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, &mut PyCoro_Type) } diff --git a/src/ffi3/longobject.rs b/src/ffi3/longobject.rs index a0befc79ecd..1bd3076e4e2 100644 --- a/src/ffi3/longobject.rs +++ b/src/ffi3/longobject.rs @@ -14,8 +14,8 @@ extern "C" { #[cfg_attr(PyPy, link_name = "PyPyLong_Type")] pub static mut PyLong_Type: PyTypeObject; } + #[inline] -#[inline(always)] pub unsafe fn PyLong_Check(op: *mut PyObject) -> c_int { PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) } @@ -81,6 +81,7 @@ extern "C" { #[cfg(not(Py_LIMITED_API))] #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { + #[cfg_attr(PyPy, link_name = "_PyPyLong_FromByteArray")] pub fn _PyLong_FromByteArray( bytes: *const c_uchar, n: size_t, diff --git a/src/ffi3/modsupport.rs b/src/ffi3/modsupport.rs index 0f995d49d22..19bfebfe8e3 100644 --- a/src/ffi3/modsupport.rs +++ b/src/ffi3/modsupport.rs @@ -86,7 +86,6 @@ extern "C" { #[cfg(py_sys_config = "Py_TRACE_REFS")] #[inline] -#[cfg_attr(PyPy, link_name = "PyPyModule_Create2")] pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { PyModule_Create2TraceRefs(module, apiver) } From 41a1d5a601e737c9aba59c4fc85c1758049e79a3 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 21 Mar 2019 09:31:15 +0200 Subject: [PATCH 099/138] restore py37 pyunicode missing def --- src/ffi3/unicodeobject.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ffi3/unicodeobject.rs b/src/ffi3/unicodeobject.rs index 889bc1c23a3..b50dd00b42d 100644 --- a/src/ffi3/unicodeobject.rs +++ b/src/ffi3/unicodeobject.rs @@ -137,9 +137,15 @@ extern "C" { pub fn PyUnicode_FromOrdinal(ordinal: c_int) -> *mut PyObject; pub fn PyUnicode_ClearFreeList() -> c_int; #[cfg(not(Py_LIMITED_API))] + #[cfg(Py_3_7)] + pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *const c_char; + #[cfg(not(Py_3_7))] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8AndSize")] pub fn PyUnicode_AsUTF8AndSize(unicode: *mut PyObject, size: *mut Py_ssize_t) -> *mut c_char; #[cfg(not(Py_LIMITED_API))] + #[cfg(Py_3_7)] + pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *const c_char; + #[cfg(not(Py_3_7))] #[cfg_attr(PyPy, link_name = "PyPyUnicode_AsUTF8")] pub fn PyUnicode_AsUTF8(unicode: *mut PyObject) -> *mut c_char; #[cfg_attr(PyPy, link_name = "PyPyUnicode_GetDefaultEncoding")] From d4ecf8cd0171689866ca2fe82ea9a92345140dbc Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 21 Mar 2019 10:11:24 +0200 Subject: [PATCH 100/138] use only `link_name` in PyPy specific declarations --- src/ffi/datetime.rs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index 18049dc9108..f4bc59c5bb7 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -107,41 +107,40 @@ pub struct PyDateTime_CAPI { #[cfg(PyPy)] extern "C" { - #[cfg_attr(PyPy, link_name = "_PyPyDateTime_Import")] + #[link_name = "_PyPyDateTime_Import"] pub fn PyDateTime_Import() -> &'static PyDateTime_CAPI; - - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_HOUR")] + #[link_name = "PyPyDateTime_DATE_GET_HOUR"] pub fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MICROSECOND")] + #[link_name = "PyPyDateTime_DATE_GET_MICROSECOND"] pub fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_MINUTE")] + #[link_name = "PyPyDateTime_DATE_GET_MINUTE"] pub fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DATE_GET_SECOND")] + #[link_name = "PyPyDateTime_DATE_GET_SECOND"] pub fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_DAYS")] + #[link_name = "PyPyDateTime_DELTA_GET_DAYS"] pub fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_MICROSECONDS")] + #[link_name = "PyPyDateTime_DELTA_GET_MICROSECONDS"] pub fn PyDateTime_DELTA_GET_MICROSECONDS(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_DELTA_GET_SECONDS")] + #[link_name = "PyPyDateTime_DELTA_GET_SECONDS"] pub fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_DAY")] + #[link_name = "PyPyDateTime_GET_DAY"] pub fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_MONTH")] + #[link_name = "PyPyDateTime_GET_MONTH"] pub fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_GET_YEAR")] + #[link_name = "PyPyDateTime_GET_YEAR"] pub fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_HOUR")] + #[link_name = "PyPyDateTime_TIME_GET_HOUR"] pub fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MICROSECOND")] + #[link_name = "PyPyDateTime_TIME_GET_MICROSECOND"] pub fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_MINUTE")] + #[link_name = "PyPyDateTime_TIME_GET_MINUTE"] pub fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_TIME_GET_SECOND")] + #[link_name = "PyPyDateTime_TIME_GET_SECOND"] pub fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int; - #[cfg_attr(PyPy, link_name = "PyPyDate_FromTimestamp")] + #[link_name = "PyPyDate_FromTimestamp"] pub fn PyDate_FromTimestamp(args: *mut PyObject) -> *mut PyObject; - #[cfg_attr(PyPy, link_name = "PyPyDateTime_FromTimestamp")] + #[link_name = "PyPyDateTime_FromTimestamp"] pub fn PyDateTime_FromTimestamp(args: *mut PyObject) -> *mut PyObject; } From fc787e7a395487c8ac9a323bb65eda6728779d63 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 21 Mar 2019 10:12:12 +0200 Subject: [PATCH 101/138] only setup PyPy when testing against PyPy --- ci/travis/setup.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index fd529133c24..2a80323a8ec 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -37,11 +37,13 @@ fi ### Setup PyPy ################################################################ -wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ -/bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ -/opt/anaconda/bin/conda install --quiet --yes conda && \ -/opt/anaconda/bin/conda config --system --add channels conda-forge && \ -/opt/anaconda/bin/conda init bash && \ -/opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ -/opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ -/opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox \ No newline at end of file +if ! [[ $FEATURES == *"pypy"* ]]; then + wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ + /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ + /opt/anaconda/bin/conda install --quiet --yes conda && \ + /opt/anaconda/bin/conda config --system --add channels conda-forge && \ + /opt/anaconda/bin/conda init bash && \ + /opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ + /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ + /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox +fi \ No newline at end of file From 2a75e19a2bcb68948884398e5a86feca92120272 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 21 Mar 2019 10:36:34 +0200 Subject: [PATCH 102/138] annotation that was eaten during merge --- src/ffi3/pythonrun.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ffi3/pythonrun.rs b/src/ffi3/pythonrun.rs index c6c629ebd81..2ee8e2a5d56 100644 --- a/src/ffi3/pythonrun.rs +++ b/src/ffi3/pythonrun.rs @@ -166,6 +166,7 @@ extern "C" { #[cfg(not(PyPy))] pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject; #[cfg(PyPy)] + #[cfg(not(Py_LIMITED_API))] #[cfg_attr(PyPy, link_name = "PyPy_CompileStringFlags")] pub fn Py_CompileStringFlags( string: *const c_char, From e829747b4bd9052c12bf483165cf38b85af98e03 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 21 Mar 2019 11:54:09 +0200 Subject: [PATCH 103/138] remove change to comment by mistake + unnecessary changes to cargo.toml --- Cargo.toml | 9 +++++---- examples/rustapi_module/requirements-dev.txt | 1 - src/ffi/datetime.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bccf6c4b8de..39d72be787c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,14 +27,15 @@ mashup = "0.1.9" num-complex = { version = "0.2.1", optional = true } inventory = "0.1.3" -[build-dependencies] -version_check = "0.1.5" -regex = "1.1.0" - [dev-dependencies] assert_approx_eq = "1.1.0" docmatic = "0.1.2" indoc = "0.3.1" + +[build-dependencies] +regex = "1.1.0" +version_check = "0.1.5" + [features] default = [] diff --git a/examples/rustapi_module/requirements-dev.txt b/examples/rustapi_module/requirements-dev.txt index 1e86e726d72..b1000dbbb17 100644 --- a/examples/rustapi_module/requirements-dev.txt +++ b/examples/rustapi_module/requirements-dev.txt @@ -1,4 +1,3 @@ hypothesis>=3.55 pytest>=3.5.0 setuptools-rust>=0.10.2 -pytest-faulthandler>=1.5.0 diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index f4bc59c5bb7..02e1e15676f 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -314,7 +314,7 @@ pub unsafe fn PyTime_CheckExact(op: *mut PyObject) -> c_int { } #[inline] -/// Check if `op` is a `PyDateTimeAPI.DetaType` or subtype.Date_FromTimestamp +/// Check if `op` is a `PyDateTimeAPI.DetaType` or subtype. pub unsafe fn PyDelta_Check(op: *mut PyObject) -> c_int { PyObject_TypeCheck(op, PyDateTimeAPI.DeltaType) as c_int } From 2d20f7208176b0a7d33ea406bea298a9693848c6 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 25 Mar 2019 21:29:46 +0200 Subject: [PATCH 104/138] xfail dates test only on pypy --- examples/rustapi_module/tests/test_datetime.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/rustapi_module/tests/test_datetime.py b/examples/rustapi_module/tests/test_datetime.py index 71cdf4181e8..9fc5b230cd2 100644 --- a/examples/rustapi_module/tests/test_datetime.py +++ b/examples/rustapi_module/tests/test_datetime.py @@ -83,9 +83,11 @@ def test_invalid_date_fails(): rdt.make_date(2017, 2, 30) -# Feeding this tests dates from too early will cause `get_timestamp` to raise. -@given(d=st.dates(min_value=pdt.date(1900, 1, 1))) +@given(d=st.dates()) def test_date_from_timestamp(d): + if PYPY and d < pdt.date(1900, 1, 1): + pytest.xfail("get_timestamp will raise on PyPy with dates before 1900") + ts = get_timestamp(pdt.datetime.combine(d, pdt.time(0))) assert rdt.date_from_timestamp(int(ts)) == pdt.date.fromtimestamp(ts) @@ -220,9 +222,11 @@ def test_datetime_typeerror(): rdt.make_datetime("2011", 1, 1, 0, 0, 0, 0) -# Feeding this tests dates from too early will cause `get_timestamp` to raise. -@given(dt=st.datetimes(min_value=pdt.datetime(1900, 1, 1))) +@given(dt=st.datetimes()) def test_datetime_from_timestamp(dt): + if PYPY and dt < pdt.datetime(1900, 1, 1): + pytest.xfail("get_timestamp will raise on PyPy with dates before 1900") + ts = get_timestamp(dt) assert rdt.datetime_from_timestamp(ts) == pdt.datetime.fromtimestamp(ts) From 27fb0f3fd0c685d7a72a52239d605e9fbeacf5e2 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 25 Mar 2019 21:43:30 +0200 Subject: [PATCH 105/138] changed comment to be a little more helpful --- src/ffi/datetime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index 02e1e15676f..1e52298995f 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -71,13 +71,13 @@ pub struct PyDateTime_CAPI { pub TimeZone_FromTimeZone: unsafe extern "C" fn(offset: *mut PyObject, name: *mut PyObject) -> *mut PyObject, - // Defined for PyPy as a separate symbol + // Defined for PyPy as `PyDateTime_FromTimestamp` pub DateTime_FromTimestamp: unsafe extern "C" fn( cls: *mut PyTypeObject, args: *mut PyObject, kwargs: *mut PyObject, ) -> *mut PyObject, - // Defined for PyPy as a separate symbol + // Defined for PyPy as `PyDate_FromTimestamp` pub Date_FromTimestamp: unsafe extern "C" fn(cls: *mut PyTypeObject, args: *mut PyObject) -> *mut PyObject, #[cfg(Py_3_6)] From 75c0748644e9b85fa5ea2e76a8f2eb89559bc409 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Mon, 25 Mar 2019 22:45:41 +0200 Subject: [PATCH 106/138] cleaned up some warnings --- build.rs | 2 +- src/ffi3/object.rs | 5 +++-- src/type_object.rs | 2 +- src/types/datetime.rs | 4 ---- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 508a1a54d7e..01447d040eb 100644 --- a/build.rs +++ b/build.rs @@ -501,7 +501,7 @@ fn configure(interpreter_version: &PythonVersion, lines: Vec) -> Result< if let PythonVersion { major: 3, minor: some_minor, - implementation: implementation, + implementation: _, } = interpreter_version { if env::var_os("CARGO_FEATURE_ABI3").is_some() { diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index afd1efd594a..d2aa773ebae 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -73,12 +73,13 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { (*ob).ob_refcnt } - #[cfg(PyPy)] pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject { return crate::ffi3::pyerrors::PyErr_Format( crate::ffi3::pyerrors::PyExc_TypeError, - CStr::from_bytes_with_nul(b"'%.200s' object is not iterable\0").unwrap().as_ptr(), + CStr::from_bytes_with_nul(b"'%.200s' object is not iterable\0") + .unwrap() + .as_ptr(), Py_TYPE((*(arg1 as *mut PyTypeObject)).tp_name as *mut PyObject), ); } diff --git a/src/type_object.rs b/src/type_object.rs index 7fe33e151ea..8717b9a5b85 100644 --- a/src/type_object.rs +++ b/src/type_object.rs @@ -13,7 +13,7 @@ use crate::Python; use crate::{class, ffi, gil}; use class::methods::PyMethodsProtocol; use std::collections::HashMap; -use std::ffi::{CStr, CString}; +use std::ffi::CString; use std::os::raw::c_void; use std::ptr::{self, NonNull}; diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 2d62193108b..49a8d858d66 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -7,13 +7,10 @@ use crate::err::PyResult; use crate::ffi; -use crate::ffi::datetime::PyDateTime_CAPI; #[cfg(PyPy)] use crate::ffi::datetime::{PyDateTime_FromTimestamp, PyDate_FromTimestamp}; use crate::ffi::PyDateTimeAPI; -use crate::ffi::PyFloat_FromDouble; -use crate::ffi::Py_BuildValue; use crate::ffi::{PyDateTime_Check, PyDate_Check, PyDelta_Check, PyTZInfo_Check, PyTime_Check}; #[cfg(Py_3_6)] use crate::ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; @@ -36,7 +33,6 @@ use crate::AsPyPointer; use crate::Python; use crate::ToPyObject; use std::os::raw::c_int; -use std::os::raw::c_long; use std::ptr; /// Access traits From acc04bcf6909bfb45c3fb8028cc216b59a5f46bb Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 28 Mar 2019 19:30:09 +0200 Subject: [PATCH 107/138] Update src/ffi3/ceval.rs Co-Authored-By: omerbenamram --- src/ffi3/ceval.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index 4376c6807e6..fa381834d47 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -52,7 +52,6 @@ extern "C" { static mut _Py_CheckRecursionLimit: c_int; } -//#[cfg_attr(PyPy, link_name = "PyPy_EnterRecursiveCall")] // TODO: Py_EnterRecursiveCall etc. #[cfg(Py_3_6)] pub type _PyFrameEvalFunction = From 1649156c2424cc48d9a20b0b1037f3c854c9324a Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 19:31:21 +0200 Subject: [PATCH 108/138] @konstin PR notes --- build.rs | 6 ------ src/ffi3/object.rs | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/build.rs b/build.rs index 01447d040eb..c3b38ed227a 100644 --- a/build.rs +++ b/build.rs @@ -532,12 +532,6 @@ fn version_from_env() -> Option { // sort env::vars so we get more explicit version specifiers first // so if the user passes e.g. the python-3 feature and the python-3-5 // feature, python-3-5 takes priority. - let interpreter_kind = if cfg!(feature = "pypy") { - PythonInterpreterKind::PyPy - } else { - PythonInterpreterKind::CPython - }; - let mut vars = env::vars().collect::>(); vars.sort_by(|a, b| b.cmp(a)); for (key, _) in vars { diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index d2aa773ebae..cba419ce2dd 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -1,4 +1,5 @@ use crate::ffi3::pyport::{Py_hash_t, Py_ssize_t}; +use std::ffi::CStr; use std::mem; use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; use std::ptr; @@ -84,12 +85,12 @@ pub unsafe fn _PyObject_NextNotImplemented(arg1: *mut PyObject) -> *mut PyObject ); } -#[inline(always)] +#[inline] pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject { (*ob).ob_type } -#[inline(always)] +#[inline] pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t { (*(ob as *mut PyVarObject)).ob_size } @@ -699,7 +700,6 @@ mod typeobject { // The exported types depend on whether Py_LIMITED_API is set pub use self::typeobject::*; -use std::ffi::CStr; #[repr(C)] #[derive(Copy, Clone)] From c531532cc2cf1ef7fce71dc30497038c73852ff9 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 19:45:51 +0200 Subject: [PATCH 109/138] rustfmt --- examples/rustapi_module/src/othermod.rs | 2 +- src/ffi3/ceval.rs | 5 ++++- src/ffi3/pyerrors.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/rustapi_module/src/othermod.rs b/examples/rustapi_module/src/othermod.rs index de1c96904c2..dd43694dbbd 100644 --- a/examples/rustapi_module/src/othermod.rs +++ b/examples/rustapi_module/src/othermod.rs @@ -32,7 +32,7 @@ fn double(x: i32) -> i32 { #[pymodule] fn othermod(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(double))?; - + m.add_class::()?; m.add("USIZE_MIN", usize::min_value())?; diff --git a/src/ffi3/ceval.rs b/src/ffi3/ceval.rs index fa381834d47..3c77de606cf 100644 --- a/src/ffi3/ceval.rs +++ b/src/ffi3/ceval.rs @@ -64,7 +64,10 @@ extern "C" { pub fn PyEval_GetCallStats(arg1: *mut PyObject) -> *mut PyObject; pub fn PyEval_EvalFrame(arg1: *mut crate::ffi3::PyFrameObject) -> *mut PyObject; #[cfg(Py_3_6)] - pub fn _PyEval_EvalFrameDefault(arg1: *mut crate::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; + pub fn _PyEval_EvalFrameDefault( + arg1: *mut crate::ffi3::PyFrameObject, + exc: c_int, + ) -> *mut PyObject; #[cfg(Py_3_6)] pub fn _PyEval_RequestCodeExtraIndex(func: FreeFunc) -> c_int; pub fn PyEval_EvalFrameEx(f: *mut crate::ffi3::PyFrameObject, exc: c_int) -> *mut PyObject; diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index c074b6d0bf4..d2a520627ea 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -1,8 +1,8 @@ use crate::ffi3::object::*; use crate::ffi3::objectabstract::PyObject_CallFunction; use crate::ffi3::pyport::Py_ssize_t; -use std::os::raw::{c_char, c_int}; use std::ffi::CStr; +use std::os::raw::{c_char, c_int}; #[cfg_attr(windows, link(name = "pythonXY"))] extern "C" { From 4c59546ff60bc763ca0f87b326a4ecbb32413ee8 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 19:45:59 +0200 Subject: [PATCH 110/138] some documentation --- README.md | 2 ++ guide/src/SUMMARY.md | 1 + guide/src/get_started.md | 2 +- guide/src/pypy.md | 11 +++++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 guide/src/pypy.md diff --git a/README.md b/README.md index 7fe39af67aa..f67c85a43c9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ A comparison with rust-cpython can be found [in the guide](https://pyo3.rs/maste 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. +PyPy is also supported (via cpyext) for Python 3.5 only, targeted PyPy version is 7.0.0. + You can either write a native python module in rust or use python from a rust binary. On some OSs, you need some additional packages. diff --git a/guide/src/SUMMARY.md b/guide/src/SUMMARY.md index 64515c6e2ba..405bb6ac777 100644 --- a/guide/src/SUMMARY.md +++ b/guide/src/SUMMARY.md @@ -10,4 +10,5 @@ - [Debugging](debugging.md) - [Advanced Topics](advanced.md) - [Building and Distribution](building-and-distribution.md) +- [PyPy support](pypy.md) - [Appendix: Pyo3 and rust-cpython](rust-cpython.md) diff --git a/guide/src/get_started.md b/guide/src/get_started.md index 365a54f7fe4..266a7ce087f 100644 --- a/guide/src/get_started.md +++ b/guide/src/get_started.md @@ -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 2.7 as well as 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. diff --git a/guide/src/pypy.md b/guide/src/pypy.md new file mode 100644 index 00000000000..46d16a68505 --- /dev/null +++ b/guide/src/pypy.md @@ -0,0 +1,11 @@ +# PyPy Support + +Using PyPy is supported via cpyext. + +Support is only provided for building rust extension for code running under PyPy. This means PyPy **cannot** be called from rust via cpyext. + +This is a limitation of cpyext and supported for embedding cpyext is not planned. + +Compilation against PyPy is done by exporting the `PYTHON_SYS_EXECUTABLE` to a pypy binary. + +For example, `PYTHON_SYS_EXECUTABLE="/path/to/pypy3" /path/to/pypy3 setup.py install` \ No newline at end of file From c5935261fc2d61a04ffde694661b6fd9929fbbc4 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 19:54:48 +0200 Subject: [PATCH 111/138] if configured via env var only, default to cpython --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 0b971508c20..020595244c5 100644 --- a/build.rs +++ b/build.rs @@ -556,7 +556,7 @@ fn version_from_env() -> Option { Some(s) => Some(s.as_str().parse().unwrap()), None => None, }, - implementation: interpreter_kind, + implementation: PythonInterpreterKind::CPython, }); } None => (), From 7cc785759943d423b7c3645da5efda149f1f8b45 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 19:54:54 +0200 Subject: [PATCH 112/138] remove extra unsafe --- src/types/datetime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 49a8d858d66..8a6e504cfdc 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -96,7 +96,7 @@ impl PyDate { let ptr = (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, time_tuple.as_ptr()); - unsafe { Py::from_owned_ptr_or_err(py, ptr) } + Py::from_owned_ptr_or_err(py, ptr) } } } From 9859f9e224d91614044e9655d2c223bd9a24d1df Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 19:56:38 +0200 Subject: [PATCH 113/138] refer users to guide for pypy --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f67c85a43c9..68a2a82fbb2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ A comparison with rust-cpython can be found [in the guide](https://pyo3.rs/maste 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. PyPy is also supported (via cpyext) for Python 3.5 only, targeted PyPy version is 7.0.0. +Please refer to the guide for installation instruction against PyPy. You can either write a native python module in rust or use python from a rust binary. From d11040ca3df47cf04a170aa1bf0642898cdd3d87 Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 28 Mar 2019 22:09:28 +0200 Subject: [PATCH 114/138] Update guide/src/pypy.md Co-Authored-By: omerbenamram --- guide/src/pypy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guide/src/pypy.md b/guide/src/pypy.md index 46d16a68505..d01ea88a998 100644 --- a/guide/src/pypy.md +++ b/guide/src/pypy.md @@ -6,6 +6,6 @@ Support is only provided for building rust extension for code running under PyPy This is a limitation of cpyext and supported for embedding cpyext is not planned. -Compilation against PyPy is done by exporting the `PYTHON_SYS_EXECUTABLE` to a pypy binary. +Compilation against PyPy is done by exporting the `PYTHON_SYS_EXECUTABLE` to a pypy binary or by compiling in a PyPy virtualenv. -For example, `PYTHON_SYS_EXECUTABLE="/path/to/pypy3" /path/to/pypy3 setup.py install` \ No newline at end of file +For example, `PYTHON_SYS_EXECUTABLE="/path/to/pypy3" /path/to/pypy3 setup.py install` From d2dea54cfba0a8c2d853b6329216f7708f77ab2b Mon Sep 17 00:00:00 2001 From: konstin Date: Thu, 28 Mar 2019 22:09:45 +0200 Subject: [PATCH 115/138] Update guide/src/pypy.md Co-Authored-By: omerbenamram --- guide/src/pypy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/src/pypy.md b/guide/src/pypy.md index d01ea88a998..bf0b0d1e742 100644 --- a/guide/src/pypy.md +++ b/guide/src/pypy.md @@ -2,7 +2,7 @@ Using PyPy is supported via cpyext. -Support is only provided for building rust extension for code running under PyPy. This means PyPy **cannot** be called from rust via cpyext. +Support is only provided for building rust extension for code running under PyPy. This means PyPy **cannot** be called from rust via cpyext. Note that there some differences in the ffi module between pypy and cpython. This is a limitation of cpyext and supported for embedding cpyext is not planned. From 7bd3c955cdfaa8b7bc4356150ef13e102dcb1470 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 28 Mar 2019 22:20:14 +0200 Subject: [PATCH 116/138] @konstin applied patch --- src/ffi/datetime.rs | 15 +++++++++++---- src/ffi3/descrobject.rs | 6 +++--- src/ffi3/object.rs | 1 + src/ffi3/pyerrors.rs | 4 +++- src/types/datetime.rs | 10 +++++----- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index 1e52298995f..3cb04f5d3ef 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -6,15 +6,15 @@ //! and covers the various date and time related objects in the Python `datetime` //! standard library module. -use crate::ffi::PyCapsule_Import; use crate::ffi::Py_hash_t; use crate::ffi::{PyObject, PyTypeObject}; use crate::ffi::{PyObject_TypeCheck, Py_TYPE}; -use std::ffi::CString; use std::ops::Deref; use std::os::raw::{c_char, c_int, c_uchar}; use std::ptr; use std::sync::Once; +#[cfg(not(PyPy))] +use {crate::ffi::PyCapsule_Import, std::ffi::CString}; // A note regarding cpyext support: // Some macros, like `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as separate symbols. @@ -338,7 +338,7 @@ pub unsafe fn PyTZInfo_CheckExact(op: *mut PyObject) -> c_int { } /// Accessor functions -/// +#[cfg(not(PyPy))] macro_rules! _access_field { ($obj:expr, $type: ident, $field:tt) => { (*($obj as *mut $type)).$field @@ -375,24 +375,28 @@ pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int { } // Accessor macros for times +#[cfg(not(PyPy))] macro_rules! _PyDateTime_GET_HOUR { ($o: expr, $offset:expr) => { c_int::from((*$o).data[$offset + 0]) }; } +#[cfg(not(PyPy))] macro_rules! _PyDateTime_GET_MINUTE { ($o: expr, $offset:expr) => { c_int::from((*$o).data[$offset + 1]) }; } +#[cfg(not(PyPy))] macro_rules! _PyDateTime_GET_SECOND { ($o: expr, $offset:expr) => { c_int::from((*$o).data[$offset + 2]) }; } +#[cfg(not(PyPy))] macro_rules! _PyDateTime_GET_MICROSECOND { ($o: expr, $offset:expr) => { (c_int::from((*$o).data[$offset + 3]) << 16) @@ -402,12 +406,14 @@ macro_rules! _PyDateTime_GET_MICROSECOND { } #[cfg(Py_3_6)] +#[cfg(not(PyPy))] macro_rules! _PyDateTime_GET_FOLD { ($o: expr) => { (*$o).fold }; } +#[cfg(not(PyPy))] macro_rules! _PyDateTime_GET_TZINFO { ($o: expr) => { (*$o).tzinfo @@ -500,7 +506,7 @@ pub unsafe fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int { _PyDateTime_GET_MICROSECOND!((o as *mut PyDateTime_Time), 0) } -#[cfg(Py_3_6)] +#[cfg(all(Py_3_6, not(PyPy)))] #[inline] /// Retrieve the fold component of a `PyDateTime_Time`. /// Returns a signed integer in the interval `[0, 1]` @@ -520,6 +526,7 @@ pub unsafe fn PyDateTime_TIME_GET_TZINFO(o: *mut PyObject) -> *mut PyObject { } // Accessor functions for PyDateTime_Delta +#[cfg(not(PyPy))] macro_rules! _access_delta_field { ($obj:expr, $field:tt) => { _access_field!($obj, PyDateTime_Delta, $field) diff --git a/src/ffi3/descrobject.rs b/src/ffi3/descrobject.rs index ce8f9d9e09f..05af23b0f3f 100644 --- a/src/ffi3/descrobject.rs +++ b/src/ffi3/descrobject.rs @@ -1,7 +1,7 @@ use crate::ffi3::methodobject::PyMethodDef; -use crate::ffi3::object::{ - PyObject, PyObject_GenericGetDict, PyObject_GenericSetDict, PyTypeObject, -}; +use crate::ffi3::object::{PyObject, PyTypeObject}; +#[cfg(not(PyPy))] +use crate::ffi3::object::{PyObject_GenericGetDict, PyObject_GenericSetDict}; use crate::ffi3::structmember::PyMemberDef; use std::os::raw::{c_char, c_int, c_void}; use std::ptr; diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index cba419ce2dd..9c90bf91c7a 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -1,4 +1,5 @@ use crate::ffi3::pyport::{Py_hash_t, Py_ssize_t}; +#[cfg(PyPy)] use std::ffi::CStr; use std::mem; use std::os::raw::{c_char, c_int, c_uint, c_ulong, c_void}; diff --git a/src/ffi3/pyerrors.rs b/src/ffi3/pyerrors.rs index d2a520627ea..bc12572e7f8 100644 --- a/src/ffi3/pyerrors.rs +++ b/src/ffi3/pyerrors.rs @@ -1,6 +1,8 @@ use crate::ffi3::object::*; +#[cfg(PyPy)] use crate::ffi3::objectabstract::PyObject_CallFunction; use crate::ffi3::pyport::Py_ssize_t; +#[cfg(PyPy)] use std::ffi::CStr; use std::os::raw::{c_char, c_int}; @@ -84,7 +86,7 @@ pub unsafe fn PyUnicodeDecodeError_Create( length: Py_ssize_t, start: Py_ssize_t, end: Py_ssize_t, - reason: *const c_char, + _reason: *const c_char, ) -> *mut PyObject { return PyObject_CallFunction( PyExc_UnicodeDecodeError, diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 8a6e504cfdc..207c4c5a01c 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -9,10 +9,9 @@ use crate::err::PyResult; use crate::ffi; #[cfg(PyPy)] use crate::ffi::datetime::{PyDateTime_FromTimestamp, PyDate_FromTimestamp}; - use crate::ffi::PyDateTimeAPI; use crate::ffi::{PyDateTime_Check, PyDate_Check, PyDelta_Check, PyTZInfo_Check, PyTime_Check}; -#[cfg(Py_3_6)] +#[cfg(all(Py_3_6, not(PyPy)))] use crate::ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; use crate::ffi::{ PyDateTime_DATE_GET_HOUR, PyDateTime_DATE_GET_MICROSECOND, PyDateTime_DATE_GET_MINUTE, @@ -33,6 +32,7 @@ use crate::AsPyPointer; use crate::Python; use crate::ToPyObject; use std::os::raw::c_int; +#[cfg(not(PyPy))] use std::ptr; /// Access traits @@ -61,7 +61,7 @@ pub trait PyTimeAccess { fn get_minute(&self) -> u8; fn get_second(&self) -> u8; fn get_microsecond(&self) -> u32; - #[cfg(Py_3_6)] + #[cfg(all(Py_3_6, not(PyPy)))] fn get_fold(&self) -> u8; } @@ -213,7 +213,7 @@ impl PyTimeAccess for PyDateTime { unsafe { PyDateTime_DATE_GET_MICROSECOND(self.as_ptr()) as u32 } } - #[cfg(Py_3_6)] + #[cfg(all(Py_3_6, not(PyPy)))] fn get_fold(&self) -> u8 { unsafe { PyDateTime_DATE_GET_FOLD(self.as_ptr()) as u8 } } @@ -290,7 +290,7 @@ impl PyTimeAccess for PyTime { unsafe { PyDateTime_TIME_GET_MICROSECOND(self.as_ptr()) as u32 } } - #[cfg(Py_3_6)] + #[cfg(all(Py_3_6, not(PyPy)))] fn get_fold(&self) -> u8 { unsafe { PyDateTime_TIME_GET_FOLD(self.as_ptr()) as u8 } } From 197c879c376ea554e8d3668252f40cd98dda88ce Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 3 Apr 2019 23:13:35 +0300 Subject: [PATCH 117/138] check that pypy at least build --- ci/travis/test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 32bcdb6ff6a..a2b49920180 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -7,6 +7,9 @@ cargo clean if ! [[ $FEATURES == *"pypy"* ]]; then cargo test --features "$FEATURES num-complex" ( cd pyo3-derive-backend; cargo test ) +else + # check that pypy at least builds + cargo build; fi if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then From 95df2b1911ba2441a05ee0a83bb2f05a8a37ed92 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 3 Apr 2019 23:33:28 +0300 Subject: [PATCH 118/138] search explicitly for libpypy --- build.rs | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/build.rs b/build.rs index 54a5f49c03e..e5664e11f0c 100644 --- a/build.rs +++ b/build.rs @@ -288,17 +288,37 @@ fn run_python_script(interpreter: &str, script: &str) -> Result Ok(String::from_utf8(out.stdout).unwrap()) } +fn get_library_link_name(version: &PythonVersion) -> String { + let minor_or_empty_string = match version.minor { + Some(minor) => format!("{}", minor), + None => String::new(), + }; + + match version.implementation { + PythonInterpreterKind::CPython => { + format!("python{}{}", version.major, minor_or_empty_string) + } + PythonInterpreterKind::PyPy => format!("pypy{}-c", version.major), + } +} + #[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "windows"))] fn get_rustc_link_lib( - _: &PythonVersion, + version: &PythonVersion, ld_version: &str, enable_shared: bool, ) -> Result { if enable_shared { - Ok(format!("cargo:rustc-link-lib=python{}", ld_version)) + Ok(format!( + "cargo:rustc-link-lib={}", + get_library_link_name(&version) + )) } else { - Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) + Ok(format!( + "cargo:rustc-link-lib=static={}", + get_library_link_name(&version) + )) } } @@ -319,13 +339,26 @@ else: } #[cfg(target_os = "macos")] -fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, _: bool) -> Result { +fn get_rustc_link_lib( + version: &PythonVersion, + ld_version: &str, + _: bool, +) -> Result { // os x can be linked to a framework or static or dynamic, and // Py_ENABLE_SHARED is wrong; framework means shared library match get_macos_linkmodel().unwrap().as_ref() { - "static" => Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", ld_version)), + "static" => Ok(format!( + "cargo:rustc-link-lib=static={}", + get_library_link_name(&version) + )), + "shared" => Ok(format!( + "cargo:rustc-link-lib={}", + get_library_link_name(&version) + )), + "framework" => Ok(format!( + "cargo:rustc-link-lib={}", + get_library_link_name(&version) + )), other => Err(format!("unknown linkmodel {}", other)), } } @@ -354,12 +387,8 @@ fn get_interpreter_version(line: &str, implementation: &str) -> Result Result { // Py_ENABLE_SHARED doesn't seem to be present on windows. Ok(format!( - "cargo:rustc-link-lib=pythonXY:python{}{}", - version.major, - match version.minor { - Some(minor) => minor.to_string(), - None => "".to_owned(), - } + "cargo:rustc-link-lib=pythonXY:{}", + get_library_link_name(&version) )) } From b3fab3cd970f4b2f6d03011c0ca36a51884d7edc Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 3 Apr 2019 23:45:59 +0300 Subject: [PATCH 119/138] added note about some known unsupported features --- guide/src/pypy.md | 10 ++++++++++ src/types/complex.rs | 7 +++++++ src/types/dict.rs | 1 + src/types/sequence.rs | 1 + 4 files changed, 19 insertions(+) diff --git a/guide/src/pypy.md b/guide/src/pypy.md index bf0b0d1e742..71729ca6f47 100644 --- a/guide/src/pypy.md +++ b/guide/src/pypy.md @@ -9,3 +9,13 @@ This is a limitation of cpyext and supported for embedding cpyext is not planned Compilation against PyPy is done by exporting the `PYTHON_SYS_EXECUTABLE` to a pypy binary or by compiling in a PyPy virtualenv. For example, `PYTHON_SYS_EXECUTABLE="/path/to/pypy3" /path/to/pypy3 setup.py install` + + +## Unsupported Features + +These are features currently supported by PyO3, but not yet implemented in cpyext. + +- Complex number functions (`_Py_c_sum`, `_Py_c_sum` ..) +- Conversion to rust's i128, u128 types. +- `PySequence_Count` (which is used to count number of element in array) +- `PyDict_MergeFromSeq2` (used in `PyDict::from_sequence`) \ No newline at end of file diff --git a/src/types/complex.rs b/src/types/complex.rs index 071387da291..fb0c4036fba 100644 --- a/src/types/complex.rs +++ b/src/types/complex.rs @@ -30,6 +30,7 @@ impl PyComplex { } /// Returns `|self|`. #[cfg(not(Py_LIMITED_API))] + #[cfg(not(PyPy))] pub fn abs(&self) -> c_double { unsafe { let val = (*(self.as_ptr() as *mut ffi::PyComplexObject)).cval; @@ -38,6 +39,7 @@ impl PyComplex { } /// Returns `self ** other` #[cfg(not(Py_LIMITED_API))] + #[cfg(not(PyPy))] pub fn pow(&self, other: &PyComplex) -> &PyComplex { unsafe { self.py() @@ -59,6 +61,7 @@ unsafe fn complex_operation( } #[cfg(not(Py_LIMITED_API))] +#[cfg(not(PyPy))] impl<'py> Add for &'py PyComplex { type Output = &'py PyComplex; fn add(self, other: &'py PyComplex) -> &'py PyComplex { @@ -70,6 +73,7 @@ impl<'py> Add for &'py PyComplex { } #[cfg(not(Py_LIMITED_API))] +#[cfg(not(PyPy))] impl<'py> Sub for &'py PyComplex { type Output = &'py PyComplex; fn sub(self, other: &'py PyComplex) -> &'py PyComplex { @@ -81,6 +85,7 @@ impl<'py> Sub for &'py PyComplex { } #[cfg(not(Py_LIMITED_API))] +#[cfg(not(PyPy))] impl<'py> Mul for &'py PyComplex { type Output = &'py PyComplex; fn mul(self, other: &'py PyComplex) -> &'py PyComplex { @@ -92,6 +97,7 @@ impl<'py> Mul for &'py PyComplex { } #[cfg(not(Py_LIMITED_API))] +#[cfg(not(PyPy))] impl<'py> Div for &'py PyComplex { type Output = &'py PyComplex; fn div(self, other: &'py PyComplex) -> &'py PyComplex { @@ -103,6 +109,7 @@ impl<'py> Div for &'py PyComplex { } #[cfg(not(Py_LIMITED_API))] +#[cfg(not(PyPy))] impl<'py> Neg for &'py PyComplex { type Output = &'py PyComplex; fn neg(self) -> &'py PyComplex { diff --git a/src/types/dict.rs b/src/types/dict.rs index b12543b97b2..f9ed8162dfa 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -30,6 +30,7 @@ impl PyDict { /// /// Returns an error on invalid input. In the case of key collisions, /// this keeps the last entry seen. + #[cfg(not(PyPy))] pub fn from_sequence(py: Python, seq: PyObject) -> PyResult<&PyDict> { unsafe { let dict = py.from_owned_ptr::(ffi::PyDict_New()); diff --git a/src/types/sequence.rs b/src/types/sequence.rs index 98153544a3d..70b840d8557 100644 --- a/src/types/sequence.rs +++ b/src/types/sequence.rs @@ -168,6 +168,7 @@ impl PySequence { /// Return the number of occurrences of value in o, that is, return the number of keys for /// which `o[key] == value` #[inline] + #[cfg(not(PyPy))] pub fn count(&self, value: V) -> PyResult where V: ToBorrowedObject, From c9fd1f13822b8f3e591769c47f593cbbb7ed4382 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 3 Apr 2019 23:51:40 +0300 Subject: [PATCH 120/138] use ld_version --- build.rs | 58 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/build.rs b/build.rs index e5664e11f0c..8682c1ade5d 100644 --- a/build.rs +++ b/build.rs @@ -288,17 +288,23 @@ fn run_python_script(interpreter: &str, script: &str) -> Result Ok(String::from_utf8(out.stdout).unwrap()) } -fn get_library_link_name(version: &PythonVersion) -> String { - let minor_or_empty_string = match version.minor { - Some(minor) => format!("{}", minor), - None => String::new(), - }; - - match version.implementation { - PythonInterpreterKind::CPython => { - format!("python{}{}", version.major, minor_or_empty_string) +fn get_library_link_name(version: &PythonVersion, ld_version: &str) -> String { + if cfg!(target_os = "windows") { + let minor_or_empty_string = match version.minor { + Some(minor) => format!("{}", minor), + None => String::new(), + }; + match version.implementation { + PythonInterpreterKind::CPython => { + format!("python{}{}", version.major, minor_or_empty_string) + } + PythonInterpreterKind::PyPy => format!("pypy{}-c", version.major), + } + } else { + match version.implementation { + PythonInterpreterKind::CPython => format!("python{}", ld_version), + PythonInterpreterKind::PyPy => format!("pypy{}-c", version.major), } - PythonInterpreterKind::PyPy => format!("pypy{}-c", version.major), } } @@ -312,12 +318,12 @@ fn get_rustc_link_lib( if enable_shared { Ok(format!( "cargo:rustc-link-lib={}", - get_library_link_name(&version) + get_library_link_name(&version, ld_version) )) } else { Ok(format!( "cargo:rustc-link-lib=static={}", - get_library_link_name(&version) + get_library_link_name(&version, ld_version) )) } } @@ -349,20 +355,33 @@ fn get_rustc_link_lib( match get_macos_linkmodel().unwrap().as_ref() { "static" => Ok(format!( "cargo:rustc-link-lib=static={}", - get_library_link_name(&version) + get_library_link_name(&version, ld_version) )), "shared" => Ok(format!( "cargo:rustc-link-lib={}", - get_library_link_name(&version) + get_library_link_name(&version, ld_version) )), "framework" => Ok(format!( "cargo:rustc-link-lib={}", - get_library_link_name(&version) + get_library_link_name(&version, ld_version) )), other => Err(format!("unknown linkmodel {}", other)), } } +#[cfg(target_os = "windows")] +fn get_rustc_link_lib( + version: &PythonVersion, + ld_version: &str, + _: bool, +) -> Result { + // Py_ENABLE_SHARED doesn't seem to be present on windows. + Ok(format!( + "cargo:rustc-link-lib=pythonXY:{}", + get_library_link_name(&version, ld_version) + )) +} + /// Parse string as interpreter version. fn get_interpreter_version(line: &str, implementation: &str) -> Result { let version_re = Regex::new(r"\((\d+), (\d+)\)").unwrap(); @@ -383,15 +402,6 @@ fn get_interpreter_version(line: &str, implementation: &str) -> Result Result { - // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!( - "cargo:rustc-link-lib=pythonXY:{}", - get_library_link_name(&version) - )) -} - /// Locate a suitable python interpreter and extract config from it. /// /// The following locations are checked in the order listed: From 879582751300e1b53df601155094baf4ba280c21 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 4 Apr 2019 22:01:57 +0300 Subject: [PATCH 121/138] export PYTHON_SYS_EXECUTABLE to `cargo build` test --- ci/travis/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/test.sh b/ci/travis/test.sh index a2b49920180..9a0a901aaf9 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -9,7 +9,7 @@ if ! [[ $FEATURES == *"pypy"* ]]; then ( cd pyo3-derive-backend; cargo test ) else # check that pypy at least builds - cargo build; + PYTHON_SYS_EXECUTABLE="/opt/anaconda/envs/pypy3/bin/pypy3" cargo build; fi if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then From 92211e28bf3ad943489b1f16f8aae55ae648065f Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 4 Apr 2019 22:07:09 +0300 Subject: [PATCH 122/138] inverted if --- ci/travis/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 65e6c74667b..4e386dee692 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -37,7 +37,7 @@ fi ### Setup PyPy ################################################################ -if ! [[ $FEATURES == *"pypy"* ]]; then +if [[ $FEATURES == *"pypy"* ]]; then wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ From d173de659bea290ad5d000d6da196d5b79b36f9a Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 4 Apr 2019 23:19:32 +0300 Subject: [PATCH 123/138] always link pypy dynamically --- build.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 8682c1ade5d..9d1a58d0353 100644 --- a/build.rs +++ b/build.rs @@ -494,9 +494,14 @@ import sys import sysconfig import platform +PYPY = platform.python_implementation() == "PyPy" + print(sys.version_info[0:2]) print(sysconfig.get_config_var('LIBDIR')) -print(sysconfig.get_config_var('Py_ENABLE_SHARED')) +if PYPY: + print("1") +else: + print(sysconfig.get_config_var('Py_ENABLE_SHARED')) print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')) print(sys.exec_prefix) print(platform.python_implementation()) From 3b099ea9166a87ae8b1fe21e17b18b61063418ae Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Thu, 4 Apr 2019 23:26:07 +0300 Subject: [PATCH 124/138] remove unused imports --- src/types/complex.rs | 3 +++ src/types/dict.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/types/complex.rs b/src/types/complex.rs index fb0c4036fba..adee578dbab 100644 --- a/src/types/complex.rs +++ b/src/types/complex.rs @@ -1,8 +1,10 @@ use crate::ffi; +#[cfg(not(PyPy))] use crate::instance::PyNativeType; use crate::object::PyObject; use crate::AsPyPointer; use crate::Python; +#[cfg(not(PyPy))] use std::ops::*; use std::os::raw::c_double; @@ -49,6 +51,7 @@ impl PyComplex { } #[cfg(not(Py_LIMITED_API))] +#[cfg(not(PyPy))] #[inline(always)] unsafe fn complex_operation( l: &PyComplex, diff --git a/src/types/dict.rs b/src/types/dict.rs index f9ed8162dfa..429729a0608 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -6,6 +6,7 @@ use crate::instance::PyNativeType; use crate::object::PyObject; use crate::types::{PyAny, PyList}; use crate::AsPyPointer; +#[cfg(not(PyPy))] use crate::IntoPyPointer; use crate::Python; use crate::{IntoPyObject, ToBorrowedObject, ToPyObject}; From 958a897250467fa5b92c7b9584426ed76ee2aecd Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 13:46:15 +0300 Subject: [PATCH 125/138] =?UTF-8?q?Apply=20@kngwyu=E2=80=99s=20suggestion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ffi3/object.rs | 90 ++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 63 deletions(-) diff --git a/src/ffi3/object.rs b/src/ffi3/object.rs index 9c90bf91c7a..a20e4c77fdb 100644 --- a/src/ffi3/object.rs +++ b/src/ffi3/object.rs @@ -520,15 +520,11 @@ mod typeobject { pub tp_next: *mut PyTypeObject, } - #[cfg(PyPy)] - macro_rules! py_type_object_init { - ($tp_as_async:ident, $($tail:tt)*) => { + macro_rules! _type_object_init { + ({$($head:tt)*} $tp_as_async:ident, $($tail:tt)*) => { as_expr! { PyTypeObject { - ob_refcnt: 1, - ob_pypy_link: 0, - ob_type: ptr::null_mut(), - ob_size: 0, + $($head)* tp_name: ptr::null(), tp_basicsize: 0, tp_itemsize: 0, @@ -575,71 +571,39 @@ mod typeobject { tp_weaklist: ptr::null_mut(), tp_del: None, tp_version_tag: 0, - tp_pypy_flags: 0, $($tail)* } } } } - #[cfg(not(PyPy))] + #[cfg(PyPy)] macro_rules! py_type_object_init { ($tp_as_async:ident, $($tail:tt)*) => { - as_expr! { - PyTypeObject { - ob_base: ffi3::object::PyVarObject { - ob_base: ffi3::object::PyObject_HEAD_INIT, - ob_size: 0 - }, - tp_name: ptr::null(), - tp_basicsize: 0, - tp_itemsize: 0, - tp_dealloc: None, - tp_print: None, - tp_getattr: None, - tp_setattr: None, - $tp_as_async: ptr::null_mut(), - tp_repr: None, - tp_as_number: ptr::null_mut(), - tp_as_sequence: ptr::null_mut(), - tp_as_mapping: ptr::null_mut(), - tp_hash: None, - tp_call: None, - tp_str: None, - tp_getattro: None, - tp_setattro: None, - tp_as_buffer: ptr::null_mut(), - tp_flags: ffi3::object::Py_TPFLAGS_DEFAULT, - tp_doc: ptr::null(), - tp_traverse: None, - tp_clear: None, - tp_richcompare: None, - tp_weaklistoffset: 0, - tp_iter: None, - tp_iternext: None, - tp_methods: ptr::null_mut(), - tp_members: ptr::null_mut(), - tp_getset: ptr::null_mut(), - tp_base: ptr::null_mut(), - tp_dict: 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: ptr::null_mut(), - tp_mro: ptr::null_mut(), - tp_cache: ptr::null_mut(), - tp_subclasses: ptr::null_mut(), - tp_weaklist: ptr::null_mut(), - tp_del: None, - tp_version_tag: 0, - $($tail)* + _type_object_init!({ + ob_refcnt: 1, + ob_pypy_link: 0, + ob_type: ptr::null_mut(), + ob_size: 0, } - } + $tp_as_async, + tp_pypy_flags: 0, + $($tail)* + ) + } + } + + #[cfg(not(PyPy))] + macro_rules! py_type_object_init { + ($tp_as_async:ident, $($tail:tt)*) => { + _type_object_init!({ + ob_base: ffi3::object::PyVarObject { + ob_base: ffi3::object::PyObject_HEAD_INIT, + ob_size: 0 + },} + $tp_as_async, + $($tail)* + ) } } From a054e0a2a99bdaf41b0fc7e8f81ce07fd8ea1c53 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 14:00:17 +0300 Subject: [PATCH 126/138] fix tox configuration --- ci/travis/test.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 9a0a901aaf9..728e50f744a 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -18,5 +18,9 @@ if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then fi for example_dir in examples/*; do - tox -c "$example_dir/tox.ini" -e py + if [[ $FEATURES == *"pypy"* ]]; then + tox -c "$example_dir/tox.ini" -e pypy3 + else + tox -c "$example_dir/tox.ini" -e py + fi done From bc4876014222d3b743796079be4c6b4a4ef36621 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 14:11:32 +0300 Subject: [PATCH 127/138] try conda virtualenv --- ci/travis/setup.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 4e386dee692..1cf02ca4f3d 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -38,6 +38,8 @@ fi ### Setup PyPy ################################################################ if [[ $FEATURES == *"pypy"* ]]; then + pip uninstall virtualenv + wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ @@ -45,5 +47,6 @@ if [[ $FEATURES == *"pypy"* ]]; then /opt/anaconda/bin/conda init bash && \ /opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ - /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox + /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox && \ + /opt/anaconda/bin/conda install --quiet --yes virtualenv fi \ No newline at end of file From efc34df5967df6d70608c0bdfcd1d9b3cb84867c Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 14:13:09 +0300 Subject: [PATCH 128/138] try to simply not install python at all inside pypy environment --- .travis.yml | 1 - ci/travis/setup.sh | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index da864c74126..07ed6190482 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,6 @@ matrix: env: TRAVIS_RUST_VERSION=nightly-2019-02-07 # Tested via anaconda PyPy (since travis's PyPy version is too old) - name: PyPy3.5 7.0 - python: "3.7" env: FEATURES="pypy" PATH="$PATH:/opt/anaconda/envs/pypy3/bin" allow_failures: - python: "3.8-dev" diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 1cf02ca4f3d..4e386dee692 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -38,8 +38,6 @@ fi ### Setup PyPy ################################################################ if [[ $FEATURES == *"pypy"* ]]; then - pip uninstall virtualenv - wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ /opt/anaconda/bin/conda install --quiet --yes conda && \ @@ -47,6 +45,5 @@ if [[ $FEATURES == *"pypy"* ]]; then /opt/anaconda/bin/conda init bash && \ /opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ - /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox && \ - /opt/anaconda/bin/conda install --quiet --yes virtualenv + /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox fi \ No newline at end of file From d971e6237d78c8e169f7529507e99d5e4d1ad83d Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 14:15:19 +0300 Subject: [PATCH 129/138] =?UTF-8?q?setup=20pypy=20before=20using=20?= =?UTF-8?q?=E2=80=9Cpython"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci/travis/setup.sh | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 4e386dee692..dab2b3f1645 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -11,9 +11,28 @@ if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then rustup component add rustfmt fi +### Setup PyPy ################################################################ + +if [[ $FEATURES == *"pypy"* ]]; then + wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ + /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ + /opt/anaconda/bin/conda install --quiet --yes conda && \ + /opt/anaconda/bin/conda config --system --add channels conda-forge && \ + /opt/anaconda/bin/conda init bash && \ + /opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ + /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ + /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox +fi + ### Setup python linker flags ################################################## -PYTHON_LIB=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") +if [[ $FEATURES == *"pypy"* ]]; then + PYTHON_BINARY="pypy3" +else + PYTHON_BINARY="python" +fi + +PYTHON_LIB=$($PYTHON_BINARY -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PYTHON_LIB:$HOME/rust/lib" @@ -32,18 +51,4 @@ if [ ! -f "$HOME/.cargo/bin/kcov" ]; then make install src/kcov $HOME/.cargo/bin/kcov cd $TRAVIS_BUILD_DIR -fi - - -### Setup PyPy ################################################################ - -if [[ $FEATURES == *"pypy"* ]]; then - wget --quiet https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ - /bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/anaconda && \ - /opt/anaconda/bin/conda install --quiet --yes conda && \ - /opt/anaconda/bin/conda config --system --add channels conda-forge && \ - /opt/anaconda/bin/conda init bash && \ - /opt/anaconda/bin/conda create -n pypy3 pypy3.5 -y && \ - /opt/anaconda/envs/pypy3/bin/pypy3 -m ensurepip && \ - /opt/anaconda/envs/pypy3/bin/pypy3 -m pip install setuptools-rust pytest pytest-benchmark tox fi \ No newline at end of file From faf764015dc8664b703f9fcfa70dcae591856ba7 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 14:18:07 +0300 Subject: [PATCH 130/138] use system_site_packages --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 07ed6190482..ff1e4363ad8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,12 @@ matrix: env: TRAVIS_RUST_VERSION=nightly-2019-02-07 # Tested via anaconda PyPy (since travis's PyPy version is too old) - name: PyPy3.5 7.0 + python: "3.7" env: FEATURES="pypy" PATH="$PATH:/opt/anaconda/envs/pypy3/bin" + # This should cause help to detect pypy's libraries correctly + virtualenv: + system_site_packages: true + allow_failures: - python: "3.8-dev" From 1932dd0ea694559572b2d638677c6a335cbe3625 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 13 Apr 2019 14:32:03 +0300 Subject: [PATCH 131/138] revert change to .travis --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff1e4363ad8..da864c74126 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,10 +27,6 @@ matrix: - name: PyPy3.5 7.0 python: "3.7" env: FEATURES="pypy" PATH="$PATH:/opt/anaconda/envs/pypy3/bin" - # This should cause help to detect pypy's libraries correctly - virtualenv: - system_site_packages: true - allow_failures: - python: "3.8-dev" From addbe9edb83814fb780c19a2da8bbea6dc2aade8 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 17 Apr 2019 19:48:04 +0300 Subject: [PATCH 132/138] moved cpyext datetime documentation to module level, and revised it. --- src/ffi/datetime.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index 3cb04f5d3ef..da736f6f379 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -5,6 +5,20 @@ //! This is the unsafe thin wrapper around the [CPython C API](https://docs.python.org/3/c-api/datetime.html), //! and covers the various date and time related objects in the Python `datetime` //! standard library module. +//! +//! (PyPy 7.0.0) - A note regarding PyPy (cpyext) support: +//! +//! PyPy's internal representation of dates differs from that of cpython. +//! It expects to initialize some internal rpython machinery when the symbol `PyDateTime_Import` is called. +//! After initialization, the emulation layer expects that all calls to the api will be limited to those defined in +//! `https://docs.python.org/3/c-api/datetime.html`. +//! +//! For example, macros such as `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as symbols in `libpypy`. +//! This means we cannot rely on emulating those macros in rust, since it doesn't ensure ABI comparability with the c structs. +//! +//! All functions that belong to `PyDateTime_CAPI`, are exported as private symbols in PyPy (ex. `_PyPyDate_FromDate`). +//! This means that their behavior is subjected to change in upcoming PyPy versions. + use crate::ffi::Py_hash_t; use crate::ffi::{PyObject, PyTypeObject}; @@ -16,11 +30,6 @@ use std::sync::Once; #[cfg(not(PyPy))] use {crate::ffi::PyCapsule_Import, std::ffi::CString}; -// A note regarding cpyext support: -// Some macros, like `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as separate symbols. -// For now, some symbols are exported as "private" symbols, like `_PyPyDate_FromDate`, -// which means they still adhere to the old API (expect a `cls` object in their signature) -// In the future they may be removed and become fully public symbols in cpyext. #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct PyDateTime_CAPI { From f291d8a0e4a63763f728bd4ef2600e898d80415f Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 17 Apr 2019 19:56:13 +0300 Subject: [PATCH 133/138] Update src/ffi/datetime.rs Co-Authored-By: omerbenamram --- src/ffi/datetime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index da736f6f379..44e4ccec962 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -261,7 +261,7 @@ impl Deref for PyDateTimeAPI { /// such as if you do not want the first call to a datetime function to be /// slightly slower than subsequent calls. pub unsafe fn PyDateTime_IMPORT() -> &'static PyDateTime_CAPI { - // PyPy excepts the C-API to be initialized via PyDateTime_Import, so trying to use + // PyPy expects the C-API to be initialized via PyDateTime_Import, so trying to use // `PyCapsule_Import` will behave unexpectedly in pypy. #[cfg(PyPy)] let py_datetime_c_api = PyDateTime_Import(); From 00ba2239fa57bc86b53dea6be3b63b8b5f84e933 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 17 Apr 2019 21:15:10 +0300 Subject: [PATCH 134/138] rustfmt --- src/ffi/datetime.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index da736f6f379..e7a79e4e5cb 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -19,7 +19,6 @@ //! All functions that belong to `PyDateTime_CAPI`, are exported as private symbols in PyPy (ex. `_PyPyDate_FromDate`). //! This means that their behavior is subjected to change in upcoming PyPy versions. - use crate::ffi::Py_hash_t; use crate::ffi::{PyObject, PyTypeObject}; use crate::ffi::{PyObject_TypeCheck, Py_TYPE}; From e677f2d3ee308dd4005f469f8cb7d5afe5429852 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Wed, 17 Apr 2019 21:27:53 +0300 Subject: [PATCH 135/138] Update src/ffi/datetime.rs Co-Authored-By: omerbenamram --- src/ffi/datetime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index c571555db2d..dfc63c78d9b 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -17,7 +17,7 @@ //! This means we cannot rely on emulating those macros in rust, since it doesn't ensure ABI comparability with the c structs. //! //! All functions that belong to `PyDateTime_CAPI`, are exported as private symbols in PyPy (ex. `_PyPyDate_FromDate`). -//! This means that their behavior is subjected to change in upcoming PyPy versions. +//! This means that their behavior is subject to change in upcoming PyPy versions. use crate::ffi::Py_hash_t; use crate::ffi::{PyObject, PyTypeObject}; From 92b23772e8f9c85282b4283b21d344e52d134c04 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Wed, 17 Apr 2019 22:31:00 +0300 Subject: [PATCH 136/138] kept only notes that are relevant to users. --- src/ffi/datetime.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/ffi/datetime.rs b/src/ffi/datetime.rs index dfc63c78d9b..c7662279cac 100644 --- a/src/ffi/datetime.rs +++ b/src/ffi/datetime.rs @@ -6,18 +6,10 @@ //! and covers the various date and time related objects in the Python `datetime` //! standard library module. //! -//! (PyPy 7.0.0) - A note regarding PyPy (cpyext) support: +//! A note regarding PyPy (cpyext) support: //! -//! PyPy's internal representation of dates differs from that of cpython. -//! It expects to initialize some internal rpython machinery when the symbol `PyDateTime_Import` is called. -//! After initialization, the emulation layer expects that all calls to the api will be limited to those defined in -//! `https://docs.python.org/3/c-api/datetime.html`. -//! -//! For example, macros such as `PyDate_FromTimestamp` and `PyDateTime_FromTimestamp` are exported as symbols in `libpypy`. -//! This means we cannot rely on emulating those macros in rust, since it doesn't ensure ABI comparability with the c structs. -//! -//! All functions that belong to `PyDateTime_CAPI`, are exported as private symbols in PyPy (ex. `_PyPyDate_FromDate`). -//! This means that their behavior is subject to change in upcoming PyPy versions. +//! Support for `PyDateTime_CAPI` is limited as of PyPy 7.0.0. +//! `DateTime_FromTimestamp` and `Date_FromTimestamp` are currently not supported. use crate::ffi::Py_hash_t; use crate::ffi::{PyObject, PyTypeObject}; From 21bf3adf61fbe3860563a757f3ff8e083100e267 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 21 Apr 2019 14:33:56 +0300 Subject: [PATCH 137/138] invert if --- ci/travis/cover.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis/cover.sh b/ci/travis/cover.sh index 7186194ef80..cca0a8f240a 100755 --- a/ci/travis/cover.sh +++ b/ci/travis/cover.sh @@ -4,7 +4,7 @@ set -ex ### PyPy does not run the test suite ########################################### -if ! [[ $FEATURES == *"pypy"* ]]; then +if [[ $FEATURES == *"pypy"* ]]; then exit 0 fi From 7d665c4942ec11433d2ce43fae41b7532c5273b8 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 21 Apr 2019 19:04:15 +0300 Subject: [PATCH 138/138] use bash and not sh --- ci/travis/cover.sh | 2 +- ci/travis/guide.sh | 2 +- ci/travis/setup.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/travis/cover.sh b/ci/travis/cover.sh index cca0a8f240a..1b68500593a 100755 --- a/ci/travis/cover.sh +++ b/ci/travis/cover.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -ex diff --git a/ci/travis/guide.sh b/ci/travis/guide.sh index 245bec37539..a0261b40833 100755 --- a/ci/travis/guide.sh +++ b/ci/travis/guide.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -ex diff --git a/ci/travis/setup.sh b/ci/travis/setup.sh index 9a103b87d57..96c9d82da45 100755 --- a/ci/travis/setup.sh +++ b/ci/travis/setup.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e