From 199648ff3729b733fe35fc510bc1e6334206fb30 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 9 Oct 2007 19:59:56 +0000 Subject: [PATCH] Changed initialization: many init functions are not needed any more since we now rely on the compiler initializing global and static variables to zero! --- CHANGELOG | 5 +++++ doc/contrib.txt | 3 ++- src/api/sockets.c | 6 +++--- src/api/tcpip.c | 10 +++++----- src/core/ipv4/igmp.c | 2 -- src/core/ipv4/ip.c | 11 ----------- src/core/ipv4/ip_frag.c | 8 -------- src/core/mem.c | 1 - src/core/netif.c | 9 --------- src/core/raw.c | 11 +---------- src/core/snmp/mib_structs.c | 2 +- src/core/snmp/msg_in.c | 2 +- src/core/stats.c | 5 ----- src/core/tcp.c | 19 ------------------- src/core/udp.c | 11 +---------- src/include/ipv4/lwip/ip.h | 2 +- src/include/lwip/netif.h | 3 +-- src/include/lwip/raw.h | 2 +- src/include/lwip/stats.h | 2 +- src/include/lwip/tcp.h | 3 +-- src/include/lwip/udp.h | 3 ++- src/include/netif/etharp.h | 2 +- src/netif/etharp.c | 30 ++++++++---------------------- 23 files changed, 35 insertions(+), 117 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 36c55d5a..005ccbe8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2007-10-08 Simon Goldschmidt + * many files: Changed initialization: many init functions are not needed any + more since we now rely on the compiler initializing global and static + variables to zero! + 2007-10-06 Simon Goldschmidt * ip_frag.c, memp.c, mib2.c, ip_frag.h, memp_std.h, opt.h: Changed IP_REASSEMBLY to enqueue the received pbufs so that multiple packets can be reassembled diff --git a/doc/contrib.txt b/doc/contrib.txt index 7c99b9be..39596fca 100644 --- a/doc/contrib.txt +++ b/doc/contrib.txt @@ -21,7 +21,8 @@ features of Savannah help us not lose users' input. 6. one space and no newline before opening curly braces of a block. 7. closing curly brace on a single line. 8. spaces surrounding assignment and comparisons. -9. use current source code style as further reference. +9. don't initialize static and/or global variables to zero, the compiler takes care of that. +10. use current source code style as further reference. 2.2 Source code documentation style: diff --git a/src/api/sockets.c b/src/api/sockets.c index 60919435..b9eebd44 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -86,10 +86,10 @@ struct lwip_setgetsockopt_data { }; static struct lwip_socket sockets[NUM_SOCKETS]; -static struct lwip_select_cb *select_cb_list = 0; +static struct lwip_select_cb *select_cb_list; -static sys_sem_t socksem = 0; -static sys_sem_t selectsem = 0; +static sys_sem_t socksem; +static sys_sem_t selectsem; static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len); static void lwip_getsockopt_internal(void *arg); diff --git a/src/api/tcpip.c b/src/api/tcpip.c index e79fabe1..939402f7 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -54,18 +54,18 @@ #include "netif/ppp_oe.h" /* global variables */ -static void (* tcpip_init_done)(void *arg) = NULL; -static void *tcpip_init_done_arg = NULL; -static sys_mbox_t mbox = SYS_MBOX_NULL; +static void (* tcpip_init_done)(void *arg); +static void *tcpip_init_done_arg; +static sys_mbox_t mbox = SYS_MBOX_NULL; #if LWIP_TCPIP_CORE_LOCKING /** The global semaphore to lock the stack. */ -sys_sem_t lock_tcpip_core = 0; +sys_sem_t lock_tcpip_core; #endif /* LWIP_TCPIP_CORE_LOCKING */ #if LWIP_TCP /* global variable that shows if the tcp timer is currently scheduled or not */ -static int tcpip_tcp_timer_active = 0; +static int tcpip_tcp_timer_active; /** * Timer callback function that calls tcp_tmr() and reschedules itself. diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index c8370b7b..7040a3af 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -113,8 +113,6 @@ igmp_init(void) IP4_ADDR(&allsystems, 224, 0, 0, 1); IP4_ADDR(&allrouters, 224, 0, 0, 2); - - igmp_group_list = NULL; } #ifdef LWIP_DEBUG diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 9980cbc8..2b0ccdec 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -55,17 +55,6 @@ #include "lwip/stats.h" #include "arch/perf.h" -/** - * Initializes the IP layer. - */ -void -ip_init(void) -{ -#if IP_REASSEMBLY - ip_reass_init(); -#endif -} - /** * Finds the appropriate network interface for a given IP address. It * searches the list of network interfaces linearly. A match is found diff --git a/src/core/ipv4/ip_frag.c b/src/core/ipv4/ip_frag.c index 3adb3de2..ffec6b80 100644 --- a/src/core/ipv4/ip_frag.c +++ b/src/core/ipv4/ip_frag.c @@ -85,14 +85,6 @@ static u16_t ip_reass_pbufcount; /* function prototypes */ static void dequeue_packet(struct ip_reassdata *ipr, struct ip_reassdata *prev); -/** - * Initializes IP reassembly states. - */ -void -ip_reass_init(void) -{ -} - /** * Reassembly timer base function * for both NO_SYS == 0 and 1 (!). diff --git a/src/core/mem.c b/src/core/mem.c index afb4a52f..01f78eda 100644 --- a/src/core/mem.c +++ b/src/core/mem.c @@ -206,7 +206,6 @@ mem_init(void) (SIZEOF_STRUCT_MEM & (MEM_ALIGNMENT-1)) == 0); /* align the heap */ - memset(ram_heap, 0, sizeof(ram_heap)); ram = LWIP_MEM_ALIGN(ram_heap); /* initialize the start of the heap */ mem = (struct mem *)ram; diff --git a/src/core/netif.c b/src/core/netif.c index 9c9da2b1..a31992d2 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -61,15 +61,6 @@ struct netif *netif_list = NULL; struct netif *netif_default = NULL; -/** - * Initialize this module - */ -void -netif_init(void) -{ - netif_list = netif_default = NULL; -} - /** * Add a network interface to the list of lwIP netifs. * diff --git a/src/core/raw.c b/src/core/raw.c index 421c4933..4ee3fc0e 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -55,16 +55,7 @@ #include /** The list of RAW PCBs */ -static struct raw_pcb *raw_pcbs = NULL; - -/** - * Initialize this module - */ -void -raw_init(void) -{ - raw_pcbs = NULL; -} +static struct raw_pcb *raw_pcbs; /** * Determine if in incoming IP packet is covered by a RAW PCB diff --git a/src/core/snmp/mib_structs.c b/src/core/snmp/mib_structs.c index ba78f857..af8994ed 100644 --- a/src/core/snmp/mib_structs.c +++ b/src/core/snmp/mib_structs.c @@ -53,7 +53,7 @@ struct nse /** right child next level */ u8_t r_nl; }; -static u8_t node_stack_cnt = 0; +static u8_t node_stack_cnt; static struct nse node_stack[NODE_STACK_SIZE]; /** diff --git a/src/core/snmp/msg_in.c b/src/core/snmp/msg_in.c index ab8b5216..e09bac18 100644 --- a/src/core/snmp/msg_in.c +++ b/src/core/snmp/msg_in.c @@ -56,7 +56,7 @@ const char snmp_publiccommunity[7] = "public"; /* statically allocated buffers for SNMP_CONCURRENT_REQUESTS */ struct snmp_msg_pstat msg_input_list[SNMP_CONCURRENT_REQUESTS]; /* UDP Protocol Control Block */ -struct udp_pcb *snmp1_pcb = NULL; +struct udp_pcb *snmp1_pcb; static void snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port); static err_t snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret, struct snmp_msg_pstat *m_stat); diff --git a/src/core/stats.c b/src/core/stats.c index 640baab5..e693d869 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -48,11 +48,6 @@ struct stats_ lwip_stats; -void -stats_init(void) -{ - memset(&lwip_stats, 0, sizeof(struct stats_)); -} #if LWIP_STATS_DISPLAY void stats_display_proto(struct stats_proto *proto, char *name) diff --git a/src/core/tcp.c b/src/core/tcp.c index a7ce7394..a28b2890 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -74,25 +74,6 @@ struct tcp_pcb *tcp_tmp_pcb; static u8_t tcp_timer; static u16_t tcp_new_port(void); -/** - * Initializes the TCP layer. - */ -void -tcp_init(void) -{ - /* Clear globals. */ - tcp_bound_pcbs = NULL; - tcp_listen_pcbs.listen_pcbs = NULL; - tcp_active_pcbs = NULL; - tcp_tw_pcbs = NULL; - tcp_tmp_pcb = NULL; - - /* initialize timer */ - tcp_ticks = 0; - tcp_timer = 0; - -} - /** * Called periodically to dispatch TCP timers. * diff --git a/src/core/udp.c b/src/core/udp.c index 437cdb1f..f78d55b0 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -65,16 +65,7 @@ /* The list of UDP PCBs */ /* exported in udp.h (was static) */ -struct udp_pcb *udp_pcbs = NULL; - -/** - * Initialize the UDP module - */ -void -udp_init(void) -{ - udp_pcbs = NULL; -} +struct udp_pcb *udp_pcbs; /** * Process an incoming UDP datagram. diff --git a/src/include/ipv4/lwip/ip.h b/src/include/ipv4/lwip/ip.h index e61ac319..3b760f00 100644 --- a/src/include/ipv4/lwip/ip.h +++ b/src/include/ipv4/lwip/ip.h @@ -43,7 +43,7 @@ extern "C" { #endif -void ip_init(void); +#define ip_init() /* Compatibility define, not init needed. */ struct netif *ip_route(struct ip_addr *dest); err_t ip_input(struct pbuf *p, struct netif *inp); err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 81dd338b..19c38087 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -192,8 +192,7 @@ extern struct netif *netif_list; /** The default network interface. */ extern struct netif *netif_default; -/* netif_init() must be called first. */ -void netif_init(void); +#define netif_init() /* Compatibility define, not init needed. */ struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, diff --git a/src/include/lwip/raw.h b/src/include/lwip/raw.h index 56d21b18..5834fc95 100644 --- a/src/include/lwip/raw.h +++ b/src/include/lwip/raw.h @@ -85,7 +85,7 @@ err_t raw_send (struct raw_pcb *pcb, struct pbuf *p); /* The following functions are the lower layer interface to RAW. */ u8_t raw_input (struct pbuf *p, struct netif *inp); -void raw_init (void); +#define raw_init() /* Compatibility define, not init needed. */ #ifdef __cplusplus } diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index 1dbc0df9..ee319b24 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -136,7 +136,7 @@ struct stats_ { extern struct stats_ lwip_stats; -void stats_init(void); +#define stats_init() /* Compatibility define, not init needed. */ #define STATS_INC(x) ++lwip_stats.x #else diff --git a/src/include/lwip/tcp.h b/src/include/lwip/tcp.h index ab87ca5b..8e2fc68a 100644 --- a/src/include/lwip/tcp.h +++ b/src/include/lwip/tcp.h @@ -52,8 +52,7 @@ struct tcp_pcb; /* Functions for interfacing with TCP: */ /* Lower layer interface to TCP: */ -void tcp_init (void); /* Must be called first to - initialize TCP. */ +#define tcp_init() /* Compatibility define, not init needed. */ void tcp_tmr (void); /* Must be called every TCP_TMR_INTERVAL ms. (Typically 250 ms). */ diff --git a/src/include/lwip/udp.h b/src/include/lwip/udp.h index cd0f33cd..89d1f5e7 100644 --- a/src/include/lwip/udp.h +++ b/src/include/lwip/udp.h @@ -130,7 +130,8 @@ err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); /* The following functions are the lower layer interface to UDP. */ void udp_input (struct pbuf *p, struct netif *inp); -void udp_init (void); + +#define udp_init() /* Compatibility define, not init needed. */ #if UDP_DEBUG void udp_debug_print(struct udp_hdr *udphdr); diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index e5d9e15d..2b76823b 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -141,7 +141,7 @@ struct etharp_q_entry { }; #endif /* ARP_QUEUEING */ -void etharp_init(void); +#define etharp_init() /* Compatibility define, not init needed. */ void etharp_tmr(void); s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr **eth_ret, struct ip_addr **ip_ret); diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 77fd2eeb..63b458cc 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -103,7 +103,7 @@ const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; const struct eth_addr ethzero = {{0,0,0,0,0,0}}; static struct etharp_entry arp_table[ARP_TABLE_SIZE]; #if !LWIP_NETIF_HWADDRHINT -static u8_t etharp_cached_entry = 0; +static u8_t etharp_cached_entry; #endif /** @@ -122,29 +122,15 @@ static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags); static err_t update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags); -/** - * Initializes ARP module. - */ -void -etharp_init(void) -{ - u8_t i; - - LWIP_ASSERT("ARP_TABLE_SIZE < 0x80 (due to s8_t limitation)", - (ARP_TABLE_SIZE < 0x80)); - /* clear ARP entries */ - for (i = 0; i < ARP_TABLE_SIZE; ++i) { - /* use memset to be safe (intialize all future variables to 0) */ - memset(&arp_table[i], 0, sizeof(struct etharp_entry)); - arp_table[i].state = ETHARP_STATE_EMPTY; -#if ARP_QUEUEING - arp_table[i].q = NULL; +/* Some checks, instead of etharp_init(): */ +#if ETHARP_STATE_EMPTY != 0 +#error ETHARP_STATE_EMPTY must be 0 to ensure correct initialization value! #endif - arp_table[i].ctime = 0; - arp_table[i].netif = NULL; - } -} +#if (LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) + #error "If you want to use ARP, ARP_TABLE_SIZE must fit in an s8_t, so, you have to reduce it in your lwipopts.h" +#endif + #if ARP_QUEUEING /** -- 2.39.2