Commit Graph

498 Commits

Author SHA1 Message Date
Georg Brandl 8083c1c310 Update changelog for #1802 and #1803. 2021-08-23 15:47:09 +02:00
David Hewitt bc1a983371 changelog: update for 0.14.3 release 2021-08-22 01:25:29 +01:00
David Hewitt 591f44ea6d
Merge pull request #1794 from indygreg/pystringdata
string: implement API to access raw string data
2021-08-21 22:54:58 +01:00
Gregory Szorc 0cf7776a4d string: implement API to access raw string data
With the recent implementation of non-limited unicode APIs, we're
able to query Python's low-level state to access the raw bytes that
Python is using to store string objects.

This commit implements a safe Rust API for obtaining a view into
Python's internals and representing the raw bytes Python is using
to store strings.

Not only do we allow accessing what Python has stored internally,
but we also support coercing this data to a `Cow<str>`.

Closes #1776.
2021-08-19 18:24:17 -07:00
Christian Heimes d74c3f6cd0 Use 'crate::' to refer to pyo3
Fixes: #1811
Signed-off-by: Christian Heimes <christian@python.org>
2021-08-18 12:54:27 +02:00
Péter Leéh f72b2c8f09
Py_CompileString decref (#1810)
* update changelog

* fix memory leak in PyModule::from_code

* add PR link to changelog

* Add Py_DECREF also when PyImport_ExecCodeModuleEx fails

* Remove duplicated calls, simplify logic

Co-authored-by: messense <messense@icloud.com>

Co-authored-by: messense <messense@icloud.com>
2021-08-18 10:50:57 +00:00
Peter Schafhalter 37ea57de2b Update changelog 2021-08-17 22:56:27 -07:00
Peter Schafhalter e4466549e5 Edit changelog 2021-08-17 14:37:39 -07:00
Aviram Hassan c6255e6734 - `PyList`, `PyTuple` and `PySequence`'s `get_item` now accepts only `usize` indices instead of `isize`.
- `PyList` and `PyTuple`'s `get_item` now always uses the safe API. See `get_item_unchecked` for retrieving index without checks.
2021-08-17 15:01:22 +01:00
David Hewitt 7a92e2699b
Merge pull request #1804 from davidhewitt/deprecate_split_from
pytuple: deprecate split_from
2021-08-17 15:00:21 +01:00
David Hewitt 37d39aa83a
Merge pull request #1751 from davidhewitt/pyany-py
pyany: add PyAny::py()
2021-08-17 14:10:16 +01:00
David Hewitt 7fd70d103e pytuple: deprecate split_from 2021-08-17 13:57:27 +01:00
Matthew Treinish 60db3a45b3
Expand supported num-complex versions
When building an extension with rust-numpy and ndarray on the MSRV of
1.41 with complex numbers. The num-complex crate version needs to be
0.2 which was the pinned version as of ndarray 0.13.1 which was the last
release of ndarray that supported building with rust 1.41. However, the
pyo3 pinned version of 0.4 is incompatible with this and will cause an
error when building because of the version mismatch. To fix this This
commit expands the supported versions for num-complex to match what
rust-numpy uses [1] so that we can build pyo3, numpy, ndarray, and
num-complex in an extension with rust 1.41.

Fixes #1798

[1] https://github.com/PyO3/rust-numpy/blob/v0.14.1/Cargo.toml#L19
2021-08-16 14:43:07 -04:00
David Hewitt 78f269e946
Merge branch 'main' into setter-handle-del 2021-08-14 08:07:15 +01:00
David Hewitt 30e6f58080
Update CHANGELOG.md 2021-08-14 07:43:32 +01:00
David Hewitt 150f4adbba
Update CHANGELOG.md 2021-08-14 07:40:52 +01:00
Gregory Szorc 410c9f13c9 macros: raise AttributeError on property deletion requests
The setter function will receive a NULL value on deletion requests.
This wasn't properly handled before, leading to a panic.

The new code raises AttributeError in this scenario instead.

A test for the behavior has been added. Documentation has also
been updated to reflect the behavior.
2021-08-13 21:01:00 -07:00
Gregory Szorc d3762a679f ffi: fix PyStatus._type
The field wasn't defined previously. And the enum wasn't defined as
`[repr(C)]`.

This missing field could result in memory corruption if a Rust-allocated
`PyStatus` was passed to a Python API, which could perform an
out-of-bounds write. In my code, the out-of-bounds write corrupted a
variable on the stack, leading to a segfault due to illegal memory
access. However, this crash only occurred on Rust 1.54! So I initially
mis-attribted it as a compiler bug / regression. It appears that a
low-level Rust change in 1.54.0 changed the LLVM IR in such a way to
cause LLVM optimization passes to produce sufficiently different
assembly code, tickling the crash. See
https://github.com/rust-lang/rust/issues/87947 if you want to see
the wild goose chase I went on in Rust / LLVM land to potentially
pin this on a compiler bug.

Lessen learned: Rust crashes are almost certainly due to use of
`unsafe`.
2021-08-13 20:51:26 -07:00
David Hewitt 0bfd50d314 ffi: cleanup pystate 2021-08-13 08:26:38 +01:00
David Hewitt ebada76ae3 pyany: add PyAny::py() 2021-08-13 08:00:13 +01:00
messense 4c734ef72a
Merge pull request #1783 from PyO3/davidhewitt-patch-1
changelog: fix missing PR number
2021-08-12 10:33:10 +08:00
David Hewitt c59b51b85b
changelog: fix missing PR number 2021-08-11 23:49:01 +01:00
messense 3ba24bee14 `PyErr::api_call_failed` should return a `SystemError` when no error is set
17f94e2888/Python/ceval.c (L4330-L4333)
2021-08-11 23:45:09 +01:00
messense 9d0b92bf32 Change `PyErr::fetch` to return an `Option<PyErr>` 2021-08-11 23:44:40 +01:00
David Hewitt 1873264b7d release: 0.14.2 2021-08-09 07:58:31 +01:00
David Hewitt 575c448345
Merge pull request #1769 from indygreg/force-acquire-gil
gil: add unsafe variation for obtaining GILGuard without checks
2021-08-09 07:49:06 +01:00
Gregory Szorc 3a6740a459 gil: add unsafe variation for obtaining GIL without checks
GILGuard::acquire() cannot be called during multi-phase Python
interpreter initialization because it calls Py_IsInitialized(),
which doesn't report the interpreter as initialized until all
phases of initialization have completed.

PyOxidizer uses the multi-phase initialization API and needs to
interact with pyo3's high-level APIs (not the FFI bindings) after
partial interpreter initialization, before the interpreter is fully
initialized. Attempts to use GILGuard::acquire() result in a panic
due to the aforementioned Py_IsInitialized() check failing.

This commit refactors the GILGuard logic into a function that
obtains the actual GILGuard and another function to perform
checks before calling the aforementioned functions.

A new unsafe `Python::with_gil_unchecked()` has been defined
to acquire the GIL via the unchecked code path so we may obtain
a `Python` during multi-phase initialization (and possibly other
scenarios).
2021-08-08 15:40:10 -07:00
Gregory Szorc 495ac98eb3 ffi: fix Py_DecodeLocale() signature
Closes #1766.
2021-08-08 10:38:00 -07:00
Dean Li 03981b373a
add CHANGELOG.md 2021-08-07 16:38:24 +08:00
David Hewitt 5af835daed pyo3-build-config: fix build for windows gnu targets 2021-08-07 00:25:14 +01:00
David Hewitt c2d6a50b35 build: revert usage of cargo:rustc-cdylib-link-arg 2021-08-03 20:04:56 +01:00
David Hewitt 4c5aee92d5 pycell: fix calculation of dictoffset on 32-bit Windows 2021-07-31 15:09:12 +01:00
David Hewitt bbe0e846b0
Merge pull request #1738 from davidhewitt/latest-links
docs: use pyo3.rs/latest instead of pyo3.rs/main
2021-07-24 17:57:03 +01:00
David Hewitt 4a71f82099
Merge pull request #1724 from davidhewitt/err-new-no-gil
err: don't use with_gil internally in PyErr::new()
2021-07-24 10:13:50 +01:00
David Hewitt c09947a61c err: don't use with_gil internally in PyErr::new() 2021-07-24 08:51:17 +01:00
David Hewitt 3794aab11f docs: use pyo3.rs/latest instead of pyo3.rs/main 2021-07-24 08:47:02 +01:00
David Hewitt d46d3265cb pypy: fix FFI definition of Py_Buffer 2021-07-24 08:37:22 +01:00
Ivan Carvalho bd0e0d808f
Add optional support for conversion from `indexmap::IndexMap` (#1728)
* Add support to IndexMap

* Fix indexmap version to 1.6.2

* Remove code duplication by mistake

* Fix ambiguity in test

* Minor change for doc.rs

* Add to lib.rs docstring

* Add indexmap to conversion table

* Add indexmap flag in docs.rs action

* Add indexmap feature to CI

* Add note in changelog

* Use with_gil in tests

* Move code to src/conversions/indexmap.rs

* Add PR number to CHANGELOG

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>

* Add round trip test

* Fix issue in MSRV Ubuntu build

* Fix Github workflow syntax

* Yet Another Attempt to Fix MSRV Ubuntu build

* Specify hashbrown to avoid ambiguity in CI

* Add suggestions

* More flexible version for indexmap

* Add documentation

* Address PR comments

* Export indexmap for docs

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-07-22 08:15:26 +01:00
Alex Gaynor a941b2c65f Added a changelog entry 2021-07-15 07:14:44 -04:00
David Hewitt d11943ab6d macros-backend: don't error on #[doc(hidden)] 2021-07-08 23:41:24 +01:00
David Hewitt 3f8c4ad38e release: 0.14.1 2021-07-04 16:49:36 +01:00
Georg Brandl f7235482eb PyPy: the PyList_GET/SET macros are defined as functions, the PyTuple_ ones do not exist 2021-07-04 15:54:40 +02:00
messense eaf5dcaab7 Implement `IntoPy<PyObject>` for `&PathBuf` and `&OsString` 2021-07-04 16:18:04 +08:00
David Hewitt adf6bdba8e release: 0.14.0 2021-07-03 08:37:00 +01:00
David Hewitt 0215054012
Merge pull request #1702 from ohadravid/to-python-set-non-default-hashbuilder
Make `ToPyObject` impl for `HashSet` accept non-default hashers.
2021-06-27 17:29:00 +01:00
Ohad Ravid fcffcdfae5 Added `size_hint` impls for `{PyDict,PyList,PySet,PyTuple}Iterator`s 2021-06-27 16:10:53 +03:00
Ohad Ravid 43fca5dad7 Make `ToPyObject` impl for `HashSet` accept non-default hashers. 2021-06-27 15:19:01 +03:00
messense b5b9a480cd Add `wrap_pyfunction` macro to prelude 2021-06-24 22:34:55 +08:00
mejrs 455cc95c54
implement ffi/cpython/pystate (#1687)
* dont reexport cpython items twice

* add ffi module level doc

* reorder to header file order

* cargo fmt

* implement cpython/pystate

* fix import errors

* make PyInterpreterState opaque

* update changelog

* fix formatting
2021-06-24 20:05:15 +08:00
David Hewitt a02353ce34
Merge pull request #1679 from messense/error-cause
Add support for setting and retrieving exception cause
2021-06-24 07:58:34 +01:00