# HG changeset patch # User Matthias Goergens # Date 1274191678 -3600 # Node ID 5e78332770e196762a4caf4b63d77aff73e29d1a # Parent efffbb0ad177e6752dda9031d81b8258d36b3c5a commit 4dbf952c5841150c6028210fb013128c0b45f7df Author: Matthias Gorgens Date: Mon Mar 8 11:48:25 2010 +0000 camldm/camldm_stubs.c: unnested helper functions Those functions are of use outside of the original context, and nested functions aren't really idiomatic C anyway. Signed-off-by: Matthias Goergens diff --git a/camldm/camldm_stubs.c b/camldm/camldm_stubs.c --- a/camldm/camldm_stubs.c +++ b/camldm/camldm_stubs.c @@ -238,39 +238,45 @@ void camldm_mknod(value path, value mode CAMLreturn0; } -/* - May leak memory. who knows? (Does the c function (_process_all) - where I copied this from (dmsetup.c) care about memory? dmsetup - exits shortly after executing it. After testing: It does not seem - to leak. Probably "dm_task_destroy(dmt);" is doing some cleaning - up. -*/ + +/* Helper functions for camldm_ls */ + #define none Val_int(0) #define Tag_some Val_int(0) + +value some (value content) { + CAMLparam1 (content); + CAMLlocal1 (result); + result = caml_alloc (1, Tag_some); + Store_field (result, 0, content); + CAMLreturn (result); +}; +value cons (value car_value, value cdr_value) { + CAMLparam2 (car_value, cdr_value); + CAMLlocal1 (cell); + + const int car = 0; + const int cdr = 1; + cell = caml_alloc (2, Tag_cons); + Store_field (cell, car, car_value); + Store_field (cell, cdr, cdr_value); + + CAMLreturn (cell); +}; +/* + camldm_ls may leak memory. Who knows? (Does the c function (_process_all) + where I copied this from (dmsetup.c) care about memory? dmsetup + exits shortly after executing it, anyway. + + After testing: It does _not_ seem to leak. Probably + "dm_task_destroy(dmt);" is doing some cleaning up. +*/ value camldm_ls() { CAMLparam0 (); CAMLlocal1 (list); - value some (value content) { - CAMLparam1 (content); - CAMLlocal1 (result); - result = caml_alloc (1, Tag_some); - Store_field (result, 0, content); - CAMLreturn (result); - }; - value cons (value car_value, value cdr_value) { - CAMLparam2 (car_value, cdr_value); - CAMLlocal1 (cell); - const int car = 0; - const int cdr = 1; - cell = caml_alloc (2, Tag_cons); - Store_field (cell, car, car_value); - Store_field (cell, cdr, cdr_value); - - CAMLreturn (cell); - }; struct dm_names *names; struct dm_task *dmt;