libmizu 0.0.1
Lock-free shared-memory IPC
Loading...
Searching...
No Matches
mizu_ext.h
Go to the documentation of this file.
1
43#ifndef MIZU_EXT_H
44#define MIZU_EXT_H
45
46#include <math.h>
47#include <string.h>
48
49#include "mizu.h"
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
58#if defined(__GNUC__) || defined(__clang__)
59# define MIZU_EXT_INLINE static inline __attribute__((unused))
60#else
61# define MIZU_EXT_INLINE static inline
62#endif
63
66#ifdef __cplusplus
67# define MIZU_EXT_LOAD_ACQ(p) \
68 std::atomic_load_explicit((p), std::memory_order_acquire)
69#else
70# define MIZU_EXT_LOAD_ACQ(p) \
71 atomic_load_explicit((p), memory_order_acquire)
72#endif
73
74// Binding-tier constants ---------------------------------------------------------
75
76#ifdef _WIN32
77# define MIZU_PREFIX_LITERAL "Local\\mizu_"
78#else
79# define MIZU_PREFIX_LITERAL "/mizu_"
80#endif
81
82#define MIZU_ALIGN64(x) (((x) + 63) & ~(size_t) 63)
83
89#define MIZU_ZC_FLOOR ((size_t) 32768)
90#define MIZU_ZC_FLOOR_RAW ((size_t) (256 << 10))
91
94#define MIZU_OPEN_CACHE_MAX 16
95
102#define MIZU_CODEC_MAGIC 0x52u
103#define MIZU_PYMIZU_CODEC_MAGIC 0x50u
104#define MIZU_INTEROP_MAGIC 0x49u
107// Language and capability registries ----------------------------------------------
108
117#define MIZU_LANG_NONE 0u
118#define MIZU_LANG_BYTES 1u
119#define MIZU_LANG_R 2u
120#define MIZU_LANG_PYTHON 3u
121
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))
151
152// Handle views -------------------------------------------------------------------
153
157typedef struct mizu_handle_s mizu_handle;
161
164enum { MIZU_HTYPE_CHANNEL = 1, MIZU_HTYPE_POOL = 2 };
165
177MIZU_API int mizu_handle_churn(const mizu_handle *);
182MIZU_API void mizu_handle_spill_info(const mizu_handle *,
183 uint32_t *fl_entries,
184 uint32_t *ledger_entries);
185
186// The binding seam ---------------------------------------------------------------
187
272typedef int (*mizu_stage_fn)(void *obj, mizu_slot_hdr *hdr,
273 uint8_t *payload, uint32_t inline_max,
274 mizu_handle *, void *ctx);
275
282#define MIZU_READ_CONSUME 1u
283
284typedef struct mizu_read_ctx_s {
285 uint32_t size;
286 int32_t outcome;
288 int32_t gone;
290 int32_t died_slot;
291 int64_t died_pid;
294 uint32_t flags;
295 void *reserved[4];
297
298typedef void *(*mizu_read_fn)(const mizu_slot_hdr *, const uint8_t *payload,
299 size_t limit, mizu_read_ctx *);
300
301typedef int (*mizu_exec_fn)(const mizu_slot_hdr *hdr, const uint8_t *payload,
302 size_t limit, mizu_result_sink *, int catching,
303 mizu_read_ctx *ctx);
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);
308
309typedef struct mizu_binding_s {
310 uint32_t size;
311 mizu_stage_fn stage;
312 mizu_read_fn read;
313 mizu_exec_fn exec;
314 mizu_check_fn check;
315 mizu_park_fn park;
316 mizu_sweep_fn sweep;
317 mizu_drop_fn drop;
318 void *ctx;
319 uint64_t ident;
322
325
335MIZU_API uint64_t mizu_channel_peer_ident(const mizu_channel *);
336MIZU_API uint64_t mizu_pool_worker_ident(const mizu_pool *);
337
363MIZU_API void *mizu_stage_arena_alloc(mizu_handle *, size_t n, uint64_t *off);
364MIZU_API mizu_status mizu_stage_spill_get(mizu_handle *, size_t n,
365 mizu_shm **out);
366MIZU_API void mizu_stage_retain(mizu_handle *, mizu_shm *region);
367MIZU_API void mizu_stage_retain_zc(mizu_handle *, mizu_shm *region);
368MIZU_API void mizu_stage_pin(mizu_handle *, void *pin);
369MIZU_API void mizu_stage_reap(mizu_handle *);
370MIZU_API void mizu_stage_rollback(mizu_handle *);
371
389MIZU_API void *mizu_stage_raw_spill(mizu_handle *, uint64_t n, int wire_type,
390 mizu_slot_hdr *, uint8_t *payload,
391 uint32_t inline_max);
392#ifdef MIZU_EXT_NO_INLINES
393MIZU_API void *mizu_stage_raw(mizu_handle *, uint64_t n, int wire_type,
394 mizu_slot_hdr *, uint8_t *payload,
395 uint32_t inline_max);
396#else
397MIZU_EXT_INLINE void *mizu_stage_raw(mizu_handle *h, uint64_t n, int wire_type,
398 mizu_slot_hdr *hdr, uint8_t *payload,
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;
404 return payload;
405 }
406 return mizu_stage_raw_spill(h, n, wire_type, hdr, payload, inline_max);
407}
408#endif
409
418 uint32_t len);
419
439MIZU_API int mizu_result_publish_err(mizu_result_sink *, void *flattened,
440 uint32_t inline_n);
441MIZU_API void mizu_result_publish_lost(mizu_result_sink *);
442
443// The built-in bytes binding -----------------------------------------------------
444
450typedef struct mizu_bytes_s {
451 void *data;
452 size_t len;
454
466MIZU_API void mizu_bytes_free(mizu_bytes *);
467
468// The region handle struct ---------------------------------------------------------
469
476 void *addr;
477 size_t size;
478 char name[MIZU_NAME_MAX];
479 uint8_t name_len;
480 unsigned int pid;
481#ifdef _WIN32
482 void *handle;
483#endif
484};
485
486// Parker (wait_*.c) ---------------------------------------------------------------
487
497typedef struct mizu_parker_s {
498 MIZU_ATOMIC(uint32_t) *epoch;
499#ifdef _WIN32
500 void *event;
501#endif
503
504typedef enum mizu_park_result_e { MIZU_PARK_WOKEN = 0, MIZU_PARK_TIMEOUT,
505 MIZU_PARK_INTR } mizu_park_result;
506
511 const char *region_name, int entity,
512 int create);
513MIZU_API void mizu_parker_detach(mizu_parker *pk);
514
520MIZU_API int mizu_park(mizu_parker *pk, uint32_t snapshot, long timeout_ms);
521MIZU_API void mizu_unpark(mizu_parker *pk);
522
523#ifdef MIZU_EXT_NO_INLINES
524MIZU_API uint32_t mizu_parker_snapshot(const mizu_parker *pk);
525#else
528 return MIZU_EXT_LOAD_ACQ(pk->epoch);
529}
530#endif
531
532// Death watch (wait_linux.c / wait_macos.c / wait_win32.c) ------------------------
533
544typedef struct mizu_death_watch_s mizu_death_watch;
545
546MIZU_API mizu_death_watch *mizu_death_watch_start(long pid,
547 MIZU_ATOMIC(int) *flag,
548 const mizu_parker *pk);
549MIZU_API void mizu_death_watch_stop(mizu_death_watch *w);
550
555
556// Liveness lock (liveness.c) ---------------------------------------------------
557
565typedef enum mizu_live_probe_e { MIZU_LIVE_ACQUIRED = 0,
566 MIZU_LIVE_HELD = 1 } mizu_live_probe;
567
573MIZU_API const char *mizu_live_dir(void);
574
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);
578
579// Preamble (preamble.c) ----------------------------------------------------------
580
585MIZU_API void mizu_preamble_write(void *region, const mizu_preamble *p);
586MIZU_API const char *mizu_preamble_validate(const void *region,
587 size_t region_size,
588 mizu_preamble *out);
589
590// Map support (pool.c; a binding's map rides these) ---------------------------------
591
597typedef struct mizu_pool_sig_s {
598 MIZU_ATOMIC(uint32_t) *help_wanted;
599 MIZU_ATOMIC(uint32_t) *shutdown;
600 MIZU_ATOMIC(int) *owner_dead;
602
611MIZU_API int mizu_pool_deque_pull(mizu_pool *, uint32_t n);
618MIZU_API int mizu_pool_map_caps(mizu_pool *, uint32_t *free_rs,
619 uint32_t *inj_cap, uint32_t *inline_entry);
623MIZU_API mizu_status mizu_pool_submit_flags(mizu_pool *, void *task_obj,
624 uint16_t flags, mizu_task *out,
625 double timeout_ms);
626
627// Map morsel protocol (morsel.c) -------------------------------------------------
628
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)
654
655enum { MIZU_MORSEL_IDLE = 0, MIZU_MORSEL_RUNNING, MIZU_MORSEL_ABANDONED };
656enum { MIZU_MORSEL_X_DESC = 0, MIZU_MORSEL_X_RAW };
657
662#define MIZU_MORSEL_T_TARGET 200e-6
663#define MIZU_MORSEL_BATCH_CAP 64
664
670#define MIZU_MORSEL_MAGIC 0x4D495A4Du
671
675typedef struct mizu_morsel_hdr_s {
676 uint32_t magic;
677 uint32_t version;
678 uint32_t flags;
679 uint32_t x_kind;
680 uint32_t x_type;
681 uint32_t out_type;
682 uint32_t out_elt;
683 uint32_t claim_n;
684 uint64_t n;
685 uint64_t desc_off, desc_len;
686 uint64_t x_off, x_len;
687 uint64_t out_off;
688 uint64_t out_m;
689 uint64_t morsel_size;
690 uint64_t n_morsels;
691 uint64_t state_off;
692 uint8_t pad[16];
694MIZU_STATIC_ASSERT(sizeof(mizu_morsel_hdr) == 128,
695 "mizu_morsel_hdr is the wire format");
696
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);
712MIZU_API const char *mizu_morsel_hdr_check(const void *base, size_t size,
713 mizu_morsel_hdr *out);
714
719typedef struct mizu_morsel_sizer_s {
720 int32_t run_r;
721 uint32_t run_gen;
722 uint64_t k;
723 uint64_t k_last;
724 double t_last;
725 double cost;
726 int skip;
728MIZU_API void mizu_morsel_sizer_init(mizu_morsel_sizer *);
729
740 mizu_morsel_sizer *sz, uint32_t r, uint32_t gen,
741 const mizu_pool_sig *sig, uint64_t pin_k,
742 double now, uint64_t *m_out, uint64_t *k_out,
743 int *help_out);
744
752MIZU_API uint32_t mizu_morsel_reset(void *base, const mizu_morsel_hdr *h);
753
760 uint32_t r, uint32_t gen);
761
766MIZU_API int mizu_morsel_cancel_get(const void *base, const mizu_morsel_hdr *h);
769MIZU_API uint32_t mizu_morsel_generation(const void *base,
770 const mizu_morsel_hdr *h);
771MIZU_API uint64_t mizu_morsel_cursor(const void *base,
772 const mizu_morsel_hdr *h);
773MIZU_API uint32_t mizu_morsel_claim(const void *base, const mizu_morsel_hdr *h,
774 uint32_t r);
775
779 uint64_t k, uint64_t *lo, uint64_t *hi);
780
788typedef struct mizu_morsel_span_s { uint64_t lo, hi; } mizu_morsel_span;
789MIZU_API size_t mizu_morsel_lost(mizu_morsel_span *spans, size_t n,
790 uint64_t bound, mizu_morsel_span *out);
791
792// The result sink and the unwind path (pool.c) ----------------------------------
793
799 mizu_pool *p;
800 mizu_rs_hdr *rs;
801 unsigned char *payload;
802 uint32_t rs_index;
803 uint32_t inline_max;
804 uint16_t sub_slot;
805 uint64_t seq;
806 uint64_t task_id;
807};
808
813MIZU_API void mizu_pool_eval_mark(mizu_pool *, int in_flight);
821
822// Zero-copy refcount words ---------------------------------------------------------
823
829#ifdef MIZU_EXT_NO_INLINES
830MIZU_API MIZU_ATOMIC(uint32_t) *mizu_zc_rc(void *base);
831MIZU_API MIZU_ATOMIC(uint32_t) *mizu_zc_flags_(void *base);
832#else
833MIZU_EXT_INLINE MIZU_ATOMIC(uint32_t) *mizu_zc_rc(void *base) {
834 return (MIZU_ATOMIC(uint32_t) *) ((unsigned char *) base +
836}
837MIZU_EXT_INLINE MIZU_ATOMIC(uint32_t) *mizu_zc_flags_(void *base) {
838 return (MIZU_ATOMIC(uint32_t) *) ((unsigned char *) base +
839 MIZU_ZC_FLAGS_OFF);
840}
841#endif
842
843// Wire-format helpers --------------------------------------------------------------
844
859typedef struct mizu_mizs_geom_s {
860 int64_t validity;
861 int64_t offsets;
862 int64_t encoding;
863 int64_t data;
865
869typedef struct mizu_mizl_entry_s {
870 int64_t data_offset;
871 int64_t data_size;
872 int32_t sexptype;
873 int32_t attrs_size;
874 int64_t length;
875 int64_t valid[2];
878
881#ifdef MIZU_EXT_NO_INLINES
883#else
886 g.validity = 0;
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);
890 return g;
891}
892#endif
893
896 uint32_t flags;
897 memcpy(&flags, (const unsigned char *) base + MIZU_HDR_FLAGS_OFF, 4);
898 return (flags & ~MIZU_HDR_FLAG_S4) == 0;
899}
900
904MIZU_EXT_INLINE int mizu_ext_valid_ok(int64_t off, int64_t count,
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;
911}
912
917 switch (sexptype & ~(int32_t) MIZU_MIZL_S4) {
918 case 0:
919 case MIZU_TYPE_LGL:
920 case MIZU_TYPE_INT:
921 case MIZU_TYPE_REAL:
922 case MIZU_TYPE_CPLX:
923 case MIZU_TYPE_STR:
924 case MIZU_TYPE_VEC:
925 case MIZU_TYPE_RAW:
926 case MIZU_TYPE_INT64:
927 case 33: /* remote leaf */
928 return 1;
929 default:
930 return 0;
931 }
932}
933
942 return ((bits >> 52) & 0x7FF) == 0x7FF && (uint32_t) bits == 0x7A2u;
943}
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;
947 int32_t v32;
948 int64_t v64;
949 switch (type) {
950 case MIZU_TYPE_LGL:
951 case MIZU_TYPE_INT:
952 memcpy(&v32, p + 4 * i, 4);
953 return v32 == MIZU_NA_INT32;
954 case MIZU_TYPE_REAL:
955 memcpy(&bits, p + 8 * i, 8);
956 return mizu_ext_na_real_bits(bits);
957 case MIZU_TYPE_CPLX:
958 memcpy(&re, p + 16 * i, 8);
959 memcpy(&im, p + 16 * i + 8, 8);
961 case MIZU_TYPE_INT64:
962 memcpy(&v64, p + 8 * i, 8);
963 return v64 == MIZU_NA_INT64;
964 default:
965 return 0;
966 }
967}
968
971MIZU_EXT_INLINE void mizu_ext_na_store(int type, void *dst, uint64_t i) {
972 unsigned char *p = (unsigned char *) dst;
973 const int32_t na32 = MIZU_NA_INT32;
974 const int64_t na64 = MIZU_NA_INT64;
975 const uint64_t nabits = MIZU_NA_REAL_BITS;
976 switch (type) {
977 case MIZU_TYPE_LGL:
978 case MIZU_TYPE_INT:
979 memcpy(p + 4 * i, &na32, 4);
980 break;
981 case MIZU_TYPE_REAL:
982 memcpy(p + 8 * i, &nabits, 8);
983 break;
984 case MIZU_TYPE_CPLX:
985 memcpy(p + 16 * i, &nabits, 8);
986 memcpy(p + 16 * i + 8, &nabits, 8);
987 break;
988 case MIZU_TYPE_INT64:
989 memcpy(p + 8 * i, &na64, 8);
990 break;
991 default:
992 break;
993 }
994}
995
1004MIZU_EXT_INLINE int mizu_ext_mizl_ent(const void *base, size_t size,
1005 int64_t i, mizu_mizl_entry *e) {
1006 const unsigned char *dir = (const unsigned char *) base +
1007 MIZU_HEADER_SIZE + 32 * (size_t) i;
1008 memcpy(&e->data_offset, dir, 8);
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);
1013 if (e->data_offset < 0 || (e->data_offset & 63) != 0 ||
1014 e->data_size < 0 ||
1015 (uint64_t) e->data_offset > (uint64_t) size ||
1016 (uint64_t) e->data_size >
1017 (uint64_t) size - (uint64_t) e->data_offset ||
1018 e->attrs_size < 0)
1019 return -1;
1020 if (!mizu_ext_mizl_tag_ok(e->sexptype)) return -1;
1021 const int32_t tag = e->sexptype & ~(int32_t) MIZU_MIZL_S4;
1022 if (tag == 33) { /* remote leaf: the span is the identifier */
1023 if ((e->sexptype & (int32_t) MIZU_MIZL_S4) != 0 || e->length < 0 ||
1024 e->data_size < 1 || e->data_size > 255)
1025 return -1;
1026 return 0;
1027 }
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;
1030 const size_t elt = mizu_type_elt_size(tag);
1031 if (elt != 0) {
1032 if (e->length < 0 || e->length > body / (int64_t) elt) return -1;
1033 } else if (tag == MIZU_TYPE_STR) {
1034 if (e->length < 0 || e->length > ((int64_t) 1 << 50) ||
1035 mizu_mizs_geometry(e->length).data > body)
1036 return -1;
1037 } else if (tag == MIZU_TYPE_VEC) {
1038 if (e->length < 0) return -1;
1039 }
1040 return 0;
1041}
1042
1047MIZU_EXT_INLINE int mizu_ext_mizh_check_impl(const void *base, size_t size,
1048 int *wire_type, int64_t *n_elems,
1049 int64_t valid[2]) {
1050 if (size < MIZU_HEADER_SIZE) return -1;
1051 uint32_t magic;
1052 int32_t t32;
1053 int64_t len, attrs, voff, vcount;
1054 memcpy(&magic, base, 4);
1055 if (magic != MIZU_MAGIC_VEC) return -1;
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);
1059 memcpy(&voff, (const unsigned char *) base + MIZU_HDR_VALID_OFF, 8);
1060 memcpy(&vcount, (const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1061 const size_t elt = mizu_type_elt_size(t32);
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)
1066 return -1;
1067 if (!mizu_ext_flags_known(base) ||
1068 !mizu_ext_valid_ok(voff, vcount, (uint64_t) len, size))
1069 return -1;
1070 *wire_type = t32;
1071 *n_elems = len;
1072 valid[0] = voff;
1073 valid[1] = vcount;
1074 return 0;
1075}
1076
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;
1081 uint32_t magic;
1082 int32_t attrs;
1083 int64_t count, block;
1084 memcpy(&magic, base, 4);
1085 if (magic != MIZU_MAGIC_STR) return -1;
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)
1090 return -1;
1091 if (!mizu_ext_flags_known(base)) return -1;
1092 const int64_t fixed = mizu_mizs_geometry(count).data;
1093 if (fixed > block ||
1094 block > (int64_t) size - (int64_t) MIZU_HEADER_SIZE ||
1095 (int64_t) attrs >
1096 (int64_t) size - (int64_t) MIZU_HEADER_SIZE - block)
1097 return -1;
1098 *n = count;
1099 *str_size = block;
1100 *attrs_size = attrs;
1101 return 0;
1102}
1103
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,
1107 int64_t valid[2]) {
1108 if (size < MIZU_HEADER_SIZE) return -1;
1109 uint32_t magic;
1110 int32_t n32;
1111 int64_t aoff, asz, voff, vcount;
1112 memcpy(&magic, base, 4);
1113 if (magic != MIZU_MAGIC_LIST) return -1;
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);
1117 memcpy(&voff, (const unsigned char *) base + MIZU_HDR_VALID_OFF, 8);
1118 memcpy(&vcount, (const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1119 if (n32 < 0 ||
1120 (uint64_t) (uint32_t) n32 >
1121 ((uint64_t) size - (uint64_t) MIZU_HEADER_SIZE) / 32)
1122 return -1;
1123 if (aoff < 0 || asz < 0 ||
1124 (uint64_t) aoff > (uint64_t) size ||
1125 (uint64_t) asz > (uint64_t) size - (uint64_t) aoff)
1126 return -1;
1127 if (!mizu_ext_flags_known(base)) return -1;
1128 uint64_t sum = 0;
1129 for (int64_t i = 0; i < (int64_t) n32; i++) {
1131 if (mizu_ext_mizl_ent(base, size, i, &e) != 0) return -1;
1132 const int32_t tag = e.sexptype & ~(int32_t) MIZU_MIZL_S4;
1133 /* vcount is an int64, so the bound needs the sum only up to
1134 INT64_MAX: saturate. Overlapping crafted leaves in a huge region
1135 can otherwise wrap the accumulation and over-reject. */
1136 if (mizu_type_elt_size(tag) != 0 && sum < (uint64_t) INT64_MAX) {
1137 const uint64_t len = (uint64_t) e.length;
1138 sum = len > (uint64_t) INT64_MAX - sum ? (uint64_t) INT64_MAX
1139 : sum + len;
1140 }
1141 }
1142 if (voff == 0) {
1143 if (vcount != 0 && vcount != -1) return -1;
1144 } else {
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)
1149 return -1;
1150 }
1151 *n = n32;
1152 *attrs_off = aoff;
1153 *attrs_size = asz;
1154 valid[0] = voff;
1155 valid[1] = vcount;
1156 return 0;
1157}
1158
1159MIZU_EXT_INLINE int mizu_ext_mizl_elem_impl(const void *base, size_t size,
1160 int64_t i,
1161 mizu_mizl_entry *elem) {
1162 if (size < MIZU_HEADER_SIZE) return -1;
1163 uint32_t magic;
1164 int32_t n32;
1165 int64_t voff, vcount;
1166 memcpy(&magic, base, 4);
1167 if (magic != MIZU_MAGIC_LIST) return -1;
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)
1172 return -1;
1173 if (!mizu_ext_flags_known(base)) return -1;
1174 if (mizu_ext_mizl_ent(base, size, i, elem) != 0) return -1;
1175 memcpy(&voff, (const unsigned char *) base + MIZU_HDR_VALID_OFF, 8);
1176 memcpy(&vcount, (const unsigned char *) base + MIZU_HDR_VALID_COUNT, 8);
1177 if (voff == 0) {
1178 if (vcount != 0 && vcount != -1) return -1;
1179 elem->valid[0] = 0;
1180 elem->valid[1] = vcount;
1181 return 0;
1182 }
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)
1187 return -1;
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);
1192 /* a remote leaf (tag 33) carries a {0,0} / {0,-1} claim alone — a
1193 bitmap offset is region-local and cannot describe a remote column.
1194 STR / VEC / serialized leaves carry no table bitmap either: the
1195 string block, the nested header, and the blob each speak for
1196 themselves, and the writers stamp those rows {0,0} */
1197 const int32_t ltag = elem->sexptype & ~(int32_t) MIZU_MIZL_S4;
1198 if ((ltag == 33 || mizu_type_elt_size(ltag) == 0) && loff != 0)
1199 return -1;
1200 if (!mizu_ext_valid_ok(loff, lcount, (uint64_t) elem->length, size))
1201 return -1;
1202 elem->valid[0] = loff;
1203 elem->valid[1] = lcount;
1204 return 0;
1205}
1206
1207MIZU_EXT_INLINE uint64_t mizu_ext_na_build_impl(int type, uint8_t *bitmap,
1208 const void *src, uint64_t n,
1209 uint64_t bit_off) {
1210 uint64_t nulls = 0;
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));
1215 nulls++;
1216 } else {
1217 bitmap[bit >> 3] |= (uint8_t) (1u << (bit & 7));
1218 }
1219 }
1220 return nulls;
1221}
1222
1223MIZU_EXT_INLINE uint64_t mizu_ext_na_apply_impl(int type, void *dst,
1224 const void *src,
1225 const uint8_t *bitmap,
1226 uint64_t n) {
1227 const size_t elt = mizu_type_elt_size(type);
1228 if (elt == 0) return 0;
1229 if (dst != src) memcpy(dst, src, (size_t) n * elt);
1230 uint64_t nulls = 0;
1231 for (uint64_t i = 0; i < n; i++) {
1232 if (((bitmap[i >> 3] >> (i & 7)) & 1) == 0) {
1233 mizu_ext_na_store(type, dst, i);
1234 nulls++;
1235 }
1236 }
1237 return nulls;
1238}
1239
1240#ifdef MIZU_EXT_NO_INLINES
1241MIZU_API double mizu_timeout_ms(double seconds);
1242MIZU_API void mizu_store_na_real(void *dst);
1243MIZU_API uint64_t mizu_aux_rawspill_pool(int type, uint32_t name_len);
1244MIZU_API uint64_t mizu_aux_shm_vec(int type, uint64_t total);
1245MIZU_API int mizu_aux_type(uint64_t aux);
1246MIZU_API uint64_t mizu_aux_hi(uint64_t aux);
1247MIZU_API void mizu_mizh_write(void *base, int wire_type, int64_t n_elems);
1248MIZU_API int mizu_mizh_check(const void *base, size_t size,
1249 int *wire_type, int64_t *n_elems, int64_t valid[2]);
1250MIZU_API void mizu_mizh_validity_set(void *base, int64_t off,
1251 int64_t count);
1252MIZU_API int mizu_mizs_check(const void *base, size_t size, int64_t *n,
1253 int64_t *str_size, int64_t *attrs_size);
1254MIZU_API int mizu_mizl_check(const void *base, size_t size, int64_t *n,
1255 int64_t *attrs_off, int64_t *attrs_size,
1256 int64_t valid[2]);
1257MIZU_API int mizu_mizl_elem(const void *base, size_t size, int64_t i,
1258 mizu_mizl_entry *elem);
1259MIZU_API uint64_t mizu_na_build(int type, uint8_t *bitmap, const void *src,
1260 uint64_t n, uint64_t bit_off);
1261MIZU_API uint64_t mizu_na_apply(int type, void *dst, const void *src,
1262 const uint8_t *bitmap, uint64_t n);
1263#else
1269MIZU_EXT_INLINE double mizu_timeout_ms(double seconds) {
1270 if (!isfinite(seconds)) return -1;
1271 if (seconds <= 0) return 0;
1272 const double ms = seconds * 1000;
1273 return isfinite(ms) ? ms : -1;
1274}
1275MIZU_EXT_INLINE void mizu_store_na_real(void *dst) {
1276 const uint64_t bits = MIZU_NA_REAL_BITS;
1277 memcpy(dst, &bits, 8);
1278}
1280MIZU_EXT_INLINE uint64_t mizu_aux_rawspill_pool(int type, uint32_t name_len) {
1281 return (uint64_t) (uint32_t) type | ((uint64_t) name_len << 8);
1282}
1284MIZU_EXT_INLINE uint64_t mizu_aux_shm_vec(int type, uint64_t total) {
1285 return (uint64_t) (uint32_t) type | (total << 8);
1286}
1291 return (int) (aux & 0xff);
1292}
1293MIZU_EXT_INLINE uint64_t mizu_aux_hi(uint64_t aux) {
1294 return aux >> 8;
1295}
1300MIZU_EXT_INLINE void mizu_mizh_write(void *base, int wire_type,
1301 int64_t n_elems) {
1302 const uint32_t magic = MIZU_MAGIC_VEC;
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);
1310}
1317MIZU_EXT_INLINE int mizu_mizh_check(const void *base, size_t size,
1318 int *wire_type, int64_t *n_elems,
1319 int64_t valid[2]) {
1320 return mizu_ext_mizh_check_impl(base, size, wire_type, n_elems, valid);
1321}
1325MIZU_EXT_INLINE void mizu_mizh_validity_set(void *base, int64_t off,
1326 int64_t count) {
1327 memcpy((unsigned char *) base + MIZU_HDR_VALID_OFF, &off, 8);
1328 memcpy((unsigned char *) base + MIZU_HDR_VALID_COUNT, &count, 8);
1329}
1335MIZU_EXT_INLINE int mizu_mizs_check(const void *base, size_t size,
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);
1339}
1345MIZU_EXT_INLINE int mizu_mizl_check(const void *base, size_t 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,
1349 valid);
1350}
1355MIZU_EXT_INLINE int mizu_mizl_elem(const void *base, size_t size, int64_t i,
1356 mizu_mizl_entry *elem) {
1357 return mizu_ext_mizl_elem_impl(base, size, i, elem);
1358}
1363MIZU_EXT_INLINE uint64_t mizu_na_build(int type, uint8_t *bitmap,
1364 const void *src, uint64_t n,
1365 uint64_t bit_off) {
1366 return mizu_ext_na_build_impl(type, bitmap, src, n, bit_off);
1367}
1371MIZU_EXT_INLINE uint64_t mizu_na_apply(int type, void *dst, const void *src,
1372 const uint8_t *bitmap, uint64_t n) {
1373 return mizu_ext_na_apply_impl(type, dst, src, bitmap, n);
1374}
1375#endif
1376
1377// The interchange stream ('I') ---------------------------------------------------
1378
1392#define MIZU_IX_VERSION 0x01u
1393#define MIZU_IX_DEPTH_MAX 64
1394
1396enum {
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
1417};
1418
1429enum {
1430 MIZU_IX_NIL = 0,
1447
1466
1470typedef struct mizu_ix_s {
1471 const unsigned char *p;
1472 const unsigned char *end;
1473 uint32_t depth;
1474 int done;
1475 int err;
1476 struct {
1477 uint32_t kind;
1478 uint64_t remaining;
1479 } stack[MIZU_IX_DEPTH_MAX];
1481
1487MIZU_API mizu_status mizu_ix_open(mizu_ix *cur, const void *buf, size_t len);
1496
1508 size_t len, mizu_ix_item *item,
1509 int max_kind);
1516
1521#define MIZU_IX_ERR_OVERHEAD 25u
1522#define MIZU_IX_ERR_TYPE_SHARE 128u
1523
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"
1538
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"
1545
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"
1551
1555MIZU_EXT_INLINE int mizu_ext_ix_utf8_valid_impl(const void *s, size_t n) {
1558 const unsigned char *b = (const unsigned char *) s;
1559 size_t i = 0;
1560 while (i < n) {
1561 const unsigned char c = b[i];
1562 if (c < 0x80) {
1563 i++;
1564 } else if (c < 0xC2 || c >= 0xF5) { /* stray cont., overlong, or
1565 past U+10FFFF */
1566 return 0;
1567 } else if (c < 0xE0) { /* 2 bytes */
1568 if (i + 2 > n || (b[i + 1] & 0xC0) != 0x80) return 0;
1569 i += 2;
1570 } else if (c < 0xF0) { /* 3 bytes */
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; /* overlong */
1574 if (c == 0xED && b[i + 1] >= 0xA0) return 0; /* surrogate */
1575 i += 3;
1576 } else { /* 4 bytes: 0xF0..0xF4 */
1577 if (i + 4 > n || (b[i + 1] & 0xC0) != 0x80 ||
1578 (b[i + 2] & 0xC0) != 0x80 || (b[i + 3] & 0xC0) != 0x80)
1579 return 0;
1580 if (c == 0xF0 && b[i + 1] < 0x90) return 0; /* overlong */
1581 if (c == 0xF4 && b[i + 1] > 0x8F) return 0; /* > U+10FFFF */
1582 i += 4;
1583 }
1584 }
1585 return 1;
1586}
1587
1591 switch (wire_type) {
1592 case MIZU_TYPE_LGL: return MIZU_IX_TAG_LGLV;
1593 case MIZU_TYPE_INT: return MIZU_IX_TAG_INTV;
1594 case MIZU_TYPE_REAL: return MIZU_IX_TAG_REALV;
1595 case MIZU_TYPE_CPLX: return MIZU_IX_TAG_CPLXV;
1596 case MIZU_TYPE_RAW: return MIZU_IX_TAG_RAWV;
1597 case MIZU_TYPE_INT64: return MIZU_IX_TAG_I64V;
1598 default: return MIZU_IX_TAG_NIL;
1599 }
1600}
1601
1607 if (dst != NULL) {
1608 dst[0] = (unsigned char) MIZU_INTEROP_MAGIC;
1609 dst[1] = (unsigned char) MIZU_IX_VERSION;
1610 }
1611 return 2;
1612}
1613
1615 uint32_t tag, uint64_t v) {
1617 if (dst != NULL) {
1618 dst[0] = (unsigned char) tag;
1619 memcpy(dst + 1, &v, 8);
1620 }
1621 return 9;
1622}
1623
1624MIZU_EXT_INLINE size_t mizu_ext_ix_put_nil_impl(unsigned char *dst) {
1625 if (dst != NULL) dst[0] = MIZU_IX_TAG_NIL;
1626 return 1;
1627}
1628
1629MIZU_EXT_INLINE size_t mizu_ext_ix_put_lgl_impl(unsigned char *dst,
1630 int value) {
1631 if (dst != NULL) {
1632 dst[0] = MIZU_IX_TAG_LGL1;
1633 dst[1] = (unsigned char) value;
1634 }
1635 return 2;
1636}
1637
1638MIZU_EXT_INLINE size_t mizu_ext_ix_put_int_impl(unsigned char *dst,
1639 int64_t value) {
1640 if (dst != NULL) {
1641 dst[0] = MIZU_IX_TAG_INT;
1642 memcpy(dst + 1, &value, 8);
1643 }
1644 return 9;
1645}
1646
1647MIZU_EXT_INLINE size_t mizu_ext_ix_put_real_impl(unsigned char *dst,
1648 double value) {
1649 if (dst != NULL) {
1650 dst[0] = MIZU_IX_TAG_REAL;
1651 memcpy(dst + 1, &value, 8);
1652 }
1653 return 9;
1654}
1655
1656MIZU_EXT_INLINE size_t mizu_ext_ix_put_cplx_impl(unsigned char *dst,
1657 double re, double im) {
1658 if (dst != NULL) {
1659 dst[0] = MIZU_IX_TAG_CPLX;
1660 memcpy(dst + 1, &re, 8);
1661 memcpy(dst + 9, &im, 8);
1662 }
1663 return 17;
1664}
1665
1666MIZU_EXT_INLINE size_t mizu_ext_ix_put_str_impl(unsigned char *dst,
1667 const void *s, int32_t len) {
1668 if (dst != NULL) {
1669 dst[0] = MIZU_IX_TAG_STR;
1670 memcpy(dst + 1, &len, 4);
1671 if (len > 0) memcpy(dst + 5, s, (size_t) len);
1672 }
1673 return (size_t) 5 + (len > 0 ? (size_t) len : 0);
1674}
1675
1676MIZU_EXT_INLINE size_t mizu_ext_ix_put_bytes_impl(unsigned char *dst,
1677 const void *data,
1678 uint64_t count) {
1679 if (dst != NULL) {
1680 dst[0] = MIZU_IX_TAG_BYTES;
1681 memcpy(dst + 1, &count, 8);
1682 if (count != 0) memcpy(dst + 9, data, (size_t) count);
1683 }
1684 return (size_t) 9 + (size_t) count;
1685}
1686
1687MIZU_EXT_INLINE size_t mizu_ext_ix_put_vec_impl(unsigned char *dst,
1688 int wire_type,
1689 const void *data,
1690 uint64_t count) {
1691 const int tag = mizu_ext_ix_tag_of_impl(wire_type);
1692 if (tag == MIZU_IX_TAG_NIL) return 0;
1693 const size_t elt = mizu_type_elt_size(wire_type);
1694 if (dst != NULL) {
1695 dst[0] = (unsigned char) tag;
1696 memcpy(dst + 1, &count, 8);
1697 if (count != 0) memcpy(dst + 9, data, (size_t) count * elt);
1698 }
1699 return (size_t) 9 + (size_t) count * elt;
1700}
1701
1702MIZU_EXT_INLINE size_t mizu_ext_ix_put_strv_begin_impl(unsigned char *dst,
1703 uint64_t count) {
1704 return mizu_ext_ix_put_tag8_impl(dst, MIZU_IX_TAG_STRV, count);
1705}
1706
1707MIZU_EXT_INLINE size_t mizu_ext_ix_put_strelt_impl(unsigned char *dst,
1708 const void *s,
1709 int32_t len) {
1710 if (dst != NULL) {
1711 memcpy(dst, &len, 4);
1712 if (len > 0) memcpy(dst + 4, s, (size_t) len);
1713 }
1714 return (size_t) 4 + (len > 0 ? (size_t) len : 0);
1715}
1716
1717MIZU_EXT_INLINE size_t mizu_ext_ix_put_list_begin_impl(unsigned char *dst,
1718 uint64_t count) {
1719 return mizu_ext_ix_put_tag8_impl(dst, MIZU_IX_TAG_LIST, count);
1720}
1721
1722MIZU_EXT_INLINE size_t mizu_ext_ix_put_dict_begin_impl(unsigned char *dst,
1723 uint64_t count) {
1724 return mizu_ext_ix_put_tag8_impl(dst, MIZU_IX_TAG_DICT, count);
1725}
1726
1727MIZU_EXT_INLINE size_t mizu_ext_ix_put_key_impl(unsigned char *dst,
1728 const void *s, uint32_t len) {
1729 if (dst != NULL) {
1730 memcpy(dst, &len, 4);
1731 if (len != 0) memcpy(dst + 4, s, (size_t) len);
1732 }
1733 return (size_t) 4 + (size_t) len;
1734}
1735
1736MIZU_EXT_INLINE size_t mizu_ext_ix_put_attr_impl(unsigned char *dst) {
1737 if (dst != NULL) dst[0] = MIZU_IX_TAG_ATTR;
1738 return 1;
1739}
1740
1741MIZU_EXT_INLINE size_t mizu_ext_ix_put_err_impl(unsigned char *dst,
1742 int has_index, uint64_t index,
1743 const void *type,
1744 uint32_t type_len,
1745 const void *message,
1746 uint32_t message_len,
1747 const void *detail,
1748 uint32_t detail_len) {
1749 if (dst != NULL) {
1750 const uint16_t flags = (uint16_t) (has_index != 0);
1751 dst[0] = MIZU_IX_TAG_ERR;
1752 memcpy(dst + 1, &flags, 2);
1753 size_t off = 3;
1754 if (has_index) {
1755 memcpy(dst + off, &index, 8);
1756 off += 8;
1757 }
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);
1762 off += 4;
1763 if (lens[i] != 0) {
1764 memcpy(dst + off, strs[i], (size_t) lens[i]);
1765 off += (size_t) lens[i];
1766 }
1767 }
1768 return off;
1769 }
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;
1773}
1774
1775MIZU_EXT_INLINE size_t mizu_ext_ix_put_task_impl(unsigned char *dst,
1776 int target, int kind,
1777 uint64_t ident) {
1778 if (dst != NULL) {
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);
1785 }
1786 return 13;
1787}
1788
1790 const void *name,
1791 uint32_t name_len) {
1794 if (name_len == 0 || name_len > 255) return 0;
1795 if (dst != NULL) {
1796 dst[0] = MIZU_IX_TAG_REF;
1797 dst[1] = (unsigned char) name_len;
1798 memcpy(dst + 2, name, (size_t) name_len);
1799 }
1800 return (size_t) 2 + name_len;
1801}
1802
1803MIZU_EXT_INLINE size_t mizu_ext_ix_err_floor_impl(const void *s, size_t n,
1804 size_t share) {
1807 if (n <= share) return n;
1808 const unsigned char *b = (const unsigned char *) s;
1809 size_t len = share;
1810 while (len > 0 && (b[len] & 0xC0) == 0x80) len--;
1811 return len;
1812}
1813
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 =
1827 budget > MIZU_IX_ERR_OVERHEAD ? budget - MIZU_IX_ERR_OVERHEAD : 0;
1828 size_t cap =
1829 avail < MIZU_IX_ERR_TYPE_SHARE ? avail : MIZU_IX_ERR_TYPE_SHARE;
1830 const size_t tn = mizu_ext_ix_err_floor_impl(type, type_n, cap);
1831 cap = budget / 2;
1832 if (cap > avail - tn) cap = avail - tn;
1833 const size_t mn = mizu_ext_ix_err_floor_impl(msg, msg_n, cap);
1834 const size_t dn =
1835 mizu_ext_ix_err_floor_impl(detail, detail_n, avail - tn - mn);
1836 size_t n = mizu_ext_ix_put_header_impl(dst);
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);
1840 return n;
1841}
1842
1843#ifdef MIZU_EXT_NO_INLINES
1844MIZU_API int mizu_ix_utf8_valid(const void *s, size_t n);
1845MIZU_API int mizu_ix_tag_of(int wire_type);
1846MIZU_API size_t mizu_ix_put_header(unsigned char *dst);
1847MIZU_API size_t mizu_ix_put_nil(unsigned char *dst);
1848MIZU_API size_t mizu_ix_put_lgl(unsigned char *dst, int value);
1849MIZU_API size_t mizu_ix_put_int(unsigned char *dst, int64_t value);
1850MIZU_API size_t mizu_ix_put_real(unsigned char *dst, double value);
1851MIZU_API size_t mizu_ix_put_cplx(unsigned char *dst, double re, double im);
1852MIZU_API size_t mizu_ix_put_str(unsigned char *dst, const void *s,
1853 int32_t len);
1854MIZU_API size_t mizu_ix_put_bytes(unsigned char *dst, const void *data,
1855 uint64_t count);
1856MIZU_API size_t mizu_ix_put_vec(unsigned char *dst, int wire_type,
1857 const void *data, uint64_t count);
1858MIZU_API size_t mizu_ix_put_strv_begin(unsigned char *dst, uint64_t count);
1859MIZU_API size_t mizu_ix_put_strelt(unsigned char *dst, const void *s,
1860 int32_t len);
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);
1863MIZU_API size_t mizu_ix_put_key(unsigned char *dst, const void *s,
1864 uint32_t len);
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,
1867 uint64_t 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);
1871MIZU_API size_t mizu_ix_put_task(unsigned char *dst, int target, int kind,
1872 uint64_t ident);
1873MIZU_API size_t mizu_ix_put_ref(unsigned char *dst, const void *name,
1874 uint32_t name_len);
1875MIZU_API size_t mizu_ix_write_err(unsigned char *dst, uint32_t inline_max,
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);
1880#else
1891MIZU_EXT_INLINE int mizu_ix_utf8_valid(const void *s, size_t n) {
1892 return mizu_ext_ix_utf8_valid_impl(s, n);
1893}
1899 return mizu_ext_ix_tag_of_impl(wire_type);
1900}
1901MIZU_EXT_INLINE size_t mizu_ix_put_header(unsigned char *dst) {
1902 return mizu_ext_ix_put_header_impl(dst);
1903}
1904MIZU_EXT_INLINE size_t mizu_ix_put_nil(unsigned char *dst) {
1905 return mizu_ext_ix_put_nil_impl(dst);
1906}
1908MIZU_EXT_INLINE size_t mizu_ix_put_lgl(unsigned char *dst, int value) {
1909 return mizu_ext_ix_put_lgl_impl(dst, value);
1910}
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);
1913}
1916MIZU_EXT_INLINE size_t mizu_ix_put_real(unsigned char *dst, double value) {
1917 return mizu_ext_ix_put_real_impl(dst, value);
1918}
1919MIZU_EXT_INLINE size_t mizu_ix_put_cplx(unsigned char *dst, double re,
1920 double im) {
1921 return mizu_ext_ix_put_cplx_impl(dst, re, im);
1922}
1924MIZU_EXT_INLINE size_t mizu_ix_put_str(unsigned char *dst, const void *s,
1925 int32_t len) {
1926 return mizu_ext_ix_put_str_impl(dst, s, len);
1927}
1928MIZU_EXT_INLINE size_t mizu_ix_put_bytes(unsigned char *dst,
1929 const void *data, uint64_t count) {
1930 return mizu_ext_ix_put_bytes_impl(dst, data, count);
1931}
1935MIZU_EXT_INLINE size_t mizu_ix_put_vec(unsigned char *dst, int wire_type,
1936 const void *data, uint64_t count) {
1937 return mizu_ext_ix_put_vec_impl(dst, wire_type, data, count);
1938}
1939MIZU_EXT_INLINE size_t mizu_ix_put_strv_begin(unsigned char *dst,
1940 uint64_t count) {
1941 return mizu_ext_ix_put_strv_begin_impl(dst, count);
1942}
1944MIZU_EXT_INLINE size_t mizu_ix_put_strelt(unsigned char *dst, const void *s,
1945 int32_t len) {
1946 return mizu_ext_ix_put_strelt_impl(dst, s, len);
1947}
1948MIZU_EXT_INLINE size_t mizu_ix_put_list_begin(unsigned char *dst,
1949 uint64_t count) {
1950 return mizu_ext_ix_put_list_begin_impl(dst, count);
1951}
1952MIZU_EXT_INLINE size_t mizu_ix_put_dict_begin(unsigned char *dst,
1953 uint64_t count) {
1954 return mizu_ext_ix_put_dict_begin_impl(dst, count);
1955}
1957MIZU_EXT_INLINE size_t mizu_ix_put_key(unsigned char *dst, const void *s,
1958 uint32_t len) {
1959 return mizu_ext_ix_put_key_impl(dst, s, len);
1960}
1961MIZU_EXT_INLINE size_t mizu_ix_put_attr(unsigned char *dst) {
1962 return mizu_ext_ix_put_attr_impl(dst);
1963}
1964MIZU_EXT_INLINE size_t mizu_ix_put_err(unsigned char *dst, int has_index,
1965 uint64_t index,
1966 const void *type, uint32_t type_len,
1967 const void *message,
1968 uint32_t message_len,
1969 const void *detail,
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);
1973}
1976MIZU_EXT_INLINE size_t mizu_ix_put_task(unsigned char *dst, int target,
1977 int kind, uint64_t ident) {
1978 return mizu_ext_ix_put_task_impl(dst, target, kind, ident);
1979}
1981MIZU_EXT_INLINE size_t mizu_ix_put_ref(unsigned char *dst, const void *name,
1982 uint32_t name_len) {
1983 return mizu_ext_ix_put_ref_impl(dst, name, name_len);
1984}
1993MIZU_EXT_INLINE size_t mizu_ix_write_err(unsigned char *dst,
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) {
1999 return mizu_ext_ix_write_err_impl(dst, inline_max, type, type_n, msg,
2000 msg_n, detail, detail_n, has_index,
2001 index);
2002}
2003#endif
2004
2005// The Arrow frame writer (arrow.c) -----------------------------------------------
2006
2014#ifndef ARROW_C_DATA_INTERFACE
2015#define ARROW_C_DATA_INTERFACE
2016typedef struct ArrowSchema {
2017 const char *format;
2018 const char *name;
2019 const char *metadata;
2020 int64_t flags;
2021 int64_t n_children;
2022 struct ArrowSchema **children;
2023 struct ArrowSchema *dictionary;
2024 void (*release)(struct ArrowSchema *);
2025 void *private_data;
2026} ArrowSchema;
2027
2028typedef struct ArrowArray {
2029 int64_t length;
2030 int64_t null_count;
2031 int64_t offset;
2032 int64_t n_buffers;
2033 int64_t n_children;
2034 const void **buffers;
2035 struct ArrowArray **children;
2036 struct ArrowArray *dictionary;
2037 void (*release)(struct ArrowArray *);
2038 void *private_data;
2039} ArrowArray;
2040#endif
2041
2042#ifndef ARROW_C_STREAM_INTERFACE
2043#define ARROW_C_STREAM_INTERFACE
2044typedef struct ArrowArrayStream {
2045 int (*get_schema)(struct ArrowArrayStream *, struct ArrowSchema *out);
2046 int (*get_next)(struct ArrowArrayStream *, struct ArrowArray *out);
2047 const char *(*get_last_error)(struct ArrowArrayStream *);
2048 void (*release)(struct ArrowArrayStream *);
2049 void *private_data;
2051#endif
2052
2053/* The element helpers: pure accessors over the ABI structs, dual-form like
2054 the 'I' cursor's — the frame writer's own loops and a binding's 'I'
2055 emitters share the one definition. */
2056MIZU_EXT_INLINE int mizu_ext_arrow_valid_impl(const ArrowArray *arr,
2057 int64_t k) {
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;
2062}
2063
2064MIZU_EXT_INLINE int mizu_ext_arrow_str_at_impl(const ArrowArray *arr,
2065 int64_t k, int form,
2066 const uint8_t **ptr,
2067 int32_t *len) {
2068 if (!mizu_ext_arrow_valid_impl(arr, k)) return 0;
2069 int64_t i = arr->offset + k;
2070 if (form == 1) {
2071 const uint8_t *offs = (const uint8_t *) arr->buffers[1];
2072 int32_t o0, o1;
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;
2077 *len = o1 - o0;
2078 } else if (form == 2) {
2079 const uint8_t *offs = (const uint8_t *) arr->buffers[1];
2080 int64_t o0, o1;
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)
2084 return -1;
2085 *ptr = (const uint8_t *) arr->buffers[2] + o0;
2086 *len = (int32_t) (o1 - o0);
2087 } else {
2088 const uint8_t *vw = (const uint8_t *) arr->buffers[1] + i * 16;
2089 int32_t l;
2090 memcpy(&l, vw, 4);
2091 if (l < 0) return -1;
2092 if (l <= 12) {
2093 *ptr = vw + 4;
2094 } else {
2095 int32_t bi, off;
2096 memcpy(&bi, vw + 8, 4);
2097 memcpy(&off, vw + 12, 4);
2098 /* The variadic data buffers are slots [2, n_buffers): the C Data
2099 spec's trailing slot is the int64 sizes array, but a producer
2100 that skips it (a nanoarrow nested or standalone export) puts a
2101 data buffer there. The reference tells the layouts apart: a
2102 spec-layout view never names the trailing slot, so one that
2103 does proves the no-sizes layout, its span the producer's word;
2104 any other span the sizes array bounds by the declared size. */
2105 if (bi < 0 || off < 0 || 2 + (int64_t) bi >= arr->n_buffers)
2106 return -1;
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) {
2111 int64_t sz;
2112 memcpy(&sz, sizes + 8 * (ptrdiff_t) bi, 8);
2113 if ((int64_t) off + l > sz) return -1;
2114 }
2115 }
2116 *ptr = (const uint8_t *) arr->buffers[2 + bi] + off;
2117 }
2118 *len = l;
2119 }
2120 return 1;
2121}
2122
2123#ifdef MIZU_EXT_NO_INLINES
2124MIZU_API int mizu_arrow_valid(const ArrowArray *, int64_t k);
2125MIZU_API int mizu_arrow_str_at(const ArrowArray *, int64_t k, int form,
2126 const uint8_t **ptr, int32_t *len);
2127#else
2129MIZU_EXT_INLINE int mizu_arrow_valid(const ArrowArray *arr, int64_t k) {
2130 return mizu_ext_arrow_valid_impl(arr, k);
2131}
2143 int form, const uint8_t **ptr,
2144 int32_t *len) {
2145 return mizu_ext_arrow_str_at_impl(arr, k, form, ptr, len);
2146}
2147#endif
2148
2150#define MIZU_ARROW_FLAG_DICTIONARY_ORDERED 1
2151#define MIZU_ARROW_FLAG_NULLABLE 2
2152
2155enum {
2158 MIZU_CVT_I16_INT,
2161 MIZU_CVT_U64_REAL,
2168
2169typedef struct mizu_cvt_row_s {
2170 int wire;
2171 int cvt;
2172 uint8_t w_in;
2173 uint8_t w_out;
2174} mizu_cvt_row;
2175
2179typedef struct mizu_arrow_warn_s {
2180 uint64_t n_range;
2181 uint64_t n_intmin;
2182 uint64_t n_int64;
2184
2188
2195MIZU_API void mizu_cvt_convert(uint8_t *dst, const uint8_t *src,
2196 const uint8_t *valid, uint64_t off, size_t n,
2197 const mizu_cvt_row *row,
2198 mizu_arrow_warn *warn);
2199
2205typedef struct mizu_arrow mizu_arrow;
2206
2211enum {
2219
2227
2241 const ArrowSchema *schema,
2242 const ArrowArray *const *batches,
2243 size_t n_batches, uint32_t peer_caps);
2244
2247MIZU_API void mizu_arrow_col_info(const mizu_arrow *, int64_t col,
2248 mizu_arrow_col *out);
2249
2259MIZU_API size_t mizu_arrow_col_body(const mizu_arrow *, int64_t col,
2260 uint8_t *dst, mizu_arrow_warn *warn);
2261
2267MIZU_API size_t mizu_arrow_col_blob(const mizu_arrow *, int64_t col,
2268 uint8_t *dst);
2269
2276MIZU_API size_t mizu_arrow_write_ix_col(const mizu_arrow *, int64_t col,
2277 uint8_t *dst, mizu_arrow_warn *warn);
2278
2289MIZU_API size_t mizu_arrow_write_ix(const mizu_arrow *, uint8_t *dst,
2290 mizu_arrow_warn *warn);
2291
2301 const char *ident, size_t ident_len,
2302 void *ref_base, size_t ref_size,
2303 int64_t ref_leaf);
2304
2309 size_t len);
2310
2314MIZU_API void mizu_arrow_tz(mizu_arrow *, int64_t col, const char *tz);
2315
2320
2334 mizu_slot_hdr *hdr,
2335 unsigned char *payload,
2336 mizu_arrow_warn *warn);
2337MIZU_API void mizu_arrow_close(mizu_arrow *);
2338
2339// Utilities ----------------------------------------------------------------------
2340
2343MIZU_API double mizu_now(void);
2344MIZU_API long mizu_self_pid(void);
2345
2348MIZU_API void mizu_err_describe(mizu_errcat, const char **summary,
2349 const char **hint);
2350
2353MIZU_API void mizu_rng_jump(int *seed);
2354
2357
2358#ifdef __cplusplus
2359}
2360#endif
2361
2362#endif
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.h:150
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
Definition mizu.h:261
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