Skip to content

Commit

Permalink
update bindings, fix a bug in BasicString
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlie Davis committed May 17, 2024
1 parent 2660c7e commit a7786b4
Show file tree
Hide file tree
Showing 688 changed files with 65,635 additions and 65,574 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
run: rustup component add clippy
- name: Fix environment
uses: ./.github/actions/fix-environment
- name: Clippy no_std
run: cargo clippy -p no_std
- name: Clippy riddle
run: cargo clippy -p riddle
- name: Clippy sample_bits
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
uses: ./.github/actions/fix-environment
- name: Clean
run: cargo clean
- name: Test no_std
run: cargo test -p no_std --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test riddle
run: cargo test -p riddle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_bits
Expand Down Expand Up @@ -154,10 +156,10 @@ jobs:
run: cargo test -p test_array --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_bcrypt
run: cargo test -p test_bcrypt --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_bstr
run: cargo test -p test_bstr --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_bstr
run: cargo test -p test_bstr --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_calling_convention
run: cargo test -p test_calling_convention --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_cfg_generic
Expand Down Expand Up @@ -256,10 +258,10 @@ jobs:
run: cargo test -p test_sys --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_targets
run: cargo test -p test_targets --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_unions
run: cargo test -p test_unions --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_unions
run: cargo test -p test_unions --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_variant
run: cargo test -p test_variant --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_wdk
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ version = "0.56.0"
path = "../bindgen"

[features]
# default = ["std"]
default = ["std"]
std = []
3 changes: 1 addition & 2 deletions crates/libs/core/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::*;
use core::marker::PhantomData;
use core::mem::{transmute_copy, size_of};
use core::mem::{size_of, transmute_copy};
use core::ptr::null_mut;
use core::sync::*;
use std::sync::Mutex;

/// A type that you can use to declare and implement an event of a specified delegate type.
Expand Down
210 changes: 105 additions & 105 deletions crates/libs/core/src/imp/com_bindings.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/libs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
#![doc(html_no_source)]
#![allow(non_snake_case, unexpected_cfgs)]
#![cfg_attr(windows_debugger_visualizer, debugger_visualizer(natvis_file = "../.natvis"))]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]

extern crate self as windows_core;

#[macro_use]
extern crate alloc;
use alloc::vec;
// use alloc::vec;

use alloc::{boxed::Box, string::String, vec::Vec};

Expand Down
4 changes: 4 additions & 0 deletions crates/libs/result/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ readme = "readme.md"
categories = ["os::windows-apis"]
exclude = ["tests"]

[features]
default = ["std"]
std = []

[lints]
workspace = true

Expand Down
6 changes: 3 additions & 3 deletions crates/libs/result/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ macro_rules! com_call {
}

#[repr(transparent)]
pub struct ComPtr(std::ptr::NonNull<std::ffi::c_void>);
pub struct ComPtr(core::ptr::NonNull<core::ffi::c_void>);

impl ComPtr {
pub fn as_raw(&self) -> *mut std::ffi::c_void {
unsafe { std::mem::transmute_copy(self) }
pub fn as_raw(&self) -> *mut core::ffi::c_void {
unsafe { core::mem::transmute_copy(self) }
}

pub fn cast(&self, iid: &GUID) -> Option<Self> {
Expand Down
32 changes: 18 additions & 14 deletions crates/libs/result/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use core::ffi::c_void;

/// An error object consists of both an error code as well as detailed error information for debugging.
#[derive(Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -94,13 +95,14 @@ impl Error {
}

/// The error object describing the error.
pub fn as_ptr(&self) -> *mut std::ffi::c_void {
pub fn as_ptr(&self) -> *mut c_void {
self.info
.as_ref()
.map_or(std::ptr::null_mut(), |info| info.as_raw())
.map_or(core::ptr::null_mut(), |info| info.as_raw())
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
unsafe impl Send for Error {}
unsafe impl Sync for Error {}
Expand All @@ -124,12 +126,14 @@ impl From<HRESULT> for Error {
}
}

#[cfg(feature = "std")]
impl From<Error> for std::io::Error {
fn from(from: Error) -> Self {
Self::from_raw_os_error(from.code.0)
}
}

#[cfg(feature = "std")]
impl From<std::io::Error> for Error {
fn from(from: std::io::Error) -> Self {
match from.raw_os_error() {
Expand All @@ -139,35 +143,35 @@ impl From<std::io::Error> for Error {
}
}

impl From<std::string::FromUtf16Error> for Error {
fn from(_: std::string::FromUtf16Error) -> Self {
impl From<alloc::string::FromUtf16Error> for Error {
fn from(_: alloc::string::FromUtf16Error) -> Self {
Self {
code: HRESULT::from_win32(ERROR_NO_UNICODE_TRANSLATION),
info: None,
}
}
}

impl From<std::string::FromUtf8Error> for Error {
fn from(_: std::string::FromUtf8Error) -> Self {
impl From<alloc::string::FromUtf8Error> for Error {
fn from(_: alloc::string::FromUtf8Error) -> Self {
Self {
code: HRESULT::from_win32(ERROR_NO_UNICODE_TRANSLATION),
info: None,
}
}
}

impl From<std::num::TryFromIntError> for Error {
fn from(_: std::num::TryFromIntError) -> Self {
impl From<core::num::TryFromIntError> for Error {
fn from(_: core::num::TryFromIntError) -> Self {
Self {
code: HRESULT::from_win32(ERROR_INVALID_DATA),
info: None,
}
}
}

impl std::fmt::Debug for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for Error {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut debug = fmt.debug_struct("Error");
debug
.field("code", &self.code)
Expand All @@ -176,13 +180,13 @@ impl std::fmt::Debug for Error {
}
}

impl std::fmt::Display for Error {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Display for Error {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let message = self.message();
if message.is_empty() {
std::write!(fmt, "{}", self.code())
core::write!(fmt, "{}", self.code())
} else {
std::write!(fmt, "{} ({})", self.message(), self.code())
core::write!(fmt, "{} ({})", self.message(), self.code())
}
}
}
12 changes: 6 additions & 6 deletions crates/libs/result/src/hresult.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ impl HRESULT {
0,
&mut message.0 as *mut _ as *mut _,
0,
std::ptr::null(),
core::ptr::null(),
);

if !message.0.is_null() && size > 0 {
String::from_utf16_lossy(wide_trim_end(std::slice::from_raw_parts(
String::from_utf16_lossy(wide_trim_end(core::slice::from_raw_parts(
message.0,
size as usize,
)))
Expand Down Expand Up @@ -130,14 +130,14 @@ impl<T> From<Result<T>> for HRESULT {
}
}

impl std::fmt::Display for HRESULT {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Display for HRESULT {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!("{:#010X}", self.0))
}
}

impl std::fmt::Debug for HRESULT {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for HRESULT {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!("HRESULT({})", self))
}
}
8 changes: 7 additions & 1 deletion crates/libs/result/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs
windows_debugger_visualizer,
debugger_visualizer(natvis_file = "../.natvis")
)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]

extern crate alloc;

use alloc::string::String;
use alloc::vec::Vec;

mod bindings;
use bindings::*;
Expand All @@ -24,4 +30,4 @@ mod hresult;
pub use hresult::HRESULT;

/// A specialized [`Result`] type that provides Windows error information.
pub type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = core::result::Result<T, Error>;
11 changes: 8 additions & 3 deletions crates/libs/result/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct HeapString(pub *mut u16);

impl Default for HeapString {
fn default() -> Self {
Self(std::ptr::null_mut())
Self(core::ptr::null_mut())
}
}

Expand Down Expand Up @@ -35,7 +35,12 @@ impl BasicString {
}

pub fn as_wide(&self) -> &[u16] {
unsafe { std::slice::from_raw_parts(self.as_ptr(), self.len()) }
let len = self.len();
if len != 0 {
unsafe { core::slice::from_raw_parts(self.as_ptr(), len) }
} else {
&[]
}
}

pub fn as_ptr(&self) -> *const u16 {
Expand All @@ -50,7 +55,7 @@ impl BasicString {

impl Default for BasicString {
fn default() -> Self {
Self(std::ptr::null_mut())
Self(core::ptr::null_mut())
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/libs/windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ windows-core = { path = "../core", version = "0.56.0" }
windows-targets = { path = "../targets", version = "0.52.5" }

[features]
default = []
default = ["std"]
docs = []
deprecated = []
implement = []
std = ["windows-core/std"]
# generated features
AI = ["Foundation"]
AI_MachineLearning = ["AI"]
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/windows/src/Windows/AI/MachineLearning/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl windows_core::RuntimeName for ILearningModelFeatureDescriptor {
}
impl ILearningModelFeatureDescriptor_Vtbl {
pub const fn new<Identity: windows_core::IUnknownImpl<Impl = Impl>, Impl: ILearningModelFeatureDescriptor_Impl, const OFFSET: isize>() -> ILearningModelFeatureDescriptor_Vtbl {
unsafe extern "system" fn Name<Identity: windows_core::IUnknownImpl<Impl = Impl>, Impl: ILearningModelFeatureDescriptor_Impl, const OFFSET: isize>(this: *mut core::ffi::c_void, result__: *mut std::mem::MaybeUninit<windows_core::HSTRING>) -> windows_core::HRESULT {
unsafe extern "system" fn Name<Identity: windows_core::IUnknownImpl<Impl = Impl>, Impl: ILearningModelFeatureDescriptor_Impl, const OFFSET: isize>(this: *mut core::ffi::c_void, result__: *mut core::mem::MaybeUninit<windows_core::HSTRING>) -> windows_core::HRESULT {
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
let this = (*this).get_impl();
match ILearningModelFeatureDescriptor_Impl::Name(this) {
Expand All @@ -21,7 +21,7 @@ impl ILearningModelFeatureDescriptor_Vtbl {
Err(err) => err.into(),
}
}
unsafe extern "system" fn Description<Identity: windows_core::IUnknownImpl<Impl = Impl>, Impl: ILearningModelFeatureDescriptor_Impl, const OFFSET: isize>(this: *mut core::ffi::c_void, result__: *mut std::mem::MaybeUninit<windows_core::HSTRING>) -> windows_core::HRESULT {
unsafe extern "system" fn Description<Identity: windows_core::IUnknownImpl<Impl = Impl>, Impl: ILearningModelFeatureDescriptor_Impl, const OFFSET: isize>(this: *mut core::ffi::c_void, result__: *mut core::mem::MaybeUninit<windows_core::HSTRING>) -> windows_core::HRESULT {
let this = (this as *const *const ()).offset(OFFSET) as *const Identity;
let this = (*this).get_impl();
match ILearningModelFeatureDescriptor_Impl::Description(this) {
Expand Down
Loading

0 comments on commit a7786b4

Please sign in to comment.