Add .attr attribute which forwards to self->fun.
A closure is intended to wrap around a function object, so forward any
requested attributes to the wrapped function object.
Signed-off-by: Michael Bentley <mikebentley15@gmail.com>
Replaces preprocessor macro for SDRAM option from #ifdef to #if in order to
allow always setting the define `MICROPY_HW_SDRAM_AVAIL` just with the
appropriate value 0/1. This eliminates one `if` in the Makefile.
The main aim of this change is to reduce the number of heap allocations
when writing data to a stream. This is done in two ways:
1. Eliminate appending of data when .write() is called multiple times
before calling .drain(). With this commit, the data is written out
immediately if the underlying stream is not blocked, so there is no
accumulation of the data in a temporary buffer.
2. Eliminate copying of non-bytes objects passed to .write(). Prior to
this commit, passing a bytearray or memoryview to .write() would always
result in a copy of it being made and turned into a bytes object. That
won't happen now if the underlying stream is not blocked.
Also, this change makes .write () more closely implement the CPython
documented semantics: "The method attempts to write the data to the
underlying socket immediately. If that fails, the data is queued in an
internal write buffer until it can be sent."
Add esp32.wake_on_ulp() to give access to esp_sleep_enable_ulp_wakeup(),
which is needed to allow the ULP co-processor to wake the main CPU from
deep sleep.
Allow esp32.ULP.load_binary() to use the maximum amount of memory available
again, which is 2040 bytes unless MICROPY_HW_RTC_USER_MEM_MAX is
customized.
This value regressed in 3d49b157b8
Using it for the rx-timeout. The value is given as ms, which is then
converted to character times. A value of less than a character time will
cause the rx call to return immediately after 1 character, which may be
inefficient at high transmission rates.
Addresses #8778.
Prior to this commit, complex("j") would return 0j, and complex("nanj")
would return nan+0j. This commit makes sure "j" is tested for after
parsing the number (nan, inf or a decimal), and also supports the case of
"j" on its own.
Signed-off-by: Damien George <damien@micropython.org>
This changes the btree implementation to use the buffer protocol for
reading key/values in all methods. `str` and `bytes` objects are not the
only bytes-like objects that could be used.
Documentation and tests are also updated.
Addresses issue #8748.
Signed-off-by: David Lechner <david@pybricks.com>
This separates extmod source files from `py.mk`. Previously, `py.mk`
assumed that every consumer of the py/ directory also wanted to include
extmod/. However, this is not the case. For example, building mpy-cross
uses py/ but doesn't need extmod/.
This commit moves all extmod-specific items from `py.mk` to `extmod.mk` and
explicitly includes `extmod.mk` in ports that use it.
Signed-off-by: David Lechner <david@pybricks.com>
The following changes are made:
- Guard entire file with MICROPY_PY_LWIP, so it can be included in the
build while still being disabled (for consistency with other extmod
modules).
- Add modlwip.c to list of all extmod source in py/py.mk and
extmod/extmod.cmake so all ports can easily use it.
- Move generic modlwip GIT_SUBMODULES build configuration code from
ports/rp2/CMakeLists.txt to extmod/extmod.cmake, so it can be reused by
other ports.
- Remove now unnecessary inclusion of modlwip.c in EXTMOD_SRC_C in esp8266
port, and in SRC_QSTR in mimxrt port.
Signed-off-by: Damien George <damien@micropython.org>
This new logic tracks when an unconditional jump/raise occurs in the
emitted code stream (bytecode or native machine code) and suppresses all
subsequent code, until a label is assigned. This eliminates a lot of
cases of dead code, with relatively simple logic.
This commit combined with the previous one (that removed the existing
dead-code finding logic) has the following code size change:
bare-arm: -16 -0.028%
minimal x86: -60 -0.036%
unix x64: -368 -0.070%
unix nanbox: -80 -0.017%
stm32: -204 -0.052% PYBV10
cc3200: +0 +0.000%
esp8266: -232 -0.033% GENERIC
esp32: -224 -0.015% GENERIC[incl -40(data)]
mimxrt: -192 -0.054% TEENSY40
renesas-ra: -200 -0.032% RA6M2_EK
nrf: +28 +0.015% pca10040
rp2: -256 -0.050% PICO
samd: -12 -0.009% ADAFRUIT_ITSYBITSY_M4_EXPRESS
Signed-off-by: Damien George <damien@micropython.org>
The search in these cases should include all finally handlers that are
after the current ip. If a handler starts at exactly ip then it is
considered "after" the ip. This can happen when END_FINALLY is followed
immediately by a finally handler (from a different finally).
Consider the function:
def f():
try:
return 0
finally:
print(1)
The current bytecode emitter generates the following code:
00 SETUP_FINALLY 5
02 LOAD_CONST_SMALL_INT 0
03 RETURN_VALUE
04 LOAD_CONST_NONE ****
05 LOAD_GLOBAL print
07 LOAD_CONST_SMALL_INT 1
08 CALL_FUNCTION n=1 nkw=0
10 POP_TOP
11 END_FINALLY
12 LOAD_CONST_NONE
13 RETURN_VALUE
The LOAD_CONST_NONE marked with **** is dead code because it follows a
RETURN_VALUE, and nothing jumps to this LOAD_CONST_NONE. If the emitter
could remove this this dead code it would produce:
00 SETUP_FINALLY 4
02 LOAD_CONST_SMALL_INT 0
03 RETURN_VALUE
04 LOAD_GLOBAL print
06 LOAD_CONST_SMALL_INT 1
07 CALL_FUNCTION n=1 nkw=0
09 POP_TOP
10 END_FINALLY
11 LOAD_CONST_NONE
12 RETURN_VALUE
In this case the finally block (which starts at offset 4) immediately
follows the RETURN_VALUE. When RETURN_VALUE executes ip will point to
offset 4 in the bytecode (because the dispatch of the opcode does *ip++)
and so the finally handler will only be found if a >= comparison is used.
It's a similar story for break/continue:
while True:
try:
break
finally:
print(1)
Although technically in this case the > comparison still works because the
extra byte from the UNWIND_JUMP (encoding the number of exception handlers
to unwind) doesn't have a *ip++ (just a *ip) so ip remains pointing within
the UNWIND_JUMP opcode, and not at the start of the following finally
handler. Nevertheless, the change is made to use >= for consistency with
the RETURN_VALUE change.
Signed-off-by: Damien George <damien@micropython.org>
Move the "delete placeholder" to the end, so it's not the first thing the
reader does. And add extra text calling out "how do I?" questions.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The WLAN.config() method now supports "ssid", "security" and "key" as
aliases to the existing "essid", "authmode" and "password", which are now
deprecated. The help text and setup helper are also updated.
Addresses issue #8083.
The WLAN.config() method now supports "ssid", "security" and "key" as
aliases to the existing "essid", "authmode" and "password", which are now
deprecated.
Addresses issue #8083.
Rename WLAN keyword args to scan(), connect() and config() to be more
consistent across ports and WLAN drivers. This change is backwards
compatible and will support obsolete keyword args, except for positional
"essid" which is now deprecated in favor of "ssid".
The changed argument names are
- "essid" changed to "ssid"
- "auth" or "authmode" changed to "security"
- "password" changed to "key"
Addresses issue #8083.
The CI scripts were using a PPA to get a backported version of uncrustify
on Ubuntu 20.04. However, this causes CI to intermittently fail due to
connection issues to launchpad.net or the key server.
Ubuntu 22.04 has a newer version of uncrustify removing the need for the
PPA. Ubuntu 22.04 is now in beta on GitHub actions, so it can be used.
Signed-off-by: David Lechner <david@pybricks.com>
Updates the Zephyr port build instructions and CI to use the latest Zephyr
release tag.
Tested on frdm_k64f.
Signed-off-by: Maureen Helm <maureen.helm@intel.com>