Skip to content

Commit 85c0216

Browse files
stinosdpgeorge
authored andcommitted
py/modsys: Implement optional sys.intern.
Signed-off-by: stijn <stijn@ignitron.net>
1 parent 05d3b22 commit 85c0216

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

py/modsys.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM);
147147
MP_DEFINE_STR_OBJ(mp_sys_executable_obj, "");
148148
#endif
149149

150+
#if MICROPY_PY_SYS_INTERN
151+
MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_intern_obj, mp_obj_str_intern_checked);
152+
#endif
153+
150154
// exit([retval]): raise SystemExit, with optional argument given to the exception
151155
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
152156
if (n_args == 0) {
@@ -293,6 +297,10 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
293297
#endif
294298
#endif
295299

300+
#if MICROPY_PY_SYS_INTERN
301+
{ MP_ROM_QSTR(MP_QSTR_intern), MP_ROM_PTR(&mp_sys_intern_obj) },
302+
#endif
303+
296304
#if MICROPY_PY_SYS_EXIT
297305
{ MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&mp_sys_exit_obj) },
298306
#endif

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,11 @@ typedef double mp_float_t;
14341434
#define MICROPY_PY_SYS_EXECUTABLE (0)
14351435
#endif
14361436

1437+
// Whether to provide "sys.intern"
1438+
#ifndef MICROPY_PY_SYS_INTERN
1439+
#define MICROPY_PY_SYS_INTERN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
1440+
#endif
1441+
14371442
// Whether to provide "sys.exit" function
14381443
#ifndef MICROPY_PY_SYS_EXIT
14391444
#define MICROPY_PY_SYS_EXIT (1)

tests/basics/sys1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@
2323
else:
2424
# Effectively skip subtests
2525
print(int)
26+
27+
try:
28+
print(sys.intern('micropython') == 'micropython')
29+
has_intern = True
30+
except AttributeError:
31+
has_intern = False
32+
print(True)
33+
34+
if has_intern:
35+
try:
36+
print(sys.intern(0))
37+
except TypeError:
38+
print(True)
39+
else:
40+
print(True)

tests/unix/extra_coverage.py.exp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ micropython machine math
6666

6767
argv atexit byteorder exc_info
6868
executable exit getsizeof implementation
69-
maxsize modules path platform
70-
print_exception ps1 ps2
71-
stderr stdin stdout tracebacklimit
72-
version version_info
69+
intern maxsize modules path
70+
platform print_exception ps1
71+
ps2 stderr stdin stdout
72+
tracebacklimit version version_info
7373
ementation
7474
# attrtuple
7575
(start=1, stop=2, step=3)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy