Merge pull request #164 from moteus/reset_slist_option

Fix. Cleanup slists references in the reset function
This commit is contained in:
Alexey Melnichuk 2021-01-06 23:00:01 +03:00 committed by GitHub
commit cb7a59ca76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 13 deletions

View File

@ -36,7 +36,7 @@ install:
) )
- if not exist c:\hererocks ( - if not exist c:\hererocks (
pip install hererocks && pip install hererocks &&
hererocks c:\hererocks --%LUA% --target %HR_TARGET% -rlatest hererocks c:\hererocks --%LUA% --target %HR_TARGET% -r2.4.4
) )
- call c:\hererocks\bin\activate - call c:\hererocks\bin\activate
- luarocks show luarocks-fetch-gitrec >nul 2>&1 || luarocks install luarocks-fetch-gitrec - luarocks show luarocks-fetch-gitrec >nul 2>&1 || luarocks install luarocks-fetch-gitrec

View File

@ -292,6 +292,10 @@ static int lcurl_easy_reset(lua_State *L){
lua_settop(L, 1); lua_settop(L, 1);
if(p->storage != LUA_NOREF){ if(p->storage != LUA_NOREF){
int i;
for (i = 0; i < LCURL_LIST_COUNT; ++i) {
p->lists[i] = LUA_NOREF;
}
lcurl_storage_free(L, p->storage); lcurl_storage_free(L, p->storage);
p->storage = lcurl_storage_init(L); p->storage = lcurl_storage_init(L);
lua_settop(L, 1); lua_settop(L, 1);

View File

@ -25,6 +25,18 @@
# define LCURL_EXPORT_API LUALIB_API # define LCURL_EXPORT_API LUALIB_API
#endif #endif
static const char* LCURL_REGISTRY = "LCURL Registry";
static const char* LCURL_USERVAL = "LCURL Uservalues";
#if LCURL_CURL_VER_GE(7,56,0)
static const char* LCURL_MIME_EASY_MAP = "LCURL Mime easy";
#endif
#if LCURL_CURL_VER_GE(7,56,0)
#define NUP 3
#else
#define NUP 2
#endif
static int lcurl_easy_new_safe(lua_State *L){ static int lcurl_easy_new_safe(lua_State *L){
return lcurl_easy_create(L, LCURL_ERROR_RETURN); return lcurl_easy_create(L, LCURL_ERROR_RETURN);
} }
@ -78,6 +90,11 @@ static int lcurl_version(lua_State *L){
return 1; return 1;
} }
static int lcurl_debug_getregistry(lua_State *L) {
lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);
return 1;
}
static int push_upper(lua_State *L, const char *str){ static int push_upper(lua_State *L, const char *str){
char buffer[128]; char buffer[128];
size_t i, n = strlen(str); size_t i, n = strlen(str);
@ -193,6 +210,8 @@ static const struct luaL_Reg lcurl_functions[] = {
{"version", lcurl_version }, {"version", lcurl_version },
{"version_info", lcurl_version_info }, {"version_info", lcurl_version_info },
{"__getregistry", lcurl_debug_getregistry},
{NULL,NULL} {NULL,NULL}
}; };
@ -208,6 +227,8 @@ static const struct luaL_Reg lcurl_functions_safe[] = {
{"version", lcurl_version }, {"version", lcurl_version },
{"version_info", lcurl_version_info }, {"version_info", lcurl_version_info },
{ "__getregistry", lcurl_debug_getregistry },
{NULL,NULL} {NULL,NULL}
}; };
@ -222,17 +243,6 @@ static const lcurl_const_t lcurl_flags[] = {
static volatile int LCURL_INIT = 0; static volatile int LCURL_INIT = 0;
static const char* LCURL_REGISTRY = "LCURL Registry";
static const char* LCURL_USERVAL = "LCURL Uservalues";
#if LCURL_CURL_VER_GE(7,56,0)
static const char* LCURL_MIME_EASY_MAP = "LCURL Mime easy";
#endif
#if LCURL_CURL_VER_GE(7,56,0)
#define NUP 3
#else
#define NUP 2
#endif
#if LCURL_CURL_VER_GE(7,56,0) #if LCURL_CURL_VER_GE(7,56,0)
#define LCURL_PUSH_NUP(L) lua_pushvalue(L, -NUP-1);lua_pushvalue(L, -NUP-1);lua_pushvalue(L, -NUP-1); #define LCURL_PUSH_NUP(L) lua_pushvalue(L, -NUP-1);lua_pushvalue(L, -NUP-1);lua_pushvalue(L, -NUP-1);

View File

@ -1103,6 +1103,23 @@ function test_set_empty_array()
assert_not_match("X%-Custom:%s*value\r\n", headers) assert_not_match("X%-Custom:%s*value\r\n", headers)
end end
function test_reset_slist()
c = curl.easy {
httpheader = {'X-Foo: 1'},
resolve = {'example.com:80:127.0.0.1'}
}
c:reset()
c:setopt{
httpheader = {'X-Foo: 2'},
resolve = {'example.com:80:127.0.0.1'}
}
local body, headers = assert_string(dump_request(c))
assert_match("X%-Foo:%s2\r\n", headers)
end
end end
local _ENV = TEST_CASE'set_null' if ENABLE then local _ENV = TEST_CASE'set_null' if ENABLE then