diff --git a/.gitignore b/.gitignore index cb3d2508..9c6831e9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,11 @@ target Cargo.lock /doc /gh-pages +build/ +__pycache__/ +.cache *.so *.out +*.egg-info extensions/stamps/ diff --git a/examples/word-count-cls/.gitignore b/examples/word-count-cls/.gitignore deleted file mode 100644 index db8bc200..00000000 --- a/examples/word-count-cls/.gitignore +++ /dev/null @@ -1,67 +0,0 @@ -target/ -**/*.rs.bk -Cargo.lock - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -bin/ -local/ -include/ -man/ -*.egg-info/ -.installed.cfg -*.egg -.ropeproject/ - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover - -# Translations -*.mo -*.pot - -# Django stuff: -*.log - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ diff --git a/examples/word-count/.gitignore b/examples/word-count/.gitignore deleted file mode 100644 index db8bc200..00000000 --- a/examples/word-count/.gitignore +++ /dev/null @@ -1,67 +0,0 @@ -target/ -**/*.rs.bk -Cargo.lock - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -bin/ -local/ -include/ -man/ -*.egg-info/ -.installed.cfg -*.egg -.ropeproject/ - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover - -# Translations -*.mo -*.pot - -# Django stuff: -*.log - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ diff --git a/guide/.gitignore b/guide/.gitignore deleted file mode 100644 index 7585238e..00000000 --- a/guide/.gitignore +++ /dev/null @@ -1 +0,0 @@ -book diff --git a/src/instance.rs b/src/instance.rs index 04036ed2..cba8db7e 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -112,12 +112,12 @@ impl Py { /// Panics if the pointer is `null`. /// Undefined behavior if the pointer is invalid. #[inline] - pub 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 { - unsafe{ Py::from_owned_ptr(ptr) } + Py::from_owned_ptr(ptr) } } @@ -125,12 +125,12 @@ impl Py { /// returns a new reference (owned pointer). /// Returns `Err(PyErr)` if the pointer is `null`. /// Unsafe because the pointer might be invalid. - pub 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 { - Ok(unsafe{ Py::from_owned_ptr(ptr) }) + Ok(Py::from_owned_ptr(ptr)) } } diff --git a/src/object.rs b/src/object.rs index feb2784e..59f00dfc 100644 --- a/src/object.rs +++ b/src/object.rs @@ -48,28 +48,25 @@ 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 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 { - Ok(unsafe{ - PyObject::from_owned_ptr(py, ptr) - }) + Ok(PyObject::from_owned_ptr(py, ptr)) } } /// 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 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 { - Some(unsafe{ - PyObject::from_owned_ptr(py, ptr) - }) + Some(PyObject::from_owned_ptr(py, ptr)) } } @@ -87,24 +84,26 @@ 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 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 { - Ok(unsafe{PyObject::from_borrowed_ptr(py, ptr)}) + Ok(PyObject::from_borrowed_ptr(py, ptr)) } } /// Creates a `PyObject` instance for the given Python FFI pointer. /// Calls Py_INCREF() on the ptr. /// Returns `None` if the pointer is `null`. - pub 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 { - Some(unsafe{PyObject::from_borrowed_ptr(py, ptr)}) + Some(PyObject::from_borrowed_ptr(py, ptr)) } }