Skip to content
Merged
124 changes: 46 additions & 78 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions extra_tests/snippets/builtins_ctypes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import os as _os, sys as _sys

from _ctypes import sizeof
from _ctypes import _SimpleCData
from struct import calcsize as _calcsize

def create_string_buffer(init, size=None):
"""create_string_buffer(aBytes) -> character array
create_string_buffer(anInteger) -> character array
create_string_buffer(aBytes, anInteger) -> character array
"""
if isinstance(init, bytes):
if size is None:
size = len(init)+1
_sys.audit("ctypes.create_string_buffer", init, size)
buftype = c_char * size
buf = buftype()
buf.value = init
return buf
elif isinstance(init, int):
_sys.audit("ctypes.create_string_buffer", None, init)
buftype = c_char * init
buf = buftype()
return buf
raise TypeError(init)

def _check_size(typ, typecode=None):
# Check if sizeof(ctypes_type) against struct.calcsize. This
# should protect somewhat against a misconfigured libffi.
Expand Down Expand Up @@ -103,3 +125,9 @@ class c_void_p(_SimpleCData):
class c_bool(_SimpleCData):
_type_ = "?"
_check_size(c_bool)

i = c_int(42)
f = c_float(3.14)
# s = create_string_buffer(b'\000' * 32)
assert i.value == 42
assert abs(f.value - 3.14) < 1e-06
1 change: 1 addition & 0 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ uname = "0.1.1"
rustyline = { workspace = true }
which = "6"
errno = "0.3"
libloading = "0.8"
widestring = { workspace = true }

[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
Expand Down
Loading
Loading