pombreda / ctypesgen

Automatically exported from code.google.com/p/ctypesgen
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Issue with _anonymous_ fields of non-struct types #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Checkout software
2. Go into test directory
3. Run "./testsuite.py"

What is the expected output? What do you see instead?

I expect all the tests to pass, instead I get 3 of these errors:

======================================================================
ERROR: test_structures (__main__.StructuresTest)
Tests from structures.py
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./testsuite.py", line 220, in setUp
    self.module, output = ctypesgentest.test(header_str)
  File "/home/jlisee/projects/ctypesgen-read-only/test/ctypesgentest.py", line 53, in test
    reload(module)  # import twice, this hack ensure that "temp" is force loaded (there *must* be a better way to do this)
  File "/home/jlisee/projects/ctypesgen-read-only/test/temp.py", line 622, in <module>
AttributeError: type object 'c_uint' has no attribute '_fields_

What version of the product are you using? On what operating system?

Python 2.7, Ubuntu 12.04 64 bit SVN r147 (with patch from Issue 39)

Please provide any additional information below.

The python docs say 
(http://docs.python.org/2/library/ctypes.html#ctypes.Structure._anonymous_):

Say "An optional sequence that lists the names of unnamed (anonymous) fields. 
_anonymous_ must be already defined when _fields_ is assigned, otherwise it 
will have no effect."

The generated code is:

# /usr/include/x86_64-linux-gnu/bits/waitstatus.h: 70
class struct_anon_21(Structure):
    pass

struct_anon_21.__slots__ = [
    '__w_termsig',
    '__w_coredump',
    '__w_retcode',
    'unnamed_1',
]

struct_anon_21._anonymous_ = [
    'unnamed_1',
]

struct_anon_21._fields_ = [
    ('__w_termsig', c_uint, 7),
    ('__w_coredump', c_uint, 1),
    ('__w_retcode', c_uint, 8),
    ('unnamed_1', c_int),
]

And the referenced source:

http://repo-genesis3.cbi.utsa.edu/crossref/ns-sli/usr/include/bits/waitstatus.h.
html

Original issue reported on code.google.com by jli...@gmail.com on 28 Feb 2013 at 3:32