-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable explicit destruction of all resources
This commit adds a suite of methods to most of the types in this package to enable explicit destruction of resources as necessary. Specifically most classes which own a pointer internally now sport some new methods: * `__enter__` and `__exit__` enable using the objects in `with` blocks. * `close` enables explicitly deallocating the object. All objects internally now validate that they have not been closed before operating, raising a `ValueError` if a closed object is operated on.
- Loading branch information
1 parent
04ce48c
commit 458af19
Showing
20 changed files
with
396 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
from . import _ffi as ffi | ||
from wasmtime import Config, WasmtimeError | ||
from wasmtime import Config, WasmtimeError, Managed | ||
from typing import Optional | ||
import ctypes | ||
|
||
|
||
class Engine: | ||
_ptr: "ctypes._Pointer[ffi.wasm_engine_t]" | ||
class Engine(Managed["ctypes._Pointer[ffi.wasm_engine_t]"]): | ||
|
||
def __init__(self, config: Optional[Config] = None): | ||
if config is None: | ||
self._ptr = ffi.wasm_engine_new() | ||
self._set_ptr(ffi.wasm_engine_new()) | ||
elif not isinstance(config, Config): | ||
raise TypeError("expected Config") | ||
elif not hasattr(config, '_ptr'): | ||
raise WasmtimeError("Config already used") | ||
else: | ||
ptr = config._ptr | ||
delattr(config, '_ptr') | ||
self._ptr = ffi.wasm_engine_new_with_config(ptr) | ||
ptr = config._consume() | ||
self._set_ptr(ffi.wasm_engine_new_with_config(ptr)) | ||
|
||
def increment_epoch(self) -> None: | ||
ffi.wasmtime_engine_increment_epoch(self._ptr) | ||
def _delete(self, ptr: "ctypes._Pointer[ffi.wasm_engine_t]") -> None: | ||
ffi.wasm_engine_delete(ptr) | ||
|
||
def __del__(self) -> None: | ||
if hasattr(self, '_ptr'): | ||
ffi.wasm_engine_delete(self._ptr) | ||
def increment_epoch(self) -> None: | ||
ffi.wasmtime_engine_increment_epoch(self.ptr()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.