예제 #1
0
 def test_pointer_identity(self):
     from _rawffi.alt import types
     x = types.Pointer(types.slong)
     y = types.Pointer(types.slong)
     z = types.Pointer(types.char)
     assert x is y
     assert x is not z
예제 #2
0
 def test_pointer_to_incomplete_struct(self):
     from _rawffi.alt import _StructDescr, Field, types
     longsize = types.slong.sizeof()
     fields = [
         Field('x', types.slong),
         Field('y', types.slong),
     ]
     descr = _StructDescr('foo')
     foo_ffitype = descr.ffitype
     foo_p = types.Pointer(descr.ffitype)
     assert foo_p.deref_pointer() is foo_ffitype
     descr.define_fields(fields)
     assert descr.ffitype is foo_ffitype
     assert foo_p.deref_pointer() is foo_ffitype
     assert types.Pointer(descr.ffitype) is foo_p
예제 #3
0
 def test_typed_pointer(self):
     from _rawffi.alt import types
     intptr = types.Pointer(types.sint)  # create a typed pointer to sint
     assert intptr.deref_pointer() is types.sint
     assert str(intptr) == '<ffi type (pointer to sint)>'
     assert types.sint.deref_pointer() is None
     raises(TypeError, "types.Pointer(42)")
예제 #4
0
 def _CData_output(self, resarray, base=None, index=-1):
     from _rawffi.alt import types
     # If a char_p or unichar_p is received, skip the string interpretation
     if base._ffiargtype != types.Pointer(types.char_p) and \
        base._ffiargtype != types.Pointer(types.unichar_p):
         # this seems to be a string if we're array of char, surprise!
         from ctypes import c_char, c_wchar
         if self._type_ is c_char:
             return _rawffi.charp2string(resarray.buffer, self._length_)
         if self._type_ is c_wchar:
             return _rawffi.wcharp2unicode(resarray.buffer, self._length_)
     res = self.__new__(self)
     ffiarray = self._ffiarray.fromaddress(resarray.buffer, self._length_)
     res._buffer = ffiarray
     if base is not None:
         res._base = base
         res._index = index
     return res
예제 #5
0
 def test_char_p_cached(self):
     from _rawffi.alt import types
     x = types.Pointer(types.char)
     assert x is types.char_p
     x = types.Pointer(types.unichar)
     assert x is types.unichar_p