Changes for version 0.22 - 2026-12-03
- delete() now accepts Iterators for either end of the range, as the SYNOPSIS already claimed, meaning the iterator's current node. An iterator that reached the end is an error, since the range is inclusive.
- Fix crashes and memory corruption:
- Stepping an insertion-order iterator past its end, including during 'each' on a tied hash with keys_in_recent_order, crashed. Stepping it backward from the end now also starts from the correct end.
- recent_limit => 0 freed newly inserted or looked-up nodes while still in use. A limit of 0 now means nodes are never added to the recent list.
- get_all with lookup_updates_recent could free values it was returning when recent_limit pruned the matching nodes.
- Node->mark_oldest (or tree->oldest_node) on the node that was already oldest, or $node->older($node), corrupted the recent list.
- Node->newer/older accepted a node from a different tree, corrupting both.
- Setting Node->key on a node that was removed from the tree crashed. It now dies with an error.
- rekey could crash when a moved node collided with a node at the edge of the tree, and modified the wrong nodes when the min/max range contained no nodes or min was greater than max.
- delete($node) and delete($node1, $node2) read uninitialized memory and did not delete the nodes.
- Integer-key comparisons overflowed for keys far apart (e.g. near +/- 2**63), which mis-sorted them.
- Calling ->new on an existing tree re-initialized it in place, corrupting its nodes. It now dies with "Tree was already initialized".
- A compare_fn callback during construction (with 'kv', 'keys' or 'values') could cause reads of freed memory if it grew the Perl stack or modified the input arrays.
- CMP_NUMSPLIT is no longer undefined behavior on non-ASCII bytes.
- Perl code that runs in the middle of a tree operation could modify or free the tree while it was in use, corrupting memory. This includes a compare_fn callback, overloaded stringification of keys, tied keys or values, and DESTROY of keys or values freed by the operation. Now:
- During a compare_fn callback or key stringification, any method call on the tree (or on its Nodes, or Iterator->delete) dies with an error. Reading Node attributes and stepping iterators are still permitted.
- Tied keys and values are read once, before the operation begins.
- Keys and values removed by an operation are freed after it completes.
- Fix corruption on older perls compiled as C23 (e.g. gcc 15), where perl defines 'bool' as 'char': a node whose subtree count was a multiple of 256 (such as the root of a 256-node tree) was treated as not being in the tree when deleted.
- NaN is no longer accepted as a key of a KEY_TYPE_FLOAT tree (it can't be ordered, which broke lookups). Using it as a key now dies, and rekey dies if 'offset' is NaN or infinite.
- The 'recent' and 'hashiter' constructor attributes now reject "-", "+", and numbers out of integer range, instead of treating them as 0 or undefined behavior.
- Fix 'put' on a tree with duplicate keys, which sometimes left some of the duplicates in place. Also, duplicates created by changing Node->key or by 'rekey' were not always found by exists, get_all, or put.
- The tree now keeps a copy of the compare_fn coderef, so reassigning the variable that was passed to the constructor no longer changes it.
- Iterator->clone now keeps the direction of the original iterator. Previously the clone always iterated forward.
- Deleting the current key during 'each' on a tied hash no longer skips the following key.
- The 'recent' constructor attribute combined with a smaller recent_limit died with "BUG: access node[idx]" or tracked and removed the wrong nodes. The limit is now applied after the recent list is restored, keeping the newest nodes.
- Storable freeze of a tree no longer resets an 'each' loop in progress on the tree object's hash.
- rekey without 'offset' now always dies, instead of only when the min/max range contained nodes.
- Fix _init_tree, which returned one less value than intended.
- Fix Node::STORABLE_thaw returning its arguments in a rare case.
- Fix delete($key) of a key not in the tree, which deleted the nodes on either side of where that key would be.
- Fix tied scalars as keys, which were reported as undef until read once.
- CMP_NUMSPLIT on overloaded objects now uses the UTF-8 flag of the stringified value.
Documentation
Provides
in util/RBGen.pm