Skip to content

Commit 9d5e807

Browse files
committed
Attempt to make mod_lua compile under a strict c89 compiler by moving all variable declarations to be before code.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@728539 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7664304 commit 9d5e807

5 files changed

Lines changed: 61 additions & 41 deletions

File tree

modules/lua/lua_apr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434

3535
apr_table_t *check_apr_table(lua_State *L, int index)
3636
{
37+
apr_table_t *t;
3738
luaL_checkudata(L, index, "Apr.Table");
38-
apr_table_t *t = (apr_table_t *) lua_unboxpointer(L, index);
39+
t = (apr_table_t *) lua_unboxpointer(L, index);
3940
return t;
4041
}
4142

modules/lua/lua_config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020

2121
static apl_dir_cfg *check_dir_config(lua_State *L, int index)
2222
{
23+
apl_dir_cfg *cfg;
2324
luaL_checkudata(L, index, "Apache2.DirConfig");
24-
apl_dir_cfg *cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
25+
cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
2526
return cfg;
2627
}
2728

2829
static cmd_parms *check_cmd_parms(lua_State *L, int index)
2930
{
31+
cmd_parms *cmd;
3032
luaL_checkudata(L, index, "Apache2.CommandParameters");
31-
cmd_parms *cmd = (cmd_parms *) lua_unboxpointer(L, index);
33+
cmd = (cmd_parms *) lua_unboxpointer(L, index);
3234
return cmd;
3335
}
3436

modules/lua/lua_request.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ void rstack_dump(lua_State *L, request_rec *r, const char *msg)
9292
*/
9393
static request_rec *apl_check_request_rec(lua_State *L, int index)
9494
{
95+
request_rec *r;
9596
luaL_checkudata(L, index, "Apache2.Request");
96-
request_rec *r = (request_rec *) lua_unboxpointer(L, index);
97+
r = (request_rec *) lua_unboxpointer(L, index);
9798
return r;
9899
}
99100

@@ -102,14 +103,15 @@ static request_rec *apl_check_request_rec(lua_State *L, int index)
102103
static int req_aprtable2luatable_cb(void *l, const char *key,
103104
const char *value)
104105
{
106+
int t;
105107
lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */
106108
/* rstack_dump(L, RRR, "start of cb"); */
107109
/* L is [table<s,t>, table<s,s>] */
108110
/* build complex */
109111

110112
lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
111113
/* rstack_dump(L, RRR, "after getfield"); */
112-
int t = lua_type(L, -1);
114+
t = lua_type(L, -1);
113115
switch (t) {
114116
case LUA_TNIL:
115117
case LUA_TNONE:{
@@ -149,10 +151,10 @@ static int req_aprtable2luatable_cb(void *l, const char *key,
149151
/* r:parseargs() returning a lua table */
150152
static int req_parseargs(lua_State *L)
151153
{
154+
apr_table_t *form_table;
152155
request_rec *r = apl_check_request_rec(L, 1);
153156
lua_newtable(L);
154157
lua_newtable(L); /* [table, table] */
155-
apr_table_t *form_table;
156158
ap_args_to_table(r, &form_table);
157159
apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
158160
return 2; /* [table<string, string>, table<string, array<string>>] */

modules/lua/lua_vmprep.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
static void pstack_dump(lua_State *L, apr_pool_t *r, int level,
2727
const char *msg)
2828
{
29-
ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
30-
3129
int i;
3230
int top = lua_gettop(L);
31+
32+
ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
33+
3334
for (i = 1; i <= top; i++) {
3435
int t = lua_type(L, i);
3536
switch (t) {
@@ -235,19 +236,25 @@ static void munge_path(lua_State *L,
235236
apr_pool_t *pool,
236237
apr_array_header_t *paths, const char *file)
237238
{
239+
const char *current;
240+
const char *parent_dir;
241+
const char *pattern;
242+
const char *modified;
243+
char *part;
244+
int i;
245+
238246
lua_getglobal(L, "package");
239247
lua_getfield(L, -1, field);
240-
const char *current = lua_tostring(L, -1);
241-
const char *parent_dir = ap_make_dirstr_parent(pool, file);
242-
const char *pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
248+
current = lua_tostring(L, -1);
249+
parent_dir = ap_make_dirstr_parent(pool, file);
250+
pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
243251
luaL_gsub(L, current, rep_pat, pattern);
244252
lua_setfield(L, -3, field);
245253
lua_getfield(L, -2, field);
246-
const char *modified = lua_tostring(L, -1);
254+
modified = lua_tostring(L, -1);
247255
lua_pop(L, 2);
248256

249-
char *part = apr_pstrdup(pool, modified);
250-
int i;
257+
part = apr_pstrdup(pool, modified);
251258
for (i = 0; i < paths->nelts; i++) {
252259
const char *new_path = ((const char **) paths->elts)[i];
253260
part = apr_pstrcat(pool, part, ";", new_path, NULL);
@@ -272,12 +279,14 @@ lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
272279
/* not available, so create */
273280
L = luaL_newstate();
274281
luaL_openlibs(L);
275-
if (package_paths)
282+
if (package_paths) {
276283
munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
277284
package_paths, spec->file);
278-
if (package_cpaths)
285+
}
286+
if (package_cpaths) {
279287
munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
280288
package_cpaths, spec->file);
289+
}
281290

282291
if (cb) {
283292
cb(L, lifecycle_pool, btn);

modules/lua/mod_lua.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apl, AP_LUA, int, lua_request,
3939
*/
4040
static void report_lua_error(lua_State *L, request_rec *r)
4141
{
42+
const char *lua_response;
4243
r->status = 500;
4344
r->content_type = "text/html";
4445

4546
ap_rputs("<b>Error!</b>\n", r);
4647
ap_rputs("<p>", r);
47-
const char *lua_response = lua_tostring(L, -1);
48+
lua_response = lua_tostring(L, -1);
4849
ap_rputs(lua_response, r);
4950
ap_rputs("</p>\n", r);
5051

@@ -107,10 +108,14 @@ static int lua_handler(request_rec *r)
107108
apl_dir_cfg *dcfg = ap_get_module_config(r->per_dir_config, &lua_module);
108109

109110
if (!r->header_only) {
111+
lua_State *L;
112+
const apl_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
113+
&lua_module);
110114
apl_request_cfg *rcfg =
111115
ap_get_module_config(r->request_config, &lua_module);
112116
mapped_request_details *d = rcfg->mapped_request_details;
113117
apl_vm_spec *spec = NULL;
118+
114119
if (!d) {
115120
d = apr_palloc(r->pool, sizeof(mapped_request_details));
116121
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
@@ -121,16 +126,15 @@ static int lua_handler(request_rec *r)
121126
d->spec = spec;
122127
d->function_name = "handle";
123128
}
129+
124130
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
125131
"request details scope:%u, cache:%u", d->spec->scope,
126132
d->spec->code_cache_style);
127-
const apl_dir_cfg *cfg =
128-
ap_get_module_config(r->per_dir_config, &lua_module);
129-
lua_State *L = apl_get_lua_state(r->pool,
130-
d->spec,
131-
cfg->package_paths,
132-
cfg->package_cpaths,
133-
&lua_open_callback, NULL);
133+
L = apl_get_lua_state(r->pool,
134+
d->spec,
135+
cfg->package_paths,
136+
cfg->package_cpaths,
137+
&lua_open_callback, NULL);
134138

135139
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
136140
if (!L) {
@@ -154,22 +158,24 @@ static int lua_handler(request_rec *r)
154158
*/
155159
static int apl_alias_munger(request_rec *r)
156160
{
161+
apl_vm_spec *spec;
162+
apl_request_cfg *rcfg = ap_get_module_config(r->request_config,
163+
&lua_module);
157164
const apl_dir_cfg *cfg =
158165
ap_get_module_config(r->per_dir_config, &lua_module);
159-
160166
int i;
161167
ap_regmatch_t matches[AP_MAX_REG_MATCH];
162168

163169
for (i = 0; i < cfg->mapped_handlers->nelts; i++) {
164170
const apl_mapped_handler_spec *cnd =
165-
((const apl_mapped_handler_spec **) cfg->mapped_handlers->
166-
elts)[i];
171+
((const apl_mapped_handler_spec **) cfg->mapped_handlers->elts)[i];
172+
167173
if (OK ==
168174
ap_regexec(cnd->uri_pattern, r->uri, AP_MAX_REG_MATCH, matches,
169175
0)) {
170176
r->handler = "lua-script";
171177

172-
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
178+
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
173179
spec->file =
174180
ap_pregsub(r->pool, cnd->file_name, r->uri, AP_MAX_REG_MATCH,
175181
matches);
@@ -191,8 +197,6 @@ static int apl_alias_munger(request_rec *r)
191197

192198
/* now do replacement on method name where? */
193199
r->filename = apr_pstrdup(r->pool, spec->file);
194-
apl_request_cfg *rcfg =
195-
ap_get_module_config(r->request_config, &lua_module);
196200
rcfg->mapped_request_details = d;
197201
return OK;
198202
}
@@ -206,6 +210,8 @@ static int apl_alias_munger(request_rec *r)
206210

207211
static int lua_request_rec_hook_harness(request_rec *r, const char *name)
208212
{
213+
lua_State *L;
214+
apl_vm_spec *spec;
209215
apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
210216
&lua_module);
211217
const apl_dir_cfg *cfg =
@@ -223,7 +229,7 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
223229
if (hook_spec == NULL) {
224230
continue;
225231
}
226-
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
232+
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
227233

228234
spec->file = hook_spec->file_name;
229235
spec->code_cache_style = hook_spec->code_cache_style;
@@ -234,11 +240,11 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
234240

235241
apr_filepath_merge(&spec->file, server_cfg->root_path,
236242
spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
237-
lua_State *L = apl_get_lua_state(r->pool,
238-
spec,
239-
cfg->package_paths,
240-
cfg->package_cpaths,
241-
&lua_open_callback, NULL);
243+
L = apl_get_lua_state(r->pool,
244+
spec,
245+
cfg->package_paths,
246+
cfg->package_cpaths,
247+
&lua_open_callback, NULL);
242248

243249

244250

@@ -446,6 +452,7 @@ static const char *register_named_block_function_hook(const char *name,
446452
lua_State *lvm;
447453
char *tmp;
448454
int rv;
455+
ap_directive_t **current;
449456

450457
apr_snprintf(buf, sizeof(buf), "%u", cmd->config_file->line_number);
451458
spec->file_name =
@@ -491,7 +498,7 @@ static const char *register_named_block_function_hook(const char *name,
491498
lua_close(lvm);
492499
}
493500

494-
ap_directive_t **current = mconfig;
501+
current = mconfig;
495502

496503
/* Here, we have to replace our current config node for the next pass */
497504
if (!*current) {
@@ -520,6 +527,7 @@ static const char *register_named_file_function_hook(const char *name,
520527
const char *file,
521528
const char *function)
522529
{
530+
apl_mapped_handler_spec *spec;
523531
apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
524532

525533
apr_array_header_t *hook_specs =
@@ -531,8 +539,7 @@ static const char *register_named_file_function_hook(const char *name,
531539
APR_HASH_KEY_STRING, hook_specs);
532540
}
533541

534-
apl_mapped_handler_spec *spec =
535-
apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
542+
spec = apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
536543
spec->file_name = apr_pstrdup(cmd->pool, file);
537544
spec->function_name = apr_pstrdup(cmd->pool, function);
538545
spec->scope = cfg->vm_scope;
@@ -823,10 +830,9 @@ static const char *lua_map_handler(cmd_parms *cmd, void *_cfg,
823830
const char *function)
824831
{
825832
apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
826-
833+
apr_status_t rv;
827834
const char *function_name;
828835
function_name = function ? function : "handle";
829-
apr_status_t rv;
830836
rv = apl_lua_map_handler(cfg, file, function_name, path, "once");
831837
if (rv != APR_SUCCESS) {
832838
return apr_psprintf(cmd->pool,

0 commit comments

Comments
 (0)