Skip to content

Commit

Permalink
chips/samd21: Prepare for picolibc stdio change
Browse files Browse the repository at this point in the history
Picolibc is changing how stdio is initialized, removing the __iob
array and using three globals (stdin/stdout/stderr). Prepare for that
by allowing either new or old libraries to work with snek.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Sep 16, 2021
1 parent 8f5c7c8 commit 17aaba4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions chips/samd21/ao-stdio.c
Expand Up @@ -22,4 +22,17 @@

static FILE __stdio = FDEV_SETUP_STREAM(ao_usb_putc, snek_io_getc, ao_usb_flush, _FDEV_SETUP_RW);

#ifdef PICOLIBC_STDIO_GLOBALS
#ifdef __strong_reference
#define STDIO_ALIAS(x) __strong_reference(stdin, x);
#else
#define STDIO_ALIAS(x) FILE *const x = &__stdio;
#endif

FILE *const stdin = &__stdio;
STDIO_ALIAS(stdout);
STDIO_ALIAS(stderr);

#else
FILE *const __iob[3] = { &__stdio, &__stdio, &__stdio };
#endif
6 changes: 3 additions & 3 deletions chips/samd21/snek-eeprom.c
Expand Up @@ -73,8 +73,8 @@ snek_eeprom_load(void)
{
snek_interactive = false;
ao_flash_read_init();
save_getc = __iob[0]->get;
__iob[0]->get = snek_eeprom_getchar;
save_getc = stdin->get;
stdin->get = snek_eeprom_getchar;
}

int
Expand All @@ -87,6 +87,6 @@ snek_eeprom_getchar(FILE *stream)
return c;
}
snek_interactive = true;
__iob[0]->get = save_getc;
stdin->get = save_getc;
return EOF;
}

0 comments on commit 17aaba4

Please sign in to comment.