Commit Graph

767 Commits

Author SHA1 Message Date
Georg Brandl 0678f11266 Protocols: implement __getattribute__
converting tp_getattro to a shared slot

Fixes #2186
2022-02-26 20:05:50 +01:00
Georg Brandl 03dc96bff1
Py/PyAny: remove PartialEq impl and add is() (#2183) 2022-02-25 19:39:45 +00:00
Tommaso Thea Cioni 487345979b
Added `eq`, `ne`, `gt` etc. methods. (#2175) 2022-02-25 18:52:20 +01:00
David Hewitt b84309b67d ffi: add missing definition PyCMethod_New 2022-02-25 07:28:52 +00:00
David Hewitt f98f116131 pypy: support released 3.9 2022-02-25 07:28:22 +00:00
David Hewitt 7c865fcc25
Merge pull request #2173 from davidhewitt/deprecate-pyproto
pyproto: deprecate protocol traits
2022-02-24 23:54:40 +00:00
Rico Hageman 1839fc208b Add CHANGELOG.md entry 2022-02-24 00:23:07 +01:00
David Hewitt 24445df633 pyproto: deprecate protocol traits 2022-02-23 07:50:52 +00:00
Rico Hageman 3fbdc863cb Include the causes when throwing a PyTypeError when argument parsing failed 2022-02-22 09:48:41 +01:00
Rico Hageman 333ebb9872 Add changelog entry 2022-02-21 23:22:56 +01:00
David Hewitt 79123b396c pyclass: deprecate gc option 2022-02-15 08:01:46 +00:00
David Hewitt 676295b8de pymethods: support gc protocol 2022-02-15 08:01:23 +00:00
David Hewitt 7851e865ae
Merge pull request #2166 from mejrs/union
Implement ml_meth as an union.
2022-02-15 07:55:24 +00:00
mejrs 59412b06e5 Add to changelog 2022-02-14 15:15:05 +01:00
Jacob Zhong de502f0b08 Update CHANGELOG.md 2022-02-12 13:28:05 -05:00
David Hewitt c5ef24bbea fix: memory leak in Option<T>::as_ptr 2022-02-11 22:18:11 +00:00
David Hewitt c93ee00130 refactor: inline handle_panic into macro output 2022-02-10 20:20:03 +00:00
David Hewitt 0c576964f8 changelog: add 2157 2022-02-09 08:07:14 +00:00
b05902132 78f5afc82e Finish implementation for pyclass enums 2022-02-07 22:17:11 +00:00
James Hilton-Balfe b2f9e28331
Add Mapping::contains (#2133)
* Add Mapping::contains

* Fix typo

* Add a changelog entry

* Use PyAny::contatins instead

* Update mapping.rs
2022-02-06 00:35:43 +00:00
David Hewitt 53c170078d pymethods: seq methods from mapping methods 2022-02-05 15:59:22 +00:00
David Hewitt 71e5a12fa2 pypy: support fast long conversion 2022-02-05 10:14:14 +00:00
David Hewitt 199cc989d4
Merge pull request #2126 from DSPOM2/main
move ffi module to separate crate
2022-01-31 23:27:36 +00:00
DSPOM 6a9a9ba38a
move ffi module to separate crate 2022-01-31 13:27:16 +01:00
mejrs b56cc3d171 Updated changelog 2022-01-25 00:09:11 +01:00
Ashley Anderson 64c09d870c Update changelog. 2022-01-19 21:22:08 -05:00
David Hewitt dc8032a5ff pyfunction: allow required positional after option 2022-01-11 00:44:41 +00:00
David Hewitt de8174684f pyfunction: allow wrap_pyfunction to work on imports (even cross-crate) 2022-01-07 08:43:05 +00:00
David Hewitt 2cee7feaaf
Merge pull request #2083 from aviramha/magic_methods
verify py method args count
2022-01-07 00:13:05 +00:00
David Hewitt be70e5441b
Merge pull request #2085 from davidhewitt/opt-argument-extraction
opt: move fastcall boilerplate out of generated code
2022-01-03 08:13:31 +00:00
Aviram Hassan 50659b6b02
`__ipow__` now supports modulo argument on Python 3.8+.
`pyo3-macros-backend` is now compiled with PyO3 cfgs to enable different magic method definitions based on version.
Add check for correct number of arguments on magic methods.
2022-01-03 09:53:56 +02:00
David Hewitt 1a782ce4db opt: move fastcall boilerplate out of generated code 2022-01-03 00:07:32 +00:00
David Hewitt cf965155f4 pymethods: support buffer protocol 2021-12-30 15:48:55 +00:00
David Hewitt e33b3e6a5b opt: don't emit T::dict_offset and T::weakref_offset without attributes 2021-12-30 14:57:27 +00:00
David Hewitt ff37f24625 macros: accept paths in wrap_x macros 2021-12-30 12:46:57 +00:00
David Hewitt 90479ddae4 opt: make argument extraction code smaller 2021-12-24 01:52:15 +00:00
David Hewitt 33a618914f opt: reduce class creation generated code 2021-12-24 01:12:59 +00:00
David Hewitt 5be5d77589 opt: improve handle_panic generated code 2021-12-24 00:17:04 +00:00
David Hewitt 492b7e4c0f macros: optimize generated code for #[derive(FromPyObject)] 2021-12-22 08:34:05 +00:00
Amanieu d'Antras ed0a6b710a Add changelog entry 2021-12-20 18:34:14 +01:00
Ashley Anderson a6c70164cd Move changelog entry for #1996. 2021-12-16 13:12:03 -05:00
Ashley Anderson c30ca03b60
Expose cross compiling configuration from pyo3-build-config (#1996)
* Initial refactor - expose cross-compiling functions and add necessary fields to InterpreterConfig

* Refactor cross_compiling to take arch/vendor/os separately.

* Address review comments.

* Update changelog with note about pyo3-build-config APIs.

* Fix panic when parsing ABI tag on Windows.

* Update parse_sysconfigdata test to best-guess values for linux.

* Revert added fields in InterpreterConfig.

* Refactor parse_sysconfigdata to return Sysconfigdata (HashMap). Add InterpreterConfig::from_sysconfigdata.

* Update BuildFlags test to use from_sysconfigdata.

* Add tests for from_sysconfigdata. Refactor Sysconfigdata API to be more open.

* Add basic tests for not cross compiling. Add some error handling.

* Address review comments.

* Update search_lib_dir to recurse into lib and pypy dirs.

* Look even harder for sysconfigdata.

* Add skip-build-config feature.

* Revert skip-build-config feature.

* Suppress cargo:rerun-if-env-changed without resolve-config feature.
2021-12-16 00:18:37 +00:00
mejrs bbe478db81 Update changelog 2021-12-14 19:19:31 +01:00
David Hewitt 469d72a001
Merge pull request #2022 from PyO3/pyo3_path
Hygiene: offer a way to set path to pyo3 crate
2021-12-09 20:27:48 +00:00
Juniper Parsons 47cf13239f
Disallow positional args after optional args 2021-12-09 10:01:59 -05:00
Georg Brandl a5b76bc365 pyo3_path, part 4: rename to `crate` to keep consistent with serde 2021-12-09 07:36:48 +01:00
Georg Brandl e4f608f605 pyo3_path, part 2: add pyo3_path options and use them. 2021-12-09 07:24:18 +01:00
David Hewitt 4c8abd1426 rust: support 1.57 2021-12-08 07:10:16 +00:00
David Hewitt b56d492c3b pytype: resurrect (deprecated) PyType::is_instance 2021-11-27 09:05:58 +00:00
David Hewitt 2ac30ec411 err: tweak names, inlining and docs 2021-11-27 08:26:04 +00:00
Gert Hulselmans 5ecc715d10 Map "PyPyObject_HasAttr" to "PyObject_HasAttr" so hasattr works with PyPy.
Map "PyPyObject_HasAttr" to "PyObject_HasAttr" so hasattr works
with PyPy. Solves: "undefined symbol: PyObject_HasAttr" when
importing the library.
2021-11-25 19:32:24 +00:00
David Hewitt a0d3ab0de1
Merge pull request #2019 from davidhewitt/inventory-0.2.0
inventory: update to 0.2
2021-11-23 07:39:05 +00:00
Miles Granger c4147cdde4
Add PyCapsule API (#1980)
Co-authored-by: Georg Brandl <georg@python.org>
2021-11-23 06:57:37 +01:00
David Hewitt f17e0d35cd inventory: update to 0.2 2021-11-22 22:57:58 +00:00
David Hewitt e9b46f76da
Merge pull request #1985 from PyO3/is_instance_of
add PyType::is_subclass_of and PyAny::is_instance_of
2021-11-20 14:56:36 +00:00
David Hewitt ded44eebfb
Merge pull request #2006 from davidhewitt/drop-py36
python: drop support for 3.6
2021-11-20 14:04:31 +00:00
Georg Brandl 43893158b1 switch is_instance/is_instance_of, is_subclass/is_subclass_of 2021-11-20 13:18:43 +00:00
Georg Brandl a83c31a3af add PyType::is_subclass_of and PyAny::is_instance_of
which get the type to check against as an arguments,
as opposed to a compile-time generic type.
2021-11-20 13:16:15 +00:00
David Hewitt cc91a7c574
Merge pull request #2007 from davidhewitt/remove-0.14-deprecations
deprecations: remove items deprecated in PyO3 0.14
2021-11-20 13:09:04 +00:00
David Hewitt 70030f130d python: drop support for 3.6 2021-11-20 13:02:42 +00:00
David Hewitt 0dfe6b0274
Merge pull request #2008 from davidhewitt/build-config-no-resolve-default
pyo3-build-config: don't enable resolve-config by default
2021-11-20 12:56:31 +00:00
David Hewitt c9a4cd1f87 deprecations: remove items deprecated in PyO3 0.14 2021-11-19 16:33:29 +00:00
Vincent Michel 91caa814d0 Add `Py::setattr` method 2021-11-19 16:59:54 +01:00
David Hewitt b9cc10f3fb pyo3-build-config: don't enable resolve-config by default 2021-11-19 14:19:24 +00:00
David Hewitt 6a65f98bd2 msrv: bump to 1.48 2021-11-19 10:10:59 +00:00
David Hewitt eb5059acc7 release: 0.15.1 2021-11-18 07:34:22 +00:00
David Hewitt 26ccc1ab37 macros: fix panic in __get__ implementation 2021-11-15 16:02:59 +00:00
David Hewitt 1df68e852e allow_threads: switch from `catch_unwind` to guard pattern 2021-11-15 12:25:53 +00:00
David Hewitt 8e41483bad
Merge pull request #1991 from messense/pypy-abi3
Don't emit `Py_LIMITED_API` cfg for PyPy
2021-11-15 10:13:23 +00:00
David Hewitt 9ae7e31e9c
Merge pull request #1977 from davidhewitt/traceback-type
types: add PyTraceback
2021-11-15 09:04:15 +00:00
messense 73c3911748 Don't emit `Py_LIMITED_API` cfg for PyPy 2021-11-15 15:40:27 +08:00
David Hewitt 88ca6bbbab types: add PyTraceback 2021-11-15 07:25:57 +00:00
messense 2325c283b0 Fix mingw platform detection 2021-11-15 15:15:16 +08:00
Moriyoshi Koizumi ae05020b13 Support Py::as_ref() and Py::into_ref() for PySequence, PyIterator and PyMapping. 2021-11-13 08:23:40 +00:00
David Hewitt 23778f5386 pymethods: test and document opt-out of protos 2021-11-10 23:28:01 +00:00
David Hewitt 47747444c7 release: 0.15.0 2021-11-03 23:00:38 +00:00
David Hewitt f801c19efe err: add `PyErr::take` 2021-11-02 23:12:36 +00:00
David Hewitt 6b1afa4040 pypy: support 3.8 2021-10-27 22:17:45 +01:00
Gregory Szorc a5f804e817 ffi: restore _PyImport_FindExtensionObject on Python 3.10
This symbol was initially removed from 3.10. But it was restored
late in the 3.10 development cycle in time for 3.10.0. See
https://bugs.python.org/issue45307. It is slated for removal in
3.11.
2021-10-23 15:24:52 -07:00
David Hewitt 4b2345fe80 pymethods: support __call__ proto 2021-10-23 00:06:46 +01:00
Azat Ibrakov 7349513f5b
Add fallback for `__mod__` magic method (#1934)
* Add fallback for `__mod__` magic method

* Add 'CHANGELOG' entry

* Complete tests
2021-10-19 23:14:26 +01:00
Ashley Anderson bf26daec2d
Positional-only args (#1925)
* Add support for positional-only args

* Update changelog. Add a few more tests. Run rust-fmt.

* Fix test.

* Fix tests again.

* Update CHANGELOG.md to link PR instead of issue

* Update guide to mention positional-only params

* Add unreachable!() per code review

* Update and expand tests for pos args.

* Fix tests, lint, add UI tests.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-10-19 23:13:27 +01:00
laurent 2042906832 pycfunction: add PyCFunction::new_closure rust defined closures 2021-10-17 07:59:50 +01:00
Chris Laplante 3b94f4b70c
Add `anyhow-integration` feature which implements From<anyhow::Error> for PyErr (#1822)
* Add 'anyhow' feature which provides simple From<anyhow::Error> for PyErr impl

This makes it possible to use anyhow::Result<T> as the return type for
methods and functions exposed to Python.

The current implementation just stringifies the anyhow::Error before
shoving it into a PyRuntimeError. Conversion back to the anyhow::Error
is not possible, but it is better than nothing.

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>

* Document `anyhow` feature in the guide

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>

* update changelog to document anyhow feature

* WIP adding tests

* Finish up anyhow feature

* Fix formatting

* Fix tests

* Fix tests

* Apply review suggestions

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
Co-authored-by: mejrs <brunokolenbrander@hotmail.com>
2021-10-17 07:54:29 +01:00
Bruno Kolenbrander ae873698d4
Implement `eyre` feature (#1893)
* Implement `eyre` feature

* Punctuation

* Add `eyre` entry in changelog

* Add `eyre` feature entry to guide

* Set eyre upper bound and move comment back

* Add eyre feature to docs.rs metadata

* Finish up review suggestions

* Update CHANGELOG.md

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-10-13 22:36:06 +00:00
Giovanni Barillari c06058888f review sysconfigdata filename match rules to support cp37m 2021-10-12 23:41:26 +01:00
David Hewitt c986b5d4ae
Merge pull request #1889 from davidhewitt/py310
packaging: formal support for Python 3.10
2021-09-29 19:36:52 +01:00
David Hewitt 7c4503e0ca ffi: updates for Python 3.10
Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2021-09-29 08:02:08 +01:00
David Hewitt a5d0aa777c py310: add abi3-py310 feature 2021-09-26 16:21:35 +01:00
David Hewitt 16ac7d481d
Merge pull request #1844 from davidhewitt/mapping-type
types: add PyMapping
2021-09-26 14:55:59 +01:00
David Hewitt d929916071 types: add PyMapping 2021-09-26 13:57:33 +01:00
Mo Mirza 4a34cc63a6
Remove use of unwrap (#1888)
* Remove use of unwrap

* Update changelog

* Update CHANGELOG.md

Co-authored-by: Mo Mirza <mo.mirza@iwoca.co.uk>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-09-26 09:01:23 +01:00
Dean Li c72033751e
update changelog 2021-09-25 21:02:06 +08:00
Sergey Kvachonok 2f74ab0d23 build-config: Always pass `abi3` flag to `default_lib_name_windows()`
Hardcoding `false` here leads to an incorrect abi3 DLL name
when cross-compiling to Windows.
2021-09-22 07:30:21 +01:00
Alex Touchet 2a09583b28 Update various links and formatting 2021-09-18 11:48:45 -07:00
David Hewitt 70d829de66 gil: try to initialize threads on Python 3.6 if possible 2021-09-17 08:48:21 +01:00
David Hewitt 097d7e09cb pyo3-build-config: fix location for conda interpreter on windows 2021-09-16 23:38:46 +01:00
David Hewitt dca02a92ce changelog: updates for 0.14.5 backports 2021-09-05 15:19:36 +01:00
Georg Brandl 7cb4faf21c PyList/PyTuple: add as_sequence()
Fixes #1845
2021-09-03 08:09:19 +02:00
Gregory Szorc 1e951d5d8b pyo3-build-config: add a crate feature to control build script
I have a use case in PyOxidizer where I want to use the
pyo3-build-config crate as a library crate so I can access the
`InterpreterConfig` struct so I can read/write config files without
reinventing the wheel.

This is doable before this commit. But it requires that the
build environment have a Python interpreter. This is undesirable
for library usage.

This commit introduces a cargo feature flag to control whether the
build script does anything. The feature flag must be present for
the build script to resolve a config. The feature flag is enabled
by default for backwards compatibility. The pyo3 and pyo3-macros-backend
crates use this feature by default, for backwards compatibility and
because it is the reasonable default.

This is probably room to conditionalize some APIs and other behavior
based on this feature flag. But we stop short of doing that for
the time being.
2021-09-01 19:44:54 -07:00
David Hewitt 921c4410ce
Merge pull request #1849 from PyO3/pylist_apis
PyList: add more sequence APIs
2021-09-01 08:50:49 +01:00
David Hewitt 868f668201
Merge pull request #1819 from indygreg/links-python
cargo: add `links = "python"`
2021-08-30 22:22:56 +01:00
Gregory Szorc 82d9b44f5e cargo: add `links = "python"`
PyOxidizer has crates depending on `pyo3` that would like to access
the `pyo3` crate configuration. (This use case isn't unique to
PyOxidizer.)

Cargo has a facility for enabling the build scripts of dependent
crates to access _exported_ variables via `DEP_` environment
variables. However, this only works if the exporting crate defines a
`links` key in its Cargo manifest. See
https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key.

While `pyo3`'s build script doesn't yet export the variables that
PyOxidizer will need, a prerequisite to making this work is adding
the `links` key. Since this change could introduce unintended
side-effects, it warrants being made in its own commit, which is
why we're making this change outside of #1793.

I _think_ this change should be mostly safe: the `links` key is
effectively metadata advertising that a crate links against a named
library. The only side-effects setting it has is to enable the
aforementioned `DEP_` environment variables in build scripts and
enforcing a limitation that only a single crate may link against the
same native library. I believe the only potential for this change
to cause problems is if there are multiple crates with `links =
"python"` entries. I'm not aware of any other crates that advertise
`links = "python"`: even `python3-sys` / `cpython` use `links =
"python3"` so this change should not prevent dual use of `pyo3` and
`cpython` in the same build.
2021-08-30 09:47:54 -07:00
David Hewitt a20864a903 ci: test and fix s390x build 2021-08-30 13:50:44 +01:00
Georg Brandl af46bf3bc6 PyList/Tuple: add more sequence APIs
See #1845
2021-08-30 12:19:31 +02:00
David Hewitt 5119bad580 changelog: updates for 0.14.4 2021-08-29 08:07:44 +01:00
David Hewitt f76535fd07 pyo3-macros-backend: support macros inside doc attributes 2021-08-28 22:47:20 +01:00
David Hewitt cf0e8a6435
Merge pull request #1830 from deantvv/ffi-cleanup-0825
ffi cleanup: pystrtod to pythonrun
2021-08-28 07:23:47 +01:00
David Hewitt 9c03227a20
Merge pull request #1833 from davidhewitt/changelog-function-brackets
changelog: remove function parentheses
2021-08-27 22:57:41 +01:00
Dean Li 73220565c1
update changelog 2021-08-27 23:36:59 +08:00
David Hewitt 755dd221e7 pystring: disable `PyString::data` on big-endian targets 2021-08-26 19:29:58 +01:00
David Hewitt 4a50a26c87 changelog: remove function parentheses 2021-08-26 18:59:07 +01:00
David Hewitt 3a90ff77f4 list,tuple,sequence: add slice indexing 2021-08-26 07:57:12 +01:00
David Hewitt de87971bf6
Merge pull request #1827 from davidhewitt/changelog-tidy
changelog: fix PR links
2021-08-24 20:29:58 +01:00
Georg Brandl 3bed78230d
Merge pull request #1828 from PyO3/get_slice_rename 2021-08-24 10:38:32 +02:00
Georg Brandl 097216702f tuple: add back old slice() for deprecation cycle 2021-08-24 09:08:08 +02:00
David Hewitt 764b1e5b95 changelog: fix PR links 2021-08-24 07:44:50 +01:00
Georg Brandl c522a9c087 list/tuple: rename slice -> get_slice 2021-08-24 08:40:05 +02:00
Georg Brandl 611126d994 list/tuple/sequence: implement Index
See #1667.
2021-08-24 08:24:47 +02:00
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
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
Alon Levy e5542f2214 pyo3-build-config: if found more than one candidate, filter on arch
If we got more then one file, only take those that contain the arch name.
For ubuntu 20.04 with host architecture x86_64 and a foreign architecture of armhf
this reduces the number of candidates to 1:

  $ find /usr/lib/python3.8/ -name '_sysconfigdata*.py' -not -lname '*'
  /usr/lib/python3.8/_sysconfigdata__x86_64-linux-gnu.py
  /usr/lib/python3.8/_sysconfigdata__arm-linux-gnueabihf.py

CHANGELOG.md: add entry for cross-sysconfigdata filter on arch

commit changelog:
1. initial
2. if filtered list is empty, use pre filtered.
3. clippy is_empty and cloned
2021-05-30 10:07:03 +03:00
Erik Johnston a56f23d7f2 Add changelog entry 2021-05-26 12:23:47 +01:00
David Hewitt 3e87ea3593 pymodule: don't call PyEval_InitThreads 2021-05-25 11:02:16 +01:00
David Hewitt 355bd0c336 pymodule: tidy up module init 2021-05-25 10:54:16 +01:00
David Hewitt f4dfafa07b changelog: fix missing bits 2021-05-25 07:32:47 +01:00
David Hewitt a109640850 pyfn: deprecate name argument 2021-05-20 08:54:29 +01:00
Tim Robinson 50352f9137 Apply review suggestions 2021-05-15 10:34:34 +01:00
Tim Robinson c803033f5e Add to CHANGELOG 2021-05-13 13:17:56 +01:00
David Hewitt 4d46abde73 macros: support `#[pyo3(name = "...")]` 2021-05-07 22:35:52 +01:00
David Hewitt 4613b3dd7e
Merge pull request #1596 from davidhewitt/remove-pytypeinfo-layout
type_object: remove layout and base type from PyTypeInfo
2021-05-07 22:32:24 +01:00
David Hewitt d81abe8344 pyclass: support extending Exception types 2021-05-04 22:00:22 +01:00
David Hewitt 7536554ceb type_object: remove layout and base type from PyTypeInfo 2021-05-04 21:39:42 +01:00
David Hewitt 3ee84a3c26
Merge pull request #1128 from c410-f3r/array
Add support for arbitrary arrays
2021-05-01 16:02:22 +01:00
David Hewitt c0ff97e525
Merge pull request #1573 from davidhewitt/utc
ffi: support PyDateTime_TimeZone_UTC
2021-04-29 22:55:35 +01:00
David Hewitt 7ead166d9d array: safer implementation of try_create_array 2021-04-26 08:22:14 +01:00
Caio 9bc5089e4b Add support for arbitrary arrays 2021-04-26 08:22:14 +01:00
David Hewitt e95e73b55e ffi: support PyDateTime_TimeZone_UTC 2021-04-22 22:42:57 +01:00
Gregory Szorc 754c27f17d ffi: Define missing import APIs
Co-authored-by: Nicholas Sim <nsim+github@posteo.net>
2021-04-21 21:01:26 +01:00