From 80c05706203ffd37830983d54471bc1dc9c3182b Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 15 May 2022 21:55:56 +0200 Subject: [PATCH] Define lwIP's s32/u32 to int (#8560) * Define lwIP's s32/u32 to int s32/u32 were previously defined as long, but long can be 64 bits in host mode, so this commit reduces valgrind complaints and increase coherency. * some lads like to use `unsigned long` for 32 bits IPv4 addresses * fix lwIP's `sys_now()` return type * fix C declarations * merge upstream (lwip2) update on sys_now() definition * matching lwIP api (2/2) Co-authored-by: Max Prokhorov --- cores/esp8266/IPAddress.h | 16 +++++++--------- libraries/ESP8266WiFi/src/WiFiServer.cpp | 4 ++-- libraries/ESP8266WiFi/src/WiFiServer.h | 11 ++++++----- tests/host/common/user_interface.cpp | 2 +- tools/sdk/lwip2/builder | 2 +- tools/sdk/lwip2/include/arch/cc.h | 16 +++++++++++++++- tools/sdk/lwip2/include/arch/sys_arch.h | 5 ----- tools/sdk/lwip2/include/lwip-err-t.h | 4 ++-- tools/sdk/lwip2/include/lwip-git-hash.h | 2 +- tools/sdk/lwip2/include/lwip/sys.h | 2 +- 10 files changed, 36 insertions(+), 28 deletions(-) delete mode 100644 tools/sdk/lwip2/include/arch/sys_arch.h diff --git a/cores/esp8266/IPAddress.h b/cores/esp8266/IPAddress.h index c070118889..894d431c68 100644 --- a/cores/esp8266/IPAddress.h +++ b/cores/esp8266/IPAddress.h @@ -69,7 +69,7 @@ class IPAddress: public Printable { IPAddress(const IPAddress& from); IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); IPAddress(uint32_t address) { ctor32(address); } - IPAddress(u32_t address) { ctor32(address); } + IPAddress(unsigned long address) { ctor32(address); } IPAddress(int address) { ctor32(address); } IPAddress(const uint8_t *address); @@ -80,16 +80,14 @@ class IPAddress: public Printable { // to a four-byte uint8_t array is expected operator uint32_t() const { return isV4()? v4(): (uint32_t)0; } operator uint32_t() { return isV4()? v4(): (uint32_t)0; } - operator u32_t() const { return isV4()? v4(): (u32_t)0; } - operator u32_t() { return isV4()? v4(): (u32_t)0; } bool isSet () const; operator bool () const { return isSet(); } // <- operator bool () { return isSet(); } // <- both are needed // generic IPv4 wrapper to uint32-view like arduino loves to see it - const u32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const) - u32_t& v4() { return ip_2_ip4(&_ip)->addr; } + const uint32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const) + uint32_t& v4() { return ip_2_ip4(&_ip)->addr; } bool operator==(const IPAddress& addr) const { return ip_addr_cmp(&_ip, &addr._ip); @@ -100,14 +98,14 @@ class IPAddress: public Printable { bool operator==(uint32_t addr) const { return isV4() && v4() == addr; } - bool operator==(u32_t addr) const { - return isV4() && v4() == addr; + bool operator==(unsigned long addr) const { + return isV4() && v4() == (uint32_t)addr; } bool operator!=(uint32_t addr) const { return !(isV4() && v4() == addr); } - bool operator!=(u32_t addr) const { - return !(isV4() && v4() == addr); + bool operator!=(unsigned long addr) const { + return isV4() && v4() != (uint32_t)addr; } bool operator==(const uint8_t* addr) const; diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index bfe2377220..acc0528389 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -186,7 +186,7 @@ T* slist_append_tail(T* head, T* item) { return head; } -long WiFiServer::_accept(tcp_pcb* apcb, long err) { +err_t WiFiServer::_accept(tcp_pcb* apcb, err_t err) { (void) err; DEBUGV("WS:ac\r\n"); @@ -212,7 +212,7 @@ void WiFiServer::_discard(ClientContext* client) { DEBUGV("WS:dis\r\n"); } -long WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, long err) { +err_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, err_t err) { return reinterpret_cast(arg)->_accept(newpcb, err); } diff --git a/libraries/ESP8266WiFi/src/WiFiServer.h b/libraries/ESP8266WiFi/src/WiFiServer.h index 081a952bb3..03f32b24e1 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.h +++ b/libraries/ESP8266WiFi/src/WiFiServer.h @@ -23,13 +23,14 @@ #define wifiserver_h extern "C" { - #include "wl_definitions.h" + #include struct tcp_pcb; } -#include "Server.h" -#include "IPAddress.h" +#include +#include +#include // lwIP-v2 backlog facility allows to keep memory safe by limiting the // maximum number of incoming *pending clients*. Default number of possibly @@ -103,10 +104,10 @@ class WiFiServer { using ClientType = WiFiClient; protected: - long _accept(tcp_pcb* newpcb, long err); + err_t _accept(tcp_pcb* newpcb, err_t err); void _discard(ClientContext* client); - static long _s_accept(void *arg, tcp_pcb* newpcb, long err); + static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err); static void _s_discard(void* server, ClientContext* ctx); }; diff --git a/tests/host/common/user_interface.cpp b/tests/host/common/user_interface.cpp index 05f90c704a..afb8ed3740 100644 --- a/tests/host/common/user_interface.cpp +++ b/tests/host/common/user_interface.cpp @@ -182,7 +182,7 @@ extern "C" { auto test_ipv4 = lwip_ntohl(*(uint32_t*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr); - mockverbose(" IPV4 (0x%08lx)", test_ipv4); + mockverbose(" IPV4 (0x%08x)", test_ipv4); if ((test_ipv4 & 0xff000000) == 0x7f000000) // 127./8 mockverbose(" (local, ignored)"); diff --git a/tools/sdk/lwip2/builder b/tools/sdk/lwip2/builder index 450bb63c1b..66f84a603e 160000 --- a/tools/sdk/lwip2/builder +++ b/tools/sdk/lwip2/builder @@ -1 +1 @@ -Subproject commit 450bb63c1bc8b35770ca7f246945cf383569f52f +Subproject commit 66f84a603ee3070467f119b5e2be5209ec22351f diff --git a/tools/sdk/lwip2/include/arch/cc.h b/tools/sdk/lwip2/include/arch/cc.h index 1b879c84cd..0b73cba842 100644 --- a/tools/sdk/lwip2/include/arch/cc.h +++ b/tools/sdk/lwip2/include/arch/cc.h @@ -85,7 +85,21 @@ typedef uint32_t sys_prot_t; /////////////////////////////// //// MISSING -#define sys_now millis // arduino wire millis() definition returns 32 bits like sys_now() does +// Arduino Core exposes time func with a generic type +#ifdef __cplusplus +extern "C" +{ +#endif +unsigned long millis(void); +#ifdef __cplusplus +} +#endif + +// b/c we have conflicting typedefs of u32_t and ulong and can't substitute funcs, +// forcibly cast the `millis()` result to lwip's version of u32_t +// (previous version was `#define sys_now millis`) +#define sys_now() ((u32_t)millis()) + #define LWIP_RAND r_rand // old lwip uses this useful undocumented function #define IPSTR "%d.%d.%d.%d" #define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ diff --git a/tools/sdk/lwip2/include/arch/sys_arch.h b/tools/sdk/lwip2/include/arch/sys_arch.h deleted file mode 100644 index abcf8afd02..0000000000 --- a/tools/sdk/lwip2/include/arch/sys_arch.h +++ /dev/null @@ -1,5 +0,0 @@ - -#ifndef MYSYSARCH_H -#define MYSYSARCH_H - -#endif // MYSYSARCH_H \ No newline at end of file diff --git a/tools/sdk/lwip2/include/lwip-err-t.h b/tools/sdk/lwip2/include/lwip-err-t.h index d4a832ab20..e546e16b71 100644 --- a/tools/sdk/lwip2/include/lwip-err-t.h +++ b/tools/sdk/lwip2/include/lwip-err-t.h @@ -4,8 +4,8 @@ typedef unsigned char u8_t; typedef signed char s8_t; typedef unsigned short u16_t; typedef signed short s16_t; -typedef unsigned long u32_t; -typedef signed long s32_t; +typedef unsigned int u32_t; +typedef signed int s32_t; typedef unsigned long mem_ptr_t; #define LWIP_ERR_T s32_t typedef uint32_t sys_prot_t; diff --git a/tools/sdk/lwip2/include/lwip-git-hash.h b/tools/sdk/lwip2/include/lwip-git-hash.h index 96c8999789..fe8698cbf2 100644 --- a/tools/sdk/lwip2/include/lwip-git-hash.h +++ b/tools/sdk/lwip2/include/lwip-git-hash.h @@ -1,5 +1,5 @@ // generated by makefiles/make-lwip2-hash #ifndef LWIP_HASH_H #define LWIP_HASH_H -#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-58-g450bb63" +#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-61-g679577b" #endif // LWIP_HASH_H diff --git a/tools/sdk/lwip2/include/lwip/sys.h b/tools/sdk/lwip2/include/lwip/sys.h index 168e465baa..e03e164aec 100644 --- a/tools/sdk/lwip2/include/lwip/sys.h +++ b/tools/sdk/lwip2/include/lwip/sys.h @@ -443,7 +443,7 @@ u32_t sys_jiffies(void); * Not implementing this function means you cannot use some modules (e.g. TCP * timestamps, internal timeouts for NO_SYS==1). */ -u32_t sys_now(void); +//u32_t sys_now(void); /* Critical Region Protection */ /* These functions must be implemented in the sys_arch.c file.