commit
23d2c96476
|
@ -145,6 +145,10 @@ jobs:
|
|||
run: |
|
||||
git describe --dirty --tags
|
||||
echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags)
|
||||
- name: Set up Python 3.8
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.8
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
brew install gettext
|
||||
|
|
|
@ -4,17 +4,13 @@
|
|||
|
||||
[submodule "lib/axtls"]
|
||||
path = lib/axtls
|
||||
url = https://github.com/pfalcon/axtls
|
||||
branch = micropython
|
||||
url = https://github.com/micropython/axtls.git
|
||||
[submodule "lib/libffi"]
|
||||
path = lib/libffi
|
||||
url = https://github.com/atgreen/libffi
|
||||
[submodule "lib/berkeley-db-1.xx"]
|
||||
path = lib/berkeley-db-1.xx
|
||||
url = https://github.com/pfalcon/berkeley-db-1.xx
|
||||
[submodule "lib/uzlib"]
|
||||
path = lib/uzlib
|
||||
url = https://github.com/pfalcon/uzlib
|
||||
[submodule "tools/uf2"]
|
||||
path = tools/uf2
|
||||
url = https://github.com/Microsoft/uf2.git
|
||||
|
|
64
LICENSE
64
LICENSE
|
@ -19,3 +19,67 @@ 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.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Unless specified otherwise (see below), the above license and copyright applies
|
||||
to all files in this repository.
|
||||
|
||||
Individual files may include additional copyright holders.
|
||||
|
||||
The various ports of MicroPython may include third-party software that is
|
||||
licensed under different terms. These licenses are summarised in the tree
|
||||
below, please refer to these files and directories for further license and
|
||||
copyright information. Note that (L)GPL-licensed code listed below is only
|
||||
used during the build process and is not part of the compiled source code.
|
||||
|
||||
/ (MIT)
|
||||
/drivers
|
||||
/cc3000 (BSD-3-clause)
|
||||
/cc3100 (BSD-3-clause)
|
||||
/wiznet5k (BSD-3-clause)
|
||||
/lib
|
||||
/asf4 (Apache-2.0)
|
||||
/axtls (BSD-3-clause)
|
||||
/config
|
||||
/scripts
|
||||
/config (GPL-2.0-or-later)
|
||||
/Rules.mak (GPL-2.0)
|
||||
/berkeley-db-1xx (BSD-4-clause)
|
||||
/btstack (See btstack/LICENSE)
|
||||
/cmsis (BSD-3-clause)
|
||||
/crypto-algorithms (NONE)
|
||||
/libhydrogen (ISC)
|
||||
/littlefs (BSD-3-clause)
|
||||
/lwip (BSD-3-clause)
|
||||
/mynewt-nimble (Apache-2.0)
|
||||
/nrfx (BSD-3-clause)
|
||||
/nxp_driver (BSD-3-Clause)
|
||||
/oofatfs (BSD-1-clause)
|
||||
/pico-sdk (BSD-3-clause)
|
||||
/re15 (BSD-3-clause)
|
||||
/stm32lib (BSD-3-clause)
|
||||
/tinytest (BSD-3-clause)
|
||||
/tinyusb (MIT)
|
||||
/uzlib (Zlib)
|
||||
/logo (uses OFL-1.1)
|
||||
/ports
|
||||
/cc3200
|
||||
/hal (BSD-3-clause)
|
||||
/simplelink (BSD-3-clause)
|
||||
/FreeRTOS (GPL-2.0 with FreeRTOS exception)
|
||||
/stm32
|
||||
/usbd*.c (MCD-ST Liberty SW License Agreement V2)
|
||||
/stm32_it.* (MIT + BSD-3-clause)
|
||||
/system_stm32*.c (MIT + BSD-3-clause)
|
||||
/boards
|
||||
/startup_stm32*.s (BSD-3-clause)
|
||||
/*/stm32*.h (BSD-3-clause)
|
||||
/usbdev (MCD-ST Liberty SW License Agreement V2)
|
||||
/usbhost (MCD-ST Liberty SW License Agreement V2)
|
||||
/teensy
|
||||
/core (PJRC.COM)
|
||||
/zephyr
|
||||
/src (Apache-2.0)
|
||||
/tools
|
||||
/dfu.py (LGPL-3.0-only)
|
||||
|
|
1
conf.py
1
conf.py
|
@ -209,6 +209,7 @@ exclude_patterns = ["**/build*",
|
|||
"ports/stm/ref",
|
||||
"ports/unix",
|
||||
"py",
|
||||
"shared/*",
|
||||
"shared-bindings/util.*",
|
||||
"shared-module",
|
||||
"supervisor",
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/objlist.h"
|
||||
#include "py/objstr.h"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
|
||||
|
|
|
@ -222,6 +222,14 @@ TCP stream connections
|
|||
|
||||
This is a coroutine, and a MicroPython extension.
|
||||
|
||||
.. method:: Stream.readexactly(n)
|
||||
|
||||
Read exactly *n* bytes and return them as a bytes object.
|
||||
|
||||
Raises an ``EOFError`` exception if the stream ends before reading *n* bytes.
|
||||
|
||||
This is a coroutine.
|
||||
|
||||
.. method:: Stream.readline()
|
||||
|
||||
Read a line and return it.
|
|
@ -24,7 +24,7 @@ Example::
|
|||
|
||||
# First, we need to open a stream which holds a database
|
||||
# This is usually a file, but can be in-memory database
|
||||
# using uio.BytesIO, a raw flash partition, etc.
|
||||
# using io.BytesIO, a raw flash partition, etc.
|
||||
# Oftentimes, you want to create a database file if it doesn't
|
||||
# exist and open if it exists. Idiom below takes care of this.
|
||||
# DO NOT open database with "a+b" access mode.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Builtin functions and exceptions
|
||||
================================
|
||||
:mod:`builtins` -- builtin functions and exceptions
|
||||
===================================================
|
||||
|
||||
All builtin functions and exceptions are described here. They are also
|
||||
available via ``builtins`` module.
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
:mod:`uctypes` -- access binary data in a structured way
|
||||
========================================================
|
||||
|
||||
.. include:: ../templates/unsupported_in_circuitpython.inc
|
||||
|
||||
.. module:: uctypes
|
||||
:synopsis: access binary data in a structured way
|
||||
|
|
@ -105,16 +105,23 @@ Other methods
|
|||
Shift the contents of the FrameBuffer by the given vector. This may
|
||||
leave a footprint of the previous colors in the FrameBuffer.
|
||||
|
||||
.. method:: FrameBuffer.blit(fbuf, x, y[, key])
|
||||
.. method:: FrameBuffer.blit(fbuf, x, y, key=-1, palette=None)
|
||||
|
||||
Draw another FrameBuffer on top of the current one at the given coordinates.
|
||||
If *key* is specified then it should be a color integer and the
|
||||
corresponding color will be considered transparent: all pixels with that
|
||||
color value will not be drawn.
|
||||
|
||||
This method works between FrameBuffer instances utilising different formats,
|
||||
but the resulting colors may be unexpected due to the mismatch in color
|
||||
formats.
|
||||
The *palette* argument enables blitting between FrameBuffers with differing
|
||||
formats. Typical usage is to render a monochrome or grayscale glyph/icon to
|
||||
a color display. The *palette* is a FrameBuffer instance whose format is
|
||||
that of the current FrameBuffer. The *palette* height is one pixel and its
|
||||
pixel width is the number of colors in the source FrameBuffer. The *palette*
|
||||
for an N-bit source needs 2**N pixels; the *palette* for a monochrome source
|
||||
would have 2 pixels representing background and foreground colors. The
|
||||
application assigns a color to each pixel in the *palette*. The color of the
|
||||
current pixel will be that of that *palette* pixel whose x position is the
|
||||
color of the corresponding source pixel.
|
||||
|
||||
Constants
|
||||
---------
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
:mod:`uheapq` -- heap queue algorithm
|
||||
=====================================
|
||||
:mod:`heapq` -- heap queue algorithm
|
||||
====================================
|
||||
|
||||
.. include:: ../templates/unsupported_in_circuitpython.inc
|
||||
|
||||
.. module:: uheapq
|
||||
.. module:: heapq
|
||||
:synopsis: heap queue algorithm
|
||||
|
||||
|see_cpython_module| :mod:`cpython:heapq`.
|
|
@ -18,15 +18,14 @@ These libraries are not enabled on CircuitPython builds with
|
|||
limited flash memory, usually on non-Express builds:
|
||||
``binascii``, ``errno``, ``json``, ``re``.
|
||||
|
||||
These libraries are not currently enabled in any CircuitPython build, but may be in the future,
|
||||
with the ``u`` prefix dropped:
|
||||
``uctypes``, ``uhashlib``, ``uzlib``.
|
||||
These libraries are not currently enabled in any CircuitPython build, but may be in the future:
|
||||
``ctypes``, ``hashlib``, ``zlib``.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
builtins.rst
|
||||
uheapq.rst
|
||||
heapq.rst
|
||||
array.rst
|
||||
binascii.rst
|
||||
collections.rst
|
||||
|
@ -37,10 +36,10 @@ with the ``u`` prefix dropped:
|
|||
json.rst
|
||||
re.rst
|
||||
sys.rst
|
||||
uasyncio.rst
|
||||
uctypes.rst
|
||||
uselect.rst
|
||||
uzlib.rst
|
||||
asyncio.rst
|
||||
ctypes.rst
|
||||
select.rst
|
||||
zlib.rst
|
||||
|
||||
Omitted functions in the ``string`` library
|
||||
-------------------------------------------
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
:mod:`uselect` -- wait for events on a set of streams
|
||||
========================================================================
|
||||
:mod:`select` -- wait for events on a set of streams
|
||||
====================================================
|
||||
|
||||
.. include:: ../templates/unsupported_in_circuitpython.inc
|
||||
|
||||
.. module:: uselect
|
||||
.. module:: select
|
||||
:synopsis: wait for events on a set of streams
|
||||
|
||||
|see_cpython_module| :mod:`cpython:select`.
|
||||
|
@ -37,15 +37,15 @@ Methods
|
|||
|
||||
Register ``stream`` *obj* for polling. *eventmask* is logical OR of:
|
||||
|
||||
* ``uselect.POLLIN`` - data available for reading
|
||||
* ``uselect.POLLOUT`` - more data can be written
|
||||
* ``select.POLLIN`` - data available for reading
|
||||
* ``select.POLLOUT`` - more data can be written
|
||||
|
||||
Note that flags like ``uselect.POLLHUP`` and ``uselect.POLLERR`` are
|
||||
Note that flags like ``select.POLLHUP`` and ``select.POLLERR`` are
|
||||
*not* valid as input eventmask (these are unsolicited events which
|
||||
will be returned from `poll()` regardless of whether they are asked
|
||||
for). This semantics is per POSIX.
|
||||
|
||||
*eventmask* defaults to ``uselect.POLLIN | uselect.POLLOUT``.
|
||||
*eventmask* defaults to ``select.POLLIN | select.POLLOUT``.
|
||||
|
||||
It is OK to call this function multiple times for the same *obj*.
|
||||
Successive calls will update *obj*'s eventmask to the value of
|
||||
|
@ -69,8 +69,8 @@ Methods
|
|||
Returns list of (``obj``, ``event``, ...) tuples. There may be other elements in
|
||||
tuple, depending on a platform and version, so don't assume that its size is 2.
|
||||
The ``event`` element specifies which events happened with a stream and
|
||||
is a combination of ``uselect.POLL*`` constants described above. Note that
|
||||
flags ``uselect.POLLHUP`` and ``uselect.POLLERR`` can be returned at any time
|
||||
is a combination of ``select.POLL*`` constants described above. Note that
|
||||
flags ``select.POLLHUP`` and ``select.POLLERR`` can be returned at any time
|
||||
(even if were not asked for), and must be acted on accordingly (the
|
||||
corresponding stream unregistered from poll and likely closed), because
|
||||
otherwise all further invocations of `poll()` may return immediately with
|
|
@ -1,9 +1,9 @@
|
|||
:mod:`uzlib` -- zlib decompression
|
||||
==================================
|
||||
:mod:`zlib` -- zlib decompression
|
||||
=================================
|
||||
|
||||
.. include:: ../templates/unsupported_in_circuitpython.inc
|
||||
|
||||
.. module:: uzlib
|
||||
.. module:: zlib
|
||||
:synopsis: zlib decompression
|
||||
|
||||
|see_cpython_module| :mod:`cpython:zlib`.
|
|
@ -18,7 +18,7 @@ void *memmove(void *dest, const void *src, size_t n) {
|
|||
}
|
||||
|
||||
void *malloc(size_t n) {
|
||||
void *ptr = m_malloc(n, false);
|
||||
void *ptr = m_malloc(n);
|
||||
return ptr;
|
||||
}
|
||||
void *realloc(void *ptr, size_t n) {
|
||||
|
@ -26,7 +26,7 @@ void *realloc(void *ptr, size_t n) {
|
|||
return NULL;
|
||||
}
|
||||
void *calloc(size_t n, size_t m) {
|
||||
void *ptr = m_malloc(n * m, false);
|
||||
void *ptr = m_malloc(n * m);
|
||||
// memory already cleared by conservative GC
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_d_obj, add_d);
|
|||
// to use but has access to the globals dict of the module via self->globals.
|
||||
STATIC mp_obj_t productf(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
|
||||
// Check number of arguments is valid
|
||||
mp_arg_check_num_mp(n_args, n_kw, 1, 1, false);
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
// Extract buffer pointer and verify typecode
|
||||
mp_buffer_info_t bufinfo;
|
||||
|
|
|
@ -31,4 +31,7 @@ const mp_obj_module_t example_user_cmodule = {
|
|||
};
|
||||
|
||||
// Register the module to make it available in Python.
|
||||
MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, MODULE_CEXAMPLE_ENABLED);
|
||||
// Note: the "1" in the third argument means this module is always enabled.
|
||||
// This "1" can be optionally replaced with a macro like MODULE_CEXAMPLE_ENABLED
|
||||
// which can then be used to conditionally enable this module.
|
||||
MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, 1);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# Create an INTERFACE library for our C module.
|
||||
add_library(usermod_cexample INTERFACE)
|
||||
|
||||
# Add our source files to the lib
|
||||
target_sources(usermod_cexample INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/examplemodule.c
|
||||
)
|
||||
|
||||
# Add the current directory as an include directory.
|
||||
target_include_directories(usermod_cexample INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Link our INTERFACE library to the usermod target.
|
||||
target_link_libraries(usermod INTERFACE usermod_cexample)
|
|
@ -22,4 +22,7 @@ const mp_obj_module_t cppexample_user_cmodule = {
|
|||
};
|
||||
|
||||
// Register the module to make it available in Python.
|
||||
MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, MODULE_CPPEXAMPLE_ENABLED);
|
||||
// Note: the "1" in the third argument means this module is always enabled.
|
||||
// This "1" can be optionally replaced with a macro like MODULE_CPPEXAMPLE_ENABLED
|
||||
// which can then be used to conditionally enable this module.
|
||||
MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, 1);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# Create an INTERFACE library for our CPP module.
|
||||
add_library(usermod_cppexample INTERFACE)
|
||||
|
||||
# Add our source files to the library.
|
||||
target_sources(usermod_cppexample INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/example.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/examplemodule.c
|
||||
)
|
||||
|
||||
# Add the current directory as an include directory.
|
||||
target_include_directories(usermod_cppexample INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Link our INTERFACE library to the usermod target.
|
||||
target_link_libraries(usermod INTERFACE usermod_cppexample)
|
|
@ -0,0 +1,10 @@
|
|||
# This top-level micropython.cmake is responsible for listing
|
||||
# the individual modules we want to include.
|
||||
# Paths are absolute, and ${CMAKE_CURRENT_LIST_DIR} can be
|
||||
# used to prefix subdirectories.
|
||||
|
||||
# Add the C example.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cexample/micropython.cmake)
|
||||
|
||||
# Add the CPP example.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cppexample/micropython.cmake)
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 Damien P. George
|
||||
*
|
||||
* 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 AXTLS_OS_PORT_H
|
||||
#define AXTLS_OS_PORT_H
|
||||
|
||||
#include <errno.h>
|
||||
#include "py/stream.h"
|
||||
#include "lib/crypto-algorithms/sha256.h"
|
||||
|
||||
#define SSL_CTX_MUTEX_INIT(mutex)
|
||||
#define SSL_CTX_MUTEX_DESTROY(mutex)
|
||||
#define SSL_CTX_LOCK(mutex)
|
||||
#define SSL_CTX_UNLOCK(mutex)
|
||||
|
||||
#define SOCKET_READ(s, buf, size) mp_stream_posix_read((void *)s, buf, size)
|
||||
#define SOCKET_WRITE(s, buf, size) mp_stream_posix_write((void *)s, buf, size)
|
||||
#define SOCKET_CLOSE(A) UNUSED
|
||||
#define SOCKET_ERRNO() errno
|
||||
|
||||
#define SHA256_CTX CRYAL_SHA256_CTX
|
||||
#define SHA256_Init(ctx) sha256_init(ctx)
|
||||
#define SHA256_Update(ctx, buf, size) sha256_update(ctx, buf, size)
|
||||
#define SHA256_Final(hash, ctx) sha256_final(ctx, hash)
|
||||
|
||||
#define TTY_FLUSH()
|
||||
|
||||
#ifdef WDEV_HWRNG
|
||||
// For esp8266 port: use the hardware RNG.
|
||||
#define PLATFORM_RNG_U8() (*WDEV_HWRNG)
|
||||
#endif
|
||||
|
||||
#endif // AXTLS_OS_PORT_H
|
|
@ -4,8 +4,9 @@ set(MICROPY_EXTMOD_DIR "${MICROPY_DIR}/extmod")
|
|||
set(MICROPY_OOFATFS_DIR "${MICROPY_DIR}/lib/oofatfs")
|
||||
|
||||
set(MICROPY_SOURCE_EXTMOD
|
||||
${MICROPY_DIR}/lib/embed/abort_.c
|
||||
${MICROPY_DIR}/lib/utils/printf.c
|
||||
${MICROPY_DIR}/shared/libc/abort_.c
|
||||
${MICROPY_DIR}/shared/libc/printf.c
|
||||
${MICROPY_EXTMOD_DIR}/machine_bitstream.c
|
||||
${MICROPY_EXTMOD_DIR}/machine_i2c.c
|
||||
${MICROPY_EXTMOD_DIR}/machine_mem.c
|
||||
${MICROPY_EXTMOD_DIR}/machine_pulse.c
|
||||
|
|
|
@ -157,7 +157,7 @@ LWIP_DIR = lib/lwip/src
|
|||
INC += -I$(TOP)/$(LWIP_DIR)/include
|
||||
CFLAGS_MOD += -DMICROPY_PY_LWIP=1
|
||||
$(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS_MOD += -Wno-address
|
||||
SRC_MOD += extmod/modlwip.c lib/netutils/netutils.c
|
||||
SRC_MOD += extmod/modlwip.c shared/netutils/netutils.c
|
||||
SRC_MOD += $(addprefix $(LWIP_DIR)/,\
|
||||
apps/mdns/mdns.c \
|
||||
core/def.c \
|
||||
|
|
|
@ -244,8 +244,8 @@ STATIC void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, u
|
|||
formats[fb->format].fill_rect(fb, x, y, xend - x, yend - y, col);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 4, 5, false);
|
||||
STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 4, 5, false);
|
||||
|
||||
mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t);
|
||||
o->base.type = type;
|
||||
|
@ -481,6 +481,10 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
|
|||
if (n_args > 4) {
|
||||
key = mp_obj_get_int(args[4]);
|
||||
}
|
||||
mp_obj_framebuf_t *palette = NULL;
|
||||
if (n_args > 5 && args[5] != mp_const_none) {
|
||||
palette = MP_OBJ_TO_PTR(mp_obj_cast_to_native_base(args[5], MP_OBJ_FROM_PTR(&mp_type_framebuf)));
|
||||
}
|
||||
|
||||
if (
|
||||
(x >= self->width) ||
|
||||
|
@ -504,6 +508,9 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
|
|||
int cx1 = x1;
|
||||
for (int cx0 = x0; cx0 < x0end; ++cx0) {
|
||||
uint32_t col = getpixel(source, cx1, y1);
|
||||
if (palette) {
|
||||
col = getpixel(palette, col, 0);
|
||||
}
|
||||
if (col != (uint32_t)key) {
|
||||
setpixel(self, cx0, y0, col);
|
||||
}
|
||||
|
@ -513,7 +520,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 5, framebuf_blit);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 6, framebuf_blit);
|
||||
|
||||
STATIC mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) {
|
||||
mp_obj_framebuf_t *self = native_framebuf(self_in);
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
|
||||
#if MICROPY_PY_UASYNCIO
|
||||
|
||||
// Used when task cannot be guaranteed to be non-NULL.
|
||||
#define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL)
|
||||
|
||||
#define TASK_STATE_RUNNING_NOT_WAITED_ON (mp_const_true)
|
||||
#define TASK_STATE_DONE_NOT_WAITED_ON (mp_const_none)
|
||||
#define TASK_STATE_DONE_WAS_WAITED_ON (mp_const_false)
|
||||
|
@ -55,7 +58,7 @@ typedef struct _mp_obj_task_queue_t {
|
|||
STATIC const mp_obj_type_t task_queue_type;
|
||||
STATIC const mp_obj_type_t task_type;
|
||||
|
||||
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
|
||||
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
|
||||
/******************************************************************************/
|
||||
// Ticks for task ordering in pairing heap
|
||||
|
@ -81,9 +84,9 @@ STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
|
|||
/******************************************************************************/
|
||||
// TaskQueue class
|
||||
|
||||
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)args;
|
||||
mp_arg_check_num(n_args, kw_args, 0, 0, false);
|
||||
mp_arg_check_num(n_args, n_kw, 0, 0, false);
|
||||
mp_obj_task_queue_t *self = m_new_obj(mp_obj_task_queue_t);
|
||||
self->base.type = type;
|
||||
self->heap = (mp_obj_task_t *)mp_pairheap_new(task_lt);
|
||||
|
@ -110,7 +113,7 @@ STATIC mp_obj_t task_queue_push_sorted(size_t n_args, const mp_obj_t *args) {
|
|||
assert(mp_obj_is_small_int(args[2]));
|
||||
task->ph_key = args[2];
|
||||
}
|
||||
self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, &self->heap->pairheap, &task->pairheap);
|
||||
self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, TASK_PAIRHEAP(self->heap), TASK_PAIRHEAP(task));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_sorted_obj, 2, 3, task_queue_push_sorted);
|
||||
|
@ -156,8 +159,8 @@ STATIC const mp_obj_type_t task_queue_type = {
|
|||
// This is the core uasyncio context with cur_task, _task_queue and CancelledError.
|
||||
STATIC mp_obj_t uasyncio_context = MP_OBJ_NULL;
|
||||
|
||||
STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 2, false);
|
||||
STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, false);
|
||||
mp_obj_task_t *self = m_new_obj(mp_obj_task_t);
|
||||
self->pairheap.base.type = type;
|
||||
mp_pairheap_init_node(task_lt, &self->pairheap);
|
||||
|
|
|
@ -205,7 +205,7 @@ STATIC mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj, mod_binascii_b2a_base64);
|
||||
|
||||
#if MICROPY_PY_UBINASCII_CRC32
|
||||
#include "../../lib/uzlib/src/tinf.h"
|
||||
#include "lib/uzlib/tinf.h"
|
||||
|
||||
STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
|
|
|
@ -74,8 +74,8 @@ STATIC NORETURN void syntax_error(void) {
|
|||
mp_raise_TypeError(MP_ERROR_TEXT("syntax error in uctypes descriptor"));
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 2, 3, false);
|
||||
STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
||||
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
|
||||
o->base.type = type;
|
||||
o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#if MICROPY_SSL_MBEDTLS
|
||||
#include "mbedtls/sha256.h"
|
||||
#else
|
||||
#include "crypto-algorithms/sha256.h"
|
||||
#include "lib/crypto-algorithms/sha256.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -106,11 +106,10 @@ static void check_not_unicode(const mp_obj_t arg) {
|
|||
}
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_SHA256
|
||||
#include "crypto-algorithms/sha256.c"
|
||||
#endif
|
||||
#include "lib/crypto-algorithms/sha256.c"
|
||||
|
||||
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
||||
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
||||
o->base.type = type;
|
||||
o->final = false;
|
||||
|
@ -160,6 +159,8 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = {
|
|||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_SHA1
|
||||
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg);
|
||||
|
||||
|
|
|
@ -17,6 +17,62 @@
|
|||
|
||||
#if MICROPY_PY_UJSON
|
||||
|
||||
#if MICROPY_PY_UJSON_SEPARATORS
|
||||
|
||||
enum {
|
||||
DUMP_MODE_TO_STRING = 1,
|
||||
DUMP_MODE_TO_STREAM = 2,
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) {
|
||||
enum { ARG_separators };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_separators, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - mode, pos_args + mode, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_print_ext_t print_ext;
|
||||
|
||||
if (args[ARG_separators].u_obj == mp_const_none) {
|
||||
print_ext.item_separator = ", ";
|
||||
print_ext.key_separator = ": ";
|
||||
} else {
|
||||
mp_obj_t *items;
|
||||
mp_obj_get_array_fixed_n(args[ARG_separators].u_obj, 2, &items);
|
||||
print_ext.item_separator = mp_obj_str_get_str(items[0]);
|
||||
print_ext.key_separator = mp_obj_str_get_str(items[1]);
|
||||
}
|
||||
|
||||
if (mode == DUMP_MODE_TO_STRING) {
|
||||
// dumps(obj)
|
||||
vstr_t vstr;
|
||||
vstr_init_print(&vstr, 8, &print_ext.base);
|
||||
mp_obj_print_helper(&print_ext.base, pos_args[0], PRINT_JSON);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
||||
} else {
|
||||
// dump(obj, stream)
|
||||
print_ext.base.data = MP_OBJ_TO_PTR(pos_args[1]);
|
||||
print_ext.base.print_strn = mp_stream_write_adaptor;
|
||||
mp_get_stream_raise(pos_args[1], MP_STREAM_OP_WRITE);
|
||||
mp_obj_print_helper(&print_ext.base, pos_args[0], PRINT_JSON);
|
||||
return mp_const_none;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dump_obj, 2, mod_ujson_dump);
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dumps_obj, 1, mod_ujson_dumps);
|
||||
|
||||
#else
|
||||
|
||||
STATIC mp_obj_t mod_ujson_dump(mp_obj_t obj, mp_obj_t stream) {
|
||||
mp_get_stream_raise(stream, MP_STREAM_OP_WRITE);
|
||||
mp_print_t print = {MP_OBJ_TO_PTR(stream), mp_stream_write_adaptor};
|
||||
|
@ -33,6 +89,7 @@ STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) {
|
|||
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps);
|
||||
#endif
|
||||
|
||||
#define JSON_DEBUG(...) (void)0
|
||||
// #define JSON_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#define re1_5_stack_chk() MP_STACK_CHECK()
|
||||
|
||||
#include "re1.5/re1.5.h"
|
||||
#include "lib/re1.5/re1.5.h"
|
||||
|
||||
#if MICROPY_PY_URE_DEBUG
|
||||
#define FLAG_DEBUG 0x1000
|
||||
|
@ -49,7 +49,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
|
|||
mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t no = mp_obj_get_int(no_in);
|
||||
if (no < 0 || no >= self->num_matches) {
|
||||
mp_raise_arg1(&mp_type_IndexError, no_in);
|
||||
mp_raise_type_arg(&mp_type_IndexError, no_in);
|
||||
}
|
||||
|
||||
const char *start = self->caps[no * 2];
|
||||
|
@ -88,7 +88,7 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span
|
|||
if (n_args == 2) {
|
||||
no = mp_obj_get_int(args[1]);
|
||||
if (no < 0 || no >= self->num_matches) {
|
||||
mp_raise_arg1(&mp_type_IndexError, args[1]);
|
||||
mp_raise_type_arg(&mp_type_IndexError, args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
|
||||
if (match_no >= (unsigned int)match->num_matches) {
|
||||
mp_raise_arg1(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no));
|
||||
mp_raise_type_arg(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no));
|
||||
}
|
||||
|
||||
const char *start_match = match->caps[match_no * 2];
|
||||
|
@ -477,11 +477,11 @@ MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure, MICROPY_PY_URE);
|
|||
// only if module is enabled by config setting.
|
||||
|
||||
#define re1_5_fatal(x) assert(!x)
|
||||
#include "re1.5/compilecode.c"
|
||||
#include "lib/re1.5/compilecode.c"
|
||||
#if MICROPY_PY_URE_DEBUG
|
||||
#include "re1.5/dumpcode.c"
|
||||
#include "lib/re1.5/dumpcode.c"
|
||||
#endif
|
||||
#include "re1.5/recursiveloop.c"
|
||||
#include "re1.5/charclass.c"
|
||||
#include "lib/re1.5/recursiveloop.c"
|
||||
#include "lib/re1.5/charclass.c"
|
||||
|
||||
#endif // MICROPY_PY_URE
|
||||
|
|
|
@ -87,6 +87,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) {
|
|||
return n_ready;
|
||||
}
|
||||
|
||||
#if MICROPY_PY_USELECT_SELECT
|
||||
// select(rlist, wlist, xlist[, timeout])
|
||||
STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
|
||||
// get array data from tuple/list arguments
|
||||
|
@ -153,6 +154,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select);
|
||||
#endif // MICROPY_PY_USELECT_SELECT
|
||||
|
||||
typedef struct _mp_obj_poll_t {
|
||||
mp_obj_base_t base;
|
||||
|
@ -335,7 +337,9 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll);
|
|||
|
||||
STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) },
|
||||
#if MICROPY_PY_USELECT_SELECT
|
||||
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(MP_STREAM_POLL_RD) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(MP_STREAM_POLL_WR) },
|
||||
|
|
|
@ -55,8 +55,8 @@ STATIC bool time_less_than(struct qentry *item, struct qentry *parent) {
|
|||
return res && res < (MODULO / 2);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t utimeq_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
STATIC mp_obj_t utimeq_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
mp_uint_t alloc = mp_obj_get_int(args[0]);
|
||||
mp_obj_utimeq_t *o = m_new_obj_var(mp_obj_utimeq_t, struct qentry, alloc);
|
||||
o->base.type = type;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#if MICROPY_PY_UZLIB
|
||||
|
||||
#define UZLIB_CONF_PARANOID_CHECKS (1)
|
||||
#include "../lib/uzlib/src/tinf.h"
|
||||
#include "lib/uzlib/tinf.h"
|
||||
|
||||
#if 0 // print debugging info
|
||||
#define DEBUG_printf DEBUG_printf
|
||||
|
@ -48,8 +48,8 @@ STATIC int read_src_stream(TINF_DATA *data) {
|
|||
return c;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 2, false);
|
||||
STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 2, false);
|
||||
mp_get_stream_raise(args[0], MP_STREAM_OP_READ);
|
||||
mp_obj_decompio_t *o = m_new_obj(mp_obj_decompio_t);
|
||||
o->base.type = type;
|
||||
|
@ -186,7 +186,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
|||
return res;
|
||||
|
||||
error:
|
||||
mp_raise_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st));
|
||||
mp_raise_type_arg(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress);
|
||||
|
||||
|
@ -209,10 +209,10 @@ const mp_obj_module_t mp_module_uzlib = {
|
|||
// only if module is enabled by config setting.
|
||||
|
||||
#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"
|
||||
#include "lib/uzlib/tinflate.c"
|
||||
#include "lib/uzlib/tinfzlib.c"
|
||||
#include "lib/uzlib/tinfgzip.c"
|
||||
#include "lib/uzlib/adler32.c"
|
||||
#include "lib/uzlib/crc32.c"
|
||||
|
||||
#endif // MICROPY_PY_UZLIB
|
||||
|
|
|
@ -79,8 +79,8 @@ async def open_connection(host, port):
|
|||
from uerrno import EINPROGRESS
|
||||
import usocket as socket
|
||||
|
||||
ai = socket.getaddrinfo(host, port)[0] # TODO this is blocking!
|
||||
s = socket.socket()
|
||||
ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0] # TODO this is blocking!
|
||||
s = socket.socket(ai[0], ai[1], ai[2])
|
||||
s.setblocking(False)
|
||||
ss = Stream(s)
|
||||
try:
|
||||
|
@ -107,15 +107,7 @@ class Server:
|
|||
async def wait_closed(self):
|
||||
await self.task
|
||||
|
||||
async def _serve(self, cb, host, port, backlog):
|
||||
import usocket as socket
|
||||
|
||||
ai = socket.getaddrinfo(host, port)[0] # TODO this is blocking!
|
||||
s = socket.socket()
|
||||
s.setblocking(False)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(ai[-1])
|
||||
s.listen(backlog)
|
||||
async def _serve(self, s, cb):
|
||||
# Accept incoming connections
|
||||
while True:
|
||||
try:
|
||||
|
@ -137,9 +129,20 @@ class Server:
|
|||
# Helper function to start a TCP stream server, running as a new task
|
||||
# TODO could use an accept-callback on socket read activity instead of creating a task
|
||||
async def start_server(cb, host, port, backlog=5):
|
||||
s = Server()
|
||||
s.task = core.create_task(s._serve(cb, host, port, backlog))
|
||||
return s
|
||||
import usocket as socket
|
||||
|
||||
# Create and bind server socket.
|
||||
host = socket.getaddrinfo(host, port)[0] # TODO this is blocking!
|
||||
s = socket.socket()
|
||||
s.setblocking(False)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(host[-1])
|
||||
s.listen(backlog)
|
||||
|
||||
# Create and return server object and task.
|
||||
srv = Server()
|
||||
srv.task = core.create_task(srv._serve(s, cb))
|
||||
return srv
|
||||
|
||||
|
||||
################################################################################
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8d93ddeaf3548d5466cee0a392a4ee89f07ce2e5
|
||||
Subproject commit b913d064e525f674d0219524988e6d9d834fe09c
|
|
@ -27,7 +27,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep);
|
|||
|
||||
STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
|
||||
mp_int_t ms = mp_obj_get_int(arg);
|
||||
if (ms > 0) {
|
||||
if (ms >= 0) {
|
||||
mp_hal_delay_ms(ms);
|
||||
}
|
||||
return mp_const_none;
|
||||
|
|
|
@ -150,7 +150,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
|
|||
#if MICROPY_VFS_LFS1
|
||||
if (memcmp(&buf[32], "littlefs", 8) == 0) {
|
||||
// LFS1
|
||||
mp_obj_t vfs = mp_type_vfs_lfs1.make_new(&mp_type_vfs_lfs1, 1, &bdev_obj, NULL);
|
||||
mp_obj_t vfs = mp_type_vfs_lfs1.make_new(&mp_type_vfs_lfs1, 1, 0, &bdev_obj);
|
||||
nlr_pop();
|
||||
return vfs;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
|
|||
#if MICROPY_VFS_LFS2
|
||||
if (memcmp(&buf[0], "littlefs", 8) == 0) {
|
||||
// LFS2
|
||||
mp_obj_t vfs = mp_type_vfs_lfs2.make_new(&mp_type_vfs_lfs2, 1, &bdev_obj, NULL);
|
||||
mp_obj_t vfs = mp_type_vfs_lfs2.make_new(&mp_type_vfs_lfs2, 1, 0, &bdev_obj);
|
||||
nlr_pop();
|
||||
return vfs;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
|
|||
#endif
|
||||
|
||||
#if MICROPY_VFS_FAT
|
||||
return mp_fat_vfs_type.make_new(&mp_fat_vfs_type, 1, &bdev_obj, NULL);
|
||||
return mp_fat_vfs_type.make_new(&mp_fat_vfs_type, 1, 0, &bdev_obj);
|
||||
#endif
|
||||
|
||||
// no filesystem found
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "py/mperrno.h"
|
||||
#include "lib/oofatfs/ff.h"
|
||||
#include "extmod/vfs_fat.h"
|
||||
#include "lib/timeutils/timeutils.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "supervisor/filesystem.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
|
@ -45,8 +45,8 @@ STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) {
|
|||
return MP_IMPORT_STAT_NO_EXIST;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
// create new object
|
||||
fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t);
|
||||
|
@ -88,7 +88,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del);
|
|||
|
||||
STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) {
|
||||
// create new object
|
||||
fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, &bdev_in, NULL));
|
||||
fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, 0, &bdev_in));
|
||||
|
||||
// make the filesystem
|
||||
uint8_t working_buf[FF_MAX_SS];
|
||||
|
|
|
@ -209,9 +209,9 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
|
|||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
|
||||
mp_arg_parse_all(n_args, args, kw_args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
|
||||
return file_open(NULL, type, arg_vals);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "lib/timeutils/timeutils.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "extmod/vfs.h"
|
||||
#include "extmod/vfs_lfs.h"
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "py/objstr.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "extmod/vfs.h"
|
||||
#include "lib/timeutils/timeutils.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
|
||||
STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, int arg, bool must_return_int) {
|
||||
mp_obj_t ret = mp_vfs_blockdev_ioctl(c->context, cmd, arg);
|
||||
|
@ -113,9 +113,9 @@ const char *MP_VFS_LFSx(make_path)(MP_OBJ_VFS_LFSx * self, mp_obj_t path_in) {
|
|||
return path;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(lfs_make_allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args);
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args);
|
||||
|
||||
MP_OBJ_VFS_LFSx *self = m_new0(MP_OBJ_VFS_LFSx, 1);
|
||||
self->base.type = type;
|
||||
|
|
|
@ -71,8 +71,8 @@ STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path
|
|||
return MP_IMPORT_STAT_NO_EXIST;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 0, 1, false);
|
||||
STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
|
||||
mp_obj_vfs_posix_t *vfs = m_new_obj(mp_obj_vfs_posix_t);
|
||||
vfs->base.type = type;
|
||||
|
|
|
@ -89,14 +89,14 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
|||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_file_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
STATIC mp_obj_t vfs_posix_file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} },
|
||||
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_QSTR(MP_QSTR_r)} },
|
||||
};
|
||||
|
||||
mp_arg_val_t arg_vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, arg_vals);
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, arg_vals);
|
||||
return mp_vfs_posix_file_open(type, arg_vals[0].u_obj, arg_vals[1].u_obj);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
This directory contains standard, low-level C libraries with emphasis on
|
||||
being independent and efficient. They can be used by any port.
|
||||
This directory contains third-party, low-level C libraries and SDKs.
|
||||
Libraries that do not target any specific platform are generally chosen
|
||||
based on them being independent and efficient.
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 43a6e6bd3bbc03dc501e16b89fba0ef042ed3ea0
|
||||
Subproject commit 531cab9c278c947d268bd4c94ecab9153a961b43
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
/*************************** HEADER FILES ***************************/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "sha256.h"
|
||||
|
||||
|
@ -47,7 +48,7 @@ static void sha256_transform(CRYAL_SHA256_CTX *ctx, const BYTE data[])
|
|||
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
|
||||
|
||||
for (i = 0, j = 0; i < 16; ++i, j += 4)
|
||||
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
|
||||
m[i] = ((uint32_t)data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
|
||||
for ( ; i < 64; ++i)
|
||||
m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
|
||||
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 27e4f4c15ba30c2cfc89575159e8efb50f95037e
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Adler-32 checksum
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Adler-32 algorithm taken from the zlib source, which is
|
||||
* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
*/
|
||||
|
||||
#include "tinf.h"
|
||||
|
||||
#define A32_BASE 65521
|
||||
#define A32_NMAX 5552
|
||||
|
||||
uint32_t uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum /* 1 */)
|
||||
{
|
||||
const unsigned char *buf = (const unsigned char *)data;
|
||||
|
||||
unsigned int s1 = prev_sum & 0xffff;
|
||||
unsigned int s2 = prev_sum >> 16;
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
int k = length < A32_NMAX ? length : A32_NMAX;
|
||||
int i;
|
||||
|
||||
for (i = k / 16; i; --i, buf += 16)
|
||||
{
|
||||
s1 += buf[0]; s2 += s1; s1 += buf[1]; s2 += s1;
|
||||
s1 += buf[2]; s2 += s1; s1 += buf[3]; s2 += s1;
|
||||
s1 += buf[4]; s2 += s1; s1 += buf[5]; s2 += s1;
|
||||
s1 += buf[6]; s2 += s1; s1 += buf[7]; s2 += s1;
|
||||
|
||||
s1 += buf[8]; s2 += s1; s1 += buf[9]; s2 += s1;
|
||||
s1 += buf[10]; s2 += s1; s1 += buf[11]; s2 += s1;
|
||||
s1 += buf[12]; s2 += s1; s1 += buf[13]; s2 += s1;
|
||||
s1 += buf[14]; s2 += s1; s1 += buf[15]; s2 += s1;
|
||||
}
|
||||
|
||||
for (i = k % 16; i; --i) { s1 += *buf++; s2 += s1; }
|
||||
|
||||
s1 %= A32_BASE;
|
||||
s2 %= A32_BASE;
|
||||
|
||||
length -= k;
|
||||
}
|
||||
|
||||
return (s2 << 16) | s1;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* CRC32 checksum
|
||||
*
|
||||
* Copyright (c) 1998-2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* CRC32 algorithm taken from the zlib source, which is
|
||||
* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
*/
|
||||
|
||||
#include "tinf.h"
|
||||
|
||||
static const unsigned int tinf_crc32tab[16] = {
|
||||
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190,
|
||||
0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344,
|
||||
0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278,
|
||||
0xbdbdf21c
|
||||
};
|
||||
|
||||
/* crc is previous value for incremental computation, 0xffffffff initially */
|
||||
uint32_t uzlib_crc32(const void *data, unsigned int length, uint32_t crc)
|
||||
{
|
||||
const unsigned char *buf = (const unsigned char *)data;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
crc ^= buf[i];
|
||||
crc = tinf_crc32tab[crc & 0x0f] ^ (crc >> 4);
|
||||
crc = tinf_crc32tab[crc & 0x0f] ^ (crc >> 4);
|
||||
}
|
||||
|
||||
// return value suitable for passing in next time, for final value invert it
|
||||
return crc/* ^ 0xffffffff*/;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) uzlib authors
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
/* This files contains type declaration and prototypes for defl_static.c.
|
||||
They may be altered/distinct from the originals used in PuTTY source
|
||||
code. */
|
||||
|
||||
struct Outbuf {
|
||||
unsigned char *outbuf;
|
||||
int outlen, outsize;
|
||||
unsigned long outbits;
|
||||
int noutbits;
|
||||
int comp_disabled;
|
||||
};
|
||||
|
||||
void outbits(struct Outbuf *out, unsigned long bits, int nbits);
|
||||
void zlib_start_block(struct Outbuf *ctx);
|
||||
void zlib_finish_block(struct Outbuf *ctx);
|
||||
void zlib_literal(struct Outbuf *ectx, unsigned char c);
|
||||
void zlib_match(struct Outbuf *ectx, int distance, int len);
|
|
@ -0,0 +1,3 @@
|
|||
/* Compatibility header for the original tinf lib/older versions of uzlib.
|
||||
Note: may be removed in the future, please migrate to uzlib.h. */
|
||||
#include "uzlib.h"
|
|
@ -0,0 +1,9 @@
|
|||
/* This header contains compatibility defines for the original tinf API
|
||||
and uzlib 2.x and below API. These defines are deprecated and going
|
||||
to be removed in the future, so applications should migrate to new
|
||||
uzlib API. */
|
||||
#define TINF_DATA struct uzlib_uncomp
|
||||
|
||||
#define destSize dest_size
|
||||
#define destStart dest_start
|
||||
#define readSource source_read_cb
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
#include "tinf.h"
|
||||
|
||||
#define FTEXT 1
|
||||
#define FHCRC 2
|
||||
#define FEXTRA 4
|
||||
#define FNAME 8
|
||||
#define FCOMMENT 16
|
||||
|
||||
void tinf_skip_bytes(TINF_DATA *d, int num);
|
||||
uint16_t tinf_get_uint16(TINF_DATA *d);
|
||||
|
||||
void tinf_skip_bytes(TINF_DATA *d, int num)
|
||||
{
|
||||
while (num--) uzlib_get_byte(d);
|
||||
}
|
||||
|
||||
uint16_t tinf_get_uint16(TINF_DATA *d)
|
||||
{
|
||||
unsigned int v = uzlib_get_byte(d);
|
||||
v = (uzlib_get_byte(d) << 8) | v;
|
||||
return v;
|
||||
}
|
||||
|
||||
int uzlib_gzip_parse_header(TINF_DATA *d)
|
||||
{
|
||||
unsigned char flg;
|
||||
|
||||
/* -- check format -- */
|
||||
|
||||
/* check id bytes */
|
||||
if (uzlib_get_byte(d) != 0x1f || uzlib_get_byte(d) != 0x8b) return TINF_DATA_ERROR;
|
||||
|
||||
/* check method is deflate */
|
||||
if (uzlib_get_byte(d) != 8) return TINF_DATA_ERROR;
|
||||
|
||||
/* get flag byte */
|
||||
flg = uzlib_get_byte(d);
|
||||
|
||||
/* check that reserved bits are zero */
|
||||
if (flg & 0xe0) return TINF_DATA_ERROR;
|
||||
|
||||
/* -- find start of compressed data -- */
|
||||
|
||||
/* skip rest of base header of 10 bytes */
|
||||
tinf_skip_bytes(d, 6);
|
||||
|
||||
/* skip extra data if present */
|
||||
if (flg & FEXTRA)
|
||||
{
|
||||
unsigned int xlen = tinf_get_uint16(d);
|
||||
tinf_skip_bytes(d, xlen);
|
||||
}
|
||||
|
||||
/* skip file name if present */
|
||||
if (flg & FNAME) { while (uzlib_get_byte(d)); }
|
||||
|
||||
/* skip file comment if present */
|
||||
if (flg & FCOMMENT) { while (uzlib_get_byte(d)); }
|
||||
|
||||
/* check header crc if present */
|
||||
if (flg & FHCRC)
|
||||
{
|
||||
/*unsigned int hcrc =*/ tinf_get_uint16(d);
|
||||
|
||||
// TODO: Check!
|
||||
// if (hcrc != (tinf_crc32(src, start - src) & 0x0000ffff))
|
||||
// return TINF_DATA_ERROR;
|
||||
}
|
||||
|
||||
/* initialize for crc32 checksum */
|
||||
d->checksum_type = TINF_CHKSUM_CRC;
|
||||
d->checksum = ~0;
|
||||
|
||||
return TINF_OK;
|
||||
}
|
|
@ -0,0 +1,659 @@
|
|||
/*
|
||||
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "tinf.h"
|
||||
|
||||
#define UZLIB_DUMP_ARRAY(heading, arr, size) \
|
||||
{ \
|
||||
printf("%s", heading); \
|
||||
for (int i = 0; i < size; ++i) { \
|
||||
printf(" %d", (arr)[i]); \
|
||||
} \
|
||||
printf("\n"); \
|
||||
}
|
||||
|
||||
uint32_t tinf_get_le_uint32(TINF_DATA *d);
|
||||
uint32_t tinf_get_be_uint32(TINF_DATA *d);
|
||||
|
||||
/* --------------------------------------------------- *
|
||||
* -- uninitialized global data (static structures) -- *
|
||||
* --------------------------------------------------- */
|
||||
|
||||
#ifdef RUNTIME_BITS_TABLES
|
||||
|
||||
/* extra bits and base tables for length codes */
|
||||
unsigned char length_bits[30];
|
||||
unsigned short length_base[30];
|
||||
|
||||
/* extra bits and base tables for distance codes */
|
||||
unsigned char dist_bits[30];
|
||||
unsigned short dist_base[30];
|
||||
|
||||
#else
|
||||
|
||||
const unsigned char length_bits[30] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4,
|
||||
5, 5, 5, 5
|
||||
};
|
||||
const unsigned short length_base[30] = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115,
|
||||
131, 163, 195, 227, 258
|
||||
};
|
||||
|
||||
const unsigned char dist_bits[30] = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2,
|
||||
3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10,
|
||||
11, 11, 12, 12, 13, 13
|
||||
};
|
||||
const unsigned short dist_base[30] = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13,
|
||||
17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073,
|
||||
4097, 6145, 8193, 12289, 16385, 24577
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* special ordering of code length codes */
|
||||
const unsigned char clcidx[] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6,
|
||||
10, 5, 11, 4, 12, 3, 13, 2,
|
||||
14, 1, 15
|
||||
};
|
||||
|
||||
/* ----------------------- *
|
||||
* -- utility functions -- *
|
||||
* ----------------------- */
|
||||
|
||||
#ifdef RUNTIME_BITS_TABLES
|
||||
/* build extra bits and base tables */
|
||||
static void tinf_build_bits_base(unsigned char *bits, unsigned short *base, int delta, int first)
|
||||
{
|
||||
int i, sum;
|
||||
|
||||
/* build bits table */
|
||||
for (i = 0; i < delta; ++i) bits[i] = 0;
|
||||
for (i = 0; i < 30 - delta; ++i) bits[i + delta] = i / delta;
|
||||
|
||||
/* build base table */
|
||||
for (sum = first, i = 0; i < 30; ++i)
|
||||
{
|
||||
base[i] = sum;
|
||||
sum += 1 << bits[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* build the fixed huffman trees */
|
||||
static void tinf_build_fixed_trees(TINF_TREE *lt, TINF_TREE *dt)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* build fixed length tree */
|
||||
for (i = 0; i < 7; ++i) lt->table[i] = 0;
|
||||
|
||||
lt->table[7] = 24;
|
||||
lt->table[8] = 152;
|
||||
lt->table[9] = 112;
|
||||
|
||||
for (i = 0; i < 24; ++i) lt->trans[i] = 256 + i;
|
||||
for (i = 0; i < 144; ++i) lt->trans[24 + i] = i;
|
||||
for (i = 0; i < 8; ++i) lt->trans[24 + 144 + i] = 280 + i;
|
||||
for (i = 0; i < 112; ++i) lt->trans[24 + 144 + 8 + i] = 144 + i;
|
||||
|
||||
/* build fixed distance tree */
|
||||
for (i = 0; i < 5; ++i) dt->table[i] = 0;
|
||||
|
||||
dt->table[5] = 32;
|
||||
|
||||
for (i = 0; i < 32; ++i) dt->trans[i] = i;
|
||||
}
|
||||
|
||||
/* given an array of code lengths, build a tree */
|
||||
static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned int num)
|
||||
{
|
||||
unsigned short offs[16];
|
||||
unsigned int i, sum;
|
||||
|
||||
/* clear code length count table */
|
||||
for (i = 0; i < 16; ++i) t->table[i] = 0;
|
||||
|
||||
/* scan symbol lengths, and sum code length counts */
|
||||
for (i = 0; i < num; ++i) t->table[lengths[i]]++;
|
||||
|
||||
#if UZLIB_CONF_DEBUG_LOG >= 2
|
||||
UZLIB_DUMP_ARRAY("codelen counts:", t->table, TINF_ARRAY_SIZE(t->table));
|
||||
#endif
|
||||
|
||||
/* In the lengths array, 0 means unused code. So, t->table[0] now contains
|
||||
number of unused codes. But table's purpose is to contain # of codes of
|
||||
particular length, and there're 0 codes of length 0. */
|
||||
t->table[0] = 0;
|
||||
|
||||
/* compute offset table for distribution sort */
|
||||
for (sum = 0, i = 0; i < 16; ++i)
|
||||
{
|
||||
offs[i] = sum;
|
||||
sum += t->table[i];
|
||||
}
|
||||
|
||||
#if UZLIB_CONF_DEBUG_LOG >= 2
|
||||
UZLIB_DUMP_ARRAY("codelen offsets:", offs, TINF_ARRAY_SIZE(offs));
|
||||
#endif
|
||||
|
||||
/* create code->symbol translation table (symbols sorted by code) */
|
||||
for (i = 0; i < num; ++i)
|
||||
{
|
||||
if (lengths[i]) t->trans[offs[lengths[i]]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------- *
|
||||
* -- decode functions -- *
|
||||
* ---------------------- */
|
||||
|
||||
unsigned char uzlib_get_byte(TINF_DATA *d)
|
||||
{
|
||||
/* If end of source buffer is not reached, return next byte from source
|
||||
buffer. */
|
||||
if (d->source < d->source_limit) {
|
||||
return *d->source++;
|
||||
}
|
||||
|
||||
/* Otherwise if there's callback and we haven't seen EOF yet, try to
|
||||
read next byte using it. (Note: the callback can also update ->source
|
||||
and ->source_limit). */
|
||||
if (d->readSource && !d->eof) {
|
||||
int val = d->readSource(d);
|
||||
if (val >= 0) {
|
||||
return (unsigned char)val;
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, we hit EOF (either from ->readSource() or from exhaustion
|
||||
of the buffer), and it will be "sticky", i.e. further calls to this
|
||||
function will end up here too. */
|
||||
d->eof = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t tinf_get_le_uint32(TINF_DATA *d)
|
||||
{
|
||||
uint32_t val = 0;
|
||||
int i;
|
||||
for (i = 4; i--;) {
|
||||
val = val >> 8 | ((uint32_t)uzlib_get_byte(d)) << 24;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
uint32_t tinf_get_be_uint32(TINF_DATA *d)
|
||||
{
|
||||
uint32_t val = 0;
|
||||
int i;
|
||||
for (i = 4; i--;) {
|
||||
val = val << 8 | uzlib_get_byte(d);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/* get one bit from source stream */
|
||||
static int tinf_getbit(TINF_DATA *d)
|
||||
{
|
||||
unsigned int bit;
|
||||
|
||||
/* check if tag is empty */
|
||||
if (!d->bitcount--)
|
||||
{
|
||||
/* load next tag */
|
||||
d->tag = uzlib_get_byte(d);
|
||||
d->bitcount = 7;
|
||||
}
|
||||
|
||||
/* shift bit out of tag */
|
||||
bit = d->tag & 0x01;
|
||||
d->tag >>= 1;
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
/* read a num bit value from a stream and add base */
|
||||
static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base)
|
||||
{
|
||||
unsigned int val = 0;
|
||||
|
||||
/* read num bits */
|
||||
if (num)
|
||||
{
|
||||
unsigned int limit = 1 << (num);
|
||||
unsigned int mask;
|
||||
|
||||
for (mask = 1; mask < limit; mask *= 2)
|
||||
if (tinf_getbit(d)) val += mask;
|
||||
}
|
||||
|
||||
return val + base;
|
||||
}
|
||||
|
||||
/* given a data stream and a tree, decode a symbol */
|
||||
static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t)
|
||||
{
|
||||
int sum = 0, cur = 0, len = 0;
|
||||
|
||||
/* get more bits while code value is above sum */
|
||||
do {
|
||||
|
||||
cur = 2*cur + tinf_getbit(d);
|
||||
|
||||
if (++len == TINF_ARRAY_SIZE(t->table)) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
|
||||
sum += t->table[len];
|
||||
cur -= t->table[len];
|
||||
|
||||
} while (cur >= 0);
|
||||
|
||||
sum += cur;
|
||||
#if UZLIB_CONF_PARANOID_CHECKS
|
||||
if (sum < 0 || sum >= TINF_ARRAY_SIZE(t->trans)) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
return t->trans[sum];
|
||||
}
|
||||
|
||||
/* given a data stream, decode dynamic trees from it */
|
||||
static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
||||
{
|
||||
/* code lengths for 288 literal/len symbols and 32 dist symbols */
|
||||
unsigned char lengths[288+32];
|
||||
unsigned int hlit, hdist, hclen, hlimit;
|
||||
unsigned int i, num, length;
|
||||
|
||||
/* get 5 bits HLIT (257-286) */
|
||||
hlit = tinf_read_bits(d, 5, 257);
|
||||
|
||||
/* get 5 bits HDIST (1-32) */
|
||||
hdist = tinf_read_bits(d, 5, 1);
|
||||
|
||||
/* get 4 bits HCLEN (4-19) */
|
||||
hclen = tinf_read_bits(d, 4, 4);
|
||||
|
||||
for (i = 0; i < 19; ++i) lengths[i] = 0;
|
||||
|
||||
/* read code lengths for code length alphabet */
|
||||
for (i = 0; i < hclen; ++i)
|
||||
{
|
||||
/* get 3 bits code length (0-7) */
|
||||
unsigned int clen = tinf_read_bits(d, 3, 0);
|
||||
|
||||
lengths[clcidx[i]] = clen;
|
||||
}
|
||||
|
||||
/* build code length tree, temporarily use length tree */
|
||||
tinf_build_tree(lt, lengths, 19);
|
||||
|
||||
/* decode code lengths for the dynamic trees */
|
||||
hlimit = hlit + hdist;
|
||||
for (num = 0; num < hlimit; )
|
||||
{
|
||||
int sym = tinf_decode_symbol(d, lt);
|
||||
unsigned char fill_value = 0;
|
||||
int lbits, lbase = 3;
|
||||
|
||||
/* error decoding */
|
||||
if (sym < 0) return sym;
|
||||
|
||||
switch (sym)
|
||||
{
|
||||
case 16:
|
||||
/* copy previous code length 3-6 times (read 2 bits) */
|
||||
if (num == 0) return TINF_DATA_ERROR;
|
||||
fill_value = lengths[num - 1];
|
||||
lbits = 2;
|
||||
break;
|
||||
case 17:
|
||||
/* repeat code length 0 for 3-10 times (read 3 bits) */
|
||||
lbits = 3;
|
||||
break;
|
||||
case 18:
|
||||
/* repeat code length 0 for 11-138 times (read 7 bits) */
|
||||
lbits = 7;
|
||||
lbase = 11;
|
||||
break;
|
||||
default:
|
||||
/* values 0-15 represent the actual code lengths */
|
||||
lengths[num++] = sym;
|
||||
/* continue the for loop */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* special code length 16-18 are handled here */
|
||||
length = tinf_read_bits(d, lbits, lbase);
|
||||
if (num + length > hlimit) return TINF_DATA_ERROR;
|
||||
for (; length; --length)
|
||||
{
|
||||
lengths[num++] = fill_value;
|
||||
}
|
||||
}
|
||||
|
||||
#if UZLIB_CONF_DEBUG_LOG >= 2
|
||||
printf("lit code lengths (%d):", hlit);
|
||||
UZLIB_DUMP_ARRAY("", lengths, hlit);
|
||||
printf("dist code lengths (%d):", hdist);
|
||||
UZLIB_DUMP_ARRAY("", lengths + hlit, hdist);
|
||||
#endif
|
||||
|
||||
#if UZLIB_CONF_PARANOID_CHECKS
|
||||
/* Check that there's "end of block" symbol */
|
||||
if (lengths[256] == 0) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* build dynamic trees */
|
||||
tinf_build_tree(lt, lengths, hlit);
|
||||
tinf_build_tree(dt, lengths + hlit, hdist);
|
||||
|
||||
return TINF_OK;
|
||||
}
|
||||
|
||||
/* ----------------------------- *
|
||||
* -- block inflate functions -- *
|
||||
* ----------------------------- */
|
||||
|
||||
/* given a stream and two trees, inflate next byte of output */
|
||||
static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
||||
{
|
||||
if (d->curlen == 0) {
|
||||
unsigned int offs;
|
||||
int dist;
|
||||
int sym = tinf_decode_symbol(d, lt);
|
||||
//printf("huff sym: %02x\n", sym);
|
||||
|
||||
if (d->eof) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
|
||||
/* literal byte */
|
||||
if (sym < 256) {
|
||||
TINF_PUT(d, sym);
|
||||
return TINF_OK;
|
||||
}
|
||||
|
||||
/* end of block */
|
||||
if (sym == 256) {
|
||||
return TINF_DONE;
|
||||
}
|
||||
|
||||
/* substring from sliding dictionary */
|
||||
sym -= 257;
|
||||
if (sym >= 29) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
|
||||
/* possibly get more bits from length code */
|
||||
d->curlen = tinf_read_bits(d, length_bits[sym], length_base[sym]);
|
||||
|
||||
dist = tinf_decode_symbol(d, dt);
|
||||
if (dist >= 30) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
|
||||
/* possibly get more bits from distance code */
|
||||
offs = tinf_read_bits(d, dist_bits[dist], dist_base[dist]);
|
||||
|
||||
/* calculate and validate actual LZ offset to use */
|
||||
if (d->dict_ring) {
|
||||
if (offs > d->dict_size) {
|
||||
return TINF_DICT_ERROR;
|
||||
}
|
||||
/* Note: unlike full-dest-in-memory case below, we don't
|
||||
try to catch offset which points to not yet filled
|
||||
part of the dictionary here. Doing so would require
|
||||
keeping another variable to track "filled in" size
|
||||
of the dictionary. Appearance of such an offset cannot
|
||||
lead to accessing memory outside of the dictionary
|
||||
buffer, and clients which don't want to leak unrelated
|
||||
information, should explicitly initialize dictionary
|
||||
buffer passed to uzlib. */
|
||||
|
||||
d->lzOff = d->dict_idx - offs;
|
||||
if (d->lzOff < 0) {
|
||||
d->lzOff += d->dict_size;
|
||||
}
|
||||
} else {
|
||||
/* catch trying to point before the start of dest buffer */
|
||||
if (offs > (unsigned int)(d->dest - d->destStart)) {
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
d->lzOff = -offs;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy next byte from dict substring */
|
||||
if (d->dict_ring) {
|
||||
TINF_PUT(d, d->dict_ring[d->lzOff]);
|
||||
if ((unsigned)++d->lzOff == d->dict_size) {
|
||||
d->lzOff = 0;
|
||||
}
|
||||
} else {
|
||||
d->dest[0] = d->dest[d->lzOff];
|
||||
d->dest++;
|
||||
}
|
||||
d->curlen--;
|
||||
return TINF_OK;
|
||||
}
|
||||
|
||||
/* inflate next byte from uncompressed block of data */
|
||||
static int tinf_inflate_uncompressed_block(TINF_DATA *d)
|
||||
{
|
||||
if (d->curlen == 0) {
|
||||
unsigned int length, invlength;
|
||||
|
||||
/* get length */
|
||||
length = uzlib_get_byte(d);
|
||||
length += 256 * uzlib_get_byte(d);
|
||||
/* get one's complement of length */
|
||||
invlength = uzlib_get_byte(d);
|
||||
invlength += 256 * uzlib_get_byte(d);
|
||||
/* check length */
|
||||
if (length != (~invlength & 0x0000ffff)) return TINF_DATA_ERROR;
|
||||
|
||||
/* increment length to properly return TINF_DONE below, without
|
||||
producing data at the same time */
|
||||
d->curlen = length + 1;
|
||||
|
||||
/* make sure we start next block on a byte boundary */
|
||||
d->bitcount = 0;
|
||||
}
|
||||
|
||||
if (--d->curlen == 0) {
|
||||
return TINF_DONE;
|
||||
}
|
||||
|
||||
unsigned char c = uzlib_get_byte(d);
|
||||
TINF_PUT(d, c);
|
||||
return TINF_OK;
|
||||
}
|
||||
|
||||
/* ---------------------- *
|
||||
* -- public functions -- *
|
||||
* ---------------------- */
|
||||
|
||||
/* initialize global (static) data */
|
||||
void uzlib_init(void)
|
||||
{
|
||||
#ifdef RUNTIME_BITS_TABLES
|
||||
/* build extra bits and base tables */
|
||||
tinf_build_bits_base(length_bits, length_base, 4, 3);
|
||||
tinf_build_bits_base(dist_bits, dist_base, 2, 1);
|
||||
|
||||
/* fix a special case */
|
||||
length_bits[28] = 0;
|
||||
length_base[28] = 258;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* initialize decompression structure */
|
||||
void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen)
|
||||
{
|
||||
d->eof = 0;
|
||||
d->bitcount = 0;
|
||||
d->bfinal = 0;
|
||||
d->btype = -1;
|
||||
d->dict_size = dictLen;
|
||||
d->dict_ring = dict;
|
||||
d->dict_idx = 0;
|
||||
d->curlen = 0;
|
||||
}
|
||||
|
||||
/* inflate next output bytes from compressed stream */
|
||||
int uzlib_uncompress(TINF_DATA *d)
|
||||
{
|
||||
do {
|
||||
int res;
|
||||
|
||||
/* start a new block */
|
||||
if (d->btype == -1) {
|
||||
next_blk:
|
||||
/* read final block flag */
|
||||
d->bfinal = tinf_getbit(d);
|
||||
/* read block type (2 bits) */
|
||||
d->btype = tinf_read_bits(d, 2, 0);
|
||||
|
||||
#if UZLIB_CONF_DEBUG_LOG >= 1
|
||||
printf("Started new block: type=%d final=%d\n", d->btype, d->bfinal);
|
||||
#endif
|
||||
|
||||
if (d->btype == 1) {
|
||||
/* build fixed huffman trees */
|
||||
tinf_build_fixed_trees(&d->ltree, &d->dtree);
|
||||
} else if (d->btype == 2) {
|
||||
/* decode trees from stream */
|
||||
res = tinf_decode_trees(d, &d->ltree, &d->dtree);
|
||||
if (res != TINF_OK) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* process current block */
|
||||
switch (d->btype)
|
||||
{
|
||||
case 0:
|
||||
/* decompress uncompressed block */
|
||||
res = tinf_inflate_uncompressed_block(d);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
/* decompress block with fixed/dynamic huffman trees */
|
||||
/* trees were decoded previously, so it's the same routine for both */
|
||||
res = tinf_inflate_block_data(d, &d->ltree, &d->dtree);
|
||||
break;
|
||||
default:
|
||||
return TINF_DATA_ERROR;
|
||||
}
|
||||
|
||||
if (res == TINF_DONE && !d->bfinal) {
|
||||
/* the block has ended (without producing more data), but we
|
||||
can't return without data, so start procesing next block */
|
||||
goto next_blk;
|
||||
}
|
||||
|
||||
if (res != TINF_OK) {
|
||||
return res;
|
||||
}
|
||||
|
||||
} while (d->dest < d->dest_limit);
|
||||
|
||||
return TINF_OK;
|
||||
}
|
||||
|
||||
/* inflate next output bytes from compressed stream, updating
|
||||
checksum, and at the end of stream, verify it */
|
||||
int uzlib_uncompress_chksum(TINF_DATA *d)
|
||||
{
|
||||
int res;
|
||||
unsigned char *data = d->dest;
|
||||
|
||||
res = uzlib_uncompress(d);
|
||||
|
||||
if (res < 0) return res;
|
||||
|
||||
switch (d->checksum_type) {
|
||||
|
||||
case TINF_CHKSUM_ADLER:
|
||||
d->checksum = uzlib_adler32(data, d->dest - data, d->checksum);
|
||||
break;
|
||||
|
||||
case TINF_CHKSUM_CRC:
|
||||
d->checksum = uzlib_crc32(data, d->dest - data, d->checksum);
|
||||
break;
|
||||
}
|
||||
|
||||
if (res == TINF_DONE) {
|
||||
unsigned int val;
|
||||
|
||||
switch (d->checksum_type) {
|
||||
|
||||
case TINF_CHKSUM_ADLER:
|
||||
val = tinf_get_be_uint32(d);
|
||||
if (d->checksum != val) {
|
||||
return TINF_CHKSUM_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case TINF_CHKSUM_CRC:
|
||||
val = tinf_get_le_uint32(d);
|
||||
if (~d->checksum != val) {
|
||||
return TINF_CHKSUM_ERROR;
|
||||
}
|
||||
// Uncompressed size. TODO: Check
|
||||
val = tinf_get_le_uint32(d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
#include "tinf.h"
|
||||
|
||||
int uzlib_zlib_parse_header(TINF_DATA *d)
|
||||
{
|
||||
unsigned char cmf, flg;
|
||||
|
||||
/* -- get header bytes -- */
|
||||
|
||||
cmf = uzlib_get_byte(d);
|
||||
flg = uzlib_get_byte(d);
|
||||
|
||||
/* -- check format -- */
|
||||
|
||||
/* check checksum */
|
||||
if ((256*cmf + flg) % 31) return TINF_DATA_ERROR;
|
||||
|
||||
/* check method is deflate */
|
||||
if ((cmf & 0x0f) != 8) return TINF_DATA_ERROR;
|
||||
|
||||
/* check window size is valid */
|
||||
if ((cmf >> 4) > 7) return TINF_DATA_ERROR;
|
||||
|
||||
/* check there is no preset dictionary */
|
||||
if (flg & 0x20) return TINF_DATA_ERROR;
|
||||
|
||||
/* initialize for adler32 checksum */
|
||||
d->checksum_type = TINF_CHKSUM_ADLER;
|
||||
d->checksum = 1;
|
||||
|
||||
return cmf >> 4;
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||
*
|
||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||
* All Rights Reserved
|
||||
* http://www.ibsensoftware.com/
|
||||
*
|
||||
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||
*
|
||||
* This software is provided 'as-is', without any express
|
||||
* or implied warranty. In no event will the authors be
|
||||
* held liable for any damages arising from the use of
|
||||
* this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software
|
||||
* for any purpose, including commercial applications,
|
||||
* and to alter it and redistribute it freely, subject to
|
||||
* the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be
|
||||
* misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this
|
||||
* software in a product, an acknowledgment in
|
||||
* the product documentation would be appreciated
|
||||
* but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked
|
||||
* as such, and must not be misrepresented as
|
||||
* being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from
|
||||
* any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef UZLIB_H_INCLUDED
|
||||
#define UZLIB_H_INCLUDED
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "defl_static.h"
|
||||
|
||||
#include "uzlib_conf.h"
|
||||
#if UZLIB_CONF_DEBUG_LOG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* calling convention */
|
||||
#ifndef TINFCC
|
||||
#ifdef __WATCOMC__
|
||||
#define TINFCC __cdecl
|
||||
#else
|
||||
#define TINFCC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ok status, more data produced */
|
||||
#define TINF_OK 0
|
||||
/* end of compressed stream reached */
|
||||
#define TINF_DONE 1
|
||||
#define TINF_DATA_ERROR (-3)
|
||||
#define TINF_CHKSUM_ERROR (-4)
|
||||
#define TINF_DICT_ERROR (-5)
|
||||
|
||||
/* checksum types */
|
||||
#define TINF_CHKSUM_NONE 0
|
||||
#define TINF_CHKSUM_ADLER 1
|
||||
#define TINF_CHKSUM_CRC 2
|
||||
|
||||
/* helper macros */
|
||||
#define TINF_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
|
||||
|
||||
/* data structures */
|
||||
|
||||
typedef struct {
|
||||
unsigned short table[16]; /* table of code length counts */
|
||||
unsigned short trans[288]; /* code -> symbol translation table */
|
||||
} TINF_TREE;
|
||||
|
||||
struct uzlib_uncomp {
|
||||
/* Pointer to the next byte in the input buffer */
|
||||
const unsigned char *source;
|
||||
/* Pointer to the next byte past the input buffer (source_limit = source + len) */
|
||||
const unsigned char *source_limit;
|
||||
/* If source_limit == NULL, or source >= source_limit, this function
|
||||
will be used to read next byte from source stream. The function may
|
||||
also return -1 in case of EOF (or irrecoverable error). Note that
|
||||
besides returning the next byte, it may also update source and
|
||||
source_limit fields, thus allowing for buffered operation. */
|
||||
int (*source_read_cb)(struct uzlib_uncomp *uncomp);
|
||||
|
||||
unsigned int tag;
|
||||
unsigned int bitcount;
|
||||
|
||||
/* Destination (output) buffer start */
|
||||
unsigned char *dest_start;
|
||||
/* Current pointer in dest buffer */
|
||||
unsigned char *dest;
|
||||
/* Pointer past the end of the dest buffer, similar to source_limit */
|
||||
unsigned char *dest_limit;
|
||||
|
||||
/* Accumulating checksum */
|
||||
unsigned int checksum;
|
||||
char checksum_type;
|
||||
bool eof;
|
||||
|
||||
int btype;
|
||||
int bfinal;
|
||||
unsigned int curlen;
|
||||
int lzOff;
|
||||
unsigned char *dict_ring;
|
||||
unsigned int dict_size;
|
||||
unsigned int dict_idx;
|
||||
|
||||
TINF_TREE ltree; /* dynamic length/symbol tree */
|
||||
TINF_TREE dtree; /* dynamic distance tree */
|
||||
};
|
||||
|
||||
#include "tinf_compat.h"
|
||||
|
||||
#define TINF_PUT(d, c) \
|
||||
{ \
|
||||
*d->dest++ = c; \
|
||||
if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \
|
||||
}
|
||||
|
||||
unsigned char TINFCC uzlib_get_byte(TINF_DATA *d);
|
||||
|
||||
/* Decompression API */
|
||||
|
||||
void TINFCC uzlib_init(void);
|
||||
void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen);
|
||||
int TINFCC uzlib_uncompress(TINF_DATA *d);
|
||||
int TINFCC uzlib_uncompress_chksum(TINF_DATA *d);
|
||||
|
||||
int TINFCC uzlib_zlib_parse_header(TINF_DATA *d);
|
||||
int TINFCC uzlib_gzip_parse_header(TINF_DATA *d);
|
||||
|
||||
/* Compression API */
|
||||
|
||||
typedef const uint8_t *uzlib_hash_entry_t;
|
||||
|
||||
struct uzlib_comp {
|
||||
struct Outbuf out;
|
||||
|
||||
uzlib_hash_entry_t *hash_table;
|
||||
unsigned int hash_bits;
|
||||
unsigned int dict_size;
|
||||
};
|
||||
|
||||
void TINFCC uzlib_compress(struct uzlib_comp *c, const uint8_t *src, unsigned slen);
|
||||
|
||||
/* Checksum API */
|
||||
|
||||
/* prev_sum is previous value for incremental computation, 1 initially */
|
||||
uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum);
|
||||
/* crc is previous value for incremental computation, 0xffffffff initially */
|
||||
uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* UZLIB_H_INCLUDED */
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||
*
|
||||
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||
*/
|
||||
|
||||
#ifndef UZLIB_CONF_H_INCLUDED
|
||||
#define UZLIB_CONF_H_INCLUDED
|
||||
|
||||
#ifndef UZLIB_CONF_DEBUG_LOG
|
||||
/* Debug logging level 0, 1, 2, etc. */
|
||||
#define UZLIB_CONF_DEBUG_LOG 0
|
||||
#endif
|
||||
|
||||
#ifndef UZLIB_CONF_PARANOID_CHECKS
|
||||
/* Perform extra checks on the input stream, even if they aren't proven
|
||||
to be strictly required (== lack of them wasn't proven to lead to
|
||||
crashes). */
|
||||
#define UZLIB_CONF_PARANOID_CHECKS 0
|
||||
#endif
|
||||
|
||||
#endif /* UZLIB_CONF_H_INCLUDED */
|
|
@ -4070,7 +4070,7 @@ msgstr "nilai sampling keluar dari jangkauan"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "kompilasi script tidak didukung"
|
||||
|
||||
|
|
|
@ -2481,10 +2481,6 @@ msgstr ""
|
|||
msgid "a bytes-like object is required"
|
||||
msgstr ""
|
||||
|
||||
#: lib/embed/abort_.c
|
||||
msgid "abort() called"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/i2cperipheral/I2CPeripheral.c
|
||||
msgid "address out of bounds"
|
||||
msgstr ""
|
||||
|
@ -3061,26 +3057,6 @@ msgstr ""
|
|||
msgid "extra positional arguments given"
|
||||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "f-string expression part cannot include a '#'"
|
||||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "f-string expression part cannot include a backslash"
|
||||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "f-string: empty expression not allowed"
|
||||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "f-string: expecting '}'"
|
||||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "f-string: single '}' is not allowed"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
|
||||
#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c
|
||||
msgid "file must be a file opened in byte mode"
|
||||
|
@ -3358,10 +3334,6 @@ msgstr ""
|
|||
msgid "invalid architecture"
|
||||
msgstr ""
|
||||
|
||||
#: lib/netutils/netutils.c
|
||||
msgid "invalid arguments"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/bitmaptools/__init__.c
|
||||
#, c-format
|
||||
msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32"
|
||||
|
@ -3966,7 +3938,7 @@ msgid "queue overflow"
|
|||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "raw f-strings are not implemented"
|
||||
msgid "raw f-strings are not supported"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/ulab/code/numpy/fft/fft_tools.c
|
||||
|
@ -4027,7 +3999,7 @@ msgstr ""
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
@ -4303,7 +4275,7 @@ msgid "unicode name escapes"
|
|||
msgstr ""
|
||||
|
||||
#: py/parse.c
|
||||
msgid "unindent does not match any outer indentation level"
|
||||
msgid "unindent doesn't match any outer indent level"
|
||||
msgstr ""
|
||||
|
||||
#: py/objstr.c
|
||||
|
|
|
@ -4030,7 +4030,7 @@ msgstr ""
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -4101,7 +4101,7 @@ msgstr "Abtastrate außerhalb der Reichweite"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "kompilieren von Skripten nicht unterstützt"
|
||||
|
||||
|
|
|
@ -4027,7 +4027,7 @@ msgstr ""
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -4071,7 +4071,7 @@ msgstr "sampling rate out of range"
|
|||
msgid "schedule queue full"
|
||||
msgstr "schedule queue full"
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "script compilation not supported"
|
||||
|
||||
|
|
|
@ -2943,7 +2943,7 @@ msgstr ""
|
|||
msgid "schedule stack full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -2950,7 +2950,7 @@ msgstr ""
|
|||
msgid "schedule stack full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -4118,7 +4118,7 @@ msgstr "frecuencia de muestreo fuera de rango"
|
|||
msgid "schedule queue full"
|
||||
msgstr "cola de planificación llena"
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "script de compilación no soportado"
|
||||
|
||||
|
|
|
@ -4076,7 +4076,7 @@ msgstr "pagpili ng rate wala sa sakop"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "script kompilasyon hindi supportado"
|
||||
|
||||
|
|
|
@ -4129,7 +4129,7 @@ msgstr "taux d'échantillonage hors bornes"
|
|||
msgid "schedule queue full"
|
||||
msgstr "file de schédule pleine"
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "compilation de script non supportée"
|
||||
|
||||
|
|
|
@ -4027,7 +4027,7 @@ msgstr ""
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -4092,7 +4092,7 @@ msgstr "frequenza di campionamento fuori intervallo"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "compilazione dello scrip non suportata"
|
||||
|
||||
|
|
|
@ -4050,7 +4050,7 @@ msgstr "サンプリングレートが範囲外"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "スクリプトのコンパイルは非対応"
|
||||
|
||||
|
|
|
@ -4031,7 +4031,7 @@ msgstr ""
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -4075,7 +4075,7 @@ msgstr "bemonsteringssnelheid buiten bereik"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "scriptcompilatie wordt niet ondersteund"
|
||||
|
||||
|
|
|
@ -4047,7 +4047,7 @@ msgstr "częstotliwość próbkowania poza zakresem"
|
|||
msgid "schedule queue full"
|
||||
msgstr ""
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "kompilowanie skryptów nieobsługiwane"
|
||||
|
||||
|
|
|
@ -4131,7 +4131,7 @@ msgstr "Taxa de amostragem fora do intervalo"
|
|||
msgid "schedule queue full"
|
||||
msgstr "fila de espera cheia"
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "compilação de script não suportada"
|
||||
|
||||
|
|
|
@ -4090,7 +4090,7 @@ msgstr "samplingsfrekvens utanför räckvidden"
|
|||
msgid "schedule queue full"
|
||||
msgstr "schemakön full"
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "skriptkompilering stöds inte"
|
||||
|
||||
|
|
|
@ -4090,7 +4090,7 @@ msgstr "qǔyàng lǜ chāochū fànwéi"
|
|||
msgid "schedule queue full"
|
||||
msgstr "shí jiān biǎo duì liè yǐ mǎn"
|
||||
|
||||
#: lib/utils/pyexec.c py/builtinimport.c
|
||||
#: shared/runtime/pyexec.c py/builtinimport.c
|
||||
msgid "script compilation not supported"
|
||||
msgstr "bù zhīchí jiǎoběn biānyì"
|
||||
|
||||
|
|
4
main.c
4
main.c
|
@ -40,8 +40,8 @@
|
|||
#include "py/gc.h"
|
||||
#include "py/stackctrl.h"
|
||||
|
||||
#include "lib/mp-readline/readline.h"
|
||||
#include "lib/utils/pyexec.h"
|
||||
#include "shared/readline/readline.h"
|
||||
#include "shared/runtime/pyexec.h"
|
||||
|
||||
#include "background.h"
|
||||
#include "mpconfigboard.h"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
PROG=mpy-cross.static.exe
|
||||
PROG=mpy-cross.static
|
||||
CROSS_COMPILE = x86_64-w64-mingw32-
|
||||
BUILD=build-static-mingw
|
||||
STATIC_BUILD=1
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "py/mpstate.h"
|
||||
#include "py/gc.h"
|
||||
|
||||
#include "lib/utils/gchelper.h"
|
||||
#include "shared/runtime/gchelper.h"
|
||||
|
||||
#if MICROPY_ENABLE_GC
|
||||
|
||||
|
|
|
@ -41,7 +41,9 @@
|
|||
#define MICROPY_READER_POSIX (1)
|
||||
#define MICROPY_ENABLE_RUNTIME (0)
|
||||
#define MICROPY_ENABLE_GC (1)
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#define MICROPY_STACK_CHECK (1)
|
||||
#endif
|
||||
#define MICROPY_HELPER_LEXER_UNIX (1)
|
||||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||
#define MICROPY_ENABLE_SOURCE_LINE (1)
|
||||
|
@ -54,6 +56,7 @@
|
|||
#define MICROPY_PY_ASYNC_AWAIT (1)
|
||||
#define MICROPY_USE_INTERNAL_PRINTF (0)
|
||||
|
||||
#define MICROPY_PY_FSTRINGS (1)
|
||||
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
|
||||
|
||||
#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
|
||||
|
|
|
@ -69,7 +69,7 @@ endif
|
|||
SRC_C += \
|
||||
main.c \
|
||||
gccollect.c \
|
||||
lib/utils/gchelper_generic.c \
|
||||
shared/runtime/gchelper_generic.c \
|
||||
supervisor/stub/safe_mode.c \
|
||||
supervisor/stub/stack.c \
|
||||
supervisor/shared/translate.c
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<Import Project="$(PyMsvcDir)sources.props" />
|
||||
<ItemGroup>
|
||||
<ClCompile Include="@(PyCoreSource)" />
|
||||
<ClCompile Include="$(PyBaseDir)lib/utils/gchelper_generic.c" >
|
||||
<ClCompile Include="$(PyBaseDir)shared/runtime/gchelper_generic.c" >
|
||||
<PreprocessorDefinitions>MICROPY_GCREGS_SETJMP</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(PyBaseDir)mpy-cross\gccollect.c"/>
|
||||
|
|
|
@ -60,7 +60,7 @@ HAL_DIR=hal/$(MCU_SERIES)
|
|||
INC += -I. \
|
||||
-I../.. \
|
||||
-I../lib/mp-readline \
|
||||
-I../lib/timeutils \
|
||||
-I../shared/timeutils \
|
||||
-Iasf4/$(CHIP_FAMILY) \
|
||||
-Iasf4/$(CHIP_FAMILY)/hal/include \
|
||||
-Iasf4/$(CHIP_FAMILY)/hal/utils/include \
|
||||
|
@ -364,11 +364,11 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
|
|||
|
||||
SRC_QSTR += $(HEADER_BUILD)/sdiodata.h
|
||||
$(HEADER_BUILD)/sdiodata.h: tools/mksdiodata.py | $(HEADER_BUILD)
|
||||
$(Q)$(PYTHON3) $< > $@
|
||||
$(Q)$(PYTHON) $< > $@
|
||||
|
||||
SRC_QSTR += $(HEADER_BUILD)/candata.h
|
||||
$(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD)
|
||||
$(Q)$(PYTHON3) $< > $@
|
||||
$(Q)$(PYTHON) $< > $@
|
||||
|
||||
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
|
||||
# Sources that only hold QSTRs after pre-processing.
|
||||
|
@ -380,7 +380,7 @@ $(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE)
|
|||
$(STEPECHO) "LINK $@"
|
||||
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs
|
||||
$(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group
|
||||
$(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE)
|
||||
$(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE)
|
||||
|
||||
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
|
||||
$(STEPECHO) "Create $@"
|
||||
|
@ -388,7 +388,7 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf
|
|||
|
||||
$(BUILD)/firmware.uf2: $(BUILD)/firmware.bin
|
||||
$(STEPECHO) "Create $@"
|
||||
$(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^
|
||||
$(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^
|
||||
|
||||
include $(TOP)/py/mkrules.mk
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "shared-bindings/busio/UART.h"
|
||||
|
||||
#include "mpconfigport.h"
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
|
||||
#include "common-hal/canio/__init__.h"
|
||||
#include "common-hal/canio/Listener.h"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "shared-bindings/i2cperipheral/I2CPeripheral.h"
|
||||
#include "common-hal/busio/I2C.h"
|
||||
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/runtime.h"
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "lib/utils/context_manager_helpers.h"
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/runtime/context_manager_helpers.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
|
||||
#include "shared-bindings/imagecapture/ParallelImageCapture.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "lib/timeutils/timeutils.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "shared-bindings/rtc/__init__.h"
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "py/runtime.h"
|
||||
#include "lib/oofatfs/ff.h" /* FatFs lower layer API */
|
||||
#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */
|
||||
#include "lib/timeutils/timeutils.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
|
||||
#if CIRCUITPY_RTC
|
||||
#include "shared-bindings/rtc/RTC.h"
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "lib/mp-readline/readline.h"
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
#include "shared/readline/readline.h"
|
||||
#include "shared/runtime/interrupt_char.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/mpstate.h"
|
||||
#include "py/runtime.h"
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue