Skip to content

Add get_key and get_value_type to dict_pkg - #1229

Open
ru551n wants to merge 2 commits into
VUnit:masterfrom
ru551n:dict-key-iteration
Open

ru551n wants to merge 2 commits into
VUnit:masterfrom
ru551n:dict-key-iteration

Conversation

@ru551n

@ru551n ru551n commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Why

The vunit-python-bridge needs to enumerate a dict_t and read each value by type through public subprograms, without touching the private p_bucket_* fields.

API added (dict_pkg)

impure function get_key(dict : dict_t; index : natural) return string;
impure function get_value_type(dict : dict_t; key : string) return data_type_t;

get_key: 0 <= index < num_keys(dict); order unspecified but stable while the dict is unmodified; reports an error if out of range. get_value_type reports an error if the key is missing. dict_pkg-2008p needs no change.

Tests

New tb_dict case enumerating a dict of mixed types, checking get_key/get_value_type after remove and across a resize (200 keys). Ran with NVC: 41 of 41 pass in the data_types run.py (tb_dict). The out-of-range error path is not tested (no existing failing-check pattern in tb_dict).

A news fragment is included.

🤖 Generated with Claude Code

@ru551n

ru551n commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Needed by the Python dict support in VUnit/vunit-python-bridge#11, which enumerates a dict_t with get_key and reads each value by type with get_value_type.

@ru551n

ru551n commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Also fixes new_dict crashing after deallocate of a dict that had grown beyond one bucket: the pointer pool recycles pointers that can be longer than requested, but dict_t uses their lengths as bucket count and size. New regression test included (it crashes without the fix).

ru551n added a commit to ru551n/vunit-python-bridge that referenced this pull request Oct 4, 2026
Needs the new_dict fix of VUnit/vunit#1229.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ru551n and others added 2 commits October 4, 2026 12:37
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The pointer pool recycles pointers that can be longer than requested, while
dict_t uses the pointer lengths as the bucket count and bucket sizes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ru551n
ru551n force-pushed the dict-key-iteration branch from e719a52 to 4899efe Compare October 4, 2026 10:37
ru551n added a commit to ru551n/vunit-python-bridge that referenced this pull request Oct 4, 2026
Needs the new_dict fix of VUnit/vunit#1229.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant