Fix. Remove values from storage on unset.

Fix. Set callback with context.
This commit is contained in:
Alexey Melnichuk 2014-09-03 11:16:10 +05:00
parent b53a4008ba
commit db7e541e09
3 changed files with 57 additions and 2 deletions

View File

@ -53,11 +53,23 @@ void lcurl_storage_remove_i(lua_State *L, int storage, int i){
lua_rawgeti(L, -1, LCURL_STORAGE_KV);
if(lua_istable(L, -1)){
lua_pushnil(L);
lua_rawseti(L, -3, i);
lua_rawseti(L, -2, i);
}
lua_pop(L, 2);
}
void lcurl_storage_get_i(lua_State *L, int storage, int i){
lua_rawgeti(L, LCURL_LUA_REGISTRY, storage);
lua_rawgeti(L, -1, LCURL_STORAGE_KV);
if(lua_istable(L, -1)){
lua_rawgeti(L, -2, i);
lua_remove(L, -2);
lua_remove(L, -2);
}
else
lua_pop(L, 2);
}
struct curl_slist* lcurl_storage_remove_slist(lua_State *L, int storage, int idx){
struct curl_slist* list;
assert(idx != LUA_NOREF);
@ -141,7 +153,7 @@ int lcurl_set_callback(lua_State *L, lcurl_callback_t *c, int i, const char *met
i = lua_absindex(L, i);
luaL_argcheck(L, !lua_isnoneornil(L, i), i, "no function present");
luaL_argcheck(L, (top < (i + 1)), i + 2, "no arguments expected");
luaL_argcheck(L, (top < (i + 2)), i + 2, "no arguments expected");
// if(top > (i + 1)) lua_settop(L, i + 1); // this for force ignore other arguments

View File

@ -33,6 +33,8 @@ void lcurl_storage_preserve_iv(lua_State *L, int storage, int i, int v);
void lcurl_storage_remove_i(lua_State *L, int storage, int i);
void lcurl_storage_get_i(lua_State *L, int storage, int i);
int lcurl_storage_free(lua_State *L, int storage);
struct curl_slist* lcurl_util_array_to_slist(lua_State *L, int t);

View File

@ -52,6 +52,14 @@ function test_write_to_file_abort()
end
function test_reset_write_callback()
f = assert(io.open(fname, "w+b"))
c = assert(curl.easy{url = url})
assert_equal(c, c:setopt_writefunction(f))
assert_equal(c, c:setopt_writefunction(f.write, f))
assert_equal(c, c:setopt_writefunction(print))
end
end
local _ENV = TEST_CASE'escape' do
@ -99,8 +107,41 @@ function test()
assert(not pfrom.value)
end
function test_unset()
local pfrom, e
do
local form = curl.form()
e = curl.easy{httppost = form}
pfrom = weak_ptr(form)
end
gc_collect()
assert(pfrom.value)
e:unsetopt_httppost()
gc_collect()
assert(not pfrom.value)
end
function test_reset()
local pfrom, e
do
local form = curl.form()
e = curl.easy{httppost = form}
pfrom = weak_ptr(form)
end
gc_collect()
assert(pfrom.value)
e:reset()
gc_collect()
assert(not pfrom.value)
end
end
if not HAS_RUNNER then lunit.run() end