Skip to content

Commit ac3fb97

Browse files
committed
unix/variants: Enable seeding random module on import in dev, coverage.
Signed-off-by: Damien George <damien@micropython.org>
1 parent d2f018b commit ac3fb97

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

ports/unix/mpconfigport.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ void mp_unix_mark_exec(void);
253253
#define MICROPY_FORCE_PLAT_ALLOC_EXEC (1)
254254
#endif
255255

256+
#ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC
257+
// Support for seeding the random module on import.
258+
#include <stddef.h>
259+
void mp_hal_get_random(size_t n, void *buf);
260+
static inline unsigned long mp_urandom_seed_init(void) {
261+
unsigned long r;
262+
mp_hal_get_random(sizeof(r), &r);
263+
return r;
264+
}
265+
#endif
266+
256267
#ifdef __linux__
257268
// Can access physical memory using /dev/mem
258269
#define MICROPY_PLAT_DEV_MEM (1)

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)
3232

3333
// Disable some features that come enabled by default with the feature level.
34-
#define MICROPY_MODULE_BUILTIN_INIT (0)
3534
#define MICROPY_PY_BUILTINS_EXECFILE (0)
3635
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
3736
#define MICROPY_PY_USELECT (0)
@@ -50,6 +49,7 @@
5049
#define MICROPY_PY_SYS_GETSIZEOF (1)
5150
#define MICROPY_PY_SYS_TRACEBACKLIMIT (1)
5251
#define MICROPY_PY_IO_BUFFEREDWRITER (1)
52+
#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (mp_urandom_seed_init())
5353
#define MICROPY_PY_URE_DEBUG (1)
5454
#define MICROPY_PY_URE_MATCH_GROUPS (1)
5555
#define MICROPY_PY_URE_MATCH_SPAN_START_END (1)

ports/unix/variants/dev/mpconfigvariant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)
2929

3030
// Disable some features that come enabled by default with the feature level.
31-
#define MICROPY_MODULE_BUILTIN_INIT (0)
3231
#define MICROPY_PY_BUILTINS_EXECFILE (0)
3332
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
3433
#define MICROPY_PY_USELECT (0)
@@ -37,3 +36,4 @@
3736
#define MICROPY_REPL_EMACS_WORDS_MOVE (1)
3837
#define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (1)
3938
#define MICROPY_PY_SYS_SETTRACE (1)
39+
#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (mp_urandom_seed_init())

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