1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

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 <prokhorov.max@outlook.com>
This commit is contained in:
david gauchard 2022-05-15 21:55:56 +02:00 committed by GitHub
parent 2de142b8db
commit 80c0570620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 28 deletions

View File

@ -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;

View File

@ -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<WiFiServer*>(arg)->_accept(newpcb, err);
}

View File

@ -23,13 +23,14 @@
#define wifiserver_h
extern "C" {
#include "wl_definitions.h"
#include <wl_definitions.h>
struct tcp_pcb;
}
#include "Server.h"
#include "IPAddress.h"
#include <Server.h>
#include <IPAddress.h>
#include <lwip/err.h>
// 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 @@ public:
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);
};

View File

@ -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)");

@ -1 +1 @@
Subproject commit 450bb63c1bc8b35770ca7f246945cf383569f52f
Subproject commit 66f84a603ee3070467f119b5e2be5209ec22351f

View File

@ -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), \

View File

@ -1,5 +0,0 @@
#ifndef MYSYSARCH_H
#define MYSYSARCH_H
#endif // MYSYSARCH_H

View File

@ -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;

View File

@ -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

View File

@ -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.