Skip to content

Commit 1189bac

Browse files
committed
i think im done
1 parent 79fb7ab commit 1189bac

File tree

15 files changed

+23
-46
lines changed

15 files changed

+23
-46
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Why would you ever need this
88

9-
- [Documentation](https://pointerspy.netlify.app/)
9+
- [Documentation](https://pointers.zintensity.dev/)
1010
- [Source](https://github.com/ZeroIntensity/pointers.py)
1111
- [PyPI](https://pypi.org/project/pointers.py)
1212

docs/using_pointers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def my_function(a: str, b: str, c: Pointer): # must be type hinted as Pointer t
8181
my_function('a', 'b', 'c')
8282
```
8383

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.
8585

8686
The first alternative is `decay_annotated`, which decays parameters hinted as `Annotated[T, Pointer]` to a pointer.
8787

@@ -110,7 +110,7 @@ def my_function(a: str, b: str, c: Annotated[str, Pointer]):
110110
print(a, b, ~c) # type checker error!
111111
```
112112

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:
114114

115115
```py
116116
from pointers import decay_wrapped, Pointer
@@ -126,7 +126,7 @@ def my_function(a: str, b: str, c: Pointer[str]):
126126
my_function('a', 'b', 'c') # works just fine, type checker things c takes a string
127127
```
128128

129-
It can be broken pretty easily though:
129+
If the wrapper doesn't match, things won't work properly:
130130

131131
```py
132132
from pointers import decay_wrapped, Pointer

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers = [
2323
dependencies = [
2424
"typing_extensions",
2525
]
26-
version = "2.2.0-beta"
26+
version = "2.2.0"
2727

2828
[project.urls]
2929
Documentation = "https://pointers.zintensity.dev"

src/mod.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ static PyObject* handle(PyObject* self, PyObject* args) {
9696

9797
PyErr_Format(
9898
PyExc_RuntimeError,
99-
"%s occured during execution of %S",
100-
val == 1 ? "segment violation" : "python aborted",
99+
"segment violation occured during execution of %S",
101100
name
102101
);
103102

src/pointers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
TypedCPointer, VoidPointer, array, cast, to_c_ptr, to_struct_ptr, to_voidp
1616
)
1717
from .calloc import AllocatedArrayPointer, calloc
18-
from .constants import NULL, Nullable, handle, raw_type, struct_cast
1918
from .custom_binding import binding, binds
2019
from .decay import decay, decay_annotated, decay_wrapped
2120
from .exceptions import (
@@ -28,6 +27,7 @@
2827
from .object_pointer import Pointer, to_ptr
2928
from .std_structs import DivT, Lconv, LDivT, Tm
3029
from .structure import Struct, StructPointer
30+
from .util import NULL, Nullable, handle, raw_type, struct_cast
3131

32-
__version__ = "2.2.0-beta"
32+
__version__ = "2.2.0"
3333
__license__ = "MIT"

src/pointers/base_pointers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from _pointers import add_ref, remove_ref
1414

1515
from ._utils import deref, force_set_attr, move_to_mem
16-
from .constants import NULL, Nullable, handle
1716
from .exceptions import DereferenceError, FreedMemoryError, NullPointerError
17+
from .util import NULL, Nullable, handle
1818

1919
__all__ = (
2020
"BasePointer",

src/pointers/bindings.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
from .exceptions import InvalidBindingParameter
2222
from .std_structs import STRUCT_MAP, DivT, Lconv, LDivT, Tm
2323
from .structure import StructPointer
24+
from .util import handle
2425

2526
if TYPE_CHECKING:
2627
from .structure import Struct
2728

2829
T = TypeVar("T")
2930

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]]]
3233
Format = Union[StringLike, PointerLike]
3334
TypedPtr = Optional[PointerLike[T]]
3435
PyCFuncPtrType = type(ctypes.CFUNCTYPE(None))
@@ -330,6 +331,7 @@ def wrapper(*args):
330331
return _CFuncTransport(wrapper, fn)
331332

332333

334+
@handle
333335
def binding_base(
334336
fn: "ctypes._NamedFuncPointer",
335337
*args,
@@ -380,7 +382,7 @@ def binding_base(
380382

381383

382384
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:
384386
raise InvalidBindingParameter(
385387
f"expected a string-like object, got {repr(data)}" # noqa
386388
)
@@ -404,6 +406,9 @@ def make_string(data: StringLike) -> Union[bytes, ctypes.c_char_p]:
404406
if isinstance(data, str):
405407
return data.encode()
406408

409+
if not data:
410+
data = ctypes.c_char_p(None) # type: ignore
411+
407412
assert isinstance(data, ctypes.c_char_p), f"{data} is not a char*"
408413
return data
409414

src/pointers/c_pointer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ._utils import get_mapped, map_type
88
from .base_pointers import BaseCPointer, IterDereferencable, Typed
9-
from .constants import handle
9+
from .util import handle
1010

1111
if TYPE_CHECKING:
1212
from .structure import Struct, StructPointer

src/pointers/calloc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from ._cstd import c_calloc, c_free
44
from .base_pointers import BaseAllocatedPointer
5-
from .constants import handle
65
from .exceptions import AllocationError
6+
from .util import handle
77

88
__all__ = ("AllocatedArrayPointer", "calloc")
99

0 commit comments

Comments
 (0)