Commits

Armin Rigo committed 5c61d61 Merge

merge heads

Comments (0)

Files changed (4)

lib_pypy/_ctypes/function.py

 import _rawffi
 import sys
 import traceback
+import warnings
 
 from _ctypes.basics import ArgumentError, keepalive_key
 from _ctypes.basics import _CData, _CDataMeta, cdata_from_address
     _com_index = None
     _com_iid = None
 
+    __restype_set = False
+
     def _getargtypes(self):
         return self._argtypes_
 
         return self._restype_
 
     def _setrestype(self, restype):
+        self.__restype_set = True
         self._ptr = None
         if restype is int:
             from ctypes import c_int
             return
 
         if argtypes is None:
+            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

lib_pypy/_sqlite3.py

 sqlite.sqlite3_errmsg.restype = c_char_p
 sqlite.sqlite3_get_autocommit.argtypes = [c_void_p]
 sqlite.sqlite3_get_autocommit.restype = c_int
+sqlite.sqlite3_libversion.argtypes = []
 sqlite.sqlite3_libversion.restype = c_char_p
 sqlite.sqlite3_open.argtypes = [c_char_p, c_void_p]
 sqlite.sqlite3_prepare_v2.argtypes = [c_void_p, c_char_p, c_int, c_void_p, POINTER(c_char_p)]

pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py

         CTP = CFUNCTYPE(None)
         cfunc = dll._testfunc_callback_void
         cfunc.argtypes = [CTP]
+        cfunc.restype = int
         cfunc(CTP(callback))
         out, err = capsys.readouterr()
         assert (out, err) == ("", "")

pypy/module/test_lib_pypy/ctypes_tests/test_functions.py

         a[1].x = 33
         u = dll.ret_un_func(a[1])
         assert u.y == 33*10000
+
+    def test_warnings(self):
+        import warnings
+        warnings.simplefilter("always")
+        with warnings.catch_warnings(record=True) as w:
+            dll.get_an_integer()
+            assert len(w) == 2
+            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)
+
+        with warnings.catch_warnings(record=True) as w:
+            dll.get_an_integer.argtypes = []
+            dll.get_an_integer()
+            assert len(w) == 1
+            assert issubclass(w[0].category, RuntimeWarning)
+            assert "C function without declared return type called" in str(w[0].message)
+            
+        with warnings.catch_warnings(record=True) as w:
+            dll.get_an_integer.restype = None
+            dll.get_an_integer()
+            assert len(w) == 0
+            
+        warnings.resetwarnings()