Commit graph

5112 commits

Author SHA1 Message Date
Matti Picus a7cc5952c7
Conditionally mangle the function name
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-03-14 09:21:35 +11:00
Matti Picus 0f1ff1d852 mangle exported functions for PyPy 2023-03-12 08:40:12 +11:00
bors[bot] 4b0b9b91a3
Merge #3036
3036: fix const-ness of some FFI name & doc members r=adamreichold a=davidhewitt

I just noticed that these are [`*const` since Python 3.7](007d7ff73f (diff-830b405713d1c40982ffa918864e39c40c1b318d79b8dd2b523646dc3bd18b52)).

This might break existing compiles, so will not include this in 0.18.2.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-03-10 17:12:15 +00:00
David Hewitt fbebc285c0 fix const-ness of some FFI name & doc members 2023-03-10 16:02:52 +00:00
bors[bot] 550473fb1d
Merge #3031
3031: mangle exported functions for PyPy r=davidhewitt a=mattip

I run HEAD of PyO3 with HEAD of some PyPy branches, and noticed that the py3.10 branch (which implements python3.10) [fails to properly build](https://github.com/pypy/binary-testing/actions/runs/4334873617/jobs/7569059852#step:6:179). The failure was a missing export:
```
 /home/runner/work/binary-testing/binary-testing/pyo3/src/exceptions.rs:715: \
    undefined reference to `PyExc_EncodingWarning'
          collect2: error: ld returned 1 exit status
```

So I grepped around in the code for `Py_3_10` to see what new functions were added and found a few that needed PyPy-specific exports.

Co-authored-by: Matti Picus <matti.picus@gmail.com>
2023-03-10 09:39:54 +00:00
bors[bot] dd6498142f
Merge #3014
3014: feat: add #[pyo3(get, set)] for Cell r=davidhewitt a=AntoineRR

This fixes #2659.
The types for which `#[pyo3(get, set)]` should now work are `Cell`, `Arc` and `Box`.

There is one issue regarding `Box`, the implementation of `FromPyObject` conflicts with another one. I could not find what the issue was, especially since the other implementations for `Arc` and `Cell` work as expected. The related code and test has been commented out for now. Maybe someone could help me fix this issue if I don't figure it out myself? There is also the possibility to remove the implementation for `Box` of course.


Co-authored-by: Antoine Romero-Romero <ant.romero2@orange.fr>
2023-03-10 06:13:28 +00:00
bors[bot] b8bf93bce0
Merge #3032
3032: fix clippy and ui tests for Rust 1.68 r=adamreichold a=davidhewitt

The usual 😄 

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-03-10 05:00:29 +00:00
David Hewitt cd36c6fc21 fix clippy and ui tests for Rust 1.68 2023-03-09 23:41:26 +00:00
Matti Picus 232f9fb8ab add newsfragment 2023-03-10 10:16:24 +11:00
Antoine Romero-Romero a629e8267a feat: add #[pyo3(get, set)] for Cell 2023-03-09 23:09:30 +00:00
Matti Picus 8446414f3b mangle exported functions for PyPy 2023-03-10 07:27:38 +11:00
bors[bot] 59bbb40a35
Merge #3025
3025: Explain that pyo3-ffi-check is part of our CI now. r=messense a=adamreichold



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-03-09 01:10:08 +00:00
Adam Reichold b63f9831ad Explain that pyo3-ffi-check is part of our CI now. 2023-03-08 16:08:27 +01:00
bors[bot] d31fa297c5
Merge #3019
3019: Use stable toolchain for Valgrind job as version 3.20 should handle the DWARF version. r=adamreichold a=adamreichold



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-03-07 06:13:31 +00:00
Adam Reichold a913be22dc Use stable toolchain for Valgrind job as version 3.20 should handle the DWARF version. 2023-03-06 23:34:13 +01:00
bors[bot] 713c02a910
Merge #3009
3009: Remove stale references to tox.ini from template substitution scripts. r=messense a=adamreichold

Closes #3008 

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-03-05 08:21:29 +00:00
Adam Reichold 39d19113fa Remove stale references to tox.ini from template substitution scripts. 2023-03-05 09:17:34 +01:00
bors[bot] c28edd0a81
Merge #2993
2993: fix `non_snake_case` lint for `#[pyfunction]` generated code r=davidhewitt a=davidhewitt

As promised in #2990 

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-28 08:49:13 +00:00
David Hewitt 7a2b1f0e13 fix non_snake_case lint for #[pyfunction] generated code 2023-02-28 08:44:17 +00:00
bors[bot] 794755c579
Merge #2990 #2991
2990: Fix `clippy::redundant_closure` lint firing for pyfunction defaults r=adamreichold a=davidhewitt

Fixes #2988

I'll push a follow-up for the FIXME as a separate PR.

2991: unpin 3.11 ci jobs r=adamreichold a=davidhewitt

With Python 3.11.2 released for a couple weeks now, I think #2817 is probably not an issue in CI any more.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-28 05:11:22 +00:00
David Hewitt 0ef5531cbd unpin 3.11 ci jobs 2023-02-27 22:25:07 +00:00
David Hewitt 226bf97ec0 Fix clippy::redundant_closure lint firing for pyfunction defaults 2023-02-27 22:10:06 +00:00
bors[bot] 410bb15d71
Merge #2982
2982: explain STATUS_DLL_NOT_FOUND r=adamreichold a=mejrs

I had someone ask me this today, and googling for it I found various other places where this was asked, with no (good) answers. 

Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2023-02-24 17:13:38 +00:00
mejrs db16580b63 Make changes 2023-02-23 12:36:54 +01:00
mejrs 90ce52175f explain STATUS_DLL_NOT_FOUND 2023-02-22 23:30:19 +01:00
bors[bot] bbaceb88b4
Merge #2899
2899: RFC: Provide a special purpose FromPyObject impl for byte slices r=davidhewitt a=adamreichold

This enables efficiently and safely getting a byte slice from either bytes or byte arrays.

The main issue I see here is discoverability, i.e. should this be mention in the docs of `PyBytes` and `PyByteArray` or in the guide?

It is also not completely clear whether this really _fixes_ the issue.

Closes #2888 

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-02-22 22:13:56 +00:00
bors[bot] 7cffc92e69
Merge #2979
2979: allow `create_exception!` to place the exception in a `dotted.module` r=adamreichold a=davidhewitt

Closes #2946 

Credit fully to `@BlueGlassBlock`

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-22 21:24:21 +00:00
Adam Reichold 0a48859fc4 Make tests of Cow::<[u8]> compatible with older Python versions by using native code instead inline Python. 2023-02-22 22:12:35 +01:00
Adam Reichold a16f2e45c8 Include conversions for bytes, bytearrays and Cow<[u8]> in the guide. 2023-02-22 22:07:59 +01:00
Adam Reichold e3e37ac624 Add ToPyObject and IntoPy impl for Cow<[u8]> to support return values as well as function arguments. 2023-02-22 22:07:59 +01:00
Adam Reichold de79ebc5f8 Provide a special purpose FromPyObject impl to efficiently and safely get a byte slice from either bytes or byte arrays. 2023-02-22 22:07:59 +01:00
David Hewitt f239d2d075 allow create_exception! to place the exception in a dotted.module 2023-02-22 20:08:53 +00:00
bors[bot] 12ce8d2e0f
Merge #2974
2974: Reduce API surface of mod gil to better encapsulate its safety invariants. r=davidhewitt a=adamreichold

Closes #2969

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-02-22 19:39:31 +00:00
bors[bot] 064e52ab66
Merge #2976
2976: Update Example projects r=adamreichold a=kngwyu

Interestingly, it may be used for ChatGPT 😅 
Also I removed my old project because it's way too outdated (around pyo3 0.10?)



Co-authored-by: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
2023-02-22 06:15:21 +00:00
Yuji Kanagawa dd7ac28b11
Update Example projects
Interestingly, it may be used for ChatGPT 😅 
Also I removed my old project because it's way too outdated (around pyo3 0.10?)
2023-02-22 14:31:44 +09:00
Adam Reichold 911046c02c Reduce API surface of mod gil to better encapsulate its safety invariants. 2023-02-21 21:08:38 +01:00
bors[bot] bd07ecc91d
Merge #2952
2952: Fix allow_threads segfault r=davidhewitt a=OliverBalfour

Please see the corresponding issue **#2951** for details. This PR adds the failing test from the issue and then a fix for it. The fix simply calls `ReferencePool::update_counts` at the end of `allow_threads` to ensure objects aren't accidentally deleted too soon.

Co-authored-by: Oliver Balfour <oliver.leo.balfour@gmail.com>
2023-02-21 08:46:06 +00:00
Oliver Balfour 83f5fa2902 update reference pool counts at the end of allow_threads to avoid use-after-free 2023-02-21 08:44:48 +00:00
bors[bot] b6d3627c91
Merge #2964
2964: Update `README.md` by adding datafusion, ballista and delta-rs r=adamreichold a=iajoiner

Add Python bindings of datafusion, ballista and the official Rust implementation of Delta Lake (delta-rs). The former two are Apache projects under Arrow and the last is from Delta Lake itself so all three projects are notable and need to be added as examples.

Co-authored-by: Ian Alexander Joiner <14581281+iajoiner@users.noreply.github.com>
2023-02-20 16:14:17 +00:00
Ian Alexander Joiner 7a0cca5a90 Fix description to match maturin and reorder examples 2023-02-20 10:46:29 -05:00
bors[bot] 2082cdc63e
Merge #2966
2966: Correct documentation for `Py::borrow_mut()`. r=adamreichold a=Enyium

Closes #2958.


Co-authored-by: Enyium <123484196+Enyium@users.noreply.github.com>
2023-02-19 20:20:45 +00:00
Enyium d700754917
Correct documentation for Py::borrow_mut(). 2023-02-19 21:12:06 +01:00
Ian Alexander Joiner 64227bf5a4
Update README.md by adding datafusion, ballista and delta-rs 2023-02-19 12:38:08 -05:00
bors[bot] f5f688dd68
Merge #2961
2961: docs: fix typo in method name r=adamreichold a=lycantropos

There's no `PyFunction::new_closure`, but there is [`PyCFunction::new_closure`](3b2c175f8d/src/types/function.rs (L50-L104)), so I guess it's a typo in docs.

Co-authored-by: Azat Ibrakov <azatibrakov@gmail.com>
2023-02-18 21:07:25 +00:00
Azat Ibrakov 9f7368922f docs: fix typo in method name 2023-02-18 22:02:05 +01:00
bors[bot] 3b2c175f8d
Merge #2947
2947: change PyModule::add_class to return an error if class creation fails r=adamreichold a=davidhewitt

Related to #2942 

At the moment there are panics deep in the `#[pyclass]` machinery when initialising the type fails. This PR adjusts a number of these functions to return `PyResult` instead, so that we can handle the error more appropriately further down the pipeline.

For example, take the following snippet:

```rust
#[pyclass(extends = PyBool)]
struct ExtendsBool;

#[pymodule]
fn pyo3_scratch(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_class::<ExtendsBool>()?;
    Ok(())
}
```

Currently, importing this module will fail with a panic:

```
TypeError: type 'bool' is not an acceptable base type
thread '<unnamed>' panicked at 'An error occurred while initializing class ExtendsBool', /Users/david/Dev/pyo3/src/pyclass.rs:412:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/david/.virtualenvs/pyo3/lib/python3.10/site-packages/pyo3_scratch/__init__.py", line 1, in <module>
    from .pyo3_scratch import *
pyo3_runtime.PanicException: An error occurred while initializing class ExtendsBool
```

After this PR, this import still fails, but with a slightly cleaner, more Pythonic error:

```
TypeError: type 'bool' is not an acceptable base type

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

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/david/.virtualenvs/pyo3/lib/python3.10/site-packages/pyo3_scratch/__init__.py", line 1, in <module>
    from .pyo3_scratch import *
RuntimeError: An error occurred while initializing class ExtendsBool
```

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-02-18 16:12:17 +00:00
Adam Reichold 577570e8c4 Reduce visibility of CaptureStdErr type to avoid warnings on older toolchains. 2023-02-18 17:11:40 +01:00
David Hewitt c7cc48f8e4 use PyO3 types within LazyTypeObject 2023-02-18 09:06:36 +00:00
bors[bot] c858ced8d4
Merge #2944
2944: optimize sequence conversion for list and tuple r=adamreichold a=davidhewitt

closes #2943 

Avoid using `PyObject_IsInstance` for checking if lists or tuples are sequences, as we know they are always sequences.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-15 23:16:35 +00:00
bors[bot] 18e7094ccc
Merge #2954
2954: optimize mapping conversion for dict r=davidhewitt a=davidhewitt

Equivalent of #2944 for dicts -> mapping.

The benchmark diff is not as significant as in #2944. Still something like 80ns -> 2ns on my machine.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-15 22:27:36 +00:00