# The functions in the libvirt API that we can generate.
my @functions = (
+ { name => "virConnectClose", sig => "conn : free" },
{ name => "virConnectGetHostname", sig => "conn : string", weak => 1 },
{ name => "virConnectGetURI", sig => "conn : string", weak => 1 },
{ name => "virConnectGetType", sig => "conn : static string" },
sig => "conn, int : string array", weak => 1 },
{ name => "virConnectGetCapabilities", sig => "conn : string" },
+ { name => "virDomainFree", sig => "dom : free" },
+ { name => "virDomainDestroy", sig => "dom : free" },
{ name => "virDomainLookupByName", sig => "conn, string : dom" },
{ name => "virDomainLookupByUUIDString", sig => "conn, string : dom" },
{ name => "virDomainGetName", sig => "dom : static string" },
{ name => "virDomainGetAutostart", sig => "dom : bool" },
{ name => "virDomainSetAutostart", sig => "dom, bool : unit" },
+ { name => "virNetworkFree", sig => "net : free" },
+ { name => "virNetworkDestroy", sig => "net : free" },
{ name => "virNetworkLookupByName", sig => "conn, string : net" },
{ name => "virNetworkLookupByUUIDString", sig => "conn, string : net" },
{ name => "virNetworkGetName", sig => "net : static string" },
{ name => "virNetworkGetAutostart", sig => "net : bool" },
{ name => "virNetworkSetAutostart", sig => "net, bool : unit" },
+ { name => "virStoragePoolFree",
+ sig => "pool : free", weak => 1 },
+ { name => "virStoragePoolDestroy",
+ sig => "pool : free", weak => 1 },
{ name => "virStoragePoolLookupByName",
sig => "conn, string : pool", weak => 1 },
{ name => "virStoragePoolLookupByUUIDString",
{ name => "virStoragePoolSetAutostart",
sig => "pool, bool : unit", weak => 1 },
+ { name => "virStorageVolFree", sig => "vol : free" },
+ { name => "virStorageVolDestroy", sig => "vol : free" },
# { name => "virStorageVolLookupByName", XXX see libvir-list posting
# sig => "pool, string : vol", weak => 1 },
{ name => "virStorageVolLookupByKey",
"ocaml_libvirt_network_create_job",
"ocaml_libvirt_network_create_xml_job",
"ocaml_libvirt_storage_pool_get_info",
- "ocaml_libvirt_storage_pool_free", #?
- "ocaml_libvirt_storage_pool_destroy", #?
"ocaml_libvirt_storage_pool_define_xml",
"ocaml_libvirt_storage_pool_create_xml",
"ocaml_libvirt_storage_pool_lookup_by_uuid",
"ocaml_libvirt_storage_vol_lookup_by_name", # XXX
- "ocaml_libvirt_storage_vol_free", #?
- "ocaml_libvirt_storage_vol_destroy", #?
"ocaml_libvirt_storage_vol_create_xml",
"ocaml_libvirt_storage_vol_get_info",
"ocaml_libvirt_pool_of_volume",
} elsif ($sig =~ /^(\w+) : unit$/) {
my $c_type = short_name_to_c_type ($1);
"int $c_name ($c_type $1)"
+ } elsif ($sig =~ /^(\w+) : free$/) {
+ my $c_type = short_name_to_c_type ($1);
+ "int $c_name ($c_type $1)"
} elsif ($sig =~ /^(\w+), string : (\w+)$/) {
my $c_type = short_name_to_c_type ($1);
my $c_ret_type = short_name_to_c_type ($2);
( "$1v" )
} elsif ($sig =~ /^(\w+) : unit$/) {
( "$1v" )
+ } elsif ($sig =~ /^(\w+) : free$/) {
+ ( "$1v" )
} elsif ($sig =~ /^(\w+), string : (\w+)$/) {
( "$1v", "strv" )
} else {
{
local $_ = shift;
- if ($_ eq "dom") {
- "rv = Val_domain (r, connv);"
- } elsif ($_ eq "net") {
- "rv = Val_network (r, connv);"
- } elsif ($_ eq "pool") {
- "rv = Val_pool (r, connv);"
- } elsif ($_ eq "vol") {
- "rv = Val_volume (r, connv);"
+ if ($_ eq "dom") { "rv = Val_domain (r, connv);" }
+ elsif ($_ eq "net") { "rv = Val_network (r, connv);" }
+ elsif ($_ eq "pool") { "rv = Val_pool (r, connv);" }
+ elsif ($_ eq "vol") { "rv = Val_volume (r, connv);" }
+ else {
+ die "unknown short name $_"
+ }
+}
+
+sub gen_free_arg
+{
+ local $_ = shift;
+
+ if ($_ eq "conn") { "Connect_val (connv) = NULL;" }
+ elsif ($_ eq "dom") { "Domain_val (domv) = NULL;" }
+ elsif ($_ eq "net") { "Network_val (netv) = NULL;" }
+ elsif ($_ eq "pool") { "Pool_val (poolv) = NULL;" }
+ elsif ($_ eq "vol") { "Volume_val (volv) = NULL;" }
+ else {
+ die "unknown short name $_"
}
}
free (r);
CAMLreturn (rv);
"
+ } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
+ "\
+ " . gen_unpack_args ($1) . "
+ int r;
+
+ NONBLOCKING (r = $c_name ($1, 0));
+ CHECK_ERROR (r == -1, conn, \"$c_name\");
+
+ CAMLreturn (Val_unit);
+"
} elsif ($sig =~ /^(\w+) : unit$/) {
"\
" . gen_unpack_args ($1) . "
CAMLreturn (Val_unit);
"
- } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
+ } elsif ($sig =~ /^(\w+) : free$/) {
"\
" . gen_unpack_args ($1) . "
int r;
- NONBLOCKING (r = $c_name ($1, 0));
+ NONBLOCKING (r = $c_name ($1));
CHECK_ERROR (r == -1, conn, \"$c_name\");
+ /* So that we don't double-free in the finalizer: */
+ " . gen_free_arg ($1) . "
+
CAMLreturn (Val_unit);
"
} elsif ($sig =~ /^(\w+), string : (\w+)$/) {