Skip to content
Snippets Groups Projects
Commit 8d3c0dee authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

Merge !80: lua cache.count(): return nil on error

... and avoid returning a negative number.
parents 1d13f9af 345c5fa6
Branches
Tags
1 merge request!80lua cache.count(): return nil on error
......@@ -768,7 +768,7 @@ daemons or manipulated from other processes, making for example synchronised loa
.. function:: cache.count()
:return: Number of entries in the cache.
:return: Number of entries in the cache or nil on error.
.. function:: cache.close()
......
......@@ -430,10 +430,11 @@ static int cache_count(lua_State *L)
struct engine *engine = engine_luaget(L);
const struct kr_cdb_api *api = engine->resolver.cache.api;
/* First key is a version counter, omit it. */
struct kr_cache *cache = &engine->resolver.cache;
if (kr_cache_is_open(cache)) {
lua_pushinteger(L, api->count(cache->db) - 1);
int count = api->count(cache->db);
if (kr_cache_is_open(cache) && count >= 0) {
/* First key is a version counter, omit it if nonempty. */
lua_pushinteger(L, count ? count - 1 : 0);
return 1;
}
return 0;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment