[pypy-commit] pypy default: Allow unicode for ctypes Structure field names.
anntzer
noreply at buildbot.pypy.org
Thu Oct 18 11:30:15 CEST 2012
Author: Antony Lee <anntzer.lee at gmail.com>
Branch:
Changeset: r58204:2020097f3291
Date: 2012-10-17 22:24 -0700
http://bitbucket.org/pypy/pypy/changeset/2020097f3291/
Log: Allow unicode for ctypes Structure field names. (Useful e.g. with
the unicode_literals future import.)
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -69,7 +69,8 @@
resnames.append(name)
names = resnames
self._names = names
- self.__dict__.update(fields)
+ for name, field in fields.items():
+ setattr(self, name, field)
class Field(object):
def __init__(self, name, offset, size, ctype, num, is_bitfield):
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
@@ -441,6 +441,11 @@
p = pointer(obj)
assert p.contents._b_base_ is p
+ def test_unicode_field_name(self):
+ # setattr autoconverts field names to bytes
+ class X(Structure):
+ _fields_ = [(u"i", c_int)]
+
class TestPointerMember(BaseCTypesTestChecker):
def test_1(self):
More information about the pypy-commit
mailing list