Skip to content

Commit

Permalink
Be a bit more type-safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadd committed Oct 12, 2024
1 parent 33e988a commit be10313
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
12 changes: 8 additions & 4 deletions scary.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ void scary_push_ref(void *p, const void *elem)
}

#define DEF_PUSH_VARIANT2(type, suffix) \
void scary_push_##suffix(void *p, type elem) \
void scary_push_##suffix(type **p, const type elem) \
{ \
type tmp = elem; \
scary_push_ref(p, &tmp); \
scary_push_ref(p, &elem); \
}
#define DEF_PUSH_VARIANT(type) DEF_PUSH_VARIANT2(type##_t, type)
#define DEF_PUSH_VARIANT1(type) DEF_PUSH_VARIANT2(type, type)

DEF_PUSH_VARIANT(int8)
DEF_PUSH_VARIANT(int16)
Expand All @@ -106,7 +106,11 @@ DEF_PUSH_VARIANT(uint8)
DEF_PUSH_VARIANT(uint16)
DEF_PUSH_VARIANT(uint32)
DEF_PUSH_VARIANT(uint64)
DEF_PUSH_VARIANT2(const void *, ptr)
DEF_PUSH_VARIANT1(char)
void scary_push_ptr(void *p, const void *elem)
{
scary_push_ref(p, &elem);
}

void scary_pop(void *p)
{
Expand Down
21 changes: 11 additions & 10 deletions scary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
void *scary_new(size_t size);
void scary_free(void *ary);
size_t scary_length(const void *ary);
void scary_push_ref(void *pary, const void *elem);
void scary_push_ref(void *ary, const void *elem);
#ifdef __APPLE__
#define scary_push_archdep_pattern() unsigned long: scary_push_uint64,
#else
Expand All @@ -20,7 +20,7 @@ void scary_push_ref(void *pary, const void *elem);
int16_t: scary_push_int16, \
int32_t: scary_push_int32, \
int64_t: scary_push_int64, \
char: scary_push_uint8, \
char: scary_push_char, \
uint8_t: scary_push_uint8, \
uint16_t: scary_push_uint16, \
uint32_t: scary_push_uint32, \
Expand All @@ -37,14 +37,15 @@ void scary_push_ref(void *pary, const void *elem);
uint32_t *: scary_push_ptr, \
uint64_t *: scary_push_ptr, \
void *: scary_push_ptr)(pary, elem)
void scary_push_int8(void *, int8_t);
void scary_push_int16(void *, int16_t);
void scary_push_int32(void *, int32_t);
void scary_push_int64(void *, int64_t);
void scary_push_uint8(void *, uint8_t);
void scary_push_uint16(void *, uint16_t);
void scary_push_uint32(void *, uint32_t);
void scary_push_uint64(void *, uint64_t);
void scary_push_char(char **, char);
void scary_push_int8(int8_t **, int8_t);
void scary_push_int16(int16_t **, int16_t);
void scary_push_int32(int32_t **, int32_t);
void scary_push_int64(int64_t **, int64_t);
void scary_push_uint8(uint8_t **, uint8_t);
void scary_push_uint16(uint16_t **, uint16_t);
void scary_push_uint32(uint32_t **, uint32_t);
void scary_push_uint64(uint64_t **, uint64_t);
void scary_push_ptr(void *, const void *);
void scary_pop(void *ary);
void *scary_dup(void *ary);
Expand Down

0 comments on commit be10313

Please sign in to comment.