From d3a8862bd8ba87c7a48819a93ff14524fbb9fe06 Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov <rojer@cesanta.com> Date: Sat, 11 Mar 2017 02:03:01 +0200 Subject: [PATCH] Make interface vtables const Frees up a bit of ram on ESP PUBLISHED_FROM=0ea046cc63704481bca138b3096937669b94733d --- docs/c-api/net.h/struct_mg_mgr_init_opts.md | 4 +-- mongoose.c | 40 ++++++++++----------- mongoose.h | 12 +++---- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/c-api/net.h/struct_mg_mgr_init_opts.md b/docs/c-api/net.h/struct_mg_mgr_init_opts.md index da3e49516..c0b658166 100644 --- a/docs/c-api/net.h/struct_mg_mgr_init_opts.md +++ b/docs/c-api/net.h/struct_mg_mgr_init_opts.md @@ -4,9 +4,9 @@ decl_name: "struct mg_mgr_init_opts" symbol_kind: "struct" signature: | struct mg_mgr_init_opts { - struct mg_iface_vtable *main_iface; + const struct mg_iface_vtable *main_iface; int num_ifaces; - struct mg_iface_vtable **ifaces; + const struct mg_iface_vtable **ifaces; }; --- diff --git a/mongoose.c b/mongoose.c index 3f7534f8a..91dc8b9f8 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2975,7 +2975,7 @@ extern "C" { #define MG_ENABLE_NET_IF_SOCKET MG_NET_IF == MG_NET_IF_SOCKET #endif -extern struct mg_iface_vtable mg_socket_iface_vtable; +extern const struct mg_iface_vtable mg_socket_iface_vtable; #ifdef __cplusplus } @@ -3003,7 +3003,7 @@ struct mg_tun_client; extern "C" { #endif /* __cplusplus */ -extern struct mg_iface_vtable mg_tun_iface_vtable; +extern const struct mg_iface_vtable mg_tun_iface_vtable; struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client, uint32_t stream_id); @@ -3023,18 +3023,18 @@ struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client, /* Amalgamated: #include "mongoose/src/net_if_socket.h" */ /* Amalgamated: #include "mongoose/src/net_if_tun.h" */ -extern struct mg_iface_vtable mg_default_iface_vtable; +extern const struct mg_iface_vtable mg_default_iface_vtable; #if MG_ENABLE_TUN -struct mg_iface_vtable *mg_ifaces[] = {&mg_default_iface_vtable, - &mg_tun_iface_vtable}; +const struct mg_iface_vtable *mg_ifaces[] = {&mg_default_iface_vtable, + &mg_tun_iface_vtable}; #else -struct mg_iface_vtable *mg_ifaces[] = {&mg_default_iface_vtable}; +const struct mg_iface_vtable *mg_ifaces[] = {&mg_default_iface_vtable}; #endif int mg_num_ifaces = (int) (sizeof(mg_ifaces) / sizeof(mg_ifaces[0])); -struct mg_iface *mg_if_create_iface(struct mg_iface_vtable *vtable, +struct mg_iface *mg_if_create_iface(const struct mg_iface_vtable *vtable, struct mg_mgr *mgr) { struct mg_iface *iface = (struct mg_iface *) MG_CALLOC(1, sizeof(*iface)); iface->mgr = mgr; @@ -3044,7 +3044,7 @@ struct mg_iface *mg_if_create_iface(struct mg_iface_vtable *vtable, } struct mg_iface *mg_find_iface(struct mg_mgr *mgr, - struct mg_iface_vtable *vtable, + const struct mg_iface_vtable *vtable, struct mg_iface *from) { int i = 0; if (from != NULL) { @@ -3790,9 +3790,9 @@ void mg_socket_if_get_conn_addr(struct mg_connection *nc, int remote, } /* clang-format on */ -struct mg_iface_vtable mg_socket_iface_vtable = MG_SOCKET_IFACE_VTABLE; +const struct mg_iface_vtable mg_socket_iface_vtable = MG_SOCKET_IFACE_VTABLE; #if MG_NET_IF == MG_NET_IF_SOCKET -struct mg_iface_vtable mg_default_iface_vtable = MG_SOCKET_IFACE_VTABLE; +const struct mg_iface_vtable mg_default_iface_vtable = MG_SOCKET_IFACE_VTABLE; #endif #endif /* MG_ENABLE_NET_IF_SOCKET */ @@ -3966,7 +3966,7 @@ struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client, } /* clang-format on */ -struct mg_iface_vtable mg_tun_iface_vtable = MG_TUN_IFACE_VTABLE; +const struct mg_iface_vtable mg_tun_iface_vtable = MG_TUN_IFACE_VTABLE; #endif /* MG_ENABLE_TUN */ #ifdef MG_MODULE_LINES @@ -13012,7 +13012,7 @@ extern "C" { #define MG_ENABLE_NET_IF_SIMPLELINK MG_NET_IF == MG_NET_IF_SIMPLELINK #endif -extern struct mg_iface_vtable mg_simplelink_iface_vtable; +extern const struct mg_iface_vtable mg_simplelink_iface_vtable; #ifdef __cplusplus } @@ -13484,9 +13484,9 @@ void sl_restart_cb(struct mg_mgr *mgr) { } /* clang-format on */ -struct mg_iface_vtable mg_simplelink_iface_vtable = MG_SL_IFACE_VTABLE; +const struct mg_iface_vtable mg_simplelink_iface_vtable = MG_SL_IFACE_VTABLE; #if MG_NET_IF == MG_NET_IF_SIMPLELINK -struct mg_iface_vtable mg_default_iface_vtable = MG_SL_IFACE_VTABLE; +const struct mg_iface_vtable mg_default_iface_vtable = MG_SL_IFACE_VTABLE; #endif #endif /* MG_ENABLE_NET_IF_SIMPLELINK */ @@ -13706,7 +13706,7 @@ int sl_set_ssl_opts(struct mg_connection *nc) { #include <stdint.h> -extern struct mg_iface_vtable mg_lwip_iface_vtable; +extern const struct mg_iface_vtable mg_lwip_iface_vtable; struct mg_lwip_conn_state { struct mg_connection *nc; @@ -14355,9 +14355,9 @@ void mg_lwip_if_sock_set(struct mg_connection *nc, sock_t sock) { } /* clang-format on */ -struct mg_iface_vtable mg_lwip_iface_vtable = MG_LWIP_IFACE_VTABLE; +const struct mg_iface_vtable mg_lwip_iface_vtable = MG_LWIP_IFACE_VTABLE; #if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL -struct mg_iface_vtable mg_default_iface_vtable = MG_LWIP_IFACE_VTABLE; +const struct mg_iface_vtable mg_default_iface_vtable = MG_LWIP_IFACE_VTABLE; #endif #endif /* MG_ENABLE_NET_IF_LWIP_LOW_LEVEL */ @@ -14902,7 +14902,7 @@ extern "C" { #define MG_ENABLE_NET_IF_PIC32 MG_NET_IF == MG_NET_IF_PIC32 #endif -extern struct mg_iface_vtable mg_pic32_iface_vtable; +extern const struct mg_iface_vtable mg_pic32_iface_vtable; #ifdef __cplusplus } @@ -15201,9 +15201,9 @@ void mg_pic32_if_connect_udp(struct mg_connection *nc) { } /* clang-format on */ -struct mg_iface_vtable mg_pic32_iface_vtable = MG_PIC32_IFACE_VTABLE; +const struct mg_iface_vtable mg_pic32_iface_vtable = MG_PIC32_IFACE_VTABLE; #if MG_NET_IF == MG_NET_IF_PIC32 -struct mg_iface_vtable mg_default_iface_vtable = MG_PIC32_IFACE_VTABLE; +const struct mg_iface_vtable mg_default_iface_vtable = MG_PIC32_IFACE_VTABLE; #endif #endif /* MG_ENABLE_NET_IF_PIC32 */ diff --git a/mongoose.h b/mongoose.h index 45fab927b..0812f9a5f 100644 --- a/mongoose.h +++ b/mongoose.h @@ -3002,7 +3002,7 @@ struct mg_iface_vtable; struct mg_iface { struct mg_mgr *mgr; void *data; /* Implementation-specific data */ - struct mg_iface_vtable *vtable; + const struct mg_iface_vtable *vtable; }; struct mg_iface_vtable { @@ -3041,11 +3041,11 @@ struct mg_iface_vtable { union socket_address *sa); }; -extern struct mg_iface_vtable *mg_ifaces[]; +extern const struct mg_iface_vtable *mg_ifaces[]; extern int mg_num_ifaces; /* Creates a new interface instance. */ -struct mg_iface *mg_if_create_iface(struct mg_iface_vtable *vtable, +struct mg_iface *mg_if_create_iface(const struct mg_iface_vtable *vtable, struct mg_mgr *mgr); /* @@ -3053,7 +3053,7 @@ struct mg_iface *mg_if_create_iface(struct mg_iface_vtable *vtable, * interface `from`, exclusive. Returns NULL if none is found. */ struct mg_iface *mg_find_iface(struct mg_mgr *mgr, - struct mg_iface_vtable *vtable, + const struct mg_iface_vtable *vtable, struct mg_iface *from); /* * Deliver a new TCP connection. Returns NULL in case on error (unable to @@ -3348,9 +3348,9 @@ void mg_mgr_init(struct mg_mgr *mgr, void *user_data); * `num_ifaces` pointers it contains will be reclaimed by `mg_mgr_free`. */ struct mg_mgr_init_opts { - struct mg_iface_vtable *main_iface; + const struct mg_iface_vtable *main_iface; int num_ifaces; - struct mg_iface_vtable **ifaces; + const struct mg_iface_vtable **ifaces; }; /* -- GitLab