@@ -333,11 +333,11 @@ class HandleTable:
333
333
return i
334
334
```
335
335
The ` 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.
341
341
342
342
The ` get ` method is used by other ` HandleTable ` methods and canonical
343
343
definitions below and uses dynamic guards to catch out-of-bounds and
@@ -349,9 +349,9 @@ use-after-free:
349
349
return self .array[i]
350
350
```
351
351
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).
355
355
``` python
356
356
def remove_or_drop (self , i , t , drop ):
357
357
h = self .get(i)
@@ -370,13 +370,13 @@ list for later recycling by `add` (above).
370
370
return h
371
371
```
372
372
The ` 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.
380
380
381
381
Finally, we can define ` HandleTables ` (plural) as simply a wrapper around
382
382
a mutable mapping from ` ResourceType ` to ` HandleTable ` :
@@ -405,8 +405,8 @@ While this Python code performs a dynamic hash-table lookup on each handle
405
405
table access, as we'll see below, the ` rt ` parameter is always statically
406
406
known such that a normal implementation can statically enumerate all
407
407
` 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
410
410
resource type used by the component, with each compiled adapter function
411
411
accessing the correct handle table as-if it were a global variable.
412
412
0 commit comments