1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-05 16:55:50 +03:00

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
This commit is contained in:
Paul Querna
2008-12-21 22:38:07 +00:00
parent afa287e242
commit ce336c773a
5 changed files with 61 additions and 41 deletions

View File

@@ -34,8 +34,9 @@
apr_table_t *check_apr_table(lua_State *L, int index)
{
apr_table_t *t;
luaL_checkudata(L, index, "Apr.Table");
apr_table_t *t = (apr_table_t *) lua_unboxpointer(L, index);
t = (apr_table_t *) lua_unboxpointer(L, index);
return t;
}

View File

@@ -20,15 +20,17 @@
static apl_dir_cfg *check_dir_config(lua_State *L, int index)
{
apl_dir_cfg *cfg;
luaL_checkudata(L, index, "Apache2.DirConfig");
apl_dir_cfg *cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
return cfg;
}
static cmd_parms *check_cmd_parms(lua_State *L, int index)
{
cmd_parms *cmd;
luaL_checkudata(L, index, "Apache2.CommandParameters");
cmd_parms *cmd = (cmd_parms *) lua_unboxpointer(L, index);
cmd = (cmd_parms *) lua_unboxpointer(L, index);
return cmd;
}

View File

@@ -92,8 +92,9 @@ void rstack_dump(lua_State *L, request_rec *r, const char *msg)
*/
static request_rec *apl_check_request_rec(lua_State *L, int index)
{
request_rec *r;
luaL_checkudata(L, index, "Apache2.Request");
request_rec *r = (request_rec *) lua_unboxpointer(L, index);
r = (request_rec *) lua_unboxpointer(L, index);
return r;
}
@@ -102,6 +103,7 @@ static request_rec *apl_check_request_rec(lua_State *L, int index)
static int req_aprtable2luatable_cb(void *l, const char *key,
const char *value)
{
int t;
lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */
/* rstack_dump(L, RRR, "start of cb"); */
/* L is [table<s,t>, table<s,s>] */
@@ -109,7 +111,7 @@ static int req_aprtable2luatable_cb(void *l, const char *key,
lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
/* rstack_dump(L, RRR, "after getfield"); */
int t = lua_type(L, -1);
t = lua_type(L, -1);
switch (t) {
case LUA_TNIL:
case LUA_TNONE:{
@@ -149,10 +151,10 @@ static int req_aprtable2luatable_cb(void *l, const char *key,
/* r:parseargs() returning a lua table */
static int req_parseargs(lua_State *L)
{
apr_table_t *form_table;
request_rec *r = apl_check_request_rec(L, 1);
lua_newtable(L);
lua_newtable(L); /* [table, table] */
apr_table_t *form_table;
ap_args_to_table(r, &form_table);
apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
return 2; /* [table<string, string>, table<string, array<string>>] */

View File

@@ -26,10 +26,11 @@
static void pstack_dump(lua_State *L, apr_pool_t *r, int level,
const char *msg)
{
ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
int i;
int top = lua_gettop(L);
ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
for (i = 1; i <= top; i++) {
int t = lua_type(L, i);
switch (t) {
@@ -235,19 +236,25 @@ static void munge_path(lua_State *L,
apr_pool_t *pool,
apr_array_header_t *paths, const char *file)
{
const char *current;
const char *parent_dir;
const char *pattern;
const char *modified;
char *part;
int i;
lua_getglobal(L, "package");
lua_getfield(L, -1, field);
const char *current = lua_tostring(L, -1);
const char *parent_dir = ap_make_dirstr_parent(pool, file);
const char *pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
current = lua_tostring(L, -1);
parent_dir = ap_make_dirstr_parent(pool, file);
pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
luaL_gsub(L, current, rep_pat, pattern);
lua_setfield(L, -3, field);
lua_getfield(L, -2, field);
const char *modified = lua_tostring(L, -1);
modified = lua_tostring(L, -1);
lua_pop(L, 2);
char *part = apr_pstrdup(pool, modified);
int i;
part = apr_pstrdup(pool, modified);
for (i = 0; i < paths->nelts; i++) {
const char *new_path = ((const char **) paths->elts)[i];
part = apr_pstrcat(pool, part, ";", new_path, NULL);
@@ -272,12 +279,14 @@ lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
/* not available, so create */
L = luaL_newstate();
luaL_openlibs(L);
if (package_paths)
if (package_paths) {
munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
package_paths, spec->file);
if (package_cpaths)
}
if (package_cpaths) {
munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
package_cpaths, spec->file);
}
if (cb) {
cb(L, lifecycle_pool, btn);

View File

@@ -39,12 +39,13 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apl, AP_LUA, int, lua_request,
*/
static void report_lua_error(lua_State *L, request_rec *r)
{
const char *lua_response;
r->status = 500;
r->content_type = "text/html";
ap_rputs("<b>Error!</b>\n", r);
ap_rputs("<p>", r);
const char *lua_response = lua_tostring(L, -1);
lua_response = lua_tostring(L, -1);
ap_rputs(lua_response, r);
ap_rputs("</p>\n", r);
@@ -107,10 +108,14 @@ static int lua_handler(request_rec *r)
apl_dir_cfg *dcfg = ap_get_module_config(r->per_dir_config, &lua_module);
if (!r->header_only) {
lua_State *L;
const apl_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
&lua_module);
apl_request_cfg *rcfg =
ap_get_module_config(r->request_config, &lua_module);
mapped_request_details *d = rcfg->mapped_request_details;
apl_vm_spec *spec = NULL;
if (!d) {
d = apr_palloc(r->pool, sizeof(mapped_request_details));
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
@@ -121,12 +126,11 @@ static int lua_handler(request_rec *r)
d->spec = spec;
d->function_name = "handle";
}
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"request details scope:%u, cache:%u", d->spec->scope,
d->spec->code_cache_style);
const apl_dir_cfg *cfg =
ap_get_module_config(r->per_dir_config, &lua_module);
lua_State *L = apl_get_lua_state(r->pool,
L = apl_get_lua_state(r->pool,
d->spec,
cfg->package_paths,
cfg->package_cpaths,
@@ -154,22 +158,24 @@ static int lua_handler(request_rec *r)
*/
static int apl_alias_munger(request_rec *r)
{
apl_vm_spec *spec;
apl_request_cfg *rcfg = ap_get_module_config(r->request_config,
&lua_module);
const apl_dir_cfg *cfg =
ap_get_module_config(r->per_dir_config, &lua_module);
int i;
ap_regmatch_t matches[AP_MAX_REG_MATCH];
for (i = 0; i < cfg->mapped_handlers->nelts; i++) {
const apl_mapped_handler_spec *cnd =
((const apl_mapped_handler_spec **) cfg->mapped_handlers->
elts)[i];
((const apl_mapped_handler_spec **) cfg->mapped_handlers->elts)[i];
if (OK ==
ap_regexec(cnd->uri_pattern, r->uri, AP_MAX_REG_MATCH, matches,
0)) {
r->handler = "lua-script";
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec->file =
ap_pregsub(r->pool, cnd->file_name, r->uri, AP_MAX_REG_MATCH,
matches);
@@ -191,8 +197,6 @@ static int apl_alias_munger(request_rec *r)
/* now do replacement on method name where? */
r->filename = apr_pstrdup(r->pool, spec->file);
apl_request_cfg *rcfg =
ap_get_module_config(r->request_config, &lua_module);
rcfg->mapped_request_details = d;
return OK;
}
@@ -206,6 +210,8 @@ static int apl_alias_munger(request_rec *r)
static int lua_request_rec_hook_harness(request_rec *r, const char *name)
{
lua_State *L;
apl_vm_spec *spec;
apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
&lua_module);
const apl_dir_cfg *cfg =
@@ -223,7 +229,7 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
if (hook_spec == NULL) {
continue;
}
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec->file = hook_spec->file_name;
spec->code_cache_style = hook_spec->code_cache_style;
@@ -234,7 +240,7 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
apr_filepath_merge(&spec->file, server_cfg->root_path,
spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
lua_State *L = apl_get_lua_state(r->pool,
L = apl_get_lua_state(r->pool,
spec,
cfg->package_paths,
cfg->package_cpaths,
@@ -446,6 +452,7 @@ static const char *register_named_block_function_hook(const char *name,
lua_State *lvm;
char *tmp;
int rv;
ap_directive_t **current;
apr_snprintf(buf, sizeof(buf), "%u", cmd->config_file->line_number);
spec->file_name =
@@ -491,7 +498,7 @@ static const char *register_named_block_function_hook(const char *name,
lua_close(lvm);
}
ap_directive_t **current = mconfig;
current = mconfig;
/* Here, we have to replace our current config node for the next pass */
if (!*current) {
@@ -520,6 +527,7 @@ static const char *register_named_file_function_hook(const char *name,
const char *file,
const char *function)
{
apl_mapped_handler_spec *spec;
apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
apr_array_header_t *hook_specs =
@@ -531,8 +539,7 @@ static const char *register_named_file_function_hook(const char *name,
APR_HASH_KEY_STRING, hook_specs);
}
apl_mapped_handler_spec *spec =
apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
spec = apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
spec->file_name = apr_pstrdup(cmd->pool, file);
spec->function_name = apr_pstrdup(cmd->pool, function);
spec->scope = cfg->vm_scope;
@@ -823,10 +830,9 @@ static const char *lua_map_handler(cmd_parms *cmd, void *_cfg,
const char *function)
{
apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
apr_status_t rv;
const char *function_name;
function_name = function ? function : "handle";
apr_status_t rv;
rv = apl_lua_map_handler(cfg, file, function_name, path, "once");
if (rv != APR_SUCCESS) {
return apr_psprintf(cmd->pool,