[pypy-svn] r26515 - in pypy/dist/pypy/rpython/rctypes: test tool
arigo at codespeak.net
arigo at codespeak.net
Fri Apr 28 12:09:07 CEST 2006
Author: arigo
Date: Fri Apr 28 12:09:06 2006
New Revision: 26515
Modified:
pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py
pypy/dist/pypy/rpython/rctypes/tool/util.py
Log:
A ctypes helper to raise an exception containing the current C-level errno.
The next step would be to support it in rctypes.
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rfunc.py Fri Apr 28 12:09:06 2006
@@ -3,7 +3,7 @@
"""
import py
-import sys
+import sys, errno
import pypy.rpython.rctypes.implementation
from pypy.annotation.annrpython import RPythonAnnotator
from pypy.translator.translator import TranslationContext, graphof
@@ -106,6 +106,21 @@
s2 = ctime(byref(c_long(N)))
assert s1.strip() == s2.strip()
+def test_open():
+ if sys.platform == 'win32':
+ py.test.skip("Unix only")
+ open = mylib.open
+ fd = open("/_rctypes_test_rfunc/this/directory/does/not/exist/at/all!",
+ 0, 0)
+ try:
+ util.setfromerrno()
+ except OSError, e:
+ pass
+ else:
+ raise AssertionError("util.setfromerrno() should have raised")
+ assert fd == -1
+ assert e.errno == errno.ENOENT
+
##def test_callback():
## assert callback(100) == 103
## assert pycallback(100) == 103
Modified: pypy/dist/pypy/rpython/rctypes/tool/util.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/tool/util.py (original)
+++ pypy/dist/pypy/rpython/rctypes/tool/util.py Fri Apr 28 12:09:06 2006
@@ -1,9 +1,16 @@
"""
-This is the module 'ctypes.util', copied from ctypes 0.9.9.6.
+This is the module 'ctypes.util', copied from ctypes 0.9.9.6,
+with an extra setfromerrno() helper.
"""
import sys, os
import ctypes
+def setfromerrno(exc=OSError):
+ """Raise an exception of the given class with the last failed C library
+ function's errno."""
+ ctypes.pythonapi.PyErr_SetFromErrno(ctypes.py_object(exc))
+
+
# find_library(name) returns the pathname of a library, or None.
if os.name == "nt":
def find_library(name):
More information about the Pypy-commit
mailing list