@@ -333,11 +333,11 @@ class HandleTable:
333333 return i
334334```
335335The ` HandleTable ` class maintains a dense array of handles that can contain
336- holes created by the ` remove ` method (defined below). These holes are kept in a
337- separate Python list here, but an optimizing implementation could instead store
338- the free list in the free elements of ` array ` . When adding a new handle,
339- ` HandleTable ` first consults the ` free ` list, which is popped LIFO to better
340- detect use-after-free bugs in the guest code.
336+ holes created by the ` remove_or_drop ` method (defined below). These holes are
337+ kept in a separate Python list here, but an optimizing implementation could
338+ instead store the free list in the free elements of ` array ` . When adding a new
339+ handle, ` HandleTable ` first consults the ` free ` list, which is popped LIFO to
340+ better detect use-after-free bugs in the guest code.
341341
342342The ` get ` method is used by other ` HandleTable ` methods and canonical
343343definitions below and uses dynamic guards to catch out-of-bounds and
@@ -349,9 +349,9 @@ use-after-free:
349349 return self .array[i]
350350```
351351
352- The last method of ` HandleTable ` , ` remove ` , is used to drop or transfer a
353- handle out of the handle table. ` remove ` adds the removed handle to the ` free `
354- list for later recycling by ` add ` (above).
352+ The last method of ` HandleTable ` , ` remove_or_drop ` , is used to drop or transfer
353+ a handle out of the handle table. ` remove_or_drop ` adds the removed handle to
354+ the ` free ` list for later recycling by ` add ` (above).
355355``` python
356356 def remove_or_drop (self , i , t , drop ):
357357 h = self .get(i)
@@ -370,13 +370,13 @@ list for later recycling by `add` (above).
370370 return h
371371```
372372The ` lend_count ` guard ensures that no dangling borrows are created when
373- destroying a resource. Because ` remove ` is used for cross-component transfer
374- of ` own ` handles (via ` lift_own ` below), this ` lend_count ` guard ensures that
375- when a component receives an ` own ` , it receives a unique reference to the
376- resource and that there aren't any dangling borrows hanging around from the
377- previous owner. The bookkeeping performed by ` remove ` for borrowed handles
378- records the fulfillment of the obligation of the borrower to drop the handle
379- before the end of the call.
373+ destroying a resource. Because ` remove_or_drop ` is used for cross-component
374+ transfer of ` own ` handles (via ` lift_own ` below), this ` lend_count ` guard
375+ ensures that when a component receives an ` own ` , it receives a unique reference
376+ to the resource and that there aren't any dangling borrows hanging around from
377+ the previous owner. The bookkeeping performed by ` remove_or_drop ` for borrowed
378+ handles records the fulfillment of the obligation of the borrower to drop the
379+ handle before the end of the call.
380380
381381Finally, we can define ` HandleTables ` (plural) as simply a wrapper around
382382a mutable mapping from ` ResourceType ` to ` HandleTable ` :
@@ -405,8 +405,8 @@ While this Python code performs a dynamic hash-table lookup on each handle
405405table access, as we'll see below, the ` rt ` parameter is always statically
406406known such that a normal implementation can statically enumerate all
407407` HandleTable ` objects at compile time and then route the calls to ` add ` ,
408- ` get ` and ` remove ` to the correct ` HandleTable ` at the callsite. The net
409- result is that each component instance will contain one handle table per
408+ ` get ` and ` remove_or_drop ` to the correct ` HandleTable ` at the callsite. The
409+ net result is that each component instance will contain one handle table per
410410resource type used by the component, with each compiled adapter function
411411accessing the correct handle table as-if it were a global variable.
412412
0 commit comments