Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify windows-sys callback generation #1344

Merged
merged 3 commits into from Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 8 additions & 25 deletions crates/deps/gen/src/sys.rs
Expand Up @@ -400,7 +400,7 @@ fn gen_callback(def: &TypeDef, gen: &Gen) -> TokenStream {

quote! {
#cfg
pub type #name = unsafe extern "system" fn(#(#params),*) #return_sig;
pub type #name = ::core::option::Option<unsafe extern "system" fn(#(#params),*) #return_sig>;
}
}

Expand Down Expand Up @@ -434,42 +434,25 @@ fn gen_sys_return_sig(signature: &MethodSignature, gen: &Gen) -> TokenStream {
}

fn gen_sys_sig(sig: &Signature, gen: &Gen) -> TokenStream {
let mut tokens = TokenStream::with_capacity();

for _ in 0..sig.pointers {
if sig.is_const {
tokens.combine(&quote! { *const });
} else {
tokens.combine(&quote! { *mut });
}
}

tokens.combine(&gen_sys_name(&sig.kind, gen));
tokens
gen_sys_param_with_const(sig, gen, sig.is_const)
}

fn gen_sys_param(param: &MethodParam, gen: &Gen) -> TokenStream {
gen_sys_param_with_const(&param.signature, gen, !param.param.flags().output())
}

fn gen_sys_param_with_const(sig: &Signature, gen: &Gen, is_const: bool) -> TokenStream {
let mut tokens = TokenStream::with_capacity();
let is_const = !param.param.flags().output();

for _ in 0..param.signature.pointers {
for _ in 0..sig.pointers {
if is_const {
tokens.combine(&quote! { *const });
} else {
tokens.combine(&quote! { *mut });
}
}

let kind = gen_sys_name(&param.signature.kind, gen);

if param.signature.kind.is_callback() {
tokens.combine(&quote! {
::core::option::Option<#kind>
});
} else {
tokens.combine(&kind)
}

tokens.combine(&gen_sys_name(&sig.kind, gen));
tokens
}

Expand Down
2 changes: 1 addition & 1 deletion crates/deps/sys/src/Windows/Win32/Data/HtmlHelp/mod.rs
Expand Up @@ -512,7 +512,7 @@ pub const IT_HIDDEN: i32 = 2i32;
pub const IT_INCLUSIVE: i32 = 0i32;
pub type IWordBreakerConfig = *mut ::core::ffi::c_void;
pub const MAX_COLUMNS: u32 = 256u32;
pub type PFNCOLHEAPFREE = unsafe extern "system" fn(param0: *mut ::core::ffi::c_void) -> i32;
pub type PFNCOLHEAPFREE = ::core::option::Option<unsafe extern "system" fn(param0: *mut ::core::ffi::c_void) -> i32>;
pub type PRIORITY = i32;
pub const PRIORITY_LOW: PRIORITY = 0i32;
pub const PRIORITY_NORMAL: PRIORITY = 1i32;
Expand Down
10 changes: 5 additions & 5 deletions crates/deps/sys/src/Windows/Win32/Data/RightsManagement/mod.rs
Expand Up @@ -26,7 +26,7 @@ extern "system" {
#[cfg(feature = "Win32_Foundation")]
pub fn DRMCreateBoundLicense(henv: u32, pparams: *mut DRMBOUNDLICENSEPARAMS, wszlicensechain: super::super::Foundation::PWSTR, phboundlicense: *mut u32, pherrorlog: *mut u32) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMCreateClientSession(pfncallback: ::core::option::Option<DRMCALLBACK>, ucallbackversion: u32, wszgroupidprovidertype: super::super::Foundation::PWSTR, wszgroupid: super::super::Foundation::PWSTR, phclient: *mut u32) -> ::windows_sys::core::HRESULT;
pub fn DRMCreateClientSession(pfncallback: DRMCALLBACK, ucallbackversion: u32, wszgroupidprovidertype: super::super::Foundation::PWSTR, wszgroupid: super::super::Foundation::PWSTR, phclient: *mut u32) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMCreateEnablingBitsDecryptor(hboundlicense: u32, wszright: super::super::Foundation::PWSTR, hauxlib: u32, wszauxplug: super::super::Foundation::PWSTR, phdecryptor: *mut u32) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -100,7 +100,7 @@ extern "system" {
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetOwnerLicense(hissuancelicense: u32, puownerlicenselength: *mut u32, wszownerlicense: super::super::Foundation::PWSTR) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetProcAddress(hlibrary: u32, wszprocname: super::super::Foundation::PWSTR, ppfnprocaddress: *mut ::core::option::Option<super::super::Foundation::FARPROC>) -> ::windows_sys::core::HRESULT;
pub fn DRMGetProcAddress(hlibrary: u32, wszprocname: super::super::Foundation::PWSTR, ppfnprocaddress: *mut super::super::Foundation::FARPROC) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetRevocationPoint(hissuancelicense: u32, puidlength: *mut u32, wszid: super::super::Foundation::PWSTR, puidtypelength: *mut u32, wszidtype: super::super::Foundation::PWSTR, puurllength: *mut u32, wszrl: super::super::Foundation::PWSTR, pstfrequency: *mut super::super::Foundation::SYSTEMTIME, punamelength: *mut u32, wszname: super::super::Foundation::PWSTR, pupublickeylength: *mut u32, wszpublickey: super::super::Foundation::PWSTR) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
Expand All @@ -112,9 +112,9 @@ extern "system" {
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetServiceLocation(hclient: u32, uservicetype: u32, uservicelocation: u32, wszissuancelicense: super::super::Foundation::PWSTR, puserviceurllength: *mut u32, wszserviceurl: super::super::Foundation::PWSTR) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetSignedIssuanceLicense(henv: u32, hissuancelicense: u32, uflags: u32, pbsymkey: *mut u8, cbsymkey: u32, wszsymkeytype: super::super::Foundation::PWSTR, wszclientlicensorcertificate: super::super::Foundation::PWSTR, pfncallback: ::core::option::Option<DRMCALLBACK>, wszurl: super::super::Foundation::PWSTR, pvcontext: *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
pub fn DRMGetSignedIssuanceLicense(henv: u32, hissuancelicense: u32, uflags: u32, pbsymkey: *mut u8, cbsymkey: u32, wszsymkeytype: super::super::Foundation::PWSTR, wszclientlicensorcertificate: super::super::Foundation::PWSTR, pfncallback: DRMCALLBACK, wszurl: super::super::Foundation::PWSTR, pvcontext: *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetSignedIssuanceLicenseEx(henv: u32, hissuancelicense: u32, uflags: u32, pbsymkey: *const u8, cbsymkey: u32, wszsymkeytype: super::super::Foundation::PWSTR, pvreserved: *const ::core::ffi::c_void, henablingprincipal: u32, hboundlicenseclc: u32, pfncallback: ::core::option::Option<DRMCALLBACK>, pvcontext: *const ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
pub fn DRMGetSignedIssuanceLicenseEx(henv: u32, hissuancelicense: u32, uflags: u32, pbsymkey: *const u8, cbsymkey: u32, wszsymkeytype: super::super::Foundation::PWSTR, pvreserved: *const ::core::ffi::c_void, henablingprincipal: u32, hboundlicenseclc: u32, pfncallback: DRMCALLBACK, pvcontext: *const ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
pub fn DRMGetTime(henv: u32, etimeridtype: DRMTIMETYPE, potimeobject: *mut super::super::Foundation::SYSTEMTIME) -> ::windows_sys::core::HRESULT;
#[cfg(feature = "Win32_Foundation")]
Expand Down Expand Up @@ -208,7 +208,7 @@ impl ::core::clone::Clone for DRMBOUNDLICENSEPARAMS {
}
}
pub const DRMBOUNDLICENSEPARAMSVERSION: u32 = 1u32;
pub type DRMCALLBACK = unsafe extern "system" fn(param0: DRM_STATUS_MSG, param1: ::windows_sys::core::HRESULT, param2: *mut ::core::ffi::c_void, param3: *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT;
pub type DRMCALLBACK = ::core::option::Option<unsafe extern "system" fn(param0: DRM_STATUS_MSG, param1: ::windows_sys::core::HRESULT, param2: *mut ::core::ffi::c_void, param3: *mut ::core::ffi::c_void) -> ::windows_sys::core::HRESULT>;
pub const DRMCALLBACKVERSION: u32 = 1u32;
pub const DRMCLIENTSTRUCTVERSION: u32 = 1u32;
pub type DRMENCODINGTYPE = i32;
Expand Down