diff options
author | default <nobody@localhost> | 2024-03-09 07:18:51 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2024-03-09 07:18:51 +0100 |
commit | e12af777993ca655f285e852ad0dbee6bdca014f (patch) | |
tree | bedce5c0ed79d2ba05c3a46a825954ba05327b16 | |
parent | 093f4af2827dab26785e788dc0d49d54308239b5 (diff) |
Backport from xs.
-rw-r--r-- | xs.h | 20 | ||||
-rw-r--r-- | xs_version.h | 2 |
2 files changed, 12 insertions, 10 deletions
@@ -154,8 +154,15 @@ xs_val xs_stock_true[] = { XSTYPE_TRUE }; xs_val xs_stock_false[] = { XSTYPE_FALSE }; xs_val xs_stock_0[] = { XSTYPE_NUMBER, '0', '\0' }; xs_val xs_stock_1[] = { XSTYPE_NUMBER, '1', '\0' }; + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ xs_val xs_stock_list[] = { XSTYPE_LIST, 0, 0, 0, 1 + _XS_TYPE_SIZE + 1, XSTYPE_EOM }; xs_val xs_stock_dict[] = { XSTYPE_DICT, 0, 0, 0, 1 + _XS_TYPE_SIZE + 1, XSTYPE_EOM }; +#else +xs_val xs_stock_list[] = { XSTYPE_LIST, 1 + _XS_TYPE_SIZE + 1, 0, 0, 0, XSTYPE_EOM }; +xs_val xs_stock_dict[] = { XSTYPE_DICT, 1 + _XS_TYPE_SIZE + 1, 0, 0, 0, XSTYPE_EOM }; +#endif + void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func) { @@ -274,21 +281,16 @@ xstype xs_type(const xs_val *data) void _xs_put_size(xs_val *ptr, int i) /* must match _XS_TYPE_SIZE */ { - unsigned char *p = (unsigned char *)ptr; - - p[0] = (i >> 24) & 0x7f; - p[1] = (i >> 16) & 0xff; - p[2] = (i >> 8) & 0xff; - p[3] = i & 0xff; + memcpy(ptr, &i, sizeof(i)); } int _xs_get_size(const xs_val *ptr) /* must match _XS_TYPE_SIZE */ { - unsigned char *p = (unsigned char *)ptr; - - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + int i; + memcpy(&i, ptr, sizeof(i)); + return i; } diff --git a/xs_version.h b/xs_version.h index c49d866..3e76a99 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* 98305e8badd7ed505bb6e667c202bad63e4e79ef 2024-02-20T05:16:49+01:00 */ +/* 73ff6e75bec88fa0b908b039462180a8ac1401de 2024-03-08T07:17:30+01:00 */ |