Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: use CX_*_IMPL macros instead of defining our own. #249

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions common/include/sqsh_common_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <sqsh_common.h>

#include <cextras/memory.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -66,30 +67,9 @@ extern "C" {
#define SQSH_CONFIG_DEFAULT(x, d) (size_t)(x == 0 ? (d) : SQSH_MAX(x, 0))

#define SQSH_NEW_IMPL(init, type, ...) \
int rv = 0; \
type *obj = calloc(1, sizeof(type)); \
if (obj == NULL) { \
rv = -SQSH_ERROR_MALLOC_FAILED; \
goto out; \
} \
rv = init(obj, __VA_ARGS__); \
if (rv < 0) { \
free(obj); \
obj = NULL; \
} \
out: \
if (err != NULL) { \
*err = rv; \
} \
return obj

#define SQSH_FREE_IMPL(cleanup, obj) \
if (obj == NULL) { \
return 0; \
} \
int rv = cleanup(obj); \
free(obj); \
return rv
CX_NEW_IMPL(init, type, -SQSH_ERROR_MALLOC_FAILED, __VA_ARGS__)

#define SQSH_FREE_IMPL(cleanup, obj) CX_FREE_IMPL(cleanup, obj)

SQSH_NO_UNUSED static inline uint64_t
sqsh_address_ref_outer_offset(uint64_t ref) {
Expand Down
Loading