[pypy-commit] pypy default: don't raise a warning if the restype is not set, and add a test to check that we hit the fastpath even in that case
antocuni
noreply at buildbot.pypy.org
Thu Jul 28 16:11:50 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r46041:9d98198682de
Date: 2011-07-28 16:12 +0200
http://bitbucket.org/pypy/pypy/changeset/9d98198682de/
Log: don't raise a warning if the restype is not set, and add a test to
check that we hit the fastpath even in that case
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -78,8 +78,6 @@
_com_iid = None
_is_fastpath = False
- __restype_set = False
-
def _getargtypes(self):
return self._argtypes_
@@ -149,7 +147,6 @@
return self._restype_
def _setrestype(self, restype):
- self.__restype_set = True
self._ptr = None
if restype is int:
from ctypes import c_int
@@ -315,10 +312,6 @@
warnings.warn('C function without declared arguments called',
RuntimeWarning, stacklevel=2)
argtypes = []
-
- if not self.__restype_set:
- warnings.warn('C function without declared return type called',
- RuntimeWarning, stacklevel=2)
if self._com_index:
from ctypes import cast, c_void_p, POINTER
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -46,6 +46,18 @@
tf_b.argtypes = (c_byte,)
assert tf_b(-126) == -42
+ def test_undeclared_restype(self):
+ # make sure we get a fresh function
+ try:
+ del dll.tf_i
+ except AttributeError:
+ pass
+ tf_i = dll.tf_i
+ assert not tf_i._is_fastpath
+ tf_i.argtypes = (c_int,)
+ assert tf_i._is_fastpath
+ assert tf_i(12) == 4
+
def test_pointer_args(self):
f = dll._testfunc_p_p
f.restype = POINTER(c_int)
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -488,11 +488,9 @@
warnings.simplefilter("always")
with warnings.catch_warnings(record=True) as w:
dll.get_an_integer()
- assert len(w) == 2
+ assert len(w) == 1
assert issubclass(w[0].category, RuntimeWarning)
- assert issubclass(w[1].category, RuntimeWarning)
assert "C function without declared arguments called" in str(w[0].message)
- assert "C function without declared return type called" in str(w[1].message)
def test_errcheck(self):
py.test.skip('fixme')
More information about the pypy-commit
mailing list