runtime.h

filter: Statementstmt 100% 7 / 7 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 95.2% 20 / 21 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« buffer.c ↑ Summary cityhash.c »
1 #ifndef CHE_RUNTIME_H
2 #define CHE_RUNTIME_H
3  
4 /* See buffer.h for the include-order convention (EXTERN.h + perl.h +
5 * XSUB.h must be included by the caller before this header). */
6  
7 #include "types.h"
8 #include "buffer.h"
9  
10 enum { DEFAULT_EMPTY_STRING = 1, DEFAULT_EXPRESSION = 2 };
11  
12 /* One column entry in an Encoder: name and type-string survive as
13 * heap-owned NUL-padded buffers; type is the parsed TypeInfo tree. */
14 typedef struct {
15 char *name;
16 STRLEN name_len;
17 char *type_str;
18 STRLEN type_len;
19 TypeInfo *type;
20 SV *default_value; /* unresolved expression when DEFAULT_EXPRESSION is set */
21 int default_flags;
22 } Column;
23  
24 452 PERL_STATIC_INLINE SV *column_value(pTHX_ Column *col, SV *value) {
25 452 ▶ if (col->default_value && (!SvOK(value)
Branch: 2 branches
BranchTrueFalseTotal
if (col->default_value && (!SvOK(value) 140 312 452
if (col->default_value && (!SvOK(value) 93 47 140
26 93 ▶ || ((col->default_flags & DEFAULT_EMPTY_STRING) && !SvROK(value) && SvPOK(value) && !SvCUR(value)))) {
Branch: 4 branches
BranchTrueFalseTotal
|| ((col->default_flags & DEFAULT_EMPTY_STRING) && !SvROK(value) && SvPOK(value) && !SvCUR(value)))) { 79 14 93
|| ((col->default_flags & DEFAULT_EMPTY_STRING) && !SvROK(value) && SvPOK(value) && !SvCUR(value)))) { 67 12 79
|| ((col->default_flags & DEFAULT_EMPTY_STRING) && !SvROK(value) && SvPOK(value) && !SvCUR(value)))) { 34 33 67
|| ((col->default_flags & DEFAULT_EMPTY_STRING) && !SvROK(value) && SvPOK(value) && !SvCUR(value)))) { 34 0 34
27 81 ▶ if (col->default_flags & DEFAULT_EXPRESSION)
Branch: 1 branch
BranchTrueFalseTotal
if (col->default_flags & DEFAULT_EXPRESSION) 14 67 81
28 28 croak("Column '%.*s' has non-literal DEFAULT '%s'; pass defaults => {'%.*s' => ...}",
29 (int)col->name_len, col->name, SvPV_nolen(col->default_value),
30 (int)col->name_len, col->name);
31 67 return col->default_value;
32 }
33 371 return value;
34 }
35  
36 typedef struct {
37 Column *columns;
38 int num_columns;
39 CHTimezone *zones;
40 char *timezone;
41 int empty_as_null;
42 } Encoder;
43  
44 /* Streamer: collects rows in an AV and flushes one Native block per
45 * batch. Holds strong refs to keep the underlying encoder/writer/buffer
46 * AVs alive for the streamer's lifetime. */
47 typedef struct {
48 SV *enc_sv; /* strong ref to keep the encoder alive */
49 Encoder *enc; /* unowned cached pointer */
50 SV *writer; /* strong ref to the writer CV */
51 AV *buffer; /* strong ref - owned */
52 int batch_size;
53 /* When non-NULL, every emitted batch is wrapped in CH's
54 * compressed-block framing via compress_native_block before being
55 * passed to writer. compress_mode is one of "lz4" / "zstd" /
56 * "auto" / "none"; hasher_sv (if non-NULL) overrides the default
57 * cityhash128. Both are owned by the Streamer. */
58 char *compress_mode;
59 SV *hasher_sv;
60 } Streamer;
61  
62 /* Encode `rows_av` (an AV of arrayrefs, one per row) into `buf`. Validates
63 * shape per Encoder schema; croaks on malformed input. */
64 void do_encode(pTHX_ Encoder *enc, AV *rows_av, Buffer *buf, const SSize_t *positions);
65 void configure_encoder(pTHX_ Encoder *enc, const char *timezone, int empty_as_null);
66 void configure_defaults(pTHX_ Encoder *enc, int empty_as_default, HV *defaults, HV *expressions);
67  
68 /* Encode `batch` into a fresh Native block and pass the bytes to `writer`.
69 * Wrapped in ENTER/SAVETMPS/FREETMPS/LEAVE so per-batch mortals don't
70 * accumulate on the caller's tmps stack across a long stream() loop. */
71 void encode_and_emit(pTHX_ Encoder *enc, AV *batch, SV *writer);
72  
73 /* Streamer flush: emits buffered rows (swap-before-emit so a writer croak
74 * leaves the streamer in a clean state). No-op when buffer is empty. */
75 void streamer_flush(pTHX_ Streamer *s);
76  
77 /* Free an Encoder and all its owned columns/types. NULL-safe. */
78 void free_encoder (pTHX_ Encoder *enc);
79 void free_streamer(pTHX_ Streamer *s);
80  
81 /* Slot-indirection cleanup callbacks for SAVEDESTRUCTOR_X: pass &slot
82 * where slot is the Encoder or Streamer pointer you just allocated.
83 * After the construction succeeds and the SV takes ownership, set
84 * slot = NULL to disarm. */
85 void cleanup_encoder_slot (pTHX_ void *p);
86 void cleanup_streamer_slot(pTHX_ void *p);
87  
88 #endif
« buffer.c ↑ Summary cityhash.c »