Skip to content

Commit

Permalink
Add deallocator attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
btrkeks committed Jun 2, 2024
1 parent 88bcc89 commit 6871fd2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void jdb_close(database *);
void jdb_add_headword_with_file(database *db, s8 headword, s8 filepath);
void jdb_add_file_with_fileinfo(database *db, s8 filepath, fileinfo fi);

s8 *jdb_get_files(database *db, s8 key);
_deallocator_(frees8buffer) s8 *jdb_get_files(database *db, s8 key);
fileinfo jdb_get_fileinfo(database *db, s8 fullpath);

i32 jdb_check_exists(s8 dbpath);
Expand Down
2 changes: 1 addition & 1 deletion include/deinflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Returns: An s8* buffer (see buf.h) containing the deinflections.
* The caller of the function takes ownership of the data, and is responsible for freeing it.
*/
s8 *deinflect(s8 word);
_deallocator_(frees8buffer) s8 *deinflect(s8 word);

/*
* Tries to give a hiragana conversion of @input using MeCab.
Expand Down
10 changes: 8 additions & 2 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ typedef __PTRDIFF_TYPE__ isize;
#define _drop_(x) __attribute__((__cleanup__(drop_##x)))
#define _nonnull_ __attribute__((nonnull))
#define _nonnull_n_(...) __attribute__((nonnull(__VA_ARGS__)))
#if defined(__clang__)
#define _deallocator_(x)
#else
#define _deallocator_(x) __attribute__((malloc(x)))
#endif
#define _printf_(a, b) __attribute__((__format__(printf, a, b)))

#define arrlen(x) \
Expand All @@ -35,8 +40,9 @@ typedef __PTRDIFF_TYPE__ isize;
/**
* Memory allocation wrapper which abort on failure
*/
__attribute__((malloc, returns_nonnull)) void *xcalloc(size_t nmemb, size_t size);
__attribute__((malloc, returns_nonnull)) void *xrealloc(void *ptr, size_t size);
__attribute__((malloc, returns_nonnull))
_deallocator_(free) void *xcalloc(size_t nmemb, size_t size);
__attribute__((malloc, returns_nonnull)) _deallocator_(free) void *xrealloc(void *ptr, size_t size);
// clang-format off
#define new(type, num) xcalloc(num, sizeof(type))
// clang-format on
Expand Down

0 comments on commit 6871fd2

Please sign in to comment.