From 1697705672bceb2392aa33849b2cd39d40338fa4 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sat, 13 Oct 2018 21:01:24 -0700 Subject: [PATCH 1/3] Implement CPython-compatible gzip.decompress, restore uzlib. Enable both for atmel-samd --- docs/library/gzip.rst | 17 ++++++++ docs/library/index.rst | 7 ++-- extmod/modgzip.c | 69 +++++++++++++++++++++++++++++++++ extmod/modgzip.h | 33 ++++++++++++++++ extmod/moduzlib.c | 65 +++++++++++++++++++++++-------- extmod/moduzlib.h | 35 +++++++++++++++++ ports/atmel-samd/mpconfigport.h | 4 ++ py/builtin.h | 1 + py/mpconfig.h | 8 ++++ py/objmodule.c | 5 ++- py/py.mk | 1 + 11 files changed, 225 insertions(+), 20 deletions(-) create mode 100644 docs/library/gzip.rst create mode 100644 extmod/modgzip.c create mode 100644 extmod/modgzip.h create mode 100644 extmod/moduzlib.h diff --git a/docs/library/gzip.rst b/docs/library/gzip.rst new file mode 100644 index 000000000000..a7f5b2346a08 --- /dev/null +++ b/docs/library/gzip.rst @@ -0,0 +1,17 @@ +:mod:`gzip` -- gzip file decompression +============================================ + +.. module:: gzip + :synopsis: gzip file decompression + +|see_cpython_module| :mod:`cpython:gzip`. + +This module enables decompression of gzip (``.gz``) files, a common format for +compressing large data (for example, CSV or TXT files). + +Functions +--------- + +.. function:: decompress(data) + + Decompress the data, returning a bytes object containing the uncompressed data. diff --git a/docs/library/index.rst b/docs/library/index.rst index 6c2e576e7de4..cec992e06dfb 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -21,15 +21,15 @@ standard Python library. You may need to change your code later if you rely on any non-standard functionality they currently provide. -CircuitPython's goal long-term goalis that code written in CircuitPython +CircuitPython's goal long-term goal is that code written in CircuitPython using Python standard libraries will be runnable on CPython without changes. Some libraries below are not enabled on CircuitPython builds with limited flash memory, usually on non-Express builds: -``uerrno``, ``ure``. +``uerrno``, ``ure``, ``uzlib``. Some libraries are not currently enabled in any CircuitPython build, but may be in the future: -``uio``, ``ujson``, ``uzlib``. +``uio``, ``ujson`` Some libraries are only enabled only WiFi-capable ports (ESP8266, nRF) because they are typically used for network software: @@ -45,6 +45,7 @@ Not all of these are enabled on all WiFi-capable ports. binascii.rst collections.rst gc.rst + gzip.rst hashlib.rst sys.rst uerrno.rst diff --git a/extmod/modgzip.c b/extmod/modgzip.c new file mode 100644 index 000000000000..d5ca39d5aff9 --- /dev/null +++ b/extmod/modgzip.c @@ -0,0 +1,69 @@ +/* + * This file is part of the CircuitPython project + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Josh Klar (https://github.com/klardotsh) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma GCC diagnostic ignored "-Wcast-align" + +#include +#include +#include + +#include "py/runtime.h" +#include "py/binary.h" +#include "extmod/modgzip.h" +#include "extmod/moduzlib.h" + +#define DEBUG_ENABLE 0 + +#if DEBUG_ENABLE // print debugging info +#define DEBUG_printf DEBUG_printf +#else // don't print debugging info +#define DEBUG_printf(...) (void)0 +#endif + +mp_obj_t mod_gzip_decompress(size_t n_args, const mp_obj_t *args) { + mp_obj_t data = args[0]; + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); + + return mod_uzlib_decompress_internal(&bufinfo, UZLIB_HEADER_GZIP); +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_gzip_decompress_obj, 1, 2, mod_gzip_decompress); + +#if MICROPY_PY_GZIP + +STATIC const mp_rom_map_elem_t mp_module_gzip_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gzip) }, + { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_gzip_decompress_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(mp_module_gzip_globals, mp_module_gzip_globals_table); + +const mp_obj_module_t mp_module_gzip = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&mp_module_gzip_globals, +}; + +#endif //MICROPY_PY_GZIP diff --git a/extmod/modgzip.h b/extmod/modgzip.h new file mode 100644 index 000000000000..67e7c67978ae --- /dev/null +++ b/extmod/modgzip.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Paul Sokolovsky + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MICROPY_INCLUDED_EXTMOD_MODGZIP_H +#define MICROPY_INCLUDED_EXTMOD_MODGZIP_H + +extern mp_obj_t mod_gzip_decompress(size_t n_args, const mp_obj_t *args); + +MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_gzip_decompress_obj); + +#endif // MICROPY_INCLUDED_EXTMOD_MODGZIP_H diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index 7f15d02a8e34..db58d386b157 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#pragma GCC diagnostic ignored "-Wcast-align" + #include #include @@ -32,11 +34,13 @@ #include "py/mperrno.h" #include "supervisor/shared/translate.h" +#include "extmod/moduzlib.h" #if MICROPY_PY_UZLIB #define UZLIB_CONF_PARANOID_CHECKS (1) #include "../../lib/uzlib/src/tinf.h" +#include "../../lib/uzlib/src/tinfgzip.c" #if 0 // print debugging info #define DEBUG_printf DEBUG_printf @@ -44,6 +48,14 @@ #define DEBUG_printf(...) (void)0 #endif +static void check_not_unicode(const mp_obj_t arg) { +#if MICROPY_CPYTHON_COMPAT + if (MP_OBJ_IS_STR(arg)) { + mp_raise_TypeError(translate("a bytes-like object is required")); + } +#endif +} + typedef struct _mp_obj_decompio_t { mp_obj_base_t base; mp_obj_t src_stream; @@ -145,37 +157,34 @@ STATIC const mp_obj_type_t decompio_type = { .locals_dict = (void*)&decompio_locals_dict, }; -STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { - mp_obj_t data = args[0]; - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); - +mp_obj_t mod_uzlib_decompress_internal(mp_buffer_info_t *bufinfo, uint header_mode) { TINF_DATA *decomp = m_new_obj(TINF_DATA); memset(decomp, 0, sizeof(*decomp)); DEBUG_printf("sizeof(TINF_DATA)=" UINT_FMT "\n", sizeof(*decomp)); uzlib_uncompress_init(decomp, NULL, 0); - mp_uint_t dest_buf_size = (bufinfo.len + 15) & ~15; + mp_uint_t dest_buf_size = (bufinfo->len + 15) & ~15; byte *dest_buf = m_new(byte, dest_buf_size); decomp->dest = dest_buf; decomp->dest_limit = dest_buf+dest_buf_size; - DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", decomp->destSize); - decomp->source = bufinfo.buf; - decomp->source_limit = (unsigned char *)bufinfo.buf + bufinfo.len; + decomp->source = bufinfo->buf; + decomp->source_limit = (unsigned char *)bufinfo->buf + bufinfo->len; int st; - bool is_zlib = true; - - if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) { - is_zlib = false; - } - if (is_zlib) { + if (header_mode == UZLIB_HEADER_ZLIB) { st = uzlib_zlib_parse_header(decomp); if (st < 0) { goto error; } } + if (header_mode == UZLIB_HEADER_GZIP) { + st = uzlib_gzip_parse_header(decomp); + if (st != TINF_OK) { + goto error; + } + } + while (1) { st = uzlib_uncompress_chksum(decomp); if (st < 0) { @@ -201,11 +210,36 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { error: nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st))); } + +STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { + mp_obj_t data = args[0]; + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); + + uint header_mode = UZLIB_HEADER_ZLIB; + + if (n_args > 1 && MP_OBJ_SMALL_INT_VALUE(args[1]) < 0) { + header_mode = UZLIB_HEADER_NONE; + } + + return mod_uzlib_decompress_internal(&bufinfo, header_mode); +} STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress); +mp_obj_t mod_uzlib_crc32(size_t n_args, const mp_obj_t *args) { + mp_buffer_info_t bufinfo; + check_not_unicode(args[0]); + mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); + uint32_t crc = (n_args > 1) ? mp_obj_get_int_truncated(args[1]) : 0; + crc = uzlib_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff); + return mp_obj_new_int_from_uint(crc ^ 0xffffffff); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_crc32_obj, 1, 2, mod_uzlib_crc32); + STATIC const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uzlib) }, { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) }, + { MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_uzlib_crc32_obj) }, { MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) }, }; @@ -222,7 +256,6 @@ const mp_obj_module_t mp_module_uzlib = { #pragma GCC diagnostic ignored "-Wsign-compare" #include "../../lib/uzlib/src/tinflate.c" #include "../../lib/uzlib/src/tinfzlib.c" -#include "../../lib/uzlib/src/tinfgzip.c" #include "../../lib/uzlib/src/adler32.c" #include "../../lib/uzlib/src/crc32.c" diff --git a/extmod/moduzlib.h b/extmod/moduzlib.h new file mode 100644 index 000000000000..4a643c86766a --- /dev/null +++ b/extmod/moduzlib.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2014 Paul Sokolovsky + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MICROPY_INCLUDED_EXTMOD_MODUZLIB_H +#define MICROPY_INCLUDED_EXTMOD_MODUZLIB_H + +#define UZLIB_HEADER_NONE 0 +#define UZLIB_HEADER_ZLIB 1 +#define UZLIB_HEADER_GZIP 2 + +extern mp_obj_t mod_uzlib_decompress_internal(mp_buffer_info_t *bufinfo, uint header_mode); + +#endif // MICROPY_INCLUDED_EXTMOD_MODUZLIB_H diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 4e15a6c308cf..ada52db75ce5 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -42,6 +42,8 @@ #define MICROPY_PY_IO (0) #define MICROPY_PY_UJSON (0) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (0) +#define MICROPY_PY_UZLIB (0) +#define MICROPY_PY_GZIP (0) #define MICROPY_PY_UERRNO_LIST \ X(EPERM) \ X(ENOENT) \ @@ -68,6 +70,8 @@ #define MICROPY_PY_IO (1) #define MICROPY_PY_UJSON (1) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) +#define MICROPY_PY_UZLIB (1) +#define MICROPY_PY_GZIP (1) // MICROPY_PY_UERRNO_LIST - Use the default #endif diff --git a/py/builtin.h b/py/builtin.h index 84b99a8a4f2e..f4444abccf97 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -102,6 +102,7 @@ extern const mp_obj_dict_t mp_module_builtins_globals; extern const mp_obj_module_t mp_module_uerrno; extern const mp_obj_module_t mp_module_uctypes; extern const mp_obj_module_t mp_module_uzlib; +extern const mp_obj_module_t mp_module_gzip; extern const mp_obj_module_t mp_module_ujson; extern const mp_obj_module_t mp_module_ure; extern const mp_obj_module_t mp_module_uheapq; diff --git a/py/mpconfig.h b/py/mpconfig.h index 3ec383817ed7..c7bb87d5931f 100755 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1161,6 +1161,14 @@ typedef double mp_float_t; #define MICROPY_PY_UZLIB (0) #endif +#ifndef MICROPY_PY_GZIP +#define MICROPY_PY_GZIP (0) +#endif + +#if MICROPY_PY_GZIP && !MICROPY_PY_UZLIB +#error gzip depends on uzlib support +#endif + #ifndef MICROPY_PY_UJSON #define MICROPY_PY_UJSON (0) #endif diff --git a/py/objmodule.c b/py/objmodule.c index 627ba79e8a26..e17cf8fa5117 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -197,7 +197,10 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { #endif #if MICROPY_PY_UZLIB { MP_ROM_QSTR(MP_QSTR_uzlib), MP_ROM_PTR(&mp_module_uzlib) }, -#endif + #if MICROPY_PY_GZIP + { MP_ROM_QSTR(MP_QSTR_gzip), MP_ROM_PTR(&mp_module_gzip) }, + #endif // MICROPY_PY_GZIP +#endif // MICROPY_PY_UZLIB #if MICROPY_PY_UJSON #if CIRCUITPY // CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. diff --git a/py/py.mk b/py/py.mk index 17cb792646d7..a17b7b12bddb 100644 --- a/py/py.mk +++ b/py/py.mk @@ -246,6 +246,7 @@ PY_EXTMOD_O_BASENAME = \ extmod/modujson.o \ extmod/modure.o \ extmod/moduzlib.o \ + extmod/modgzip.o \ extmod/moduheapq.o \ extmod/modutimeq.o \ extmod/moduhashlib.o \ From bf3ff730799770e57c9d34687a76b81ecd1e87ff Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sun, 11 Aug 2019 15:17:03 -0700 Subject: [PATCH 2/3] New translations --- locale/ID.po | 4 ++-- locale/circuitpython.pot | 4 ++-- locale/de_DE.po | 4 ++-- locale/en_US.po | 4 ++-- locale/en_x_pirate.po | 4 ++-- locale/es.po | 4 ++-- locale/fil.po | 4 ++-- locale/fr.po | 4 ++-- locale/it_IT.po | 4 ++-- locale/pl.po | 4 ++-- locale/pt_BR.po | 4 ++-- locale/zh_Latn_pinyin.po | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index e8fdf3595f8a..f4b6a34da2f8 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1342,7 +1342,7 @@ msgstr "" msgid "__new__ arg must be a user-type" msgstr "" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "sebuah objek menyerupai byte (bytes-like) dibutuhkan" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index a2e66cc5d865..24e0dcf3ad6d 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1309,7 +1309,7 @@ msgstr "" msgid "__new__ arg must be a user-type" msgstr "" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 3037a5369d69..4d1010b60188 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -1349,7 +1349,7 @@ msgstr "__init__() sollte None zurückgeben, nicht '%s'" msgid "__new__ arg must be a user-type" msgstr "__new__ arg muss user-type sein" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "ein Byte-ähnliches Objekt ist erforderlich" diff --git a/locale/en_US.po b/locale/en_US.po index 6d15af4dd7ae..4cc83c89dc46 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -1309,7 +1309,7 @@ msgstr "" msgid "__new__ arg must be a user-type" msgstr "" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 57bb45380b31..0b30ab3e1cf4 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -1313,7 +1313,7 @@ msgstr "" msgid "__new__ arg must be a user-type" msgstr "" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "" diff --git a/locale/es.po b/locale/es.po index a3ffe579917c..773698477a7f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-31 16:30-0500\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -1358,7 +1358,7 @@ msgstr "__init__() deberia devolver None, no '%s'" msgid "__new__ arg must be a user-type" msgstr "__new__ arg debe ser un user-type" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "se requiere un objeto bytes-like" diff --git a/locale/fil.po b/locale/fil.po index f8342988298c..3eaec3cebf5c 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-31 16:30-0500\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -1362,7 +1362,7 @@ msgstr "__init__() dapat magbalink na None, hindi '%s'" msgid "__new__ arg must be a user-type" msgstr "__new__ arg ay dapat na user-type" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "a bytes-like object ay kailangan" diff --git a/locale/fr.po b/locale/fr.po index 07355526fd16..5631321a694d 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-31 16:30-0500\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -1387,7 +1387,7 @@ msgstr "__init__() doit retourner None, pas '%s'" msgid "__new__ arg must be a user-type" msgstr "l'argument __new__ doit être d'un type défini par l'utilisateur" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "un objet 'bytes-like' est requis" diff --git a/locale/it_IT.po b/locale/it_IT.po index 4360cd2214e4..287b389ae6b3 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-31 16:30-0500\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -1356,7 +1356,7 @@ msgstr "__init__() deve ritornare None, non '%s'" msgid "__new__ arg must be a user-type" msgstr "" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "un oggetto byte-like è richiesto" diff --git a/locale/pl.po b/locale/pl.po index 0a38aa914472..90f8c9ef4149 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -1333,7 +1333,7 @@ msgstr "__init__() powinien zwracać None, nie '%s'" msgid "__new__ arg must be a user-type" msgstr "Argument __new__ musi być typu użytkownika" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "wymagany obiekt typu bytes" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index defeb3e44c0d..d4d679acb48d 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-31 16:30-0500\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -1330,7 +1330,7 @@ msgstr "" msgid "__new__ arg must be a user-type" msgstr "" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index c0537202cca8..191c6a66c788 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-05 17:52-0700\n" +"POT-Creation-Date: 2019-08-11 15:16-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -1343,7 +1343,7 @@ msgstr "__Init__() yīnggāi fǎnhuí not, ér bùshì '%s'" msgid "__new__ arg must be a user-type" msgstr "__new__ cānshù bìxū shì yònghù lèixíng" -#: extmod/modubinascii.c extmod/moduhashlib.c +#: extmod/modubinascii.c extmod/moduhashlib.c extmod/moduzlib.c msgid "a bytes-like object is required" msgstr "xūyào yīgè zì jié lèi duìxiàng" From 47d23848505d4fb70ea3875b8ee10f54e78ad668 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sun, 11 Aug 2019 15:46:10 -0700 Subject: [PATCH 3/3] WIP: start moving to shared-bindings --- py/circuitpy_defns.mk | 2 ++ py/objmodule.c | 6 ---- py/py.mk | 2 -- .../gzip/__init__.c | 0 .../gzip/__init__.h | 0 .../zlib/__init__.c | 28 +++++++++---------- .../zlib/__init__.h | 0 7 files changed, 16 insertions(+), 22 deletions(-) rename extmod/modgzip.c => shared-bindings/gzip/__init__.c (100%) rename extmod/modgzip.h => shared-bindings/gzip/__init__.h (100%) rename extmod/moduzlib.c => shared-bindings/zlib/__init__.c (87%) rename extmod/moduzlib.h => shared-bindings/zlib/__init__.h (100%) diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index a6dde61dac4b..960b22eb497e 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -250,6 +250,7 @@ $(filter $(SRC_PATTERNS), \ displayio/ParallelBus.c \ frequencyio/__init__.c \ frequencyio/FrequencyIn.c \ + gzip/__init__c. \ i2cslave/I2CSlave.c \ i2cslave/__init__.c \ microcontroller/Pin.c \ @@ -274,6 +275,7 @@ $(filter $(SRC_PATTERNS), \ time/__init__.c \ touchio/TouchIn.c \ touchio/__init__.c \ + zlib/__init__.c \ ) # These don't have corresponding files in each port but are still located in diff --git a/py/objmodule.c b/py/objmodule.c index e17cf8fa5117..19e6baa776b4 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -195,12 +195,6 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { #if MICROPY_PY_UCTYPES { MP_ROM_QSTR(MP_QSTR_uctypes), MP_ROM_PTR(&mp_module_uctypes) }, #endif -#if MICROPY_PY_UZLIB - { MP_ROM_QSTR(MP_QSTR_uzlib), MP_ROM_PTR(&mp_module_uzlib) }, - #if MICROPY_PY_GZIP - { MP_ROM_QSTR(MP_QSTR_gzip), MP_ROM_PTR(&mp_module_gzip) }, - #endif // MICROPY_PY_GZIP -#endif // MICROPY_PY_UZLIB #if MICROPY_PY_UJSON #if CIRCUITPY // CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here. diff --git a/py/py.mk b/py/py.mk index a17b7b12bddb..4cd4941f945a 100644 --- a/py/py.mk +++ b/py/py.mk @@ -245,8 +245,6 @@ PY_EXTMOD_O_BASENAME = \ extmod/moductypes.o \ extmod/modujson.o \ extmod/modure.o \ - extmod/moduzlib.o \ - extmod/modgzip.o \ extmod/moduheapq.o \ extmod/modutimeq.o \ extmod/moduhashlib.o \ diff --git a/extmod/modgzip.c b/shared-bindings/gzip/__init__.c similarity index 100% rename from extmod/modgzip.c rename to shared-bindings/gzip/__init__.c diff --git a/extmod/modgzip.h b/shared-bindings/gzip/__init__.h similarity index 100% rename from extmod/modgzip.h rename to shared-bindings/gzip/__init__.h diff --git a/extmod/moduzlib.c b/shared-bindings/zlib/__init__.c similarity index 87% rename from extmod/moduzlib.c rename to shared-bindings/zlib/__init__.c index db58d386b157..3a9416f74cd4 100644 --- a/extmod/moduzlib.c +++ b/shared-bindings/zlib/__init__.c @@ -157,7 +157,7 @@ STATIC const mp_obj_type_t decompio_type = { .locals_dict = (void*)&decompio_locals_dict, }; -mp_obj_t mod_uzlib_decompress_internal(mp_buffer_info_t *bufinfo, uint header_mode) { +mp_obj_t mod_zlib_decompress_internal(mp_buffer_info_t *bufinfo, uint header_mode) { TINF_DATA *decomp = m_new_obj(TINF_DATA); memset(decomp, 0, sizeof(*decomp)); DEBUG_printf("sizeof(TINF_DATA)=" UINT_FMT "\n", sizeof(*decomp)); @@ -201,7 +201,7 @@ mp_obj_t mod_uzlib_decompress_internal(mp_buffer_info_t *bufinfo, uint header_mo } mp_uint_t final_sz = decomp->dest - dest_buf; - DEBUG_printf("uzlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz); + DEBUG_printf("zlib: Resizing from " UINT_FMT " to final size: " UINT_FMT " bytes\n", dest_buf_size, final_sz); dest_buf = (byte*)m_renew(byte, dest_buf, dest_buf_size, final_sz); mp_obj_t res = mp_obj_new_bytearray_by_ref(final_sz, dest_buf); m_del_obj(TINF_DATA, decomp); @@ -211,7 +211,7 @@ mp_obj_t mod_uzlib_decompress_internal(mp_buffer_info_t *bufinfo, uint header_mo nlr_raise(mp_obj_new_exception_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st))); } -STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t mod_zlib_decompress(size_t n_args, const mp_obj_t *args) { mp_obj_t data = args[0]; mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); @@ -222,11 +222,11 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { header_mode = UZLIB_HEADER_NONE; } - return mod_uzlib_decompress_internal(&bufinfo, header_mode); + return mod_zlib_decompress_internal(&bufinfo, header_mode); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_zlib_decompress_obj, 1, 3, mod_zlib_decompress); -mp_obj_t mod_uzlib_crc32(size_t n_args, const mp_obj_t *args) { +mp_obj_t mod_zlib_crc32(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; check_not_unicode(args[0]); mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); @@ -234,20 +234,20 @@ mp_obj_t mod_uzlib_crc32(size_t n_args, const mp_obj_t *args) { crc = uzlib_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff); return mp_obj_new_int_from_uint(crc ^ 0xffffffff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_crc32_obj, 1, 2, mod_uzlib_crc32); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_zlib_crc32_obj, 1, 2, mod_zlib_crc32); -STATIC const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uzlib) }, - { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) }, - { MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_uzlib_crc32_obj) }, +STATIC const mp_rom_map_elem_t mp_module_zlib_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zlib) }, + { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_zlib_decompress_obj) }, + { MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_zlib_crc32_obj) }, { MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_table); +STATIC MP_DEFINE_CONST_DICT(mp_module_zlib_globals, mp_module_zlib_globals_table); -const mp_obj_module_t mp_module_uzlib = { +const mp_obj_module_t mp_module_zlib = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&mp_module_uzlib_globals, + .globals = (mp_obj_dict_t*)&mp_module_zlib_globals, }; // Source files #include'd here to make sure they're compiled in diff --git a/extmod/moduzlib.h b/shared-bindings/zlib/__init__.h similarity index 100% rename from extmod/moduzlib.h rename to shared-bindings/zlib/__init__.h