core: Add feature known_stubs to retrieve all known stubs

This commit is contained in:
Nathan Adams 2023-01-31 17:45:49 +01:00
parent 4a0529dedc
commit 366f8bef43
4 changed files with 59 additions and 4 deletions

21
Cargo.lock generated
View File

@ -2361,6 +2361,26 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "linkme"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22bcb06ef182e7557cf18d85bd151319d657bd8f699d381435781871f3027af8"
dependencies = [
"linkme-impl",
]
[[package]]
name = "linkme-impl"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83f2011c1121c45eb4d9639cf5dcbae9622d2978fc5e922a346bfdc6c46700b5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.1.4" version = "0.1.4"
@ -3463,6 +3483,7 @@ dependencies = [
"generational-arena", "generational-arena",
"indexmap", "indexmap",
"instant", "instant",
"linkme",
"lzma-rs", "lzma-rs",
"nellymoser-rs", "nellymoser-rs",
"num-derive", "num-derive",

View File

@ -8,6 +8,7 @@ repository.workspace = true
version.workspace = true version.workspace = true
[dependencies] [dependencies]
linkme = { version = "0.3", optional = true }
byteorder = "1.4" byteorder = "1.4"
bitstream-io = "1.6.0" bitstream-io = "1.6.0"
flate2 = "1.0.25" flate2 = "1.0.25"
@ -64,6 +65,7 @@ timeline_debug = []
mp3 = ["symphonia"] mp3 = ["symphonia"]
nellymoser = ["nellymoser-rs"] nellymoser = ["nellymoser-rs"]
audio = ["dasp"] audio = ["dasp"]
known_stubs = ["linkme"]
[build-dependencies] [build-dependencies]
build_playerglobal = { path = "build_playerglobal" } build_playerglobal = { path = "build_playerglobal" }

View File

@ -63,3 +63,31 @@ macro_rules! avm_error {
} }
) )
} }
#[macro_export]
macro_rules! avm1_stub {
($activation: ident, $class: literal, $method: literal) => {
#[cfg_attr(
feature = "known_stubs",
linkme::distributed_slice($crate::stub::KNOWN_STUBS)
)]
static STUB: $crate::stub::Stub = $crate::stub::Stub::Avm1Method {
class: $class,
method: $method,
specifics: None,
};
$activation.context.stub_tracker.encounter(&STUB);
};
($activation: ident, $class: literal, $method: literal, $specifics: literal) => {
#[cfg_attr(
feature = "known_stubs",
linkme::distributed_slice($crate::stub::KNOWN_STUBS)
)]
static STUB: $crate::stub::Stub = $crate::stub::Stub::Avm1Method {
class: $class,
method: $method,
specifics: Some(Cow::Borrowed($specifics)),
};
$activation.context.stub_tracker.encounter(&STUB);
};
}

View File

@ -3,12 +3,16 @@ use std::borrow::Cow;
use std::collections::hash_set::Iter; use std::collections::hash_set::Iter;
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display, Formatter};
#[cfg(feature = "known_stubs")]
#[linkme::distributed_slice]
pub static KNOWN_STUBS: [Stub] = [..];
#[derive(Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Clone)] #[derive(Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Clone)]
pub enum Stub { pub enum Stub {
Avm1Method { Avm1Method {
class: &'static str, class: &'static str,
method: &'static str, method: &'static str,
specifics: Option<Cow<'static, str>>, specifics: Option<&'static str>,
}, },
Other(Cow<'static, str>), Other(Cow<'static, str>),
} }
@ -45,10 +49,10 @@ impl StubCollection {
Self::default() Self::default()
} }
pub fn encounter(&mut self, stub: Stub) { pub fn encounter(&mut self, stub: &Stub) {
if !self.inner.contains(&stub) { if !self.inner.contains(stub) {
tracing::warn!("Encountered stub: {stub}"); tracing::warn!("Encountered stub: {stub}");
self.inner.insert(stub); self.inner.insert(stub.clone());
} }
} }