[pypy-commit] pypy default: Test get_errno() and get_last_error() here
arigo
noreply at buildbot.pypy.org
Tue Dec 9 19:35:02 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r74871:05a286a4b5e0
Date: 2014-12-09 18:34 +0000
http://bitbucket.org/pypy/pypy/changeset/05a286a4b5e0/
Log: Test get_errno() and get_last_error() here
diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -16,6 +16,7 @@
#include "src/precommondefs.h"
#include <stdlib.h>
#include <stdio.h>
+ #include <errno.h>
struct x
{
@@ -204,6 +205,24 @@
return inp;
}
+ RPY_EXPORTED
+ int check_errno(int incoming)
+ {
+ int old_errno = errno;
+ errno = incoming;
+ return old_errno;
+ }
+
+ #ifdef _WIN32
+ #include <Windows.h>
+ RPY_EXPORTED
+ int check_last_error(int incoming)
+ {
+ int old_errno = GetLastError();
+ SetLastError(incoming);
+ return old_errno;
+ }
+ #endif
'''))
eci = ExternalCompilationInfo(include_dirs=[cdir])
return str(platform.compile([c_file], eci, 'x', standalone=False))
@@ -1150,6 +1169,37 @@
raises(OverflowError, "arg1[0] = 10**900")
arg1.free()
+ def test_errno(self):
+ import _rawffi
+ lib = _rawffi.CDLL(self.lib_name)
+ A = _rawffi.Array('i')
+ f = lib.ptr('check_errno', ['i'], 'i')
+ _rawffi.set_errno(42)
+ arg = A(1)
+ arg[0] = 43
+ res = f(arg)
+ assert res[0] == 42
+ z = _rawffi.get_errno()
+ assert z == 43
+ arg.free()
+
+ 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()
+
class AppTestAutoFree:
spaceconfig = dict(usemodules=['_rawffi', 'struct'])
More information about the pypy-commit
mailing list