From 79844dc432f484c21631b3e0d71b899797d1ad7d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 17 Dec 2016 15:04:39 +0100 Subject: [PATCH] Fix #10: Windows support. --- appveyor.yml | 6 +++--- examples/hello.rs | 18 ++++++++++-------- python27-sys/build.rs | 12 ++++++------ python27-sys/src/boolobject.rs | 3 +-- python27-sys/src/bufferobject.rs | 4 ++-- python27-sys/src/bytearrayobject.rs | 4 ++-- python27-sys/src/cellobject.rs | 4 ++-- python27-sys/src/ceval.rs | 4 ++-- python27-sys/src/classobject.rs | 4 ++-- python27-sys/src/cobject.rs | 4 ++-- python27-sys/src/code.rs | 2 +- python27-sys/src/compile.rs | 2 +- python27-sys/src/complexobject.rs | 6 +++--- python27-sys/src/descrobject.rs | 4 ++-- python27-sys/src/dictobject.rs | 4 ++-- python27-sys/src/enumobject.rs | 2 +- python27-sys/src/eval.rs | 2 +- python27-sys/src/fileobject.rs | 4 ++-- python27-sys/src/floatobject.rs | 4 ++-- python27-sys/src/frameobject.rs | 4 ++-- python27-sys/src/funcobject.rs | 4 ++-- python27-sys/src/genobject.rs | 4 ++-- python27-sys/src/import.rs | 2 +- python27-sys/src/intobject.rs | 4 ++-- python27-sys/src/iterobject.rs | 2 +- python27-sys/src/listobject.rs | 4 ++-- python27-sys/src/longobject.rs | 4 ++-- python27-sys/src/memoryobject.rs | 4 ++-- python27-sys/src/methodobject.rs | 6 +++--- python27-sys/src/modsupport.rs | 2 +- python27-sys/src/moduleobject.rs | 2 +- python27-sys/src/object.rs | 12 ++++++------ python27-sys/src/objectabstract.rs | 2 +- python27-sys/src/objimpl.rs | 2 +- python27-sys/src/pyarena.rs | 2 +- python27-sys/src/pycapsule.rs | 4 ++-- python27-sys/src/pydebug.rs | 2 +- python27-sys/src/pyerrors.rs | 6 +++--- python27-sys/src/pymem.rs | 2 +- python27-sys/src/pystate.rs | 2 +- python27-sys/src/pythonrun.rs | 2 +- python27-sys/src/rangeobject.rs | 2 +- python27-sys/src/setobject.rs | 4 ++-- python27-sys/src/sliceobject.rs | 6 +++--- python27-sys/src/stringobject.rs | 4 ++-- python27-sys/src/structmember.rs | 2 +- python27-sys/src/traceback.rs | 2 +- python27-sys/src/tupleobject.rs | 4 ++-- python27-sys/src/unicodeobject.rs | 6 +++--- python27-sys/src/warnings.rs | 2 +- python27-sys/src/weakrefobject.rs | 4 ++-- python3-sys/build.rs | 12 ++++++------ python3-sys/src/bltinmodule.rs | 2 +- python3-sys/src/boolobject.rs | 2 +- python3-sys/src/bytearrayobject.rs | 4 ++-- python3-sys/src/bytesobject.rs | 4 ++-- python3-sys/src/ceval.rs | 8 ++++---- python3-sys/src/code.rs | 2 +- python3-sys/src/codecs.rs | 2 +- python3-sys/src/compile.rs | 2 +- python3-sys/src/complexobject.rs | 4 ++-- python3-sys/src/descrobject.rs | 2 +- python3-sys/src/dictobject.rs | 4 ++-- python3-sys/src/enumobject.rs | 2 +- python3-sys/src/eval.rs | 2 +- python3-sys/src/fileobject.rs | 2 +- python3-sys/src/floatobject.rs | 4 ++-- python3-sys/src/frameobject.rs | 4 ++-- python3-sys/src/import.rs | 4 ++-- python3-sys/src/intrcheck.rs | 2 +- python3-sys/src/iterobject.rs | 2 +- python3-sys/src/listobject.rs | 4 ++-- python3-sys/src/longobject.rs | 4 ++-- python3-sys/src/memoryobject.rs | 4 ++-- python3-sys/src/methodobject.rs | 8 ++++---- python3-sys/src/modsupport.rs | 4 ++-- python3-sys/src/moduleobject.rs | 4 ++-- python3-sys/src/object.rs | 12 ++++++------ python3-sys/src/objectabstract.rs | 18 +++++++++--------- python3-sys/src/objimpl.rs | 6 +++--- python3-sys/src/osmodule.rs | 2 +- python3-sys/src/pycapsule.rs | 4 ++-- python3-sys/src/pydebug.rs | 2 +- python3-sys/src/pyerrors.rs | 4 ++-- python3-sys/src/pyhash.rs | 2 +- python3-sys/src/pymem.rs | 6 +++--- python3-sys/src/pystate.rs | 4 ++-- python3-sys/src/pystrtod.rs | 2 +- python3-sys/src/pythonrun.rs | 8 ++++---- python3-sys/src/rangeobject.rs | 2 +- python3-sys/src/setobject.rs | 4 ++-- python3-sys/src/sliceobject.rs | 6 +++--- python3-sys/src/structmember.rs | 2 +- python3-sys/src/structseq.rs | 2 +- python3-sys/src/sysmodule.rs | 2 +- python3-sys/src/traceback.rs | 2 +- python3-sys/src/tupleobject.rs | 4 ++-- python3-sys/src/unicodeobject.rs | 4 ++-- python3-sys/src/warnings.rs | 2 +- python3-sys/src/weakrefobject.rs | 4 ++-- src/lib.rs | 26 ++++++++++++++------------ src/py_class/py_class.rs | 2 +- 102 files changed, 220 insertions(+), 217 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 295e701c..a72d7947 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,6 +22,6 @@ install: build_script: - set PATH=C:\Python27-x64;%PATH%&& cargo build --verbose --features python27-sys --no-default-features - set PATH=C:\Python34-x64;%PATH%&& cargo build --verbose --features python3-sys --no-default-features -test: false -#test_script: -# - cargo test --verbose +test_script: + - set PATH=C:\Python27-x64;%PATH%&& cargo test --verbose --features python27-sys --no-default-features + - set PATH=C:\Python34-x64;%PATH%&& cargo test --verbose --features python3-sys --no-default-features diff --git a/examples/hello.rs b/examples/hello.rs index 26070bf5..35084cc8 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,18 +1,20 @@ extern crate cpython; -use cpython::Python; -use cpython::ObjectProtocol; //for call method +use cpython::{Python, PyDict, PyResult}; fn main() { let gil = Python::acquire_gil(); - let py = gil.python(); + hello(gil.python()).unwrap(); +} - let sys = py.import("sys").unwrap(); - let version: String = sys.get(py, "version").unwrap().extract(py).unwrap(); +fn hello(py: Python) -> PyResult<()> { + let sys = py.import("sys")?; + let version: String = sys.get(py, "version")?.extract(py)?; - let os = py.import("os").unwrap(); - let getenv = os.get(py, "getenv").unwrap(); - let user: String = getenv.call(py, ("USER",), None).unwrap().extract(py).unwrap(); + let locals = PyDict::new(py); + locals.set_item(py, "os", py.import("os")?)?; + let user: String = py.eval("os.getenv('USER') or os.getenv('USERNAME')", None, Some(&locals))?.extract(py)?; println!("Hello {}, I'm Python {}", user, version); + Ok(()) } diff --git a/python27-sys/build.rs b/python27-sys/build.rs index 3969cfb7..b485c9f3 100644 --- a/python27-sys/build.rs +++ b/python27-sys/build.rs @@ -182,9 +182,9 @@ fn run_python_script(interpreter: &str, script: &str) -> Result fn get_rustc_link_lib(version: &PythonVersion, enable_shared: bool) -> Result { let dotted_version = format!("{}.{}", version.major, version.minor.unwrap()); if enable_shared { - Ok(format!("cargo:rustc-link-lib=python{}", dotted_version)) + Ok(format!("cargo:rustc-link-lib=pythonXY:python{}", dotted_version)) } else { - Ok(format!("cargo:rustc-link-lib=static=python{}", dotted_version)) + Ok(format!("cargo:rustc-link-lib=static=pythonXY:python{}", dotted_version)) } } @@ -201,11 +201,11 @@ fn get_rustc_link_lib(version: &PythonVersion, _: bool) -> Result Ok(format!("cargo:rustc-link-lib=static=python{}", + "static" => Ok(format!("cargo:rustc-link-lib=static=pythonXY:python{}", dotted_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", + "shared" => Ok(format!("cargo:rustc-link-lib=pythonXY:python{}", dotted_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", + "framework" => Ok(format!("cargo:rustc-link-lib=pythonXY:python{}", dotted_version)), other => Err(format!("unknown linkmodel {}", other)) } @@ -226,7 +226,7 @@ fn get_interpreter_version(line: &str) -> Result { #[cfg(target_os="windows")] fn get_rustc_link_lib(version: &PythonVersion, _: bool) -> Result { // Py_ENABLE_SHARED doesn't seem to be present on windows. - Ok(format!("cargo:rustc-link-lib=python{}{}", version.major, + Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, match version.minor { Some(minor) => minor.to_string(), None => "".to_owned() diff --git a/python27-sys/src/boolobject.rs b/python27-sys/src/boolobject.rs index 234307c9..c92422a0 100644 --- a/python27-sys/src/boolobject.rs +++ b/python27-sys/src/boolobject.rs @@ -4,8 +4,7 @@ use intobject::PyIntObject; pub type PyBoolObject = PyIntObject; - -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyBool_Type: PyTypeObject; static mut _Py_ZeroStruct: PyIntObject; static mut _Py_TrueStruct: PyIntObject; diff --git a/python27-sys/src/bufferobject.rs b/python27-sys/src/bufferobject.rs index ee618b01..3f1262c8 100644 --- a/python27-sys/src/bufferobject.rs +++ b/python27-sys/src/bufferobject.rs @@ -2,7 +2,7 @@ use libc::{c_void, c_int}; use object::*; use pyport::Py_ssize_t; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyBuffer_Type: PyTypeObject; } @@ -14,7 +14,7 @@ pub unsafe fn PyBuffer_Check(op : *mut PyObject) -> c_int { pub const Py_END_OF_BUFFER: Py_ssize_t = -1; -extern "C" { +#[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, diff --git a/python27-sys/src/bytearrayobject.rs b/python27-sys/src/bytearrayobject.rs index a2fc4c3d..cff5b0d4 100644 --- a/python27-sys/src/bytearrayobject.rs +++ b/python27-sys/src/bytearrayobject.rs @@ -17,7 +17,7 @@ struct PyByteArrayObject { pub ob_bytes: *mut c_char, }*/ -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } @@ -31,7 +31,7 @@ pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == u) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; diff --git a/python27-sys/src/cellobject.rs b/python27-sys/src/cellobject.rs index c21692ff..c86dc177 100644 --- a/python27-sys/src/cellobject.rs +++ b/python27-sys/src/cellobject.rs @@ -14,7 +14,7 @@ struct PyCellObject { pub ob_ref: *mut PyObject } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCell_Type: PyTypeObject; } @@ -23,7 +23,7 @@ pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCell_Type) as c_int } -extern "C" { +#[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; diff --git a/python27-sys/src/ceval.rs b/python27-sys/src/ceval.rs index 02f5e549..26c804a5 100644 --- a/python27-sys/src/ceval.rs +++ b/python27-sys/src/ceval.rs @@ -5,7 +5,7 @@ use frameobject::PyFrameObject; use pystate::{PyThreadState, Py_tracefunc}; use pythonrun::PyCompilerFlags; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyEval_CallObjectWithKeywords(callable: *mut PyObject, args: *mut PyObject, kwds: *mut PyObject) @@ -53,7 +53,7 @@ extern "C" { } #[cfg(py_sys_config="WITH_THREAD")] -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyEval_ThreadsInitialized() -> c_int; pub fn PyEval_InitThreads(); pub fn PyEval_AcquireLock(); diff --git a/python27-sys/src/classobject.rs b/python27-sys/src/classobject.rs index 81ac29ed..ed599b97 100644 --- a/python27-sys/src/classobject.rs +++ b/python27-sys/src/classobject.rs @@ -49,7 +49,7 @@ pub struct PyMethodObject { pub im_weakreflist: *mut PyObject, } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyClass_Type: PyTypeObject; pub static mut PyInstance_Type: PyTypeObject; pub static mut PyMethod_Type: PyTypeObject; @@ -73,7 +73,7 @@ pub unsafe fn PyMethod_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == u) as c_int } -extern "C" { +#[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, diff --git a/python27-sys/src/cobject.rs b/python27-sys/src/cobject.rs index 8f34459c..4cf90905 100644 --- a/python27-sys/src/cobject.rs +++ b/python27-sys/src/cobject.rs @@ -1,7 +1,7 @@ use libc::{c_void, c_char, c_int}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCObject_Type: PyTypeObject; } @@ -10,7 +10,7 @@ pub unsafe fn PyCObject_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyCObject_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyCObject_FromVoidPtr(cobj: *mut c_void, destruct: Option *mut PyCodeObject; pub fn PyAST_Compile(arg1: *mut Struct__mod, arg2: *const c_char, diff --git a/python27-sys/src/complexobject.rs b/python27-sys/src/complexobject.rs index 96a181e6..024faf6e 100644 --- a/python27-sys/src/complexobject.rs +++ b/python27-sys/src/complexobject.rs @@ -9,7 +9,7 @@ pub struct Py_complex { pub imag: c_double } -extern "C" { +#[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; @@ -31,7 +31,7 @@ pub struct PyComplexObject { pub cval: Py_complex } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyComplex_Type: PyTypeObject; } @@ -46,7 +46,7 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == u) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyComplex_FromCComplex(v: Py_complex) -> *mut PyObject; pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; diff --git a/python27-sys/src/descrobject.rs b/python27-sys/src/descrobject.rs index e0208654..1f366292 100644 --- a/python27-sys/src/descrobject.rs +++ b/python27-sys/src/descrobject.rs @@ -53,7 +53,7 @@ impl Clone for wrapperbase { pub const PyWrapperFlag_KEYWORDS : c_int = 1; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyWrapperDescr_Type: PyTypeObject; pub static mut PyDictProxy_Type: PyTypeObject; pub static mut PyGetSetDescr_Type: PyTypeObject; @@ -78,7 +78,7 @@ pub unsafe fn PyDescr_IsData(d: *mut PyObject) -> c_int { (*Py_TYPE(d)).tp_descr_set.is_some() as c_int } -extern "C" { +#[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) diff --git a/python27-sys/src/dictobject.rs b/python27-sys/src/dictobject.rs index c363dc7f..0018a27c 100644 --- a/python27-sys/src/dictobject.rs +++ b/python27-sys/src/dictobject.rs @@ -4,7 +4,7 @@ use object::*; //pub enum PyDictObject { /* representation hidden */ } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -25,7 +25,7 @@ pub unsafe fn PyDict_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == u) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyDict_New() -> *mut PyObject; pub fn PyDictProxy_New(dict: *mut PyObject) -> *mut PyObject; pub fn PyDict_Clear(mp: *mut PyObject); diff --git a/python27-sys/src/enumobject.rs b/python27-sys/src/enumobject.rs index fde39e5d..c8fe8c50 100644 --- a/python27-sys/src/enumobject.rs +++ b/python27-sys/src/enumobject.rs @@ -1,6 +1,6 @@ use object::PyTypeObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyEnum_Type: PyTypeObject; pub static mut PyReversed_Type: PyTypeObject; } diff --git a/python27-sys/src/eval.rs b/python27-sys/src/eval.rs index 3abcbd20..84eb3769 100644 --- a/python27-sys/src/eval.rs +++ b/python27-sys/src/eval.rs @@ -2,7 +2,7 @@ use libc::c_int; use object::PyObject; use code::PyCodeObject; -extern "C" { +#[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, diff --git a/python27-sys/src/fileobject.rs b/python27-sys/src/fileobject.rs index 81cb72a9..71793642 100644 --- a/python27-sys/src/fileobject.rs +++ b/python27-sys/src/fileobject.rs @@ -1,7 +1,7 @@ use libc::{c_char, c_int, size_t, FILE}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyFile_Type: PyTypeObject; } @@ -18,7 +18,7 @@ pub unsafe fn PyFile_CheckExact(op : *mut PyObject) -> c_int { pub const PY_STDIOTEXTMODE : &'static str = "b"; -extern "C" { +#[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); diff --git a/python27-sys/src/floatobject.rs b/python27-sys/src/floatobject.rs index c064dcd9..10e4a460 100644 --- a/python27-sys/src/floatobject.rs +++ b/python27-sys/src/floatobject.rs @@ -14,7 +14,7 @@ struct PyFloatObject { pub ob_fval: c_double } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyFloat_Type: PyTypeObject; } @@ -31,7 +31,7 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { pub const PyFloat_STR_PRECISION : c_int = 12; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyFloat_FromString(str: *mut PyObject, pend: *mut *mut c_char) -> *mut PyObject; diff --git a/python27-sys/src/frameobject.rs b/python27-sys/src/frameobject.rs index 6d8e2d3d..70fe2e00 100644 --- a/python27-sys/src/frameobject.rs +++ b/python27-sys/src/frameobject.rs @@ -52,7 +52,7 @@ pub struct PyFrameObject { pub f_localsplus: [*mut PyObject; 1] /* locals+stack, dynamically sized */ } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyFrame_Type: PyTypeObject; } @@ -66,7 +66,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { // ((*f).f_builtins != (*(*(*f).f_tstate).interp).builtins) as c_int //} -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; diff --git a/python27-sys/src/funcobject.rs b/python27-sys/src/funcobject.rs index a04bef88..acda783b 100644 --- a/python27-sys/src/funcobject.rs +++ b/python27-sys/src/funcobject.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyFunction_Type: PyTypeObject; } @@ -12,7 +12,7 @@ pub unsafe fn PyFunction_Check(op : *mut PyObject) -> c_int { } -extern "C" { +#[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; diff --git a/python27-sys/src/genobject.rs b/python27-sys/src/genobject.rs index c3110ffd..60ed29a7 100644 --- a/python27-sys/src/genobject.rs +++ b/python27-sys/src/genobject.rs @@ -18,7 +18,7 @@ pub struct PyGenObject { pub gi_weakreflist: *mut PyObject } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyGen_Type: PyTypeObject; } @@ -32,7 +32,7 @@ pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyGen_Type) as c_int } -extern "C" { +#[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/python27-sys/src/import.rs b/python27-sys/src/import.rs index 5e098263..e52ceec2 100644 --- a/python27-sys/src/import.rs +++ b/python27-sys/src/import.rs @@ -28,7 +28,7 @@ pub unsafe fn PyImport_ImportModuleEx(name: *mut c_char, PyImport_ImportModuleLevel(name, globals, locals, fromlist, -1) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; pub fn PyImport_ImportModuleNoBlock(name: *const c_char) diff --git a/python27-sys/src/intobject.rs b/python27-sys/src/intobject.rs index 39605296..c0b7525a 100644 --- a/python27-sys/src/intobject.rs +++ b/python27-sys/src/intobject.rs @@ -14,7 +14,7 @@ pub struct PyIntObject { pub ob_ival: c_long } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyInt_Type: PyTypeObject; } @@ -29,7 +29,7 @@ pub unsafe fn PyInt_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == u) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyInt_FromString(str: *mut c_char, pend: *mut *mut c_char, base: c_int) -> *mut PyObject; diff --git a/python27-sys/src/iterobject.rs b/python27-sys/src/iterobject.rs index 7021648d..e14d7eb6 100644 --- a/python27-sys/src/iterobject.rs +++ b/python27-sys/src/iterobject.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; diff --git a/python27-sys/src/listobject.rs b/python27-sys/src/listobject.rs index f3d38d40..65761371 100644 --- a/python27-sys/src/listobject.rs +++ b/python27-sys/src/listobject.rs @@ -16,7 +16,7 @@ pub struct PyListObject { pub allocated: Py_ssize_t, } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyList_Type: PyTypeObject; } @@ -49,7 +49,7 @@ 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; } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; pub fn PyList_Size(list: *mut PyObject) -> Py_ssize_t; pub fn PyList_GetItem(list: *mut PyObject, index: Py_ssize_t) diff --git a/python27-sys/src/longobject.rs b/python27-sys/src/longobject.rs index 153253b0..9c8b54d3 100644 --- a/python27-sys/src/longobject.rs +++ b/python27-sys/src/longobject.rs @@ -5,7 +5,7 @@ use object::*; //enum PyLongObject { /* representation hidden */ } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyLong_Type: PyTypeObject; } @@ -20,7 +20,7 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == u) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyLong_FromLong(v: c_long) -> *mut PyObject; pub fn PyLong_FromUnsignedLong(v: c_ulong) -> *mut PyObject; pub fn PyLong_FromSsize_t(v: Py_ssize_t) -> *mut PyObject; diff --git a/python27-sys/src/memoryobject.rs b/python27-sys/src/memoryobject.rs index d60911f2..6d42f281 100644 --- a/python27-sys/src/memoryobject.rs +++ b/python27-sys/src/memoryobject.rs @@ -2,7 +2,7 @@ use libc::{c_int, c_char}; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyMemoryView_Type: PyTypeObject; } @@ -23,7 +23,7 @@ pub unsafe fn PyMemoryView_GET_BASE(op : *mut PyObject) -> *mut PyObject { } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyMemoryView_GetContiguous(base: *mut PyObject, buffertype: c_int, fort: c_char) -> *mut PyObject; diff --git a/python27-sys/src/methodobject.rs b/python27-sys/src/methodobject.rs index 9d7effa9..7cca275e 100644 --- a/python27-sys/src/methodobject.rs +++ b/python27-sys/src/methodobject.rs @@ -3,7 +3,7 @@ use core::ptr; //use pyport::Py_ssize_t; use object::{PyObject, PyTypeObject, Py_TYPE}; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCFunction_Type: PyTypeObject; } @@ -26,7 +26,7 @@ pub type PyNoArgsFunction = -> *mut PyObject; -extern "C" { +#[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; @@ -92,7 +92,7 @@ struct PyCFunctionObject { } */ -extern "C" { +#[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, diff --git a/python27-sys/src/modsupport.rs b/python27-sys/src/modsupport.rs index f8a8792b..f5e90bfb 100644 --- a/python27-sys/src/modsupport.rs +++ b/python27-sys/src/modsupport.rs @@ -4,7 +4,7 @@ use pyport::Py_ssize_t; use object::PyObject; use methodobject::PyMethodDef; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyArg_Parse(args: *mut PyObject, format: *const c_char, ...) -> c_int; pub fn PyArg_ParseTuple(args: *mut PyObject, diff --git a/python27-sys/src/moduleobject.rs b/python27-sys/src/moduleobject.rs index 7421884c..85b4b987 100644 --- a/python27-sys/src/moduleobject.rs +++ b/python27-sys/src/moduleobject.rs @@ -1,7 +1,7 @@ use libc::{c_char, c_int}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyModule_Type: PyTypeObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; diff --git a/python27-sys/src/object.rs b/python27-sys/src/object.rs index 4c17b030..8c663fc2 100644 --- a/python27-sys/src/object.rs +++ b/python27-sys/src/object.rs @@ -614,7 +614,7 @@ pub unsafe fn PyHeapType_GET_MEMBERS(etype: *mut PyHeapTypeObject) -> *mut ::str (etype as *mut u8).offset(basicsize as isize) as *mut ::structmember::PyMemberDef } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } @@ -623,7 +623,7 @@ 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 } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyType_Type: PyTypeObject; pub static mut PyBaseObject_Type: PyTypeObject; pub static mut PySuper_Type: PyTypeObject; @@ -639,7 +639,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == (&mut PyType_Type as *mut _)) as c_int } -extern "C" { +#[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; @@ -666,7 +666,7 @@ pub unsafe fn PyObject_Bytes(o: *mut PyObject) -> *mut PyObject { PyObject_Str(o) } -extern "C" { +#[link(name="pythonXY")] extern "C" { #[cfg(py_sys_config="Py_USING_UNICODE")] pub fn PyObject_Unicode(o: *mut PyObject) -> *mut PyObject; @@ -862,7 +862,7 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) { } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); @@ -888,7 +888,7 @@ pub const Py_NE : c_int = 3; pub const Py_GT : c_int = 4; pub const Py_GE : c_int = 5; -extern "C" { +#[link(name="pythonXY")] extern "C" { fn _PyTrash_thread_deposit_object(o: *mut PyObject); fn _PyTrash_thread_destroy_chain(); } diff --git a/python27-sys/src/objectabstract.rs b/python27-sys/src/objectabstract.rs index 0877526f..70a57032 100644 --- a/python27-sys/src/objectabstract.rs +++ b/python27-sys/src/objectabstract.rs @@ -13,7 +13,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ PyObject_SetAttr(o, attr_name, ptr::null_mut()) } -extern "C" { +#[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, diff --git a/python27-sys/src/objimpl.rs b/python27-sys/src/objimpl.rs index 122e9359..3b78ba74 100644 --- a/python27-sys/src/objimpl.rs +++ b/python27-sys/src/objimpl.rs @@ -2,7 +2,7 @@ use libc::{c_void, c_char, c_int, size_t}; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyObject_Malloc(arg1: size_t) -> *mut c_void; pub fn PyObject_Realloc(arg1: *mut c_void, arg2: size_t) -> *mut c_void; diff --git a/python27-sys/src/pyarena.rs b/python27-sys/src/pyarena.rs index 2b88d57d..6ccb420a 100644 --- a/python27-sys/src/pyarena.rs +++ b/python27-sys/src/pyarena.rs @@ -4,7 +4,7 @@ use object::PyObject; #[allow(missing_copy_implementations)] pub enum PyArena { } -extern "C" { +#[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) diff --git a/python27-sys/src/pycapsule.rs b/python27-sys/src/pycapsule.rs index 1db2b575..5f3bd788 100644 --- a/python27-sys/src/pycapsule.rs +++ b/python27-sys/src/pycapsule.rs @@ -1,7 +1,7 @@ use libc::{c_void, c_char, c_int}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCapsule_Type: PyTypeObject; } @@ -12,7 +12,7 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PyCapsule_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyCapsule_New(pointer: *mut c_void, name: *const c_char, destructor: Option) -> *mut PyObject; diff --git a/python27-sys/src/pydebug.rs b/python27-sys/src/pydebug.rs index e1a732af..2faca7d1 100644 --- a/python27-sys/src/pydebug.rs +++ b/python27-sys/src/pydebug.rs @@ -1,6 +1,6 @@ use libc::{c_char, c_int}; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut Py_DebugFlag: c_int; pub static mut Py_VerboseFlag: c_int; pub static mut Py_InteractiveFlag: c_int; diff --git a/python27-sys/src/pyerrors.rs b/python27-sys/src/pyerrors.rs index 25e763c4..be8938bc 100644 --- a/python27-sys/src/pyerrors.rs +++ b/python27-sys/src/pyerrors.rs @@ -6,7 +6,7 @@ use stringobject::PyString_AS_STRING; #[cfg(py_sys_config="Py_USING_UNICODE")] use unicodeobject::Py_UNICODE; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyErr_SetNone(arg1: *mut PyObject); pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject); pub fn PyErr_SetString(arg1: *mut PyObject, arg2: *const c_char); @@ -54,7 +54,7 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyExc_BaseException: *mut PyObject; pub static mut PyExc_Exception: *mut PyObject; pub static mut PyExc_StopIteration: *mut PyObject; @@ -138,7 +138,7 @@ extern "C" { } #[cfg(py_sys_config="Py_USING_UNICODE")] -extern "C" { +#[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, diff --git a/python27-sys/src/pymem.rs b/python27-sys/src/pymem.rs index ddcfaf90..9f9c19a2 100644 --- a/python27-sys/src/pymem.rs +++ b/python27-sys/src/pymem.rs @@ -1,6 +1,6 @@ use libc::{c_void, size_t}; -extern "C" { +#[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; diff --git a/python27-sys/src/pystate.rs b/python27-sys/src/pystate.rs index b7068bc1..2bfd7998 100644 --- a/python27-sys/src/pystate.rs +++ b/python27-sys/src/pystate.rs @@ -59,7 +59,7 @@ pub enum PyGILState_STATE { } -extern "C" { +#[link(name="pythonXY")] extern "C" { static mut _PyThreadState_Current: *mut PyThreadState; //static mut _PyThreadState_GetFrame: PyThreadFrameGetter; diff --git a/python27-sys/src/pythonrun.rs b/python27-sys/src/pythonrun.rs index de447077..3f498bb0 100644 --- a/python27-sys/src/pythonrun.rs +++ b/python27-sys/src/pythonrun.rs @@ -25,7 +25,7 @@ pub enum Struct__node { } #[allow(missing_copy_implementations)] pub enum Struct_symtable { } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn Py_SetProgramName(arg1: *mut c_char); pub fn Py_GetProgramName() -> *mut c_char; pub fn Py_SetPythonHome(arg1: *mut c_char); diff --git a/python27-sys/src/rangeobject.rs b/python27-sys/src/rangeobject.rs index acaf9f53..062f3203 100644 --- a/python27-sys/src/rangeobject.rs +++ b/python27-sys/src/rangeobject.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyRange_Type: PyTypeObject; } diff --git a/python27-sys/src/setobject.rs b/python27-sys/src/setobject.rs index 7d4b8796..a5dc4223 100644 --- a/python27-sys/src/setobject.rs +++ b/python27-sys/src/setobject.rs @@ -4,7 +4,7 @@ use object::*; //enum PySetObject { /* representation hidden */ } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PySet_Type: PyTypeObject; pub static mut PyFrozenSet_Type: PyTypeObject; } @@ -41,7 +41,7 @@ pub unsafe fn PyFrozenSet_Check(ob : *mut PyObject) -> c_int { (Py_TYPE(ob) == f || PyType_IsSubtype(Py_TYPE(ob), f) != 0) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PySet_New(iterable: *mut PyObject) -> *mut PyObject; pub fn PyFrozenSet_New(iterable: *mut PyObject) -> *mut PyObject; pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; diff --git a/python27-sys/src/sliceobject.rs b/python27-sys/src/sliceobject.rs index 9379342d..094746ba 100644 --- a/python27-sys/src/sliceobject.rs +++ b/python27-sys/src/sliceobject.rs @@ -2,7 +2,7 @@ use libc::c_int; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { static mut _Py_EllipsisObject: PyObject; } @@ -25,7 +25,7 @@ pub struct PySliceObject { pub step: *mut PyObject } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } @@ -35,7 +35,7 @@ pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PySlice_Type) as c_int } -extern "C" { +#[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, diff --git a/python27-sys/src/stringobject.rs b/python27-sys/src/stringobject.rs index a990e522..458f6156 100644 --- a/python27-sys/src/stringobject.rs +++ b/python27-sys/src/stringobject.rs @@ -17,7 +17,7 @@ pub struct PyStringObject { pub ob_sval: [c_char; 1], } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyBaseString_Type: PyTypeObject; pub static mut PyString_Type: PyTypeObject; } @@ -45,7 +45,7 @@ pub unsafe fn PyString_AS_STRING(op : *mut PyObject) -> *mut c_char { (*(op as *mut PyStringObject)).ob_sval.as_mut_ptr() } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyString_FromString(v: *const c_char) -> *mut PyObject; pub fn PyString_FromStringAndSize(v: *const c_char, len: Py_ssize_t) -> *mut PyObject; diff --git a/python27-sys/src/structmember.rs b/python27-sys/src/structmember.rs index 225cda27..3ada3685 100644 --- a/python27-sys/src/structmember.rs +++ b/python27-sys/src/structmember.rs @@ -53,7 +53,7 @@ pub const PY_WRITE_RESTRICTED : c_int = 4; pub const RESTRICTED : c_int = (READ_RESTRICTED | PY_WRITE_RESTRICTED); -extern "C" { +#[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/python27-sys/src/traceback.rs b/python27-sys/src/traceback.rs index 0a53c459..3d67e867 100644 --- a/python27-sys/src/traceback.rs +++ b/python27-sys/src/traceback.rs @@ -18,7 +18,7 @@ pub struct PyTracebackObject { pub tb_lineno: c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyTraceBack_Here(arg1: *mut PyFrameObject) -> c_int; pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; diff --git a/python27-sys/src/tupleobject.rs b/python27-sys/src/tupleobject.rs index 29030d42..f469f2ec 100644 --- a/python27-sys/src/tupleobject.rs +++ b/python27-sys/src/tupleobject.rs @@ -15,7 +15,7 @@ pub struct PyTupleObject { pub ob_item: [*mut PyObject; 1], } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyTuple_Type: PyTypeObject; } @@ -48,7 +48,7 @@ pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObjec *(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i as isize) = v; } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyTuple_New(size: Py_ssize_t) -> *mut PyObject; pub fn PyTuple_Size(p: *mut PyObject) -> Py_ssize_t; pub fn PyTuple_GetItem(p: *mut PyObject, pos: Py_ssize_t) diff --git a/python27-sys/src/unicodeobject.rs b/python27-sys/src/unicodeobject.rs index a62e36ac..4b67192d 100644 --- a/python27-sys/src/unicodeobject.rs +++ b/python27-sys/src/unicodeobject.rs @@ -29,7 +29,7 @@ pub struct PyUnicodeObject { pub defenc: *mut PyObject, } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyUnicode_Type: PyTypeObject; } @@ -69,7 +69,7 @@ pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UNICODE = 0xFFFD; #[allow(dead_code)] #[cfg(py_sys_config="Py_UNICODE_SIZE_4")] -extern "C" { +#[link(name="pythonXY")] extern "C" { fn PyUnicodeUCS4_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject; fn PyUnicodeUCS4_FromStringAndSize(u: *const c_char, @@ -313,7 +313,7 @@ extern "C" { #[allow(dead_code)] #[cfg(not(py_sys_config="Py_UNICODE_SIZE_4"))] -extern "C" { +#[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, diff --git a/python27-sys/src/warnings.rs b/python27-sys/src/warnings.rs index e30d9d39..7ea49000 100644 --- a/python27-sys/src/warnings.rs +++ b/python27-sys/src/warnings.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use pyport::Py_ssize_t; use object::PyObject; -extern "C" { +#[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, diff --git a/python27-sys/src/weakrefobject.rs b/python27-sys/src/weakrefobject.rs index 41249732..3bdbf150 100644 --- a/python27-sys/src/weakrefobject.rs +++ b/python27-sys/src/weakrefobject.rs @@ -18,7 +18,7 @@ pub struct PyWeakReference { pub wr_next: *mut PyWeakReference } -extern "C" { +#[link(name="pythonXY")] extern "C" { static mut _PyWeakref_RefType: PyTypeObject; static mut _PyWeakref_ProxyType: PyTypeObject; static mut _PyWeakref_CallableProxyType: PyTypeObject; @@ -45,7 +45,7 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { (PyWeakref_CheckRef(op) != 0 || PyWeakref_CheckProxy(op) != 0) as c_int } -extern "C" { +#[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) diff --git a/python3-sys/build.rs b/python3-sys/build.rs index 5f80c5ed..088b4c59 100644 --- a/python3-sys/build.rs +++ b/python3-sys/build.rs @@ -181,9 +181,9 @@ fn run_python_script(interpreter: &str, script: &str) -> Result #[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)) + Ok(format!("cargo:rustc-link-lib=pythonXY:python{}", ld_version)) } else { - Ok(format!("cargo:rustc-link-lib=static=python{}", ld_version)) + Ok(format!("cargo:rustc-link-lib=static=pythonXY:python{}", ld_version)) } } @@ -199,11 +199,11 @@ fn get_rustc_link_lib(_: &PythonVersion, ld_version: &str, _: bool) -> Result Ok(format!("cargo:rustc-link-lib=static=python{}", + "static" => Ok(format!("cargo:rustc-link-lib=static=pythonXY:python{}", ld_version)), - "shared" => Ok(format!("cargo:rustc-link-lib=python{}", + "shared" => Ok(format!("cargo:rustc-link-lib=pythonXY:python{}", ld_version)), - "framework" => Ok(format!("cargo:rustc-link-lib=python{}", + "framework" => Ok(format!("cargo:rustc-link-lib=pythonXY:python{}", ld_version)), other => Err(format!("unknown linkmodel {}", other)) } @@ -225,7 +225,7 @@ fn get_interpreter_version(line: &str) -> Result { #[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=python{}{}", version.major, + Ok(format!("cargo:rustc-link-lib=pythonXY:python{}{}", version.major, match version.minor { Some(minor) => minor.to_string(), None => "".to_owned() diff --git a/python3-sys/src/bltinmodule.rs b/python3-sys/src/bltinmodule.rs index 37de6953..c63d0241 100644 --- a/python3-sys/src/bltinmodule.rs +++ b/python3-sys/src/bltinmodule.rs @@ -1,6 +1,6 @@ use object::PyTypeObject; -extern "C" { +#[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/python3-sys/src/boolobject.rs b/python3-sys/src/boolobject.rs index 0edcc9e0..cc311720 100644 --- a/python3-sys/src/boolobject.rs +++ b/python3-sys/src/boolobject.rs @@ -2,7 +2,7 @@ use libc::{c_int, c_long}; use object::*; use longobject::PyLongObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyBool_Type: PyTypeObject; static mut _Py_FalseStruct: PyLongObject; static mut _Py_TrueStruct: PyLongObject; diff --git a/python3-sys/src/bytearrayobject.rs b/python3-sys/src/bytearrayobject.rs index 76591953..b17470b4 100644 --- a/python3-sys/src/bytearrayobject.rs +++ b/python3-sys/src/bytearrayobject.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use object::*; use pyport::Py_ssize_t; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyByteArray_Type: PyTypeObject; pub static mut PyByteArrayIter_Type: PyTypeObject; } @@ -17,7 +17,7 @@ pub unsafe fn PyByteArray_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyByteArray_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyByteArray_FromObject(o: *mut PyObject) -> *mut PyObject; pub fn PyByteArray_Concat(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject; diff --git a/python3-sys/src/bytesobject.rs b/python3-sys/src/bytesobject.rs index 16734853..de17e6d9 100644 --- a/python3-sys/src/bytesobject.rs +++ b/python3-sys/src/bytesobject.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use object::*; use pyport::Py_ssize_t; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyBytes_Type: PyTypeObject; pub static mut PyBytesIter_Type: PyTypeObject; } @@ -17,7 +17,7 @@ pub unsafe fn PyBytes_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyBytes_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyBytes_FromStringAndSize(arg1: *const c_char, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyBytes_FromString(arg1: *const c_char) -> *mut PyObject; diff --git a/python3-sys/src/ceval.rs b/python3-sys/src/ceval.rs index 3f9da903..dc93c9ed 100644 --- a/python3-sys/src/ceval.rs +++ b/python3-sys/src/ceval.rs @@ -2,7 +2,7 @@ use libc::{c_void, c_char, c_int}; use object::PyObject; use pystate::PyThreadState; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyEval_CallObjectWithKeywords(func: *mut PyObject, obj: *mut PyObject, kwargs: *mut PyObject) @@ -14,7 +14,7 @@ pub unsafe fn PyEval_CallObject(func: *mut PyObject, arg: *mut PyObject) -> *mut PyEval_CallObjectWithKeywords(func, arg, ::core::ptr::null_mut()) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyEval_CallFunction(obj: *mut PyObject, format: *const c_char, ...) -> *mut PyObject; @@ -39,7 +39,7 @@ extern "C" { // TODO: Py_EnterRecursiveCall etc. -extern "C" { +#[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; @@ -51,7 +51,7 @@ extern "C" { } #[cfg(py_sys_config = "WITH_THREAD")] -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyEval_ThreadsInitialized() -> c_int; pub fn PyEval_InitThreads() -> (); pub fn PyEval_AcquireLock() -> (); diff --git a/python3-sys/src/code.rs b/python3-sys/src/code.rs index 60b7bcca..9e8f8183 100644 --- a/python3-sys/src/code.rs +++ b/python3-sys/src/code.rs @@ -70,7 +70,7 @@ pub const CO_FUTURE_GENERATOR_STOP : c_int = 0x80000; pub const CO_MAXBLOCKS: usize = 20; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCode_Type: PyTypeObject; pub fn PyCode_New(arg1: c_int, arg2: c_int, diff --git a/python3-sys/src/codecs.rs b/python3-sys/src/codecs.rs index 086b78dc..90d585cd 100644 --- a/python3-sys/src/codecs.rs +++ b/python3-sys/src/codecs.rs @@ -1,7 +1,7 @@ use libc::{c_char, c_int}; use object::PyObject; -extern "C" { +#[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/python3-sys/src/compile.rs b/python3-sys/src/compile.rs index 52586dba..40be6553 100644 --- a/python3-sys/src/compile.rs +++ b/python3-sys/src/compile.rs @@ -32,7 +32,7 @@ pub const FUTURE_BARRY_AS_BDFL : &'static str = "barry_as_FLUFL"; pub const FUTURE_GENERATOR_STOP : &'static str = "generator_stop"; #[cfg(not(Py_LIMITED_API))] -extern "C" { +#[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, diff --git a/python3-sys/src/complexobject.rs b/python3-sys/src/complexobject.rs index 555c3847..346ceae2 100644 --- a/python3-sys/src/complexobject.rs +++ b/python3-sys/src/complexobject.rs @@ -1,7 +1,7 @@ use libc::{c_double, c_int}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyComplex_Type: PyTypeObject; } @@ -15,7 +15,7 @@ pub unsafe fn PyComplex_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyComplex_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyComplex_FromDoubles(real: c_double, imag: c_double) -> *mut PyObject; pub fn PyComplex_RealAsDouble(op: *mut PyObject) -> c_double; diff --git a/python3-sys/src/descrobject.rs b/python3-sys/src/descrobject.rs index 3745e81d..be32dbca 100644 --- a/python3-sys/src/descrobject.rs +++ b/python3-sys/src/descrobject.rs @@ -27,7 +27,7 @@ impl Clone for PyGetSetDef { #[inline] fn clone(&self) -> PyGetSetDef { *self } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyClassMethodDescr_Type: PyTypeObject; pub static mut PyGetSetDescr_Type: PyTypeObject; pub static mut PyMemberDescr_Type: PyTypeObject; diff --git a/python3-sys/src/dictobject.rs b/python3-sys/src/dictobject.rs index ee4c91d7..ad8007d5 100644 --- a/python3-sys/src/dictobject.rs +++ b/python3-sys/src/dictobject.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyDict_Type: PyTypeObject; pub static mut PyDictIterKey_Type: PyTypeObject; pub static mut PyDictIterValue_Type: PyTypeObject; @@ -42,7 +42,7 @@ pub unsafe fn PyDictViewSet_Check(op : *mut PyObject) -> c_int { (PyDictKeys_Check(op) != 0 || PyDictItems_Check(op) != 0) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyDict_New() -> *mut PyObject; pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject; diff --git a/python3-sys/src/enumobject.rs b/python3-sys/src/enumobject.rs index fde39e5d..c8fe8c50 100644 --- a/python3-sys/src/enumobject.rs +++ b/python3-sys/src/enumobject.rs @@ -1,6 +1,6 @@ use object::PyTypeObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyEnum_Type: PyTypeObject; pub static mut PyReversed_Type: PyTypeObject; } diff --git a/python3-sys/src/eval.rs b/python3-sys/src/eval.rs index f6aa8ee2..b2b8a20b 100644 --- a/python3-sys/src/eval.rs +++ b/python3-sys/src/eval.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::PyObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyEval_EvalCode(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; pub fn PyEval_EvalCodeEx(co: *mut PyObject, globals: *mut PyObject, diff --git a/python3-sys/src/fileobject.rs b/python3-sys/src/fileobject.rs index ec3d2a0b..2ac3869d 100644 --- a/python3-sys/src/fileobject.rs +++ b/python3-sys/src/fileobject.rs @@ -3,7 +3,7 @@ use object::PyObject; pub const PY_STDIOTEXTMODE : &'static str = "b"; -extern "C" { +#[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, diff --git a/python3-sys/src/floatobject.rs b/python3-sys/src/floatobject.rs index efe170e4..576f28d7 100644 --- a/python3-sys/src/floatobject.rs +++ b/python3-sys/src/floatobject.rs @@ -1,7 +1,7 @@ use libc::{c_int, c_double}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyFloat_Type: PyTypeObject; } @@ -15,7 +15,7 @@ pub unsafe fn PyFloat_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFloat_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyFloat_GetMax() -> c_double; pub fn PyFloat_GetMin() -> c_double; pub fn PyFloat_GetInfo() -> *mut PyObject; diff --git a/python3-sys/src/frameobject.rs b/python3-sys/src/frameobject.rs index c30c80ee..dbced528 100644 --- a/python3-sys/src/frameobject.rs +++ b/python3-sys/src/frameobject.rs @@ -51,7 +51,7 @@ pub struct PyFrameObject { pub f_localsplus: [*mut PyObject; 1] /* locals+stack, dynamically sized */ } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyFrame_Type: PyTypeObject; } @@ -60,7 +60,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyFrame_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyFrame_New(tstate: *mut PyThreadState, code: *mut PyCodeObject, globals: *mut PyObject, locals: *mut PyObject) -> *mut PyFrameObject; diff --git a/python3-sys/src/import.rs b/python3-sys/src/import.rs index e7e8c7b3..23abd7a1 100644 --- a/python3-sys/src/import.rs +++ b/python3-sys/src/import.rs @@ -1,7 +1,7 @@ use libc::{c_char, c_int, c_long}; use object::PyObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyImport_GetMagicNumber() -> c_long; pub fn PyImport_GetMagicTag() -> *const c_char; pub fn PyImport_ExecCodeModule(name: *const c_char, @@ -51,7 +51,7 @@ pub unsafe fn PyImport_ImportModuleEx(name: *const c_char, PyImport_ImportModuleLevel(name, globals, locals, fromlist, 0) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject; pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; diff --git a/python3-sys/src/intrcheck.rs b/python3-sys/src/intrcheck.rs index 8508466d..17d0e490 100644 --- a/python3-sys/src/intrcheck.rs +++ b/python3-sys/src/intrcheck.rs @@ -1,6 +1,6 @@ use libc::c_int; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyOS_InterruptOccurred() -> c_int; pub fn PyOS_InitInterrupts() -> (); pub fn PyOS_AfterFork() -> (); diff --git a/python3-sys/src/iterobject.rs b/python3-sys/src/iterobject.rs index 7021648d..e14d7eb6 100644 --- a/python3-sys/src/iterobject.rs +++ b/python3-sys/src/iterobject.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PySeqIter_Type: PyTypeObject; pub static mut PyCallIter_Type: PyTypeObject; diff --git a/python3-sys/src/listobject.rs b/python3-sys/src/listobject.rs index 49a7dffe..77b385cd 100644 --- a/python3-sys/src/listobject.rs +++ b/python3-sys/src/listobject.rs @@ -2,7 +2,7 @@ use libc::c_int; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyList_Type: PyTypeObject; pub static mut PyListIter_Type: PyTypeObject; pub static mut PyListRevIter_Type: PyTypeObject; @@ -18,7 +18,7 @@ pub unsafe fn PyList_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyList_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyList_New(size: Py_ssize_t) -> *mut PyObject; pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t; pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) diff --git a/python3-sys/src/longobject.rs b/python3-sys/src/longobject.rs index adc4e596..bd911c55 100644 --- a/python3-sys/src/longobject.rs +++ b/python3-sys/src/longobject.rs @@ -4,7 +4,7 @@ use pyport::Py_ssize_t; pub enum PyLongObject {} -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyLong_Type: PyTypeObject; } @@ -18,7 +18,7 @@ pub unsafe fn PyLong_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyLong_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyLong_FromLong(arg1: c_long) -> *mut PyObject; pub fn PyLong_FromUnsignedLong(arg1: c_ulong) -> *mut PyObject; pub fn PyLong_FromSize_t(arg1: size_t) -> *mut PyObject; diff --git a/python3-sys/src/memoryobject.rs b/python3-sys/src/memoryobject.rs index f064eb2e..c8b7faf8 100644 --- a/python3-sys/src/memoryobject.rs +++ b/python3-sys/src/memoryobject.rs @@ -2,7 +2,7 @@ use libc::{c_int, c_char}; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyMemoryView_Type: PyTypeObject; } @@ -11,7 +11,7 @@ pub unsafe fn PyMemoryView_Check(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyMemoryView_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject; pub fn PyMemoryView_FromMemory(mem: *mut c_char, size: Py_ssize_t, flags: c_int) -> *mut PyObject; diff --git a/python3-sys/src/methodobject.rs b/python3-sys/src/methodobject.rs index 0620b1aa..676094fb 100644 --- a/python3-sys/src/methodobject.rs +++ b/python3-sys/src/methodobject.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use core::{mem, ptr}; use object::{PyObject, PyTypeObject, Py_TYPE}; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCFunction_Type: PyTypeObject; } @@ -31,7 +31,7 @@ pub type PyNoArgsFunction = unsafe extern "C" fn(slf: *mut PyObject) -> *mut PyObject; -extern "C" { +#[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; @@ -60,7 +60,7 @@ pub unsafe fn PyCFunction_New(ml: *mut PyMethodDef, slf: *mut PyObject) -> *mut PyCFunction_NewEx(ml, slf, ptr::null_mut()) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyCFunction_NewEx(arg1: *mut PyMethodDef, arg2: *mut PyObject, arg3: *mut PyObject) -> *mut PyObject; } @@ -88,7 +88,7 @@ pub const METH_COEXIST : c_int = 0x0040; #[cfg(all(Py_3_6, not(Py_LIMITED_API)))] pub const METHOD_FASTCALL : c_int = 0x0080; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyCFunction_ClearFreeList() -> c_int; } diff --git a/python3-sys/src/modsupport.rs b/python3-sys/src/modsupport.rs index 8606ec37..1b9138d7 100644 --- a/python3-sys/src/modsupport.rs +++ b/python3-sys/src/modsupport.rs @@ -5,7 +5,7 @@ use moduleobject::PyModuleDef; #[cfg(Py_3_5)] use methodobject::PyMethodDef; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyArg_Parse(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; pub fn PyArg_ParseTuple(arg1: *mut PyObject, @@ -53,7 +53,7 @@ pub const Py_CLEANUP_SUPPORTED: i32 = 0x20000; pub const PYTHON_API_VERSION: i32 = 1013; pub const PYTHON_ABI_VERSION: i32 = 3; -extern "C" { +#[link(name="pythonXY")] extern "C" { #[cfg(not(py_sys_config="Py_TRACE_REFS"))] pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; diff --git a/python3-sys/src/moduleobject.rs b/python3-sys/src/moduleobject.rs index 79c6edee..5f0a740d 100644 --- a/python3-sys/src/moduleobject.rs +++ b/python3-sys/src/moduleobject.rs @@ -3,7 +3,7 @@ use pyport::Py_ssize_t; use object::*; use methodobject::PyMethodDef; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyModule_Type: PyTypeObject; } @@ -17,7 +17,7 @@ pub unsafe fn PyModule_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyModule_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; pub fn PyModule_New(name: *const c_char) -> *mut PyObject; pub fn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject; diff --git a/python3-sys/src/object.rs b/python3-sys/src/object.rs index f215a4d7..10143690 100644 --- a/python3-sys/src/object.rs +++ b/python3-sys/src/object.rs @@ -657,7 +657,7 @@ impl Default for PyType_Spec { fn default() -> PyType_Spec { unsafe { ::core::mem::zeroed() } } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyType_FromSpec(arg1: *mut PyType_Spec) -> *mut PyObject; //#[cfg(Py_3_3)] @@ -669,7 +669,7 @@ extern "C" { -> *mut c_void; } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyType_IsSubtype(a: *mut PyTypeObject, b: *mut PyTypeObject) -> c_int; } @@ -678,7 +678,7 @@ 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 } -extern "C" { +#[link(name="pythonXY")] extern "C" { /// built-in 'type' pub static mut PyType_Type: PyTypeObject; /// built-in 'object' @@ -699,7 +699,7 @@ pub unsafe fn PyType_CheckExact(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyType_Type) as c_int } -extern "C" { +#[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; @@ -824,7 +824,7 @@ pub unsafe fn PyType_FastSubclass(t : *mut PyTypeObject, f : c_ulong) -> c_int { PyType_HasFeature(t, f) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn _Py_Dealloc(arg1: *mut PyObject) -> (); } @@ -873,7 +873,7 @@ pub unsafe fn Py_XDECREF(op : *mut PyObject) { } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn Py_IncRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject); diff --git a/python3-sys/src/objectabstract.rs b/python3-sys/src/objectabstract.rs index 97cbb1c4..60c713e0 100644 --- a/python3-sys/src/objectabstract.rs +++ b/python3-sys/src/objectabstract.rs @@ -13,7 +13,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_ PyObject_SetAttr(o, attr_name, ptr::null_mut()) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyObject_Call(callable_object: *mut PyObject, args: *mut PyObject, kw: *mut PyObject) -> *mut PyObject; pub fn PyObject_CallObject(callable_object: *mut PyObject, @@ -41,7 +41,7 @@ pub unsafe fn PyObject_Length(o: *mut PyObject) -> Py_ssize_t { PyObject_Size(o) } -extern "C" { +#[link(name="pythonXY")] extern "C" { #[cfg(all(not(Py_LIMITED_API), Py_3_4))] pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; @@ -78,7 +78,7 @@ pub unsafe fn PyObject_CheckBuffer(o: *mut PyObject) -> c_int { } #[cfg(not(Py_LIMITED_API))] -extern "C" { +#[link(name="pythonXY")] extern "C" { 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) @@ -105,7 +105,7 @@ extern "C" { pub fn PyBuffer_Release(view: *mut Py_buffer) -> (); } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyObject_Format(obj: *mut PyObject, format_spec: *mut PyObject) -> *mut PyObject; pub fn PyObject_GetIter(arg1: *mut PyObject) -> *mut PyObject; @@ -120,7 +120,7 @@ pub unsafe fn PyIter_Check(o: *mut PyObject) -> c_int { }) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyIter_Next(arg1: *mut PyObject) -> *mut PyObject; pub fn PyNumber_Check(o: *mut PyObject) -> c_int; @@ -165,7 +165,7 @@ pub unsafe fn PyIndex_Check(o: *mut PyObject) -> c_int { (!tp_as_number.is_null() && (*tp_as_number).nb_index.is_some()) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyNumber_Index(o: *mut PyObject) -> *mut PyObject; pub fn PyNumber_AsSsize_t(o: *mut PyObject, exc: *mut PyObject) -> Py_ssize_t; @@ -210,7 +210,7 @@ pub unsafe fn PySequence_Length(o: *mut PyObject) -> Py_ssize_t { PySequence_Size(o) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PySequence_Concat(o1: *mut PyObject, o2: *mut PyObject) -> *mut PyObject; pub fn PySequence_Repeat(o: *mut PyObject, count: Py_ssize_t) @@ -244,7 +244,7 @@ pub unsafe fn PySequence_In(o: *mut PyObject, value: *mut PyObject) -> c_int { PySequence_Contains(o, value) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PySequence_Index(o: *mut PyObject, value: *mut PyObject) -> Py_ssize_t; pub fn PySequence_InPlaceConcat(o1: *mut PyObject, o2: *mut PyObject) @@ -270,7 +270,7 @@ pub unsafe fn PyMapping_DelItem(o : *mut PyObject, key : *mut PyObject) -> c_int PyObject_DelItem(o, key) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyMapping_HasKeyString(o: *mut PyObject, key: *const c_char) -> c_int; diff --git a/python3-sys/src/objimpl.rs b/python3-sys/src/objimpl.rs index bdf36876..4de05ee1 100644 --- a/python3-sys/src/objimpl.rs +++ b/python3-sys/src/objimpl.rs @@ -2,7 +2,7 @@ use libc::{c_void, c_int, size_t}; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyObject_Malloc(size: size_t) -> *mut c_void; #[cfg(Py_3_5)] pub fn PyObject_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; @@ -44,7 +44,7 @@ impl Default for PyObjectArenaAllocator { #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } #[cfg(all(not(Py_LIMITED_API), Py_3_4))] -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator) -> (); pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator) @@ -68,7 +68,7 @@ pub unsafe fn PyObject_IS_GC(o : *mut PyObject) -> c_int { }) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn _PyObject_GC_Resize(arg1: *mut PyVarObject, arg2: Py_ssize_t) -> *mut PyVarObject; diff --git a/python3-sys/src/osmodule.rs b/python3-sys/src/osmodule.rs index bd9ea3f4..f151a7f2 100644 --- a/python3-sys/src/osmodule.rs +++ b/python3-sys/src/osmodule.rs @@ -1,6 +1,6 @@ // This header is new in Python 3.6 use object::PyObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyOS_FSPath(path: *mut PyObject) -> *mut PyObject; } diff --git a/python3-sys/src/pycapsule.rs b/python3-sys/src/pycapsule.rs index 1db2b575..5f3bd788 100644 --- a/python3-sys/src/pycapsule.rs +++ b/python3-sys/src/pycapsule.rs @@ -1,7 +1,7 @@ use libc::{c_void, c_char, c_int}; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyCapsule_Type: PyTypeObject; } @@ -12,7 +12,7 @@ pub unsafe fn PyCapsule_CheckExact(ob: *mut PyObject) -> c_int { (Py_TYPE(ob) == &mut PyCapsule_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyCapsule_New(pointer: *mut c_void, name: *const c_char, destructor: Option) -> *mut PyObject; diff --git a/python3-sys/src/pydebug.rs b/python3-sys/src/pydebug.rs index 6649352b..bffcb6fc 100644 --- a/python3-sys/src/pydebug.rs +++ b/python3-sys/src/pydebug.rs @@ -1,7 +1,7 @@ use libc::c_int; #[cfg(not(Py_LIMITED_API))] -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut Py_DebugFlag: c_int; pub static mut Py_VerboseFlag: c_int; pub static mut Py_QuietFlag: c_int; diff --git a/python3-sys/src/pyerrors.rs b/python3-sys/src/pyerrors.rs index 10fc779c..7554c532 100644 --- a/python3-sys/src/pyerrors.rs +++ b/python3-sys/src/pyerrors.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyErr_SetNone(arg1: *mut PyObject) -> (); pub fn PyErr_SetObject(arg1: *mut PyObject, arg2: *mut PyObject) -> (); pub fn PyErr_SetString(exception: *mut PyObject, @@ -52,7 +52,7 @@ pub unsafe fn PyExceptionInstance_Class(x: *mut PyObject) -> *mut PyObject { (*x).ob_type as *mut PyObject } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyExc_BaseException: *mut PyObject; pub static mut PyExc_Exception: *mut PyObject; pub static mut PyExc_StopIteration: *mut PyObject; diff --git a/python3-sys/src/pyhash.rs b/python3-sys/src/pyhash.rs index 4b0833af..b358c82b 100644 --- a/python3-sys/src/pyhash.rs +++ b/python3-sys/src/pyhash.rs @@ -18,7 +18,7 @@ impl Default for PyHash_FuncDef { #[inline] fn default() -> Self { unsafe { ::core::mem::zeroed() } } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef; } diff --git a/python3-sys/src/pymem.rs b/python3-sys/src/pymem.rs index 479ecf34..953bb9d6 100644 --- a/python3-sys/src/pymem.rs +++ b/python3-sys/src/pymem.rs @@ -2,7 +2,7 @@ use libc::{c_void, size_t}; #[cfg(Py_3_4)] #[cfg(not(Py_LIMITED_API))] -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; #[cfg(Py_3_5)] pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) @@ -12,7 +12,7 @@ extern "C" { pub fn PyMem_RawFree(ptr: *mut c_void) -> (); } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyMem_Malloc(size: size_t) -> *mut c_void; #[cfg(Py_3_5)] pub fn PyMem_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; @@ -71,7 +71,7 @@ pub struct PyMemAllocatorEx { #[cfg(Py_3_4)] #[cfg(not(Py_LIMITED_API))] -extern "C" { +#[link(name="pythonXY")] extern "C" { #[cfg(not(Py_3_5))] pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocator) -> (); diff --git a/python3-sys/src/pystate.rs b/python3-sys/src/pystate.rs index 30102adf..0fb65747 100644 --- a/python3-sys/src/pystate.rs +++ b/python3-sys/src/pystate.rs @@ -8,7 +8,7 @@ pub const MAX_CO_EXTRA_USERS: c_int = 255; pub enum PyInterpreterState { } pub enum PyThreadState { } -extern "C" { +#[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) -> (); @@ -38,7 +38,7 @@ pub enum PyGILState_STATE { PyGILState_UNLOCKED } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyGILState_Ensure() -> PyGILState_STATE; pub fn PyGILState_Release(arg1: PyGILState_STATE) -> (); pub fn PyGILState_GetThisThreadState() -> *mut PyThreadState; diff --git a/python3-sys/src/pystrtod.rs b/python3-sys/src/pystrtod.rs index f5cbc224..3dfc1757 100644 --- a/python3-sys/src/pystrtod.rs +++ b/python3-sys/src/pystrtod.rs @@ -1,7 +1,7 @@ use libc::{c_char, c_int, c_double}; use object::PyObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyOS_string_to_double(str: *const c_char, endptr: *mut *mut c_char, overflow_exception: *mut PyObject) diff --git a/python3-sys/src/pythonrun.rs b/python3-sys/src/pythonrun.rs index 651f330c..f30db019 100644 --- a/python3-sys/src/pythonrun.rs +++ b/python3-sys/src/pythonrun.rs @@ -7,7 +7,7 @@ use pyarena::PyArena; // TODO: PyCF_MASK etc. constants -extern "C" { // TODO: these moved to pylifecycle.h +#[link(name="pythonXY")] extern "C" { // TODO: these moved to pylifecycle.h pub fn Py_SetProgramName(arg1: *mut wchar_t) -> (); pub fn Py_GetProgramName() -> *mut wchar_t; pub fn Py_SetPythonHome(arg1: *mut wchar_t) -> (); @@ -31,7 +31,7 @@ pub struct PyCompilerFlags { pub enum _mod {} #[cfg(not(Py_LIMITED_API))] -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int; @@ -105,7 +105,7 @@ pub unsafe fn PyParser_SimpleParseFile(fp: *mut FILE, s: *const c_char, b: c_int PyParser_SimpleParseFileFlags(fp, s, b, 0) } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyParser_SimpleParseStringFlags(arg1: *const c_char, arg2: c_int, arg3: c_int) @@ -147,7 +147,7 @@ pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int 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) } -extern "C" { +#[link(name="pythonXY")] extern "C" { #[cfg(not(Py_LIMITED_API))] pub fn Py_CompileStringExFlags(str: *const c_char, filename: *const c_char, diff --git a/python3-sys/src/rangeobject.rs b/python3-sys/src/rangeobject.rs index 8cb510b8..26bce592 100644 --- a/python3-sys/src/rangeobject.rs +++ b/python3-sys/src/rangeobject.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyRange_Type: PyTypeObject; pub static mut PyRangeIter_Type: PyTypeObject; pub static mut PyLongRangeIter_Type: PyTypeObject; diff --git a/python3-sys/src/setobject.rs b/python3-sys/src/setobject.rs index b2c5cc9a..08fd365a 100644 --- a/python3-sys/src/setobject.rs +++ b/python3-sys/src/setobject.rs @@ -2,7 +2,7 @@ use libc::c_int; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PySet_Type: PyTypeObject; pub static mut PyFrozenSet_Type: PyTypeObject; pub static mut PySetIter_Type: PyTypeObject; @@ -35,7 +35,7 @@ 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 } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PySet_New(arg1: *mut PyObject) -> *mut PyObject; pub fn PyFrozenSet_New(arg1: *mut PyObject) -> *mut PyObject; pub fn PySet_Size(anyset: *mut PyObject) -> Py_ssize_t; diff --git a/python3-sys/src/sliceobject.rs b/python3-sys/src/sliceobject.rs index 12d49846..56c1db7e 100644 --- a/python3-sys/src/sliceobject.rs +++ b/python3-sys/src/sliceobject.rs @@ -2,7 +2,7 @@ use libc::c_int; use pyport::Py_ssize_t; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { static mut _Py_EllipsisObject: PyObject; } @@ -11,7 +11,7 @@ pub unsafe fn Py_Ellipsis() -> *mut PyObject { &mut _Py_EllipsisObject } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PySlice_Type: PyTypeObject; pub static mut PyEllipsis_Type: PyTypeObject; } @@ -21,7 +21,7 @@ pub unsafe fn PySlice_Check(op: *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PySlice_Type) as c_int } -extern "C" { +#[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, diff --git a/python3-sys/src/structmember.rs b/python3-sys/src/structmember.rs index 6f618fac..1af7a799 100644 --- a/python3-sys/src/structmember.rs +++ b/python3-sys/src/structmember.rs @@ -51,7 +51,7 @@ 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); -extern "C" { +#[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/python3-sys/src/structseq.rs b/python3-sys/src/structseq.rs index 3701bc5c..d3fc5f2e 100644 --- a/python3-sys/src/structseq.rs +++ b/python3-sys/src/structseq.rs @@ -24,7 +24,7 @@ impl Clone for PyStructSequence_Desc { #[inline] fn clone(&self) -> PyStructSequence_Desc { *self } } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyStructSequence_NewType(desc: *mut PyStructSequence_Desc) -> *mut PyTypeObject; pub fn PyStructSequence_New(_type: *mut PyTypeObject) -> *mut PyObject; diff --git a/python3-sys/src/sysmodule.rs b/python3-sys/src/sysmodule.rs index d64c1b76..6787a66a 100644 --- a/python3-sys/src/sysmodule.rs +++ b/python3-sys/src/sysmodule.rs @@ -1,7 +1,7 @@ use libc::{c_char, c_int, wchar_t}; use object::PyObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PySys_GetObject(arg1: *const c_char) -> *mut PyObject; pub fn PySys_SetObject(arg1: *const c_char, arg2: *mut PyObject) -> c_int; diff --git a/python3-sys/src/traceback.rs b/python3-sys/src/traceback.rs index 927e4462..0f82594c 100644 --- a/python3-sys/src/traceback.rs +++ b/python3-sys/src/traceback.rs @@ -1,7 +1,7 @@ use libc::c_int; use object::*; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyTraceBack_Here(arg1: *mut ::PyFrameObject) -> c_int; pub fn PyTraceBack_Print(arg1: *mut PyObject, arg2: *mut PyObject) -> c_int; diff --git a/python3-sys/src/tupleobject.rs b/python3-sys/src/tupleobject.rs index 6c024c31..a52f92a0 100644 --- a/python3-sys/src/tupleobject.rs +++ b/python3-sys/src/tupleobject.rs @@ -9,7 +9,7 @@ pub struct PyTupleObject { pub ob_item: [*mut PyObject; 1], } -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyTuple_Type: PyTypeObject; pub static mut PyTupleIter_Type: PyTypeObject; } @@ -24,7 +24,7 @@ pub unsafe fn PyTuple_CheckExact(op : *mut PyObject) -> c_int { (Py_TYPE(op) == &mut PyTuple_Type) as c_int } -extern "C" { +#[link(name="pythonXY")] extern "C" { 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) diff --git a/python3-sys/src/unicodeobject.rs b/python3-sys/src/unicodeobject.rs index 794988ea..dddee249 100644 --- a/python3-sys/src/unicodeobject.rs +++ b/python3-sys/src/unicodeobject.rs @@ -9,7 +9,7 @@ pub type Py_UCS4 = u32; pub type Py_UCS2 = u16; pub type Py_UCS1 = u8; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub static mut PyUnicode_Type: PyTypeObject; pub static mut PyUnicodeIter_Type: PyTypeObject; } @@ -26,7 +26,7 @@ pub unsafe fn PyUnicode_CheckExact(op : *mut PyObject) -> c_int { pub const Py_UNICODE_REPLACEMENT_CHARACTER : Py_UCS4 = 0xFFFD; -extern "C" { +#[link(name="pythonXY")] extern "C" { #[cfg(not(Py_LIMITED_API))] pub fn PyUnicode_New(size: Py_ssize_t, maxchar: Py_UCS4) -> *mut PyObject; diff --git a/python3-sys/src/warnings.rs b/python3-sys/src/warnings.rs index f88ef2d4..5e6fa90e 100644 --- a/python3-sys/src/warnings.rs +++ b/python3-sys/src/warnings.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_int}; use pyport::Py_ssize_t; use object::PyObject; -extern "C" { +#[link(name="pythonXY")] extern "C" { pub fn PyErr_WarnEx(category: *mut PyObject, message: *const c_char, stack_level: Py_ssize_t) -> c_int; diff --git a/python3-sys/src/weakrefobject.rs b/python3-sys/src/weakrefobject.rs index 357d13ac..3ad7cfc1 100644 --- a/python3-sys/src/weakrefobject.rs +++ b/python3-sys/src/weakrefobject.rs @@ -3,7 +3,7 @@ use object::*; pub enum PyWeakReference {} -extern "C" { +#[link(name="pythonXY")] extern "C" { static mut _PyWeakref_RefType: PyTypeObject; static mut _PyWeakref_ProxyType: PyTypeObject; static mut _PyWeakref_CallableProxyType: PyTypeObject; @@ -30,7 +30,7 @@ pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int { (PyWeakref_CheckRef(op) != 0 || PyWeakref_CheckProxy(op) != 0) as c_int } -extern "C" { +#[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) diff --git a/src/lib.rs b/src/lib.rs index 8e41ba0f..15553314 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,21 +63,23 @@ //! ``` //! extern crate cpython; //! -//! use cpython::{PythonObject, Python}; -//! use cpython::ObjectProtocol; //for call method -//! +//! use cpython::{Python, PyDict, PyResult}; +//! //! fn main() { //! let gil = Python::acquire_gil(); -//! let py = gil.python(); // obtain `Python` token -//! -//! let sys = py.import("sys").unwrap(); -//! let version: String = sys.get(py, "version").unwrap().extract(py).unwrap(); -//! -//! let os = py.import("os").unwrap(); -//! let getenv = os.get(py, "getenv").unwrap(); -//! let user: String = getenv.call(py, ("USER",), None).unwrap().extract(py).unwrap(); -//! +//! hello(gil.python()).unwrap(); +//! } +//! +//! fn hello(py: Python) -> PyResult<()> { +//! let sys = py.import("sys")?; +//! let version: String = sys.get(py, "version")?.extract(py)?; +//! +//! let locals = PyDict::new(py); +//! locals.set_item(py, "os", py.import("os")?)?; +//! let user: String = py.eval("os.getenv('USER') or os.getenv('USERNAME')", None, Some(&locals))?.extract(py)?; +//! //! println!("Hello {}, I'm Python {}", user, version); +//! Ok(()) //! } //! ``` diff --git a/src/py_class/py_class.rs b/src/py_class/py_class.rs index 841e854d..a0c0e6c5 100644 --- a/src/py_class/py_class.rs +++ b/src/py_class/py_class.rs @@ -347,7 +347,7 @@ py_class!(class MyIterator |py| { the same method of the second operand is called, with the operands in the same order. This means that you can't rely on the first parameter of these methods being `self` - or being the right type, and you should test the types of both operands before deciding what to do. + or being the correct type, and you should test the types of both operands before deciding what to do. If you can't handle the combination of types you've been given, you should return `Ok(py.NotImplemented())`.