Skip to documentation
SLOP

tiny.python.object.heap

Reference tiny.python object heap

Defined in object.

The heap owns every object the virtual machine creates while it runs a program: lists, tuples, dictionaries, ranges, copied strings, iterators, bound methods and dictionary views.

API (23)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callsobjectheap
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns dictionary view itera...test sourcelib.python.src.object.heaptest: heap owns dictionary viewstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsobject.HeapcreateDict
Static calls · unresolved targets: 2 · external targets: 4.
Called byCallsNo direct callersprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateDictIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateDictReverseIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns dictionary view itera...test sourcelib.python.src.object.heaptest: heap owns dictionary viewstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsobject.HeapcreateDictView
Static calls · unresolved targets: 1 · external targets: 2.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns dictionary view itera...private sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateDictViewIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateDictViewReverseIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns enumerate iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateEnumerateIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns enumerate iteratorstest sourcelib.python.src.object.heaptest: heap owns list iteratorstest sourcelib.python.src.object.heaptest: heap owns list objectstest sourcelib.python.src.object.heaptest: heap owns native methodstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsobject.HeapcreateList
Static calls · unresolved targets: 1 · external targets: 4.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns enumerate iteratorstest sourcelib.python.src.object.heaptest: heap owns list iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateListIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateListReverseIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns native methodsobject.HeapcreateNativeMethod
Static calls · unresolved targets: 1 · external targets: 2.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns range iteratorstest sourcelib.python.src.object.heaptest: heap owns range objectstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsobject.HeapcreateRange
Static calls · unresolved targets: 1 · external targets: 2.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns range iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateRangeIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateRangeReverseIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns string objectsobject.HeapcreateString
Static calls · unresolved targets: 1 · external targets: 2.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns string iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateStringIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateStringReverseIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorstest sourcelib.python.src.object.heaptest: heap owns tuple iteratorstest sourcelib.python.src.object.heaptest: heap owns tuple objectsobject.HeapcreateTuple
Static calls · unresolved targets: 1 · external targets: 4.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns tuple iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateTupleIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.python.src.object.heaptest: heap owns reverse iteratorsprivate sourcelib.python.src.object.heap.HeapcreateIteratorobject.HeapcreateTupleReverseIterator
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns dictionary view itera...test sourcelib.python.src.object.heaptest: heap owns dictionary viewstest sourcelib.python.src.object.heaptest: heap owns enumerate iteratorstest sourcelib.python.src.object.heaptest: heap owns list iteratorstest sourcelib.python.src.object.heaptest: heap owns list objects+8 moreobject.Heapdeinit
Static calls · unresolved targets: 0 · external targets: 5.
Called byCallsNo direct callstest sourcelib.python.src.object.heaptest: heap owns dictionary view itera...test sourcelib.python.src.object.heaptest: heap owns dictionary viewstest sourcelib.python.src.object.heaptest: heap owns enumerate iteratorstest sourcelib.python.src.object.heaptest: heap owns list iteratorstest sourcelib.python.src.object.heaptest: heap owns list objects+8 moreobject.Heapinit
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/python/src/object/heap.zig

zig
//! The heap owns every object the virtual machine creates while it runs a program: lists, tuples,//! dictionaries, ranges, copied strings, iterators, bound methods and dictionary views. A program's//! values point at each other freely, and a list can hold itself. Every object has to be freed//! exactly once, when the caller is done with the program's result.//!//! Values are copied between the stack, the variables and the containers with no bookkeeping, so//! nothing records when an object stops being used.//!//! The heap keeps one list of pointers for each kind of object, and `deinit` frees every object at//! once. Every object lives until the heap is freed, so a run's memory grows with each object it//! creates, including the bound method made by each method read and the iterator made by each loop.//! Each create function allocates the object and a slot in its list. When an allocation fails, a//! create function frees what it allocated and leaves the heap as it was. The package's `execute`//! moves the heap out of the virtual machine into its `Result`, so the values of the result stay//! valid until `Result.deinit`.const std = @import("std");const value = @import("value.zig");/// The allocator and, for each kind of object, one list holding every object the virtual machine/// created. The virtual machine creates every object through a heap, and `execute` hands it to the/// caller inside `Result`. A heap is made with `init` and freed with `deinit`, which frees every/// object at once. Nothing is freed before `deinit`.pub const Heap = struct {    /// The allocator given to `init`. Every object and every list of the heap comes from it.    allocator: std.mem.Allocator,    /// Every list the heap created, each with its item storage.    lists: std.ArrayListUnmanaged(*value.List) = .empty,    /// Every tuple the heap created, each with its array of items.    tuples: std.ArrayListUnmanaged(*value.Tuple) = .empty,    /// Every dictionary the heap created, each with its entries and its hash table.    dicts: std.ArrayListUnmanaged(*value.Dict) = .empty,    /// Every range the heap created.    ranges: std.ArrayListUnmanaged(*value.Range) = .empty,    /// The bytes of every string the heap copied. A string literal and its slices borrow the source    /// text, so they have no entry here.    strings: std.ArrayListUnmanaged([]u8) = .empty,    /// Every iterator the heap created, one for each loop, `iter` call or consuming builtin that    /// started a walk.    iterators: std.ArrayListUnmanaged(*value.Iterator) = .empty,    /// Every bound method the heap created, one for each method read.    methods: std.ArrayListUnmanaged(*value.NativeMethod) = .empty,    /// Every dictionary view the heap created.    views: std.ArrayListUnmanaged(*value.DictView) = .empty,    /// Returns an empty heap that allocates from the given allocator. `Vm.init` makes the machine's    /// heap with it, and `Vm.takeHeap` makes the empty heap it leaves behind. The call allocates    /// nothing, so it cannot fail.    pub fn init(allocator: std.mem.Allocator) Heap {        return .{ .allocator = allocator };    }    /// Frees every object with its storage, then the eight lists, and leaves the heap undefined.    /// `Result.deinit` and `Vm.deinit` call it to free a run's objects. Every value that points    /// into the heap is invalid afterwards.    pub fn deinit(self: *Heap) void {        for (self.iterators.items) |iterator| {            self.allocator.destroy(iterator);        }        for (self.methods.items) |method| {            self.allocator.destroy(method);        }        for (self.views.items) |view| {            self.allocator.destroy(view);        }        for (self.lists.items) |list| {            list.deinit(self.allocator);            self.allocator.destroy(list);        }        for (self.tuples.items) |tuple| {            self.allocator.free(tuple.items);            self.allocator.destroy(tuple);        }        for (self.dicts.items) |dict| {            dict.deinit(self.allocator);            self.allocator.destroy(dict);        }        for (self.ranges.items) |range| {            self.allocator.destroy(range);        }        for (self.strings.items) |string| {            self.allocator.free(string);        }        self.lists.deinit(self.allocator);        self.tuples.deinit(self.allocator);        self.dicts.deinit(self.allocator);        self.ranges.deinit(self.allocator);        self.strings.deinit(self.allocator);        self.iterators.deinit(self.allocator);        self.methods.deinit(self.allocator);        self.views.deinit(self.allocator);        self.* = undefined;    }    /// Returns a list value that holds a copy of the given items, in a new list that the heap owns.    /// The virtual machine makes every new list with it, for list displays, `list()`, joins,    /// repeats, slices and copies. The copy takes the item values, so the objects they point to are    /// shared. The call returns `error.OutOfMemory` when an allocation fails, after freeing what it    /// allocated.    pub fn createList(self: *Heap, items: []const value.Value) std.mem.Allocator.Error!value.Value {        const list = try self.allocator.create(value.List);        errdefer self.allocator.destroy(list);        list.* = .empty;        errdefer list.deinit(self.allocator);        try list.appendSlice(self.allocator, items);        try self.lists.append(self.allocator, list);        return .{ .list = list };    }    /// Returns a tuple value that holds a copy of the given items. The virtual machine makes every    /// new tuple with it, for tuple displays, `tuple()`, joins, repeats, slices and the pairs that    /// dictionaries and `enumerate` yield. The heap owns the tuple and its array, which has exactly    /// one slot per item. The copy takes the item values, so the objects they point to are shared.    /// The call returns `error.OutOfMemory` when an allocation fails, after freeing what it    /// allocated.    pub fn createTuple(self: *Heap, items: []const value.Value) std.mem.Allocator.Error!value.Value {        const owned_items = try self.allocator.dupe(value.Value, items);        errdefer self.allocator.free(owned_items);        const tuple = try self.allocator.create(value.Tuple);        errdefer self.allocator.destroy(tuple);        tuple.* = .{ .items = owned_items };        try self.tuples.append(self.allocator, tuple);        return .{ .tuple = tuple };    }    /// Returns a dictionary value that holds the given entries in order. The virtual machine makes    /// every new dictionary with it, for displays, `dict()` and `copy()`. A repeated key keeps its    /// first position and takes the later value. The call reserves room for every entry before it    /// inserts the first. Every key has to be hashable, and the insertion asserts it. The call    /// returns `error.OutOfMemory` when an allocation fails or when there are more entries than a    /// 32-bit count holds, after freeing what it allocated.    pub fn createDict(self: *Heap, entries: []const value.DictEntry) std.mem.Allocator.Error!value.Value {        const dict = try self.allocator.create(value.Dict);        errdefer self.allocator.destroy(dict);        dict.* = .{};        errdefer dict.deinit(self.allocator);        try dict.ensureTotalCapacity(self.allocator, entries.len);        for (entries) |entry| try dict.put(self.allocator, entry.key, entry.value);        try self.dicts.append(self.allocator, dict);        return .{ .dict = dict };    }    /// Returns a range value with the given start, stop, step and element count. `range()` and    /// range slices make each new range with it. The call stores the count as given without    /// checking it against the other three, so the caller computes it. The call returns    /// `error.OutOfMemory` when an allocation fails, after freeing what it allocated.    pub fn createRange(self: *Heap, start: i128, stop: i128, step: i128, length: usize) std.mem.Allocator.Error!value.Value {        const range = try self.allocator.create(value.Range);        errdefer self.allocator.destroy(range);        range.* = .{            .start = start,            .stop = stop,            .step = step,            .length = length,        };        try self.ranges.append(self.allocator, range);        return .{ .range = range };    }    /// Returns a string value that holds a copy of the given bytes. The virtual machine makes every    /// string it builds with it, for joins, repeats and slices with a step other than 1. The heap    /// owns the copy. The call returns `error.OutOfMemory` when an allocation fails, after freeing    /// what it allocated.    pub fn createString(self: *Heap, bytes: []const u8) std.mem.Allocator.Error!value.Value {        const owned = try self.allocator.dupe(u8, bytes);        errdefer self.allocator.free(owned);        try self.strings.append(self.allocator, owned);        return .{ .string = owned };    }    /// Returns an iterator that walks the list from its first item. `iter`, `for` loops and the    /// builtins that consume a list start their walk with it. The iterator borrows the list and    /// reads its length at each step, so items appended during the walk are visited. The call    /// returns `error.OutOfMemory` when an allocation fails.    pub fn createListIterator(self: *Heap, list: *value.List) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .list = .{ .list = list } });    }    /// Returns an iterator that walks the list from its last item to its first. `reversed` starts    /// its walk of a list with it. The iterator borrows the list. The call returns    /// `error.OutOfMemory` when an allocation fails.    pub fn createListReverseIterator(self: *Heap, list: *value.List) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .list = .{ .list = list, .reverse = true } });    }    /// Returns an iterator over the dictionary's keys, in insertion order. `iter`, `for` loops and    /// `list()` start their walk of a dictionary with it. The iterator borrows the dictionary. The    /// call returns `error.OutOfMemory` when an allocation fails.    pub fn createDictIterator(self: *Heap, dict: *value.Dict) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .dict = .{ .dict = dict } });    }    /// Returns an iterator over the dictionary's keys, from the last inserted to the first.    /// `reversed` starts its walk of a dictionary with it. The iterator borrows the dictionary. The    /// call returns `error.OutOfMemory` when an allocation fails.    pub fn createDictReverseIterator(self: *Heap, dict: *value.Dict) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .dict = .{ .dict = dict, .reverse = true } });    }    /// Returns an iterator that pairs each item of the given iterator with a counter that starts at    /// `start`, as a two-item tuple. `enumerate` wraps the iterator of its argument with it. The    /// new iterator borrows the given one and advances it. The call returns `error.OutOfMemory`    /// when an allocation fails.    pub fn createEnumerateIterator(self: *Heap, iterator: *value.Iterator, start: i128) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .enumerate = .{            .iterator = iterator,            .index = start,        } });    }    /// Returns an iterator over a dictionary view, in insertion order: keys, values, or key and    /// value tuples, as the view's kind says. `iter`, `for` loops and the consuming builtins start    /// their walk of a dictionary view with it. The iterator borrows the view. The call returns    /// `error.OutOfMemory` when an allocation fails.    pub fn createDictViewIterator(self: *Heap, view: *value.DictView) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .view = .{ .view = view } });    }    /// Returns an iterator over a dictionary view, from the last inserted entry to the first.    /// `reversed` starts its walk of a dictionary view with it. The iterator borrows the view. The    /// call returns `error.OutOfMemory` when an allocation fails.    pub fn createDictViewReverseIterator(self: *Heap, view: *value.DictView) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .view = .{ .view = view, .reverse = true } });    }    /// Returns an iterator that walks the tuple from its first item. `iter`, `for` loops and the    /// consuming builtins start their walk of a tuple with it. The iterator borrows the tuple. The    /// call returns `error.OutOfMemory` when an allocation fails.    pub fn createTupleIterator(self: *Heap, tuple: *value.Tuple) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .tuple = .{ .tuple = tuple } });    }    /// Returns an iterator that walks the tuple from its last item to its first. `reversed` starts    /// its walk of a tuple with it. The iterator borrows the tuple. The call returns    /// `error.OutOfMemory` when an allocation fails.    pub fn createTupleReverseIterator(self: *Heap, tuple: *value.Tuple) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .tuple = .{ .tuple = tuple, .reverse = true } });    }    /// Returns an iterator that yields the range's elements from its start. `iter`, `for` loops and    /// the consuming builtins start their walk of a range with it. The iterator borrows the range.    /// The call returns `error.OutOfMemory` when an allocation fails.    pub fn createRangeIterator(self: *Heap, range: *value.Range) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .range = .{            .range = range,            .next = range.start,        } });    }    /// Returns an iterator that yields the range's elements from its last to its start. `reversed`    /// starts its walk of a range with it. The iterator computes each element from its position.    /// The iterator borrows the range. The call returns `error.OutOfMemory` when an allocation    /// fails.    pub fn createRangeReverseIterator(self: *Heap, range: *value.Range) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .range = .{            .range = range,            .next = range.start,            .reverse = true,        } });    }    /// Returns an iterator that yields each codepoint of the string as a string of its own,    /// pointing into the same bytes. `iter`, `for` loops and the consuming builtins start their    /// walk of a string with it. The iterator borrows the bytes. The call returns    /// `error.OutOfMemory` when an allocation fails.    pub fn createStringIterator(self: *Heap, string: []const u8) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .string = .{ .value = string } });    }    /// Returns an iterator that yields each codepoint of the string from the last to the first, as    /// strings pointing into the same bytes. `reversed` starts its walk of a string with it. The    /// iterator borrows the bytes and starts its position at their end. The call returns    /// `error.OutOfMemory` when an allocation fails.    pub fn createStringReverseIterator(self: *Heap, string: []const u8) std.mem.Allocator.Error!value.Value {        return try self.createIterator(.{ .string = .{            .value = string,            .index = string.len,            .reverse = true,        } });    }    fn createIterator(self: *Heap, value_iterator: value.Iterator) std.mem.Allocator.Error!value.Value {        const iterator = try self.allocator.create(value.Iterator);        errdefer self.allocator.destroy(iterator);        iterator.* = value_iterator;        try self.iterators.append(self.allocator, iterator);        return .{ .iterator = iterator };    }    /// Returns a bound method value for the given method and its receiver, in a new object on the    /// heap. The virtual machine calls it on every method read of a list or dictionary. Each method    /// read makes a new object, so two reads give equal values that are different objects. The call    /// returns `error.OutOfMemory` when an allocation fails, after freeing what it allocated.    pub fn createNativeMethod(self: *Heap, method_value: value.NativeMethod) std.mem.Allocator.Error!value.Value {        const method = try self.allocator.create(value.NativeMethod);        errdefer self.allocator.destroy(method);        method.* = method_value;        try self.methods.append(self.allocator, method);        return .{ .method = method };    }    /// Returns, for the given dictionary, a view of the given kind: keys, values or items.    /// `keys()`, `values()` and `items()` make their views with it. The view borrows the dictionary    /// and shows every later change to it. The call returns `error.OutOfMemory` when an allocation    /// fails, after freeing what it allocated.    pub fn createDictView(self: *Heap, dict: *value.Dict, kind: value.DictViewKind) std.mem.Allocator.Error!value.Value {        const view = try self.allocator.create(value.DictView);        errdefer self.allocator.destroy(view);        view.* = .{            .dict = dict,            .kind = kind,        };        try self.views.append(self.allocator, view);        return .{ .view = view };    }};test "heap owns list objects" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const first = try heap.createList(&.{ .{ .integer = 1 }, .{ .integer = 2 } });    try std.testing.expect(first == .list);    try std.testing.expectEqual(@as(usize, 2), first.list.items.len);    try std.testing.expectEqual(value.Value{ .integer = 2 }, first.list.items[1]);}test "heap owns tuple objects" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const first = try heap.createTuple(&.{ .{ .integer = 1 }, .{ .integer = 2 } });    try std.testing.expect(first == .tuple);    try std.testing.expectEqual(@as(usize, 2), first.tuple.items.len);    try std.testing.expectEqual(value.Value{ .integer = 2 }, first.tuple.items[1]);}test "heap owns range objects" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const first = try heap.createRange(0, 5, 2, 3);    try std.testing.expect(first == .range);    try std.testing.expectEqual(@as(i128, 0), first.range.start);    try std.testing.expectEqual(@as(i128, 5), first.range.stop);    try std.testing.expectEqual(@as(i128, 2), first.range.step);    try std.testing.expectEqual(@as(usize, 3), first.range.length);}test "heap owns string objects" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const first = try heap.createString("abc");    try std.testing.expect(first == .string);    try std.testing.expectEqualStrings("abc", first.string);}test "heap owns list iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const list = try heap.createList(&.{.{ .integer = 1 }});    const iterator = try heap.createListIterator(list.list);    try std.testing.expect(iterator == .iterator);    try std.testing.expect(iterator.iterator.* == .list);    try std.testing.expectEqual(list.list, iterator.iterator.list.list);    try std.testing.expectEqual(@as(usize, 0), iterator.iterator.list.index);    try std.testing.expect(!iterator.iterator.list.reverse);}test "heap owns native methods" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const list = try heap.createList(&.{});    const method = try heap.createNativeMethod(.{ .list_append = list.list });    try std.testing.expect(method == .method);    try std.testing.expect(method.method.* == .list_append);    try std.testing.expect(method.method.list_append == list.list);}test "heap owns dictionary views" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const dict = try heap.createDict(&.{});    const view = try heap.createDictView(dict.dict, .keys);    try std.testing.expect(view == .view);    try std.testing.expectEqual(dict.dict, view.view.dict);    try std.testing.expectEqual(value.DictViewKind.keys, view.view.kind);}test "heap owns dictionary view iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const dict = try heap.createDict(&.{});    const view = try heap.createDictView(dict.dict, .items);    const iterator = try heap.createDictViewIterator(view.view);    try std.testing.expect(iterator == .iterator);    try std.testing.expect(iterator.iterator.* == .view);    try std.testing.expectEqual(view.view, iterator.iterator.view.view);    try std.testing.expectEqual(@as(usize, 0), iterator.iterator.view.index);    try std.testing.expect(!iterator.iterator.view.reverse);}test "heap owns enumerate iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const list = try heap.createList(&.{.{ .integer = 1 }});    const child = try heap.createListIterator(list.list);    const iterator = try heap.createEnumerateIterator(child.iterator, 4);    try std.testing.expect(iterator == .iterator);    try std.testing.expect(iterator.iterator.* == .enumerate);    try std.testing.expectEqual(child.iterator, iterator.iterator.enumerate.iterator);    try std.testing.expectEqual(@as(i128, 4), iterator.iterator.enumerate.index);    try std.testing.expect(!iterator.iterator.enumerate.overflowed);}test "heap owns tuple iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const tuple = try heap.createTuple(&.{.{ .integer = 1 }});    const iterator = try heap.createTupleIterator(tuple.tuple);    try std.testing.expect(iterator == .iterator);    try std.testing.expect(iterator.iterator.* == .tuple);    try std.testing.expectEqual(tuple.tuple, iterator.iterator.tuple.tuple);    try std.testing.expectEqual(@as(usize, 0), iterator.iterator.tuple.index);    try std.testing.expect(!iterator.iterator.tuple.reverse);}test "heap owns range iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const range = try heap.createRange(1, 5, 2, 2);    const iterator = try heap.createRangeIterator(range.range);    try std.testing.expect(iterator == .iterator);    try std.testing.expect(iterator.iterator.* == .range);    try std.testing.expectEqual(range.range, iterator.iterator.range.range);    try std.testing.expectEqual(@as(usize, 0), iterator.iterator.range.index);    try std.testing.expectEqual(@as(i128, 1), iterator.iterator.range.next);    try std.testing.expect(!iterator.iterator.range.reverse);}test "heap owns string iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const iterator = try heap.createStringIterator("abc");    try std.testing.expect(iterator == .iterator);    try std.testing.expect(iterator.iterator.* == .string);    try std.testing.expectEqualStrings("abc", iterator.iterator.string.value);    try std.testing.expectEqual(@as(usize, 0), iterator.iterator.string.index);    try std.testing.expect(!iterator.iterator.string.reverse);}test "heap owns reverse iterators" {    var heap = Heap.init(std.testing.allocator);    defer heap.deinit();    const list = try heap.createList(&.{.{ .integer = 1 }});    const list_iterator = try heap.createListReverseIterator(list.list);    try std.testing.expect(list_iterator.iterator.* == .list);    try std.testing.expect(list_iterator.iterator.list.reverse);    const dict = try heap.createDict(&.{});    const dict_iterator = try heap.createDictReverseIterator(dict.dict);    try std.testing.expect(dict_iterator.iterator.* == .dict);    try std.testing.expect(dict_iterator.iterator.dict.reverse);    const view = try heap.createDictView(dict.dict, .keys);    const view_iterator = try heap.createDictViewReverseIterator(view.view);    try std.testing.expect(view_iterator.iterator.* == .view);    try std.testing.expect(view_iterator.iterator.view.reverse);    const tuple = try heap.createTuple(&.{.{ .integer = 1 }});    const tuple_iterator = try heap.createTupleReverseIterator(tuple.tuple);    try std.testing.expect(tuple_iterator.iterator.* == .tuple);    try std.testing.expect(tuple_iterator.iterator.tuple.reverse);    const range = try heap.createRange(1, 5, 2, 2);    const range_iterator = try heap.createRangeReverseIterator(range.range);    try std.testing.expect(range_iterator.iterator.* == .range);    try std.testing.expect(range_iterator.iterator.range.reverse);    const string_iterator = try heap.createStringReverseIterator("abc");    try std.testing.expect(string_iterator.iterator.* == .string);    try std.testing.expect(string_iterator.iterator.string.reverse);    try std.testing.expectEqual(@as(usize, 3), string_iterator.iterator.string.index);}

Source: lib/python/src/object/root.zig:11

zig
pub const heap = @import("heap.zig");

Complete caller list for object.Heap.deinit

13 direct callers.

Complete caller list for object.Heap.init

13 direct callers.

Audit

Definitions24
Public names47
Members9
Version26.7.0
Revisiondaab053ee433