Artifact 13f6e5603a85cccaced19ee10988220d6aeea1d7f8e103c74e405a005e784e16:
- File typeparse/tests_tclsh/t84_codec_c_tailles.out — part of check-in [1a6fc7a4f8] at 2026-10-25 12:21:18 on branch tip-764_tcl90 — I have implemented the three points, delivered in v16d. The C codec now covers calculated sizes and prefixes, `at(...)`, and links. It produces the same bytes and values as the Tcl layer, with a performance gain of 30 to 100 times. 1. Calculated sizes and prefixes Length prefix: `string(utf-8,int(u,16,be))`, `string(raw,int(u,8))`, `list(int(u,8)).T`. Expressions based on previously read fields: `$len`, `$len - 4`, `($a + $b) * 2`, with `/` and `%` operators rounding toward negative infinity (matching Tcl’s `expr` behavior). Less common forms, such as `$h(off)` or a field from an external product, remain handled by the Tcl layer. 2. `at(EXPR).T` During reading, the value is retrieved from the calculated position without moving the cursor. During writing, the value is encoded separately and then placed at the specified position at the end, consistent with the Tcl layer’s behavior. 3. Links `*(ORIGIN,REPR).T` Origins: `//`, `.`, `./`, and `../`. Reading: Within a product, the target is read after all other fields; consequently, its size definitions may reference a field that appears later. Writing: Targets are written after the value, and their addresses are subsequently backfilled. `opt(T)` and linked lists: The C implementation supports up to 512 chained links; beyond this limit, the Tcl layer takes over. The following remain handled by the Tcl layer: named reference systems, finite `-linkdepth`, `-dedupe`, and null links for fields with a default value. Measurements, in µs, C codec vs. Tcl layer: |case | write | read | |:--------| ---- :| --------:| prefixed header | 1.3 / 36 | 1.7 / 54 | string(raw,$len) | 0.9 / 51 | 1.1 / 68 | at($off).list($n).pt| 1.9 / 107| 3.0 / 163 | two ./ links| 1.6 / 121| 1.6 / 108 | linked list of 400 nodes| 0.10 / 304 ms | 0.23 / 1,444 ms The Tcl layer exhibits quadratic behavior with linked lists, which accounts for the discrepancy in the last row. Fix implemented: A list of links in compact form (e.g., list($n).*(//,u8).rec) was being copied element-by-element, just like a list of ordinary values, without accounting for the links. This resulted in incorrect bytes being written. Verifications: All 64 tests pass, in both ordinary and compact forms. Three new tests cover these scenarios: t84, t85, and t86. All examples produce identical output, whether using the C codec or not. Valgrind reports no new issues, and a full `make test` run shows the same 61 failures as the reference. (user: Florentis, size: 1341) [annotate] [blame] [check-ins using]
pascal 13 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 010005c38974c3a90461620063 pascal nat 13 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 010005c38974c3a90461620063 blob 11 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 0500000068656c6c6f0700 texte -4 7 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 08006162636401 ($a+$b)*2 10 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 01000100020003000400 nat 10 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 01000100020003000400 / et % 4 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 07010209 préfixe liste 18 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 09030100020003000400050006004d000000 préfixe nat 20 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 090003000100020003000400050006004d000000 préfixe vide 6 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 09004d000000 préfixe tronqué : 1 012c00 écart : 1 type binary: field data of blob holds 5, but the field it depends on says 4 ($len) tronqué : 1 type binary: data truncated at offset 4 reading field data of blob (needs 9 bytes, got 3) préfixe tronqué lu : 1 type binary: data truncated at offset 3 reading field nom of pascal (needs 50 bytes, got 0) chemin 7 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 0000030078797a extérieur 4 octets C=Tcl 1 relu C=Tcl 1 relu=v 1 03616263 extérieur : 0