Skip to content

Commit 80c0570

Browse files
d-a-vmcspr
andauthored
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 <[email protected]>
1 parent 2de142b commit 80c0570

File tree

10 files changed

+36
-28
lines changed

10 files changed

+36
-28
lines changed

Diff for: cores/esp8266/IPAddress.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class IPAddress: public Printable {
6969
IPAddress(const IPAddress& from);
7070
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
7171
IPAddress(uint32_t address) { ctor32(address); }
72-
IPAddress(u32_t address) { ctor32(address); }
72+
IPAddress(unsigned long address) { ctor32(address); }
7373
IPAddress(int address) { ctor32(address); }
7474
IPAddress(const uint8_t *address);
7575

@@ -80,16 +80,14 @@ class IPAddress: public Printable {
8080
// to a four-byte uint8_t array is expected
8181
operator uint32_t() const { return isV4()? v4(): (uint32_t)0; }
8282
operator uint32_t() { return isV4()? v4(): (uint32_t)0; }
83-
operator u32_t() const { return isV4()? v4(): (u32_t)0; }
84-
operator u32_t() { return isV4()? v4(): (u32_t)0; }
8583

8684
bool isSet () const;
8785
operator bool () const { return isSet(); } // <-
8886
operator bool () { return isSet(); } // <- both are needed
8987

9088
// generic IPv4 wrapper to uint32-view like arduino loves to see it
91-
const u32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const)
92-
u32_t& v4() { return ip_2_ip4(&_ip)->addr; }
89+
const uint32_t& v4() const { return ip_2_ip4(&_ip)->addr; } // for raw_address(const)
90+
uint32_t& v4() { return ip_2_ip4(&_ip)->addr; }
9391

9492
bool operator==(const IPAddress& addr) const {
9593
return ip_addr_cmp(&_ip, &addr._ip);
@@ -100,14 +98,14 @@ class IPAddress: public Printable {
10098
bool operator==(uint32_t addr) const {
10199
return isV4() && v4() == addr;
102100
}
103-
bool operator==(u32_t addr) const {
104-
return isV4() && v4() == addr;
101+
bool operator==(unsigned long addr) const {
102+
return isV4() && v4() == (uint32_t)addr;
105103
}
106104
bool operator!=(uint32_t addr) const {
107105
return !(isV4() && v4() == addr);
108106
}
109-
bool operator!=(u32_t addr) const {
110-
return !(isV4() && v4() == addr);
107+
bool operator!=(unsigned long addr) const {
108+
return isV4() && v4() != (uint32_t)addr;
111109
}
112110
bool operator==(const uint8_t* addr) const;
113111

Diff for: libraries/ESP8266WiFi/src/WiFiServer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ T* slist_append_tail(T* head, T* item) {
186186
return head;
187187
}
188188

189-
long WiFiServer::_accept(tcp_pcb* apcb, long err) {
189+
err_t WiFiServer::_accept(tcp_pcb* apcb, err_t err) {
190190
(void) err;
191191
DEBUGV("WS:ac\r\n");
192192

@@ -212,7 +212,7 @@ void WiFiServer::_discard(ClientContext* client) {
212212
DEBUGV("WS:dis\r\n");
213213
}
214214

215-
long WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, long err) {
215+
err_t WiFiServer::_s_accept(void *arg, tcp_pcb* newpcb, err_t err) {
216216
return reinterpret_cast<WiFiServer*>(arg)->_accept(newpcb, err);
217217
}
218218

Diff for: libraries/ESP8266WiFi/src/WiFiServer.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
#define wifiserver_h
2424

2525
extern "C" {
26-
#include "wl_definitions.h"
26+
#include <wl_definitions.h>
2727

2828
struct tcp_pcb;
2929
}
3030

31-
#include "Server.h"
32-
#include "IPAddress.h"
31+
#include <Server.h>
32+
#include <IPAddress.h>
33+
#include <lwip/err.h>
3334

3435
// lwIP-v2 backlog facility allows to keep memory safe by limiting the
3536
// maximum number of incoming *pending clients*. Default number of possibly
@@ -103,10 +104,10 @@ class WiFiServer {
103104
using ClientType = WiFiClient;
104105

105106
protected:
106-
long _accept(tcp_pcb* newpcb, long err);
107+
err_t _accept(tcp_pcb* newpcb, err_t err);
107108
void _discard(ClientContext* client);
108109

109-
static long _s_accept(void *arg, tcp_pcb* newpcb, long err);
110+
static err_t _s_accept(void *arg, tcp_pcb* newpcb, err_t err);
110111
static void _s_discard(void* server, ClientContext* ctx);
111112
};
112113

Diff for: tests/host/common/user_interface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ extern "C"
182182
{
183183
auto test_ipv4
184184
= lwip_ntohl(*(uint32_t*)&((struct sockaddr_in*)ifa->ifa_addr)->sin_addr);
185-
mockverbose(" IPV4 (0x%08lx)", test_ipv4);
185+
mockverbose(" IPV4 (0x%08x)", test_ipv4);
186186
if ((test_ipv4 & 0xff000000) == 0x7f000000)
187187
// 127./8
188188
mockverbose(" (local, ignored)");

Diff for: tools/sdk/lwip2/include/arch/cc.h

+15-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,21 @@ typedef uint32_t sys_prot_t;
8585
///////////////////////////////
8686
//// MISSING
8787

88-
#define sys_now millis // arduino wire millis() definition returns 32 bits like sys_now() does
88+
// Arduino Core exposes time func with a generic type
89+
#ifdef __cplusplus
90+
extern "C"
91+
{
92+
#endif
93+
unsigned long millis(void);
94+
#ifdef __cplusplus
95+
}
96+
#endif
97+
98+
// b/c we have conflicting typedefs of u32_t and ulong and can't substitute funcs,
99+
// forcibly cast the `millis()` result to lwip's version of u32_t
100+
// (previous version was `#define sys_now millis`)
101+
#define sys_now() ((u32_t)millis())
102+
89103
#define LWIP_RAND r_rand // old lwip uses this useful undocumented function
90104
#define IPSTR "%d.%d.%d.%d"
91105
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \

Diff for: tools/sdk/lwip2/include/arch/sys_arch.h

-5
This file was deleted.

Diff for: tools/sdk/lwip2/include/lwip-err-t.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ typedef unsigned char u8_t;
44
typedef signed char s8_t;
55
typedef unsigned short u16_t;
66
typedef signed short s16_t;
7-
typedef unsigned long u32_t;
8-
typedef signed long s32_t;
7+
typedef unsigned int u32_t;
8+
typedef signed int s32_t;
99
typedef unsigned long mem_ptr_t;
1010
#define LWIP_ERR_T s32_t
1111
typedef uint32_t sys_prot_t;

Diff for: tools/sdk/lwip2/include/lwip-git-hash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// generated by makefiles/make-lwip2-hash
22
#ifndef LWIP_HASH_H
33
#define LWIP_HASH_H
4-
#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-58-g450bb63"
4+
#define LWIP_HASH_STR "STABLE-2_1_3_RELEASE/glue:1.2-61-g679577b"
55
#endif // LWIP_HASH_H

Diff for: tools/sdk/lwip2/include/lwip/sys.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ u32_t sys_jiffies(void);
443443
* Not implementing this function means you cannot use some modules (e.g. TCP
444444
* timestamps, internal timeouts for NO_SYS==1).
445445
*/
446-
u32_t sys_now(void);
446+
//u32_t sys_now(void);
447447

448448
/* Critical Region Protection */
449449
/* These functions must be implemented in the sys_arch.c file.

0 commit comments

Comments
 (0)