Skip to content

Commit

Permalink
Harden method overload support (#3477)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 10, 2025
1 parent 35c31ad commit b8e3197
Show file tree
Hide file tree
Showing 34 changed files with 1,715 additions and 84 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ jobs:
run: cargo clippy -p test_noexcept
- name: Clippy test_not_dll
run: cargo clippy -p test_not_dll
- name: Clippy test_overloads
run: cargo clippy -p test_overloads
- name: Clippy test_overloads_client
run: cargo clippy -p test_overloads_client
- name: Clippy test_query_signature
run: cargo clippy -p test_query_signature
- name: Clippy test_readme
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/raw-dylib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,18 @@ jobs:
run: cargo test -p test_noexcept --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_not_dll
run: cargo test -p test_not_dll --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_overloads
run: cargo test -p test_overloads --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_overloads_client
run: cargo test -p test_overloads_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_query_signature
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_ref_params
run: cargo test -p test_ref_params --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
Expand Down Expand Up @@ -360,12 +364,12 @@ jobs:
run: cargo test -p windows_i686_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_i686_gnullvm
run: cargo test -p windows_i686_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test windows_i686_msvc
run: cargo test -p windows_i686_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_gnu
run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test windows_x86_64_gnullvm
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_msvc
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,18 @@ jobs:
run: cargo test -p test_noexcept --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_not_dll
run: cargo test -p test_not_dll --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_overloads
run: cargo test -p test_overloads --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_overloads_client
run: cargo test -p test_overloads_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_query_signature
run: cargo test -p test_query_signature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_readme
run: cargo test -p test_readme --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_ref_params
run: cargo test -p test_ref_params --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reference
run: cargo test -p test_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_reference_client
Expand Down Expand Up @@ -357,12 +361,12 @@ jobs:
run: cargo test -p windows_i686_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_i686_gnullvm
run: cargo test -p windows_i686_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test windows_i686_msvc
run: cargo test -p windows_i686_msvc --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_gnu
run: cargo test -p windows_x86_64_gnu --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test windows_x86_64_gnullvm
run: cargo test -p windows_x86_64_gnullvm --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test windows_x86_64_msvc
Expand Down
2 changes: 2 additions & 0 deletions crates/libs/bindgen/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::*;
pub struct Filter(Vec<(String, bool)>);

impl Filter {
#[track_caller]
pub fn new(reader: &Reader, include: &[&str], exclude: &[&str]) -> Self {
let mut rules = vec![];

Expand Down Expand Up @@ -68,6 +69,7 @@ impl Filter {
}
}

#[track_caller]
fn push_filter(reader: &Reader, rules: &mut Vec<(String, bool)>, filter: &str, include: bool) {
if reader.contains_key(filter) {
rules.push((filter.to_string(), include));
Expand Down
11 changes: 9 additions & 2 deletions crates/libs/bindgen/src/method_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ fn method_def_special_name(row: MethodDef) -> String {
} else {
if let Some(attribute) = row.find_attribute("OverloadAttribute") {
for (_, arg) in attribute.args() {
if let Value::Str(name) = arg {
return name.to_string();
if let Value::Str(overload) = arg {
// Detect generated overload and revert back to original name.
if let Some(suffix) = overload.strip_prefix(name) {
if suffix.parse::<u32>().is_ok() {
return name.to_string();
}
}

return overload.to_string();
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/libs/bindgen/src/types/cpp_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
#[derive(Clone, Debug)]
pub enum CppMethodOrName {
Method(CppMethod),
Name(&'static str),
Name(MethodDef),
}

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -38,7 +38,7 @@ impl CppInterface {
if method.dependencies.included(writer.config) {
CppMethodOrName::Method(method)
} else {
CppMethodOrName::Name(method.def.name())
CppMethodOrName::Name(method.def)
}
})
.collect()
Expand Down Expand Up @@ -104,8 +104,8 @@ impl CppInterface {
}
}
}
CppMethodOrName::Name(name) => {
let name = to_ident(name);
CppMethodOrName::Name(method) => {
let name = names.add(*method);
quote! { #name: usize, }
}
});
Expand Down Expand Up @@ -256,8 +256,8 @@ impl CppInterface {
quote! { #name: #name::<Identity>, }
}
}
CppMethodOrName::Name(name) => {
let name = to_ident(name);
CppMethodOrName::Name(method) => {
let name = names.add(*method);
quote! { #name: 0, }
}
})
Expand Down
12 changes: 6 additions & 6 deletions crates/libs/bindgen/src/types/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum InterfaceKind {
#[derive(Clone, Debug)]
pub enum MethodOrName {
Method(Method),
Name(&'static str),
Name(MethodDef),
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Interface {
if method.dependencies.included(writer.config) {
MethodOrName::Method(method)
} else {
MethodOrName::Name(method.def.name())
MethodOrName::Name(method.def)
}
})
.collect()
Expand Down Expand Up @@ -120,8 +120,8 @@ impl Interface {
}
}
}
MethodOrName::Name(name) => {
let name = to_ident(name);
MethodOrName::Name(method) => {
let name = virtual_names.add(*method);
quote! { #name: usize, }
}
});
Expand Down Expand Up @@ -373,8 +373,8 @@ impl Interface {
let name = names.add(method.def);
quote! { #name: #name::<#(#generics,)* Identity, OFFSET>, }
}
MethodOrName::Name(name) => {
let name = to_ident(name);
MethodOrName::Name(method) => {
let name = names.add(*method);
quote! { #name: 0, }
}
})
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/windows/src/Windows/ApplicationModel/Chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,11 @@ impl ChatMessageStore {
(windows_core::Interface::vtable(this).GetMessageAsync)(windows_core::Interface::as_raw(this), core::mem::transmute_copy(localchatmessageid), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
}
}
pub fn GetMessageReader1(&self) -> windows_core::Result<ChatMessageReader> {
pub fn GetMessageReader(&self) -> windows_core::Result<ChatMessageReader> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).GetMessageReader1)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
(windows_core::Interface::vtable(this).GetMessageReader)(windows_core::Interface::as_raw(this), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
}
}
pub fn GetMessageReader2(&self, recenttimelimit: super::super::Foundation::TimeSpan) -> windows_core::Result<ChatMessageReader> {
Expand Down Expand Up @@ -2497,7 +2497,7 @@ pub struct IChatMessageStore_Vtbl {
pub DeleteMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub DownloadMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub GetMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub GetMessageReader1: unsafe extern "system" fn(*mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub GetMessageReader: unsafe extern "system" fn(*mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub GetMessageReader2: unsafe extern "system" fn(*mut core::ffi::c_void, super::super::Foundation::TimeSpan, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub MarkMessageReadAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub RetrySendMessageAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ impl DnssdServiceInstance {
}
}
#[cfg(feature = "Networking_Sockets")]
pub fn RegisterStreamSocketListenerAsync1<P0>(&self, socket: P0) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<DnssdRegistrationResult>>
pub fn RegisterStreamSocketListenerAsync<P0>(&self, socket: P0) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<DnssdRegistrationResult>>
where
P0: windows_core::Param<super::super::Sockets::StreamSocketListener>,
{
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).RegisterStreamSocketListenerAsync1)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
(windows_core::Interface::vtable(this).RegisterStreamSocketListenerAsync)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
}
}
#[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))]
Expand All @@ -163,14 +163,14 @@ impl DnssdServiceInstance {
}
}
#[cfg(feature = "Networking_Sockets")]
pub fn RegisterDatagramSocketAsync1<P0>(&self, socket: P0) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<DnssdRegistrationResult>>
pub fn RegisterDatagramSocketAsync<P0>(&self, socket: P0) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<DnssdRegistrationResult>>
where
P0: windows_core::Param<super::super::Sockets::DatagramSocket>,
{
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).RegisterDatagramSocketAsync1)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
(windows_core::Interface::vtable(this).RegisterDatagramSocketAsync)(windows_core::Interface::as_raw(this), socket.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
}
}
#[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))]
Expand Down Expand Up @@ -425,17 +425,17 @@ pub struct IDnssdServiceInstance_Vtbl {
#[cfg(not(feature = "Foundation_Collections"))]
TextAttributes: usize,
#[cfg(feature = "Networking_Sockets")]
pub RegisterStreamSocketListenerAsync1: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub RegisterStreamSocketListenerAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
#[cfg(not(feature = "Networking_Sockets"))]
RegisterStreamSocketListenerAsync1: usize,
RegisterStreamSocketListenerAsync: usize,
#[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))]
pub RegisterStreamSocketListenerAsync2: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
#[cfg(not(all(feature = "Networking_Connectivity", feature = "Networking_Sockets")))]
RegisterStreamSocketListenerAsync2: usize,
#[cfg(feature = "Networking_Sockets")]
pub RegisterDatagramSocketAsync1: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub RegisterDatagramSocketAsync: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
#[cfg(not(feature = "Networking_Sockets"))]
RegisterDatagramSocketAsync1: usize,
RegisterDatagramSocketAsync: usize,
#[cfg(all(feature = "Networking_Connectivity", feature = "Networking_Sockets"))]
pub RegisterDatagramSocketAsync2: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut core::ffi::c_void, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
#[cfg(not(all(feature = "Networking_Connectivity", feature = "Networking_Sockets")))]
Expand Down
10 changes: 5 additions & 5 deletions crates/libs/windows/src/Windows/UI/Input/Inking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ pub struct IInkManager_Vtbl {
pub ProcessPointerUp: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void, *mut super::super::super::Foundation::Rect) -> windows_core::HRESULT,
pub SetDefaultDrawingAttributes: unsafe extern "system" fn(*mut core::ffi::c_void, *mut core::ffi::c_void) -> windows_core::HRESULT,
#[cfg(feature = "Foundation_Collections")]
pub RecognizeAsync2: unsafe extern "system" fn(*mut core::ffi::c_void, InkRecognitionTarget, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
pub RecognizeAsync: unsafe extern "system" fn(*mut core::ffi::c_void, InkRecognitionTarget, *mut *mut core::ffi::c_void) -> windows_core::HRESULT,
#[cfg(not(feature = "Foundation_Collections"))]
RecognizeAsync2: usize,
RecognizeAsync: usize,
}
windows_core::imp::define_interface!(IInkModelerAttributes, IInkModelerAttributes_Vtbl, 0xbad31f27_0cd9_4bfd_b6f3_9e03ba8d7454);
impl windows_core::RuntimeType for IInkModelerAttributes {
Expand Down Expand Up @@ -1749,11 +1749,11 @@ impl InkManager {
unsafe { (windows_core::Interface::vtable(this).SetDefaultDrawingAttributes)(windows_core::Interface::as_raw(this), drawingattributes.param().abi()).ok() }
}
#[cfg(feature = "Foundation_Collections")]
pub fn RecognizeAsync2(&self, recognitiontarget: InkRecognitionTarget) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<super::super::super::Foundation::Collections::IVectorView<InkRecognitionResult>>> {
pub fn RecognizeAsync(&self, recognitiontarget: InkRecognitionTarget) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<super::super::super::Foundation::Collections::IVectorView<InkRecognitionResult>>> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).RecognizeAsync2)(windows_core::Interface::as_raw(this), recognitiontarget, &mut result__).and_then(|| windows_core::Type::from_abi(result__))
(windows_core::Interface::vtable(this).RecognizeAsync)(windows_core::Interface::as_raw(this), recognitiontarget, &mut result__).and_then(|| windows_core::Type::from_abi(result__))
}
}
pub fn SetDefaultRecognizer<P0>(&self, recognizer: P0) -> windows_core::Result<()>
Expand All @@ -1764,7 +1764,7 @@ impl InkManager {
unsafe { (windows_core::Interface::vtable(this).SetDefaultRecognizer)(windows_core::Interface::as_raw(this), recognizer.param().abi()).ok() }
}
#[cfg(feature = "Foundation_Collections")]
pub fn RecognizeAsync<P0>(&self, strokecollection: P0, recognitiontarget: InkRecognitionTarget) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<super::super::super::Foundation::Collections::IVectorView<InkRecognitionResult>>>
pub fn RecognizeAsync2<P0>(&self, strokecollection: P0, recognitiontarget: InkRecognitionTarget) -> windows_core::Result<super::super::super::Foundation::IAsyncOperation<super::super::super::Foundation::Collections::IVectorView<InkRecognitionResult>>>
where
P0: windows_core::Param<InkStrokeContainer>,
{
Expand Down
12 changes: 6 additions & 6 deletions crates/tests/bindgen/src/interface_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl IAsyncInfo_Vtbl {
Self {
base__: windows_core::IInspectable_Vtbl::new::<Identity, IAsyncInfo, OFFSET>(),
Id: Id::<Identity, OFFSET>,
get_Status: 0,
Status: 0,
ErrorCode: ErrorCode::<Identity, OFFSET>,
Cancel: Cancel::<Identity, OFFSET>,
Close: Close::<Identity, OFFSET>,
Expand All @@ -136,7 +136,7 @@ impl IAsyncInfo_Vtbl {
pub struct IAsyncInfo_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub Id: unsafe extern "system" fn(*mut core::ffi::c_void, *mut u32) -> windows_core::HRESULT,
get_Status: usize,
Status: usize,
pub ErrorCode: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut windows_core::HRESULT,
Expand Down Expand Up @@ -269,8 +269,8 @@ impl<TResult: windows_core::RuntimeType + 'static> IAsyncOperation_Vtbl<TResult>
IAsyncOperation<TResult>,
OFFSET,
>(),
put_Completed: 0,
get_Completed: 0,
SetCompleted: 0,
Completed: 0,
GetResults: GetResults::<TResult, Identity, OFFSET>,
TResult: core::marker::PhantomData::<TResult>,
}
Expand All @@ -285,8 +285,8 @@ where
TResult: windows_core::RuntimeType + 'static,
{
pub base__: windows_core::IInspectable_Vtbl,
put_Completed: usize,
get_Completed: usize,
SetCompleted: usize,
Completed: usize,
pub GetResults: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut windows_core::AbiType<TResult>,
Expand Down
Loading

0 comments on commit b8e3197

Please sign in to comment.