From a718b29b6d4566a601d70ef039db5cd5f3c4562c Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Wed, 4 Mar 2015 16:48:34 +0100 Subject: [PATCH] MINOR: lua: remove some #define The #define compilation directives are centralized in the hlua include files. This permits to remove ome #ifdef from the haproxy main code. --- include/proto/hlua.h | 15 +++++++++++++++ include/types/hlua.h | 10 ++++++++++ include/types/session.h | 5 ----- include/types/stream_interface.h | 4 ---- src/haproxy.c | 6 ------ src/hlua.c | 3 +++ src/session.c | 11 ++--------- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/proto/hlua.h b/include/proto/hlua.h index 50d6aa333e..b9530aa0a5 100644 --- a/include/proto/hlua.h +++ b/include/proto/hlua.h @@ -1,13 +1,28 @@ #ifndef _PROTO_HLUA_H #define _PROTO_HLUA_H +#ifdef USE_LUA + #include #include +#define HLUA_INIT(__hlua) do { (__hlua)->T = 0; } while(0) + /* Lua HAProxy integration functions. */ void hlua_ctx_destroy(struct hlua *lua); void hlua_init(); int hlua_post_init(); +#else /* USE_LUA */ + +#define HLUA_INIT(__hlua) + +/* Empty function for compilation without Lua. */ +static inline void hlua_init() { } +static inline int hlua_post_init() { return 1; } +static inline void hlua_ctx_destroy() { } + +#endif /* USE_LUA */ + #endif /* _PROTO_HLUA_H */ diff --git a/include/types/hlua.h b/include/types/hlua.h index d0e0348e59..2257d5c8ab 100644 --- a/include/types/hlua.h +++ b/include/types/hlua.h @@ -1,6 +1,8 @@ #ifndef _TYPES_HLUA_H #define _TYPES_HLUA_H +#ifdef USE_LUA + #include #include @@ -121,4 +123,12 @@ struct hlua_channel { struct channel *chn; }; +#else /* USE_LUA */ + +/* Empty struct for compilation compatibility */ +struct hlua { }; +struct hlua_socket { }; + +#endif /* USE_LUA */ + #endif /* _TYPES_HLUA_H */ diff --git a/include/types/session.h b/include/types/session.h index ad31ae2dd9..8aa20bd88c 100644 --- a/include/types/session.h +++ b/include/types/session.h @@ -33,10 +33,7 @@ #include #include - -#ifdef USE_LUA #include -#endif #include #include #include @@ -164,9 +161,7 @@ struct session { struct list *current_rule_list; /* this is used to store the current executed rule list. */ struct list *current_rule; /* this is used to store the current rule to be resumed. */ -#ifdef USE_LUA struct hlua hlua; /* lua runtime context */ -#endif }; #endif /* _TYPES_SESSION_H */ diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h index ab0e750c4f..03cdd6e32e 100644 --- a/include/types/stream_interface.h +++ b/include/types/stream_interface.h @@ -27,9 +27,7 @@ #include #include -#ifdef USE_LUA #include -#endif #include #include @@ -153,14 +151,12 @@ struct appctx { struct pattern_expr *expr; struct chunk chunk; } map; -#ifdef USE_LUA struct { int connected; struct hlua_socket *socket; struct list wake_on_read; struct list wake_on_write; } hlua; -#endif } ctx; /* used by stats I/O handlers to dump the stats */ }; diff --git a/src/haproxy.c b/src/haproxy.c index 19687b2f29..872aab827b 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -88,9 +88,7 @@ #include #include #include -#ifdef USE_LUA #include -#endif #include #include #include @@ -567,10 +565,8 @@ void init(int argc, char **argv) init_pendconn(); init_proto_http(); -#ifdef USE_LUA /* Initialise lua. */ hlua_init(); -#endif global.tune.options |= GTUNE_USE_SELECT; /* select() is always available */ #if defined(ENABLE_POLL) @@ -1064,10 +1060,8 @@ void init(int argc, char **argv) if (!global.node) global.node = strdup(hostname); -#ifdef USE_LUA if (!hlua_post_init()) exit(1); -#endif } static void deinit_acl_cond(struct acl_cond *cond) diff --git a/src/hlua.c b/src/hlua.c index d3f302f0b9..83c31a7ac2 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -526,6 +526,9 @@ int hlua_ctx_init(struct hlua *lua, struct task *task) */ void hlua_ctx_destroy(struct hlua *lua) { + if (!lua->T) + return; + /* Remove context. */ hlua_delhlua(lua); diff --git a/src/session.c b/src/session.c index 77ec4ca2ab..fd1a60621e 100644 --- a/src/session.c +++ b/src/session.c @@ -33,9 +33,7 @@ #include #include #include -#ifdef USE_LUA #include -#endif #include #include #include @@ -544,9 +542,7 @@ int session_complete(struct session *s) txn->req.chn = s->req; txn->rsp.chn = s->rep; -#ifdef USE_LUA - s->hlua.T = NULL; -#endif + HLUA_INIT(&s->hlua); /* finish initialization of the accepted file descriptor */ conn_data_want_recv(conn); @@ -635,10 +631,7 @@ static void session_free(struct session *s) if (!LIST_ISEMPTY(&buffer_wq)) session_offer_buffers(); -#ifdef USE_LUA - if (s->hlua.T) - hlua_ctx_destroy(&s->hlua); -#endif + hlua_ctx_destroy(&s->hlua); pool_free2(pool2_channel, s->req); pool_free2(pool2_channel, s->rep); -- 2.47.2