Skip to content

Commit

Permalink
windows-bindgen should generate no_std bindings by default (#3366)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Dec 9, 2024
1 parent 8fb1736 commit f95580d
Show file tree
Hide file tree
Showing 54 changed files with 216 additions and 347 deletions.
5 changes: 1 addition & 4 deletions crates/libs/bindgen/src/types/cpp_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,17 @@ impl CppInterface {
}
}
}
#[cfg(feature = "std")]
#cfg
struct #implvtbl_ident<T: #impl_name> (core::marker::PhantomData<T>);
#[cfg(feature = "std")]
#cfg
impl<T: #impl_name> #implvtbl_ident<T> {
const VTABLE: #vtbl_name = #vtbl_name::new::<T>();
}
#[cfg(feature = "std")]
#cfg
impl #name {
pub fn new<'a, T: #impl_name>(this: &'a T) -> windows_core::ScopedInterface<'a, Self> {
let this = windows_core::ScopedHeap { vtable: &#implvtbl_ident::<T>::VTABLE as *const _ as *const _, this: this as *const _ as *const _ };
let this = core::mem::ManuallyDrop::new(Box::new(this));
let this = core::mem::ManuallyDrop::new(windows_core::imp::Box::new(this));
unsafe { windows_core::ScopedInterface::new(core::mem::transmute(&this.vtable)) }
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/types/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Delegate {
invoke,
};
unsafe {
core::mem::transmute(Box::new(com))
core::mem::transmute(windows_core::imp::Box::new(com))
}
}
#invoke
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Delegate {
let remaining = (*this).count.release();

if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}

remaining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ impl windows_core::RuntimeType for BackgroundTaskCanceledEventHandler {
impl BackgroundTaskCanceledEventHandler {
pub fn new<F: FnMut(Option<&IBackgroundTaskInstance>, BackgroundTaskCancellationReason) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = BackgroundTaskCanceledEventHandlerBox { vtable: &BackgroundTaskCanceledEventHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0>(&self, sender: P0, reason: BackgroundTaskCancellationReason) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -628,7 +628,7 @@ impl<F: FnMut(Option<&IBackgroundTaskInstance>, BackgroundTaskCancellationReason
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down Expand Up @@ -696,7 +696,7 @@ impl windows_core::RuntimeType for BackgroundTaskCompletedEventHandler {
impl BackgroundTaskCompletedEventHandler {
pub fn new<F: FnMut(Option<&BackgroundTaskRegistration>, Option<&BackgroundTaskCompletedEventArgs>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = BackgroundTaskCompletedEventHandlerBox { vtable: &BackgroundTaskCompletedEventHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, sender: P0, args: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -741,7 +741,7 @@ impl<F: FnMut(Option<&BackgroundTaskRegistration>, Option<&BackgroundTaskComplet
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down Expand Up @@ -811,7 +811,7 @@ impl windows_core::RuntimeType for BackgroundTaskProgressEventHandler {
impl BackgroundTaskProgressEventHandler {
pub fn new<F: FnMut(Option<&BackgroundTaskRegistration>, Option<&BackgroundTaskProgressEventArgs>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = BackgroundTaskProgressEventHandlerBox { vtable: &BackgroundTaskProgressEventHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, sender: P0, args: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -856,7 +856,7 @@ impl<F: FnMut(Option<&BackgroundTaskRegistration>, Option<&BackgroundTaskProgres
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ impl windows_core::RuntimeType for DataProviderHandler {
impl DataProviderHandler {
pub fn new<F: FnMut(Option<&DataProviderRequest>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = DataProviderHandlerBox { vtable: &DataProviderHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0>(&self, request: P0) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -1204,7 +1204,7 @@ impl<F: FnMut(Option<&DataProviderRequest>) -> windows_core::Result<()> + Send +
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down Expand Up @@ -2274,7 +2274,7 @@ impl windows_core::RuntimeType for ShareProviderHandler {
impl ShareProviderHandler {
pub fn new<F: FnMut(Option<&ShareProviderOperation>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = ShareProviderHandlerBox { vtable: &ShareProviderHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0>(&self, operation: P0) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -2318,7 +2318,7 @@ impl<F: FnMut(Option<&ShareProviderOperation>) -> windows_core::Result<()> + Sen
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ impl windows_core::RuntimeType for PaymentRequestChangedHandler {
impl PaymentRequestChangedHandler {
pub fn new<F: FnMut(Option<&PaymentRequest>, Option<&PaymentRequestChangedArgs>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = PaymentRequestChangedHandlerBox { vtable: &PaymentRequestChangedHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, paymentrequest: P0, args: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -1476,7 +1476,7 @@ impl<F: FnMut(Option<&PaymentRequest>, Option<&PaymentRequestChangedArgs>) -> wi
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/windows/src/Windows/Data/Text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl windows_core::RuntimeType for SelectableWordSegmentsTokenizingHandler {
impl SelectableWordSegmentsTokenizingHandler {
pub fn new<F: FnMut(Option<&super::super::Foundation::Collections::IIterable<SelectableWordSegment>>, Option<&super::super::Foundation::Collections::IIterable<SelectableWordSegment>>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = SelectableWordSegmentsTokenizingHandlerBox { vtable: &SelectableWordSegmentsTokenizingHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, precedingwords: P0, words: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -403,7 +403,7 @@ impl<F: FnMut(Option<&super::super::Foundation::Collections::IIterable<Selectabl
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down Expand Up @@ -1034,7 +1034,7 @@ impl windows_core::RuntimeType for WordSegmentsTokenizingHandler {
impl WordSegmentsTokenizingHandler {
pub fn new<F: FnMut(Option<&super::super::Foundation::Collections::IIterable<WordSegment>>, Option<&super::super::Foundation::Collections::IIterable<WordSegment>>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = WordSegmentsTokenizingHandlerBox { vtable: &WordSegmentsTokenizingHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, precedingwords: P0, words: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -1082,7 +1082,7 @@ impl<F: FnMut(Option<&super::super::Foundation::Collections::IIterable<WordSegme
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/windows/src/Windows/Devices/SmartCards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,7 @@ impl windows_core::RuntimeType for SmartCardPinResetHandler {
impl SmartCardPinResetHandler {
pub fn new<F: FnMut(Option<&SmartCardProvisioning>, Option<&SmartCardPinResetRequest>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = SmartCardPinResetHandlerBox { vtable: &SmartCardPinResetHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, sender: P0, request: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -2941,7 +2941,7 @@ impl<F: FnMut(Option<&SmartCardProvisioning>, Option<&SmartCardPinResetRequest>)
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/windows/src/Windows/Devices/Sms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ impl windows_core::RuntimeType for SmsDeviceStatusChangedEventHandler {
impl SmsDeviceStatusChangedEventHandler {
pub fn new<F: FnMut(Option<&SmsDevice>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = SmsDeviceStatusChangedEventHandlerBox { vtable: &SmsDeviceStatusChangedEventHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0>(&self, sender: P0) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -2240,7 +2240,7 @@ impl<F: FnMut(Option<&SmsDevice>) -> windows_core::Result<()> + Send + 'static>
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down Expand Up @@ -2574,7 +2574,7 @@ impl windows_core::RuntimeType for SmsMessageReceivedEventHandler {
impl SmsMessageReceivedEventHandler {
pub fn new<F: FnMut(Option<&SmsDevice>, Option<&SmsMessageReceivedEventArgs>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = SmsMessageReceivedEventHandlerBox { vtable: &SmsMessageReceivedEventHandlerBox::<F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, sender: P0, e: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -2622,7 +2622,7 @@ impl<F: FnMut(Option<&SmsDevice>, Option<&SmsMessageReceivedEventArgs>) -> windo
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
8 changes: 4 additions & 4 deletions crates/libs/windows/src/Windows/Foundation/Collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'static> MapChangedEventHandler<K, V> {
pub fn new<F: FnMut(Option<&IObservableMap<K, V>>, Option<&IMapChangedEventArgs<K>>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = MapChangedEventHandlerBox { vtable: &MapChangedEventHandlerBox::<K, V, F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, sender: P0, event: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -1758,7 +1758,7 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down Expand Up @@ -2100,7 +2100,7 @@ impl<T: windows_core::RuntimeType + 'static> windows_core::RuntimeType for Vecto
impl<T: windows_core::RuntimeType + 'static> VectorChangedEventHandler<T> {
pub fn new<F: FnMut(Option<&IObservableVector<T>>, Option<&IVectorChangedEventArgs>) -> windows_core::Result<()> + Send + 'static>(invoke: F) -> Self {
let com = VectorChangedEventHandlerBox { vtable: &VectorChangedEventHandlerBox::<T, F>::VTABLE, count: windows_core::imp::RefCount::new(1), invoke };
unsafe { core::mem::transmute(Box::new(com)) }
unsafe { core::mem::transmute(windows_core::imp::Box::new(com)) }
}
pub fn Invoke<P0, P1>(&self, sender: P0, event: P1) -> windows_core::Result<()>
where
Expand Down Expand Up @@ -2156,7 +2156,7 @@ impl<T: windows_core::RuntimeType + 'static, F: FnMut(Option<&IObservableVector<
let this = this as *mut *mut core::ffi::c_void as *mut Self;
let remaining = (*this).count.release();
if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}
remaining
}
Expand Down
Loading

0 comments on commit f95580d

Please sign in to comment.