Commit Graph

485 Commits

Author SHA1 Message Date
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
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
messense 2bac6c5a3a Add support for setting and retrieving exception cause 2021-06-23 20:14:49 +08:00
Gabriel Majeri b048bfa75f Update the changelog 2021-06-23 15:03:03 +03:00
David Hewitt f916867375 pyclass: refactor initialization, call native type dealloc 2021-06-23 07:45:51 +01:00
David Hewitt a290971759
Merge pull request #1650 from davidhewitt/pymodule-name
pymodule: accept `#[pyo3(name = "...")]` option
2021-06-06 11:11:10 +01:00
Georg Brandl 98461a2ef6 PyList tests: simplify construction 2021-06-06 10:28:15 +02:00
David Hewitt 18e0aa17e0 pymodule: accept `#[pyo3(name = "...")]` option 2021-06-06 08:41:20 +01:00
Georg Brandl 3bebc19e2d PyList: remove get_parked_item, use macros for speed on !abi3 2021-06-06 07:54:38 +02:00
Georg Brandl 60862c308b Update changelog entry. 2021-06-06 07:08:23 +02:00
David Hewitt cec4c2d2e9 text_signature: move to `#[pyo3(text_signature = "...")]` 2021-06-05 16:33:03 +01:00
David Hewitt a5810eaffa
Merge pull request #1619 from birkenfeld/fastcall
Implement METH_FASTCALL for pyfunctions.
2021-06-05 12:32:16 +01:00
Georg Brandl 3e8d003faf Implement METH_FASTCALL for pyfunctions and pymethods. 2021-06-05 12:57:22 +02:00
David Hewitt 97d6f15b32
Merge pull request #1626 from alonblade/cross-sysconfig
build.rs: if found more than one candidate, filter on arch
2021-06-05 09:29:00 +01:00
messense bd1045e289 Add support for extracting PathBuf from pathlib.Path 2021-06-05 14:59:26 +08:00