Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs

This commit is contained in:
2026-09-15 10:41:00 -06:00
parent 6dc77e8eb0
commit a2b65bb47f
16427 changed files with 6972976 additions and 3 deletions
+120
View File
@@ -0,0 +1,120 @@
use crate::{
zstd::{params::DParameter, OperationExt},
{DecodeV2, DecodedSize},
};
use compression_core::{
unshared::Unshared,
util::{PartialBuffer, WriteBuffer},
};
use libzstd::stream::raw::Decoder;
use std::{
convert::TryInto,
io::{self, Result},
};
use zstd_safe::get_error_name;
#[derive(Debug)]
pub struct ZstdDecoder {
decoder: Unshared<Decoder<'static>>,
stream_ended: bool,
needs_input: bool,
}
impl Default for ZstdDecoder {
fn default() -> Self {
Self {
decoder: Unshared::new(Decoder::new().unwrap()),
stream_ended: false,
needs_input: false,
}
}
}
impl ZstdDecoder {
pub fn new() -> Self {
Self::default()
}
pub fn new_with_params(params: &[DParameter]) -> Self {
let mut decoder = Decoder::new().unwrap();
for param in params {
decoder.set_parameter(param.as_zstd()).unwrap();
}
Self {
decoder: Unshared::new(decoder),
stream_ended: false,
needs_input: false,
}
}
pub fn new_with_dict(dictionary: &[u8]) -> io::Result<Self> {
let decoder = Decoder::with_dictionary(dictionary)?;
Ok(Self {
decoder: Unshared::new(decoder),
stream_ended: false,
needs_input: false,
})
}
}
impl DecodeV2 for ZstdDecoder {
fn reinit(&mut self) -> Result<()> {
self.decoder.reinit()?;
self.stream_ended = false;
self.needs_input = false;
Ok(())
}
fn decode(
&mut self,
input: &mut PartialBuffer<&[u8]>,
output: &mut WriteBuffer<'_>,
) -> Result<bool> {
let empty_input = input.unwritten().is_empty();
// Once buffered output is drained, wait for input before calling zstd
// again. Repeated empty-input calls (e.g. while a reader is Pending)
// otherwise trigger its no-forward-progress error and poison the context.
if empty_input && self.needs_input {
return Ok(false);
}
let before = output.written_len();
let finished = self.decoder.run(input, output)?;
self.needs_input =
empty_input && output.written_len() == before && !output.has_no_spare_space();
if finished {
self.stream_ended = true;
}
Ok(finished)
}
fn flush(&mut self, output: &mut WriteBuffer<'_>) -> Result<bool> {
// Note: stream_ended is not updated here because zstd's flush only flushes
// buffered output and doesn't indicate stream completion. Stream completion
// is detected in decode() when status.remaining == 0.
self.decoder.flush(output)
}
fn finish(&mut self, output: &mut WriteBuffer<'_>) -> Result<bool> {
self.decoder.finish(output)?;
if self.stream_ended {
Ok(true)
} else {
Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"zstd stream did not finish",
))
}
}
}
impl DecodedSize for ZstdDecoder {
fn decoded_size(input: &[u8]) -> Result<u64> {
zstd_safe::find_frame_compressed_size(input)
.map_err(|error_code| io::Error::other(get_error_name(error_code)))
.and_then(|size| {
size.try_into()
.map_err(|_| io::Error::from(io::ErrorKind::FileTooLarge))
})
}
}
+59
View File
@@ -0,0 +1,59 @@
use crate::{
zstd::{params::CParameter, OperationExt},
EncodeV2,
};
use compression_core::{
unshared::Unshared,
util::{PartialBuffer, WriteBuffer},
};
use libzstd::stream::raw::Encoder;
use std::io::{self, Result};
#[derive(Debug)]
pub struct ZstdEncoder {
encoder: Unshared<Encoder<'static>>,
}
impl ZstdEncoder {
pub fn new(level: i32) -> Self {
Self {
encoder: Unshared::new(Encoder::new(level).unwrap()),
}
}
pub fn new_with_params(level: i32, params: &[CParameter]) -> Self {
let mut encoder = Encoder::new(level).unwrap();
for param in params {
encoder.set_parameter(param.as_zstd()).unwrap();
}
Self {
encoder: Unshared::new(encoder),
}
}
pub fn new_with_dict(level: i32, dictionary: &[u8]) -> io::Result<Self> {
let encoder = Encoder::with_dictionary(level, dictionary)?;
Ok(Self {
encoder: Unshared::new(encoder),
})
}
}
impl EncodeV2 for ZstdEncoder {
fn encode(
&mut self,
input: &mut PartialBuffer<&[u8]>,
output: &mut WriteBuffer<'_>,
) -> Result<()> {
self.encoder.run(input, output)?;
Ok(())
}
fn flush(&mut self, output: &mut WriteBuffer<'_>) -> Result<bool> {
self.encoder.flush(output)
}
fn finish(&mut self, output: &mut WriteBuffer<'_>) -> Result<bool> {
self.encoder.finish(output)
}
}
+97
View File
@@ -0,0 +1,97 @@
mod decoder;
mod encoder;
pub mod params;
pub use self::{decoder::ZstdDecoder, encoder::ZstdEncoder};
use compression_core::{
unshared::Unshared,
util::{PartialBuffer, WriteBuffer},
};
use libzstd::stream::raw::{InBuffer, Operation, OutBuffer, WriteBuf};
use std::io;
#[repr(transparent)]
struct WriteBufferWrapper<'a>(WriteBuffer<'a>);
unsafe impl WriteBuf for WriteBufferWrapper<'_> {
fn as_slice(&self) -> &[u8] {
self.0.written()
}
fn capacity(&self) -> usize {
self.0.capacity()
}
fn as_mut_ptr(&mut self) -> *mut u8 {
self.0.as_mut_ptr()
}
unsafe fn filled_until(&mut self, n: usize) {
self.0.set_written_and_initialized_len(n);
}
}
trait WriteBufExt {
fn get_out_buf(&mut self) -> OutBuffer<'_, WriteBufferWrapper<'_>>;
}
impl WriteBufExt for WriteBuffer<'_> {
fn get_out_buf(&mut self) -> OutBuffer<'_, WriteBufferWrapper<'_>> {
{
use std::mem::{align_of, size_of};
assert_eq!(
size_of::<WriteBuffer<'static>>(),
size_of::<WriteBufferWrapper<'static>>()
);
assert_eq!(
align_of::<WriteBuffer<'static>>(),
align_of::<WriteBufferWrapper<'static>>()
);
}
// Pass written_len to avoid overwriting existing data in buffer.
let written_len = self.written_len();
OutBuffer::around_pos(
unsafe { &mut *(self as *mut _ as *mut WriteBufferWrapper<'_>) },
written_len,
)
}
}
trait OperationExt {
fn reinit(&mut self) -> io::Result<()>;
/// Return `true` if finished.
fn run(
&mut self,
input: &mut PartialBuffer<&[u8]>,
output: &mut WriteBuffer<'_>,
) -> io::Result<bool>;
fn flush(&mut self, output: &mut WriteBuffer<'_>) -> io::Result<bool>;
fn finish(&mut self, output: &mut WriteBuffer<'_>) -> io::Result<bool>;
}
impl<C: Operation> OperationExt for Unshared<C> {
fn reinit(&mut self) -> io::Result<()> {
self.get_mut().reinit()
}
fn run(
&mut self,
input: &mut PartialBuffer<&[u8]>,
output: &mut WriteBuffer<'_>,
) -> io::Result<bool> {
let mut in_buf = InBuffer::around(input.unwritten());
let result = self.get_mut().run(&mut in_buf, &mut output.get_out_buf());
input.advance(in_buf.pos());
Ok(result? == 0)
}
fn flush(&mut self, output: &mut WriteBuffer<'_>) -> io::Result<bool> {
Ok(self.get_mut().flush(&mut output.get_out_buf())? == 0)
}
fn finish(&mut self, output: &mut WriteBuffer<'_>) -> io::Result<bool> {
Ok(self.get_mut().finish(&mut output.get_out_buf(), true)? == 0)
}
}
+154
View File
@@ -0,0 +1,154 @@
//! This module contains zstd-specific types for async-compression.
use compression_core::Level;
/// A compression parameter for zstd. This is a stable wrapper around zstd's own `CParameter`
/// type, to abstract over different versions of the zstd library.
///
/// See the [zstd documentation](https://facebook.github.io/zstd/zstd_manual.html) for more
/// information on these parameters.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CParameter(libzstd::stream::raw::CParameter);
impl From<CParameter> for libzstd::stream::raw::CParameter {
fn from(value: CParameter) -> Self {
value.0
}
}
impl CParameter {
pub fn quality(level: Level) -> i32 {
let (fastest, best) = libzstd::compression_level_range().into_inner();
// NOTE: zstd's "fastest" level is -131072 which can create outputs larger than inputs.
// This library chooses a "fastest" level which has a more-or-less equivalent compression
// ratio to gzip's fastest mode. We still allow precise levels to go negative.
// See discussion in https://github.com/Nullus157/async-compression/issues/352
const OUR_FASTEST: i32 = 1;
match level {
Level::Fastest => OUR_FASTEST,
Level::Best => best,
Level::Precise(quality) => quality.clamp(fastest, best),
_ => libzstd::DEFAULT_COMPRESSION_LEVEL,
}
}
/// Window size in bytes (as a power of two)
pub fn window_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::WindowLog(value))
}
/// Size of the initial probe table in 4-byte entries (as a power of two)
pub fn hash_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::HashLog(value))
}
/// Size of the multi-probe table in 4-byte entries (as a power of two)
pub fn chain_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::ChainLog(value))
}
/// Number of search attempts (as a power of two)
pub fn search_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::SearchLog(value))
}
/// Minimum size of matches searched for
pub fn min_match(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::MinMatch(value))
}
/// Strategy-dependent length modifier
pub fn target_length(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::TargetLength(value))
}
/// Enable long-distance matching mode to look for and emit long-distance references.
///
/// This increases the default window size.
pub fn enable_long_distance_matching(value: bool) -> Self {
Self(libzstd::stream::raw::CParameter::EnableLongDistanceMatching(value))
}
/// Size of the long-distance matching table (as a power of two)
pub fn ldm_hash_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::LdmHashLog(value))
}
/// Minimum size of long-distance matches searched for
pub fn ldm_min_match(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::LdmMinMatch(value))
}
/// Size of each bucket in the LDM hash table for collision resolution (as a power of two)
pub fn ldm_bucket_size_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::LdmBucketSizeLog(value))
}
/// Frequency of using the LDM hash table (as a power of two)
pub fn ldm_hash_rate_log(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::LdmHashRateLog(value))
}
/// Emit the size of the content (default: true).
pub fn content_size_flag(value: bool) -> Self {
Self(libzstd::stream::raw::CParameter::ContentSizeFlag(value))
}
/// Emit a checksum (default: false).
pub fn checksum_flag(value: bool) -> Self {
Self(libzstd::stream::raw::CParameter::ChecksumFlag(value))
}
/// Emit a dictionary ID when using a custom dictionary (default: true).
pub fn dict_id_flag(value: bool) -> Self {
Self(libzstd::stream::raw::CParameter::DictIdFlag(value))
}
/// Number of threads to spawn.
///
/// If set to 0, compression functions will block; if set to 1 or more, compression will
/// run in background threads and `flush` pushes bytes through the compressor.
///
/// # Panics
///
/// This parameter requires feature `zstdmt` to be enabled, otherwise it will cause a panic
/// when used in `ZstdEncoder::with_quality_and_params()` calls.
//
// TODO: make this a normal feature guarded fn on next breaking release
#[cfg_attr(docsrs, doc(cfg(feature = "zstdmt")))]
pub fn nb_workers(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::NbWorkers(value))
}
/// Number of bytes given to each worker.
///
/// If set to 0, zstd selects a job size based on compression parameters.
pub fn job_size(value: u32) -> Self {
Self(libzstd::stream::raw::CParameter::JobSize(value))
}
pub(crate) fn as_zstd(&self) -> libzstd::stream::raw::CParameter {
self.0
}
}
/// A decompression parameter for zstd. This is a stable wrapper around zstd's own `DParameter`
/// type, to abstract over different versions of the zstd library.
///
/// See the [zstd documentation](https://facebook.github.io/zstd/zstd_manual.html) for more
/// information on these parameters.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct DParameter(libzstd::stream::raw::DParameter);
impl DParameter {
/// Maximum window size in bytes (as a power of two)
pub fn window_log_max(value: u32) -> Self {
Self(libzstd::stream::raw::DParameter::WindowLogMax(value))
}
pub(crate) fn as_zstd(&self) -> libzstd::stream::raw::DParameter {
self.0
}
}