Skip to content

Commit 5ab98d5

Browse files
committed
stmhal: Convert to use internal errno symbols; enable uerrno module.
1 parent 088127d commit 5ab98d5

12 files changed

Lines changed: 32 additions & 32 deletions

File tree

stmhal/can.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
#include <stdio.h>
2828
#include <string.h>
2929
#include <stdarg.h>
30-
#include <errno.h>
3130

3231
#include "py/nlr.h"
3332
#include "py/objtuple.h"
3433
#include "py/runtime.h"
3534
#include "py/gc.h"
35+
#include "py/mperrno.h"
3636
#include "py/mphal.h"
3737
#include "bufhelper.h"
3838
#include "can.h"
@@ -817,7 +817,7 @@ mp_uint_t can_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *err
817817
ret |= MP_IOCTL_POLL_WR;
818818
}
819819
} else {
820-
*errcode = EINVAL;
820+
*errcode = MP_EINVAL;
821821
ret = -1;
822822
}
823823
return ret;

stmhal/modnetwork.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <stdio.h>
2828
#include <stdint.h>
2929
#include <string.h>
30-
#include <errno.h>
3130

3231
#include "py/nlr.h"
3332
#include "py/objlist.h"

stmhal/modnwcc3k.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <string.h>
2828
#include <stdarg.h>
29-
#include <errno.h>
3029

3130
// CC3000 defines its own ENOBUFS (different to standard one!)
3231
#undef ENOBUFS

stmhal/modnwwiznet5k.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <stdio.h>
2828
#include <stdint.h>
2929
#include <string.h>
30-
#include <errno.h>
3130

3231
#include "py/nlr.h"
3332
#include "py/objlist.h"

stmhal/moduselect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
*/
2626

2727
#include <stdio.h>
28-
#include <errno.h>
2928

3029
#include "py/nlr.h"
3130
#include "py/obj.h"
3231
#include "py/objlist.h"
32+
#include "py/mperrno.h"
3333
#include "py/mphal.h"
3434
#include "pybioctl.h"
3535

@@ -212,7 +212,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
212212
mp_obj_poll_t *self = self_in;
213213
mp_map_elem_t *elem = mp_map_lookup(&self->poll_map, mp_obj_id(obj_in), MP_MAP_LOOKUP);
214214
if (elem == NULL) {
215-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOENT)));
215+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOENT)));
216216
}
217217
((poll_obj_t*)elem->value)->flags = mp_obj_get_int(eventmask_in);
218218
return mp_const_none;

stmhal/modusocket.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
#include <stdio.h>
2828
#include <string.h>
29-
#include <errno.h>
3029

3130
#include "py/nlr.h"
3231
#include "py/objtuple.h"
3332
#include "py/objlist.h"
3433
#include "py/runtime.h"
34+
#include "py/mperrno.h"
3535
#include "netutils.h"
3636
#include "modnetwork.h"
3737

@@ -116,7 +116,7 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
116116
if (self->nic == MP_OBJ_NULL) {
117117
// not connected
118118
// TODO I think we can listen even if not bound...
119-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOTCONN)));
119+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOTCONN)));
120120
}
121121

122122
int _errno;
@@ -186,7 +186,7 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
186186
mod_network_socket_obj_t *self = self_in;
187187
if (self->nic == MP_OBJ_NULL) {
188188
// not connected
189-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EPIPE)));
189+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)));
190190
}
191191
mp_buffer_info_t bufinfo;
192192
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
@@ -204,7 +204,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
204204
mod_network_socket_obj_t *self = self_in;
205205
if (self->nic == MP_OBJ_NULL) {
206206
// not connected
207-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOTCONN)));
207+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOTCONN)));
208208
}
209209
mp_int_t len = mp_obj_get_int(len_in);
210210
vstr_t vstr;
@@ -253,7 +253,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
253253
mod_network_socket_obj_t *self = self_in;
254254
if (self->nic == MP_OBJ_NULL) {
255255
// not connected
256-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOTCONN)));
256+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOTCONN)));
257257
}
258258
vstr_t vstr;
259259
vstr_init_len(&vstr, mp_obj_get_int(len_in));
@@ -314,7 +314,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
314314
mod_network_socket_obj_t *self = self_in;
315315
if (self->nic == MP_OBJ_NULL) {
316316
// not connected
317-
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENOTCONN)));
317+
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENOTCONN)));
318318
}
319319
mp_uint_t timeout;
320320
if (timeout_in == mp_const_none) {

stmhal/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define MICROPY_STREAMS_NON_BLOCK (1)
6262
#define MICROPY_MODULE_WEAK_LINKS (1)
6363
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
64+
#define MICROPY_USE_INTERNAL_ERRNO (1)
6465
#define MICROPY_PY_FUNCTION_ATTRS (1)
6566
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
6667
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
@@ -80,6 +81,7 @@
8081
#define MICROPY_PY_CMATH (1)
8182
#define MICROPY_PY_IO (1)
8283
#define MICROPY_PY_IO_FILEIO (1)
84+
#define MICROPY_PY_UERRNO (1)
8385
#define MICROPY_PY_UBINASCII (1)
8486
#define MICROPY_PY_URANDOM (1)
8587
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
@@ -141,6 +143,7 @@ extern const struct _mp_obj_module_t mp_module_network;
141143
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
142144
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&mp_module_ustruct }, \
143145
{ MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \
146+
{ MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \
144147

145148
// extra constants
146149
#define MICROPY_PORT_CONSTANTS \

stmhal/mphalport.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#include <errno.h>
21
#include <string.h>
32

43
#include "py/mpstate.h"
4+
#include "py/mperrno.h"
55
#include "py/mphal.h"
66
#include "usb.h"
77
#include "uart.h"
88

99
// this table converts from HAL_StatusTypeDef to POSIX errno
1010
const byte mp_hal_status_to_errno_table[4] = {
1111
[HAL_OK] = 0,
12-
[HAL_ERROR] = EIO,
13-
[HAL_BUSY] = EBUSY,
14-
[HAL_TIMEOUT] = ETIMEDOUT,
12+
[HAL_ERROR] = MP_EIO,
13+
[HAL_BUSY] = MP_EBUSY,
14+
[HAL_TIMEOUT] = MP_ETIMEDOUT,
1515
};
1616

1717
NORETURN void mp_hal_raise(HAL_StatusTypeDef status) {

stmhal/pybstdio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
#include <stdio.h>
2828
#include <string.h>
29-
#include <errno.h>
3029

3130
#include "py/obj.h"
3231
#include "py/stream.h"
32+
#include "py/mperrno.h"
3333
#include "py/mphal.h"
3434

3535
// TODO make stdin, stdout and stderr writable objects so they can
@@ -69,7 +69,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er
6969
}
7070
return size;
7171
} else {
72-
*errcode = EPERM;
72+
*errcode = MP_EPERM;
7373
return MP_STREAM_ERROR;
7474
}
7575
}
@@ -80,7 +80,7 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
8080
mp_hal_stdout_tx_strn_cooked(buf, size);
8181
return size;
8282
} else {
83-
*errcode = EPERM;
83+
*errcode = MP_EPERM;
8484
return MP_STREAM_ERROR;
8585
}
8686
}

stmhal/uart.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
#include <stdio.h>
2828
#include <string.h>
2929
#include <stdarg.h>
30-
#include <errno.h>
3130

3231
#include "py/nlr.h"
3332
#include "py/runtime.h"
3433
#include "py/stream.h"
34+
#include "py/mperrno.h"
3535
#include "py/mphal.h"
3636
#include "uart.h"
3737
#include "pybioctl.h"
@@ -829,7 +829,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
829829

830830
// check that size is a multiple of character width
831831
if (size & self->char_width) {
832-
*errcode = EIO;
832+
*errcode = MP_EIO;
833833
return MP_STREAM_ERROR;
834834
}
835835

@@ -844,7 +844,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
844844
// wait for first char to become available
845845
if (!uart_rx_wait(self, self->timeout)) {
846846
// return EAGAIN error to indicate non-blocking (then read() method returns None)
847-
*errcode = EAGAIN;
847+
*errcode = MP_EAGAIN;
848848
return MP_STREAM_ERROR;
849849
}
850850

@@ -871,13 +871,13 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
871871

872872
// check that size is a multiple of character width
873873
if (size & self->char_width) {
874-
*errcode = EIO;
874+
*errcode = MP_EIO;
875875
return MP_STREAM_ERROR;
876876
}
877877

878878
// wait to be able to write the first character. EAGAIN causes write to return None
879879
if (!uart_tx_wait(self, self->timeout)) {
880-
*errcode = EAGAIN;
880+
*errcode = MP_EAGAIN;
881881
return MP_STREAM_ERROR;
882882
}
883883

@@ -917,7 +917,7 @@ STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t a
917917
ret |= MP_IOCTL_POLL_WR;
918918
}
919919
} else {
920-
*errcode = EINVAL;
920+
*errcode = MP_EINVAL;
921921
ret = MP_STREAM_ERROR;
922922
}
923923
return ret;

0 commit comments

Comments
 (0)