Skip to content

Commit 85e6507

Browse files
davidhewittIcxolu
andauthored
drop memoffset dependency (#5545)
* drop `memoffset` dependency * drop "Runtime" building of `PyMethodDefType` * Update src/impl_/pyclass.rs Co-authored-by: Icxolu <[email protected]> * coverage * newsfragment --------- Co-authored-by: Icxolu <[email protected]>
1 parent 52c198a commit 85e6507

File tree

10 files changed

+224
-179
lines changed

10 files changed

+224
-179
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ rust-version.workspace = true
2626

2727
[dependencies]
2828
libc = "0.2.62"
29-
memoffset = "0.9"
3029
once_cell = "1.21"
3130

3231
# ffi bindings to the python interpreter, split into a separate crate so they can be used independently

newsfragments/5545.packaging.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Drop `memoffset` dependency.

pyo3-macros-backend/src/pyclass.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,14 +1671,12 @@ pub fn gen_complex_enum_variant_attr(
16711671
};
16721672

16731673
let method_def = quote! {
1674-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
1675-
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
1676-
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
1677-
#python_name,
1678-
#cls_type::#wrapper_ident
1679-
)
1680-
})
1681-
)
1674+
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
1675+
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
1676+
#python_name,
1677+
#cls_type::#wrapper_ident
1678+
)
1679+
})
16821680
};
16831681

16841682
MethodAndMethodDef {

pyo3-macros-backend/src/pyimpl.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,12 @@ pub fn gen_py_const(cls: &syn::Type, spec: &ConstSpec, ctx: &Ctx) -> MethodAndMe
242242
};
243243

244244
let method_def = quote! {
245-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
246-
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
247-
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
248-
#python_name,
249-
#cls::#wrapper_ident
250-
)
251-
})
252-
)
245+
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
246+
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
247+
#python_name,
248+
#cls::#wrapper_ident
249+
)
250+
})
253251
};
254252

255253
MethodAndMethodDef {

pyo3-macros-backend/src/pymethod.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,7 @@ pub fn impl_py_method_def(
365365
};
366366
let methoddef = spec.get_methoddef(quote! { #cls::#wrapper_ident }, doc, ctx);
367367
let method_def = quote! {
368-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
369-
#pyo3_path::impl_::pymethods::PyMethodDefType::#methoddef_type(#methoddef #add_flags)
370-
)
368+
#pyo3_path::impl_::pymethods::PyMethodDefType::#methoddef_type(#methoddef #add_flags)
371369
};
372370
Ok(MethodAndMethodDef {
373371
associated_method,
@@ -600,14 +598,12 @@ pub(crate) fn impl_py_class_attribute(
600598
};
601599

602600
let method_def = quote! {
603-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
604-
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
605-
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
606-
#python_name,
607-
#cls::#wrapper_ident
608-
)
609-
})
610-
)
601+
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
602+
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
603+
#python_name,
604+
#cls::#wrapper_ident
605+
)
606+
})
611607
};
612608

613609
Ok(MethodAndMethodDef {
@@ -788,13 +784,11 @@ pub fn impl_py_setter_def(
788784

789785
let method_def = quote! {
790786
#cfg_attrs
791-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
792-
#pyo3_path::impl_::pymethods::PyMethodDefType::Setter(
793-
#pyo3_path::impl_::pymethods::PySetterDef::new(
794-
#python_name,
795-
#cls::#wrapper_ident,
796-
#doc
797-
)
787+
#pyo3_path::impl_::pymethods::PyMethodDefType::Setter(
788+
#pyo3_path::impl_::pymethods::PySetterDef::new(
789+
#python_name,
790+
#cls::#wrapper_ident,
791+
#doc
798792
)
799793
)
800794
};
@@ -862,33 +856,21 @@ pub fn impl_py_getter_def(
862856
syn::Index::from(field_index).to_token_stream()
863857
};
864858

865-
// TODO: on MSRV 1.77+, we can use `::std::mem::offset_of!` here, and it should
866-
// make it possible for the `MaybeRuntimePyMethodDef` to be a `Static` variant.
867859
let generator = quote_spanned! { ty.span() =>
868-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Runtime(
869-
|| GENERATOR.generate(#python_name, #doc)
870-
)
860+
GENERATOR.generate(#python_name, #doc)
871861
};
872-
// This is separate so that the unsafe below does not inherit the span and thus does not
862+
// This is separate from `generator` so that the unsafe below does not inherit the span and thus does not
873863
// trigger the `unsafe_code` lint
874864
let method_def = quote! {
875865
#cfg_attrs
876866
{
877867
#[allow(unused_imports)] // might not be used if all probes are positive
878868
use #pyo3_path::impl_::pyclass::Probe as _;
879869

880-
struct Offset;
881-
unsafe impl #pyo3_path::impl_::pyclass::OffsetCalculator<#cls, #ty> for Offset {
882-
fn offset() -> usize {
883-
#pyo3_path::impl_::pyclass::class_offset::<#cls>() +
884-
#pyo3_path::impl_::pyclass::offset_of!(#cls, #field)
885-
}
886-
}
887-
888870
const GENERATOR: #pyo3_path::impl_::pyclass::PyClassGetterGenerator::<
889871
#cls,
890872
#ty,
891-
Offset,
873+
{ ::std::mem::offset_of!(#cls, #field) },
892874
{ #pyo3_path::impl_::pyclass::IsPyT::<#ty>::VALUE },
893875
{ #pyo3_path::impl_::pyclass::IsIntoPyObjectRef::<#ty>::VALUE },
894876
{ #pyo3_path::impl_::pyclass::IsIntoPyObject::<#ty>::VALUE },
@@ -930,13 +912,11 @@ pub fn impl_py_getter_def(
930912

931913
let method_def = quote! {
932914
#cfg_attrs
933-
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
934-
#pyo3_path::impl_::pymethods::PyMethodDefType::Getter(
935-
#pyo3_path::impl_::pymethods::PyGetterDef::new(
936-
#python_name,
937-
#cls::#wrapper_ident,
938-
#doc
939-
)
915+
#pyo3_path::impl_::pymethods::PyMethodDefType::Getter(
916+
#pyo3_path::impl_::pymethods::PyGetterDef::new(
917+
#python_name,
918+
#cls::#wrapper_ident,
919+
#doc
940920
)
941921
)
942922
};

0 commit comments

Comments
 (0)