Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace *GetXMLDesc with macro

And clean up a few memory leaks along the way.
  • Loading branch information...
commit e7c8e911ed0d7a9fc1ab07b451cb6fdd7ac34dfe 1 parent 7d525e1
@msantos authored
View
27 c_src/vert.h
@@ -311,7 +311,7 @@ vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
VERT_RESOURCE *rp = NULL; \
char buf[VIR_UUID_STRING_BUFLEN] = {0}; \
\
- VERT_GET_RESOURCE(0, rp, VERT_RES_NWFILTER); \
+ VERT_GET_RESOURCE(0, rp, type); \
\
VERTERR(fun(rp->res, buf) < 0); \
\
@@ -320,6 +320,31 @@ vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
enif_make_string(env, buf, ERL_NIF_LATIN1)); \
}
+#define VERT_FUN_GETXMLDESC(fun, type) \
+ ERL_NIF_TERM \
+vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
+{ \
+ VERT_RESOURCE *rp = NULL; \
+ u_int32_t flags = 0; \
+ \
+ char *desc = NULL; \
+ ERL_NIF_TERM term = {0}; \
+ \
+ VERT_GET_RESOURCE(0, rp, type); \
+ VERT_GET_UINT(1, flags); \
+ \
+ desc = fun(rp->res, flags); \
+ \
+ VERTERR(desc == NULL); \
+ \
+ term = enif_make_tuple2(env, atom_ok, \
+ enif_make_string(env, desc, ERL_NIF_LATIN1)); \
+ \
+ free(desc); \
+ \
+ return term; \
+}
+
#define VERT_FUN_UNSUPPORTED(fun) \
ERL_NIF_TERM \
vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
View
26 c_src/vert_domain.c
@@ -45,6 +45,7 @@ VERT_FUN_DEFINEXML(virDomainDefineXML, VERT_RES_DOMAIN, atom_domain)
VERT_FUN_GETNAME(virDomainGetName, VERT_RES_DOMAIN)
VERT_FUN_GETUUID(virDomainGetUUID, VERT_RES_DOMAIN)
VERT_FUN_GETUUIDSTRING(virDomainGetUUIDString, VERT_RES_DOMAIN)
+VERT_FUN_GETXMLDESC(virDomainGetXMLDesc, VERT_RES_DOMAIN)
#if HAVE_VIRDOMAINCREATEWITHFLAGS
ERL_NIF_TERM
@@ -420,31 +421,6 @@ vert_virDomainGetVcpus(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
#endif
ERL_NIF_TERM
-vert_virDomainGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *dp = NULL;
- char *desc = NULL;
- int flags = 0;
-
- ERL_NIF_TERM term = {0};
-
-
- VERT_GET_RESOURCE(0, dp, VERT_RES_DOMAIN);
- VERT_GET_INT(1, flags);
-
- desc = virDomainGetXMLDesc(dp->res, flags);
-
- VERTERR(desc == NULL);
-
- term = enif_make_tuple2(env, atom_ok,
- enif_make_string(env, desc, ERL_NIF_LATIN1));
-
- free(desc);
-
- return term;
-}
-
- ERL_NIF_TERM
vert_virDomainSave(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *dp = NULL;
View
31 c_src/vert_interface.c
@@ -38,6 +38,7 @@ VERT_FUN_INT_RES(virInterfaceUndefine, VERT_RES_INTERFACE)
VERT_FUN_GETNAME(virInterfaceGetMACString, VERT_RES_INTERFACE)
VERT_FUN_GETNAME(virInterfaceGetName, VERT_RES_INTERFACE)
+VERT_FUN_GETXMLDESC(virInterfaceGetXMLDesc, VERT_RES_INTERFACE)
ERL_NIF_TERM
@@ -53,12 +54,6 @@ vert_virInterfaceLookupByMACString(ErlNifEnv *env, int argc, const ERL_NIF_TERM
}
ERL_NIF_TERM
-vert_virInterfaceGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- return vert_interface_ccharp_res_uint(env, argv, virInterfaceGetXMLDesc);
-}
-
- ERL_NIF_TERM
vert_virInterfaceDefineXML(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *vp = NULL;
@@ -136,30 +131,6 @@ vert_interface_res_res_ccharp(
}
ERL_NIF_TERM
-vert_interface_ccharp_res_uint(
- ErlNifEnv *env,
- const ERL_NIF_TERM argv[],
- char *(*fp)(virInterfacePtr, unsigned int))
-{
- VERT_RESOURCE *ifp = NULL;
- int flag;
-
- const char *p = NULL;
-
-
- VERT_GET_RESOURCE(0, ifp, VERT_RES_INTERFACE);
- VERT_GET_INT(1, flag);
-
- p = fp(ifp->res, flag);
-
- VERTERR(p == NULL);
-
- return enif_make_tuple2(env,
- atom_ok,
- enif_make_string(env, p, ERL_NIF_LATIN1));
-}
-
- ERL_NIF_TERM
vert_interface_int_res_uint(
ErlNifEnv *env,
const ERL_NIF_TERM argv[],
View
21 c_src/vert_network.c
@@ -44,6 +44,7 @@ VERT_FUN_DEFINEXML(virNetworkDefineXML, VERT_RES_NETWORK, atom_network)
VERT_FUN_GETNAME(virNetworkGetName, VERT_RES_NETWORK)
VERT_FUN_GETUUID(virNetworkGetUUID, VERT_RES_NETWORK)
VERT_FUN_GETUUIDSTRING(virNetworkGetUUIDString, VERT_RES_NETWORK)
+VERT_FUN_GETXMLDESC(virNetworkGetXMLDesc, VERT_RES_NETWORK)
ERL_NIF_TERM
vert_virNetworkLookupByName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
@@ -117,26 +118,6 @@ vert_virNetworkGetBridgeName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]
term);
}
- ERL_NIF_TERM
-vert_virNetworkGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *np = NULL;
- int flags = 0;
-
- char *desc = NULL;
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NETWORK);
- VERT_GET_INT(1, flags);
-
- desc = virNetworkGetXMLDesc(np->res, flags);
- VERTERR(desc == NULL);
-
- return enif_make_tuple2(env,
- atom_ok,
- enif_make_string(env, desc, ERL_NIF_LATIN1));
-}
-
/*
* Internal functions
*/
View
26 c_src/vert_nwfilter.c
@@ -39,31 +39,7 @@ VERT_FUN_DEFINEXML(virNWFilterDefineXML, VERT_RES_NWFILTER, atom_nwfilter)
VERT_FUN_GETNAME(virNWFilterGetName, VERT_RES_NWFILTER)
VERT_FUN_GETUUID(virNWFilterGetUUID, VERT_RES_NWFILTER)
VERT_FUN_GETUUIDSTRING(virNWFilterGetUUIDString, VERT_RES_NWFILTER)
-
- ERL_NIF_TERM
-vert_virNWFilterGetXMLDesc(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
-{
- VERT_RESOURCE *np = NULL;
- char *desc = NULL;
- u_int32_t flags = 0;
-
- ERL_NIF_TERM term = {0};
-
-
- VERT_GET_RESOURCE(0, np, VERT_RES_NWFILTER);
- VERT_GET_UINT(1, flags);
-
- desc = virNWFilterGetXMLDesc(np->res, flags);
-
- VERTERR(desc == NULL);
-
- term = enif_make_tuple2(env, atom_ok,
- enif_make_string(env, desc, ERL_NIF_LATIN1));
-
- free(desc);
-
- return term;
-}
+VERT_FUN_GETXMLDESC(virNWFilterGetXMLDesc, VERT_RES_NWFILTER)
ERL_NIF_TERM
vert_virNWFilterLookupByName(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
Please sign in to comment.
Something went wrong with that request. Please try again.