mark method that work with raw pointer unsafe

This commit is contained in:
Nikolay Kim 2017-12-26 13:41:27 -08:00
parent 017c404d69
commit 050397b723
6 changed files with 19 additions and 151 deletions

4
.gitignore vendored
View File

@ -2,7 +2,11 @@ target
Cargo.lock
/doc
/gh-pages
build/
__pycache__/
.cache
*.so
*.out
*.egg-info
extensions/stamps/

View File

@ -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/

View File

@ -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/

1
guide/.gitignore vendored
View File

@ -1 +0,0 @@
book

View File

@ -112,12 +112,12 @@ impl<T> Py<T> {
/// 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<T>
pub unsafe fn from_owned_ptr_or_panic(ptr: *mut ffi::PyObject) -> Py<T>
{
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<T> Py<T> {
/// 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<Py<T>>
pub unsafe fn from_owned_ptr_or_err(py: Python, ptr: *mut ffi::PyObject) -> PyResult<Py<T>>
{
if ptr.is_null() {
Err(PyErr::fetch(py))
} else {
Ok(unsafe{ Py::from_owned_ptr(ptr) })
Ok(Py::from_owned_ptr(ptr))
}
}

View File

@ -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<PyObject>
pub unsafe fn from_owned_ptr_or_err(py: Python, ptr: *mut ffi::PyObject)
-> PyResult<PyObject>
{
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<PyObject>
pub unsafe fn from_owned_ptr_or_opt(py: Python, ptr: *mut ffi::PyObject) -> Option<PyObject>
{
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<PyObject>
pub unsafe fn from_borrowed_ptr_or_err(py: Python, ptr: *mut ffi::PyObject)
-> PyResult<PyObject>
{
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<PyObject>
pub unsafe fn from_borrowed_ptr_or_opt(py: Python, ptr: *mut ffi::PyObject)
-> Option<PyObject>
{
if ptr.is_null() {
None
} else {
Some(unsafe{PyObject::from_borrowed_ptr(py, ptr)})
Some(PyObject::from_borrowed_ptr(py, ptr))
}
}