8000 py/mpconfig.h: Add MICROPY_STREAMS_POSIX_API setting. · sparkfun/circuitpython@61e77a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 61e77a4

Browse files
committed
py/mpconfig.h: Add MICROPY_STREAMS_POSIX_API setting.
To filter out even prototypes of mp_stream_posix_*() functions, which require POSIX types like ssize_t & off_t, which may be not available in some ports.
1 parent 58d9d85 commit 61e77a4

File tree

5 files changed

+13
-1
lines changed
  • esp8266
  • py
    • stream.c
  • unix

5 files changed

+13
-1
lines changed

esp8266/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#define MICROPY_WARNINGS (1)
7676
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
7777
#define MICROPY_STREAMS_NON_BLOCK (1)
78+
#define MICROPY_STREAMS_POSIX_API (1)
7879
#define MICROPY_MODULE_FROZEN_STR (1)
7980
#define MICROPY_MODULE_FROZEN_MPY (1)
8081
#define MICROPY_MODULE_FROZEN_LEXER mp_lexer_new_from_str32

< 8000 code>‎py/mpconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ typedef double mp_float_t;
522522
#define MICROPY_STREAMS_NON_BLOCK (0)
523523
#endif
524524

525+
// Whether to provide stream functions with POSIX-like signatures
526+
// (useful for porting existing libraries to MicroPython).
527+
#ifndef MICROPY_STREAMS_POSIX_API
528+
#define MICROPY_STREAMS_POSIX_API (0)
529+
#endif
530+
525531
// Whether to call __init__ when importing builtin modules for the first time
526532
#ifndef MICROPY_MODULE_BUILTIN_INIT
527533
#define MICROPY_MODULE_BUILTIN_INIT (0)

py/stream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) {
511511
}
512512
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl);
513513

514+
#if MICROPY_STREAMS_POSIX_API
514515
/*
515516
* POSIX-like functions
516517
*
@@ -519,7 +520,6 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl);
519520
* POSIX-compatible software to work with MicroPython streams.
520521
*/
521522

522-
523523
// errno-like variable. If any of the functions below returned with error
524524
// status, this variable will contain error no.
525525
int mp_stream_errno;
@@ -568,3 +568,5 @@ int mp_stream_posix_fsync(mp_obj_t stream) {
568568
}
569569
return res;
570570
}
571+
572+
#endif

py/stream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf, mp_uint_t size, int *errcode,
8484

8585
void mp_stream_write_adaptor(void *self, const char *buf, size_t len);
8686

87+
#if MICROPY_STREAMS_POSIX_API
8788
// Functions with POSIX-compatible signatures
8889
ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len);
8990
ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len);
9091
off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence);
9192
int mp_stream_posix_fsync(mp_obj_t stream);
93+
#endif
9294

9395
#if MICROPY_STREAMS_NON_BLOCK
9496
#define mp_is_nonblocking_error(errno) ((errno) == EAGAIN || (errno) == EWOULDBLOCK)

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
6464
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
6565
#define MICROPY_STREAMS_NON_BLOCK (1)
66+
#define MICROPY_STREAMS_POSIX_API (1)
6667
#define MICROPY_OPT_COMPUTED_GOTO (1)
6768
#ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
6869
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (1)

0 commit comments

Comments
 (0)
0