Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e2b0fe4

Browse filesBrowse files
authored
_ctypes pt. 2 (#5524)
* add __version__ * add more types/constants * shared library and ExternalLibs implementation * FreeLibrary for windows * fixed PyCSimple * LoadLibrary and FreeLibrary for non-windows * fault-tolerant float equality Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent fa2acd7 commit e2b0fe4
Copy full SHA for e2b0fe4

File tree

11 files changed

+424
-95
lines changed
Filter options

11 files changed

+424
-95
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+46-78
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎extra_tests/snippets/builtins_ctypes.py

Copy file name to clipboardExpand all lines: extra_tests/snippets/builtins_ctypes.py
+28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
import os as _os, sys as _sys
2+
13
from _ctypes import sizeof
24
from _ctypes import _SimpleCData
35
from struct import calcsize as _calcsize
46

7+
def create_string_buffer(init, size=None):
8+
"""create_string_buffer(aBytes) -> character array
9+
create_string_buffer(anInteger) -> character array
10+
create_string_buffer(aBytes, anInteger) -> character array
11+
"""
12+
if isinstance(init, bytes):
13+
if size is None:
14+
size = len(init)+1
15+
_sys.audit("ctypes.create_string_buffer", init, size)
16+
buftype = c_char * size
17+
buf = buftype()
18+
buf.value = init
19+
return buf
20+
elif isinstance(init, int):
21+
_sys.audit("ctypes.create_string_buffer", None, init)
22+
buftype = c_char * init
23+
buf = buftype()
24+
return buf
25+
raise TypeError(init)
26+
527
def _check_size(typ, typecode=None):
628
# Check if sizeof(ctypes_type) against struct.calcsize. This
729
# should protect somewhat against a misconfigured libffi.
@@ -103,3 +125,9 @@ class c_void_p(_SimpleCData):
103125
class c_bool(_SimpleCData):
104126
_type_ = "?"
105127
_check_size(c_bool)
128+
129+
i = c_int(42)
130+
f = c_float(3.14)
131+
# s = create_string_buffer(b'\000' * 32)
132+
assert i.value == 42
133+
assert abs(f.value - 3.14) < 1e-06

‎vm/Cargo.toml

Copy file name to clipboardExpand all lines: vm/Cargo.toml
+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ uname = "0.1.1"
100100
rustyline = { workspace = true }
101101
which = "6"
102102
errno = "0.3"
103+
libloading = "0.8"
103104
widestring = { workspace = true }
104105

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.