Skip to content

Commit d1e5539

Browse files
committed
misc: removed dead code, guard non-OpenResty LuaJIT definitions, and fixed styling issues.
1 parent 478bae6 commit d1e5539

15 files changed

+143
-170
lines changed

src/api/ngx_http_lua_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/* Public API for other Nginx modules */
2020

2121

22-
#define ngx_http_lua_version 10016
22+
#define ngx_http_lua_version 10016
2323

2424

2525
typedef struct {

src/ngx_http_lua_balancer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static ngx_int_t ngx_http_lua_balancer_get_peer(ngx_peer_connection_t *pc,
5454
void *data);
5555
static ngx_int_t ngx_http_lua_balancer_by_chunk(lua_State *L,
5656
ngx_http_request_t *r);
57-
void ngx_http_lua_balancer_free_peer(ngx_peer_connection_t *pc, void *data,
58-
ngx_uint_t state);
57+
static void ngx_http_lua_balancer_free_peer(ngx_peer_connection_t *pc,
58+
void *data, ngx_uint_t state);
5959

6060

6161
ngx_int_t
@@ -399,7 +399,7 @@ ngx_http_lua_balancer_by_chunk(lua_State *L, ngx_http_request_t *r)
399399
}
400400

401401

402-
void
402+
static void
403403
ngx_http_lua_balancer_free_peer(ngx_peer_connection_t *pc, void *data,
404404
ngx_uint_t state)
405405
{

src/ngx_http_lua_clfactory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@
288288
typedef enum {
289289
NGX_LUA_TEXT_FILE,
290290
NGX_LUA_BT_LUA,
291-
NGX_LUA_BT_LJ
291+
NGX_LUA_BT_LJ,
292292
} ngx_http_lua_clfactory_file_type_e;
293293

294294

295295
enum {
296-
NGX_LUA_READER_BUFSIZE = 4096
296+
NGX_LUA_READER_BUFSIZE = 4096,
297297
};
298298

299299

src/ngx_http_lua_common.h

Lines changed: 55 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,44 @@
2222
#include <lauxlib.h>
2323

2424

25-
#if (NGX_PCRE)
26-
27-
#include <pcre.h>
25+
#if defined(NDK) && NDK
26+
#include <ndk.h>
2827

29-
#if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
30-
# define LUA_HAVE_PCRE_JIT 1
31-
#else
32-
# define LUA_HAVE_PCRE_JIT 0
28+
typedef struct {
29+
size_t size;
30+
int ref;
31+
u_char *key;
32+
ngx_str_t script;
33+
} ngx_http_lua_set_var_data_t;
3334
#endif
3435

36+
37+
#ifdef NGX_LUA_USE_ASSERT
38+
#include <assert.h>
39+
# define ngx_http_lua_assert(a) assert(a)
40+
#else
41+
# define ngx_http_lua_assert(a)
3542
#endif
3643

3744

38-
#if !defined(nginx_version) || (nginx_version < 1006000)
39-
#error at least nginx 1.6.0 is required but found an older version
45+
#if (NGX_PCRE)
46+
#include <pcre.h>
47+
# if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
48+
# define LUA_HAVE_PCRE_JIT 1
49+
# else
50+
# define LUA_HAVE_PCRE_JIT 0
51+
# endif
4052
#endif
4153

4254

43-
#if defined(NDK) && NDK
44-
#include <ndk.h>
55+
#if !defined(nginx_version) || (nginx_version < 1006000)
56+
# error at least nginx 1.6.0 is required but found an older version
4557
#endif
4658

47-
4859
#if LUA_VERSION_NUM != 501
4960
# error unsupported Lua language version
5061
#endif
5162

52-
5363
#if !defined(LUAJIT_VERSION_NUM) || (LUAJIT_VERSION_NUM < 20000)
5464
# error unsupported LuaJIT version
5565
#endif
@@ -60,26 +70,25 @@
6070
#endif
6171

6272
#ifndef NGX_HTTP_PERMANENT_REDIRECT
63-
# define NGX_HTTP_PERMANENT_REDIRECT 308
73+
# define NGX_HTTP_PERMANENT_REDIRECT 308
6474
#endif
6575

6676
#ifndef NGX_HAVE_SHA1
6777
# if defined(nginx_version) && (nginx_version >= 1011002)
68-
# define NGX_HAVE_SHA1 1
78+
# define NGX_HAVE_SHA1 1
6979
# endif
7080
#endif
7181

72-
7382
#ifndef MD5_DIGEST_LENGTH
74-
#define MD5_DIGEST_LENGTH 16
83+
# define MD5_DIGEST_LENGTH 16
7584
#endif
7685

86+
#ifndef NGX_HTTP_LUA_MAX_ARGS
87+
# define NGX_HTTP_LUA_MAX_ARGS 100
88+
#endif
7789

78-
#ifdef NGX_LUA_USE_ASSERT
79-
# include <assert.h>
80-
# define ngx_http_lua_assert(a) assert(a)
81-
#else
82-
# define ngx_http_lua_assert(a)
90+
#ifndef NGX_HTTP_LUA_MAX_HEADERS
91+
# define NGX_HTTP_LUA_MAX_HEADERS 100
8392
#endif
8493

8594

@@ -104,26 +113,6 @@
104113
(NGX_HTTP_LUA_FILE_TAG_LEN + 2 * MD5_DIGEST_LENGTH)
105114

106115

107-
#if defined(NDK) && NDK
108-
typedef struct {
109-
size_t size;
110-
int ref;
111-
u_char *key;
112-
ngx_str_t script;
113-
} ngx_http_lua_set_var_data_t;
114-
#endif
115-
116-
117-
#ifndef NGX_HTTP_LUA_MAX_ARGS
118-
#define NGX_HTTP_LUA_MAX_ARGS 100
119-
#endif
120-
121-
122-
#ifndef NGX_HTTP_LUA_MAX_HEADERS
123-
#define NGX_HTTP_LUA_MAX_HEADERS 100
124-
#endif
125-
126-
127116
/* must be within 16 bit */
128117
#define NGX_HTTP_LUA_CONTEXT_SET 0x0001
129118
#define NGX_HTTP_LUA_CONTEXT_REWRITE 0x0002
@@ -145,30 +134,38 @@ typedef struct {
145134

146135

147136
#if (NGX_PTR_SIZE >= 8 && !defined(_WIN64))
148-
#define ngx_http_lua_lightudata_mask(ludata) \
149-
((void *) ((uintptr_t) (&ngx_http_lua_##ludata) & ((1UL << 47) - 1)))
150-
137+
# define ngx_http_lua_lightudata_mask(ludata) \
138+
((void *) ((uintptr_t) (&ngx_http_lua_##ludata) & ((1UL << 47) - 1)))
151139
#else
152-
#define ngx_http_lua_lightudata_mask(ludata) (&ngx_http_lua_##ludata)
140+
# define ngx_http_lua_lightudata_mask(ludata) \
141+
(&ngx_http_lua_##ludata)
153142
#endif
154143

155144

156-
typedef struct ngx_http_lua_main_conf_s ngx_http_lua_main_conf_t;
157-
typedef union ngx_http_lua_srv_conf_u ngx_http_lua_srv_conf_t;
145+
typedef struct ngx_http_lua_co_ctx_s ngx_http_lua_co_ctx_t;
158146

147+
typedef struct ngx_http_lua_sema_mm_s ngx_http_lua_sema_mm_t;
159148

160-
typedef struct ngx_http_lua_balancer_peer_data_s
161-
ngx_http_lua_balancer_peer_data_t;
149+
typedef union ngx_http_lua_srv_conf_u ngx_http_lua_srv_conf_t;
162150

151+
typedef struct ngx_http_lua_main_conf_s ngx_http_lua_main_conf_t;
163152

164-
typedef struct ngx_http_lua_sema_mm_s ngx_http_lua_sema_mm_t;
153+
typedef struct ngx_http_lua_header_val_s ngx_http_lua_header_val_t;
154+
155+
typedef struct ngx_http_lua_posted_thread_s ngx_http_lua_posted_thread_t;
165156

157+
typedef struct ngx_http_lua_balancer_peer_data_s
158+
ngx_http_lua_balancer_peer_data_t;
166159

167160
typedef ngx_int_t (*ngx_http_lua_main_conf_handler_pt)(ngx_log_t *log,
168161
ngx_http_lua_main_conf_t *lmcf, lua_State *L);
162+
169163
typedef ngx_int_t (*ngx_http_lua_srv_conf_handler_pt)(ngx_http_request_t *r,
170164
ngx_http_lua_srv_conf_t *lscf, lua_State *L);
171165

166+
typedef ngx_int_t (*ngx_http_lua_set_header_pt)(ngx_http_request_t *r,
167+
ngx_http_lua_header_val_t *hv, ngx_str_t *value);
168+
172169

173170
typedef struct {
174171
u_char *package;
@@ -198,11 +195,9 @@ struct ngx_http_lua_main_conf_s {
198195
ngx_int_t regex_cache_entries;
199196
ngx_int_t regex_cache_max_entries;
200197
ngx_int_t regex_match_limit;
201-
202-
#if (LUA_HAVE_PCRE_JIT)
198+
# if (LUA_HAVE_PCRE_JIT)
203199
pcre_jit_stack *jit_stack;
204-
#endif
205-
200+
# endif
206201
#endif
207202

208203
ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */
@@ -298,10 +293,10 @@ union ngx_http_lua_srv_conf_u {
298293
#endif
299294

300295
struct {
301-
ngx_http_lua_srv_conf_handler_pt handler;
302-
ngx_str_t src;
303-
u_char *src_key;
304-
int src_ref;
296+
ngx_http_lua_srv_conf_handler_pt handler;
297+
ngx_str_t src;
298+
u_char *src_key;
299+
int src_ref;
305300
} balancer;
306301
};
307302

@@ -398,7 +393,7 @@ typedef enum {
398393
NGX_HTTP_LUA_USER_CORO_NOP = 0,
399394
NGX_HTTP_LUA_USER_CORO_RESUME = 1,
400395
NGX_HTTP_LUA_USER_CORO_YIELD = 2,
401-
NGX_HTTP_LUA_USER_THREAD_RESUME = 3
396+
NGX_HTTP_LUA_USER_THREAD_RESUME = 3,
402397
} ngx_http_lua_user_coro_op_t;
403398

404399

@@ -411,21 +406,12 @@ typedef enum {
411406
} ngx_http_lua_co_status_t;
412407

413408

414-
typedef struct ngx_http_lua_co_ctx_s ngx_http_lua_co_ctx_t;
415-
416-
typedef struct ngx_http_lua_posted_thread_s ngx_http_lua_posted_thread_t;
417-
418409
struct ngx_http_lua_posted_thread_s {
419410
ngx_http_lua_co_ctx_t *co_ctx;
420411
ngx_http_lua_posted_thread_t *next;
421412
};
422413

423414

424-
enum {
425-
NGX_HTTP_LUA_SUBREQ_TRUNCATED = 1
426-
};
427-
428-
429415
struct ngx_http_lua_co_ctx_s {
430416
void *data; /* user state for cosockets */
431417

@@ -615,13 +601,6 @@ typedef struct ngx_http_lua_ctx_s {
615601
} ngx_http_lua_ctx_t;
616602

617603

618-
typedef struct ngx_http_lua_header_val_s ngx_http_lua_header_val_t;
619-
620-
621-
typedef ngx_int_t (*ngx_http_lua_set_header_pt)(ngx_http_request_t *r,
622-
ngx_http_lua_header_val_t *hv, ngx_str_t *value);
623-
624-
625604
struct ngx_http_lua_header_val_s {
626605
ngx_http_complex_value_t value;
627606
ngx_uint_t hash;

src/ngx_http_lua_directive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ enum {
6666
FOUND_RIGHT_LBRACKET,
6767
FOUND_COMMENT_LINE,
6868
FOUND_DOUBLE_QUOTED,
69-
FOUND_SINGLE_QUOTED
69+
FOUND_SINGLE_QUOTED,
7070
};
7171

7272

@@ -1272,7 +1272,7 @@ ngx_http_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)
12721272
ngx_array_t *saved;
12731273
enum {
12741274
parse_block = 0,
1275-
parse_param
1275+
parse_param,
12761276
} type;
12771277

12781278
if (cf->conf_file->file.fd != NGX_INVALID_FILE) {
@@ -1422,7 +1422,7 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
14221422
ngx_http_lua_block_parser_ctx_t *ctx)
14231423
{
14241424
enum {
1425-
OVEC_SIZE = 2
1425+
OVEC_SIZE = 2,
14261426
};
14271427
int i, rc;
14281428
int ovec[OVEC_SIZE];

src/ngx_http_lua_headers_in.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ ngx_http_lua_validate_host(ngx_str_t *host, ngx_pool_t *pool, ngx_uint_t alloc)
340340
enum {
341341
sw_usual = 0,
342342
sw_literal,
343-
sw_rest
343+
sw_rest,
344344
} state;
345345

346346
dot_pos = host->len;

src/ngx_http_lua_log_ringbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef struct {
1717

1818

1919
enum {
20-
HEADER_LEN = sizeof(ngx_http_lua_log_ringbuf_header_t)
20+
HEADER_LEN = sizeof(ngx_http_lua_log_ringbuf_header_t),
2121
};
2222

2323

src/ngx_http_lua_pipe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ enum {
118118
PIPE_ERR_TIMEOUT,
119119
PIPE_ERR_ADD_READ_EV,
120120
PIPE_ERR_ADD_WRITE_EV,
121-
PIPE_ERR_ABORTED
121+
PIPE_ERR_ABORTED,
122122
};
123123

124124

125125
enum {
126126
PIPE_READ_ALL = 0,
127127
PIPE_READ_BYTES,
128128
PIPE_READ_LINE,
129-
PIPE_READ_ANY
129+
PIPE_READ_ANY,
130130
};
131131

132132

src/ngx_http_lua_semaphore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void ngx_http_lua_ffi_sema_gc(ngx_http_lua_sema_t *sem);
3737

3838
enum {
3939
SEMAPHORE_WAIT_SUCC = 0,
40-
SEMAPHORE_WAIT_TIMEOUT = 1
40+
SEMAPHORE_WAIT_TIMEOUT = 1,
4141
};
4242

4343

src/ngx_http_lua_socket_tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ enum {
174174
SOCKET_OP_CONNECT,
175175
SOCKET_OP_READ,
176176
SOCKET_OP_WRITE,
177-
SOCKET_OP_RESUME_CONN
177+
SOCKET_OP_RESUME_CONN,
178178
};
179179

180180

@@ -1915,8 +1915,8 @@ ngx_http_lua_ssl_handshake_retval_handler(ngx_http_request_t *r,
19151915
} else {
19161916
*ud = ssl_session;
19171917

1918-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
1919-
"lua ssl save session: %p", ssl_session);
1918+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
1919+
"lua ssl save session: %p", ssl_session);
19201920

19211921
/* set up the __gc metamethod */
19221922
lua_pushlightuserdata(L, ngx_http_lua_lightudata_mask(

0 commit comments

Comments
 (0)