[pypy-svn] r78917 - pypy/branch/fast-forward/lib_pypy/_ctypes

afa at codespeak.net afa at codespeak.net
Tue Nov 9 13:41:43 CET 2010


Author: afa
Date: Tue Nov  9 13:41:40 2010
New Revision: 78917

Modified:
   pypy/branch/fast-forward/lib_pypy/_ctypes/array.py
   pypy/branch/fast-forward/lib_pypy/_ctypes/structure.py
Log:
Make some ctypes exceptions more like CPython.


Modified: pypy/branch/fast-forward/lib_pypy/_ctypes/array.py
==============================================================================
--- pypy/branch/fast-forward/lib_pypy/_ctypes/array.py	(original)
+++ pypy/branch/fast-forward/lib_pypy/_ctypes/array.py	Tue Nov  9 13:41:40 2010
@@ -91,6 +91,9 @@
                 if len(value) > self._length_:
                     raise ValueError("Invalid length")
                 value = self(*value)
+            elif not isinstance(value, self):
+                raise TypeError("expected string or Unicode object, %s found"
+                                % (value.__class__.__name__,))
         else:
             if isinstance(value, tuple):
                 if len(value) > self._length_:

Modified: pypy/branch/fast-forward/lib_pypy/_ctypes/structure.py
==============================================================================
--- pypy/branch/fast-forward/lib_pypy/_ctypes/structure.py	(original)
+++ pypy/branch/fast-forward/lib_pypy/_ctypes/structure.py	Tue Nov  9 13:41:40 2010
@@ -144,7 +144,11 @@
 
     def from_param(self, value):
         if isinstance(value, tuple):
-            value = self(*value)
+            try:
+                value = self(*value)
+            except Exception, e:
+                # XXX CPython does not even respect the exception type
+                raise RuntimeError("(%s) %s: %s" % (self.__name__, type(e), e))
         return _CDataMeta.from_param(self, value)
 
     def _CData_output(self, resarray, base=None, index=-1):
@@ -174,7 +178,7 @@
 
     def __init__(self, *args, **kwds):
         if len(args) > len(self._names):
-            raise TypeError("too many arguments")
+            raise TypeError("too many initializers")
         for name, arg in zip(self._names, args):
             if name in kwds:
                 raise TypeError("duplicate value for argument %r" % (



More information about the Pypy-commit mailing list