From 17aaba4da9ad3c4fe62a5afae7526ad4e3dfa9b1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 16 Sep 2021 15:48:13 -0700 Subject: [PATCH] chips/samd21: Prepare for picolibc stdio change 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 --- chips/samd21/ao-stdio.c | 13 +++++++++++++ chips/samd21/snek-eeprom.c | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/chips/samd21/ao-stdio.c b/chips/samd21/ao-stdio.c index 22f4aef..de8ef96 100644 --- a/chips/samd21/ao-stdio.c +++ b/chips/samd21/ao-stdio.c @@ -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 diff --git a/chips/samd21/snek-eeprom.c b/chips/samd21/snek-eeprom.c index fcebcb4..df33357 100644 --- a/chips/samd21/snek-eeprom.c +++ b/chips/samd21/snek-eeprom.c @@ -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 @@ -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; }