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

Disable most functionality for VARIANT on non-Windows platforms #3101

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions crates/libs/core/src/variant.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(windows), allow(unused_variables))]

use super::*;
use core::mem::transmute;

Expand All @@ -23,30 +25,40 @@ impl Default for PROPVARIANT {

impl Clone for VARIANT {
fn clone(&self) -> Self {
#[cfg(windows)]
unsafe {
let mut value = Self::new();
imp::VariantCopy(&mut value.0, &self.0);
value
}

#[cfg(not(windows))]
unimplemented!();
}
}

impl Clone for PROPVARIANT {
fn clone(&self) -> Self {
#[cfg(windows)]
unsafe {
let mut value = Self::new();
imp::PropVariantCopy(&mut value.0, &self.0);
value
}

#[cfg(not(windows))]
unimplemented!();
}
}

#[cfg(windows)]
impl Drop for VARIANT {
fn drop(&mut self) {
unsafe { imp::VariantClear(&mut self.0) };
}
}

#[cfg(windows)]
impl Drop for PROPVARIANT {
fn drop(&mut self) {
unsafe { imp::PropVariantClear(&mut self.0) };
Expand All @@ -66,6 +78,7 @@ impl core::fmt::Debug for VARIANT {
let mut debug = f.debug_struct("VARIANT");
debug.field("type", &unsafe { self.0.Anonymous.Anonymous.vt });

#[cfg(windows)]
if let Ok(value) = BSTR::try_from(self) {
debug.field("value", &value);
}
Expand All @@ -79,6 +92,7 @@ impl core::fmt::Debug for PROPVARIANT {
let mut debug = f.debug_struct("PROPVARIANT");
debug.field("type", &unsafe { self.0.Anonymous.Anonymous.vt });

#[cfg(windows)]
if let Ok(value) = BSTR::try_from(self) {
debug.field("value", &value);
}
Expand All @@ -87,12 +101,14 @@ impl core::fmt::Debug for PROPVARIANT {
}
}

#[cfg(windows)]
impl core::fmt::Display for VARIANT {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::write!(f, "{}", BSTR::try_from(self).unwrap_or_default())
}
}

#[cfg(windows)]
impl core::fmt::Display for PROPVARIANT {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::write!(f, "{}", BSTR::try_from(self).unwrap_or_default())
Expand All @@ -101,6 +117,7 @@ impl core::fmt::Display for PROPVARIANT {

impl PartialEq for VARIANT {
fn eq(&self, other: &Self) -> bool {
#[cfg(windows)]
unsafe {
if self.0.Anonymous.Anonymous.vt != other.0.Anonymous.Anonymous.vt {
return false;
Expand All @@ -114,18 +131,25 @@ impl PartialEq for VARIANT {
false
}
}

#[cfg(not(windows))]
unimplemented!();
}
}

impl PartialEq for PROPVARIANT {
fn eq(&self, other: &Self) -> bool {
#[cfg(windows)]
unsafe {
if self.0.Anonymous.Anonymous.vt != other.0.Anonymous.Anonymous.vt {
return false;
}

imp::PropVariantCompareEx(&self.0, &other.0, 0, 0) == 0
}

#[cfg(not(windows))]
unimplemented!();
}
}

Expand Down Expand Up @@ -188,6 +212,7 @@ impl PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for PROPVARIANT {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -198,6 +223,7 @@ impl TryFrom<&VARIANT> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for VARIANT {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -316,18 +342,21 @@ impl From<BSTR> for PROPVARIANT {
}
}

#[cfg(windows)]
impl From<&str> for VARIANT {
fn from(value: &str) -> Self {
BSTR::from(value).into()
}
}

#[cfg(windows)]
impl From<&str> for PROPVARIANT {
fn from(value: &str) -> Self {
BSTR::from(value).into()
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for BSTR {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -336,6 +365,7 @@ impl TryFrom<&VARIANT> for BSTR {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for BSTR {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -383,6 +413,7 @@ impl From<bool> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for bool {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -391,6 +422,7 @@ impl TryFrom<&VARIANT> for bool {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for bool {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -501,6 +533,7 @@ impl From<u16> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for u16 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -509,6 +542,7 @@ impl TryFrom<&VARIANT> for u16 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for u16 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -551,6 +585,7 @@ impl From<i16> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for i16 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -559,6 +594,7 @@ impl TryFrom<&VARIANT> for i16 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for i16 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -601,6 +637,7 @@ impl From<u32> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for u32 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -609,6 +646,7 @@ impl TryFrom<&VARIANT> for u32 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for u32 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -651,6 +689,7 @@ impl From<i32> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for i32 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -659,6 +698,7 @@ impl TryFrom<&VARIANT> for i32 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for i32 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -701,6 +741,7 @@ impl From<u64> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for u64 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -709,6 +750,7 @@ impl TryFrom<&VARIANT> for u64 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for u64 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -751,6 +793,7 @@ impl From<i64> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for i64 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -759,6 +802,7 @@ impl TryFrom<&VARIANT> for i64 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for i64 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down Expand Up @@ -835,6 +879,7 @@ impl From<f64> for PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&VARIANT> for f64 {
type Error = Error;
fn try_from(from: &VARIANT) -> Result<Self> {
Expand All @@ -843,6 +888,7 @@ impl TryFrom<&VARIANT> for f64 {
}
}

#[cfg(windows)]
impl TryFrom<&PROPVARIANT> for f64 {
type Error = Error;
fn try_from(from: &PROPVARIANT) -> Result<Self> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::Win32::System::Com::IDispatch;

#[cfg(windows)]
impl From<IDispatch> for windows_core::VARIANT {
fn from(value: IDispatch) -> Self {
unsafe {
Expand All @@ -12,6 +13,7 @@ impl From<IDispatch> for windows_core::VARIANT {
}
}

#[cfg(windows)]
impl From<IDispatch> for windows_core::PROPVARIANT {
fn from(value: IDispatch) -> Self {
unsafe {
Expand All @@ -24,6 +26,7 @@ impl From<IDispatch> for windows_core::PROPVARIANT {
}
}

#[cfg(windows)]
impl TryFrom<&windows_core::VARIANT> for IDispatch {
type Error = windows_core::Error;
fn try_from(from: &windows_core::VARIANT) -> windows_core::Result<Self> {
Expand All @@ -39,6 +42,7 @@ impl TryFrom<&windows_core::VARIANT> for IDispatch {
}
}

#[cfg(windows)]
impl TryFrom<&windows_core::PROPVARIANT> for IDispatch {
type Error = windows_core::Error;
fn try_from(from: &windows_core::PROPVARIANT) -> windows_core::Result<Self> {
Expand Down