Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 8 additions & 2 deletions crates/libs/bindgen/src/types/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ impl Method {
quote! { core::slice::from_raw_parts(core::mem::transmute_copy(&#name), #abi_size_name as usize) }
} else if param.is_primitive(reader) {
quote! { #name }
} else if param.is_const_ref() || param.is_interface() || matches!(&param.ty, Type::Generic(_)) {
} else if param.is_const_ref() || param.is_interface() {
quote! { core::mem::transmute_copy(&#name) }
} else if let Type::Generic(g) = &param.ty {
let type_name = to_ident(g.name());
quote! { <#type_name as windows_core::Type<#type_name>>::abi_to_generic(&#name) }
} else {
quote! { core::mem::transmute(&#name) }
}
Expand Down Expand Up @@ -150,9 +153,12 @@ impl Method {
quote! { &[#default_type] }
} else if p.is_primitive(config.reader) {
quote! { #default_type }
} else if p.is_interface() || matches!(&p.ty, Type::Generic(_)) {
} else if p.is_interface() {
let type_name = p.write_name(config);
quote! { windows_core::Ref<#type_name> }
} else if matches!(&p.ty, Type::Generic(_)) {
let type_name = p.write_name(config);
quote! { windows_core::Generic<'_, #type_name> }
} else {
quote! { &#default_type }
}
Expand Down
70 changes: 46 additions & 24 deletions crates/libs/collections/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,16 +679,16 @@ where
K: windows_core::RuntimeType + 'static,
V: windows_core::RuntimeType + 'static,
{
fn Lookup(&self, key: windows_core::Ref<K>) -> windows_core::Result<V>;
fn Lookup(&self, key: windows_core::Generic<'_, K>) -> windows_core::Result<V>;
fn Size(&self) -> windows_core::Result<u32>;
fn HasKey(&self, key: windows_core::Ref<K>) -> windows_core::Result<bool>;
fn HasKey(&self, key: windows_core::Generic<'_, K>) -> windows_core::Result<bool>;
fn GetView(&self) -> windows_core::Result<IMapView<K, V>>;
fn Insert(
&self,
key: windows_core::Ref<K>,
value: windows_core::Ref<V>,
key: windows_core::Generic<'_, K>,
value: windows_core::Generic<'_, V>,
) -> windows_core::Result<bool>;
fn Remove(&self, key: windows_core::Ref<K>) -> windows_core::Result<()>;
fn Remove(&self, key: windows_core::Generic<'_, K>) -> windows_core::Result<()>;
fn Clear(&self) -> windows_core::Result<()>;
}
impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'static>
Expand All @@ -708,7 +708,7 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IMap_Impl::Lookup(this, core::mem::transmute_copy(&key)) {
match IMap_Impl::Lookup(this, <K as windows_core::Type<K>>::abi_to_generic(&key)) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
core::mem::forget(ok__);
Expand Down Expand Up @@ -752,7 +752,7 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IMap_Impl::HasKey(this, core::mem::transmute_copy(&key)) {
match IMap_Impl::HasKey(this, <K as windows_core::Type<K>>::abi_to_generic(&key)) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
windows_core::HRESULT(0)
Expand Down Expand Up @@ -799,8 +799,8 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IMap_Impl::Insert(
this,
core::mem::transmute_copy(&key),
core::mem::transmute_copy(&value),
<K as windows_core::Type<K>>::abi_to_generic(&key),
<V as windows_core::Type<V>>::abi_to_generic(&value),
) {
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
Expand All @@ -822,7 +822,7 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IMap_Impl::Remove(this, core::mem::transmute_copy(&key)).into()
IMap_Impl::Remove(this, <K as windows_core::Type<K>>::abi_to_generic(&key)).into()
}
}
unsafe extern "system" fn Clear<
Expand Down Expand Up @@ -1166,9 +1166,9 @@ where
K: windows_core::RuntimeType + 'static,
V: windows_core::RuntimeType + 'static,
{
fn Lookup(&self, key: windows_core::Ref<K>) -> windows_core::Result<V>;
fn Lookup(&self, key: windows_core::Generic<'_, K>) -> windows_core::Result<V>;
fn Size(&self) -> windows_core::Result<u32>;
fn HasKey(&self, key: windows_core::Ref<K>) -> windows_core::Result<bool>;
fn HasKey(&self, key: windows_core::Generic<'_, K>) -> windows_core::Result<bool>;
fn Split(
&self,
first: windows_core::OutRef<IMapView<K, V>>,
Expand All @@ -1192,7 +1192,8 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IMapView_Impl::Lookup(this, core::mem::transmute_copy(&key)) {
match IMapView_Impl::Lookup(this, <K as windows_core::Type<K>>::abi_to_generic(&key))
{
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
core::mem::forget(ok__);
Expand Down Expand Up @@ -1236,7 +1237,8 @@ impl<K: windows_core::RuntimeType + 'static, V: windows_core::RuntimeType + 'sta
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IMapView_Impl::HasKey(this, core::mem::transmute_copy(&key)) {
match IMapView_Impl::HasKey(this, <K as windows_core::Type<K>>::abi_to_generic(&key))
{
Ok(ok__) => {
result__.write(core::mem::transmute_copy(&ok__));
windows_core::HRESULT(0)
Expand Down Expand Up @@ -2121,11 +2123,16 @@ where
fn GetAt(&self, index: u32) -> windows_core::Result<T>;
fn Size(&self) -> windows_core::Result<u32>;
fn GetView(&self) -> windows_core::Result<IVectorView<T>>;
fn IndexOf(&self, value: windows_core::Ref<T>, index: &mut u32) -> windows_core::Result<bool>;
fn SetAt(&self, index: u32, value: windows_core::Ref<T>) -> windows_core::Result<()>;
fn InsertAt(&self, index: u32, value: windows_core::Ref<T>) -> windows_core::Result<()>;
fn IndexOf(
&self,
value: windows_core::Generic<'_, T>,
index: &mut u32,
) -> windows_core::Result<bool>;
fn SetAt(&self, index: u32, value: windows_core::Generic<'_, T>) -> windows_core::Result<()>;
fn InsertAt(&self, index: u32, value: windows_core::Generic<'_, T>)
-> windows_core::Result<()>;
fn RemoveAt(&self, index: u32) -> windows_core::Result<()>;
fn Append(&self, value: windows_core::Ref<T>) -> windows_core::Result<()>;
fn Append(&self, value: windows_core::Generic<'_, T>) -> windows_core::Result<()>;
fn RemoveAtEnd(&self) -> windows_core::Result<()>;
fn Clear(&self) -> windows_core::Result<()>;
fn GetMany(
Expand Down Expand Up @@ -2218,7 +2225,7 @@ impl<T: windows_core::RuntimeType + 'static> IVector_Vtbl<T> {
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IVector_Impl::IndexOf(
this,
core::mem::transmute_copy(&value),
<T as windows_core::Type<T>>::abi_to_generic(&value),
core::mem::transmute_copy(&index),
) {
Ok(ok__) => {
Expand All @@ -2241,7 +2248,12 @@ impl<T: windows_core::RuntimeType + 'static> IVector_Vtbl<T> {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IVector_Impl::SetAt(this, index, core::mem::transmute_copy(&value)).into()
IVector_Impl::SetAt(
this,
index,
<T as windows_core::Type<T>>::abi_to_generic(&value),
)
.into()
}
}
unsafe extern "system" fn InsertAt<
Expand All @@ -2256,7 +2268,12 @@ impl<T: windows_core::RuntimeType + 'static> IVector_Vtbl<T> {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IVector_Impl::InsertAt(this, index, core::mem::transmute_copy(&value)).into()
IVector_Impl::InsertAt(
this,
index,
<T as windows_core::Type<T>>::abi_to_generic(&value),
)
.into()
}
}
unsafe extern "system" fn RemoveAt<
Expand Down Expand Up @@ -2284,7 +2301,8 @@ impl<T: windows_core::RuntimeType + 'static> IVector_Vtbl<T> {
unsafe {
let this: &Identity =
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
IVector_Impl::Append(this, core::mem::transmute_copy(&value)).into()
IVector_Impl::Append(this, <T as windows_core::Type<T>>::abi_to_generic(&value))
.into()
}
}
unsafe extern "system" fn RemoveAtEnd<
Expand Down Expand Up @@ -2666,7 +2684,11 @@ where
{
fn GetAt(&self, index: u32) -> windows_core::Result<T>;
fn Size(&self) -> windows_core::Result<u32>;
fn IndexOf(&self, value: windows_core::Ref<T>, index: &mut u32) -> windows_core::Result<bool>;
fn IndexOf(
&self,
value: windows_core::Generic<'_, T>,
index: &mut u32,
) -> windows_core::Result<bool>;
fn GetMany(
&self,
startIndex: u32,
Expand Down Expand Up @@ -2732,7 +2754,7 @@ impl<T: windows_core::RuntimeType + 'static> IVectorView_Vtbl<T> {
&*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IVectorView_Impl::IndexOf(
this,
core::mem::transmute_copy(&value),
<T as windows_core::Type<T>>::abi_to_generic(&value),
core::mem::transmute_copy(&index),
) {
Ok(ok__) => {
Expand Down
27 changes: 18 additions & 9 deletions crates/libs/collections/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,44 @@ where
K::Default: Clone + Ord,
V::Default: Clone,
{
fn Lookup(&self, key: Ref<K>) -> Result<V> {
fn Lookup(&self, key: Generic<'_, K>) -> Result<V> {
let map = self.map.read().unwrap();
let value = map.get(&*key).ok_or_else(|| Error::from(E_BOUNDS))?;
let value = map
.get(K::generic_as_default(&key))
.ok_or_else(|| Error::from(E_BOUNDS))?;
V::from_default(value)
}

fn Size(&self) -> Result<u32> {
Ok(self.map.read().unwrap().len().try_into()?)
}

fn HasKey(&self, key: Ref<K>) -> Result<bool> {
Ok(self.map.read().unwrap().contains_key(&*key))
fn HasKey(&self, key: Generic<'_, K>) -> Result<bool> {
Ok(self
.map
.read()
.unwrap()
.contains_key(K::generic_as_default(&key)))
}

fn GetView(&self) -> Result<IMapView<K, V>> {
let snapshot = self.map.read().unwrap().clone();
Ok(IMapView::<K, V>::from(snapshot))
}

fn Insert(&self, key: Ref<K>, value: Ref<V>) -> Result<bool> {
fn Insert(&self, key: Generic<'_, K>, value: Generic<'_, V>) -> Result<bool> {
let mut map = self.map.write().unwrap();
let replaced = map.contains_key(&*key);
map.insert((*key).clone(), (*value).clone());
let replaced = map.contains_key(K::generic_as_default(&key));
map.insert(
K::generic_as_default(&key).clone(),
V::generic_as_default(&value).clone(),
);
Ok(replaced)
}

fn Remove(&self, key: Ref<K>) -> Result<()> {
fn Remove(&self, key: Generic<'_, K>) -> Result<()> {
let mut map = self.map.write().unwrap();
if map.remove(&*key).is_none() {
if map.remove(K::generic_as_default(&key)).is_none() {
return Err(Error::from(E_BOUNDS));
}
Ok(())
Expand Down
11 changes: 7 additions & 4 deletions crates/libs/collections/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ where
K::Default: Clone + Ord,
V::Default: Clone,
{
fn Lookup(&self, key: Ref<K>) -> Result<V> {
let value = self.map.get(&*key).ok_or_else(|| Error::from(E_BOUNDS))?;
fn Lookup(&self, key: Generic<'_, K>) -> Result<V> {
let value = self
.map
.get(K::generic_as_default(&key))
.ok_or_else(|| Error::from(E_BOUNDS))?;

V::from_default(value)
}
Expand All @@ -45,8 +48,8 @@ where
Ok(self.map.len().try_into()?)
}

fn HasKey(&self, key: Ref<K>) -> Result<bool> {
Ok(self.map.contains_key(&*key))
fn HasKey(&self, key: Generic<'_, K>) -> Result<bool> {
Ok(self.map.contains_key(K::generic_as_default(&key)))
}

fn Split(&self, first: OutRef<IMapView<K, V>>, second: OutRef<IMapView<K, V>>) -> Result<()> {
Expand Down
31 changes: 20 additions & 11 deletions crates/libs/collections/src/observable_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,55 @@ where
K::Default: Clone + Ord,
V::Default: Clone,
{
fn Lookup(&self, key: Ref<K>) -> Result<V> {
fn Lookup(&self, key: Generic<'_, K>) -> Result<V> {
let map = self.map.read().unwrap();
let value = map.get(&*key).ok_or_else(|| Error::from(E_BOUNDS))?;
let value = map
.get(K::generic_as_default(&key))
.ok_or_else(|| Error::from(E_BOUNDS))?;
V::from_default(value)
}

fn Size(&self) -> Result<u32> {
Ok(self.map.read().unwrap().len().try_into()?)
}

fn HasKey(&self, key: Ref<K>) -> Result<bool> {
Ok(self.map.read().unwrap().contains_key(&*key))
fn HasKey(&self, key: Generic<'_, K>) -> Result<bool> {
Ok(self
.map
.read()
.unwrap()
.contains_key(K::generic_as_default(&key)))
}

fn GetView(&self) -> Result<IMapView<K, V>> {
let snapshot = self.map.read().unwrap().clone();
Ok(IMapView::<K, V>::from(snapshot))
}

fn Insert(&self, key: Ref<K>, value: Ref<V>) -> Result<bool> {
fn Insert(&self, key: Generic<'_, K>, value: Generic<'_, V>) -> Result<bool> {
let replaced = {
let mut map = self.map.write().unwrap();
let replaced = map.contains_key(&*key);
map.insert((*key).clone(), (*value).clone());
let replaced = map.contains_key(K::generic_as_default(&key));
map.insert(
K::generic_as_default(&key).clone(),
V::generic_as_default(&value).clone(),
);
replaced
};
let change = if replaced {
CollectionChange::ItemChanged
} else {
CollectionChange::ItemInserted
};
self.fire_changed(change, Some((*key).clone()));
self.fire_changed(change, Some(K::generic_as_default(&key).clone()));
Ok(replaced)
}

fn Remove(&self, key: Ref<K>) -> Result<()> {
let key_clone = (*key).clone();
fn Remove(&self, key: Generic<'_, K>) -> Result<()> {
let key_clone = K::generic_as_default(&key).clone();
{
let mut map = self.map.write().unwrap();
if map.remove(&*key).is_none() {
if map.remove(K::generic_as_default(&key)).is_none() {
return Err(Error::from(E_BOUNDS));
}
}
Expand Down
Loading
Loading