Skip to content
Snippets Groups Projects
Commit fb9f798b authored by Simon McVittie's avatar Simon McVittie
Browse files

libc-utils: Factor out autoclear attribute

parent 7673b700
No related branches found
No related tags found
1 merge request!801check-va-api: Use supported surface format + opportunistic cleanup
......@@ -21,13 +21,23 @@ int steal_fd (int *fdp);
void clear_with_free (void *pp);
void clear_with_fclose (void *pp);
/*
* autoclear:
* @clear: A function that can clear a variable of the type with this attribute
*
* A type attribute marking a variable to be cleared with the given
* function when it goes out of scope:
* `autoclear(clear_with_fclose) FILE *fh = fopen (...);`.
*/
#define autoclear(clear) __attribute__((__cleanup__(clear)))
/*
* autofclose:
*
* A type attribute marking a `FILE *` variable to be closed with `fclose()`
* when it goes out of scope: `autofclose FILE *fh = fopen (...);`.
*/
#define autofclose __attribute__((__cleanup__(clear_with_fclose)))
#define autofclose autoclear(clear_with_fclose)
/*
* autofree:
......@@ -35,7 +45,7 @@ void clear_with_fclose (void *pp);
* A type attribute marking a pointer variable to be freed with `free()`
* when it goes out of scope: `autofree char *str = strdup (...);`.
*/
#define autofree __attribute__((__cleanup__(clear_with_free)))
#define autofree autoclear(clear_with_free)
/*
* clear_pointer:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment