From 4f2ba9fbdcbafd7ae09199186320f4173bcc8c31 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Tue, 10 May 2016 23:25:39 +0100
Subject: [PATCH] esp8266: Convert to use new MP_Exxx errno symbols.

These symbols are still defined in terms of the system Exxx symbols, and
can be switched to internal numeric definitions at a later stage.

Note that extmod/modlwip still uses many system Exxx symbols.
---
 esp8266/modesp.c       | 8 ++++----
 esp8266/modnetwork.c   | 1 -
 esp8266/modpybspi.c    | 1 -
 esp8266/modpybuart.c   | 6 +++---
 esp8266/moduos.c       | 4 ++--
 esp8266/mpconfigport.h | 1 +
 6 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 44401d3a6..885e7ae95 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -27,12 +27,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdbool.h>
-#include <errno.h>
 
 #include "py/nlr.h"
 #include "py/obj.h"
 #include "py/gc.h"
 #include "py/runtime.h"
+#include "py/mperrno.h"
 #include "py/mphal.h"
 #include "netutils.h"
 #include "queue.h"
@@ -577,7 +577,7 @@ STATIC mp_obj_t esp_flash_read(mp_obj_t offset_in, mp_obj_t len_or_buf_in) {
     if (alloc_buf) {
         m_del(byte, buf, len);
     }
-    nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? ETIMEDOUT : EIO)));
+    nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO)));
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_read_obj, esp_flash_read);
 
@@ -594,7 +594,7 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) {
     }
     nlr_raise(mp_obj_new_exception_arg1(
         &mp_type_OSError,
-        MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? ETIMEDOUT : EIO)));
+        MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO)));
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_flash_write_obj, esp_flash_write);
 
@@ -606,7 +606,7 @@ STATIC mp_obj_t esp_flash_erase(mp_obj_t sector_in) {
     }
     nlr_raise(mp_obj_new_exception_arg1(
         &mp_type_OSError,
-        MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? ETIMEDOUT : EIO)));
+        MP_OBJ_NEW_SMALL_INT(res == SPI_FLASH_RESULT_TIMEOUT ? MP_ETIMEDOUT : MP_EIO)));
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_flash_erase_obj, esp_flash_erase);
 
diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c
index 5e9273158..4ad4137b6 100644
--- a/esp8266/modnetwork.c
+++ b/esp8266/modnetwork.c
@@ -27,7 +27,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
-#include <errno.h>
 
 #include "py/nlr.h"
 #include "py/objlist.h"
diff --git a/esp8266/modpybspi.c b/esp8266/modpybspi.c
index 1131e8ef6..e8ee0f343 100644
--- a/esp8266/modpybspi.c
+++ b/esp8266/modpybspi.c
@@ -27,7 +27,6 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
-#include <errno.h>
 
 #include "ets_sys.h"
 #include "etshal.h"
diff --git a/esp8266/modpybuart.c b/esp8266/modpybuart.c
index eefb38d99..5971ffece 100644
--- a/esp8266/modpybuart.c
+++ b/esp8266/modpybuart.c
@@ -27,13 +27,13 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
-#include <errno.h>
 
 #include "ets_sys.h"
 #include "uart.h"
 
 #include "py/runtime.h"
 #include "py/stream.h"
+#include "py/mperrno.h"
 #include "modpyb.h"
 
 // baudrate is currently fixed to this value
@@ -136,7 +136,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
 
     // wait for first char to become available
     if (!uart_rx_wait(self->timeout * 1000)) {
-        *errcode = EAGAIN;
+        *errcode = MP_EAGAIN;
         return MP_STREAM_ERROR;
     }
 
@@ -173,7 +173,7 @@ STATIC mp_uint_t pyb_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t
 }
 
 STATIC mp_uint_t pyb_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
-    *errcode = EINVAL;
+    *errcode = MP_EINVAL;
     return MP_STREAM_ERROR;
 }
 
diff --git a/esp8266/moduos.c b/esp8266/moduos.c
index d75062eaf..bc2838d2d 100644
--- a/esp8266/moduos.c
+++ b/esp8266/moduos.c
@@ -25,7 +25,6 @@
  */
 
 #include <string.h>
-#include <errno.h>
 
 #include "py/mpconfig.h"
 #include "py/nlr.h"
@@ -33,6 +32,7 @@
 #include "py/objtuple.h"
 #include "py/objstr.h"
 #include "py/runtime.h"
+#include "py/mperrno.h"
 #include "extmod/misc.h"
 #include "genhdr/mpversion.h"
 #include "esp_mphal.h"
@@ -74,7 +74,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
 #if MICROPY_VFS_FAT
 mp_obj_t vfs_proxy_call(qstr method_name, mp_uint_t n_args, const mp_obj_t *args) {
     if (MP_STATE_PORT(fs_user_mount)[0] == NULL) {
-        nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ENODEV)));
+        nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(MP_ENODEV)));
     }
 
     mp_obj_t meth[n_args + 2];
diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h
index 89f3bb952..1c0b465ab 100644
--- a/esp8266/mpconfigport.h
+++ b/esp8266/mpconfigport.h
@@ -24,6 +24,7 @@
 #define MICROPY_ENABLE_SOURCE_LINE  (1)
 #define MICROPY_MODULE_WEAK_LINKS   (1)
 #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
+#define MICROPY_USE_INTERNAL_ERRNO  (0)
 #define MICROPY_PY_BUILTINS_COMPLEX (0)
 #define MICROPY_PY_BUILTINS_STR_UNICODE (1)
 #define MICROPY_PY_BUILTINS_BYTEARRAY (1)
-- 
GitLab