From dccaacb3ba8ff3cc2cd6f2c58372aa2bf27bf190 Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Fri, 25 May 2012 11:18:05 -0700 Subject: Test reference counting of custom backends. --- src/odb_backend.nobj.lua | 1 + tests/test_backend.lua | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/odb_backend.nobj.lua b/src/odb_backend.nobj.lua index cd5295b..57b6912 100644 --- a/src/odb_backend.nobj.lua +++ b/src/odb_backend.nobj.lua @@ -40,6 +40,7 @@ static void ODBBackend_ref(ODBBackend *backend) { static void ODBBackend_unref(ODBBackend *backend) { lua_State *L = backend->L; + assert(backend->ref_count > 0); if((--backend->ref_count) == 0) { luaL_unref(L, LUA_REGISTRYINDEX, backend->read); luaL_unref(L, LUA_REGISTRYINDEX, backend->read_prefix); diff --git a/tests/test_backend.lua b/tests/test_backend.lua index ba0633a..bb17ed9 100644 --- a/tests/test_backend.lua +++ b/tests/test_backend.lua @@ -18,6 +18,11 @@ local function dump_obj(obj) end print('id = ', obj:id()) print('type = ', obj:type()) + local data = obj:data() + print('data = ', data) + if data then + print('hash = ', git2.ODB.hash(data,git2.Object.string2type(obj:type()))) + end end -- create odb @@ -93,6 +98,8 @@ end, local backend = git2.ODBBackend(cbs) print('add backend:', assert(db:add_backend(backend, 0))) +backend = nil +collectgarbage"collect" print("test writing test blob to odb:") local oid, err = db:write("any ol content will do", 'blob') @@ -127,6 +134,8 @@ db = rep:odb() print("=============================================== repo db=", db) backend = git2.ODBBackend(cbs) print("add backend repository's odb:", assert(db:add_backend(backend, 0))) +backend = nil +collectgarbage"collect" print() print("try reading objects from repository:") @@ -138,7 +147,8 @@ local object_ids = { } for _,obj in ipairs(object_ids) do local oid = git2.OID.hex(obj[2]) - local obj, err = rep:lookup(oid, obj[1]) + --local obj, err = rep:lookup(oid, obj[1]) + local obj, err = db:read(oid) print('read', obj, err) print() end -- cgit v1.2.1