Skip to content

Commit 1edb62c

Browse files
committed
a few patches
1 parent d9c6527 commit 1edb62c

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

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"
26+
version = "2.3.0-alpha"
2727

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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if __name__ == "__main__":
77
setup(
88
name="pointers.py",
9-
version="2.2.0",
9+
version="2.3.0-alpha",
1010
packages=["pointers"],
1111
license="MIT",
1212
project_urls={

src/mod.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#include <stdio.h>
1515
#include <frameobject.h> // needed to get members of PyFrameObject
1616
#define GETOBJ PyObject* obj; if (!PyArg_ParseTuple(args, "O", &obj)) return NULL
17-
#define INIT_HANDLER(sig, handle, msg) if (signal(sig, handle) == SIG_ERR) { \
18-
PyErr_SetString(PyExc_ImportError, msg); \
19-
return NULL; \
20-
}
2117

2218
static jmp_buf buf;
2319

src/pointers/bindings.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
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
24+
from .util import NULL, Nullable, handle
2525

2626
if TYPE_CHECKING:
2727
from .structure import Struct
2828

2929
T = TypeVar("T")
3030

31-
PointerLike = Optional[Union[TypedCPointer[T], VoidPointer]]
31+
PointerLike = Nullable[Optional[Union[TypedCPointer[T], VoidPointer]]]
3232
StringLike = Optional[Union[str, bytes, VoidPointer, TypedCPointer[bytes]]]
3333
Format = Union[StringLike, PointerLike]
3434
TypedPtr = Optional[PointerLike[T]]
@@ -276,7 +276,11 @@ def _process_args(
276276
if not (isinstance if not is_type else issubclass)(value, n_type):
277277
v_type = type(value) if not is_type else value
278278

279-
if (n_type is BasePointer) and (value is None):
279+
if (n_type in {
280+
BasePointer,
281+
BaseCPointer,
282+
StructPointer
283+
}) and (value is None):
280284
continue
281285

282286
if (n_type is FunctionType) and is_c_func:
@@ -334,19 +338,21 @@ def wrapper(*args):
334338
@handle
335339
def binding_base(
336340
fn: "ctypes._NamedFuncPointer",
337-
*args,
341+
*simple_args,
338342
map_extra: Optional[StructMap] = None,
339343
) -> Any:
340344
smap = {**STRUCT_MAP, **(map_extra or {})}
341345

346+
args = [i if i is not NULL else None for i in simple_args]
347+
342348
validator_args = [
343349
arg
344350
if (
345351
(not isinstance(arg, FunctionType))
346352
and (not isinstance(arg, PyCFuncPtrType))
347353
)
348354
else _solve_func(
349-
arg,
355+
arg, # type: ignore
350356
typ, # type: ignore
351357
smap,
352358
)

src/pointers/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434

3535

3636
class NULL:
37-
"""Unique object representing a NULL address."""
37+
"""Unique object representing a NULL address.
38+
39+
May be used with object pointers or passed to bindings.
40+
"""
3841

3942

4043
Nullable = Union[T, Type[NULL]]

0 commit comments

Comments
 (0)