def _call_funcptr(self, funcptr, *newargs): if self._flags_ & _rawffi.FUNCFLAG_USE_ERRNO: tmp = _rawffi.get_errno() _rawffi.set_errno(get_errno()) set_errno(tmp) if self._flags_ & _rawffi.FUNCFLAG_USE_LASTERROR: tmp = _rawffi.get_last_error() _rawffi.set_last_error(get_last_error()) set_last_error(tmp) try: result = funcptr(*newargs) finally: if self._flags_ & _rawffi.FUNCFLAG_USE_ERRNO: tmp = _rawffi.get_errno() _rawffi.set_errno(get_errno()) set_errno(tmp) if self._flags_ & _rawffi.FUNCFLAG_USE_LASTERROR: tmp = _rawffi.get_last_error() _rawffi.set_last_error(get_last_error()) set_last_error(tmp) # try: return self._build_result(self._restype_, result) finally: funcptr.free_temp_buffers()
def test_last_error(self): import sys if sys.platform != 'win32': skip("Windows test") import _rawffi lib = _rawffi.CDLL(self.lib_name) A = _rawffi.Array('i') f = lib.ptr('check_last_error', ['i'], 'i') _rawffi.set_last_error(42) arg = A(1) arg[0] = 43 res = f(arg) assert res[0] == 42 z = _rawffi.get_last_error() assert z == 43 arg.free()