search for: my_fn

Displaying 9 results from an estimated 9 matches for "my_fn".

2019 Aug 14
2
Re: [PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
...data; > int (*callback) (unsigned valid_flag, void *user_data, int *error); > } nbd_completion_callback; > > The nbd_aio_pread function can now be called using: > > nbd_aio_pread (nbd, buf, sizeof buf, offset, > (nbd_completion_callback) { .callback = my_fn, > .user_data = my_data }, Is it worth arranging the C struct to match the typical argument ordering of user_data last? It doesn't make any real difference (the struct size doesn't change, and the compiler handles out-of-order member initial...
2019 Aug 14
0
Re: [PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
...(unsigned valid_flag, void *user_data, int *error); > > } nbd_completion_callback; > > > > The nbd_aio_pread function can now be called using: > > > > nbd_aio_pread (nbd, buf, sizeof buf, offset, > > (nbd_completion_callback) { .callback = my_fn, > > .user_data = my_data }, > > Is it worth arranging the C struct to match the typical argument > ordering of user_data last? It doesn't make any real difference (the > struct size doesn't change, and the compiler handles ou...
2019 Aug 14
1
Re: [PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
On 8/14/19 4:21 AM, Richard W.M. Jones wrote: >>> The nbd_aio_pread function can now be called using: >>> >>> nbd_aio_pread (nbd, buf, sizeof buf, offset, >>> (nbd_completion_callback) { .callback = my_fn, >>> .user_data = my_data }, >> >> Is it worth arranging the C struct to match the typical argument >> ordering of user_data last? It doesn't make any real difference (the >> struct size doesn't change, and the c...
2019 Aug 15
0
[PATCH libnbd v2 04/10] lib: Permit .callback = NULL, .free != NULL.
...docs/libnbd.pod | 15 +++++++++++++++ lib/internal.h | 18 +++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/docs/libnbd.pod b/docs/libnbd.pod index f6fd4cd..d230cb4 100644 --- a/docs/libnbd.pod +++ b/docs/libnbd.pod @@ -643,6 +643,21 @@ S<C<chunk.callback = my_fn>> function is called. The free function is only accessible in the C API as it is not needed in garbage collected programming languages. +=head2 Callbacks with C<.callback=NULL> and C<.free!=NULL> + +It is possible to register a callback like this: + + ... + (nbd_completion...
2019 Aug 13
8
[PATCH libnbd 0/4] Add free function to callbacks.
Patches 1 & 2 are rather complex, but the end result is that we pass closures + user_data + free function in single struct parameters as I described previously in this email: https://www.redhat.com/archives/libguestfs/2019-August/msg00210.html Patch 3 adds a convenient FREE_CALLBACK macro which seems a worthwhile simplification if you buy into 1 & 2. Patch 4 adds another macro which is
2019 Aug 14
1
Re: [PATCH libnbd 2/4] api: Add free function and remove valid_flag parameter.
...-=over 4 > +This can be used to free associated C<user_data>. For example: > > -=item C<LIBNBD_CALLBACK_VALID> > + void *my_data = malloc (...); > + > + nbd_aio_pread_structured (nbd, buf, sizeof buf, offset, > + (nbd_chunk_callback) { .callback = my_fn, > + .user_data = my_data, > + .free = free }, > + NBD_NULL_CALLBACK(completion), Needs rebasing based on the tweak to patch 1. > diff --git a/examples/strict-structured-reads.c b/examples/stri...
2019 Aug 13
0
[PATCH libnbd 2/4] api: Add free function and remove valid_flag parameter.
...l not be called again by libnbd. -=over 4 +This can be used to free associated C<user_data>. For example: -=item C<LIBNBD_CALLBACK_VALID> + void *my_data = malloc (...); + + nbd_aio_pread_structured (nbd, buf, sizeof buf, offset, + (nbd_chunk_callback) { .callback = my_fn, + .user_data = my_data, + .free = free }, + NBD_NULL_CALLBACK(completion), + 0); -The callback parameters are valid and this is a normal callback. +will call L<free(3)> on C<my_data...
2019 Aug 13
0
[PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
...typedef struct { void *user_data; int (*callback) (unsigned valid_flag, void *user_data, int *error); } nbd_completion_callback; The nbd_aio_pread function can now be called using: nbd_aio_pread (nbd, buf, sizeof buf, offset, (nbd_completion_callback) { .callback = my_fn, .user_data = my_data }, 0); Note that the whole structure is passed by value not by reference. For OClosure only, a NULL callback can be passed using this macro: nbd_aio_pread (nbd, buf, sizeof buf, offset, NBD_NUL...
2019 Aug 15
13
[PATCH libnbd v2 00/10] Callbacks and OCaml and Python persistent buffers.
This is a combination of these two earlier series: https://www.redhat.com/archives/libguestfs/2019-August/msg00235.html https://www.redhat.com/archives/libguestfs/2019-August/msg00240.html plus changes to allow .callback = NULL / .free != NULL, and to reduce the complexity of freeing callbacks. Although it's rather long there's nothing complex here. We might consider squashing some