You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@apache.org on 2008/11/06 18:34:11 UTC
svn commit: r711920 - in /httpd/mod_wombat/trunk: mod_wombat.c vmprep.c
vmprep.h
Author: brianm
Date: Thu Nov 6 09:33:46 2008
New Revision: 711920
URL: http://svn.apache.org/viewvc?rev=711920&view=rev
Log:
more progress on new style lua_State management
Modified:
httpd/mod_wombat/trunk/mod_wombat.c
httpd/mod_wombat/trunk/vmprep.c
httpd/mod_wombat/trunk/vmprep.h
Modified: httpd/mod_wombat/trunk/mod_wombat.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/mod_wombat.c?rev=711920&r1=711919&r2=711920&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/mod_wombat.c (original)
+++ httpd/mod_wombat/trunk/mod_wombat.c Thu Nov 6 09:33:46 2008
@@ -51,6 +51,18 @@
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, r->pool, "Lua error: %s", lua_response);
}
+static void wombat_open_callback(lua_State *L, apr_pool_t *p, void* ctx) {
+ apr_lua_init(L, p);
+ apw_load_apache2_lmodule(L);
+ apw_load_request_lmodule(L, p);
+ apw_load_config_lmodule(L);
+}
+
+static int wombat_open_hook(lua_State *L, apr_pool_t *p) {
+ wombat_open_callback(L, p, NULL);
+ return OK;
+}
+
/*
static apr_status_t wombathood(ap_filter_t *f, apr_bucket_brigade *bb) {
apr_bucket* b;
@@ -106,8 +118,15 @@
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "request details scope:%u, cache:%u",
d->spec->scope,
d->spec->code_cache_style);
- spec = d->spec;
- lua_State *L = apw_rgetvm(r, spec);
+ const apw_dir_cfg* cfg = ap_get_module_config(r->per_dir_config, &wombat_module);
+ lua_State *L = apw_get_lua_state(r->pool,
+ d->spec->file,
+ cfg->package_paths,
+ cfg->package_cpaths,
+ &wombat_open_callback, NULL);
+
+ // lua_State *L = apw_rgetvm(r, spec);
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
if (!L) {
// TODO annotate spec with failure reason
r->status = 500;
@@ -122,6 +141,8 @@
return OK;
}
+
+
/**
* Like mod_alias except for lua handler fun :-)
*/
@@ -511,14 +532,6 @@
return cfg;
}
-static int wombat_open_hook(lua_State *L, apr_pool_t *p) {
- apr_lua_init(L, p);
- apw_load_apache2_lmodule(L);
- apw_load_request_lmodule(L, p);
- apw_load_config_lmodule(L);
- return OK;
-}
-
static int wombat_request_hook(lua_State *L, request_rec *r) {
apw_push_request(L, r);
return OK;
Modified: httpd/mod_wombat/trunk/vmprep.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/vmprep.c?rev=711920&r1=711919&r2=711920&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/vmprep.c (original)
+++ httpd/mod_wombat/trunk/vmprep.c Thu Nov 6 09:33:46 2008
@@ -218,9 +218,12 @@
return APR_SUCCESS;
}
-static void munge_path(lua_State *L, const char *field,
- const char *sub_pat, const char *rep_pat,
- apr_pool_t *pool, apr_array_header_t *paths,
+static void munge_path(lua_State *L,
+ const char *field,
+ const char *sub_pat,
+ const char *rep_pat,
+ apr_pool_t *pool,
+ apr_array_header_t *paths,
const char *file) {
lua_getglobal(L, "package");
lua_getfield(L, -1, field);
@@ -655,23 +658,36 @@
return lua_pcall(L, 0, LUA_MULTRET, 0);
}
-lua_State* apw_get_lua_state(apr_pool_t* lifecycle_pool, char* file) {
+/* BEGIN NEW STYLE lua_State MANAGEMENT */
+
+lua_State* apw_get_lua_state(apr_pool_t* lifecycle_pool,
+ char* file,
+ apr_array_header_t* package_paths,
+ apr_array_header_t* package_cpaths,
+ apw_lua_state_open_callback cb,
+ void* open_ctx) {
lua_State* L;
if (!apr_pool_userdata_get((void**)&L, file, lifecycle_pool)) {
// not available, so create
L = luaL_newstate();
- luaL_openlibs(L);
- apw_run_wombat_open(L, lifecycle_pool);
+ luaL_openlibs(L);
+ if (package_paths)
+ munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool, package_paths, file);
+ if (package_cpaths)
+ munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool, package_cpaths, file);
+
+ if (cb) {
+ cb(L, lifecycle_pool, open_ctx);
+ }
- // munge_path(L, "path", "?.lua", "./?.lua", pool, spec->package_paths, spec->file);
- // munge_path(L, "cpath", "?.so", "./?.so", pool, spec->package_cpaths, spec->file);
luaL_loadfile(L, file);
lua_pcall(L, 0, LUA_MULTRET, 0);
apr_pool_userdata_set(L, file, &cleanup_lua, lifecycle_pool);
lua_pushlightuserdata(L, lifecycle_pool);
lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
+
}
return L;
}
Modified: httpd/mod_wombat/trunk/vmprep.h
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/vmprep.h?rev=711920&r1=711919&r2=711920&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/vmprep.h (original)
+++ httpd/mod_wombat/trunk/vmprep.h Thu Nov 6 09:33:46 2008
@@ -53,7 +53,7 @@
apr_array_header_t* package_cpaths;
// name of base file to load in the vm
- const char *file;
+ char *file;
// APW_CODE_CACHE_STAT | APW_CODE_CACHE_FOREVER | APW_CODE_CACHE_NEVER
int code_cache_style;
@@ -103,8 +103,26 @@
// returns NULL if the spec requires a request scope or conn scope
lua_State* apw_sgetvm(server_rec *r, apw_vm_spec *spec);
-// alternate means of getting lua_State
-lua_State* apw_get_lua_state(apr_pool_t* lifecycle_pool, char* file);
+typedef void (*apw_lua_state_open_callback) (lua_State* L, apr_pool_t* p, void* ctx);
+
+// alternate means of getting lua_State (preferred eventually)
+// Obtain a lua_State which has loaded file and is associated with lifecycle_pool
+// If one exists, will return extant one, otherwise will create, attach, and return
+// This does no locking around the lua_State, so if the pool is shared between
+// threads, locking is up the client.
+//
+// @lifecycle_pool -> pool whose lifeycle controls the lua_State
+// @file file to be opened, also used as a key for uniquing lua_States
+// @cb callback for vm initialization called *before* the file is opened
+// @ctx a baton passed to cb
+lua_State* apw_get_lua_state(apr_pool_t* lifecycle_pool,
+ char* file,
+ apr_array_header_t* package_paths,
+ apr_array_header_t* package_cpaths,
+ apw_lua_state_open_callback cb,
+ void* open_ctx);
+
+
#endif