Skip to content

Commit

Permalink
stack smashing my beloved
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroIntensity committed Mar 6, 2024
1 parent 31fc15e commit 325d8ad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/pointers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def attempt_decode(data: bytes) -> Union[str, bytes]:
def map_type(data: Any) -> "ctypes._CData":
"""Map the specified data to a C type."""
typ = get_mapped(type(data))
return typ(data) # type: ignore

try:
return typ(data) # type: ignore
except TypeError:
return ctypes.py_object(data)

def get_mapped(typ: Any) -> "Type[ctypes._CData]":
"""Get the C mapped value of the given type."""
Expand Down
2 changes: 1 addition & 1 deletion src/pointers/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def binding_base(
fn,
)


@handle
def make_string(data: StringLike) -> Union[bytes, ctypes.c_char_p]:
if (type(data) not in {VoidPointer, str, bytes, TypedCPointer}) and data:
raise InvalidBindingParameter(
Expand Down
1 change: 1 addition & 0 deletions src/pointers/c_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def to_voidp(ptr: TypedCPointer[Any]) -> VoidPointer:
def to_c_ptr(data: T) -> TypedCPointer[T]:
"""Convert a python type to a pointer to a C type."""
ct = map_type(data)
print(ct)

add_ref(ct)
address = ctypes.addressof(ct)
Expand Down
4 changes: 4 additions & 0 deletions src/pointers/stack_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def __init__(
self._freed = False
self._assigned = assigned

@property
def freed(self) -> bool:
return self._freed

@property
def address(self) -> Optional[int]:
return self._address
Expand Down

0 comments on commit 325d8ad

Please sign in to comment.