Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
85c02166
Commit
85c02166
authored
Dec 04, 2023
by
stijn
Committed by
Damien George
Dec 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py/modsys: Implement optional sys.intern.
Signed-off-by:
stijn
<
stijn@ignitron.net
>
parent
05d3b223
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
4 deletions
+32
-4
py/modsys.c
py/modsys.c
+8
-0
py/mpconfig.h
py/mpconfig.h
+5
-0
tests/basics/sys1.py
tests/basics/sys1.py
+15
-0
tests/unix/extra_coverage.py.exp
tests/unix/extra_coverage.py.exp
+4
-4
No files found.
py/modsys.c
View file @
85c02166
...
...
@@ -147,6 +147,10 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM);
MP_DEFINE_STR_OBJ
(
mp_sys_executable_obj
,
""
);
#endif
#if MICROPY_PY_SYS_INTERN
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_sys_intern_obj
,
mp_obj_str_intern_checked
);
#endif
// exit([retval]): raise SystemExit, with optional argument given to the exception
STATIC
mp_obj_t
mp_sys_exit
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
if
(
n_args
==
0
)
{
...
...
@@ -293,6 +297,10 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
#endif
#endif
#if MICROPY_PY_SYS_INTERN
{
MP_ROM_QSTR
(
MP_QSTR_intern
),
MP_ROM_PTR
(
&
mp_sys_intern_obj
)
},
#endif
#if MICROPY_PY_SYS_EXIT
{
MP_ROM_QSTR
(
MP_QSTR_exit
),
MP_ROM_PTR
(
&
mp_sys_exit_obj
)
},
#endif
...
...
py/mpconfig.h
View file @
85c02166
...
...
@@ -1434,6 +1434,11 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_EXECUTABLE (0)
#endif
// Whether to provide "sys.intern"
#ifndef MICROPY_PY_SYS_INTERN
#define MICROPY_PY_SYS_INTERN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
#endif
// Whether to provide "sys.exit" function
#ifndef MICROPY_PY_SYS_EXIT
#define MICROPY_PY_SYS_EXIT (1)
...
...
tests/basics/sys1.py
View file @
85c02166
...
...
@@ -23,3 +23,18 @@ if hasattr(sys.implementation, '_mpy'):
else
:
# Effectively skip subtests
print
(
int
)
try
:
print
(
sys
.
intern
(
'micropython'
)
==
'micropython'
)
has_intern
=
True
except
AttributeError
:
has_intern
=
False
print
(
True
)
if
has_intern
:
try
:
print
(
sys
.
intern
(
0
))
except
TypeError
:
print
(
True
)
else
:
print
(
True
)
tests/unix/extra_coverage.py.exp
View file @
85c02166
...
...
@@ -66,10 +66,10 @@ micropython machine math
argv atexit byteorder exc_info
executable exit getsizeof implementation
maxsize modules path platform
p
rint_exception ps1 ps2
stderr stdin stdout tracebacklimi
t
version version_info
intern maxsize modules path
p
latform print_exception ps1
ps2 stderr stdin stdou
t
tracebacklimit
version version_info
ementation
# attrtuple
(start=1, stop=2, step=3)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment