From ae181d69afcc34ff88e9e82952cdf28e5488615f Mon Sep 17 00:00:00 2001 From: Bobby Jap Date: Mon, 28 Aug 2023 21:36:32 -0700 Subject: [PATCH] Update wrappers to use new gzip changes --- shared-bindings/zlib/__init__.c | 8 ++++---- shared-bindings/zlib/__init__.h | 2 +- shared-module/zlib/__init__.c | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/shared-bindings/zlib/__init__.c b/shared-bindings/zlib/__init__.c index d0fd803d3a..1b38d59ff4 100644 --- a/shared-bindings/zlib/__init__.c +++ b/shared-bindings/zlib/__init__.c @@ -71,12 +71,12 @@ //| ... //| STATIC mp_obj_t zlib_decompress(size_t n_args, const mp_obj_t *args) { - bool is_zlib = true; - if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) { - is_zlib = false; + mp_int_t wbits = 0; + if (n_args > 1) { + wbits = MP_OBJ_SMALL_INT_VALUE(args[1]); } - return common_hal_zlib_decompress(args[0], is_zlib); + return common_hal_zlib_decompress(args[0], wbits); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(zlib_decompress_obj, 1, 3, zlib_decompress); diff --git a/shared-bindings/zlib/__init__.h b/shared-bindings/zlib/__init__.h index 232d08e294..06ffb4aef6 100644 --- a/shared-bindings/zlib/__init__.h +++ b/shared-bindings/zlib/__init__.h @@ -27,6 +27,6 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H #define MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H -mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib); +mp_obj_t common_hal_zlib_decompress(mp_obj_t data, mp_int_t wbits); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_ZLIB___INIT___H diff --git a/shared-module/zlib/__init__.c b/shared-module/zlib/__init__.c index a057e6e2f7..082464fad2 100644 --- a/shared-module/zlib/__init__.c +++ b/shared-module/zlib/__init__.c @@ -48,7 +48,7 @@ #define DEBUG_printf(...) (void)0 #endif -mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib) { +mp_obj_t common_hal_zlib_decompress(mp_obj_t data, mp_int_t wbits) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); @@ -66,7 +66,12 @@ mp_obj_t common_hal_zlib_decompress(mp_obj_t data, bool is_zlib) { decomp->source_limit = (unsigned char *)bufinfo.buf + bufinfo.len; int st; - if (is_zlib) { + if (wbits >= 16) { + st = uzlib_gzip_parse_header(decomp); + if (st < 0) { + goto error; + } + } else if (wbits >= 0) { st = uzlib_zlib_parse_header(decomp); if (st < 0) { goto error;