micropython: Document heap_lock, heap_unlock.

Fixes https://github.com/pybricks/pybricks-api/issues/116
This commit is contained in:
Laurens Valk
2022-11-29 13:51:34 +01:00
parent 1ae0a9005f
commit 9b314777e0
3 changed files with 31 additions and 5 deletions
+8 -4
View File
@@ -6,16 +6,20 @@
.. autofunction:: micropython.const
.. autofunction:: micropython.opt_level
.. autofunction:: micropython.heap_lock
.. autofunction:: micropython.heap_unlock
.. autofunction:: micropython.kbd_intr
.. autofunction:: micropython.mem_info
.. autofunction:: micropython.opt_level
.. autofunction:: micropython.qstr_info
.. autofunction:: micropython.stack_use
.. autofunction:: micropython.kbd_intr
Examples
---------------------
+2
View File
@@ -149,6 +149,8 @@ def test_from_micropython_import():
completions: list[CompletionItem] = json.loads(complete(code, 1, len(code) + 1))
assert [c["insertText"] for c in completions] == [
"const",
"heap_lock",
"heap_unlock",
"kbd_intr",
"mem_info",
"opt_level",
+21 -1
View File
@@ -108,7 +108,27 @@ def stack_use() -> int:
"""
# REVISIT: Skipping heap lock funcs for now
def heap_lock() -> None:
"""
heap_lock()
Locks the heap. When locked, no memory allocation can occur. A
``MemoryError`` will be raised if any heap allocation is attempted.
"""
def heap_unlock() -> int:
"""
heap_unlock() -> int
Unlocks the heap. Memory allocation is now allowed again.
If :func:`heap_lock()` was called multiple times, :func:`heap_unlock()`
must be called the same number of times to make the heap available again.
Returns:
The lock depth after unlocking. It is ``0`` once it is unlocked.
"""
def kbd_intr(chr: int) -> None: