--- a/runtime/typemapping.py Mon Oct 31 18:21:09 2022 +0800
+++ b/runtime/typemapping.py Tue Nov 01 14:19:23 2022 +0800
@@ -4,14 +4,9 @@
# See COPYING.Runtime file for copyrights details.
from datetime import timedelta as td
-ctypes.pythonapi.PyUnicode_AsUTF8.argtypes = (ctypes.c_void_p,)
-ctypes.pythonapi.PyUnicode_AsUTF8.restype = ctypes.POINTER(ctypes.c_char)
class IEC_STRING(Structure):
Must be changed according to changes in iec_types.h
@@ -28,18 +23,18 @@
("ns", c_long)] # tv_nsec
-def _t(t, u=lambda x: x.value, p=lambda t, x: t(x)):
+def _t(t, u=lambda x: x.contents, p=lambda t, x: t(x)): - lambda x: td(0, x.s, x.ns/1000.0),
+ lambda x: td(0, x.contents.s, x.contents.ns/1000.0), lambda t, x: t(x.days * 24 * 3600 + x.seconds, x.microseconds*1000))
SameEndianessTypeTranslator = {
- "BOOL": _t(c_uint8, lambda x: x.value != 0),
+ "BOOL": _t(c_uint8, lambda x: bool(x.contents)), "TRANSITION": _t(c_uint8),
@@ -47,7 +42,7 @@
- lambda x: x.body[:x.len],
+ lambda x: x.contents.body[:x.contents.len], lambda t, x: t(len(x), x)),
@@ -80,10 +75,10 @@
- buffptr = cast(ctypes.pythonapi.PyString_AsString(id(buff)), c_void_p).value
+ buffptr = cast(cast(buff, c_char_p), c_void_p).value - c_type, unpack_func, _pack_func = \
- TypeTranslator.get(iectype, (None, None, None))
+ c_type, unpack_func, _pack_func = TypeTranslator.get(iectype, cursor = c_void_p(buffptr + buffoffset)
@@ -97,8 +92,12 @@
if c_type is not None and (buffoffset + size) <= buffsize:
- value = unpack_func(cast(cursor,
- POINTER(c_type)).contents)
+ n = cast(cursor, POINTER(c_type)) + if iectype not in ["BOOL", "DATE", "DT", "STRING", "TIME", "TOD"]: + elif iectype == "STRING":