author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 11 Mar 2025 02:29:42 +0100 | |
branch | stable |
changeset 53042 | cdd7bf612c7b |
parent 52851 | d9d6ae9b9722 |
permissions | -rw-r--r-- |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
1 |
use crate::cpython::buffer::Element; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
2 |
use cpython::{ |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
3 |
buffer::PyBuffer, exc::ValueError, PyBytes, PyErr, PyResult, Python, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
4 |
}; |
47954
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47953
diff
changeset
|
5 |
use stable_deref_trait::StableDeref; |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
6 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
7 |
/// Safe abstraction over a `PyBytes` together with the `&[u8]` slice |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
8 |
/// that borrows it. Implements `Deref<Target = [u8]>`. |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
9 |
/// |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
10 |
/// Calling `PyBytes::data` requires a GIL marker but we want to access the |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
11 |
/// data in a thread that (ideally) does not need to acquire the GIL. |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
12 |
/// This type allows separating the call an the use. |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
13 |
/// |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
14 |
/// It also enables using a (wrapped) `PyBytes` in GIL-unaware generic code. |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
15 |
pub struct PyBytesDeref { |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
16 |
#[allow(unused)] |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
17 |
keep_alive: PyBytes, |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
18 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
19 |
/// Borrows the buffer inside `self.keep_alive`, |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
20 |
/// but the borrow-checker cannot express self-referential structs. |
52851
d9d6ae9b9722
rust-pyo3-dirstate: making bytes slices in core Sync
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52163
diff
changeset
|
21 |
data: &'static [u8], |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
22 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
23 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
24 |
impl PyBytesDeref { |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
25 |
pub fn new(py: Python, bytes: PyBytes) -> Self { |
52851
d9d6ae9b9722
rust-pyo3-dirstate: making bytes slices in core Sync
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52163
diff
changeset
|
26 |
let as_raw: *const [u8] = bytes.data(py); |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
27 |
Self { |
52851
d9d6ae9b9722
rust-pyo3-dirstate: making bytes slices in core Sync
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52163
diff
changeset
|
28 |
// Safety: the raw pointer is valid as long as the PyBytes is still |
d9d6ae9b9722
rust-pyo3-dirstate: making bytes slices in core Sync
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52163
diff
changeset
|
29 |
// alive, and the objecs owns it. |
d9d6ae9b9722
rust-pyo3-dirstate: making bytes slices in core Sync
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52163
diff
changeset
|
30 |
data: unsafe { &*as_raw }, |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
31 |
keep_alive: bytes, |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
32 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
33 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
34 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
35 |
pub fn unwrap(self) -> PyBytes { |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
36 |
self.keep_alive |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
37 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
38 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
39 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
40 |
impl std::ops::Deref for PyBytesDeref { |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
41 |
type Target = [u8]; |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
42 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
43 |
fn deref(&self) -> &[u8] { |
52851
d9d6ae9b9722
rust-pyo3-dirstate: making bytes slices in core Sync
Georges Racinet <georges.racinet@cloudcrane.io>
parents:
52163
diff
changeset
|
44 |
self.data |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
45 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
46 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
47 |
|
47954
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47953
diff
changeset
|
48 |
unsafe impl StableDeref for PyBytesDeref {} |
4afd6cc447b9
rust: Make OwningDirstateMap generic and move it into hg-core
Simon Sapin <simon.sapin@octobus.net>
parents:
47953
diff
changeset
|
49 |
|
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
50 |
fn require_send<T: Send>() {} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
51 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
52 |
#[allow(unused)] |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
53 |
fn static_assert_pybytes_is_send() { |
49933
be3b545c5cff
rust-clippy: fix remaining warnings in `hg-cpython`
Rapha?l Gom?s <rgomes@octobus.net>
parents:
47954
diff
changeset
|
54 |
#[allow(clippy::no_effect)] |
47953
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
55 |
require_send::<PyBytes>; |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
56 |
} |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
57 |
|
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
58 |
// Safety: PyBytes is Send. Raw pointers are not by default, |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
59 |
// but here sending one to another thread is fine since we ensure it stays |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
60 |
// valid. |
8f031a274cd6
rust: Move PyBytesWithData out of copy-tracing code
Simon Sapin <simon.sapin@octobus.net>
parents:
diff
changeset
|
61 |
unsafe impl Send for PyBytesDeref {} |
52163
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
62 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
63 |
/// |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
64 |
/// It also enables using a (wrapped) `PyBuffer` in GIL-unaware generic code. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
65 |
pub struct PyBufferDeref { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
66 |
#[allow(unused)] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
67 |
keep_alive: PyBuffer, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
68 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
69 |
/// Borrows the buffer inside `self.keep_alive`, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
70 |
/// but the borrow-checker cannot express self-referential structs. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
71 |
data: *const [u8], |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
72 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
73 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
74 |
fn get_buffer<'a>(py: Python, buf: &'a PyBuffer) -> PyResult<&'a [u8]> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
75 |
let len = buf.item_count(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
76 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
77 |
let cbuf = buf.buf_ptr(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
78 |
let has_correct_item_size = std::mem::size_of::<u8>() == buf.item_size(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
79 |
let is_valid_buffer = has_correct_item_size |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
80 |
&& buf.is_c_contiguous() |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
81 |
&& u8::is_compatible_format(buf.format()) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
82 |
&& buf.readonly(); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
83 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
84 |
let bytes = if is_valid_buffer { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
85 |
unsafe { std::slice::from_raw_parts(cbuf as *const u8, len) } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
86 |
} else { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
87 |
return Err(PyErr::new::<ValueError, _>( |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
88 |
py, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
89 |
"Buffer has an invalid memory representation", |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
90 |
)); |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
91 |
}; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
92 |
Ok(bytes) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
93 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
94 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
95 |
impl PyBufferDeref { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
96 |
pub fn new(py: Python, buf: PyBuffer) -> PyResult<Self> { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
97 |
Ok(Self { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
98 |
data: get_buffer(py, &buf)?, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
99 |
keep_alive: buf, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
100 |
}) |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
101 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
102 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
103 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
104 |
impl std::ops::Deref for PyBufferDeref { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
105 |
type Target = [u8]; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
106 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
107 |
fn deref(&self) -> &[u8] { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
108 |
// Safety: the raw pointer is valid as long as the PyBuffer is still |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
109 |
// alive, and the returned slice borrows `self`. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
110 |
unsafe { &*self.data } |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
111 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
112 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
113 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
114 |
unsafe impl StableDeref for PyBufferDeref {} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
115 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
116 |
#[allow(unused)] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
117 |
fn static_assert_pybuffer_is_send() { |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
118 |
#[allow(clippy::no_effect)] |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
119 |
require_send::<PyBuffer>; |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
120 |
} |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
121 |
|
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
122 |
// Safety: PyBuffer is Send. Raw pointers are not by default, |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
123 |
// but here sending one to another thread is fine since we ensure it stays |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
124 |
// valid. |
7346f93be7a4
revlog: add the glue to use the Rust `InnerRevlog` from Python
Rapha?l Gom?s <rgomes@octobus.net>
parents:
49933
diff
changeset
|
125 |
unsafe impl Send for PyBufferDeref {} |