| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 79fb7ab commit 1189bac
15 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | Why would you ever need this | |
| 8 | 8 | ||
| 9 | - - [Documentation](https://pointerspy.netlify.app/) | ||
| 9 | + - [Documentation](https://pointers.zintensity.dev/) | ||
| 10 | 10 | - [Source](https://github.com/ZeroIntensity/pointers.py) | |
| 11 | 11 | - [PyPI](https://pypi.org/project/pointers.py) | |
| 12 | 12 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,7 +81,7 @@ def my_function(a: str, b: str, c: Pointer): # must be type hinted as Pointer t | |||
| 81 | 81 | my_function('a', 'b', 'c') | |
| 82 | 82 | ``` | |
| 83 | 83 | ||
| 84 | - This will be fine for most people, but it hsa removes type safety on the target function. If you don't care about type safety in your code, then don't worry about this, but if you do, then there are alternatives. | ||
| 84 | + This will be fine for most people, but it removes type safety on the target function. If you don't care about type safety in your code, then don't worry about this, but if you do, then there are alternatives. | ||
| 85 | 85 | ||
| 86 | 86 | The first alternative is `decay_annotated`, which decays parameters hinted as `Annotated[T, Pointer]` to a pointer. | |
| 87 | 87 | ||
@@ -110,7 +110,7 @@ def my_function(a: str, b: str, c: Annotated[str, Pointer]): | |||
| 110 | 110 | print(a, b, ~c) # type checker error! | |
| 111 | 111 | ``` | |
| 112 | 112 | ||
| 113 | - The solution is to use `decay_wrapped`, which takes the caller function as a paremeter: | ||
| 113 | + The solution is to use `decay_wrapped`, which takes a fake function as a parameter: | ||
| 114 | 114 | ||
| 115 | 115 | ```py | |
| 116 | 116 | from pointers import decay_wrapped, Pointer | |
@@ -126,7 +126,7 @@ def my_function(a: str, b: str, c: Pointer[str]): | |||
| 126 | 126 | my_function('a', 'b', 'c') # works just fine, type checker things c takes a string | |
| 127 | 127 | ``` | |
| 128 | 128 | ||
| 129 | - It can be broken pretty easily though: | ||
| 129 | + If the wrapper doesn't match, things won't work properly: | ||
| 130 | 130 | ||
| 131 | 131 | ```py | |
| 132 | 132 | from pointers import decay_wrapped, Pointer | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ classifiers = [ | |||
| 23 | 23 | dependencies = [ | |
| 24 | 24 | "typing_extensions", | |
| 25 | 25 | ] | |
| 26 | - version = "2.2.0-beta" | ||
| 26 | + version = "2.2.0" | ||
| 27 | 27 | ||
| 28 | 28 | [project.urls] | |
| 29 | 29 | Documentation = "https://pointers.zintensity.dev" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -96,8 +96,7 @@ static PyObject* handle(PyObject* self, PyObject* args) { | |||
| 96 | 96 | ||
| 97 | 97 | PyErr_Format( | |
| 98 | 98 | PyExc_RuntimeError, | |
| 99 | - "%s occured during execution of %S", | ||
| 100 | - val == 1 ? "segment violation" : "python aborted", | ||
| 99 | + "segment violation occured during execution of %S", | ||
| 101 | 100 | name | |
| 102 | 101 | ); | |
| 103 | 102 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ | |||
| 15 | 15 | TypedCPointer, VoidPointer, array, cast, to_c_ptr, to_struct_ptr, to_voidp | |
| 16 | 16 | ) | |
| 17 | 17 | from .calloc import AllocatedArrayPointer, calloc | |
| 18 | - from .constants import NULL, Nullable, handle, raw_type, struct_cast | ||
| 19 | 18 | from .custom_binding import binding, binds | |
| 20 | 19 | from .decay import decay, decay_annotated, decay_wrapped | |
| 21 | 20 | from .exceptions import ( | |
@@ -28,6 +27,7 @@ | |||
| 28 | 27 | from .object_pointer import Pointer, to_ptr | |
| 29 | 28 | from .std_structs import DivT, Lconv, LDivT, Tm | |
| 30 | 29 | from .structure import Struct, StructPointer | |
| 30 | + from .util import NULL, Nullable, handle, raw_type, struct_cast | ||
| 31 | 31 | ||
| 32 | - __version__ = "2.2.0-beta" | ||
| 32 | + __version__ = "2.2.0" | ||
| 33 | 33 | __license__ = "MIT" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,8 +13,8 @@ | |||
| 13 | 13 | from _pointers import add_ref, remove_ref | |
| 14 | 14 | ||
| 15 | 15 | from ._utils import deref, force_set_attr, move_to_mem | |
| 16 | - from .constants import NULL, Nullable, handle | ||
| 17 | 16 | from .exceptions import DereferenceError, FreedMemoryError, NullPointerError | |
| 17 | + from .util import NULL, Nullable, handle | ||
| 18 | 18 | ||
| 19 | 19 | __all__ = ( | |
| 20 | 20 | "BasePointer", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,14 +21,15 @@ | |||
| 21 | 21 | from .exceptions import InvalidBindingParameter | |
| 22 | 22 | from .std_structs import STRUCT_MAP, DivT, Lconv, LDivT, Tm | |
| 23 | 23 | from .structure import StructPointer | |
| 24 | + from .util import handle | ||
| 24 | 25 | ||
| 25 | 26 | if TYPE_CHECKING: | |
| 26 | 27 | from .structure import Struct | |
| 27 | 28 | ||
| 28 | 29 | T = TypeVar("T") | |
| 29 | 30 | ||
| 30 | - PointerLike = Union[TypedCPointer[T], VoidPointer, None] | ||
| 31 | - StringLike = Union[str, bytes, VoidPointer, TypedCPointer[bytes]] | ||
| 31 | + PointerLike = Optional[Union[TypedCPointer[T], VoidPointer]] | ||
| 32 | + StringLike = Optional[Union[str, bytes, VoidPointer, TypedCPointer[bytes]]] | ||
| 32 | 33 | Format = Union[StringLike, PointerLike] | |
| 33 | 34 | TypedPtr = Optional[PointerLike[T]] | |
| 34 | 35 | PyCFuncPtrType = type(ctypes.CFUNCTYPE(None)) | |
@@ -330,6 +331,7 @@ def wrapper(*args): | |||
| 330 | 331 | return _CFuncTransport(wrapper, fn) | |
| 331 | 332 | ||
| 332 | 333 | ||
| 334 | + @handle | ||
| 333 | 335 | def binding_base( | |
| 334 | 336 | fn: "ctypes._NamedFuncPointer", | |
| 335 | 337 | *args, | |
@@ -380,7 +382,7 @@ def binding_base( | |||
| 380 | 382 | ||
| 381 | 383 | ||
| 382 | 384 | def make_string(data: StringLike) -> Union[bytes, ctypes.c_char_p]: | |
| 383 | - if type(data) not in {VoidPointer, str, bytes, TypedCPointer}: | ||
| 385 | + if (type(data) not in {VoidPointer, str, bytes, TypedCPointer}) and data: | ||
| 384 | 386 | raise InvalidBindingParameter( | |
| 385 | 387 | f"expected a string-like object, got {repr(data)}" # noqa | |
| 386 | 388 | ) | |
@@ -404,6 +406,9 @@ def make_string(data: StringLike) -> Union[bytes, ctypes.c_char_p]: | |||
| 404 | 406 | if isinstance(data, str): | |
| 405 | 407 | return data.encode() | |
| 406 | 408 | ||
| 409 | + if not data: | ||
| 410 | + data = ctypes.c_char_p(None) # type: ignore | ||
| 411 | + | ||
| 407 | 412 | assert isinstance(data, ctypes.c_char_p), f"{data} is not a char*" | |
| 408 | 413 | return data | |
| 409 | 414 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | from ._utils import get_mapped, map_type | |
| 8 | 8 | from .base_pointers import BaseCPointer, IterDereferencable, Typed | |
| 9 | - from .constants import handle | ||
| 9 | + from .util import handle | ||
| 10 | 10 | ||
| 11 | 11 | if TYPE_CHECKING: | |
| 12 | 12 | from .structure import Struct, StructPointer | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | from ._cstd import c_calloc, c_free | |
| 4 | 4 | from .base_pointers import BaseAllocatedPointer | |
| 5 | - from .constants import handle | ||
| 6 | 5 | from .exceptions import AllocationError | |
| 6 | + from .util import handle | ||
| 7 | 7 | ||
| 8 | 8 | __all__ = ("AllocatedArrayPointer", "calloc") | |
| 9 | 9 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments