Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
par down ctypes
  • Loading branch information
arihant2math committed Mar 24, 2025
commit 62259987fa87f0b33339c6b62c0445215805d477
26 changes: 16 additions & 10 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def create_unicode_buffer(init, size=None):
return buf
elif isinstance(init, int):
_sys.audit("ctypes.create_unicode_buffer", None, init)
buftype = c_wchar * init
buftype = c_wchar.__mul__(init)
Comment thread
arihant2math marked this conversation as resolved.
buf = buftype()
return buf
raise TypeError(init)
Expand Down Expand Up @@ -495,14 +495,15 @@ def WinError(code=None, descr=None):
c_ssize_t = c_longlong

# functions

from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, _cast_addr

## void *memmove(void *, const void *, size_t);
memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr)
# TODO: RUSTPYTHON
Comment thread
youknowone marked this conversation as resolved.
Outdated
# memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr)

## void *memset(void *, int, size_t)
memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr)
# TODO: RUSTPYTHON
Comment thread
youknowone marked this conversation as resolved.
Outdated
# memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr)

def PYFUNCTYPE(restype, *argtypes):
class CFunctionType(_CFuncPtr):
Expand All @@ -511,11 +512,13 @@ class CFunctionType(_CFuncPtr):
_flags_ = _FUNCFLAG_CDECL | _FUNCFLAG_PYTHONAPI
return CFunctionType

_cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)(_cast_addr)
# TODO: RUSTPYTHON
Comment thread
youknowone marked this conversation as resolved.
Outdated
# _cast = PYFUNCTYPE(py_object, c_void_p, py_object, py_object)(_cast_addr)
def cast(obj, typ):
return _cast(obj, obj, typ)

_string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
# TODO: RUSTPYTHON
Comment thread
youknowone marked this conversation as resolved.
Outdated
# _string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
def string_at(ptr, size=-1):
"""string_at(addr[, size]) -> string

Expand All @@ -527,7 +530,8 @@ def string_at(ptr, size=-1):
except ImportError:
pass
else:
_wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
# TODO: RUSTPYTHON
Comment thread
youknowone marked this conversation as resolved.
Outdated
# _wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
def wstring_at(ptr, size=-1):
"""wstring_at(addr[, size]) -> string

Expand All @@ -551,8 +555,9 @@ def DllCanUnloadNow():
return 0 # S_OK
return ccom.DllCanUnloadNow()

from ctypes._endian import BigEndianStructure, LittleEndianStructure
from ctypes._endian import BigEndianUnion, LittleEndianUnion
# TODO: RUSTPYTHON
# from ctypes._endian import BigEndianStructure, LittleEndianStructure
# from ctypes._endian import BigEndianUnion, LittleEndianUnion

# Fill in specifically-sized types
c_int8 = c_byte
Expand All @@ -574,4 +579,5 @@ def DllCanUnloadNow():
else:
raise SystemError(f"Unexpected sizeof(time_t): {SIZEOF_TIME_T=}")

_reset_cache()
# TODO: RUSTPYTHON
# _reset_cache()