Skip to content

Object references are never resolved: instance_refs is never populated and Ref(Some()) is returned #104

Description

@nsmith-

🤖 AI generated content

read_streamed_item returns the placeholder Ref(Some()) for every non-null object reference (src/rootfilespec/bootstrap/streamedobject.py:158-166, with # TODO: fetch the referenced object from the buffer.instance_refs). BufferContext.instance_refs is declared at src/rootfilespec/serializable.py:66-75 and nothing ever writes to it (# TODO: register the object addr …, streamedobject.py:191).

Spec: Buffer framing §6.1 "Object references": a reference means "the object I already built at that position"; two slots referring to one object are the same object, and cyclic graphs round-trip. When the position is not yet in the map, ROOT seeks and reads out of order — position - 2 for an object, position - 2 - 4 for a class. §6.2: "a reader MUST treat a reference of 1 as the record's top-level object rather than as a buffer position, and MUST NOT reject it."

Effect: data is lost silently — e.g. a TMap's shared values (Containers §1.1), every repeated entry of a TList, and TTree::fLeavesTBranch::fLeaves sharing.

Suggested fix: register each object under the position of its slot's byte-count word (+ kMapOffset) as it is built, resolve references from that map, special-case 1 (top-level object) and 0 (null, already handled). Note the two maps currently use different key conventions: type_refs is keyed by the raw tag offset with kMapOffset subtracted at lookup (streamedobject.py:81, :94), while instance_refs's docstring says "the position of the StreamHeader". Pick one. Ref already avoids a dataclass repr for cycles; out-of-order resolution needs either a lazy Ref or a seek-and-read path.

Severity / size: medium / M.

Related: #106, #105, #101 (TRef/TRefArray are a separate, fUniqueID-based mechanism: #110).

Assisted-by: claude-code:claude-fable-5-1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions