Skip to content

Commit 325d8ad

Browse files
committed
stack smashing my beloved
1 parent 31fc15e commit 325d8ad

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/pointers/_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ def attempt_decode(data: bytes) -> Union[str, bytes]:
8282
def map_type(data: Any) -> "ctypes._CData":
8383
"""Map the specified data to a C type."""
8484
typ = get_mapped(type(data))
85-
return typ(data) # type: ignore
8685

86+
try:
87+
return typ(data) # type: ignore
88+
except TypeError:
89+
return ctypes.py_object(data)
8790

8891
def get_mapped(typ: Any) -> "Type[ctypes._CData]":
8992
"""Get the C mapped value of the given type."""

src/pointers/bindings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def binding_base(
393393
fn,
394394
)
395395

396-
396+
@handle
397397
def make_string(data: StringLike) -> Union[bytes, ctypes.c_char_p]:
398398
if (type(data) not in {VoidPointer, str, bytes, TypedCPointer}) and data:
399399
raise InvalidBindingParameter(

src/pointers/c_pointer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def to_voidp(ptr: TypedCPointer[Any]) -> VoidPointer:
254254
def to_c_ptr(data: T) -> TypedCPointer[T]:
255255
"""Convert a python type to a pointer to a C type."""
256256
ct = map_type(data)
257+
print(ct)
257258

258259
add_ref(ct)
259260
address = ctypes.addressof(ct)

src/pointers/stack_pointer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def __init__(
3232
self._freed = False
3333
self._assigned = assigned
3434

35+
@property
36+
def freed(self) -> bool:
37+
return self._freed
38+
3539
@property
3640
def address(self) -> Optional[int]:
3741
return self._address

0 commit comments

Comments
 (0)