You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pq...@apache.org on 2008/12/21 23:21:55 UTC
svn commit: r728531 - in /httpd/httpd/trunk/modules/lua: lua_vmprep.c
lua_vmprep.h mod_lua.c
Author: pquerna
Date: Sun Dec 21 14:21:54 2008
New Revision: 728531
URL: http://svn.apache.org/viewvc?rev=728531&view=rev
Log:
Change apl_get_lua_state to take a apl_vm_spec instead of a filename, and to
load the bytecode if it is present, rather than the file, as this gets the
inline config file blocks hooks working again.
Modified:
httpd/httpd/trunk/modules/lua/lua_vmprep.c
httpd/httpd/trunk/modules/lua/lua_vmprep.h
httpd/httpd/trunk/modules/lua/mod_lua.c
Modified: httpd/httpd/trunk/modules/lua/lua_vmprep.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_vmprep.c?rev=728531&r1=728530&r2=728531&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_vmprep.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_vmprep.c Sun Dec 21 14:21:54 2008
@@ -258,7 +258,7 @@
}
lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
- char *file,
+ apl_vm_spec *spec,
apr_array_header_t *package_paths,
apr_array_header_t *package_cpaths,
apl_lua_state_open_callback cb, void *btn)
@@ -267,29 +267,37 @@
lua_State *L;
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
"obtaining lua_State");
- if (!apr_pool_userdata_get((void **) &L, file, lifecycle_pool)) {
+ if (!apr_pool_userdata_get((void **) &L, spec->file, lifecycle_pool)) {
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
- "creating lua_State with file %s", file);
+ "creating lua_State with file %s", spec->file);
/* not available, so create */
L = luaL_newstate();
luaL_openlibs(L);
if (package_paths)
munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
- package_paths, file);
+ package_paths, spec->file);
if (package_cpaths)
munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
- package_cpaths, file);
+ package_cpaths, spec->file);
if (cb) {
cb(L, lifecycle_pool, btn);
}
- luaL_loadfile(L, file);
- lua_pcall(L, 0, LUA_MULTRET, 0);
- apr_pool_userdata_set(L, file, &cleanup_lua, lifecycle_pool);
+ apr_pool_userdata_set(L, spec->file, &cleanup_lua, lifecycle_pool);
+
+ if (spec->bytecode && spec->bytecode_len > 0) {
+ luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
+ lua_pcall(L, 0, LUA_MULTRET, 0);
+ }
+ else {
+ luaL_loadfile(L, spec->file);
+ lua_pcall(L, 0, LUA_MULTRET, 0);
+ }
lua_pushlightuserdata(L, lifecycle_pool);
lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
}
+
return L;
}
Modified: httpd/httpd/trunk/modules/lua/lua_vmprep.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_vmprep.h?rev=728531&r1=728530&r2=728531&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_vmprep.h (original)
+++ httpd/httpd/trunk/modules/lua/lua_vmprep.h Sun Dec 21 14:21:54 2008
@@ -65,6 +65,10 @@
/* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
apr_pool_t *pool;
+ /* Pre-compiled Lua Byte code to load directly. If bytecode_len is >0,
+ * the file part of this structure is ignored for loading purposes, but
+ * it is used for error messages.
+ */
const char *bytecode;
apr_size_t bytecode_len;
} apl_vm_spec;
@@ -127,7 +131,7 @@
* @ctx a baton passed to cb
*/
lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
- char *file,
+ apl_vm_spec *spec,
apr_array_header_t *package_paths,
apr_array_header_t *package_cpaths,
apl_lua_state_open_callback cb, void *btn);
Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=728531&r1=728530&r2=728531&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
+++ httpd/httpd/trunk/modules/lua/mod_lua.c Sun Dec 21 14:21:54 2008
@@ -127,7 +127,7 @@
const apl_dir_cfg *cfg =
ap_get_module_config(r->per_dir_config, &lua_module);
lua_State *L = apl_get_lua_state(r->pool,
- d->spec->file,
+ d->spec,
cfg->package_paths,
cfg->package_cpaths,
&lua_open_callback, NULL);
@@ -206,8 +206,8 @@
static int lua_request_rec_hook_harness(request_rec *r, const char *name)
{
- char *fixed_filename;
-
+ apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
+ &lua_module);
const apl_dir_cfg *cfg =
(apl_dir_cfg *) ap_get_module_config(r->per_dir_config,
&lua_module);
@@ -216,10 +216,13 @@
if (hook_specs) {
int i;
for (i = 0; i < hook_specs->nelts; i++) {
+ char *fixed_filename = NULL;
apl_mapped_handler_spec *hook_spec =
((apl_mapped_handler_spec **) hook_specs->elts)[i];
- if (hook_spec == NULL)
+
+ if (hook_spec == NULL) {
continue;
+ }
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec->file = hook_spec->file_name;
@@ -229,20 +232,10 @@
spec->bytecode_len = hook_spec->bytecode_len;
spec->pool = r->pool;
- /*
- const apl_dir_cfg* cfg = ap_get_module_config(r->per_dir_config, &lua_module);
- lua_State *L = apl_get_lua_state(r->pool,
- d->spec->file,
- cfg->package_paths,
- cfg->package_cpaths,
- &lua_open_callback, NULL);
- */
- apl_server_cfg *server_cfg =
- ap_get_module_config(r->server->module_config, &lua_module);
- apr_filepath_merge(&fixed_filename, server_cfg->root_path,
+ 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,
- fixed_filename,
+ spec,
cfg->package_paths,
cfg->package_cpaths,
&lua_open_callback, NULL);