示例#1
0
 def test_returning_str(self):
     import _rawffi
     lib = _rawffi.CDLL(self.lib_name)
     char_check = lib.ptr('char_check', ['c', 'c'], 's')
     A = _rawffi.Array('c')
     arg1 = A(1)
     arg2 = A(1)
     arg1[0] = 'y'
     arg2[0] = 'x'
     res = char_check(arg1, arg2)
     assert _rawffi.charp2string(res[0]) == 'xxxxxx'
     assert _rawffi.charp2rawstring(res[0]) == 'xxxxxx'
     assert _rawffi.charp2rawstring(res[0], 3) == 'xxx'
     a = A(6, 'xx\x00\x00xx')
     assert _rawffi.charp2string(a.buffer) == 'xx'
     assert _rawffi.charp2rawstring(a.buffer, 4) == 'xx\x00\x00'
     res.free()
     arg1[0] = 'x'
     arg2[0] = 'y'
     res = char_check(arg1, arg2)
     assert res[0] == 0
     assert _rawffi.charp2string(res[0]) is None
     res.free()
     arg1.free()
     arg2.free()
示例#2
0
 def test_buffer_info(self):
     a = self.array('c', 'Hi!')
     bi = a.buffer_info()
     assert bi[0] != 0
     assert bi[1] == 3
     import _rawffi
     data = _rawffi.charp2string(bi[0])
     assert data[0:3] == 'Hi!'
示例#3
0
 def test_buffer_info(self):
     a = self.array('c', 'Hi!')
     bi = a.buffer_info()
     assert bi[0] != 0
     assert bi[1] == 3
     import _rawffi
     data = _rawffi.charp2string(bi[0])
     assert data[0:3] == 'Hi!'
示例#4
0
    def test_array_autofree(self):
        import gc, _rawffi
        oldnum = _rawffi._num_of_allocated_objects()

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        assert oldnum == _rawffi._num_of_allocated_objects()
示例#5
0
    def test_array_autofree(self):
        import gc, _rawffi
        gc.collect()
        oldnum = _rawffi._num_of_allocated_objects()

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        assert oldnum == _rawffi._num_of_allocated_objects()
示例#6
0
 def _CData_output(self, resarray, base=None, index=-1):
     # 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
     res._base = base
     res._index = index
     return res
示例#7
0
 def _CData_output(self, resarray, base=None, index=-1):
     # 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
     res._base = base
     res._index = index
     return res
示例#8
0
 def test_returning_str(self):
     import _rawffi
     lib = _rawffi.CDLL(self.lib_name)
     char_check = lib.ptr('char_check', ['c', 'c'], 's')
     A = _rawffi.Array('c')
     arg1 = A(1)
     arg2 = A(1)
     arg1[0] = 'y'
     arg2[0] = 'x'
     res = char_check(arg1, arg2)
     assert _rawffi.charp2string(res[0]) == 'xxxxxx'
     assert _rawffi.charp2rawstring(res[0]) == 'xxxxxx'
     assert _rawffi.charp2rawstring(res[0], 3) == 'xxx'
     a = A(6, 'xx\x00\x00xx')
     assert _rawffi.charp2string(a.buffer) == 'xx'
     assert _rawffi.charp2rawstring(a.buffer, 4) == 'xx\x00\x00'
     arg1[0] = 'x'
     arg2[0] = 'y'
     res = char_check(arg1, arg2)
     assert res[0] == 0
     assert _rawffi.charp2string(res[0]) is None
     arg1.free()
     arg2.free()
示例#9
0
    def test_array_autofree(self):
        import gc, _rawffi
        gc.collect()
        try:
            oldnum = _rawffi._num_of_allocated_objects()
        except RuntimeError:
            oldnum = '?'

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        if oldnum != '?':
            assert oldnum == _rawffi._num_of_allocated_objects()
示例#10
0
    def test_array_autofree(self):
        import gc, _rawffi
        gc.collect()
        try:
            oldnum = _rawffi._num_of_allocated_objects()
        except RuntimeError:
            oldnum = '?'

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        if oldnum != '?':
            assert oldnum == _rawffi._num_of_allocated_objects()
示例#11
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
示例#12
0
 def _getvalue(self):
     addr = self._buffer[0]
     if addr == 0:
         return None
     else:
         return _rawffi.charp2string(addr)
示例#13
0
 def getvalue(self):
     return _rawffi.charp2string(self._buffer.buffer,
                                 self._length_)
示例#14
0
 def _getvalue(self):
     addr = self._buffer[0]
     if addr == 0:
         return None
     else:
         return _rawffi.charp2string(addr)
示例#15
0
 def getvalue(self):
     return _rawffi.charp2string(self._buffer.buffer,
                                 self._length_)