Commit f4c9cfdf authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Fix SWIG/ctypes inteface issues

The mapping of the ctypes value (returned by the shared lib) to a swig
pointer was incorrect. The return value of the Ada function had to be
set in ctypes to POINTER(c_char) and not to c_char_p (which returned a
python 'str' objet with messy values inside).
parent 459b6b36
......@@ -99,20 +99,18 @@ class sdlHandler(object):
typename = sort.ReferencedTypeName.replace('-', '_')
print 'Reading variable "{}" of type "{}"'.format(var, typename)
get_size = getattr(self.dll, "{}_size".format(var))
get_size.restype = ctypes.c_long
get_value = getattr(self.dll, "{}_value".format(var))
get_value.restype = ctypes.c_char_p
get_size.restype = ctypes.c_uint
size = get_size()
# ctypes hint: don't use c_char_p except for text strings
get_value = getattr(self.dll, "{}_value".format(var))
get_value.restype = ctypes.POINTER(ctypes.c_char)
value = get_value()
# From the pointer to the value, copy the content in a byte array
# (this is needed to convert the value to SWIG)
as_bytes = ctypes.cast(value,
ctypes.POINTER((ctypes.c_ubyte * size)))
swig_ptr = ASN1.DV.new_byte_SWIG_PTR(size)
for idx in xrange(size):
if value[idx] else 0)
asn1_instance = getattr(ASN1, typename)()
setter = getattr(ASN1.DV, "SetDataFor_{}".format(typename))
setter(asn1_instance._ptr, swig_ptr)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment