diff --git a/codecs/oxipng/Cargo.lock b/codecs/oxipng/Cargo.lock index d3abbefa..49428bb2 100644 --- a/codecs/oxipng/Cargo.lock +++ b/codecs/oxipng/Cargo.lock @@ -20,9 +20,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bit-vec" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" @@ -56,9 +56,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "cc" -version = "1.0.62" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" [[package]] name = "cfg-if" @@ -98,9 +98,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "const_fn" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab" +checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" [[package]] name = "crc" @@ -143,9 +143,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f" +checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" dependencies = [ "cfg-if 1.0.0", "const_fn", @@ -157,13 +157,12 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5" +checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" dependencies = [ "autocfg", "cfg-if 1.0.0", - "const_fn", "lazy_static", ] @@ -200,9 +199,9 @@ dependencies = [ [[package]] name = "image" -version = "0.23.11" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f0a8345b33b082aedec2f4d7d4a926b845cee184cbe78b703413066564431b" +checksum = "7ce04077ead78e39ae8610ad26216aed811996b043d47beed5090db674f9e9b5" dependencies = [ "bytemuck", "byteorder", @@ -215,9 +214,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" dependencies = [ "autocfg", "hashbrown", @@ -226,9 +225,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" dependencies = [ "either", ] @@ -241,24 +240,24 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libdeflate-sys" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f5b1582a0ebf8c55a46166c04d7c66f6bb17add3a6cbf69a082ac2219f31671" +checksum = "4a95fa4be7085dd06a8296dcc3f399f12ab8b0309c157dcaa90669130b175b97" dependencies = [ "cc", ] [[package]] name = "libdeflater" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93edd93a53970951da84ef733a8b6e30189a8f8a9e19610f69e4cc5bb1f4d654" +checksum = "ccc147465654929bf7b56518cc46d11701ba290f4ff94398ae3f89f1663cf60f" dependencies = [ "libdeflate-sys", ] @@ -274,9 +273,9 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.5.6" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" +checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" dependencies = [ "autocfg", ] @@ -359,9 +358,9 @@ checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" [[package]] name = "oxipng" -version = "4.0.1" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fefb26bde273c3db896a313151301a69e698a7495ee577fe2168ed7065c29c4" +checksum = "50d0b53912a666fe2970f8ab254e283531c816aed16551ab66c52485eadb44e6" dependencies = [ "bit-vec", "byteorder", @@ -390,9 +389,9 @@ dependencies = [ [[package]] name = "png" -version = "0.16.7" +version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ "bitflags", "crc32fast", @@ -411,9 +410,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" dependencies = [ "proc-macro2", ] @@ -478,9 +477,9 @@ dependencies = [ [[package]] name = "semver-parser" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" dependencies = [ "pest", ] @@ -490,6 +489,7 @@ name = "squoosh-oxipng" version = "0.1.0" dependencies = [ "crossbeam-channel", + "libdeflater", "log", "once_cell", "oxipng", @@ -499,9 +499,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.48" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" dependencies = [ "proc-macro2", "quote", @@ -522,19 +522,19 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "wasm-bindgen" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" +checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" +checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" dependencies = [ "bumpalo", "lazy_static", @@ -547,9 +547,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" +checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -557,9 +557,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" +checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" dependencies = [ "proc-macro2", "quote", @@ -570,6 +570,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" +checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" diff --git a/codecs/oxipng/Cargo.toml b/codecs/oxipng/Cargo.toml index 73ef8261..6ab15d3a 100644 --- a/codecs/oxipng/Cargo.toml +++ b/codecs/oxipng/Cargo.toml @@ -12,7 +12,8 @@ wasm-opt = ["-O", "--no-validation"] crate-type = ["cdylib"] [dependencies] -oxipng = { version = "4.0.0", default-features = false, features = ["libdeflater"] } +oxipng = { version = "4.0.1", default-features = false, features = ["libdeflater"] } +libdeflater = { version = "0.7.1", features = ["freestanding"] } wasm-bindgen = "0.2.68" log = { version = "0.4.11", features = ["release_max_level_off"] } rayon = { version = "1.5.0", optional = true } diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts index a5cfa570..3ed1d157 100644 --- a/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng.d.ts @@ -22,8 +22,6 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl export interface InitOutput { readonly optimise: (a: number, b: number, c: number, d: number) => void; - readonly malloc: (a: number) => number; - readonly free: (a: number) => void; readonly worker_initializer: (a: number) => number; readonly start_main_thread: () => void; readonly start_worker_thread: () => void; diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm index bb9559c8..a90f2296 100644 Binary files a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm and b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm differ diff --git a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts index e4189249..d1b8b633 100644 --- a/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts +++ b/codecs/oxipng/pkg-parallel/squoosh_oxipng_bg.wasm.d.ts @@ -1,8 +1,6 @@ /* tslint:disable */ /* eslint-disable */ export function optimise(a: number, b: number, c: number, d: number): void; -export function malloc(a: number): number; -export function free(a: number): void; export function worker_initializer(a: number): number; export function start_main_thread(): void; export function start_worker_thread(): void; diff --git a/codecs/oxipng/pkg/squoosh_oxipng.d.ts b/codecs/oxipng/pkg/squoosh_oxipng.d.ts index 196593fb..1c5c5b4d 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng.d.ts +++ b/codecs/oxipng/pkg/squoosh_oxipng.d.ts @@ -12,8 +12,6 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl export interface InitOutput { readonly memory: WebAssembly.Memory; readonly optimise: (a: number, b: number, c: number, d: number) => void; - readonly malloc: (a: number) => number; - readonly free: (a: number) => void; readonly __wbindgen_malloc: (a: number) => number; readonly __wbindgen_free: (a: number, b: number) => void; } diff --git a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm index ab9e78e9..d8dc493d 100644 Binary files a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm and b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm differ diff --git a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts index 81b35d76..d16fb460 100644 --- a/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts +++ b/codecs/oxipng/pkg/squoosh_oxipng_bg.wasm.d.ts @@ -2,7 +2,5 @@ /* eslint-disable */ export const memory: WebAssembly.Memory; export function optimise(a: number, b: number, c: number, d: number): void; -export function malloc(a: number): number; -export function free(a: number): void; export function __wbindgen_malloc(a: number): number; export function __wbindgen_free(a: number, b: number): void; diff --git a/codecs/oxipng/src/lib.rs b/codecs/oxipng/src/lib.rs index f48c66f3..d9d44655 100644 --- a/codecs/oxipng/src/lib.rs +++ b/codecs/oxipng/src/lib.rs @@ -1,8 +1,6 @@ use oxipng::AlphaOptim; use wasm_bindgen::prelude::*; -mod malloc_shim; - #[cfg(feature = "parallel")] pub mod parallel; diff --git a/codecs/oxipng/src/malloc_shim.rs b/codecs/oxipng/src/malloc_shim.rs deleted file mode 100644 index ff199d4b..00000000 --- a/codecs/oxipng/src/malloc_shim.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! This is a module that provides `malloc` and `free` for `libdeflate`. -//! These implementations are compatible with the standard signatures -//! but use Rust allocator instead of including libc one as well. -//! -//! Rust allocator APIs requires passing size and alignment to the -//! `dealloc` function. This is different from C API, which only -//! expects a pointer in `free` and expects allocators to take care of -//! storing any necessary information elsewhere. -//! -//! In order to simulate C API, we allocate a `size_and_data_ptr` -//! of size `sizeof(usize) + size` where `size` is the requested number -//! of bytes. Then, we store `size` at the beginning of the allocated -//! chunk (within those `sizeof(usize)` bytes) and return -//! `data_ptr = size_and_data_ptr + sizeof(usize)` to the calleer: -//! -//! [`size`][...actual data] -//! -^------------------ `size_and_data_ptr` -//! ---------^---------- `data_ptr` -//! -//! Then, in `free`, the caller gives us `data_ptr`. We can subtract -//! `sizeof(usize)` back and get the original `size_and_data_ptr`. -//! At this point we can read `size` back and call the Rust `dealloc` -//! for the whole allocated chunk. -//! -//! I've raised an upstream issue to hopefully make this easier in -//! future: https://github.com/ebiggers/libdeflate/issues/62 - -use std::alloc::*; -use std::mem::{align_of, size_of}; - -unsafe fn layout_for(size: usize) -> Layout { - Layout::from_size_align_unchecked(size_of::() + size, align_of::()) -} - -#[no_mangle] -pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 { - let size_and_data_ptr = alloc(layout_for(size)); - *(size_and_data_ptr as *mut usize) = size; - size_and_data_ptr.add(size_of::()) -} - -#[no_mangle] -pub unsafe extern "C" fn free(data_ptr: *mut u8) { - let size_and_data_ptr = data_ptr.sub(size_of::()); - let size = *(size_and_data_ptr as *const usize); - dealloc(size_and_data_ptr, layout_for(size)) -}