58#if defined(__GNUC__) || defined(__clang__)
59# define MIZU_EXT_INLINE static inline __attribute__((unused))
61# define MIZU_EXT_INLINE static inline
67# define MIZU_EXT_LOAD_ACQ(p) \
68 std::atomic_load_explicit((p), std::memory_order_acquire)
70# define MIZU_EXT_LOAD_ACQ(p) \
71 atomic_load_explicit((p), memory_order_acquire)
77# define MIZU_PREFIX_LITERAL "Local\\mizu_"
79# define MIZU_PREFIX_LITERAL "/mizu_"
82#define MIZU_ALIGN64(x) (((x) + 63) & ~(size_t) 63)
89#define MIZU_ZC_FLOOR ((size_t) 32768)
90#define MIZU_ZC_FLOOR_RAW ((size_t) (256 << 10))
94#define MIZU_OPEN_CACHE_MAX 16
102#define MIZU_CODEC_MAGIC 0x52u
103#define MIZU_PYMIZU_CODEC_MAGIC 0x50u
104#define MIZU_INTEROP_MAGIC 0x49u
117#define MIZU_LANG_NONE 0u
118#define MIZU_LANG_BYTES 1u
119#define MIZU_LANG_R 2u
120#define MIZU_LANG_PYTHON 3u
131#define MIZU_CAP_MIZS (1u << 0)
132#define MIZU_CAP_ATTRS (1u << 1)
134#define MIZU_CAP_MIZL (1u << 2)
135#define MIZU_CAP_TASKREF (1u << 3)
138#define MIZU_CAP_MIZL_REF (1u << 4)
140#define MIZU_CAP_MIZL_TSN (1u << 5)
142#define MIZU_CAP_MIZL_U64V (1u << 6)
149#define MIZU_IDENT(lang, caps) \
150 ((uint64_t) (uint8_t) (lang) | ((uint64_t) (uint32_t) (caps) << 32))
164enum { MIZU_HTYPE_CHANNEL = 1, MIZU_HTYPE_POOL = 2 };
183 uint32_t *fl_entries,
184 uint32_t *ledger_entries);
282#define MIZU_READ_CONSUME 1u
298typedef void *(*mizu_read_fn)(
const mizu_slot_hdr *,
const uint8_t *payload,
301typedef int (*mizu_exec_fn)(
const mizu_slot_hdr *hdr,
const uint8_t *payload,
304typedef int (*mizu_check_fn)(
void *ctx);
305typedef void (*mizu_park_fn)(
void *ctx,
int entering);
306typedef void (*mizu_sweep_fn)(
void *ctx);
307typedef void (*mizu_drop_fn)(
void *ctx,
void *pin);
336MIZU_API uint64_t mizu_pool_worker_ident(
const mizu_pool *);
391 uint32_t inline_max);
392#ifdef MIZU_EXT_NO_INLINES
395 uint32_t inline_max);
399 uint32_t inline_max) {
400 if (n <= (uint64_t) inline_max) {
401 hdr->
kind = MIZU_KIND_RAWVEC;
402 hdr->len = (uint32_t) n;
403 hdr->aux = (uint64_t) (uint32_t) wire_type;
504typedef enum mizu_park_result_e { MIZU_PARK_WOKEN = 0, MIZU_PARK_TIMEOUT,
505 MIZU_PARK_INTR } mizu_park_result;
511 const char *region_name,
int entity,
523#ifdef MIZU_EXT_NO_INLINES
575MIZU_API int mizu_live_open(
const char *path, intptr_t *out);
576MIZU_API int mizu_live_try(intptr_t h);
577MIZU_API void mizu_live_close(intptr_t h);
586MIZU_API const char *mizu_preamble_validate(
const void *region,
611MIZU_API int mizu_pool_deque_pull(mizu_pool *, uint32_t n);
619 uint32_t *inj_cap, uint32_t *inline_entry);
647#define MIZU_MORSEL_CANCEL_OFF ((uint64_t) 0)
648#define MIZU_MORSEL_GEN_OFF ((uint64_t) 4)
649#define MIZU_MORSEL_CURSOR_OFF ((uint64_t) 64)
650#define MIZU_MORSEL_CLAIM_OFF ((uint64_t) 128)
653#define MIZU_MORSEL_GEN_MASK ((uint32_t) 0x3FFFFFFF)
655enum { MIZU_MORSEL_IDLE = 0, MIZU_MORSEL_RUNNING, MIZU_MORSEL_ABANDONED };
656enum { MIZU_MORSEL_X_DESC = 0, MIZU_MORSEL_X_RAW };
662#define MIZU_MORSEL_T_TARGET 200e-6
663#define MIZU_MORSEL_BATCH_CAP 64
670#define MIZU_MORSEL_MAGIC 0x4D495A4Du
685 uint64_t desc_off, desc_len;
686 uint64_t x_off, x_len;
695 "mizu_morsel_hdr is the wire format");
705 uint64_t n, uint64_t morsel_size,
706 uint64_t desc_len, uint32_t x_type,
707 uint64_t x_len, uint32_t out_type,
708 uint64_t out_m, uint32_t claim_n);
742 double now, uint64_t *m_out, uint64_t *k_out,
760 uint32_t r, uint32_t gen);
771MIZU_API uint64_t mizu_morsel_cursor(
const void *base,
779 uint64_t k, uint64_t *lo, uint64_t *hi);
829#ifdef MIZU_EXT_NO_INLINES
834 return (
MIZU_ATOMIC(uint32_t) *) ((
unsigned char *) base +
838 return (
MIZU_ATOMIC(uint32_t) *) ((
unsigned char *) base +
881#ifdef MIZU_EXT_NO_INLINES
887 g.offsets = (int64_t) MIZU_ALIGN64((uint64_t) (n + 7) / 8);
888 g.encoding = g.offsets + (int64_t) MIZU_ALIGN64(8 * ((uint64_t) n + 1));
889 g.data = g.encoding + (int64_t) MIZU_ALIGN64((uint64_t) n);
898 return (flags & ~MIZU_HDR_FLAG_S4) == 0;
905 uint64_t n,
size_t size) {
906 if (off == 0)
return count == 0 || count == -1;
907 if (count < 0 || (uint64_t) count > n || (off & 63) != 0)
return 0;
908 const uint64_t bytes = (n + 7) / 8;
909 return (uint64_t) off <= (uint64_t) size &&
910 bytes <= (uint64_t) size - (uint64_t) off;
942 return ((bits >> 52) & 0x7FF) == 0x7FF && (uint32_t) bits == 0x7A2u;
944MIZU_EXT_INLINE int mizu_ext_na_at(
int type,
const void *src, uint64_t i) {
945 const unsigned char *p = (
const unsigned char *) src;
946 uint64_t bits, re, im;
952 memcpy(&v32, p + 4 * i, 4);
955 memcpy(&bits, p + 8 * i, 8);
958 memcpy(&re, p + 16 * i, 8);
959 memcpy(&im, p + 16 * i + 8, 8);
962 memcpy(&v64, p + 8 * i, 8);
972 unsigned char *p = (
unsigned char *) dst;
979 memcpy(p + 4 * i, &na32, 4);
982 memcpy(p + 8 * i, &nabits, 8);
985 memcpy(p + 16 * i, &nabits, 8);
986 memcpy(p + 16 * i + 8, &nabits, 8);
989 memcpy(p + 8 * i, &na64, 8);
1006 const unsigned char *dir = (
const unsigned char *) base +
1007 MIZU_HEADER_SIZE + 32 * (
size_t) i;
1009 memcpy(&e->data_size, dir + 8, 8);
1010 memcpy(&e->sexptype, dir + 16, 4);
1011 memcpy(&e->attrs_size, dir + 20, 4);
1012 memcpy(&e->length, dir + 24, 8);
1016 (uint64_t) e->data_size >
1021 const int32_t tag = e->sexptype & ~(int32_t)
MIZU_MIZL_S4;
1023 if ((e->sexptype & (int32_t)
MIZU_MIZL_S4) != 0 || e->length < 0 ||
1024 e->data_size < 1 || e->data_size > 255)
1028 if ((int64_t) e->attrs_size > e->data_size)
return -1;
1029 const int64_t body = e->data_size - (int64_t) e->attrs_size;
1032 if (e->length < 0 || e->length > body / (int64_t) elt)
return -1;
1034 if (e->length < 0 || e->length > ((int64_t) 1 << 50) ||
1038 if (e->length < 0)
return -1;
1048 int *wire_type, int64_t *n_elems,
1050 if (size < MIZU_HEADER_SIZE)
return -1;
1053 int64_t len, attrs, voff, vcount;
1054 memcpy(&magic, base, 4);
1056 memcpy(&t32, (
const unsigned char *) base + 4, 4);
1057 memcpy(&len, (
const unsigned char *) base + 8, 8);
1058 memcpy(&attrs, (
const unsigned char *) base + 16, 8);
1060 memcpy(&vcount, (
const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1062 if (elt == 0 || len < 0 || attrs < 0 ||
1063 len > ((int64_t) size - (int64_t) MIZU_HEADER_SIZE) / (int64_t) elt ||
1064 attrs > (int64_t) size - (int64_t) MIZU_HEADER_SIZE -
1065 len * (int64_t) elt)
1077MIZU_EXT_INLINE int mizu_ext_mizs_check_impl(
const void *base,
size_t size,
1078 int64_t *n, int64_t *str_size,
1079 int64_t *attrs_size) {
1080 if (size < MIZU_HEADER_SIZE)
return -1;
1083 int64_t count, block;
1084 memcpy(&magic, base, 4);
1086 memcpy(&attrs, (
const unsigned char *) base + 4, 4);
1087 memcpy(&count, (
const unsigned char *) base + 8, 8);
1088 memcpy(&block, (
const unsigned char *) base + 16, 8);
1089 if (attrs < 0 || count < 0 || count > ((int64_t) 1 << 50) || block < 0)
1093 if (fixed > block ||
1094 block > (int64_t) size - (int64_t) MIZU_HEADER_SIZE ||
1096 (int64_t) size - (int64_t) MIZU_HEADER_SIZE - block)
1100 *attrs_size = attrs;
1104MIZU_EXT_INLINE int mizu_ext_mizl_check_impl(
const void *base,
size_t size,
1105 int64_t *n, int64_t *attrs_off,
1106 int64_t *attrs_size,
1108 if (size < MIZU_HEADER_SIZE)
return -1;
1111 int64_t aoff, asz, voff, vcount;
1112 memcpy(&magic, base, 4);
1114 memcpy(&n32, (
const unsigned char *) base + 4, 4);
1115 memcpy(&aoff, (
const unsigned char *) base + 8, 8);
1116 memcpy(&asz, (
const unsigned char *) base + 16, 8);
1118 memcpy(&vcount, (
const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1120 (uint64_t) (uint32_t) n32 >
1121 ((uint64_t) size - (uint64_t) MIZU_HEADER_SIZE) / 32)
1123 if (aoff < 0 || asz < 0 ||
1124 (uint64_t) aoff > (uint64_t) size ||
1125 (uint64_t) asz > (uint64_t) size - (uint64_t) aoff)
1129 for (int64_t i = 0; i < (int64_t) n32; i++) {
1132 const int32_t tag = e.sexptype & ~(int32_t)
MIZU_MIZL_S4;
1137 const uint64_t len = (uint64_t) e.length;
1138 sum = len > (uint64_t) INT64_MAX - sum ? (uint64_t) INT64_MAX
1143 if (vcount != 0 && vcount != -1)
return -1;
1145 const uint64_t bytes = (uint64_t) (uint32_t) n32 * 16;
1146 if (vcount < 0 || (uint64_t) vcount > sum || (voff & 63) != 0 ||
1147 (uint64_t) voff > (uint64_t) size ||
1148 bytes > (uint64_t) size - (uint64_t) voff)
1159MIZU_EXT_INLINE int mizu_ext_mizl_elem_impl(
const void *base,
size_t size,
1162 if (size < MIZU_HEADER_SIZE)
return -1;
1165 int64_t voff, vcount;
1166 memcpy(&magic, base, 4);
1168 memcpy(&n32, (
const unsigned char *) base + 4, 4);
1169 if (n32 < 0 || i < 0 || i >= (int64_t) n32 ||
1170 (uint64_t) (uint32_t) n32 >
1171 ((uint64_t) size - (uint64_t) MIZU_HEADER_SIZE) / 32)
1176 memcpy(&vcount, (
const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1178 if (vcount != 0 && vcount != -1)
return -1;
1180 elem->
valid[1] = vcount;
1183 if ((voff & 63) != 0)
return -1;
1184 const uint64_t bytes = (uint64_t) (uint32_t) n32 * 16;
1185 if ((uint64_t) voff > (uint64_t) size ||
1186 bytes > (uint64_t) size - (uint64_t) voff)
1188 const unsigned char *tab = (
const unsigned char *) base + voff;
1189 int64_t loff, lcount;
1190 memcpy(&loff, tab + 16 * (
size_t) i, 8);
1191 memcpy(&lcount, tab + 16 * (
size_t) i + 8, 8);
1197 const int32_t ltag = elem->sexptype & ~(int32_t)
MIZU_MIZL_S4;
1202 elem->
valid[0] = loff;
1203 elem->
valid[1] = lcount;
1207MIZU_EXT_INLINE uint64_t mizu_ext_na_build_impl(
int type, uint8_t *bitmap,
1208 const void *src, uint64_t n,
1211 for (uint64_t i = 0; i < n; i++) {
1212 const uint64_t bit = bit_off + i;
1213 if (mizu_ext_na_at(type, src, i)) {
1214 bitmap[bit >> 3] &= (uint8_t) ~(1u << (bit & 7));
1217 bitmap[bit >> 3] |= (uint8_t) (1u << (bit & 7));
1225 const uint8_t *bitmap,
1228 if (elt == 0)
return 0;
1229 if (dst != src) memcpy(dst, src, (
size_t) n * elt);
1231 for (uint64_t i = 0; i < n; i++) {
1232 if (((bitmap[i >> 3] >> (i & 7)) & 1) == 0) {
1240#ifdef MIZU_EXT_NO_INLINES
1242MIZU_API void mizu_store_na_real(
void *dst);
1246MIZU_API uint64_t mizu_aux_hi(uint64_t aux);
1249 int *wire_type, int64_t *n_elems, int64_t valid[2]);
1253 int64_t *str_size, int64_t *attrs_size);
1255 int64_t *attrs_off, int64_t *attrs_size,
1260 uint64_t n, uint64_t bit_off);
1262 const uint8_t *bitmap, uint64_t n);
1270 if (!isfinite(seconds))
return -1;
1271 if (seconds <= 0)
return 0;
1272 const double ms = seconds * 1000;
1273 return isfinite(ms) ? ms : -1;
1277 memcpy(dst, &bits, 8);
1281 return (uint64_t) (uint32_t) type | ((uint64_t) name_len << 8);
1285 return (uint64_t) (uint32_t) type | (total << 8);
1291 return (
int) (aux & 0xff);
1303 const int32_t t32 = wire_type;
1304 const int64_t zero64 = 0;
1305 memcpy(base, &magic, 4);
1306 memcpy((
unsigned char *) base + 4, &t32, 4);
1307 memcpy((
unsigned char *) base + 8, &n_elems, 8);
1308 memcpy((
unsigned char *) base + 16, &zero64, 8);
1309 memset((
unsigned char *) base + 24, 0, MIZU_HEADER_SIZE - 24);
1318 int *wire_type, int64_t *n_elems,
1328 memcpy((
unsigned char *) base + MIZU_HDR_VALID_COUNT, &count, 8);
1336 int64_t *n, int64_t *str_size,
1337 int64_t *attrs_size) {
1338 return mizu_ext_mizs_check_impl(base, size, n, str_size, attrs_size);
1346 int64_t *n, int64_t *attrs_off,
1347 int64_t *attrs_size, int64_t valid[2]) {
1348 return mizu_ext_mizl_check_impl(base, size, n, attrs_off, attrs_size,
1357 return mizu_ext_mizl_elem_impl(base, size, i, elem);
1364 const void *src, uint64_t n,
1366 return mizu_ext_na_build_impl(type, bitmap, src, n, bit_off);
1372 const uint8_t *bitmap, uint64_t n) {
1373 return mizu_ext_na_apply_impl(type, dst, src, bitmap, n);
1392#define MIZU_IX_VERSION 0x01u
1393#define MIZU_IX_DEPTH_MAX 64
1397 MIZU_IX_TAG_NIL = 0x00,
1398 MIZU_IX_TAG_LGL1 = 0x01,
1399 MIZU_IX_TAG_INT = 0x02,
1400 MIZU_IX_TAG_REAL = 0x03,
1401 MIZU_IX_TAG_STR = 0x04,
1402 MIZU_IX_TAG_BYTES = 0x05,
1403 MIZU_IX_TAG_LGLV = 0x06,
1404 MIZU_IX_TAG_INTV = 0x07,
1405 MIZU_IX_TAG_REALV = 0x08,
1406 MIZU_IX_TAG_CPLXV = 0x09,
1407 MIZU_IX_TAG_RAWV = 0x0a,
1408 MIZU_IX_TAG_STRV = 0x0b,
1409 MIZU_IX_TAG_LIST = 0x0c,
1410 MIZU_IX_TAG_DICT = 0x0d,
1411 MIZU_IX_TAG_I64V = 0x0e,
1412 MIZU_IX_TAG_ATTR = 0x0f,
1413 MIZU_IX_TAG_CPLX = 0x10,
1414 MIZU_IX_TAG_ERR = 0x11,
1415 MIZU_IX_TAG_TASK = 0x12,
1416 MIZU_IX_TAG_REF = 0x13
1471 const unsigned char *p;
1472 const unsigned char *end;
1479 } stack[MIZU_IX_DEPTH_MAX];
1521#define MIZU_IX_ERR_OVERHEAD 25u
1522#define MIZU_IX_ERR_TYPE_SHARE 128u
1529#define MIZU_IX_ATTR_NAMES "names"
1530#define MIZU_IX_ATTR_LEVELS "levels"
1531#define MIZU_IX_ATTR_DIM "dim"
1532#define MIZU_IX_ATTR_CLASS "class"
1533#define MIZU_IX_ATTR_UNITS "units"
1534#define MIZU_IX_ATTR_ROWNAMES "row.names"
1535#define MIZU_IX_ATTR_TZONE "tzone"
1536#define MIZU_IX_ATTR_TSCALE "tscale"
1537#define MIZU_IX_ATTR_U64 "u64"
1539#define MIZU_IX_CLASS_FACTOR "factor"
1540#define MIZU_IX_CLASS_DATE "Date"
1541#define MIZU_IX_CLASS_POSIXCT "POSIXct"
1542#define MIZU_IX_CLASS_POSIXT "POSIXt"
1543#define MIZU_IX_CLASS_DIFFTIME "difftime"
1544#define MIZU_IX_CLASS_DATAFRAME "data.frame"
1546#define MIZU_IX_UNIT_SECS "secs"
1547#define MIZU_IX_UNIT_MINS "mins"
1548#define MIZU_IX_UNIT_HOURS "hours"
1549#define MIZU_IX_UNIT_DAYS "days"
1550#define MIZU_IX_UNIT_WEEKS "weeks"
1558 const unsigned char *b = (
const unsigned char *) s;
1561 const unsigned char c = b[i];
1564 }
else if (c < 0xC2 || c >= 0xF5) {
1567 }
else if (c < 0xE0) {
1568 if (i + 2 > n || (b[i + 1] & 0xC0) != 0x80)
return 0;
1570 }
else if (c < 0xF0) {
1571 if (i + 3 > n || (b[i + 1] & 0xC0) != 0x80 ||
1572 (b[i + 2] & 0xC0) != 0x80)
return 0;
1573 if (c == 0xE0 && b[i + 1] < 0xA0)
return 0;
1574 if (c == 0xED && b[i + 1] >= 0xA0)
return 0;
1577 if (i + 4 > n || (b[i + 1] & 0xC0) != 0x80 ||
1578 (b[i + 2] & 0xC0) != 0x80 || (b[i + 3] & 0xC0) != 0x80)
1580 if (c == 0xF0 && b[i + 1] < 0x90)
return 0;
1581 if (c == 0xF4 && b[i + 1] > 0x8F)
return 0;
1591 switch (wire_type) {
1598 default:
return MIZU_IX_TAG_NIL;
1615 uint32_t tag, uint64_t v) {
1618 dst[0] = (
unsigned char) tag;
1619 memcpy(dst + 1, &v, 8);
1625 if (dst != NULL) dst[0] = MIZU_IX_TAG_NIL;
1632 dst[0] = MIZU_IX_TAG_LGL1;
1633 dst[1] = (
unsigned char) value;
1641 dst[0] = MIZU_IX_TAG_INT;
1642 memcpy(dst + 1, &value, 8);
1650 dst[0] = MIZU_IX_TAG_REAL;
1651 memcpy(dst + 1, &value, 8);
1657 double re,
double im) {
1659 dst[0] = MIZU_IX_TAG_CPLX;
1660 memcpy(dst + 1, &re, 8);
1661 memcpy(dst + 9, &im, 8);
1667 const void *s, int32_t len) {
1669 dst[0] = MIZU_IX_TAG_STR;
1670 memcpy(dst + 1, &len, 4);
1671 if (len > 0) memcpy(dst + 5, s, (
size_t) len);
1673 return (
size_t) 5 + (len > 0 ? (size_t) len : 0);
1680 dst[0] = MIZU_IX_TAG_BYTES;
1681 memcpy(dst + 1, &count, 8);
1682 if (count != 0) memcpy(dst + 9, data, (
size_t) count);
1684 return (
size_t) 9 + (size_t) count;
1692 if (tag == MIZU_IX_TAG_NIL)
return 0;
1695 dst[0] = (
unsigned char) tag;
1696 memcpy(dst + 1, &count, 8);
1697 if (count != 0) memcpy(dst + 9, data, (
size_t) count * elt);
1699 return (
size_t) 9 + (size_t) count * elt;
1702MIZU_EXT_INLINE size_t mizu_ext_ix_put_strv_begin_impl(
unsigned char *dst,
1711 memcpy(dst, &len, 4);
1712 if (len > 0) memcpy(dst + 4, s, (
size_t) len);
1714 return (
size_t) 4 + (len > 0 ? (size_t) len : 0);
1717MIZU_EXT_INLINE size_t mizu_ext_ix_put_list_begin_impl(
unsigned char *dst,
1722MIZU_EXT_INLINE size_t mizu_ext_ix_put_dict_begin_impl(
unsigned char *dst,
1728 const void *s, uint32_t len) {
1730 memcpy(dst, &len, 4);
1731 if (len != 0) memcpy(dst + 4, s, (
size_t) len);
1733 return (
size_t) 4 + (size_t) len;
1737 if (dst != NULL) dst[0] = MIZU_IX_TAG_ATTR;
1742 int has_index, uint64_t index,
1745 const void *message,
1746 uint32_t message_len,
1748 uint32_t detail_len) {
1750 const uint16_t flags = (uint16_t) (has_index != 0);
1751 dst[0] = MIZU_IX_TAG_ERR;
1752 memcpy(dst + 1, &flags, 2);
1755 memcpy(dst + off, &index, 8);
1758 const void *strs[3] = { type, message, detail };
1759 const uint32_t lens[3] = { type_len, message_len, detail_len };
1760 for (
int i = 0; i < 3; i++) {
1761 memcpy(dst + off, &lens[i], 4);
1764 memcpy(dst + off, strs[i], (
size_t) lens[i]);
1765 off += (size_t) lens[i];
1770 return (
size_t) 3 + (has_index ? 8 : 0) +
1771 (
size_t) 12 + (size_t) type_len + (
size_t) message_len +
1772 (size_t) detail_len;
1776 int target,
int kind,
1779 const uint16_t zero = 0;
1780 dst[0] = MIZU_IX_TAG_TASK;
1781 dst[1] = (
unsigned char) target;
1782 dst[2] = (
unsigned char) kind;
1783 memcpy(dst + 3, &zero, 2);
1784 memcpy(dst + 5, &ident, 8);
1791 uint32_t name_len) {
1794 if (name_len == 0 || name_len > 255)
return 0;
1796 dst[0] = MIZU_IX_TAG_REF;
1797 dst[1] = (
unsigned char) name_len;
1798 memcpy(dst + 2, name, (
size_t) name_len);
1800 return (
size_t) 2 + name_len;
1807 if (n <= share)
return n;
1808 const unsigned char *b = (
const unsigned char *) s;
1810 while (len > 0 && (b[len] & 0xC0) == 0x80) len--;
1815 unsigned char *dst, uint32_t inline_max,
1816 const void *type,
size_t type_n,
1817 const void *msg,
size_t msg_n,
1818 const void *detail,
size_t detail_n,
1819 int has_index, uint64_t index) {
1825 const size_t budget = inline_max;
1826 const size_t avail =
1829 avail < MIZU_IX_ERR_TYPE_SHARE ? avail : MIZU_IX_ERR_TYPE_SHARE;
1832 if (cap > avail - tn) cap = avail - tn;
1837 n += mizu_ext_ix_put_err_impl(dst != NULL ? dst + n : NULL, has_index,
1838 index, type, (uint32_t) tn, msg,
1839 (uint32_t) mn, detail, (uint32_t) dn);
1843#ifdef MIZU_EXT_NO_INLINES
1846MIZU_API size_t mizu_ix_put_header(
unsigned char *dst);
1847MIZU_API size_t mizu_ix_put_nil(
unsigned char *dst);
1849MIZU_API size_t mizu_ix_put_int(
unsigned char *dst, int64_t value);
1851MIZU_API size_t mizu_ix_put_cplx(
unsigned char *dst,
double re,
double im);
1854MIZU_API size_t mizu_ix_put_bytes(
unsigned char *dst,
const void *data,
1857 const void *data, uint64_t count);
1858MIZU_API size_t mizu_ix_put_strv_begin(
unsigned char *dst, uint64_t count);
1861MIZU_API size_t mizu_ix_put_list_begin(
unsigned char *dst, uint64_t count);
1862MIZU_API size_t mizu_ix_put_dict_begin(
unsigned char *dst, uint64_t count);
1865MIZU_API size_t mizu_ix_put_attr(
unsigned char *dst);
1866MIZU_API size_t mizu_ix_put_err(
unsigned char *dst,
int has_index,
1868 const void *type, uint32_t type_len,
1869 const void *message, uint32_t message_len,
1870 const void *detail, uint32_t detail_len);
1876 const void *type,
size_t type_n,
1877 const void *msg,
size_t msg_n,
1878 const void *detail,
size_t detail_n,
1879 int has_index, uint64_t index);
1905 return mizu_ext_ix_put_nil_impl(dst);
1909 return mizu_ext_ix_put_lgl_impl(dst, value);
1911MIZU_EXT_INLINE size_t mizu_ix_put_int(
unsigned char *dst, int64_t value) {
1912 return mizu_ext_ix_put_int_impl(dst, value);
1917 return mizu_ext_ix_put_real_impl(dst, value);
1921 return mizu_ext_ix_put_cplx_impl(dst, re, im);
1926 return mizu_ext_ix_put_str_impl(dst, s, len);
1929 const void *data, uint64_t count) {
1930 return mizu_ext_ix_put_bytes_impl(dst, data, count);
1936 const void *data, uint64_t count) {
1937 return mizu_ext_ix_put_vec_impl(dst, wire_type, data, count);
1941 return mizu_ext_ix_put_strv_begin_impl(dst, count);
1946 return mizu_ext_ix_put_strelt_impl(dst, s, len);
1950 return mizu_ext_ix_put_list_begin_impl(dst, count);
1954 return mizu_ext_ix_put_dict_begin_impl(dst, count);
1959 return mizu_ext_ix_put_key_impl(dst, s, len);
1962 return mizu_ext_ix_put_attr_impl(dst);
1964MIZU_EXT_INLINE size_t mizu_ix_put_err(
unsigned char *dst,
int has_index,
1966 const void *type, uint32_t type_len,
1967 const void *message,
1968 uint32_t message_len,
1970 uint32_t detail_len) {
1971 return mizu_ext_ix_put_err_impl(dst, has_index, index, type, type_len,
1972 message, message_len, detail, detail_len);
1977 int kind, uint64_t ident) {
1978 return mizu_ext_ix_put_task_impl(dst, target, kind, ident);
1982 uint32_t name_len) {
1994 uint32_t inline_max,
1995 const void *type,
size_t type_n,
1996 const void *msg,
size_t msg_n,
1997 const void *detail,
size_t detail_n,
1998 int has_index, uint64_t index) {
2000 msg_n, detail, detail_n, has_index,
2014#ifndef ARROW_C_DATA_INTERFACE
2015#define ARROW_C_DATA_INTERFACE
2019 const char *metadata;
2034 const void **buffers;
2042#ifndef ARROW_C_STREAM_INTERFACE
2043#define ARROW_C_STREAM_INTERFACE
2058 if (arr->null_count == 0 || arr->buffers[0] == NULL)
return 1;
2059 int64_t i = arr->offset + k;
2060 const uint8_t *bm = (
const uint8_t *) arr->buffers[0];
2061 return (bm[i >> 3] >> (i & 7)) & 1;
2065 int64_t k,
int form,
2066 const uint8_t **ptr,
2068 if (!mizu_ext_arrow_valid_impl(arr, k))
return 0;
2069 int64_t i = arr->offset + k;
2071 const uint8_t *offs = (
const uint8_t *) arr->buffers[1];
2073 memcpy(&o0, offs + 4 * i, 4);
2074 memcpy(&o1, offs + 4 * (i + 1), 4);
2075 if (o0 < 0 || o1 < o0)
return -1;
2076 *ptr = (
const uint8_t *) arr->buffers[2] + o0;
2078 }
else if (form == 2) {
2079 const uint8_t *offs = (
const uint8_t *) arr->buffers[1];
2081 memcpy(&o0, offs + 8 * i, 8);
2082 memcpy(&o1, offs + 8 * (i + 1), 8);
2083 if (o0 < 0 || o1 < o0 || o1 - o0 > INT32_MAX)
2085 *ptr = (
const uint8_t *) arr->buffers[2] + o0;
2086 *len = (int32_t) (o1 - o0);
2088 const uint8_t *vw = (
const uint8_t *) arr->buffers[1] + i * 16;
2091 if (l < 0)
return -1;
2096 memcpy(&bi, vw + 8, 4);
2097 memcpy(&off, vw + 12, 4);
2105 if (bi < 0 || off < 0 || 2 + (int64_t) bi >= arr->n_buffers)
2107 if (2 + bi < arr->n_buffers - 1) {
2108 const uint8_t *sizes =
2109 (
const uint8_t *) arr->buffers[arr->n_buffers - 1];
2110 if (sizes != NULL) {
2112 memcpy(&sz, sizes + 8 * (ptrdiff_t) bi, 8);
2113 if ((int64_t) off + l > sz)
return -1;
2116 *ptr = (
const uint8_t *) arr->buffers[2 + bi] + off;
2123#ifdef MIZU_EXT_NO_INLINES
2126 const uint8_t **ptr, int32_t *len);
2130 return mizu_ext_arrow_valid_impl(arr, k);
2143 int form,
const uint8_t **ptr,
2145 return mizu_ext_arrow_str_at_impl(arr, k, form, ptr, len);
2150#define MIZU_ARROW_FLAG_DICTIONARY_ORDERED 1
2151#define MIZU_ARROW_FLAG_NULLABLE 2
2196 const uint8_t *valid, uint64_t off,
size_t n,
2243 size_t n_batches, uint32_t peer_caps);
2301 const char *ident,
size_t ident_len,
2302 void *ref_base,
size_t ref_size,
2335 unsigned char *payload,
libmizu public API: SPSC channels and work-stealing task pools between processes on one machine.
#define MIZU_NA_INT32
The missing-value sentinels of the atomic wire types (the R ABI fixes the bit patterns; a binding of ...
Definition mizu.h:289
@ MIZU_TYPE_CPLX
interleaved float64 re/im
Definition mizu.h:279
@ MIZU_TYPE_RAW
bytes
Definition mizu.h:282
@ MIZU_TYPE_REAL
float64; a specific NaN payload is the sentinel
Definition mizu.h:278
@ MIZU_TYPE_LGL
int32 logical; INT_MIN is the missing sentinel
Definition mizu.h:276
@ MIZU_TYPE_STR
string vector (MIZS layout)
Definition mizu.h:280
@ MIZU_TYPE_VEC
list tree (MIZL layout)
Definition mizu.h:281
@ MIZU_TYPE_INT64
int64; INT64_MIN is the missing sentinel
Definition mizu.h:283
@ MIZU_TYPE_INT
int32; INT_MIN is the missing sentinel
Definition mizu.h:277
#define MIZU_MAGIC_VEC
"MIZH"
Definition mizu.h:368
#define MIZU_MAGIC_STR
"MIZS"
Definition mizu.h:369
#define MIZU_HDR_VALID_OFF
Header bytes [40-47] and [48-55] are the optional validity-bitmap section of every MIZH and MIZL head...
Definition mizu.h:338
enum mizu_errcat_e mizu_errcat
Portable failure categories for MIZU_ERR (the platform layer classifies errno / GetLastError).
#define MIZU_MIZL_S4
MIZH (atomic vector): [4-7] i32 wire type, [8-15] i64 element count, [16-23] i64 attrs blob size; bar...
Definition mizu.h:366
#define MIZU_NAME_MAX
fits Windows worst case + NUL; Darwin PSHMNAMLEN
Definition mizu.h:373
#define MIZU_NA_INT64
NA_integer64_ sentinel.
Definition mizu.h:290
#define MIZU_API
Export macro.
Definition mizu.h:87
#define MIZU_ZC_REFCOUNT_OFF
Zero-copy view protocol: mizu-owned bytes [24-31] of every MIZU* region header (reserved [24-63] in t...
Definition mizu.h:302
#define MIZU_MAGIC_LIST
"MIZL"
Definition mizu.h:370
size_t mizu_type_elt_size(int type)
Element size of an atomic wire type, 0 for non-atomic.
enum mizu_status_e mizu_status
The verb result.
#define MIZU_ATOMIC(T)
The wire-format structs carry atomic words.
Definition mizu.h:68
#define MIZU_NA_REAL_BITS
NA_real_ (a NaN payload)
Definition mizu.h:291
#define MIZU_HDR_FLAGS_OFF
Region magics (first 4 bytes): atomic vector, string vector, list tree.
Definition mizu.h:318
static size_t mizu_ix_put_str(unsigned char *dst, const void *s, int32_t len)
The 0x04 string scalar; len -1 is NA (s may then be NULL).
Definition mizu_ext.h:1924
void mizu_binding_bytes(mizu_binding *)
Fill binding with the bytes binding: stage/read only — exec, check, park, sweep, drop are NULL (a byt...
mizu_status mizu_ixt_want_dict(mizu_ix *cur, mizu_ix_item *item)
The next item must be a DICT begin (the named field).
static uint64_t mizu_na_build(int type, uint8_t *bitmap, const void *src, uint64_t n, uint64_t bit_off)
The sentinels-to-bitmap scan: bit (bit_off + i) of bitmap records element i of src,...
Definition mizu_ext.h:1363
static uint32_t * mizu_zc_rc(void *base)
The zc refcount / flags words of a MIZU* region header (bytes [24-31] of the reserved band — the wire...
Definition mizu_ext.h:833
static mizu_mizs_geom mizu_mizs_geometry(int64_t n)
The string block's section offsets for n strings (each section 64-byte aligned from the block start).
Definition mizu_ext.h:884
static size_t mizu_ix_put_strelt(unsigned char *dst, const void *s, int32_t len)
A bare strv element; len -1 is NA.
Definition mizu_ext.h:1944
static uint64_t mizu_aux_shm_vec(int type, uint64_t total)
aux = layout type tag | exact used bytes << 8.
Definition mizu_ext.h:1284
mizu_status mizu_pool_submit_flags(mizu_pool *, void *task_obj, uint16_t flags, mizu_task *out, double timeout_ms)
The map runner's submit: mizu_pool_submit plus the entry flags (MIZU_ENTRY_RUNNER marks a map's join ...
int mizu_pool_help_once(mizu_pool *)
One doorbell help beat (claims a map runner and re-homes it onto the helper's own deque) and the test...
static int mizu_ext_ix_tag_of_impl(int wire_type)
Definition mizu_ext.h:1588
mizu_status mizu_arrow_stage(mizu_handle *, mizu_arrow *, mizu_slot_hdr *hdr, unsigned char *payload, mizu_arrow_warn *warn)
The one-call stage over the handle seam, valid only during a stage_fn call.
static int mizu_arrow_str_at(const ArrowArray *arr, int64_t k, int form, const uint8_t **ptr, int32_t *len)
The string forms' per-batch element access: utf8 (i32 offsets), large_utf8 (i64), string_view (16-byt...
Definition mizu_ext.h:2142
static uint64_t mizu_aux_rawspill_pool(int type, uint32_t name_len)
aux = wire type tag | region name length << 8.
Definition mizu_ext.h:1280
#define MIZU_EXT_INLINE
Some static inlines below go unused in some TUs; the amalgamation folds this header into the single m...
Definition mizu_ext.h:61
struct mizu_mizl_entry_s mizu_mizl_entry
One MIZL directory entry plus its validity-table pair (mizu.h documents the 32-byte entry): mizu_mizl...
struct mizu_pool_sig_s mizu_pool_sig
The opaque pool-signal trio a map runner loads relaxed once per batch transition: the help_wanted doo...
uint32_t mizu_morsel_generation(const void *base, const mizu_morsel_hdr *h)
Single reads of the mutable words: the generation (masked), the cursor clamped to n_morsels,...
static size_t mizu_ext_ix_put_ref_impl(unsigned char *dst, const void *name, uint32_t name_len)
Definition mizu_ext.h:1789
void mizu_pool_eval_mark(mizu_pool *, int in_flight)
The eval-in-flight marker a binding sets around its catching = 0 task eval only (R: around Rf_eval,...
mizu_status mizu_ix_open(mizu_ix *cur, const void *buf, size_t len)
Open a cursor over a whole stream: the magic and version checks, the unknown version taking the infor...
static size_t mizu_ix_put_ref(unsigned char *dst, const void *name, uint32_t name_len)
The ref leaf: the region identifier span (1-255 bytes; 0 returns 0).
Definition mizu_ext.h:1981
void mizu_morsel_cancel_set(void *base, const mizu_morsel_hdr *h)
The cancel word: set by the submitter on timeout / interrupt / death, and by an erroring runner itsel...
static int mizu_ext_valid_ok(int64_t off, int64_t count, uint64_t n, size_t size)
The three-state validity pair of an MIZH header or one MIZL leaf-table entry: {0, 0} absent,...
Definition mizu_ext.h:904
#define MIZU_INTEROP_MAGIC
'I': the interchange stream (DESIGN.md's Interchange codec section)
Definition mizu_ext.h:104
static int mizu_ext_mizh_check_impl(const void *base, size_t size, int *wire_type, int64_t *n_elems, int64_t valid[2])
The bodies behind the larger dual-form functions below: both the header inline and the exported symbo...
Definition mizu_ext.h:1047
void mizu_cvt_convert(uint8_t *dst, const uint8_t *src, const uint8_t *valid, uint64_t off, size_t n, const mizu_cvt_row *row, mizu_arrow_warn *warn)
One run's convert into a reserved destination: the BIT_LGL / masked / plain dispatch.
static double mizu_timeout_ms(double seconds)
seconds (a binding's convention; <= 0 polls, non-finite waits indefinitely) to the core's timeout_ms ...
Definition mizu_ext.h:1269
const char * mizu_live_dir(void)
Directory for liveness lock files: the MIZU_LIVENESS_DIR override (read-through, checked every call) ...
void mizu_tune(void)
malloc tuning (tune.c), called by the binding at load.
static size_t mizu_ext_ix_put_tag8_impl(unsigned char *dst, uint32_t tag, uint64_t v)
Definition mizu_ext.h:1614
struct mizu_arrow mizu_arrow
The Arrow -> MIZL frame writer: a classified, batch-vetted frame plus its size-pass results,...
Definition mizu_ext.h:2205
static size_t mizu_ext_ix_put_header_impl(unsigned char *dst)
The interop emit helpers' bodies (the interchange stream section below): every count and value follow...
Definition mizu_ext.h:1606
@ MIZU_CVT_U16_INT
zero-widen
Definition mizu_ext.h:2159
@ MIZU_CVT_COPY
identity: one memcpy per run
Definition mizu_ext.h:2156
@ MIZU_CVT_U32_REAL
exact
Definition mizu_ext.h:2160
@ MIZU_CVT_BOOL8_LGL
one byte per source lane (numpy '?') -> int32 0/1
Definition mizu_ext.h:2164
@ MIZU_CVT_F32_REAL
exact
Definition mizu_ext.h:2163
@ MIZU_CVT_BIT_LGL
one bit per source lane (Arrow 'b') -> int32 0/1
Definition mizu_ext.h:2165
@ MIZU_CVT_I8_INT
sign-widen
Definition mizu_ext.h:2157
@ MIZU_CVT_C64_CPLX
float re/im -> double re/im
Definition mizu_ext.h:2166
@ MIZU_CVT_F16_REAL
exact (half decodes into double's wider fields)
Definition mizu_ext.h:2162
static int mizu_ext_flags_known(const void *base)
The [32-35] format flags word admits only the assigned S4 bit.
Definition mizu_ext.h:895
const char * mizu_morsel_hdr_check(const void *base, size_t size, mizu_morsel_hdr *out)
Validate a region's header against the mapping size, including section placement.
static int mizu_ix_tag_of(int wire_type)
The wire-type -> vector-tag mapping: MIZU_TYPE_LGL / INT / REAL / CPLX / RAW / INT64 -> 0x06 / 0x07 /...
Definition mizu_ext.h:1898
int mizu_handle_kind(const mizu_handle *)
Handle queries standing in for field access into the private handle struct.
uint32_t mizu_morsel_reset(void *base, const mizu_morsel_hdr *h)
Prepared-run re-arm, O(1) in n (no per-morsel state exists to clear): bump the generation,...
mizu_status mizu_ixt_want_code(mizu_ix *cur, mizu_ix_item *item)
The next item must be a non-NA STR1 (the 0x04 code string).
struct mizu_death_watch_s mizu_death_watch
Translates a watched pid's exit into *flag = 1 plus a directed unpark of pk (optional,...
Definition mizu_ext.h:544
@ MIZU_ARROW_TS
timestamp -> REAL seconds + the POSIXct blob
Definition mizu_ext.h:2216
@ MIZU_ARROW_TD
duration -> REAL seconds + the difftime blob
Definition mizu_ext.h:2217
@ MIZU_ARROW_CVT
fixed-width, through the cvt row
Definition mizu_ext.h:2212
@ MIZU_ARROW_DATE
date32 -> REAL days + the Date blob
Definition mizu_ext.h:2215
@ MIZU_ARROW_DICT
dictionary<strings> -> a factor
Definition mizu_ext.h:2214
@ MIZU_ARROW_STR
utf8 / large_utf8 / string_view -> MIZS
Definition mizu_ext.h:2213
mizu_status mizu_ix_next(mizu_ix *cur, mizu_ix_item *item)
The next item: bounds, depth, UTF-8 and grammar checks per the spec.
void * mizu_stage_arena_alloc(mizu_handle *, size_t n, uint64_t *off)
Core services for a stager (per handle), valid only during a stage_fn call — staging is single-thread...
struct mizu_morsel_sizer_s mizu_morsel_sizer
Batch-sizing state: process-private, never wire state, reset at each run's first-call CLAIM CAS.
int mizu_morsel_abandon(void *base, const mizu_morsel_hdr *h, uint32_t r, uint32_t gen)
The exhausted-runner trim's CAS, folding its own trigger: a no-op unless the cursor is exhausted or t...
size_t mizu_arrow_write_ix_col(const mizu_arrow *, int64_t col, uint8_t *dst, mizu_arrow_warn *warn)
One column's 'I' value form (the inline small-table path): the plain vectors bare (the cvt tag off th...
#define MIZU_IX_VERSION
The byte-level half of DESIGN.md's Interchange codec section: a validating pull cursor (mizu_ix_open ...
Definition mizu_ext.h:1392
static int mizu_aux_type(uint64_t aux)
The decode half of the aux split (low byte the type tag, the kind's field above it): the tag,...
Definition mizu_ext.h:1290
static int mizu_mizs_check(const void *base, size_t size, int64_t *n, int64_t *str_size, int64_t *attrs_size)
Validate the MIZS header at base against the region: magic, the format flags word,...
Definition mizu_ext.h:1335
mizu_status mizu_arrow_open(mizu_arrow **out, const ArrowSchema *schema, const ArrowArray *const *batches, size_t n_batches, uint32_t peer_caps)
Classify every column off the schema (a struct schema; the type map of DESIGN.md's frame section),...
struct mizu_handle_s mizu_handle
Generic handle view for the stager services; the core passes the handle a binding's callbacks were re...
Definition mizu_ext.h:157
static int mizu_arrow_valid(const ArrowArray *arr, int64_t k)
The validity bit for element k of a batch (Arrow LSB-first).
Definition mizu_ext.h:2129
void mizu_morsel_span_of(const mizu_morsel_hdr *h, uint64_t m, uint64_t k, uint64_t *lo, uint64_t *hi)
A batch's element range, 0-based half-open: [m * morsel_size, min((m + k) morsel_size,...
static uint32_t mizu_parker_snapshot(const mizu_parker *pk)
The park handshake's first step (dual form — see the banner).
Definition mizu_ext.h:527
size_t mizu_arrow_write_ix(const mizu_arrow *, uint8_t *dst, mizu_arrow_warn *warn)
One complete 'I' stream of the whole frame (the small-table path): the header, the attr mark,...
void mizu_preamble_write(void *region, const mizu_preamble *p)
Host writes at create, immutable thereafter; the peer validates before any shared atomic is read or w...
static int mizu_ix_utf8_valid(const void *s, size_t n)
The emit helpers: each returns its byte count, writing only when dst is not NULL, so a binding's two-...
Definition mizu_ext.h:1891
int64_t mizu_handle_keep_out(const mizu_handle *)
The tx-keeper count: outstanding staging retains on a channel handle (the reap gate's own count,...
int(* mizu_stage_fn)(void *obj, mizu_slot_hdr *hdr, uint8_t *payload, uint32_t inline_max, mizu_handle *, void *ctx)
The core never sees a language object.
Definition mizu_ext.h:272
static size_t mizu_ix_put_lgl(unsigned char *dst, int value)
value on the wire: 0, 1, or 2 (NA).
Definition mizu_ext.h:1908
double mizu_now(void)
Monotonic seconds (the spin/deadline clock) and the current pid (cached, with an atfork reset).
mizu_status mizu_ix_end(mizu_ix *cur)
The finishing check: exactly one value per stream — fails on a truncated root value or on bytes past ...
uint64_t mizu_morsel_layout(mizu_morsel_hdr *h, uint64_t n, uint64_t morsel_size, uint64_t desc_len, uint32_t x_type, uint64_t x_len, uint32_t out_type, uint64_t out_m, uint32_t claim_n)
Fill *h with the section layout for a map of n elements (morsel_size the geometry input,...
static size_t mizu_ext_ix_write_err_impl(unsigned char *dst, uint32_t inline_max, const void *type, size_t type_n, const void *msg, size_t msg_n, const void *detail, size_t detail_n, int has_index, uint64_t index)
Definition mizu_ext.h:1814
static size_t mizu_ix_write_err(unsigned char *dst, uint32_t inline_max, const void *type, size_t type_n, const void *msg, size_t msg_n, const void *detail, size_t detail_n, int has_index, uint64_t index)
A complete 'I' err stream in one call: the two-byte header, then the 0x11 err item,...
Definition mizu_ext.h:1993
size_t mizu_arrow_col_body(const mizu_arrow *, int64_t col, uint8_t *dst, mizu_arrow_warn *warn)
One column's by-value body bytes over every batch — the cvt lanes, a dictionary's 1-based codes,...
struct mizu_morsel_span_s mizu_morsel_span
Worker-death lost set: issued = [0, bound), lost = issued minus the union of the collected batch hist...
static void mizu_ext_na_store(int type, void *dst, uint64_t i)
Write the wire type's missing sentinel over element i (the CPLX pair both parts).
Definition mizu_ext.h:971
void mizu_arrow_col_info(const mizu_arrow *, int64_t col, mizu_arrow_col *out)
The per-column classification, for a binding's own emitters over the same batches (pymizu's inline fr...
static size_t mizu_ix_put_vec(unsigned char *dst, int wire_type, const void *data, uint64_t count)
The fixed-width vector tags: wire_type one of MIZU_TYPE_LGL / INT / REAL / CPLX / RAW / INT64 (any ot...
Definition mizu_ext.h:1935
static int mizu_mizl_elem(const void *base, size_t size, int64_t i, mizu_mizl_entry *elem)
One bounds-checked MIZL directory entry (index i), with its validity-table pair: a {0,...
Definition mizu_ext.h:1355
enum mizu_live_probe_e mizu_live_probe
Exclusive flock (POSIX) / LockFileEx (Windows) held for a process's entire lifetime and released by t...
mizu_pool_sig * mizu_pool_signals(mizu_pool *)
A malloc'd copy of the signal trio (the caller frees).
void mizu_err_describe(mizu_errcat, const char **summary, const char **hint)
Category + remediation text for an MIZU_ERRCAT (what the handle / thread-local error slot records).
mizu_status mizu_ixt_open(mizu_ix *cur, const void *buf, size_t len, mizu_ix_item *item, int max_kind)
The task-stream decode shim (DESIGN.md's byte-shape helper registry): the per-field shape checks ever...
static size_t mizu_ix_put_key(unsigned char *dst, const void *s, uint32_t len)
A bare dict key: never NA, so the length is unsigned.
Definition mizu_ext.h:1957
void * mizu_stage_raw_spill(mizu_handle *, uint64_t n, int wire_type, mizu_slot_hdr *, uint8_t *payload, uint32_t inline_max)
Raw-tier reservation (stage_raw.c), valid only during stage_fn: choose the tier for n bare bytes of w...
size_t mizu_arrow_col_blob(const mizu_arrow *, int64_t col, uint8_t *dst)
One column's attribute dict as a bare 0x0d dict value (the §3.5 blob without its stream header — a bi...
void mizu_arrow_tz(mizu_arrow *, int64_t col, const char *tz)
The tzone override: the POSIXct leaf blob writes tz verbatim (a same-language sender's naivety-preser...
static size_t mizu_ix_put_real(unsigned char *dst, double value)
real and cplx take doubles and memcpy them: NaN payloads are bitwise-preserved.
Definition mizu_ext.h:1916
int mizu_morsel_next(void *base, const mizu_morsel_hdr *h, mizu_morsel_sizer *sz, uint32_t r, uint32_t gen, const mizu_pool_sig *sig, uint64_t pin_k, double now, uint64_t *m_out, uint64_t *k_out, int *help_out)
One whole batch transition — generation-fenced lane claim, cancel and pool-signal checks,...
size_t mizu_arrow_size(mizu_arrow *)
The region span in bytes: runs the size pass on first call (the result memoizes; an override register...
static size_t mizu_ix_put_task(unsigned char *dst, int target, int kind, uint64_t ident)
The task header: target language byte, kind byte, the reserved u16 flags written zero,...
Definition mizu_ext.h:1976
static size_t mizu_ext_ix_err_floor_impl(const void *s, size_t n, size_t share)
Definition mizu_ext.h:1803
void mizu_death_listener_teardown(void)
Library-unload teardown; joins the Linux epoll thread (no-op elsewhere: macOS dispatch sources and Wi...
int mizu_pool_map_caps(mizu_pool *, uint32_t *free_rs, uint32_t *inj_cap, uint32_t *inline_entry)
A map's batch-sizing inputs: claims the worker's nested-submitter slot when unclaimed (as a first nes...
struct mizu_bytes_s mizu_bytes
A byte buffer.
void mizu_binding_init(mizu_binding *)
Zero and size-stamp a binding struct.
struct mizu_ix_s mizu_ix
The pull cursor.
struct mizu_arrow_warn_s mizu_arrow_warn
The conversion warning counts, accumulated by mizu_cvt_convert and the frame writer; the binding rais...
static int mizu_mizl_check(const void *base, size_t size, int64_t *n, int64_t *attrs_off, int64_t *attrs_size, int64_t valid[2])
Validate the MIZL header at base and its directory's extent against the region: magic,...
Definition mizu_ext.h:1345
int mizu_pool_unwind_sink(mizu_pool *, mizu_result_sink *out)
The unwind path for a binding whose catching = 0 exec abandons (R's longjmp): when the eval marker sa...
mizu_shm * mizu_read_region(mizu_read_ctx *, const uint8_t *name, uint32_t len)
Read-side service, invoked through the read_ctx handed to read_fn: a borrowed consumer mapping for a ...
int mizu_parker_attach(mizu_parker *pk, uint32_t *epoch, const char *region_name, int entity, int create)
region_name/entity name the Windows event ("<region>.pk.<entity>"), created by the region's host (cre...
static void mizu_mizh_validity_set(void *base, int64_t off, int64_t count)
Stamp the validity pair of an MIZH or MIZL header (the one write site): {0, 0} absent,...
Definition mizu_ext.h:1325
struct mizu_parker_s mizu_parker
One parker per waiting entity: a 32-bit monotonic epoch word in the shared region plus,...
mizu_live_probe_e
Exclusive flock (POSIX) / LockFileEx (Windows) held for a process's entire lifetime and released by t...
Definition mizu_ext.h:565
#define MIZU_EXT_LOAD_ACQ(p)
The dual-form inlines touch atomics; spell the acquire load per language (mizu.h's MIZU_ATOMIC gives ...
Definition mizu_ext.h:70
struct mizu_morsel_hdr_s mizu_morsel_hdr
The 128-byte region header.
@ MIZU_IX_ATTR
begin: one value item, then one DICT begin
Definition mizu_ext.h:1442
@ MIZU_IX_CPLX
u64[0..1]: the re / im f64 bits
Definition mizu_ext.h:1434
@ MIZU_IX_BYTES
the 0x05 bytes scalar
Definition mizu_ext.h:1437
@ MIZU_IX_REAL
u64[0]: the f64 bits
Definition mizu_ext.h:1433
@ MIZU_IX_LIST
begin: count value items follow
Definition mizu_ext.h:1440
@ MIZU_IX_STR1
the 0x04 string scalar
Definition mizu_ext.h:1435
@ MIZU_IX_TASK
header: count fields follow as ordinary items
Definition mizu_ext.h:1444
@ MIZU_IX_VEC
0x06-0x0a, 0x0e: type is the MIZU_TYPE_* tag
Definition mizu_ext.h:1438
@ MIZU_IX_LGL
u64[0]: 0, 1, or 2 (NA)
Definition mizu_ext.h:1431
@ MIZU_IX_ERR
the err fields; legal at the top level only
Definition mizu_ext.h:1443
@ MIZU_IX_DICT
begin: count (STR key, value) pairs follow
Definition mizu_ext.h:1441
@ MIZU_IX_REF
the 0x13 region identifier span (ptr, len)
Definition mizu_ext.h:1445
@ MIZU_IX_STR
a bare string (strv element, or dict key: key=1)
Definition mizu_ext.h:1436
@ MIZU_IX_INT
u64[0]: the i64
Definition mizu_ext.h:1432
@ MIZU_IX_STRV
begin: count STR items follow
Definition mizu_ext.h:1439
void mizu_arrow_root_blob(mizu_arrow *, const void *blob, size_t len)
The root-blob override: a complete 'I' stream for the frame attributes the caller built (pymizu's cus...
mizu_status mizu_ixt_want_list(mizu_ix *cur, mizu_ix_item *item)
The next item must be a LIST begin (the positional field).
static uint64_t mizu_na_apply(int type, void *dst, const void *src, const uint8_t *bitmap, uint64_t n)
The bitmap-to-sentinels copy: n elements land at dst, the clear bits' elements written as the wire ty...
Definition mizu_ext.h:1371
const mizu_cvt_row * mizu_cvt_for_arrow(const char *fmt)
The Arrow-format keying of the conversion table (every supported row a single character); NULL when t...
static int mizu_ext_mizl_ent(const void *base, size_t size, int64_t i, mizu_mizl_entry *e)
One MIZL directory entry's checks, shared by mizu_mizl_check's pass and mizu_mizl_elem: alignment and...
Definition mizu_ext.h:1004
static int mizu_ext_na_real_bits(uint64_t bits)
One per-element NA test per NA-capable wire type (anything else is never null): INT32_MIN for LGL and...
Definition mizu_ext.h:941
struct mizu_mizs_geom_s mizu_mizs_geom
The small pure helpers over mizu.h's wire-format conventions, dual form like the zc accessors above (...
#define MIZU_IX_ERR_OVERHEAD
The err framer's budget constants (mizu_ix_write_err below) — the wire authority for the bounded err ...
Definition mizu_ext.h:1521
void mizu_rng_jump(int *seed)
One 2^127-step L'Ecuyer-CMRG stream jump in place over a 6-word state (rng_jump.c; a binding's map de...
static int mizu_ext_mizl_tag_ok(int32_t sexptype)
A directory entry's sexptype: MIZU_MIZL_S4 masked off, the remainder a listed tag — 0 (a serialized l...
Definition mizu_ext.h:916
static int mizu_mizh_check(const void *base, size_t size, int *wire_type, int64_t *n_elems, int64_t valid[2])
Validate the MIZH header at base: region size, magic, a known atomic wire type, the element/attribute...
Definition mizu_ext.h:1317
int mizu_park(mizu_parker *pk, uint32_t snapshot, long timeout_ms)
Sleeps while the epoch still equals snapshot, up to timeout_ms (0 = poll: never sleeps; < 0 = indefin...
uint64_t mizu_channel_peer_ident(const mizu_channel *)
The identity words (the language registry above).
static void mizu_mizh_write(void *base, int wire_type, int64_t n_elems)
The flat MIZH header: magic, type, element count, zero attrs, and the reserved band [24,...
Definition mizu_ext.h:1300
int mizu_arrow_remote(mizu_arrow *, int64_t col, const char *ident, size_t ident_len, void *ref_base, size_t ref_size, int64_t ref_leaf)
A remote-leaf override (pymizu's provenance match): column col crosses as directory tag 33 — the iden...
static int mizu_ext_ix_utf8_valid_impl(const void *s, size_t n)
The byte-shape helpers' bodies (DESIGN.md's byte-shape helper registry): pure byte math over the wire...
Definition mizu_ext.h:1555
int mizu_result_publish(mizu_result_sink *, void *value)
Result publish, valid during exec only.
Definition mizu_ext.h:2044
Definition mizu_ext.h:2028
Definition mizu_ext.h:2016
Definition mizu_ext.h:2220
int u64_verbatim
CVT 'L': the MIZU_CAP_MIZL_U64V verdict (the leaf writes INT64 + the u64 blob attr,...
Definition mizu_ext.h:2224
int str_form
STR / DICT: 1 utf8, 2 large_utf8, 3 view.
Definition mizu_ext.h:2223
int kind
MIZU_ARROW_*.
Definition mizu_ext.h:2221
const mizu_cvt_row * row
CVT.
Definition mizu_ext.h:2222
The conversion warning counts, accumulated by mizu_cvt_convert and the frame writer; the binding rais...
Definition mizu_ext.h:2179
uint64_t n_int64
a genuine int64 INT64_MIN: reads as NA in R
Definition mizu_ext.h:2182
uint64_t n_intmin
a genuine int32 INT32_MIN: reads as NA in R
Definition mizu_ext.h:2181
uint64_t n_range
uint64 past 2^53 -> NA_real_
Definition mizu_ext.h:2180
Definition mizu_ext.h:309
mizu_exec_fn exec
pool workers only; NULL on submitter handles
Definition mizu_ext.h:313
uint64_t ident
MIZU_IDENT word; a zero language byte is rejected at create, attach and join.
Definition mizu_ext.h:319
mizu_check_fn check
interrupt poll; NULL for plain-C consumers
Definition mizu_ext.h:314
mizu_sweep_fn sweep
idle cache drop; usually NULL
Definition mizu_ext.h:316
uint32_t size
sizeof(mizu_binding); set via mizu_binding_init
Definition mizu_ext.h:310
mizu_park_fn park
around-park lock release; usually NULL
Definition mizu_ext.h:315
mizu_drop_fn drop
pin release; NULL when the binding never pins
Definition mizu_ext.h:317
void * ctx
opaque to the core
Definition mizu_ext.h:318
A byte buffer.
Definition mizu_ext.h:450
Definition mizu_ext.h:2169
int cvt
MIZU_CVT_*.
Definition mizu_ext.h:2171
int wire
the MIZU_TYPE_* the row produces
Definition mizu_ext.h:2170
uint8_t w_in
source element bytes (0: bit-packed, MIZU_CVT_BIT_LGL)
Definition mizu_ext.h:2172
Definition mizu_ext.h:1448
uint64_t len
STR1 / STR / REF: the span's byte length.
Definition mizu_ext.h:1454
int key
STR: a dict key (an strv element has 0)
Definition mizu_ext.h:1452
uint32_t task_kind
TASK: the kind byte.
Definition mizu_ext.h:1460
uint32_t kind
MIZU_IX_*.
Definition mizu_ext.h:1449
uint32_t err_flags
ERR: bit 0 = index present.
Definition mizu_ext.h:1461
uint64_t err_index
ERR: valid when err_flags bit 0 is set.
Definition mizu_ext.h:1462
uint32_t target
TASK: the target language byte.
Definition mizu_ext.h:1459
uint32_t type
VEC: the MIZU_TYPE_* wire type.
Definition mizu_ext.h:1450
uint64_t count
BYTES / VEC / STRV / LIST / DICT: the element (pair) count; TASK: the field arity.
Definition mizu_ext.h:1455
const unsigned char * ptr
STR1 / STR / BYTES / VEC / REF: the data span.
Definition mizu_ext.h:1453
uint64_t u64[2]
LGL: u64[0] in {0, 1, 2}; INT / REAL: u64[0]; CPLX: both; TASK: u64[0] = submitter identity.
Definition mizu_ext.h:1457
int na
STR1 / STR: the -1 (NA) form.
Definition mizu_ext.h:1451
The pull cursor.
Definition mizu_ext.h:1470
int done
the root value completed
Definition mizu_ext.h:1474
uint64_t remaining
items owned at this level
Definition mizu_ext.h:1478
int err
latched: all later calls fail
Definition mizu_ext.h:1475
uint32_t kind
the MIZU_IX_* begin kind
Definition mizu_ext.h:1477
One MIZL directory entry plus its validity-table pair (mizu.h documents the 32-byte entry): mizu_mizl...
Definition mizu_ext.h:869
int64_t data_offset
64-byte aligned
Definition mizu_ext.h:870
int64_t valid[2]
{0, 0} absent, {0, -1} known-NA-free, else {bitmap offset, null count}
Definition mizu_ext.h:875
The small pure helpers over mizu.h's wire-format conventions, dual form like the zc accessors above (...
Definition mizu_ext.h:859
The 128-byte region header.
Definition mizu_ext.h:675
uint32_t out_type
template element wire type; 0 = no output
Definition mizu_ext.h:681
uint32_t version
MIZU_ABI_VERSION.
Definition mizu_ext.h:677
uint32_t claim_n
CLAIM word count (runner ordinal bound)
Definition mizu_ext.h:683
uint32_t out_elt
template element size, bytes
Definition mizu_ext.h:682
uint32_t magic
MIZU_MORSEL_MAGIC.
Definition mizu_ext.h:676
uint64_t state_off
morsel state section offset
Definition mizu_ext.h:691
uint64_t morsel_size
elements per morsel
Definition mizu_ext.h:689
uint64_t out_m
template length: values per element
Definition mizu_ext.h:688
uint32_t x_type
raw x section wire type (MIZU_TYPE_*)
Definition mizu_ext.h:680
uint32_t x_kind
MIZU_MORSEL_X_*.
Definition mizu_ext.h:679
uint64_t n
map elements
Definition mizu_ext.h:684
uint64_t n_morsels
ceiling(n / morsel_size)
Definition mizu_ext.h:690
uint32_t flags
reserved, 0
Definition mizu_ext.h:678
Batch-sizing state: process-private, never wire state, reset at each run's first-call CLAIM CAS.
Definition mizu_ext.h:719
uint64_t k_last
morsels issued last transition
Definition mizu_ext.h:723
double cost
est.
Definition mizu_ext.h:725
uint64_t k
current batch size, morsels
Definition mizu_ext.h:722
int32_t run_r
ordinal whose ramp this is (-1 = none)
Definition mizu_ext.h:720
int skip
last interval contained a help: no update
Definition mizu_ext.h:726
double t_last
mizu_now() at the last issue
Definition mizu_ext.h:724
Worker-death lost set: issued = [0, bound), lost = issued minus the union of the collected batch hist...
Definition mizu_ext.h:788
One parker per waiting entity: a 32-bit monotonic epoch word in the shared region plus,...
Definition mizu_ext.h:497
uint32_t * epoch
in the shared region
Definition mizu_ext.h:498
The opaque pool-signal trio a map runner loads relaxed once per batch transition: the help_wanted doo...
Definition mizu_ext.h:597
Definition mizu_ext.h:284
uint32_t flags
binding-set MIZU_READ_*; zero on entry
Definition mizu_ext.h:294
void * binding_ctx
the handle's binding.ctx
Definition mizu_ext.h:293
int32_t gone
set by mizu_read_region on a vanished region; read_fn propagates by returning NULL
Definition mizu_ext.h:288
int32_t died_slot
MIZU_RS_DIED: the claimant worker slot (-1)
Definition mizu_ext.h:290
int64_t died_pid
MIZU_RS_DIED: its pid (0 when unknown)
Definition mizu_ext.h:291
mizu_handle * handle
the reading handle
Definition mizu_ext.h:292
uint32_t size
core-set: sizeof the struct it knows
Definition mizu_ext.h:285
void * reserved[4]
zero; future growth without a soname bump
Definition mizu_ext.h:295
int32_t outcome
pool: mizu_rs_status of the result (channel: MIZU_RS_OK)
Definition mizu_ext.h:286
The result-sink struct: the core fills it from a claimed entry and hands it to exec_fn; the binding p...
Definition mizu_ext.h:798
unsigned char * payload
rs + sizeof(mizu_rs_hdr): the frame buffer
Definition mizu_ext.h:801
uint64_t seq
rs->sequence at claim
Definition mizu_ext.h:805
uint32_t inline_max
the slot's payload capacity
Definition mizu_ext.h:803
uint16_t sub_slot
the task's submitter (zc keying, probes)
Definition mizu_ext.h:804
Result slot header; the payload framing header sits at offset 24 and payload bytes at 40.
Definition mizu.h:450
The public opaque type in mizu.h; defined here for bindings (the core's control-region mappings embed...
Definition mizu_ext.h:475
unsigned int pid
creator PID: fork guard (POSIX only)
Definition mizu_ext.h:480
uint32_t kind
mizu_kind
Definition mizu.h:262
A task handle: an 8-byte value identifying one result slot at one sequence — 40-bit sequence in the l...
Definition mizu.h:717