uproot-custom 2.6.0__tar.gz → 2.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/PKG-INFO +2 -2
  2. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/example/read-tobjarray.md +2 -5
  3. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/detree-dsl.md +7 -1
  4. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/tutorial/write-a-reader.md +1 -1
  5. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/pyproject.toml +1 -1
  6. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/detree/test_exec.py +126 -1
  7. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/detree/test_frontend.py +57 -1
  8. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/_version.py +3 -3
  9. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/compiler/frontend.py +22 -1
  10. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/compiler/ir_builder.py +6 -0
  11. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/stream.py +20 -0
  12. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.clang-format +0 -0
  13. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/release.yml +0 -0
  14. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/workflows/build-wheels.yml +0 -0
  15. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/workflows/deploy-docs.yml +0 -0
  16. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/workflows/python-publish.yml +0 -0
  17. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/workflows/semantic-pr-titles.yml +0 -0
  18. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/workflows/test-package.yml +0 -0
  19. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.github/workflows/weekly-build.yml +0 -0
  20. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.gitignore +0 -0
  21. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/.pre-commit-config.yaml +0 -0
  22. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/LICENSE +0 -0
  23. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/README.md +0 -0
  24. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/Doxyfile +0 -0
  25. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/_static/.gitkeep +0 -0
  26. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/advanced/cpp-reader.md +0 -0
  27. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/advanced/index.md +0 -0
  28. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/advanced/python-reader.md +0 -0
  29. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/concepts/choosing-a-route.md +0 -0
  30. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/concepts/how-it-works.md +0 -0
  31. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/conf.py +0 -0
  32. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/example/override-streamer.md +0 -0
  33. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/getting-started.md +0 -0
  34. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/index.md +0 -0
  35. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/api/.gitignore +0 -0
  36. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/api/cpp-api.md +0 -0
  37. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/api/uproot-custom-ref.md +0 -0
  38. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/api.md +0 -0
  39. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/binary-format.md +0 -0
  40. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/reference/version-requirements.md +0 -0
  41. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/tutorial/debug-a-reader.md +0 -0
  42. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/tutorial/index.md +0 -0
  43. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/tutorial/investigate-data.md +0 -0
  44. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/docs/tutorial/package-your-project.md +0 -0
  45. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/kernel/CMakeLists.txt +0 -0
  46. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/kernel/include/uproot-custom/uproot-custom.hh +0 -0
  47. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/kernel/share/cmake/uproot-customConfig.cmake +0 -0
  48. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/kernel/src/uproot-custom.cc +0 -0
  49. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/conftest.py +0 -0
  50. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_cstyle_array.root +0 -0
  51. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_pointers.root +0 -0
  52. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_primitive.root +0 -0
  53. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_pure_struct.root +0 -0
  54. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_root_objects.root +0 -0
  55. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_simple_obj.root +0 -0
  56. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_array.root +0 -0
  57. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_complicated.root +0 -0
  58. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_map.root +0 -0
  59. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_map_with_obj.root +0 -0
  60. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_nested.root +0 -0
  61. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_seq_with_obj.root +0 -0
  62. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_sequence.root +0 -0
  63. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/data/test_stl_string.root +0 -0
  64. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/detree/conftest.py +0 -0
  65. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/detree/test_decl.py +0 -0
  66. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/detree/test_machine.py +0 -0
  67. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/detree/test_pipeline.py +0 -0
  68. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/CMakeLists.txt +0 -0
  69. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/README.md +0 -0
  70. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/LinkDef.h +0 -0
  71. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TBasicTypes.hh +0 -0
  72. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TCStyleArray.hh +0 -0
  73. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TComplicatedSTL.hh +0 -0
  74. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TNestedSTL.hh +0 -0
  75. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TPointers.hh +0 -0
  76. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TPureStruct.hh +0 -0
  77. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TRootObjects.hh +0 -0
  78. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSTLArray.hh +0 -0
  79. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSTLMap.hh +0 -0
  80. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSTLMapWithObj.hh +0 -0
  81. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSTLSeqWithObj.hh +0 -0
  82. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSTLSequence.hh +0 -0
  83. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSTLString.hh +0 -0
  84. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/include/TSimpleObject.hh +0 -0
  85. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/gen-test-data/src/main.cc +0 -0
  86. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/test_AsCustom.py +0 -0
  87. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/test_claim.py +0 -0
  88. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/test_cpp_stream.py +0 -0
  89. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/test_python_stream.py +0 -0
  90. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/tests/test_readers.py +0 -0
  91. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/__init__.py +0 -0
  92. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/_forth.py +0 -0
  93. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/backend.py +0 -0
  94. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/consts.py +0 -0
  95. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/cpp/__init__.py +0 -0
  96. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/cpp/kernel.pyi +0 -0
  97. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/__init__.py +0 -0
  98. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/bufferproxy.py +0 -0
  99. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/builtin.py +0 -0
  100. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/cache.py +0 -0
  101. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/compiler/__init__.py +0 -0
  102. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/decl.py +0 -0
  103. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/interp.py +0 -0
  104. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/detree/run.py +0 -0
  105. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/factories.py +0 -0
  106. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/interpretation.py +0 -0
  107. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/python.py +0 -0
  108. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/share/cmake/__init__.py +0 -0
  109. {uproot_custom-2.6.0 → uproot_custom-2.6.1}/uproot_custom/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: uproot-custom
3
- Version: 2.6.0
3
+ Version: 2.6.1
4
4
  Summary: Uproot extension for reading custom classes
5
5
  Author-Email: Mingrun Li <mrli@ihep.ac.cn>
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -31,7 +31,7 @@ Requires-Python: <3.15,>=3.9
31
31
  Requires-Dist: uproot>=5.6.7
32
32
  Requires-Dist: numpy
33
33
  Requires-Dist: awkward>=2.8.0
34
- Requires-Dist: detree-vm>=0.1.1
34
+ Requires-Dist: detree-vm>=0.1.2
35
35
  Description-Content-Type: text/markdown
36
36
 
37
37
  # Introduction
@@ -230,10 +230,7 @@ class TObjArrayReader(Reader):
230
230
  stream.skip_fVersion()
231
231
  stream.skip_TObject()
232
232
 
233
- size = stream.read_uint8() # fName is a TString
234
- if size == 255:
235
- size = stream.read_uint32()
236
- stream.skip(size)
233
+ stream.skip_TString() # fName
237
234
 
238
235
  fSize = stream.read_uint32()
239
236
  stream.skip(4) # fLowerBound
@@ -452,7 +449,7 @@ class TObjArrayReader(IReader):
452
449
  return np.asarray(self.offsets), self.element_reader.data()
453
450
  ```
454
451
 
455
- The Python reader reads the `TString` name with `read_TString()`; the Detree version skips it by length. See [stage 1 of the route](../advanced/python-reader.md).
452
+ The Python reader reads the `TString` name with `read_TString()`; the Detree reader skips it with `skip_TString()`, since the value is not used. See [stage 1 of the route](../advanced/python-reader.md).
456
453
  ````
457
454
 
458
455
  ````{tab-item} C++ reader
@@ -80,7 +80,7 @@ Implement `read_many_memberwise` when the reader can appear in a memberwise-stor
80
80
  | statements | `if`/`else`, `while`, `for _ in range(n)`, `for child in self.<ChildList>`, `with stream.check_nbytes():`, `assert`, `pass`, assignment to a local, a `State`, or `stream.cursor` |
81
81
  | integer and boolean expressions | `+ - * // / % << >> & \| ^ ~`, unary `-`, comparisons, `if` expression, `and`/`or`/`not` in conditions, `bool()`, `int()` |
82
82
  | buffers | `buf.append(x)`, `len(buf)`, `buf[-1]` |
83
- | stream | the scalar `read_*` methods, `read_into`, `read_bulk`, `read_fNBytes`, `read_fVersion`, `read_null_terminated_string`, `skip` and the `skip_*` helpers, `next_offset_after`, `check_nbytes_start`, `check_nbytes_end`, `cursor`, `entries`, `initial_cursor_position`, `has_ref`, `ref_*`, `set_*_ref`, `check_class_name` |
83
+ | stream | the scalar `read_*` methods, `read_into`, `read_bulk`, `read_fNBytes`, `read_fVersion`, `read_null_terminated_string`, `read_TString`, `skip_TString`, `skip` and the `skip_*` helpers, `next_offset_after`, `check_nbytes_start`, `check_nbytes_end`, `cursor`, `entries`, `initial_cursor_position`, `has_ref`, `ref_*`, `set_*_ref`, `check_class_name` |
84
84
  | names | module-level `int` and `bool` constants, e.g. `kByteCountMask` |
85
85
 
86
86
  | Not allowed | Reason |
@@ -96,6 +96,12 @@ Implement `read_many_memberwise` when the reader can appear in a memberwise-stor
96
96
 
97
97
  A construct outside the subset fails with `ReaderContractError` (when the class is defined) or `UnsupportedNode` (when the reader is compiled), naming the method and the offending line. Rewrite the reader, or take the [Python + C++ route](../advanced/index.md); there is no fallback for a reader the compiler rejects.
98
98
 
99
+ ### Strings and names
100
+
101
+ `stream.read_null_terminated_string()` and `stream.read_TString()` return an interned name: a `str` in Python, and an id into the machine's string arena in the compiled module. Store it in a `State(str, ...)`, compare it with `==`/`!=` against a string, or pass it to `stream.check_class_name()`. `len()` applies to buffers only, so a reader that needs the character count reads the bytes into a `Buffer("B")` with `read_bulk` instead. `data()` runs after the run and sees the decoded `str` for a string state.
102
+
103
+ `read_TString` compiles to `SREAD_TSTR`, which reads ROOT's `1`-byte length (or `0xFF` followed by a `uint32`) and interns the characters; a length past the end of the event fails the run. `stream.skip_TString()` consumes the same layout without interning anything, for a name the reader does not need.
104
+
99
105
  ## Counted regions
100
106
 
101
107
  A ROOT object framed by its byte count declares how many bytes follow it. Write the frame as a `with` block and the machine checks where it ends:
@@ -368,7 +368,7 @@ The read path must stay inside a small subset of Python:
368
368
  | statements | `if`/`else`, `while`, `for _ in range(n)`, `for child in self.<ChildList>`, `with stream.check_nbytes():`, `assert`, assignment to a local, a `State`, or `stream.cursor` |
369
369
  | expressions | integer and boolean arithmetic and comparisons, `and`/`or`/`not`, `if` expressions, `bool()`, `int()` |
370
370
  | buffers | `buf.append(x)`, `len(buf)`, `buf[-1]` |
371
- | stream | the scalar `read_*` methods, `read_into`, `read_bulk`, `skip` and the `skip_*` helpers, `next_offset_after`, the reference helpers |
371
+ | stream | the scalar `read_*` methods, `read_into`, `read_bulk`, `read_TString`, `skip_TString`, `skip` and the `skip_*` helpers, `next_offset_after`, the reference helpers |
372
372
 
373
373
  | Not allowed | Use instead |
374
374
  | ----------- | ----------- |
@@ -48,7 +48,7 @@ classifiers = [
48
48
  "Topic :: Software Development",
49
49
  "Topic :: Utilities"
50
50
  ]
51
- dependencies = ["uproot>=5.6.7", "numpy", "awkward>=2.8.0", "detree-vm>=0.1.1"]
51
+ dependencies = ["uproot>=5.6.7", "numpy", "awkward>=2.8.0", "detree-vm>=0.1.2"]
52
52
  description = "Uproot extension for reading custom classes"
53
53
  dynamic = ["version"]
54
54
  name = "uproot-custom"
@@ -30,7 +30,7 @@ from uproot_custom.consts import (
30
30
  kStreamedMemberwise,
31
31
  )
32
32
  from uproot_custom.detree import interp
33
- from uproot_custom.detree.decl import Buffer, Reader, reader
33
+ from uproot_custom.detree.decl import Buffer, Reader, State, reader
34
34
  from uproot_custom.detree.run import read_data
35
35
 
36
36
 
@@ -366,6 +366,131 @@ def test_a_counted_reader_reports_a_wrong_byte_count():
366
366
  read_data(reader, payload, [0, len(payload)])
367
367
 
368
368
 
369
+ # -- length-prefixed strings ---------------------------------------------------
370
+ class _TStringValueReader(python.IReader):
371
+ """
372
+ The python-backend form of `_TStringSlotReader`.
373
+ """
374
+
375
+ def __init__(self, name):
376
+ super().__init__(name)
377
+ self.value = ""
378
+
379
+ def read(self, stream):
380
+ self.value = stream.read_TString()
381
+
382
+ def data(self):
383
+ return self.value
384
+
385
+
386
+ @reader
387
+ class _TStringSlotReader(Reader):
388
+ """
389
+ One `TString`, kept in a name slot so `data` can return it.
390
+ """
391
+
392
+ value = State(str, "")
393
+
394
+ def read(self, stream):
395
+ self.value = stream.read_TString()
396
+
397
+ def data(self):
398
+ return self.value
399
+
400
+
401
+ def test_read_tstring_short_form():
402
+ payload = struct.pack(">B", 3) + b"abc"
403
+ assert (
404
+ _check(
405
+ _TStringValueReader("s"),
406
+ _TStringSlotReader("s"),
407
+ payload,
408
+ [0, len(payload)],
409
+ )
410
+ == "abc"
411
+ )
412
+
413
+
414
+ def test_read_tstring_long_form():
415
+ payload = struct.pack(">B", 255) + struct.pack(">I", 5) + b"hello"
416
+ assert (
417
+ _check(
418
+ _TStringValueReader("s"),
419
+ _TStringSlotReader("s"),
420
+ payload,
421
+ [0, len(payload)],
422
+ )
423
+ == "hello"
424
+ )
425
+
426
+
427
+ class _SkipTStringValueReader(python.IReader):
428
+ """
429
+ The python-backend form of `_SkipTStringReader`; the backend has no
430
+ `skip_TString`, so the length prefix is read by hand.
431
+ """
432
+
433
+ def __init__(self, name):
434
+ super().__init__(name)
435
+ self.values = []
436
+
437
+ def read(self, stream):
438
+ self.values.append(stream.read_int32())
439
+ size = stream.read_uint8()
440
+ if size == 255:
441
+ size = stream.read_uint32()
442
+ stream.skip(size)
443
+ self.values.append(stream.read_int32())
444
+
445
+ def data(self):
446
+ return np.asarray(self.values)
447
+
448
+
449
+ @reader
450
+ class _SkipTStringReader(Reader):
451
+ """
452
+ A `TString` between two values, skipped instead of decoded.
453
+ """
454
+
455
+ values = Buffer("i")
456
+
457
+ def read(self, stream):
458
+ self.values.append(stream.read_int32())
459
+ stream.skip_TString()
460
+ self.values.append(stream.read_int32())
461
+
462
+ def data(self):
463
+ return np.asarray(self.values)
464
+
465
+
466
+ def test_skip_tstring_short_form():
467
+ payload = struct.pack(">i", 1) + struct.pack(">B", 3) + b"abc" + struct.pack(">i", 2)
468
+ expected = _check(
469
+ _SkipTStringValueReader("s"),
470
+ _SkipTStringReader("s"),
471
+ payload,
472
+ [0, len(payload)],
473
+ )
474
+ np.testing.assert_array_equal(expected, [1, 2])
475
+
476
+
477
+ def test_skip_tstring_long_form():
478
+ payload = (
479
+ struct.pack(">i", 1)
480
+ + struct.pack(">B", 255)
481
+ + struct.pack(">I", 5)
482
+ + b"hello"
483
+ + struct.pack(">i", 2)
484
+ )
485
+ expected = _check(
486
+ _SkipTStringValueReader("s"),
487
+ _SkipTStringReader("s"),
488
+ payload,
489
+ [0, len(payload)],
490
+ )
491
+ np.testing.assert_array_equal(expected, [1, 2])
492
+
493
+
369
494
  # -- pointers ------------------------------------------------------------------
370
495
  def test_any_pointer_null():
371
496
  payload = _u32(0)
@@ -14,7 +14,7 @@ from uproot_custom.detree.compiler.frontend import (
14
14
  compile_reader,
15
15
  describe_reader,
16
16
  )
17
- from uproot_custom.detree.decl import Buffer, Reader, reader
17
+ from uproot_custom.detree.decl import Buffer, Reader, State, reader
18
18
 
19
19
 
20
20
  def _prim(name="p", typecode="i"):
@@ -241,3 +241,59 @@ def test_check_nbytes_start_is_refused_in_a_condition():
241
241
 
242
242
  with pytest.raises(UnsupportedNode, match="cannot be used in a condition"):
243
243
  compile_reader(_Conditional("c"))
244
+
245
+
246
+ # -- strings -------------------------------------------------------------------
247
+ def test_read_tstring_compiles_to_one_opcode():
248
+ @reader
249
+ class _TString(Reader):
250
+ value = State(str, "")
251
+
252
+ def read(self, stream):
253
+ self.value = stream.read_TString()
254
+
255
+ def data(self):
256
+ return self.value
257
+
258
+ raw, _ = compile_reader(_TString("s"))
259
+ operators = _ops_of(raw, "root.read")
260
+
261
+ assert operators.count(detree.spec.isa.Op.SREAD_TSTR) == 1
262
+
263
+
264
+ def test_a_tstring_can_be_compared_with_a_name():
265
+ @reader
266
+ class _Named(Reader):
267
+ value = State(str, "")
268
+ values = Buffer("i")
269
+
270
+ def read(self, stream):
271
+ self.value = stream.read_TString()
272
+ self.values.append(int(self.value == "x"))
273
+
274
+ def data(self):
275
+ return None
276
+
277
+ raw, _ = compile_reader(_Named("n"))
278
+ operators = _ops_of(raw, "root.read")
279
+
280
+ assert detree.spec.isa.Op.SREAD_TSTR in operators
281
+ assert detree.spec.isa.Op.STR_EQ in operators
282
+
283
+
284
+ def test_skip_tstring_compiles_to_one_opcode():
285
+ @reader
286
+ class _Skipped(Reader):
287
+ values = Buffer("i")
288
+
289
+ def read(self, stream):
290
+ stream.skip_TString()
291
+ self.values.append(stream.read_int32())
292
+
293
+ def data(self):
294
+ return self.values
295
+
296
+ raw, _ = compile_reader(_Skipped("s"))
297
+ operators = _ops_of(raw, "root.read")
298
+
299
+ assert operators.count(detree.spec.isa.Op.SKIP_TSTR) == 1
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '2.6.0'
22
- __version_tuple__ = version_tuple = (2, 6, 0)
21
+ __version__ = version = '2.6.1'
22
+ __version_tuple__ = version_tuple = (2, 6, 1)
23
23
 
24
- __commit_id__ = commit_id = 'g1922c5a21'
24
+ __commit_id__ = commit_id = 'geb26e3c88'
@@ -25,6 +25,18 @@ if not hasattr(nodes, "FNBegin"): # pragma: no cover - depends on the installed
25
25
  "(FNB_BEGIN/FNB_END); upgrade detree-vm"
26
26
  )
27
27
 
28
+ if not hasattr(nodes, "StreamReadTString"): # pragma: no cover - detree-vm dependent
29
+ raise ImportError(
30
+ "uproot-custom needs a detree-vm with length-prefixed strings "
31
+ "(SREAD_TSTR); upgrade detree-vm"
32
+ )
33
+
34
+ if not hasattr(nodes, "SkipTString"): # pragma: no cover - detree-vm dependent
35
+ raise ImportError(
36
+ "uproot-custom needs a detree-vm with length-prefixed strings "
37
+ "(SKIP_TSTR); upgrade detree-vm"
38
+ )
39
+
28
40
  STREAM_READS = {
29
41
  "read_uint8": Typecode.UINT8,
30
42
  "read_uint16": Typecode.UINT16,
@@ -743,7 +755,9 @@ class _MethodEmitter:
743
755
  return True
744
756
  if isinstance(value, nodes.StateGet):
745
757
  return self.compiler.program.states[value.slot].type == "name"
746
- return isinstance(value, (nodes.StreamReadCString, nodes.RefGetClass))
758
+ return isinstance(
759
+ value, (nodes.StreamReadCString, nodes.StreamReadTString, nodes.RefGetClass)
760
+ )
747
761
 
748
762
  def compare(self, node: ast.Compare):
749
763
  operator = type(node.ops[0])
@@ -962,6 +976,13 @@ class _MethodEmitter:
962
976
  return self.fn.read_version()
963
977
  if name == "read_null_terminated_string":
964
978
  return self.fn.read_cstr()
979
+ if name == "read_TString":
980
+ return self.fn.read_tstring()
981
+ if name == "skip_TString":
982
+ if node.args:
983
+ raise _Unsupported(f"line {node.lineno}: skip_TString takes no arguments")
984
+ self.fn.skip_tstring()
985
+ return self.result()
965
986
  if name in STREAM_SKIPS:
966
987
  self.fn.emit(STREAM_SKIPS[name])
967
988
  return self.result()
@@ -264,6 +264,9 @@ class IRFunctionBuilder:
264
264
  def read_cstr(self, dst=None):
265
265
  return nodes.StreamReadCString()
266
266
 
267
+ def read_tstring(self, dst=None):
268
+ return nodes.StreamReadTString()
269
+
267
270
  def buf_last(self, buf):
268
271
  return nodes.BufferLast(int(buf))
269
272
 
@@ -317,6 +320,9 @@ class IRFunctionBuilder:
317
320
  def skip_cstr(self):
318
321
  return self.emit(nodes.SkipCStr())
319
322
 
323
+ def skip_tstring(self):
324
+ return self.emit(nodes.SkipTString())
325
+
320
326
  def set_cursor(self, value):
321
327
  return self.emit(nodes.SetCursor(_value(value)))
322
328
 
@@ -164,6 +164,26 @@ class Stream:
164
164
  self.cursor += 1
165
165
  return value
166
166
 
167
+ def read_TString(self):
168
+ """
169
+ Read a length-prefixed string: one byte, or `0xFF` and a `uint32`.
170
+ """
171
+ size = self.read_uint8()
172
+ if size == 255:
173
+ size = self.read_uint32()
174
+ self.skip(size)
175
+ start = self.cursor - size
176
+ return self.data[start : self.cursor].decode()
177
+
178
+ def skip_TString(self):
179
+ """
180
+ Skip a length-prefixed string: one byte, or `0xFF` and a `uint32`.
181
+ """
182
+ size = self.read_uint8()
183
+ if size == 255:
184
+ size = self.read_uint32()
185
+ self.skip(size)
186
+
167
187
  def skip(self, nbytes):
168
188
  if self.cursor + nbytes > len(self.data):
169
189
  raise IndexError(f"skip of {nbytes} bytes past the end of the basket")
File without changes
File without changes
File without changes