61#if defined(__GNUC__) || defined(__clang__)
62# define MIZU_EXT_INLINE static inline __attribute__((unused))
64# define MIZU_EXT_INLINE static inline
70# define MIZU_EXT_LOAD_ACQ(p) \
71 std::atomic_load_explicit((p), std::memory_order_acquire)
73# define MIZU_EXT_LOAD_ACQ(p) \
74 atomic_load_explicit((p), memory_order_acquire)
80# define MIZU_PREFIX_LITERAL "Local\\mizu_"
82# define MIZU_PREFIX_LITERAL "/mizu_"
85#define MIZU_ALIGN64(x) (((x) + 63) & ~(size_t) 63)
92#define MIZU_ZC_FLOOR ((size_t) 32768)
93#define MIZU_ZC_FLOOR_RAW ((size_t) (256 << 10))
97#define MIZU_OPEN_CACHE_MAX 16
104#define MIZU_CODEC_MAGIC 0x52u
105#define MIZU_PYMIZU_CODEC_MAGIC 0x50u
106#define MIZU_INTEROP_MAGIC 0x49u
119#define MIZU_LANG_NONE 0u
120#define MIZU_LANG_BYTES 1u
121#define MIZU_LANG_R 2u
122#define MIZU_LANG_PYTHON 3u
133#define MIZU_CAP_MIZS (1u << 0)
134#define MIZU_CAP_ATTRS (1u << 1)
136#define MIZU_CAP_MIZL (1u << 2)
137#define MIZU_CAP_TASKREF (1u << 3)
140#define MIZU_CAP_MIZL_REF (1u << 4)
142#define MIZU_CAP_MIZL_TSN (1u << 5)
144#define MIZU_CAP_MIZL_U64V (1u << 6)
146#define MIZU_CAP_LABELED (1u << 7)
150#define MIZU_CAP_ORDERED (1u << 8)
159#define MIZU_IDENT(lang, caps) \
160 ((uint64_t) (uint8_t) (lang) | ((uint64_t) (uint32_t) (caps) << 32))
174enum { MIZU_HTYPE_CHANNEL = 1, MIZU_HTYPE_POOL = 2 };
193 uint32_t *fl_entries,
194 uint32_t *ledger_entries);
312#define MIZU_READ_CONSUME 1u
328typedef void *(*mizu_read_fn)(
const mizu_slot_hdr *,
const uint8_t *payload,
329 size_t limit, mizu_read_ctx *);
331typedef int (*mizu_exec_fn)(
const mizu_slot_hdr *hdr,
const uint8_t *payload,
334typedef int (*mizu_check_fn)(
void *ctx);
335typedef void (*mizu_park_fn)(
void *ctx,
int entering);
336typedef void (*mizu_sweep_fn)(
void *ctx);
337typedef void (*mizu_drop_fn)(
void *ctx,
void *pin);
359#define MIZU_BINDING_SPLIT_WAITER 1u
360#define MIZU_BINDING_FLAGS_ALL MIZU_BINDING_SPLIT_WAITER
375MIZU_API uint64_t mizu_pool_worker_ident(
const mizu_pool *);
429 mizu_slot_hdr *, uint8_t *payload,
430 uint32_t inline_max);
431#ifdef MIZU_EXT_NO_INLINES
433 mizu_slot_hdr *, uint8_t *payload,
434 uint32_t inline_max);
437 mizu_slot_hdr *hdr, uint8_t *payload,
438 uint32_t inline_max) {
439 if (n <= (uint64_t) inline_max) {
440 hdr->
kind = MIZU_KIND_RAWVEC;
441 hdr->len = (uint32_t) n;
442 hdr->aux = (uint64_t) (uint32_t) wire_type;
548typedef enum mizu_park_result_e { MIZU_PARK_WOKEN = 0, MIZU_PARK_TIMEOUT,
549 MIZU_PARK_INTR } mizu_park_result;
555 const char *region_name,
int entity,
574#ifdef MIZU_EXT_NO_INLINES
667 void (*cb)(
void *),
void *ctx);
679 void (*cb)(
void *),
void *ctx);
725MIZU_API int mizu_live_open(
const char *path, intptr_t *out);
726MIZU_API int mizu_live_try(intptr_t h);
727MIZU_API void mizu_live_close(intptr_t h);
736MIZU_API const char *mizu_preamble_validate(
const void *region,
761MIZU_API int mizu_pool_deque_pull(mizu_pool *, uint32_t n);
769 uint32_t *inj_cap, uint32_t *inline_entry);
807#define MIZU_MORSEL_CANCEL_OFF ((uint64_t) 0)
808#define MIZU_MORSEL_GEN_OFF ((uint64_t) 4)
809#define MIZU_MORSEL_CURSOR_OFF ((uint64_t) 64)
810#define MIZU_MORSEL_CLAIM_OFF ((uint64_t) 128)
813#define MIZU_MORSEL_GEN_MASK ((uint32_t) 0x3FFFFFFF)
815enum { MIZU_MORSEL_IDLE = 0, MIZU_MORSEL_RUNNING, MIZU_MORSEL_ABANDONED };
816enum { MIZU_MORSEL_X_DESC = 0, MIZU_MORSEL_X_RAW };
822#define MIZU_MORSEL_T_TARGET 200e-6
823#define MIZU_MORSEL_BATCH_CAP 64
830#define MIZU_MORSEL_MAGIC 0x4D495A4Du
845 uint64_t desc_off, desc_len;
846 uint64_t x_off, x_len;
855 "mizu_morsel_hdr is the wire format");
865 uint64_t n, uint64_t morsel_size,
866 uint64_t desc_len, uint32_t x_type,
867 uint64_t x_len, uint32_t out_type,
868 uint64_t out_m, uint32_t claim_n);
904 double now, uint64_t *m_out, uint64_t *k_out,
922 uint32_t r, uint32_t gen);
933MIZU_API uint64_t mizu_morsel_cursor(
const void *base,
941 uint64_t k, uint64_t *lo, uint64_t *hi);
992#ifdef MIZU_EXT_NO_INLINES
997 return (
MIZU_ATOMIC(uint32_t) *) ((
unsigned char *) base +
1001 return (
MIZU_ATOMIC(uint32_t) *) ((
unsigned char *) base +
1044#ifdef MIZU_EXT_NO_INLINES
1050 g.offsets = (int64_t) MIZU_ALIGN64((uint64_t) (n + 7) / 8);
1051 g.encoding = g.offsets + (int64_t) MIZU_ALIGN64(8 * ((uint64_t) n + 1));
1052 g.data = g.encoding + (int64_t) MIZU_ALIGN64((uint64_t) n);
1061 return (flags & ~MIZU_HDR_FLAG_S4) == 0;
1068 uint64_t n,
size_t size) {
1069 if (off == 0)
return count == 0 || count == -1;
1070 if (count < 0 || (uint64_t) count > n || (off & 63) != 0)
return 0;
1071 const uint64_t bytes = (n + 7) / 8;
1072 return (uint64_t) off <= (uint64_t) size &&
1073 bytes <= (uint64_t) size - (uint64_t) off;
1105 return ((bits >> 52) & 0x7FF) == 0x7FF && (uint32_t) bits == 0x7A2u;
1107MIZU_EXT_INLINE int mizu_ext_na_at(
int type,
const void *src, uint64_t i) {
1108 const unsigned char *p = (
const unsigned char *) src;
1109 uint64_t bits, re, im;
1115 memcpy(&v32, p + 4 * i, 4);
1118 memcpy(&bits, p + 8 * i, 8);
1121 memcpy(&re, p + 16 * i, 8);
1122 memcpy(&im, p + 16 * i + 8, 8);
1125 memcpy(&v64, p + 8 * i, 8);
1135 unsigned char *p = (
unsigned char *) dst;
1142 memcpy(p + 4 * i, &na32, 4);
1145 memcpy(p + 8 * i, &nabits, 8);
1148 memcpy(p + 16 * i, &nabits, 8);
1149 memcpy(p + 16 * i + 8, &nabits, 8);
1152 memcpy(p + 8 * i, &na64, 8);
1169 const unsigned char *dir = (
const unsigned char *) base +
1170 MIZU_HEADER_SIZE + 32 * (
size_t) i;
1172 memcpy(&e->data_size, dir + 8, 8);
1173 memcpy(&e->sexptype, dir + 16, 4);
1174 memcpy(&e->attrs_size, dir + 20, 4);
1175 memcpy(&e->length, dir + 24, 8);
1179 (uint64_t) e->data_size >
1184 const int32_t tag = e->sexptype & ~(int32_t)
MIZU_MIZL_S4;
1186 if ((e->sexptype & (int32_t)
MIZU_MIZL_S4) != 0 || e->length < 0 ||
1187 e->data_size < 1 || e->data_size > 255)
1191 if ((int64_t) e->attrs_size > e->data_size)
return -1;
1192 const int64_t body = e->data_size - (int64_t) e->attrs_size;
1195 if (e->length < 0 || e->length > body / (int64_t) elt)
return -1;
1197 if (e->length < 0 || e->length > ((int64_t) 1 << 50) ||
1201 if (e->length < 0)
return -1;
1211 int *wire_type, int64_t *n_elems,
1213 if (size < MIZU_HEADER_SIZE)
return -1;
1216 int64_t len, attrs, voff, vcount;
1217 memcpy(&magic, base, 4);
1219 memcpy(&t32, (
const unsigned char *) base + 4, 4);
1220 memcpy(&len, (
const unsigned char *) base + 8, 8);
1221 memcpy(&attrs, (
const unsigned char *) base + 16, 8);
1223 memcpy(&vcount, (
const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1225 if (elt == 0 || len < 0 || attrs < 0 ||
1226 len > ((int64_t) size - (int64_t) MIZU_HEADER_SIZE) / (int64_t) elt ||
1227 attrs > (int64_t) size - (int64_t) MIZU_HEADER_SIZE -
1228 len * (int64_t) elt)
1240MIZU_EXT_INLINE int mizu_ext_mizs_check_impl(
const void *base,
size_t size,
1241 int64_t *n, int64_t *str_size,
1242 int64_t *attrs_size) {
1243 if (size < MIZU_HEADER_SIZE)
return -1;
1246 int64_t count, block;
1247 memcpy(&magic, base, 4);
1249 memcpy(&attrs, (
const unsigned char *) base + 4, 4);
1250 memcpy(&count, (
const unsigned char *) base + 8, 8);
1251 memcpy(&block, (
const unsigned char *) base + 16, 8);
1252 if (attrs < 0 || count < 0 || count > ((int64_t) 1 << 50) || block < 0)
1256 if (fixed > block ||
1257 block > (int64_t) size - (int64_t) MIZU_HEADER_SIZE ||
1259 (int64_t) size - (int64_t) MIZU_HEADER_SIZE - block)
1263 *attrs_size = attrs;
1267MIZU_EXT_INLINE int mizu_ext_mizl_check_impl(
const void *base,
size_t size,
1268 int64_t *n, int64_t *attrs_off,
1269 int64_t *attrs_size,
1271 if (size < MIZU_HEADER_SIZE)
return -1;
1274 int64_t aoff, asz, voff, vcount;
1275 memcpy(&magic, base, 4);
1277 memcpy(&n32, (
const unsigned char *) base + 4, 4);
1278 memcpy(&aoff, (
const unsigned char *) base + 8, 8);
1279 memcpy(&asz, (
const unsigned char *) base + 16, 8);
1281 memcpy(&vcount, (
const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1283 (uint64_t) (uint32_t) n32 >
1284 ((uint64_t) size - (uint64_t) MIZU_HEADER_SIZE) / 32)
1286 if (aoff < 0 || asz < 0 ||
1287 (uint64_t) aoff > (uint64_t) size ||
1288 (uint64_t) asz > (uint64_t) size - (uint64_t) aoff)
1292 for (int64_t i = 0; i < (int64_t) n32; i++) {
1295 const int32_t tag = e.sexptype & ~(int32_t)
MIZU_MIZL_S4;
1300 const uint64_t len = (uint64_t) e.length;
1301 sum = len > (uint64_t) INT64_MAX - sum ? (uint64_t) INT64_MAX
1306 if (vcount != 0 && vcount != -1)
return -1;
1308 const uint64_t bytes = (uint64_t) (uint32_t) n32 * 16;
1309 if (vcount < 0 || (uint64_t) vcount > sum || (voff & 63) != 0 ||
1310 (uint64_t) voff > (uint64_t) size ||
1311 bytes > (uint64_t) size - (uint64_t) voff)
1322MIZU_EXT_INLINE int mizu_ext_mizl_elem_impl(
const void *base,
size_t size,
1325 if (size < MIZU_HEADER_SIZE)
return -1;
1328 int64_t voff, vcount;
1329 memcpy(&magic, base, 4);
1331 memcpy(&n32, (
const unsigned char *) base + 4, 4);
1332 if (n32 < 0 || i < 0 || i >= (int64_t) n32 ||
1333 (uint64_t) (uint32_t) n32 >
1334 ((uint64_t) size - (uint64_t) MIZU_HEADER_SIZE) / 32)
1339 memcpy(&vcount, (
const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1341 if (vcount != 0 && vcount != -1)
return -1;
1343 elem->
valid[1] = vcount;
1346 if ((voff & 63) != 0)
return -1;
1347 const uint64_t bytes = (uint64_t) (uint32_t) n32 * 16;
1348 if ((uint64_t) voff > (uint64_t) size ||
1349 bytes > (uint64_t) size - (uint64_t) voff)
1351 const unsigned char *tab = (
const unsigned char *) base + voff;
1352 int64_t loff, lcount;
1353 memcpy(&loff, tab + 16 * (
size_t) i, 8);
1354 memcpy(&lcount, tab + 16 * (
size_t) i + 8, 8);
1360 const int32_t ltag = elem->sexptype & ~(int32_t)
MIZU_MIZL_S4;
1365 elem->
valid[0] = loff;
1366 elem->
valid[1] = lcount;
1370MIZU_EXT_INLINE uint64_t mizu_ext_na_build_impl(
int type, uint8_t *bitmap,
1371 const void *src, uint64_t n,
1374 for (uint64_t i = 0; i < n; i++) {
1375 const uint64_t bit = bit_off + i;
1376 if (mizu_ext_na_at(type, src, i)) {
1377 bitmap[bit >> 3] &= (uint8_t) ~(1u << (bit & 7));
1380 bitmap[bit >> 3] |= (uint8_t) (1u << (bit & 7));
1388 const uint8_t *bitmap,
1391 if (elt == 0)
return 0;
1392 if (dst != src) memcpy(dst, src, (
size_t) n * elt);
1394 for (uint64_t i = 0; i < n; i++) {
1395 if (((bitmap[i >> 3] >> (i & 7)) & 1) == 0) {
1406 if (!isfinite(seconds))
return -1;
1407 if (seconds <= 0)
return 0;
1408 const double ms = seconds * 1000;
1409 return isfinite(ms) ? ms : -1;
1412#ifdef MIZU_EXT_NO_INLINES
1414MIZU_API void mizu_store_na_real(
void *dst);
1418MIZU_API uint64_t mizu_aux_hi(uint64_t aux);
1421 int *wire_type, int64_t *n_elems, int64_t valid[2]);
1425 int64_t *str_size, int64_t *attrs_size);
1427 int64_t *attrs_off, int64_t *attrs_size,
1432 uint64_t n, uint64_t bit_off);
1434 const uint8_t *bitmap, uint64_t n);
1442 return mizu_ext_timeout_ms_impl(seconds);
1446 memcpy(dst, &bits, 8);
1450 return (uint64_t) (uint32_t) type | ((uint64_t) name_len << 8);
1454 return (uint64_t) (uint32_t) type | (total << 8);
1460 return (
int) (aux & 0xff);
1472 const int32_t t32 = wire_type;
1473 const int64_t zero64 = 0;
1474 memcpy(base, &magic, 4);
1475 memcpy((
unsigned char *) base + 4, &t32, 4);
1476 memcpy((
unsigned char *) base + 8, &n_elems, 8);
1477 memcpy((
unsigned char *) base + 16, &zero64, 8);
1488 int *wire_type, int64_t *n_elems,
1498 memcpy((
unsigned char *) base + MIZU_HDR_VALID_COUNT, &count, 8);
1506 int64_t *n, int64_t *str_size,
1507 int64_t *attrs_size) {
1508 return mizu_ext_mizs_check_impl(base, size, n, str_size, attrs_size);
1516 int64_t *n, int64_t *attrs_off,
1517 int64_t *attrs_size, int64_t valid[2]) {
1518 return mizu_ext_mizl_check_impl(base, size, n, attrs_off, attrs_size,
1527 return mizu_ext_mizl_elem_impl(base, size, i, elem);
1534 const void *src, uint64_t n,
1536 return mizu_ext_na_build_impl(type, bitmap, src, n, bit_off);
1542 const uint8_t *bitmap, uint64_t n) {
1543 return mizu_ext_na_apply_impl(type, dst, src, bitmap, n);
1562#define MIZU_IX_VERSION 0x01u
1563#define MIZU_IX_DEPTH_MAX 64
1567 MIZU_IX_TAG_NIL = 0x00,
1568 MIZU_IX_TAG_LGL1 = 0x01,
1569 MIZU_IX_TAG_INT = 0x02,
1570 MIZU_IX_TAG_REAL = 0x03,
1571 MIZU_IX_TAG_STR = 0x04,
1572 MIZU_IX_TAG_BYTES = 0x05,
1573 MIZU_IX_TAG_LGLV = 0x06,
1574 MIZU_IX_TAG_INTV = 0x07,
1575 MIZU_IX_TAG_REALV = 0x08,
1576 MIZU_IX_TAG_CPLXV = 0x09,
1577 MIZU_IX_TAG_RAWV = 0x0a,
1578 MIZU_IX_TAG_STRV = 0x0b,
1579 MIZU_IX_TAG_LIST = 0x0c,
1580 MIZU_IX_TAG_DICT = 0x0d,
1581 MIZU_IX_TAG_I64V = 0x0e,
1582 MIZU_IX_TAG_ATTR = 0x0f,
1583 MIZU_IX_TAG_CPLX = 0x10,
1584 MIZU_IX_TAG_ERR = 0x11,
1585 MIZU_IX_TAG_TASK = 0x12,
1586 MIZU_IX_TAG_REF = 0x13
1633 struct {
const unsigned char *
ptr; uint64_t
len; } err_str[3];
1643 const unsigned char *p;
1644 const unsigned char *end;
1651 } stack[MIZU_IX_DEPTH_MAX + 1];
1688 size_t len, mizu_ix_item *item,
1701#define MIZU_IX_ERR_OVERHEAD 25u
1702#define MIZU_IX_ERR_TYPE_SHARE 128u
1709#define MIZU_IX_ATTR_NAMES "names"
1710#define MIZU_IX_ATTR_LEVELS "levels"
1711#define MIZU_IX_ATTR_DIM "dim"
1712#define MIZU_IX_ATTR_DIMNAMES "dimnames"
1713#define MIZU_IX_ATTR_CLASS "class"
1714#define MIZU_IX_ATTR_UNITS "units"
1715#define MIZU_IX_ATTR_ROWNAMES "row.names"
1716#define MIZU_IX_ATTR_TZONE "tzone"
1717#define MIZU_IX_ATTR_TSCALE "tscale"
1718#define MIZU_IX_ATTR_U64 "u64"
1719#define MIZU_IX_ATTR_TSP "tsp"
1721#define MIZU_IX_CLASS_FACTOR "factor"
1722#define MIZU_IX_CLASS_ORDERED "ordered"
1723#define MIZU_IX_CLASS_DATE "Date"
1724#define MIZU_IX_CLASS_POSIXCT "POSIXct"
1725#define MIZU_IX_CLASS_POSIXT "POSIXt"
1726#define MIZU_IX_CLASS_DIFFTIME "difftime"
1727#define MIZU_IX_CLASS_DATAFRAME "data.frame"
1728#define MIZU_IX_CLASS_TABLE "table"
1730#define MIZU_IX_UNIT_SECS "secs"
1731#define MIZU_IX_UNIT_MINS "mins"
1732#define MIZU_IX_UNIT_HOURS "hours"
1733#define MIZU_IX_UNIT_DAYS "days"
1734#define MIZU_IX_UNIT_WEEKS "weeks"
1742 const unsigned char *b = (
const unsigned char *) s;
1745 const unsigned char c = b[i];
1748 }
else if (c < 0xC2 || c >= 0xF5) {
1751 }
else if (c < 0xE0) {
1752 if (i + 2 > n || (b[i + 1] & 0xC0) != 0x80)
return 0;
1754 }
else if (c < 0xF0) {
1755 if (i + 3 > n || (b[i + 1] & 0xC0) != 0x80 ||
1756 (b[i + 2] & 0xC0) != 0x80)
return 0;
1757 if (c == 0xE0 && b[i + 1] < 0xA0)
return 0;
1758 if (c == 0xED && b[i + 1] >= 0xA0)
return 0;
1761 if (i + 4 > n || (b[i + 1] & 0xC0) != 0x80 ||
1762 (b[i + 2] & 0xC0) != 0x80 || (b[i + 3] & 0xC0) != 0x80)
1764 if (c == 0xF0 && b[i + 1] < 0x90)
return 0;
1765 if (c == 0xF4 && b[i + 1] > 0x8F)
return 0;
1775 switch (wire_type) {
1782 default:
return MIZU_IX_TAG_NIL;
1788 static const char *
const reserved[] = {
1790 MIZU_IX_ATTR_DIMNAMES, MIZU_IX_ATTR_CLASS, MIZU_IX_ATTR_UNITS,
1791 MIZU_IX_ATTR_ROWNAMES, MIZU_IX_ATTR_TZONE, MIZU_IX_ATTR_TSCALE,
1792 MIZU_IX_ATTR_U64, MIZU_IX_ATTR_TSP
1794 for (
size_t i = 0; i <
sizeof reserved /
sizeof reserved[0]; i++)
1795 if (strlen(reserved[i]) == len && memcmp(key, reserved[i], len) == 0)
1813 uint32_t tag, uint64_t v) {
1816 dst[0] = (
unsigned char) tag;
1817 memcpy(dst + 1, &v, 8);
1823 if (dst != NULL) dst[0] = MIZU_IX_TAG_NIL;
1830 dst[0] = MIZU_IX_TAG_LGL1;
1831 dst[1] = (
unsigned char) value;
1839 dst[0] = MIZU_IX_TAG_INT;
1840 memcpy(dst + 1, &value, 8);
1848 dst[0] = MIZU_IX_TAG_REAL;
1849 memcpy(dst + 1, &value, 8);
1855 double re,
double im) {
1857 dst[0] = MIZU_IX_TAG_CPLX;
1858 memcpy(dst + 1, &re, 8);
1859 memcpy(dst + 9, &im, 8);
1865 const void *s, int32_t len) {
1867 dst[0] = MIZU_IX_TAG_STR;
1868 memcpy(dst + 1, &len, 4);
1869 if (len > 0) memcpy(dst + 5, s, (
size_t) len);
1871 return (
size_t) 5 + (len > 0 ? (size_t) len : 0);
1878 dst[0] = MIZU_IX_TAG_BYTES;
1879 memcpy(dst + 1, &count, 8);
1880 if (count != 0) memcpy(dst + 9, data, (
size_t) count);
1882 return (
size_t) 9 + (size_t) count;
1890 if (tag == MIZU_IX_TAG_NIL)
return 0;
1893 dst[0] = (
unsigned char) tag;
1894 memcpy(dst + 1, &count, 8);
1895 if (count != 0) memcpy(dst + 9, data, (
size_t) count * elt);
1897 return (
size_t) 9 + (size_t) count * elt;
1900MIZU_EXT_INLINE size_t mizu_ext_ix_put_strv_begin_impl(
unsigned char *dst,
1909 memcpy(dst, &len, 4);
1910 if (len > 0) memcpy(dst + 4, s, (
size_t) len);
1912 return (
size_t) 4 + (len > 0 ? (size_t) len : 0);
1915MIZU_EXT_INLINE size_t mizu_ext_ix_put_list_begin_impl(
unsigned char *dst,
1920MIZU_EXT_INLINE size_t mizu_ext_ix_put_dict_begin_impl(
unsigned char *dst,
1926 const void *s, uint32_t len) {
1928 memcpy(dst, &len, 4);
1929 if (len != 0) memcpy(dst + 4, s, (
size_t) len);
1931 return (
size_t) 4 + (size_t) len;
1935 if (dst != NULL) dst[0] = MIZU_IX_TAG_ATTR;
1940 int has_index, uint64_t index,
1943 const void *message,
1944 uint32_t message_len,
1946 uint32_t detail_len) {
1948 const uint16_t flags = (uint16_t) (has_index != 0);
1949 dst[0] = MIZU_IX_TAG_ERR;
1950 memcpy(dst + 1, &flags, 2);
1953 memcpy(dst + off, &index, 8);
1956 const void *strs[3] = { type, message, detail };
1957 const uint32_t lens[3] = { type_len, message_len, detail_len };
1958 for (
int i = 0; i < 3; i++) {
1959 memcpy(dst + off, &lens[i], 4);
1962 memcpy(dst + off, strs[i], (
size_t) lens[i]);
1963 off += (size_t) lens[i];
1968 return (
size_t) 3 + (has_index ? 8 : 0) +
1969 (
size_t) 12 + (size_t) type_len + (
size_t) message_len +
1970 (size_t) detail_len;
1974 int target,
int kind,
1977 const uint16_t zero = 0;
1978 dst[0] = MIZU_IX_TAG_TASK;
1979 dst[1] = (
unsigned char) target;
1980 dst[2] = (
unsigned char) kind;
1981 memcpy(dst + 3, &zero, 2);
1982 memcpy(dst + 5, &ident, 8);
1989 uint32_t name_len) {
1992 if (name_len == 0 || name_len > 255)
return 0;
1994 dst[0] = MIZU_IX_TAG_REF;
1995 dst[1] = (
unsigned char) name_len;
1996 memcpy(dst + 2, name, (
size_t) name_len);
1998 return (
size_t) 2 + name_len;
2005 if (n <= share)
return n;
2006 const unsigned char *b = (
const unsigned char *) s;
2008 while (len > 0 && (b[len] & 0xC0) == 0x80) len--;
2013 unsigned char *dst, uint32_t inline_max,
2014 const void *type,
size_t type_n,
2015 const void *msg,
size_t msg_n,
2016 const void *detail,
size_t detail_n,
2017 int has_index, uint64_t index) {
2023 const size_t budget = inline_max;
2024 const size_t avail =
2027 avail < MIZU_IX_ERR_TYPE_SHARE ? avail : MIZU_IX_ERR_TYPE_SHARE;
2030 if (cap > avail - tn) cap = avail - tn;
2035 n += mizu_ext_ix_put_err_impl(dst != NULL ? dst + n : NULL, has_index,
2036 index, type, (uint32_t) tn, msg,
2037 (uint32_t) mn, detail, (uint32_t) dn);
2041#ifdef MIZU_EXT_NO_INLINES
2045MIZU_API size_t mizu_ix_put_header(
unsigned char *dst);
2046MIZU_API size_t mizu_ix_put_nil(
unsigned char *dst);
2048MIZU_API size_t mizu_ix_put_int(
unsigned char *dst, int64_t value);
2050MIZU_API size_t mizu_ix_put_cplx(
unsigned char *dst,
double re,
double im);
2053MIZU_API size_t mizu_ix_put_bytes(
unsigned char *dst,
const void *data,
2056 const void *data, uint64_t count);
2057MIZU_API size_t mizu_ix_put_strv_begin(
unsigned char *dst, uint64_t count);
2060MIZU_API size_t mizu_ix_put_list_begin(
unsigned char *dst, uint64_t count);
2061MIZU_API size_t mizu_ix_put_dict_begin(
unsigned char *dst, uint64_t count);
2064MIZU_API size_t mizu_ix_put_attr(
unsigned char *dst);
2065MIZU_API size_t mizu_ix_put_err(
unsigned char *dst,
int has_index,
2067 const void *type, uint32_t type_len,
2068 const void *message, uint32_t message_len,
2069 const void *detail, uint32_t detail_len);
2075 const void *type,
size_t type_n,
2076 const void *msg,
size_t msg_n,
2077 const void *detail,
size_t detail_n,
2078 int has_index, uint64_t index);
2106 return mizu_ext_ix_attr_reserved_impl(key, len);
2112 return mizu_ext_ix_put_nil_impl(dst);
2116 return mizu_ext_ix_put_lgl_impl(dst, value);
2118MIZU_EXT_INLINE size_t mizu_ix_put_int(
unsigned char *dst, int64_t value) {
2119 return mizu_ext_ix_put_int_impl(dst, value);
2124 return mizu_ext_ix_put_real_impl(dst, value);
2128 return mizu_ext_ix_put_cplx_impl(dst, re, im);
2133 return mizu_ext_ix_put_str_impl(dst, s, len);
2136 const void *data, uint64_t count) {
2137 return mizu_ext_ix_put_bytes_impl(dst, data, count);
2143 const void *data, uint64_t count) {
2144 return mizu_ext_ix_put_vec_impl(dst, wire_type, data, count);
2148 return mizu_ext_ix_put_strv_begin_impl(dst, count);
2153 return mizu_ext_ix_put_strelt_impl(dst, s, len);
2157 return mizu_ext_ix_put_list_begin_impl(dst, count);
2161 return mizu_ext_ix_put_dict_begin_impl(dst, count);
2166 return mizu_ext_ix_put_key_impl(dst, s, len);
2169 return mizu_ext_ix_put_attr_impl(dst);
2171MIZU_EXT_INLINE size_t mizu_ix_put_err(
unsigned char *dst,
int has_index,
2173 const void *type, uint32_t type_len,
2174 const void *message,
2175 uint32_t message_len,
2177 uint32_t detail_len) {
2178 return mizu_ext_ix_put_err_impl(dst, has_index, index, type, type_len,
2179 message, message_len, detail, detail_len);
2184 int kind, uint64_t ident) {
2185 return mizu_ext_ix_put_task_impl(dst, target, kind, ident);
2189 uint32_t name_len) {
2201 uint32_t inline_max,
2202 const void *type,
size_t type_n,
2203 const void *msg,
size_t msg_n,
2204 const void *detail,
size_t detail_n,
2205 int has_index, uint64_t index) {
2207 msg_n, detail, detail_n, has_index,
2221#ifndef ARROW_C_DATA_INTERFACE
2222#define ARROW_C_DATA_INTERFACE
2226 const char *metadata;
2241 const void **buffers;
2249#ifndef ARROW_C_STREAM_INTERFACE
2250#define ARROW_C_STREAM_INTERFACE
2265 if (arr->null_count == 0 || arr->buffers[0] == NULL)
return 1;
2266 int64_t i = arr->offset + k;
2267 const uint8_t *bm = (
const uint8_t *) arr->buffers[0];
2268 return (bm[i >> 3] >> (i & 7)) & 1;
2272 int64_t k,
int form,
2273 const uint8_t **ptr,
2275 if (!mizu_ext_arrow_valid_impl(arr, k))
return 0;
2276 int64_t i = arr->offset + k;
2278 const uint8_t *offs = (
const uint8_t *) arr->buffers[1];
2280 memcpy(&o0, offs + 4 * i, 4);
2281 memcpy(&o1, offs + 4 * (i + 1), 4);
2282 if (o0 < 0 || o1 < o0)
return -1;
2283 *ptr = (
const uint8_t *) arr->buffers[2] + o0;
2285 }
else if (form == 2) {
2286 const uint8_t *offs = (
const uint8_t *) arr->buffers[1];
2288 memcpy(&o0, offs + 8 * i, 8);
2289 memcpy(&o1, offs + 8 * (i + 1), 8);
2290 if (o0 < 0 || o1 < o0 || o1 - o0 > INT32_MAX)
2292 *ptr = (
const uint8_t *) arr->buffers[2] + o0;
2293 *len = (int32_t) (o1 - o0);
2295 const uint8_t *vw = (
const uint8_t *) arr->buffers[1] + i * 16;
2298 if (l < 0)
return -1;
2303 memcpy(&bi, vw + 8, 4);
2304 memcpy(&off, vw + 12, 4);
2312 if (bi < 0 || off < 0 || 2 + (int64_t) bi >= arr->n_buffers)
2314 if (2 + bi < arr->n_buffers - 1) {
2315 const uint8_t *sizes =
2316 (
const uint8_t *) arr->buffers[arr->n_buffers - 1];
2317 if (sizes != NULL) {
2319 memcpy(&sz, sizes + 8 * (ptrdiff_t) bi, 8);
2320 if ((int64_t) off + l > sz)
return -1;
2323 *ptr = (
const uint8_t *) arr->buffers[2 + bi] + off;
2330#ifdef MIZU_EXT_NO_INLINES
2333 const uint8_t **ptr, int32_t *len);
2337 return mizu_ext_arrow_valid_impl(arr, k);
2350 int form,
const uint8_t **ptr,
2352 return mizu_ext_arrow_str_at_impl(arr, k, form, ptr, len);
2357#define MIZU_ARROW_FLAG_DICTIONARY_ORDERED 1
2358#define MIZU_ARROW_FLAG_NULLABLE 2
2405 const uint8_t *valid, uint64_t off,
size_t n,
2406 const mizu_cvt_row *row,
2452 size_t n_batches, uint32_t peer_caps);
2465 uint32_t peer_caps);
2493 uint32_t peer_caps);
2498 mizu_arrow_col *out);
2537 int32_t *offs, uint8_t *data);
2570 const char *ident,
size_t ident_len,
2571 void *ref_base,
size_t ref_size,
2604 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:338
@ MIZU_TYPE_CPLX
interleaved float64 re/im
Definition mizu.h:328
@ MIZU_TYPE_RAW
bytes
Definition mizu.h:331
@ MIZU_TYPE_REAL
float64; a specific NaN payload is the sentinel
Definition mizu.h:327
@ MIZU_TYPE_LGL
int32 logical; INT_MIN is the missing sentinel
Definition mizu.h:325
@ MIZU_TYPE_STR
string vector (MIZS layout)
Definition mizu.h:329
@ MIZU_TYPE_VEC
list tree (MIZL layout)
Definition mizu.h:330
@ MIZU_TYPE_INT64
int64; INT64_MIN is the missing sentinel
Definition mizu.h:332
@ MIZU_TYPE_INT
int32; INT_MIN is the missing sentinel
Definition mizu.h:326
#define MIZU_MAGIC_VEC
"MIZH"
Definition mizu.h:414
#define MIZU_MAGIC_STR
"MIZS"
Definition mizu.h:415
#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:386
struct mizu_binding_s mizu_binding
The binding callbacks struct, taken by pointer at create/attach/join.
Definition mizu.h:167
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:412
#define MIZU_NAME_MAX
fits Windows worst case + NUL; Darwin PSHMNAMLEN
Definition mizu.h:419
#define MIZU_NA_INT64
NA_integer64_ sentinel.
Definition mizu.h:339
#define MIZU_API
Export macro.
Definition mizu.h:105
#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:351
#define MIZU_MAGIC_LIST
"MIZL"
Definition mizu.h:416
size_t mizu_type_elt_size(int type)
Element size of an atomic wire type, 0 for non-atomic.
struct mizu_task_s mizu_task
A task handle: an 8-byte value identifying one result slot at one sequence, with a 40-bit sequence in...
enum mizu_status_e mizu_status
The verb result.
#define MIZU_ATOMIC(T)
The wire-format structs carry atomic words.
Definition mizu.h:86
#define MIZU_NA_REAL_BITS
NA_real_ (a NaN payload).
Definition mizu.h:340
#define MIZU_HDR_FLAGS_OFF
Region magics (first 4 bytes): atomic vector, string vector, list tree.
Definition mizu.h:367
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:2131
void mizu_binding_bytes(mizu_binding *)
Fill binding with the bytes binding: stage/read only; exec, check, park, sweep, drop are NULL (a byte...
mizu_status mizu_arrow_open_lazy(mizu_arrow **out, const ArrowSchema *schema, const ArrowArray *const *batches, size_t n_batches, uint32_t peer_caps)
The open without the string walks, for a binding that registers remote overrides (mizu_arrow_remote) ...
mizu_status mizu_pool_collect_terminal(mizu_pool *, const mizu_task *, size_t n, void **values_out, size_t *count_out, size_t *fail_out)
The event-driven drain's batch collect: mizu_pool_collect's claim half over a task set,...
#define MIZU_IX_ATTR_NAMES
The attribute vocabulary (DESIGN.md's byte-shape helper registry): the shape whitelist's wire strings...
Definition mizu_ext.h:1709
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:1533
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,...
Definition mizu_ext.h:996
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:1047
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:2151
int64_t mizu_arrow_col_utf8(const mizu_arrow *, int64_t col, int32_t *offs, uint8_t *data)
A null-free utf8 or large_utf8 column's strings over every batch, concatenated for a binding's own st...
@ MIZU_ARROW_TS
timestamp -> REAL seconds + the POSIXct blob
Definition mizu_ext.h:2425
@ MIZU_ARROW_TD
duration -> REAL seconds + the difftime blob
Definition mizu_ext.h:2426
@ MIZU_ARROW_CVT
fixed-width, through the cvt row
Definition mizu_ext.h:2421
@ MIZU_ARROW_DATE
date32 -> REAL days + the Date blob
Definition mizu_ext.h:2424
@ MIZU_ARROW_DICT
dictionary<strings> -> a factor
Definition mizu_ext.h:2423
@ MIZU_ARROW_STR
utf8 / large_utf8 / string_view -> MIZS
Definition mizu_ext.h:2422
static uint64_t mizu_aux_shm_vec(int type, uint64_t total)
aux = layout type tag | exact used bytes << 8.
Definition mizu_ext.h:1453
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...
mizu_status mizu_ix_skip(mizu_ix *cur, const unsigned char **start, size_t *len)
Consume one complete value at the cursor's position without building it, reporting its byte span: *st...
static int mizu_ext_ix_tag_of_impl(int wire_type)
Definition mizu_ext.h:1772
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:2349
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:1449
size_t mizu_arrow_size_floor(const mizu_arrow *)
A lower bound on the fully local region span (every remote override ignored), O(columns) and valid st...
#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:64
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:1987
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:2188
void mizu_unpark_all(mizu_parker *pk)
The split-waiter form: wakes every sleeper on the epoch word.
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}...
Definition mizu_ext.h:1067
#define MIZU_INTEROP_MAGIC
'I': the interchange stream (DESIGN.md's Interchange codec section)
Definition mizu_ext.h:106
void mizu_pool_submit_wake(mizu_pool *, size_t done)
The batch submit's protocol wake, for a binding that abandons mizu_pool_submit_batch_fn mid-burst (a ...
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:1210
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:1441
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:1812
struct mizu_arrow mizu_arrow
The Arrow -> MIZL frame writer: a classified, batch-vetted frame plus its size-pass results,...
Definition mizu_ext.h:2414
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:1804
mizu_status mizu_arrow_validate(mizu_arrow *)
The string walks a lazy open deferred: every string column not yet walked and not registered remote.
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:1058
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:2097
@ MIZU_IX_ATTR
begin: one value item, then one DICT begin
Definition mizu_ext.h:1612
@ MIZU_IX_CPLX
u64[0..1]: the re / im f64 bits
Definition mizu_ext.h:1604
@ MIZU_IX_BYTES
the 0x05 bytes scalar
Definition mizu_ext.h:1607
@ MIZU_IX_REAL
u64[0]: the f64 bits
Definition mizu_ext.h:1603
@ MIZU_IX_LIST
begin: count value items follow
Definition mizu_ext.h:1610
@ MIZU_IX_STR1
the 0x04 string scalar
Definition mizu_ext.h:1605
@ MIZU_IX_TASK
header: count fields follow as ordinary items
Definition mizu_ext.h:1614
@ MIZU_IX_VEC
0x06-0x0a, 0x0e: type is the MIZU_TYPE_* tag
Definition mizu_ext.h:1608
@ MIZU_IX_LGL
u64[0]: 0, 1, or 2 (NA)
Definition mizu_ext.h:1601
@ MIZU_IX_ERR
the err fields; legal at the top level only
Definition mizu_ext.h:1613
@ MIZU_IX_DICT
begin: count (STR key, value) pairs follow
Definition mizu_ext.h:1611
@ MIZU_IX_REF
the 0x13 region identifier span (ptr, len)
Definition mizu_ext.h:1615
@ MIZU_IX_STR
a bare string (strv element, or dict key: key=1)
Definition mizu_ext.h:1606
@ MIZU_IX_INT
u64[0]: the i64
Definition mizu_ext.h:1602
@ MIZU_IX_STRV
begin: count STR items follow
Definition mizu_ext.h:1609
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:595
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.
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:1562
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:1459
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:1505
size_t mizu_channel_avail(mizu_channel *)
The consumer's published-not-yet-consumed message count: one acquire load on a local-cache miss,...
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:167
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:2336
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:578
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:2090
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:302
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:2115
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.
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:2012
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:2200
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:1134
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:2142
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:1525
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...
struct mizu_result_sink_s mizu_result_sink
Valid only during an exec callback.
Definition mizu_ext.h:170
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:2164
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...
mizu_status mizu_channel_notify_arm(mizu_channel *, int on, int *avail_out)
Event-driven wakes for a binding's async integration: an armed consumer owns a named,...
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,...
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:2123
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:2183
static size_t mizu_ext_ix_err_floor_impl(const void *s, size_t n, size_t share)
Definition mizu_ext.h:2001
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.
static int mizu_ix_attr_reserved(const char *key, size_t len)
The reserved attribute keys: every MIZU_IX_ATTR_* key (the whitelist vocabulary) plus "tsp": 1 when t...
Definition mizu_ext.h:2105
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:1515
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 ...
mizu_status mizu_arrow_open_vector(mizu_arrow **out, const ArrowSchema *schema, const ArrowArray *const *batches, size_t n_batches, uint32_t peer_caps)
The bare-vector counterpart, for a binding's per-column writers over a one-column struct wrapper.
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:1495
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:715
#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:73
struct mizu_morsel_hdr_s mizu_morsel_hdr
The 128-byte region header.
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:1541
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:1167
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:1104
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 i...
Definition mizu_ext.h:1701
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 le...
Definition mizu_ext.h:1079
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:1487
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...
@ MIZU_CVT_U16_INT
zero-widen
Definition mizu_ext.h:2366
@ MIZU_CVT_COPY
identity: one memcpy per run
Definition mizu_ext.h:2363
@ MIZU_CVT_U32_REAL
exact
Definition mizu_ext.h:2367
@ MIZU_CVT_BOOL8_LGL
one byte per source lane (numpy '?
Definition mizu_ext.h:2372
@ MIZU_CVT_F32_REAL
exact
Definition mizu_ext.h:2371
@ MIZU_CVT_U64_INT64
in-range exact; past INT64_MAX the int64 NA sentinel, counted in n_range
Definition mizu_ext.h:2368
@ MIZU_CVT_BIT_LGL
one bit per source lane (Arrow 'b') -> int32 0/1
Definition mizu_ext.h:2373
@ MIZU_CVT_I8_INT
sign-widen
Definition mizu_ext.h:2364
@ MIZU_CVT_C64_CPLX
float re/im -> double re/im
Definition mizu_ext.h:2374
@ MIZU_CVT_F16_REAL
exact (half decodes into double's wider fields)
Definition mizu_ext.h:2370
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:1469
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 ident...
int64_t mizu_arrow_col_validity(const mizu_arrow *, int64_t col, uint8_t *dst)
One column's validity over every batch, concatenated from bit 0 into dst ((rows + 7) / 8 bytes,...
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:1739
int mizu_result_publish(mizu_result_sink *, void *value)
Result publish, valid during exec only.
Definition mizu_ext.h:2251
Definition mizu_ext.h:2235
Definition mizu_ext.h:2223
Definition mizu_ext.h:2429
int u64_verbatim
CVT 'L': the MIZU_CAP_MIZL_U64V verdict (the leaf writes INT64 + the u64 blob attr,...
Definition mizu_ext.h:2433
int str_form
STR / DICT: 1 utf8, 2 large_utf8, 3 view.
Definition mizu_ext.h:2432
int kind
MIZU_ARROW_*.
Definition mizu_ext.h:2430
const mizu_cvt_row * row
CVT.
Definition mizu_ext.h:2431
The conversion warning counts, accumulated by mizu_cvt_convert and the frame writer; the binding rais...
Definition mizu_ext.h:2387
uint64_t n_int64
a genuine int64 INT64_MIN: reads as NA in R
Definition mizu_ext.h:2390
uint64_t n_intmin
a genuine int32 INT32_MIN: reads as NA in R
Definition mizu_ext.h:2389
uint64_t n_range
uint64 past INT64_MAX -> the int64 NA sentinel
Definition mizu_ext.h:2388
Definition mizu_ext.h:339
mizu_exec_fn exec
pool workers only; NULL on submitter handles
Definition mizu_ext.h:344
uint64_t ident
MIZU_IDENT word; a zero language byte is rejected at create, attach and join.
Definition mizu_ext.h:350
mizu_check_fn check
interrupt poll; NULL for plain-C consumers
Definition mizu_ext.h:345
mizu_sweep_fn sweep
idle cache drop; usually NULL
Definition mizu_ext.h:347
uint32_t size
sizeof(mizu_binding); set with mizu_binding_init and checked at create/attach/join
Definition mizu_ext.h:340
mizu_park_fn park
around-park lock release; usually NULL
Definition mizu_ext.h:346
mizu_drop_fn drop
pin release; NULL when the binding never pins
Definition mizu_ext.h:348
void * ctx
opaque to the core
Definition mizu_ext.h:349
uint32_t flags
MIZU_BINDING_* bits (the seam comment above); zero from mizu_binding_init.
Definition mizu_ext.h:352
A byte buffer.
Definition mizu_ext.h:490
Definition mizu_ext.h:2377
int cvt
MIZU_CVT_*.
Definition mizu_ext.h:2379
int wire
the MIZU_TYPE_* the row produces
Definition mizu_ext.h:2378
uint8_t w_in
source element bytes (0: bit-packed, MIZU_CVT_BIT_LGL)
Definition mizu_ext.h:2380
Definition mizu_ext.h:1618
uint64_t len
STR1 / STR / REF: the span's byte length.
Definition mizu_ext.h:1624
int key
STR: a dict key (an strv element has 0).
Definition mizu_ext.h:1622
uint32_t task_kind
TASK: the kind byte.
Definition mizu_ext.h:1630
uint32_t kind
MIZU_IX_*.
Definition mizu_ext.h:1619
uint32_t err_flags
ERR: bit 0 = index present.
Definition mizu_ext.h:1631
uint64_t err_index
ERR: valid when err_flags bit 0 is set.
Definition mizu_ext.h:1632
uint32_t target
TASK: the target language byte.
Definition mizu_ext.h:1629
uint32_t type
VEC: the MIZU_TYPE_* wire type.
Definition mizu_ext.h:1620
uint64_t count
BYTES / VEC / STRV / LIST / DICT: the element (pair) count; TASK: the field arity.
Definition mizu_ext.h:1625
const unsigned char * ptr
STR1 / STR / BYTES / VEC / REF: the data span.
Definition mizu_ext.h:1623
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:1627
int na
STR1 / STR: the -1 (NA) form.
Definition mizu_ext.h:1621
The pull cursor.
Definition mizu_ext.h:1642
int done
the root value completed
Definition mizu_ext.h:1646
uint64_t remaining
items owned at this level
Definition mizu_ext.h:1650
int err
latched: all later calls fail
Definition mizu_ext.h:1647
uint32_t kind
the MIZU_IX_* begin kind
Definition mizu_ext.h:1649
One MIZL directory entry plus its validity-table pair (mizu.h documents the 32-byte entry): mizu_mizl...
Definition mizu_ext.h:1032
int64_t data_offset
64-byte aligned
Definition mizu_ext.h:1033
int64_t valid[2]
{0, 0} absent, {0, -1} known-NA-free, else {bitmap offset, null count}
Definition mizu_ext.h:1038
The small pure helpers over mizu.h's wire-format conventions, dual form like the zc accessors above (...
Definition mizu_ext.h:1022
The 128-byte region header.
Definition mizu_ext.h:835
uint32_t out_type
template element wire type; 0 = no output
Definition mizu_ext.h:841
uint32_t version
MIZU_ABI_VERSION.
Definition mizu_ext.h:837
uint32_t claim_n
CLAIM word count (runner ordinal bound).
Definition mizu_ext.h:843
uint32_t out_elt
template element size, bytes
Definition mizu_ext.h:842
uint32_t magic
MIZU_MORSEL_MAGIC.
Definition mizu_ext.h:836
uint64_t state_off
morsel state section offset
Definition mizu_ext.h:851
uint64_t morsel_size
elements per morsel
Definition mizu_ext.h:849
uint64_t out_m
template length: values per element
Definition mizu_ext.h:848
uint32_t x_type
raw x section wire type (MIZU_TYPE_*)
Definition mizu_ext.h:840
uint32_t x_kind
MIZU_MORSEL_X_*.
Definition mizu_ext.h:839
uint64_t n
map elements
Definition mizu_ext.h:844
uint64_t n_morsels
ceiling(n / morsel_size)
Definition mizu_ext.h:850
uint32_t flags
reserved, 0
Definition mizu_ext.h:838
Batch-sizing state: process-private, never wire state, reset at each run's first-call CLAIM CAS.
Definition mizu_ext.h:879
uint64_t k_last
morsels issued last transition
Definition mizu_ext.h:883
double cost
est.
Definition mizu_ext.h:885
uint64_t k
current batch size, morsels
Definition mizu_ext.h:882
int32_t run_r
ordinal whose ramp this is (-1 = none)
Definition mizu_ext.h:880
int skip
last interval contained a help: no update
Definition mizu_ext.h:886
double t_last
mizu_now() at the last issue
Definition mizu_ext.h:884
Worker-death lost set: issued = [0, bound), lost = issued minus the union of the collected batch hist...
Definition mizu_ext.h:950
One parker per waiting entity: a 32-bit monotonic epoch word in the shared region plus,...
Definition mizu_ext.h:541
uint32_t * epoch
in the shared region
Definition mizu_ext.h:542
The opaque pool-signal trio a map runner loads relaxed once per batch transition: the help_wanted doo...
Definition mizu_ext.h:747
Definition mizu_ext.h:314
uint32_t flags
binding-set MIZU_READ_*; zero on entry
Definition mizu_ext.h:324
void * binding_ctx
the handle's binding.ctx
Definition mizu_ext.h:323
int32_t gone
set by mizu_read_region on a vanished region; read_fn propagates by returning NULL
Definition mizu_ext.h:318
int32_t died_slot
MIZU_RS_DIED: the claimant worker slot (-1).
Definition mizu_ext.h:320
int64_t died_pid
MIZU_RS_DIED: its pid (0 when unknown).
Definition mizu_ext.h:321
mizu_handle * handle
the reading handle
Definition mizu_ext.h:322
uint32_t size
core-set: sizeof the struct it knows
Definition mizu_ext.h:315
void * reserved[4]
zero; future growth without a soname bump
Definition mizu_ext.h:325
int32_t outcome
pool: mizu_rs_status of the result (channel: MIZU_RS_OK)
Definition mizu_ext.h:316
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:960
unsigned char * payload
rs + sizeof(mizu_rs_hdr): the frame buffer
Definition mizu_ext.h:963
uint64_t seq
the claimed incarnation (the state word's sequence; the publish CAS expects RUNNING,...
Definition mizu_ext.h:967
uint32_t inline_max
the slot's payload capacity
Definition mizu_ext.h:965
uint16_t sub_slot
the task's submitter (zc keying, probes)
Definition mizu_ext.h:966
The public opaque type in mizu.h; defined here for bindings (the core's control-region mappings embed...
Definition mizu_ext.h:515
uint8_t collapsed
Linux: whole 2 MiB extents of addr are huge (set by a successful MADV_COLLAPSE; one-way latch — a sha...
Definition mizu_ext.h:521
unsigned int pid
creator PID: fork guard (POSIX only)
Definition mizu_ext.h:520
uint32_t kind
mizu_kind
Definition mizu.h:312