Skip to content

Commit 40375e3

Browse files
committed
feature: updated the subsys templates to support the new ngx_meta_lua_module.
1 parent fe748fb commit 40375e3

17 files changed

+55
-2564
lines changed

src/http/ngx_http_lua_headerfilterby.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "ngx_http_lua_string.h"
2020
#include "ngx_http_lua_misc.h"
2121
#include "ngx_http_lua_consts.h"
22-
#include "ngx_http_lua_shdict.h"
2322

2423

2524
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;

src/http/ngx_http_lua_setby.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "ngx_http_lua_string.h"
2020
#include "ngx_http_lua_misc.h"
2121
#include "ngx_http_lua_consts.h"
22-
#include "ngx_http_lua_shdict.h"
2322
#include "ngx_http_lua_util.h"
2423

2524

src/subsys/api/ngx_subsys_lua_api.h.tt2

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ lua_State *ngx_[% subsys %]_lua_get_global_state(ngx_conf_t *cf);
5757
ngx_int_t ngx_[% subsys %]_lua_add_package_preload(ngx_conf_t *cf,
5858
const char *package, lua_CFunction func);
5959

60-
ngx_int_t ngx_[% subsys %]_lua_shared_dict_get(ngx_shm_zone_t *shm_zone,
61-
u_char *key_data, size_t key_len, ngx_[% subsys %]_lua_value_t *value);
62-
63-
ngx_shm_zone_t *ngx_[% subsys %]_lua_find_zone(u_char *name_data,
64-
size_t name_len);
65-
66-
ngx_shm_zone_t *ngx_[% subsys %]_lua_shared_memory_add(ngx_conf_t *cf,
67-
ngx_str_t *name, size_t size, void *tag);
68-
6960

7061
#endif /* _NGX_[% SUBSYS %]_LUA_API_H_INCLUDED_ */
7162

src/subsys/ddebug.h.tt2

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/subsys/ngx_subsys_lua_api.c.tt2

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "ngx_[% subsys %]_lua_common.h"
1414
#include "api/ngx_[% subsys %]_lua_api.h"
15-
#include "ngx_[% subsys %]_lua_shdict.h"
1615
#include "ngx_[% subsys %]_lua_util.h"
1716

1817

@@ -34,10 +33,6 @@ ngx_[% subsys %]_lua_get_request(lua_State *L)
3433
}
3534

3635

37-
static ngx_int_t ngx_[% subsys %]_lua_shared_memory_init(ngx_shm_zone_t *shm_zone,
38-
void *data);
39-
40-
4136
ngx_int_t
4237
ngx_[% subsys %]_lua_add_package_preload(ngx_conf_t *cf, const char *package,
4338
lua_CFunction func)
@@ -84,135 +79,4 @@ ngx_[% subsys %]_lua_add_package_preload(ngx_conf_t *cf, const char *package,
8479
}
8580

8681

87-
ngx_shm_zone_t *
88-
ngx_[% subsys %]_lua_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name,
89-
size_t size, void *tag)
90-
{
91-
ngx_[% subsys %]_lua_main_conf_t *lmcf;
92-
ngx_[% subsys %]_lua_shm_zone_ctx_t *ctx;
93-
94-
ngx_shm_zone_t **zp;
95-
ngx_shm_zone_t *zone;
96-
ngx_int_t n;
97-
98-
lmcf = ngx_[% subsys %]_conf_get_module_main_conf(cf, ngx_[% subsys %]_lua_module);
99-
if (lmcf == NULL) {
100-
return NULL;
101-
}
102-
103-
if (lmcf->shm_zones == NULL) {
104-
lmcf->shm_zones = ngx_palloc(cf->pool, sizeof(ngx_array_t));
105-
if (lmcf->shm_zones == NULL) {
106-
return NULL;
107-
}
108-
109-
if (ngx_array_init(lmcf->shm_zones, cf->pool, 2,
110-
sizeof(ngx_shm_zone_t *))
111-
!= NGX_OK)
112-
{
113-
return NULL;
114-
}
115-
}
116-
117-
zone = ngx_shared_memory_add(cf, name, (size_t) size, tag);
118-
if (zone == NULL) {
119-
return NULL;
120-
}
121-
122-
if (zone->data) {
123-
ctx = (ngx_[% subsys %]_lua_shm_zone_ctx_t *) zone->data;
124-
return &ctx->zone;
125-
}
126-
127-
n = sizeof(ngx_[% subsys %]_lua_shm_zone_ctx_t);
128-
129-
ctx = ngx_pcalloc(cf->pool, n);
130-
if (ctx == NULL) {
131-
return NULL;
132-
}
133-
134-
ctx->lmcf = lmcf;
135-
ctx->log = &cf->cycle->new_log;
136-
ctx->cycle = cf->cycle;
137-
138-
ngx_memcpy(&ctx->zone, zone, sizeof(ngx_shm_zone_t));
139-
140-
zp = ngx_array_push(lmcf->shm_zones);
141-
if (zp == NULL) {
142-
return NULL;
143-
}
144-
145-
*zp = zone;
146-
147-
/* set zone init */
148-
zone->init = ngx_[% subsys %]_lua_shared_memory_init;
149-
zone->data = ctx;
150-
151-
lmcf->requires_shm = 1;
152-
153-
return &ctx->zone;
154-
}
155-
156-
157-
static ngx_int_t
158-
ngx_[% subsys %]_lua_shared_memory_init(ngx_shm_zone_t *shm_zone, void *data)
159-
{
160-
ngx_[% subsys %]_lua_shm_zone_ctx_t *octx = data;
161-
ngx_[% subsys %]_lua_main_conf_t *lmcf;
162-
ngx_[% subsys %]_lua_shm_zone_ctx_t *ctx;
163-
164-
ngx_shm_zone_t *ozone;
165-
void *odata;
166-
ngx_int_t rc;
167-
volatile ngx_cycle_t *saved_cycle;
168-
ngx_shm_zone_t *zone;
169-
170-
ctx = (ngx_[% subsys %]_lua_shm_zone_ctx_t *) shm_zone->data;
171-
zone = &ctx->zone;
172-
173-
odata = NULL;
174-
if (octx) {
175-
ozone = &octx->zone;
176-
odata = ozone->data;
177-
}
178-
179-
zone->shm = shm_zone->shm;
180-
#if defined(nginx_version) && nginx_version >= 1009000
181-
zone->noreuse = shm_zone->noreuse;
182-
#endif
183-
184-
if (zone->init(zone, odata) != NGX_OK) {
185-
return NGX_ERROR;
186-
}
187-
188-
dd("get lmcf");
189-
190-
lmcf = ctx->lmcf;
191-
if (lmcf == NULL) {
192-
return NGX_ERROR;
193-
}
194-
195-
dd("lmcf->lua: %p", lmcf->lua);
196-
197-
lmcf->shm_zones_inited++;
198-
199-
if (lmcf->shm_zones_inited == lmcf->shm_zones->nelts
200-
&& lmcf->init_handler && !ngx_test_config)
201-
{
202-
saved_cycle = ngx_cycle;
203-
ngx_cycle = ctx->cycle;
204-
205-
rc = lmcf->init_handler(ctx->log, lmcf, lmcf->lua);
206-
207-
ngx_cycle = saved_cycle;
208-
209-
if (rc != NGX_OK) {
210-
/* an error happened */
211-
return NGX_ERROR;
212-
}
213-
}
214-
215-
return NGX_OK;
216-
}
217-
21882
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/subsys/ngx_subsys_lua_common.h.tt2

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <lauxlib.h>
2525

2626

27+
#include "ngx_meta_lua_api.h"
28+
29+
2730
[% IF stream_subsys %]
2831
#include "ngx_stream_lua_request.h"
2932
[% END %]
@@ -52,6 +55,11 @@
5255
#endif
5356

5457

58+
#if !defined(ngx_meta_lua_version) || ngx_meta_lua_version < 00001
59+
# error ngx_meta_lua_module 0.0.1 or above is required
60+
#endif
61+
62+
5563
[% IF http_subsys %]
5664
#if defined(NDK) && NDK
5765
#include <ndk.h>
@@ -204,8 +212,6 @@ typedef struct ngx_[% subsys %]_lua_balancer_peer_data_s
204212
typedef struct ngx_[% subsys %]_lua_sema_mm_s ngx_[% subsys %]_lua_sema_mm_t;
205213

206214

207-
typedef ngx_int_t (*ngx_[% subsys %]_lua_main_conf_handler_pt)(ngx_log_t *log,
208-
ngx_[% subsys %]_lua_main_conf_t *lmcf, lua_State *L);
209215
typedef ngx_int_t (*ngx_[% subsys %]_lua_srv_conf_handler_pt)(
210216
[% req_type %] *r, ngx_[% subsys %]_lua_srv_conf_t *lscf, lua_State *L);
211217

@@ -245,10 +251,6 @@ struct ngx_[% subsys %]_lua_main_conf_s {
245251

246252
#endif
247253

248-
ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */
249-
250-
ngx_array_t *shdict_zones; /* shm zones of "shdict" */
251-
252254
ngx_array_t *preload_hooks; /* of ngx_[% subsys %]_lua_preload_hook_t */
253255

254256
[% IF http_subsys %]
@@ -259,10 +261,10 @@ struct ngx_[% subsys %]_lua_main_conf_s {
259261
ngx_flag_t postponed_to_preread_phase_end;
260262
[% END %]
261263

262-
ngx_[% subsys %]_lua_main_conf_handler_pt init_handler;
264+
ngx_meta_lua_main_conf_handler_pt init_handler;
263265
ngx_str_t init_src;
264266

265-
ngx_[% subsys %]_lua_main_conf_handler_pt init_worker_handler;
267+
ngx_meta_lua_main_conf_handler_pt init_worker_handler;
266268
ngx_str_t init_worker_src;
267269

268270
ngx_[% subsys %]_lua_balancer_peer_data_t *balancer_peer_data;
@@ -295,8 +297,6 @@ struct ngx_[% subsys %]_lua_main_conf_s {
295297
*/
296298

297299
[% END %]
298-
ngx_uint_t shm_zones_inited;
299-
300300
ngx_[% subsys %]_lua_sema_mm_t *sema_mm;
301301

302302
ngx_uint_t malloc_trim_cycle; /* a cycle is defined as the number
@@ -327,7 +327,6 @@ struct ngx_[% subsys %]_lua_main_conf_s {
327327
[% END %]
328328

329329
unsigned requires_log:1;
330-
unsigned requires_shm:1;
331330
unsigned requires_capture_log:1;
332331
};
333332

0 commit comments

Comments
 (0)