Skip to content

Commit 410757f

Browse files
committed
unix/mphalport.h: Fix build when MICROPY_USE_READLINE=0.
If the built-in input() is enabled (which it is by default) then it needs some form of readline, so supply it with one when MICROPY_USE_READLINE=0. Fixes issue micropython#5658.
1 parent a9ce8df commit 410757f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ports/unix/mphalport.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,21 @@ void mp_hal_set_interrupt_char(char c);
3535
void mp_hal_stdio_mode_raw(void);
3636
void mp_hal_stdio_mode_orig(void);
3737

38-
#if MICROPY_USE_READLINE == 1 && MICROPY_PY_BUILTINS_INPUT
38+
#if MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 0
39+
40+
#include <malloc.h>
41+
#include "py/misc.h"
42+
#include "input.h"
43+
#define mp_hal_readline mp_hal_readline
44+
static inline int mp_hal_readline(vstr_t *vstr, const char *p) {
45+
char *line = prompt((char*)p);
46+
vstr_add_str(vstr, line);
47+
free(line);
48+
return 0;
49+
}
50+
51+
#elif MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 1
52+
3953
#include "py/misc.h"
4054
#include "lib/mp-readline/readline.h"
4155
// For built-in input() we need to wrap the standard readline() to enable raw mode
@@ -46,6 +60,7 @@ static inline int mp_hal_readline(vstr_t *vstr, const char *p) {
4660
mp_hal_stdio_mode_orig();
4761
return ret;
4862
}
63+
4964
#endif
5065

5166
// TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep:

0 commit comments

Comments
 (0)