Commit graph

3717 commits

Author SHA1 Message Date
David Hewitt 7a92e2699b
Merge pull request #1804 from davidhewitt/deprecate_split_from
pytuple: deprecate split_from
2021-08-17 15:00:21 +01:00
mejrs 3be3af4121 fix extends param 2021-08-17 15:19:19 +02:00
mejrs bce5100dc3 use macro to shadow 2021-08-17 15:16:03 +02: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
David Hewitt df41903c98
Merge pull request #1802 from PyO3/pylist_insert_index
Some PyList index fixes
2021-08-17 13:54:54 +01:00
Georg Brandl 79d9741906 Add PyList::slice and fix index types of PyTuple::slice, PyList::insert and PyList::set_item.
NB: the behavior on out-of-range indices hasn't changed;
it was merely wrongly documented before.

See #1667
2021-08-17 09:45:06 +02:00
David Hewitt 029ac5b416
Merge pull request #1799 from mtreinish/loosen-num-complex
Expand supported num-complex versions
2021-08-17 08:02:35 +01:00
Matthew Treinish d575c30eb6
Update Cargo.toml
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-08-16 18:22:46 -04: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
mejrs 370968b595 test macro hygiene for pyclass 2021-08-16 16:32:11 +02:00
David Hewitt 336e87ec18
Merge pull request #1795 from davidhewitt/update-cargo-llvm-cov
ci: update cargo-llvm-cov
2021-08-16 08:17:02 +01:00
David Hewitt b1abe03984 ci: update cargo-llvm-cov 2021-08-15 23:54:43 +01:00
David Hewitt eafc75ab06
Merge pull request #1777 from indygreg/unicode-apis
ffi: define some cpython/unicodeobject bindings
2021-08-14 23:07:49 +01:00
Gregory Szorc 807c8ee33c string: enable use of PyUnicode_AsUTF8AndSize on all Python versions
This API is available in all supported Python versions and isn't
deprecated.
2021-08-14 11:19:02 -07:00
David Hewitt 974a782895 ffi: PyPy and Python 3.10 attributes for unicodeobject 2021-08-14 10:09:57 -07:00
Gregory Szorc 9690e9ece6 ffi: move limited API unicode symbols to cpython/unicodeobject.rs
All symbols which are canonically defined in cpython/unicodeobject.h
and had been defined in our unicodeobject.rs have been moved to our
corresponding cpython/unicodeobject.rs file.

This module is only present in non-limited build configurations, so
we were able to drop the cfg annotations as part of moving the
definitions.
2021-08-14 08:19:10 -07:00
Gregory Szorc b8738b0430 ffi: define some cpython/unicodeobject bindings
pyo3 doesn't currently define various Unicode bindings that allow the
retrieval of raw data from Python strings. Said bindings are a
prerequisite to possibly exposing this data in the Rust API (#1776).
Even if those high-level APIs never materialize, the FFI bindings are
necessary to enable consumers of the raw C API to utilize them.

This commit partially defines the FFI bindings as defined in
CPython's Include/cpython/unicodeobject.h file.

I used the latest CPython 3.9 Git commit for defining the order
of the symbols and the implementation of various inline preprocessor
macros. I tried to be as faithful as possible to the original
implementation, preserving intermediate `#define`s as inline functions.

Missing symbols have been annotated with `skipped` and symbols currently
defined in `src/ffi/unicodeobject.rs` have been annotated with `move`.

The `state` field of `PyASCIIObject` is a bitfield, which Rust doesn't
support. So we've provided accessor functions for retrieving these
fields' values. No accessor functions are present because you shouldn't
be touching these values from Rust code.

Tests of the bitfield APIs and macro implementations have been added.
2021-08-14 08:19:10 -07:00
David Hewitt 584de688c3
Merge pull request #1779 from indygreg/setter-handle-del
macros: raise AttributeError on property deletion requests
2021-08-14 08:57:33 +01:00
David Hewitt 78f269e946
Merge branch 'main' into setter-handle-del 2021-08-14 08:07:15 +01:00
David Hewitt 739a885f5a
Merge pull request #1791 from indygreg/fix-pystatus
ffi: fix PyStatus._type
2021-08-14 08:05:40 +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 254ea53f3f
Merge pull request #1789 from davidhewitt/example-word-count
examples: make `word-count` example comparison fairer
2021-08-13 15:08:16 +01:00
David Hewitt e44920ef9c
Merge pull request #1790 from PyO3/davidhewitt-patch-1
ffi: fix PyPy symbols for `cpython/pystate.rs`
2021-08-13 15:07:29 +01:00
David Hewitt 06ff76fec2
examples: make word-count example comparison fairer 2021-08-13 14:19:46 +01:00
David Hewitt c439f97f1a
ffi: fix PyPy symbols for cpython/pystate.rs 2021-08-13 14:07:15 +01:00
David Hewitt 388c2552f8
Merge pull request #1786 from mejrs/with_gil2
tests: switch to python_with_gil
2021-08-13 12:39:17 +01:00
David Hewitt 874e7e5cab
Merge pull request #1787 from davidhewitt/ffi-pystate
ffi: cleanup pystate
2021-08-13 12:36:37 +01: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
mejrs 596c3ff4b7 remove now unused imports 2021-08-12 12:08:54 +02:00
mejrs 9fe3e2b2b8
Apply suggestions from code review
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-08-12 11:52:56 +02:00
David Hewitt 0b269c4d3d
Merge pull request #1678 from sansyrox/main
Add documentation to call async python from rust
2021-08-12 08:58:46 +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
messense 2a7c4f495b
Merge pull request #1784 from davidhewitt/gh-actions-pages-v3
guide: allow using newer gh-actions-pages version
2021-08-12 10:32:35 +08:00
messense d197357478
Merge pull request #1785 from davidhewitt/pin-bitflags
ci: pin bitflags for MSRV job
2021-08-12 10:31:13 +08:00
mejrs f55a9c8ab0 tests: switch to python_with_gil 2021-08-12 02:47:41 +02:00
David Hewitt 4eee9009db ci: pin bitflags for MSRV job 2021-08-12 00:27:49 +01:00
David Hewitt bdad08ce6a
Merge pull request #1717 from messense/pyerr-fetch
Change `PyErr::fetch` to return an `Option<PyErr>`
2021-08-12 00:24:15 +01:00
Sanskar Jethi aac3d1da6e Add documentation to call async python from rust 2021-08-12 00:22:10 +01:00
David Hewitt 72f3f1131b guide: allow using newer gh-actions-pages version 2021-08-11 23:50:58 +01: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 93b25edba1 Use errror_on_minusone more often 2021-08-11 23:44:40 +01:00
messense 9d0b92bf32 Change PyErr::fetch to return an Option<PyErr> 2021-08-11 23:44:40 +01:00
David Hewitt 140c090504
Merge pull request #1780 from davidhewitt/pin-trybuild
ci: downgrade trybuild to 1.0.43
2021-08-11 09:26:41 +01:00
David Hewitt c59f518f76 ci: downgrade trybuild to 1.0.43 2021-08-11 08:39:37 +01:00