8000 py/persistentcode: Introduce MICROPY_PERSISTENT_CODE_SAVE_FILE option. · micropython/micropython@cb30928 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb30928

Browse files
devnexendpgeorge
authored andcommitted
py/persistentcode: Introduce MICROPY_PERSISTENT_CODE_SAVE_FILE option.
This should be enabled when the mp_raw_code_save_file function is needed. It is enabled for mpy-cross, and a check for defined(__APPLE__) is added to cover Mac M1 systems.
1 parent cb8e2f0 commit cb30928

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

mpy-cross/mpconfigport.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#define MICROPY_PERSISTENT_CODE_LOAD (0)
3131
#define MICROPY_PERSISTENT_CODE_SAVE (1)
3232

33+
#ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE
34+
#if defined(__i386__) || defined(__x86_64__) || defined(_WIN32) || defined(__unix__) || defined(__APPLE__)
35+
#define MICROPY_PERSISTENT_CODE_SAVE_FILE (1)
36+
#else
37+
#define MICROPY_PERSISTENT_CODE_SAVE_FILE (0)
38+
#endif
39+
#endif
40+
3341
#define MICROPY_EMIT_X64 (1)
3442
#define MICROPY_EMIT_X86 (1)
3543
#define MICROPY_EMIT_THUMB (1)

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@
283283
#define MICROPY_PERSISTENT_CODE_SAVE (0)
284284
#endif
285285

286+
// Whether to support saving persistent code to a file via mp_raw_code_save_file
287+
#ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE
288+
#define MICROPY_PERSISTENT_CODE_SAVE_FILE (0)
289+
#endif
290+
286291
// Whether generated code can persist independently of the VM/runtime instance
287292
// This is enabled automatically when needed by other features
288293
#ifndef MICROPY_PERSISTENT_CODE

py/persistentcode.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,7 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) {
825825
save_raw_code(print, rc, &qw);
826826
}
827827

828-
// here we define mp_raw_code_save_file depending on the port
829-
// TODO abstract this away properly
830-
831-
#if defined(__i386__) || defined(__x86_64__) || defined(_WIN32) || defined(__unix__)
828+
#if MICROPY_PERSISTENT_CODE_SAVE_FILE
832829

833830
#include <unistd.h>
834831
#include <sys/stat.h>
@@ -853,8 +850,6 @@ void mp_raw_code_save_file(mp_raw_code_t *rc, const char *filename) {
853850
MP_THREAD_GIL_ENTER();
854851
}
855852

856-
#else
857-
#error mp_raw_code_save_file not implemented for this platform
858-
#endif
853+
#endif // MICROPY_PERSISTENT_CODE_SAVE_FILE
859854

860855
#endif // MICROPY_PERSISTENT_CODE_SAVE

0 commit comments

Comments
 (0)
0