Skip to content

Commit

Permalink
py/persistentcode: Introduce MICROPY_PERSISTENT_CODE_SAVE_FILE option.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devnexen authored and dpgeorge committed Jan 30, 2021
1 parent cb8e2f0 commit cb30928
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions mpy-cross/mpconfigport.h
Expand Up @@ -30,6 +30,14 @@
#define MICROPY_PERSISTENT_CODE_LOAD (0)
#define MICROPY_PERSISTENT_CODE_SAVE (1)

#ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE
#if defined(__i386__) || defined(__x86_64__) || defined(_WIN32) || defined(__unix__) || defined(__APPLE__)
#define MICROPY_PERSISTENT_CODE_SAVE_FILE (1)
#else
#define MICROPY_PERSISTENT_CODE_SAVE_FILE (0)
#endif
#endif

#define MICROPY_EMIT_X64 (1)
#define MICROPY_EMIT_X86 (1)
#define MICROPY_EMIT_THUMB (1)
Expand Down
5 changes: 5 additions & 0 deletions py/mpconfig.h
Expand Up @@ -283,6 +283,11 @@
#define MICROPY_PERSISTENT_CODE_SAVE (0)
#endif

// Whether to support saving persistent code to a file via mp_raw_code_save_file
#ifndef MICROPY_PERSISTENT_CODE_SAVE_FILE
#define MICROPY_PERSISTENT_CODE_SAVE_FILE (0)
#endif

// Whether generated code can persist independently of the VM/runtime instance
// This is enabled automatically when needed by other features
#ifndef MICROPY_PERSISTENT_CODE
Expand Down
9 changes: 2 additions & 7 deletions py/persistentcode.c
Expand Up @@ -825,10 +825,7 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) {
save_raw_code(print, rc, &qw);
}

// here we define mp_raw_code_save_file depending on the port
// TODO abstract this away properly

#if defined(__i386__) || defined(__x86_64__) || defined(_WIN32) || defined(__unix__)
#if MICROPY_PERSISTENT_CODE_SAVE_FILE

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

#else
#error mp_raw_code_save_file not implemented for this platform
#endif
#endif // MICROPY_PERSISTENT_CODE_SAVE_FILE

#endif // MICROPY_PERSISTENT_CODE_SAVE

0 comments on commit cb30928

Please sign in to comment.