Skip to content

Commit

Permalink
Merge pull request #249 from Gottox/improve/cx-constructor-macros
Browse files Browse the repository at this point in the history
common: use CX_*_IMPL macros instead of defining our own.
  • Loading branch information
Gottox committed Jun 2, 2024
2 parents 7146b96 + e1e9fd1 commit 45d4c84
Showing 1 changed file with 4 additions and 24 deletions.
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

0 comments on commit 45d4c84

Please sign in to comment.