Author: Amaury Forgeot d'Arc <amaur...@gmail.com>
Branch: stdlib-2.7.3
Changeset: r55663:7c6d45a4cf28
Date: 2012-06-14 08:40 +0200
http://bitbucket.org/pypy/pypy/changeset/7c6d45a4cf28/

Log:    ctypes raises a TypeError when a non-ascii unicode field name is
        used.

diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -28,7 +28,12 @@
             raise OperationError(space.w_ValueError, space.wrap(
                 "Expected list of 2- or 3-size tuples"))
 
-        name = space.str_w(l_w[0])
+        try:
+            name = space.str_w(l_w[0])
+        except OperationError:
+            raise OperationError(space.w_TypeError, space.wrap(
+               "structure field name must be string not %s" % 
+               space.type(l_w[0]).getname(space)))
         tp = unpack_shape_with_length(space, l_w[1])
 
         if len_l == 3:
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
@@ -555,6 +555,7 @@
         raises(ValueError, "lib.ptr('get_char', [], 'x')")
         raises(ValueError, "_rawffi.Structure(['x1', 'xx'])")
         raises(ValueError, _rawffi.Structure, [('x1', 'xx')])
+        raises(TypeError, _rawffi.Structure, [(u'\xe9', 'l')])
         raises(ValueError, "_rawffi.Array('xx')")
 
     def test_longs_ulongs(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to