xolox/lua-apr — Issue #12: support mod_dbd in apache2(zhaozg fork)
Author: zhaozg
Created: 2011-12-15 15:40:18+00:00
State: open

I use lua-apr in mod_luaex(which extend mod_lua) , below patch enabled apr-dbd to access mod_dbd api. please notice.

@@ -85,6 +85,7 @@
85	85
const apr_dbd_driver_t *driver;
86	86
apr_dbd_t *handle;
87	87
apr_dbd_transaction_t *trans;
88
+ int managed;
88	89
} lua_apr_dbd_object;
89	90

90	91
/* XXX The result set object's memory pool must be the same memory pool used
...	...
@@ -455,7 +456,7 @@ int lua_apr_dbd(lua_State *L)
455	456
status = apr_dbd_get_driver(driver->pool, name, &driver->driver);
456	457
if (status != APR_SUCCESS)
457	458
return push_error_status(L, status);
458
-
459
+ driver->managed = 1;
459	460
return 1;
460	461
}
461	462

...	...
@@ -1078,9 +1079,12 @@ static int dbd_close(lua_State *L)
1078	1079
apr_status_t status;
1079	1080

1080	1081
object = check_dbd(L, 1, 1, 0);
1081
- status = dbd_close_impl(object);
1082
+ if(object->managed){
1083
+ status = dbd_close_impl(object);
1082	1084

1083
- return push_status(L, status);
1085
+ return push_status(L, status);
1086
+ }
1087
+ return 0;
1084	1088
}
1085	1089

1086	1090
/* tostring(driver) -> string {{{1 */
...	...
@@ -1103,9 +1107,11 @@ static int dbd_tostring(lua_State *L)
1103	1107
static int dbd_gc(lua_State *L)
1104	1108
{
1105	1109
lua_apr_dbd_object *driver = check_dbd(L, 1, 0, 0);
1106
- if (object_collectable((lua_apr_refobj*)driver))
1107
- dbd_close_impl(driver);
1108
- release_object((lua_apr_refobj*)driver);
1110
+ if(driver->managed) {
1111
+ if (object_collectable((lua_apr_refobj*)driver))
1112
+ dbd_close_impl(driver);
1113
+ release_object((lua_apr_refobj*)driver);
1114
+ }
1109	1115
return 0;
1110	1116
}
1111	1117

...	...
@@ -1226,6 +1232,7 @@ LUA_APR_EXPORT int lua_apr_dbd_register(lua_State *L, ap_dbd_t* a_dbd)
1226	1232
driver->driver = a_dbd->driver;
1227	1233
/* FIXME should not release a connection */
1228	1234
driver->handle = a_dbd->handle;
1235
+ driver->managed = 0;
1229	1236

1230	1237
return 1;
1231	1238
}