|
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 | +from .util import NULL, Nullable, handle |
25 | 25 |
|
26 | 26 | if TYPE_CHECKING: |
27 | 27 | from .structure import Struct |
28 | 28 |
|
29 | 29 | T = TypeVar("T") |
30 | 30 |
|
31 | | -PointerLike = Optional[Union[TypedCPointer[T], VoidPointer]] |
| 31 | +PointerLike = Nullable[Optional[Union[TypedCPointer[T], VoidPointer]]] |
32 | 32 | StringLike = Optional[Union[str, bytes, VoidPointer, TypedCPointer[bytes]]] |
33 | 33 | Format = Union[StringLike, PointerLike] |
34 | 34 | TypedPtr = Optional[PointerLike[T]] |
@@ -276,7 +276,11 @@ def _process_args( |
276 | 276 | if not (isinstance if not is_type else issubclass)(value, n_type): |
277 | 277 | v_type = type(value) if not is_type else value |
278 | 278 |
|
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): |
280 | 284 | continue |
281 | 285 |
|
282 | 286 | if (n_type is FunctionType) and is_c_func: |
@@ -334,19 +338,21 @@ def wrapper(*args): |
334 | 338 | @handle |
335 | 339 | def binding_base( |
336 | 340 | fn: "ctypes._NamedFuncPointer", |
337 | | - *args, |
| 341 | + *simple_args, |
338 | 342 | map_extra: Optional[StructMap] = None, |
339 | 343 | ) -> Any: |
340 | 344 | smap = {**STRUCT_MAP, **(map_extra or {})} |
341 | 345 |
|
| 346 | + args = [i if i is not NULL else None for i in simple_args] |
| 347 | + |
342 | 348 | validator_args = [ |
343 | 349 | arg |
344 | 350 | if ( |
345 | 351 | (not isinstance(arg, FunctionType)) |
346 | 352 | and (not isinstance(arg, PyCFuncPtrType)) |
347 | 353 | ) |
348 | 354 | else _solve_func( |
349 | | - arg, |
| 355 | + arg, # type: ignore |
350 | 356 | typ, # type: ignore |
351 | 357 | smap, |
352 | 358 | ) |
|
0 commit comments