Permalink
Browse files

Enforce consistent use of tagged tuples

Ensure all return values are tagged {ok, ...}. Whether the tag should
be the atom 'ok' or another value (e.g., {max, Max}, {ulong, Ulong},
etc) is an open question (should we then tag {ok, {int, Int}}?)
  • Loading branch information...
1 parent 1c6ebd0 commit 0084a5a0543d2a3e31e3b523c594c93cc59dce06 @msantos committed Jul 25, 2011
Showing with 24 additions and 15 deletions.
  1. +2 −2 README.md
  2. +13 −4 c_src/vert_domain.c
  3. +1 −5 c_src/vert_interface.c
  4. +6 −2 c_src/vert_network.c
  5. +2 −2 src/vert.erl
View
@@ -120,8 +120,8 @@ running domains. The example is taken from:
ok = vert:virDomainDestroy(Domain).
info(Domain) ->
- Name = vert:virDomainGetName(Domain),
- Info = vert:virDomainGetInfo(Domain),
+ {ok, Name} = vert:virDomainGetName(Domain),
+ {ok, Info} = vert:virDomainGetInfo(Domain),
[{name, Name}, {info, Info}].
View
@@ -152,7 +152,9 @@ vert_virDomainGetID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
VERTERR(id == (unsigned int)-1);
- return enif_make_uint(env, id);
+ return enif_make_tuple2(env,
+ atom_ok,
+ enif_make_uint(env, id));
}
ERL_NIF_TERM
@@ -220,7 +222,10 @@ vert_virDomainGetMaxMemory(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
mem = virDomainGetMaxMemory(dp->res); // XXX can also be NULL for domain0
VERTERR(mem == 0);
- return enif_make_ulong(env, mem);
+
+ return enif_make_tuple2(env,
+ atom_ok,
+ enif_make_ulong(env, mem));
}
ERL_NIF_TERM
@@ -271,7 +276,9 @@ vert_virDomainGetName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
name = virDomainGetName(dp->res);
VERTERR(name == NULL);
- return enif_make_string(env, name, ERL_NIF_LATIN1);
+ return enif_make_tuple2(env,
+ atom_ok,
+ enif_make_string(env, name, ERL_NIF_LATIN1));
}
ERL_NIF_TERM
@@ -291,7 +298,9 @@ vert_virDomainGetOSType(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
term = enif_make_string(env, name, ERL_NIF_LATIN1);
free(name);
- return term;
+ return enif_make_tuple2(env,
+ atom_ok,
+ term);
}
ERL_NIF_TERM
View
@@ -155,19 +155,15 @@ vert_interface_ccharp_res(
VERT_RESOURCE *vp = NULL;
const char *p = NULL;
- ERL_NIF_TERM term = {0};
-
VERT_GET_RESOURCE(0, vp, VERT_RES_INTERFACE);
p = fp(vp->res);
VERTERR(p == NULL);
- term = enif_make_tuple2(env, atom_ok,
+ return enif_make_tuple2(env, atom_ok,
enif_make_string(env, p, ERL_NIF_LATIN1));
-
- return term;
}
ERL_NIF_TERM
View
@@ -93,7 +93,9 @@ vert_virNetworkGetUUID(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
BINCOPY(term, uuid, sizeof(uuid));
- return term;
+ return enif_make_tuple2(env,
+ atom_ok,
+ term);
}
ERL_NIF_TERM
@@ -111,7 +113,9 @@ vert_virNetworkGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
desc = virNetworkGetXMLDesc(np->res, flags);
VERTERR(desc == NULL);
- return enif_make_string(env, desc, ERL_NIF_LATIN1);
+ return enif_make_tuple2(env,
+ atom_ok,
+ enif_make_string(env, desc, ERL_NIF_LATIN1));
}
ERL_NIF_TERM
View
@@ -515,13 +515,13 @@ virDomainGetInfo(#resource{type = domain, res = Res}) ->
NrVirtCpu:2/native-unsigned-integer-unit:8, % _Pad1:16,
CpuTime:8/native-unsigned-integer-unit:8
>>} ->
- #domain_info{
+ {ok, #domain_info{
state = state({domain, State}),
maxmem = MaxMem,
memory = Memory,
nrvirtcpu = NrVirtCpu,
cputime = CpuTime
- };
+ }};
Err ->
Err
end.

0 comments on commit 0084a5a

Please sign in to comment.