@@ -218,12 +218,10 @@ void supervisor_execution_status(void) {
218
218
}
219
219
#endif
220
220
221
- #define STRING_LIST (...) {__VA_ARGS__, ""}
222
-
223
221
// Look for the first file that exists in the list of filenames, using mp_import_stat().
224
222
// Return its index. If no file found, return -1.
225
- STATIC const char * first_existing_file_in_list (const char * const * filenames ) {
226
- for (int i = 0 ; filenames [ i ] != ( char * ) "" ; i ++ ) {
223
+ STATIC const char * first_existing_file_in_list (const char * const * filenames , size_t n_filenames ) {
224
+ for (size_t i = 0 ; i < n_filenames ; i ++ ) {
227
225
mp_import_stat_t stat = mp_import_stat (filenames [i ]);
228
226
if (stat == MP_IMPORT_STAT_FILE ) {
229
227
return filenames [i ];
@@ -232,11 +230,11 @@ STATIC const char *first_existing_file_in_list(const char *const *filenames) {
232
230
return NULL ;
233
231
}
234
232
235
- STATIC bool maybe_run_list (const char * const * filenames ) {
233
+ STATIC bool maybe_run_list (const char * const * filenames , size_t n_filenames ) {
236
234
_exec_result .return_code = 0 ;
237
235
_exec_result .exception = MP_OBJ_NULL ;
238
236
_exec_result .exception_line = 0 ;
239
- _current_executing_filename = first_existing_file_in_list (filenames );
237
+ _current_executing_filename = first_existing_file_in_list (filenames , n_filenames );
240
238
if (_current_executing_filename == NULL ) {
241
239
return false;
242
240
}
@@ -391,12 +389,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
391
389
filesystem_flush ();
392
390
}
393
391
if (safe_mode == NO_SAFE_MODE && !autoreload_pending ()) {
394
- static const char * const supported_filenames [] = STRING_LIST (
395
- "code.txt" , "code.py" , "main.py" , "main.txt" );
392
+ static const char * const supported_filenames [] = {
393
+ "code.txt" , "code.py" , "main.py" , "main.txt"
394
+ };
396
395
#if CIRCUITPY_FULL_BUILD
397
- static const char * const double_extension_filenames [] = STRING_LIST (
396
+ static const char * const double_extension_filenames [] = {
398
397
"code.txt.py" , "code.py.txt" , "code.txt.txt" ,"code.py.py" ,
399
- "main.txt.py" , "main.py.txt" , "main.txt.txt" ,"main.py.py" );
398
+ "main.txt.py" , "main.py.txt" , "main.txt.txt" ,"main.py.py"
399
+ };
400
400
#endif
401
401
402
402
supervisor_allocation * heap = allocate_remaining_memory ();
@@ -410,26 +410,27 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
410
410
411
411
// Check if a different run file has been allocated
412
412
if (next_code_allocation ) {
413
- ((next_code_info_t * )next_code_allocation -> ptr )-> options &= ~ SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
414
- next_code_options = (( next_code_info_t * ) next_code_allocation -> ptr ) -> options ;
415
- if ((( next_code_info_t * ) next_code_allocation -> ptr ) -> filename [ 0 ] != '\0' ) {
416
- const char * next_list [] = {(( next_code_info_t * ) next_code_allocation -> ptr ) -> filename , "" };
413
+ next_code_info_t * info = ((next_code_info_t * )next_code_allocation -> ptr );
414
+ info -> options &= ~ SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
415
+ next_code_options = info -> options ;
416
+ if ( info -> filename [ 0 ] != '\0' ) {
417
417
// This is where the user's python code is actually executed:
418
- found_main = maybe_run_list (next_list );
418
+ const char * const filenames [] = { info -> filename };
419
+ found_main = maybe_run_list (filenames , MP_ARRAY_SIZE (filenames ));
419
420
if (!found_main ) {
420
- serial_write ((( next_code_info_t * ) next_code_allocation -> ptr ) -> filename );
421
+ serial_write (info -> filename );
421
422
serial_write_compressed (translate (" not found.\n" ));
422
423
}
423
424
}
424
425
}
425
426
// Otherwise, default to the standard list of filenames
426
427
if (!found_main ) {
427
428
// This is where the user's python code is actually executed:
428
- found_main = maybe_run_list (supported_filenames );
429
+ found_main = maybe_run_list (supported_filenames , MP_ARRAY_SIZE ( supported_filenames ) );
429
430
// If that didn't work, double check the extensions
430
431
#if CIRCUITPY_FULL_BUILD
431
432
if (!found_main ) {
432
- found_main = maybe_run_list (double_extension_filenames );
433
+ found_main = maybe_run_list (double_extension_filenames , MP_ARRAY_SIZE ( double_extension_filenames ) );
433
434
if (found_main ) {
434
435
serial_write_compressed (translate ("WARNING: Your code filename has two extensions\n" ));
435
436
}
@@ -741,7 +742,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
741
742
&& safe_mode == NO_SAFE_MODE
742
743
&& MP_STATE_VM (vfs_mount_table ) != NULL ;
743
744
744
- static const char * const boot_py_filenames [] = STRING_LIST ( "boot.py" , "boot.txt" ) ;
745
+ static const char * const boot_py_filenames [] = { "boot.py" , "boot.txt" } ;
745
746
746
747
// Do USB setup even if boot.py is not run.
747
748
@@ -778,7 +779,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
778
779
port_boot_info ();
779
780
#endif
780
781
781
- bool found_boot = maybe_run_list (boot_py_filenames );
782
+ bool found_boot = maybe_run_list (boot_py_filenames , MP_ARRAY_SIZE ( boot_py_filenames ) );
782
783
(void )found_boot ;
783
784
784
785
0 commit comments