functionalscript 0.0.412 → 0.0.413
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/com/rust/nanocom/Cargo.toml +7 -2
- package/com/rust/nanocom/rstest/src/lib.rs +85 -3
- package/com/rust/nanocom/src/class.rs +2 -2
- package/com/rust/nanocom/src/cobject.rs +5 -8
- package/com/rust/nanocom/src/interface.rs +4 -0
- package/com/rust/nanocom/src/iunknown.rs +11 -5
- package/com/rust/nanocom/src/lib.rs +2 -3
- package/com/rust/nanocom/src/object.rs +6 -9
- package/com/rust/nanocom/src/ref.rs +3 -3
- package/com/rust/nanocom/src/vmt.rs +2 -2
- package/package.json +1 -1
- package/com/rust/nanocom/src/iunknownvmt.rs +0 -13
package/Cargo.lock
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "nanocom"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
edition = "2021"
|
|
5
|
-
description = "Nano-
|
|
5
|
+
description = "Nano-COM, extremly small subset of cross-platform COM"
|
|
6
|
+
authors = ["NatFoam"]
|
|
6
7
|
license = "MIT"
|
|
8
|
+
homepage = "https://github.com/functionalscript/functionalscript/tree/main/com/rust/nanocom"
|
|
9
|
+
repository = "https://github.com/functionalscript/functionalscript"
|
|
10
|
+
keywords = ["com", "xpcom", "abi"]
|
|
11
|
+
categories = ["development-tools::ffi", "external-ffi-bindings", "api-bindings"]
|
|
7
12
|
|
|
8
13
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
9
14
|
|
|
@@ -61,7 +61,7 @@ mod test {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// interface implementation
|
|
64
|
-
mod
|
|
64
|
+
mod number {
|
|
65
65
|
use nanocom::{CObject, Class, Ref, Vmt};
|
|
66
66
|
|
|
67
67
|
use super::library::{IMy, IMyEx, IMyVmt};
|
|
@@ -90,10 +90,10 @@ mod test {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
mod
|
|
93
|
+
mod use_number {
|
|
94
94
|
use nanocom::Class;
|
|
95
95
|
|
|
96
|
-
use crate::test::{library::IMyEx,
|
|
96
|
+
use crate::test::{library::IMyEx, number::X};
|
|
97
97
|
|
|
98
98
|
#[test]
|
|
99
99
|
fn test() {
|
|
@@ -106,4 +106,86 @@ mod test {
|
|
|
106
106
|
assert_eq!(b.B(), 43);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
mod destructor {
|
|
111
|
+
use std::{
|
|
112
|
+
rc::Rc,
|
|
113
|
+
sync::atomic::{AtomicU32, Ordering},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
use nanocom::{CObject, Class, Ref, Vmt};
|
|
117
|
+
|
|
118
|
+
use super::library::{IMy, IMyEx, IMyVmt};
|
|
119
|
+
|
|
120
|
+
pub struct X {
|
|
121
|
+
p: Rc<AtomicU32>,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
impl X {
|
|
125
|
+
pub fn new(p: Rc<AtomicU32>) -> Self {
|
|
126
|
+
p.fetch_add(1, Ordering::Relaxed);
|
|
127
|
+
Self { p }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
impl Drop for X {
|
|
132
|
+
fn drop(&mut self) {
|
|
133
|
+
self.p.fetch_sub(1, Ordering::Relaxed);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
impl Class for X {
|
|
138
|
+
type Interface = IMy;
|
|
139
|
+
fn static_vmt() -> &'static Vmt<Self::Interface> {
|
|
140
|
+
static V: Vmt<IMy> = Vmt {
|
|
141
|
+
iunknown: X::IUNKNOWN,
|
|
142
|
+
interface: X::INTERFACE,
|
|
143
|
+
};
|
|
144
|
+
&V
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#[allow(non_snake_case)]
|
|
149
|
+
impl IMyEx for CObject<X> {
|
|
150
|
+
fn A(&self) -> Ref<IMy> {
|
|
151
|
+
self.to_interface().into()
|
|
152
|
+
}
|
|
153
|
+
fn B(&self) -> u32 {
|
|
154
|
+
self.value.p.load(Ordering::Relaxed)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
mod use_destructor {
|
|
160
|
+
use std::{
|
|
161
|
+
rc::Rc,
|
|
162
|
+
sync::atomic::{AtomicU32, Ordering},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
use nanocom::Class;
|
|
166
|
+
|
|
167
|
+
use crate::test::{destructor::X, library::IMyEx};
|
|
168
|
+
|
|
169
|
+
#[test]
|
|
170
|
+
fn test() {
|
|
171
|
+
let p = Rc::new(AtomicU32::default());
|
|
172
|
+
{
|
|
173
|
+
assert_eq!(p.load(Ordering::Relaxed), 0);
|
|
174
|
+
let a = X::new(p.clone()).cobject_new();
|
|
175
|
+
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
176
|
+
let a1 = a.A();
|
|
177
|
+
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
178
|
+
assert_eq!(a, a1);
|
|
179
|
+
assert_eq!(a.B(), 1);
|
|
180
|
+
{
|
|
181
|
+
let b = X::new(p.clone()).cobject_new();
|
|
182
|
+
assert_eq!(p.load(Ordering::Relaxed), 2);
|
|
183
|
+
assert_ne!(a, b);
|
|
184
|
+
assert_eq!(b.B(), 2);
|
|
185
|
+
}
|
|
186
|
+
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
187
|
+
}
|
|
188
|
+
assert_eq!(p.load(Ordering::Relaxed), 0);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
109
191
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
use crate::{
|
|
1
|
+
use crate::{iunknown::IUnknown, CObject, Interface, Object, Ref, Vmt};
|
|
2
2
|
|
|
3
3
|
pub trait Class: Sized {
|
|
4
4
|
type Interface: Interface;
|
|
5
5
|
fn static_vmt() -> &'static Vmt<Self::Interface>;
|
|
6
|
-
const IUNKNOWN:
|
|
6
|
+
const IUNKNOWN: IUnknown<Self::Interface> = CObject::<Self>::IUNKNOWN;
|
|
7
7
|
fn cobject_new(self) -> Ref<Self::Interface> {
|
|
8
8
|
CObject::new(self)
|
|
9
9
|
}
|
|
@@ -3,10 +3,7 @@ use std::{
|
|
|
3
3
|
sync::atomic::{AtomicU32, Ordering},
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
-
use crate::{
|
|
7
|
-
hresult::HRESULT, iunknown::IUnknown, iunknownvmt::IUnknownVmt, Class, Interface, Object, Ref,
|
|
8
|
-
Vmt,
|
|
9
|
-
};
|
|
6
|
+
use crate::{hresult::HRESULT, iunknown::IUnknown, Class, Interface, Object, Ref, Vmt};
|
|
10
7
|
|
|
11
8
|
#[repr(C)]
|
|
12
9
|
pub struct CObject<T: Class> {
|
|
@@ -31,7 +28,7 @@ impl<T: Class> CObject<T> {
|
|
|
31
28
|
unsafe { &*p }
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
pub const IUNKNOWN:
|
|
31
|
+
pub const IUNKNOWN: IUnknown<T::Interface> = IUnknown {
|
|
35
32
|
QueryInterface: Self::QueryInterface,
|
|
36
33
|
AddRef: Self::AddRef,
|
|
37
34
|
Release: Self::Release,
|
|
@@ -41,11 +38,11 @@ impl<T: Class> CObject<T> {
|
|
|
41
38
|
extern "stdcall" fn QueryInterface(
|
|
42
39
|
this: &Object<T::Interface>,
|
|
43
40
|
riid: &u128,
|
|
44
|
-
ppv_object: &mut *const Object
|
|
41
|
+
ppv_object: &mut *const Object,
|
|
45
42
|
) -> HRESULT {
|
|
46
|
-
let (p, r) = if *riid ==
|
|
43
|
+
let (p, r) = if *riid == <()>::GUID || *riid == T::Interface::GUID {
|
|
47
44
|
Self::AddRef(this);
|
|
48
|
-
(this.to_iunknown() as *const Object
|
|
45
|
+
(this.to_iunknown() as *const Object, HRESULT::S_OK)
|
|
49
46
|
} else {
|
|
50
47
|
(null(), HRESULT::E_NOINTERFACE)
|
|
51
48
|
};
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
use crate::{
|
|
1
|
+
use crate::{hresult::HRESULT, Object, GUID};
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
#[allow(non_snake_case)]
|
|
4
|
+
#[repr(C)]
|
|
5
|
+
pub struct IUnknown<I: 'static> {
|
|
6
|
+
pub QueryInterface: unsafe extern "stdcall" fn(
|
|
7
|
+
this: &Object<I>,
|
|
8
|
+
riid: &GUID,
|
|
9
|
+
ppv_object: &mut *const Object,
|
|
10
|
+
) -> HRESULT,
|
|
11
|
+
pub AddRef: unsafe extern "stdcall" fn(this: &Object<I>) -> u32,
|
|
12
|
+
pub Release: unsafe extern "stdcall" fn(this: &Object<I>) -> u32,
|
|
7
13
|
}
|
|
@@ -4,12 +4,11 @@ mod guid;
|
|
|
4
4
|
mod hresult;
|
|
5
5
|
mod interface;
|
|
6
6
|
mod iunknown;
|
|
7
|
-
mod iunknownvmt;
|
|
8
7
|
mod object;
|
|
9
8
|
mod r#ref;
|
|
10
9
|
mod vmt;
|
|
11
10
|
|
|
12
11
|
pub use crate::{
|
|
13
|
-
class::Class, cobject::CObject, guid::GUID, interface::Interface,
|
|
14
|
-
vmt::Vmt,
|
|
12
|
+
class::Class, cobject::CObject, guid::GUID, interface::Interface, iunknown::IUnknown,
|
|
13
|
+
object::Object, r#ref::Ref, vmt::Vmt,
|
|
15
14
|
};
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
use crate::{
|
|
2
|
-
hresult::HRESULT, interface::Interface, iunknown::IUnknown, iunknownvmt::IUnknownVmt,
|
|
3
|
-
r#ref::Ref, vmt::Vmt,
|
|
4
|
-
};
|
|
1
|
+
use crate::{hresult::HRESULT, interface::Interface, iunknown::IUnknown, r#ref::Ref, vmt::Vmt};
|
|
5
2
|
use std::ptr::null;
|
|
6
3
|
|
|
7
4
|
#[repr(C)]
|
|
8
|
-
pub struct Object<I: 'static>(&'static Vmt<I>);
|
|
5
|
+
pub struct Object<I: 'static = ()>(&'static Vmt<I>);
|
|
9
6
|
|
|
10
7
|
impl<I> Object<I> {
|
|
11
|
-
pub unsafe fn iunknown(&self) -> &'static
|
|
8
|
+
pub unsafe fn iunknown(&self) -> &'static IUnknown<I> {
|
|
12
9
|
&self.0.iunknown
|
|
13
10
|
}
|
|
14
11
|
pub unsafe fn interface(&self) -> &'static I {
|
|
15
12
|
&self.0.interface
|
|
16
13
|
}
|
|
17
|
-
pub fn to_iunknown(&self) -> &Object
|
|
18
|
-
let p = self as *const Object<I> as *const Object
|
|
14
|
+
pub fn to_iunknown(&self) -> &Object {
|
|
15
|
+
let p = self as *const Object<I> as *const Object;
|
|
19
16
|
unsafe { &*p }
|
|
20
17
|
}
|
|
21
18
|
pub fn query_interface<J: Interface>(&self) -> Result<Ref<J>, HRESULT> {
|
|
@@ -28,7 +25,7 @@ impl<I> Object<I> {
|
|
|
28
25
|
e => Err(e),
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
pub fn query_iunknown(&self) -> Ref
|
|
28
|
+
pub fn query_iunknown(&self) -> Ref {
|
|
32
29
|
self.query_interface().unwrap()
|
|
33
30
|
}
|
|
34
31
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
use std::{cmp::Eq, fmt::Debug, ops::Deref};
|
|
1
|
+
use std::{cmp::Eq, fmt::{Debug, Formatter}, ops::Deref};
|
|
2
2
|
|
|
3
3
|
use crate::object::Object;
|
|
4
4
|
|
|
5
5
|
#[repr(transparent)]
|
|
6
|
-
pub struct Ref<I: 'static>(*const Object<I>);
|
|
6
|
+
pub struct Ref<I: 'static = ()>(*const Object<I>);
|
|
7
7
|
|
|
8
8
|
impl<I: 'static> Ref<I> {
|
|
9
9
|
pub unsafe fn from_raw(p: *const Object<I>) -> Ref<I> {
|
|
@@ -39,7 +39,7 @@ impl<I> From<&Object<I>> for Ref<I> {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
impl<I> Debug for Ref<I> {
|
|
42
|
-
fn fmt(&self, f: &mut
|
|
42
|
+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
43
43
|
f.debug_tuple("Ref").field(&self.0).finish()
|
|
44
44
|
}
|
|
45
45
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
use crate::{hresult::HRESULT, iunknown::IUnknown, Object, GUID};
|
|
2
|
-
|
|
3
|
-
#[allow(non_snake_case)]
|
|
4
|
-
#[repr(C)]
|
|
5
|
-
pub struct IUnknownVmt<I: 'static> {
|
|
6
|
-
pub QueryInterface: unsafe extern "stdcall" fn(
|
|
7
|
-
this: &Object<I>,
|
|
8
|
-
riid: &GUID,
|
|
9
|
-
ppv_object: &mut *const Object<IUnknown>,
|
|
10
|
-
) -> HRESULT,
|
|
11
|
-
pub AddRef: unsafe extern "stdcall" fn(this: &Object<I>) -> u32,
|
|
12
|
-
pub Release: unsafe extern "stdcall" fn(this: &Object<I>) -> u32,
|
|
13
|
-
}
|