Keep references purely in erlang

Refernces contain three pieces of data which we already keep in the
erlang record. Keep the repository it belongs to in the record as well
and remove resource in the NIF. This makes the code easier to reason
about, as we don't need to keep any reference counts or GC the C
struct.

This does mean we cannot re-use references across geef_repo restarts,
but that's probably a good thing.
This commit is contained in:
Carlos Martín Nieto
2013-08-31 17:23:46 +02:00
parent da7a070522
commit 70867b9615
6 changed files with 185 additions and 199 deletions

View File

@@ -18,7 +18,6 @@
ErlNifResourceType *geef_repository_type;
ErlNifResourceType *geef_odb_type;
ErlNifResourceType *geef_ref_type;
ErlNifResourceType *geef_ref_iter_type;
ErlNifResourceType *geef_object_type;
ErlNifResourceType *geef_revwalk_type;
@@ -42,12 +41,6 @@ static int load(ErlNifEnv *env, void **priv, ERL_NIF_TERM load_info)
if (geef_odb_type == NULL)
return -1;
geef_ref_type = enif_open_resource_type(env, NULL,
"ref_type", geef_ref_free, ERL_NIF_RT_CREATE, NULL);
if (geef_ref_type == NULL)
return -1;
geef_ref_iter_type = enif_open_resource_type(env, NULL,
"ref_iter_type", geef_ref_iter_free, ERL_NIF_RT_CREATE, NULL);
@@ -160,10 +153,7 @@ static ErlNifFunc geef_funcs[] =
{"reference_lookup", 2, geef_reference_lookup},
{"reference_iterator", 2, geef_reference_iterator},
{"reference_next", 1, geef_reference_next},
{"reference_resolve", 1, geef_reference_resolve},
{"reference_target", 1, geef_reference_target},
{"reference_type", 1, geef_reference_type},
{"reference_name", 1, geef_reference_name},
{"reference_resolve", 2, geef_reference_resolve},
{"reference_create", 5, geef_reference_create},
{"reference_dwim", 2, geef_reference_dwim},
{"oid_fmt", 1, geef_oid_fmt},