fix crash on macos for dev

This commit is contained in:
2026-08-28 23:31:23 +02:00
parent ecc792bcb6
commit ee3aa1e488
13 changed files with 1768 additions and 10495 deletions
+30 -49
View File
@@ -12,78 +12,59 @@
typedef void (*cast_done_typed)(struct discord *,
struct discord_response *,
const void *);
typedef void (*cast_init)(void *);
typedef void (*cast_cleanup)(void *);
typedef size_t (*cast_from_json)(const char *, size_t, void *);
typedef struct reflectc_wrap *(*cast_init)(struct reflectc *,
void *,
struct reflectc_wrap *);
/* helper typedef for getting sizeof of `struct discord_ret` common fields */
typedef struct {
DISCORD_RET_DEFAULT_FIELDS;
} discord_ret_default_fields;
#define _RET_COPY_TYPED(dest, src) \
#define _RET_COPY_TYPED(_dest, _src) \
do { \
memcpy(&(dest), &(src), sizeof(discord_ret_default_fields)); \
(dest).has_type = true; \
(dest).done.typed = (cast_done_typed)(src).done; \
(dest).sync = (src).sync; \
memcpy(&(_dest), &(_src), sizeof(discord_ret_default_fields)); \
(_dest).has_type = true; \
(_dest).done.typed = (cast_done_typed)(_src).done; \
(_dest).sync = (_src).sync; \
} while (0)
#define _RET_COPY_TYPELESS(dest, src) \
#define _RET_COPY_TYPELESS(_dest, _src) \
do { \
memcpy(&(dest), &(src), sizeof(discord_ret_default_fields)); \
(dest).has_type = false; \
(dest).done.typeless = (src).done; \
(dest).sync = (void *)(src).sync; \
memcpy(&(_dest), &(_src), sizeof(discord_ret_default_fields)); \
(_dest).has_type = false; \
(_dest).done.typeless = (_src).done; \
(_dest).sync = (void *)(_src).sync; \
} while (0)
/**
* @brief Helper for setting attributes for a specs-generated return struct
*
* @param[out] attr @ref discord_attributes handler to be initialized
* @param[in] type datatype of the struct
* @param[in] ret dispatch attributes
* @param[out] _attr @ref discord_attributes handler to be initialized
* @param[in] _type datatype of the struct
* @param[in] _ret dispatch attributes
* @param[in] _reason reason for request (if available)
*/
#define DISCORD_ATTR_INIT(attr, type, ret, _reason) \
#define DISCORD_ATTR_INIT(_attr, _type, _ret, _reason) \
do { \
(attr).response.size = sizeof(struct type); \
(attr).response.init = (cast_init)type##_init; \
(attr).response.from_json = (cast_from_json)type##_from_json; \
(attr).response.cleanup = (cast_cleanup)type##_cleanup; \
(attr).reason = _reason; \
if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
(_attr).response.size = sizeof(struct _type); \
(_attr).response.init = (cast_init)reflectc_from_##_type; \
(_attr).reason = _reason; \
if (_ret) _RET_COPY_TYPED((_attr).dispatch, *(_ret)); \
} while (0)
/**
* @brief Helper for setting attributes for a specs-generated list
*
* @param[out] attr @ref discord_attributes handler to be initialized
* @param[in] type datatype of the list
* @param[in] ret dispatch attributes
* @param[in] _reason reason for request (if available)
*/
#define DISCORD_ATTR_LIST_INIT(attr, type, ret, _reason) \
do { \
(attr).response.size = sizeof(struct type); \
(attr).response.from_json = (cast_from_json)type##_from_json; \
(attr).response.cleanup = (cast_cleanup)type##_cleanup; \
(attr).reason = _reason; \
if (ret) _RET_COPY_TYPED(attr.dispatch, *ret); \
} while (0)
/**
* @brief Helper for setting attributes for attruests that doensn't expect a
* @brief Helper for setting attributes for attributes that don't have a
* response object
*
* @param[out] attr @ref discord_attributes handler to be initialized
* @param[in] ret dispatch attributes
* @param[out] _attr @ref discord_attributes handler to be initialized
* @param[in] _ret dispatch attributes
* @param[in] _reason reason for request (if available)
*/
#define DISCORD_ATTR_BLANK_INIT(attr, ret, _reason) \
#define DISCORD_ATTR_BLANK_INIT(_attr, _ret, _reason) \
do { \
(attr).reason = _reason; \
if (ret) _RET_COPY_TYPELESS(attr.dispatch, *ret); \
(_attr).reason = _reason; \
if (_ret) _RET_COPY_TYPELESS((_attr).dispatch, *(_ret)); \
} while (0)
/**
@@ -91,10 +72,10 @@ typedef struct {
*
* @param[in,out] attchs a @ref discord_attachments to have its IDs initialized
*/
#define DISCORD_ATTACHMENTS_IDS_INIT(attchs) \
#define DISCORD_ATTACHMENTS_IDS_INIT(_attchs) \
do { \
for (int i = 0; i < attchs->size; ++i) { \
attchs->array[i].id = (u64snowflake)i; \
for (int i = 0; i < (_attchs)->size; ++i) { \
(_attchs)->array[i].id = (u64snowflake)i; \
} \
} while (0)