Commit graph

5010 commits

Author SHA1 Message Date
Nate Kent f11290d314
Add additional unit test for GC traversal
Since we're just testing a bug during traversal, we don't actually have
to reap the object, we just have to make a reference cycle so that it's
traverse method is called.
2023-01-26 16:27:54 -08:00
Nate Kent f38841a8e2
Check to see if object is None before traversing
Closes #2915

When using the C API directly, the intended way to call `visitproc` is
via the `Py_VISIT` macro, which checks to see that the provided pointer
is not null before passing it along to `visitproc`. Because PyO3 isn't
using the macro, it needs to manually check that the pointer isn't null.
Without this check, calling `visit.call(&obj)` where `let obj = None;`
will segfault.
2023-01-26 15:55:58 -08:00
bors[bot] 98b12973fc
Merge #2922
2922: Update rust 1.67 r=mejrs a=mejrs



Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2023-01-26 21:38:25 +00:00
mejrs 2052269aea Update rust 1.67 2023-01-26 21:44:05 +01:00
bors[bot] 9004bd2d9e
Merge #2919
2919: Fix link for #2879 r=mejrs a=qbx2

Fixes an incorrect link in changelog.

Co-authored-by: Sunyeop Lee <sunyeop97@gmail.com>
2023-01-26 14:09:53 +00:00
Sunyeop Lee e637b39abd
Fix link for #2879 2023-01-26 21:54:27 +09:00
bors[bot] 18081ba14e
Merge #2896
2896: make rust function benchmarks more similar to the Python ones r=adamreichold a=davidhewitt

We have some benchmarks in `pytests/tests/test_pyfunctions.py` which I occasionally peek at, which compares some `#[pyfunction]` performance with pure-Python equivalents. It's designed purely to measure the overheads.

The existing comparison wasn't exactly fair because it used Rust types such as i32 on the Rust side, meaning there was additional runtime type checking going on compared to the Python implementations.

I've removed that in this PR, making all the input types on the Rust side just `&PyAny` or `Option<&PyAny>`. This does reduce the gap between the Python and Rust ones where we're slower, however it shows there is still some wins we could yet find in overhead reduction.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-20 20:43:12 +00:00
bors[bot] 8f0a2bbf7b
Merge #2897
2897: add link on how to obtain GIL to guide r=birkenfeld a=davidhewitt

Closes #2164 

Most of that issue is already addressed with the new `#[pyo3(signature = (...))]` option and its guide page. The final suggestion to make it easier to find recommendations on how to acquire the GIL seems reasonable to me.

(EDIT: original issue link was wrong)

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-20 12:29:13 +00:00
David Hewitt e83803e813 add link on how to obtain GIL to guide 2023-01-20 08:21:57 +00:00
David Hewitt 0362855773 make rust benchmarks more similar to the Python ones 2023-01-20 07:24:05 +00:00
David Hewitt 16d347d96a remove benchmarks from deprecated_pyfunctions 2023-01-20 07:19:13 +00:00
bors[bot] 4d8537499f
Merge #2895
2895: tidy up implementation of pyclass `tp_dealloc` r=adamreichold a=davidhewitt

Just carries out a TODO to remove one level from the call stack. No external-facing changes.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-19 21:48:41 +00:00
David Hewitt 255d9bacce tidy up implementation of pyclass tp_dealloc 2023-01-19 21:31:59 +00:00
bors[bot] dbb108c2c5
Merge #2893
2893: rename `wrap_pyfunction` impl to `wrap_pyfunction_impl` r=messense a=davidhewitt

I mistyped the other day and wrote `wrap_pyfunction(f, py)` without the `!` to invoke the macro, and `rust-analyzer` imported the hidden symbol `pyo3::impl_::pyfunction::wrap_pyfunction`. Took me a moment to realise the compilation failure was because I'd forgotten the `!`.

This PR just renames that hidden symbol to `pyo3::impl_::pyfunction::wrap_pyfunction_impl` so it doesn't clash with the user-facing macro.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-19 20:08:59 +00:00
bors[bot] 0c9078ade4
Merge #2886
2886: send errors in `__releasebuffer__` to `sys.unraisablehook` r=adamreichold a=davidhewitt

I noticed that in the `__releasebuffer__` implementation we currently diverge from documentation by allowing `-> PyResult<()>` return values, but they cause crashes later down the line.

e.g. without the other changes in this PR, the new test case would crash with the following message:

```
ValueError: oh dear

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemError: <class 'bytes'> returned a result with an exception set
```

After some deliberation I decided to allow `-> PyResult<()>` returns because:
 - it keeps the macro implementation and usage simpler
 - errors might be produced by the `__releasebuffer__` internals anyway (e.g. due to `PyCell` locking, or invalid self type passed)

As a result, this PR cleans up the case discussed to send errors to `sys.unraisablehook`, and updates the documentation to be clearer on the allowed behaviour.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-19 19:15:43 +00:00
David Hewitt 586fed2c4b send errors in __releasebuffer__ to sys.unraisablehook 2023-01-19 19:10:06 +00:00
David Hewitt 89d4ae1dbf rename wrap_pyfunction impl to wrap_pyfunction_impl 2023-01-19 08:51:44 +00:00
bors[bot] bed4f9d6ee
Merge #2883
2883: release: 0.18.0 r=davidhewitt a=davidhewitt

Release for 0.18.0

I propose to put this live on Tuesday, will merge #2882 and rebase first.

Closes #2785 

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-17 20:40:43 +00:00
David Hewitt 224a4160b4 release: 0.18.0 2023-01-17 19:04:30 +00:00
David Hewitt ca1bbe3d39 add migration notes for PyO3 0.18 2023-01-17 08:14:32 +00:00
bors[bot] 72c561ce13
Merge #2882
2882: inspect: gate behind `experimental-inspect` feature r=davidhewitt a=davidhewitt

This is the last thing I want to do before preparing 0.18 release.

The `pyo3::inspect` functionality looks useful as a first step towards #2454. However, we don't actually make use of this anywhere within PyO3 yet (we could probably use it for better error messages). I think we also have open questions about the traits which I'd like to resolve before committing to these additional APIs. (For example, this PR adds `IntoPy::type_output`, which seems potentially misplaced to me, the `type_output` function probably wants to be on a non-generic trait e.g. `ToPyObject` or maybe #2316.) 

As such, I propose putting these APIs behind an `experimental-inspect` feature gate for now, and invite users who find them useful to contribute a finished-off design.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-17 07:31:09 +00:00
bors[bot] 713f51a7df
Merge #2879
2879: Improve derive(FromPyObject) to apply intern! when applicable to get_item r=davidhewitt a=qbx2

This PR adds more `intern!`s to FromPyObject derive macro implementation. This should improve performance when using `#[pyo3(item)]`.


Co-authored-by: Sunyeop Lee <sunyeop97@gmail.com>
2023-01-15 14:53:07 +00:00
Sunyeop Lee 8026f3521e Improve derive(FromPyObject) to apply intern! when applicable 2023-01-15 13:39:06 +00:00
David Hewitt 20ca3be659 inspect: gate behind experimental-inspect feature 2023-01-15 12:41:23 +00:00
bors[bot] 556b3cf48a
Merge #2703
2703: deprecate required argument after `Option<T>` without signature r=davidhewitt a=davidhewitt

This PR is a follow-up to #2702 to make required arguments after `Option<T>` arguments require a `#[pyo3(signature)]` annotation to remove the possible ambiguity on whether the developer actually wanted to have a required option (which is what PyO3 is currently forced to assume).

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-15 10:19:13 +00:00
David Hewitt 8f48d157d6 deprecate required arguments after option arguments without signature 2023-01-15 10:17:20 +00:00
bors[bot] ed0f3384d2
Merge #2875
2875: Update `memoffset`, `send_wrapper` and `hashbrown` r=adamreichold a=messense



Co-authored-by: messense <messense@icloud.com>
2023-01-12 06:02:24 +00:00
messense a7a9daed24
Add a changelog entry for #2875 2023-01-12 14:00:53 +08:00
messense 40a51985b3
Set minimal package versions by parsing Cargo.lock 2023-01-12 14:00:53 +08:00
messense 15b1ff6c9a
Relax hashbrown version constraint to allow 0.13.x 2023-01-11 23:13:24 +08:00
messense cb969b7ea0
Update send_wrapper to 0.6 2023-01-11 23:10:11 +08:00
messense d6b15af0ff
Update memoffset to 0.8 2023-01-11 23:09:51 +08:00
bors[bot] 3fc0634ee6
Merge #2874
2874: netlify: fix root redirect r=messense a=davidhewitt

See https://github.com/PyO3/pyo3/pull/2871#issuecomment-1378074972

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-11 03:58:50 +00:00
David Hewitt 71f02ff0bb netlify: fix root redirect 2023-01-11 00:44:14 +00:00
bors[bot] 61e0a09cb7
Merge #2871
2871: netlify: generate all redirects automatically r=messense a=davidhewitt

Uses the versions from the pulled `gh-pages` tarball to generate the `docs.rs` redirects. Simplifies the release process.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-10 22:24:24 +00:00
David Hewitt 68e2054fc4 netlify: generate all redirects automatically 2023-01-10 08:26:02 +00:00
bors[bot] 02fa6b85ba
Merge #2864
2864: Add a section on memory management for `extension` r=davidhewitt a=haixuanTao

Adding a special case of memory management when writing an extension.

This is a documentation of: https://github.com/PyO3/pyo3/issues/1056 and https://github.com/PyO3/pyo3/issues/2853


Co-authored-by: Haixuan Xavier Tao <tao.xavier@outlook.com>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-10 07:44:27 +00:00
David Hewitt eea2a31bd3 adjust location and wording for extension module memory management 2023-01-10 07:42:39 +00:00
Haixuan Xavier Tao 8af9d2a19a Add a section on memory management for extension
Adding a special case of memory management when writing an extension.

This is a documentation of: https://github.com/PyO3/pyo3/issues/1056 and https://github.com/PyO3/pyo3/issues/2853
2023-01-10 07:37:21 +00:00
bors[bot] 34b9445faf
Merge #2869
2869: change latest URL from netlify proxy to redirect r=davidhewitt a=davidhewitt

Now that we serve all gh-pages content in netlify, it's nicer to have this as a proper redirect rather than a rewrite. Then the user can see what version of the docs they have landed on.

Closes #2867 

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-08 20:54:43 +00:00
bors[bot] bbf972f144
Merge #2868
2868: remove fallback rewrite for netlify -> gh-pages r=davidhewitt a=davidhewitt

Instead of having a rewrite to serve all content in gh-pages but not in netlify, instead I've added a webhook so that netlify will pull and rebuild when there is a push to gh-pages.

Fixes #2850

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-08 20:04:21 +00:00
David Hewitt 70c3260262 remove fallback redirect for netlify -> gh-pages 2023-01-08 19:58:56 +00:00
David Hewitt b6c71a8525 change latest URL from netlify proxy to redirect 2023-01-08 19:55:24 +00:00
bors[bot] 94c568d746
Merge #2678
2678: github pages example for sys.dict modules r=davidhewitt a=flickpp

Add an example into `python_from_rust.md` for creating a module and inserting it into the `sys.modules` dictionary.

As discussed here:
GH-2649 example for inserting moulde in sys.dict

Co-authored-by: James Welchman <jamesw@plantpot.ai>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-01-06 08:53:36 +00:00
David Hewitt 8651d3b0e8 address feedback in review #2678 2023-01-06 08:53:00 +00:00
James Welchman e52dbc907d GH-2649 example for inserting moulde in sys.dict 2023-01-05 21:26:47 +00:00
bors[bot] c09d24e64d
Merge #2859
2859: Remove `libpython.so` from cross compile error message r=davidhewitt a=messense

See https://github.com/PyO3/pyo3/discussions/2858.

Same as https://github.com/PyO3/maturin/pull/1389

Co-authored-by: messense <messense@icloud.com>
2023-01-05 10:17:09 +00:00
messense 7e89456c77
Remove libpython.so from cross compile error message 2023-01-05 17:07:21 +08:00
bors[bot] 09470eb42c
Merge #2852
2852: Fix links in `logging.md` r=adamreichold a=messense

It's broken: https://pyo3.rs/main/ecosystem/logging

After: https://deploy-preview-2852--pyo3.netlify.app/main/ecosystem/logging

Co-authored-by: messense <messense@icloud.com>
2023-01-03 12:23:09 +00:00
messense c722402e46
Fix links in logging.md 2023-01-03 20:03:51 +08:00