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()
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()
def _string_at_addr(addr, lgt): # address here can be almost anything import ctypes arg = ctypes.c_char_p._CData_value(addr) return _rawffi.charp2rawstring(arg, lgt)
def getraw(self): return _rawffi.charp2rawstring(self._buffer.buffer, self._length_)
def _string_at_addr(addr, lgt): # address here can be almost anything import ctypes cobj = ctypes.c_void_p.from_param(addr) arg = cobj._get_buffer_value() return _rawffi.charp2rawstring(arg, lgt)