Skip to content

Commit ac9a05f

Browse files
author
roman_yakovenko
committed
fix 2779781 bug( pygccxml reverses array dimensions )
1 parent 6d04c5d commit ac9a05f

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

pygccxml/declarations/cpptypes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,22 @@ def _set_size(self, size):#sometimes there is a need to update the size of the a
446446
doc="returns array size" )
447447

448448
def build_decl_string(self, with_defaults=True):
449-
return self.base.build_decl_string(with_defaults) + '[%d]' % self.size
449+
#return self.base.build_decl_string(with_defaults) + '[%d]' % self.size
450+
return self.__bds_for_multi_dim_arrays( None, with_defaults )
451+
452+
def __bds_for_multi_dim_arrays(self, parent_dims=None, with_defaults=True):
453+
if parent_dims:
454+
parent_dims.append( self.size )
455+
else:
456+
parent_dims = [self.size]
457+
458+
if isinstance( self.base, array_t ):
459+
return self.base.__bds_for_multi_dim_arrays( parent_dims, with_defaults)
460+
else:
461+
tmp = []
462+
for s in parent_dims:
463+
tmp.append( '[%d]' % s )
464+
return self.base.build_decl_string(with_defaults) + ''.join( tmp )
450465

451466
def _clone_impl( self ):
452467
return array_t( self.base.clone(), self.size )

unittests/array_bug_tester.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2004-2008 Roman Yakovenko.
2+
# Distributed under the Boost Software License, Version 1.0. (See
3+
# accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
import os
7+
import unittest
8+
import autoconfig
9+
import parser_test_case
10+
11+
from pygccxml import utils
12+
from pygccxml import parser
13+
from pygccxml import declarations
14+
15+
16+
class tester_t( parser_test_case.parser_test_case_t ):
17+
def __init__(self, *args):
18+
parser_test_case.parser_test_case_t.__init__(self, *args)
19+
20+
def test1(self):
21+
code = 'int aaaa[2][3][4][5];'
22+
src_reader = parser.source_reader_t( self.config )
23+
global_ns = declarations.get_global_namespace( src_reader.read_string( code ) )
24+
aaaa_type = global_ns.var('aaaa').type
25+
self.failUnless( 'int[2][3][4][5]' == aaaa_type.decl_string, aaaa_type.decl_string )
26+
27+
def test2(self):
28+
code = 'int* aaaa[2][3][4][5];'
29+
src_reader = parser.source_reader_t( self.config )
30+
global_ns = declarations.get_global_namespace( src_reader.read_string( code ) )
31+
aaaa_type = global_ns.var('aaaa').type
32+
self.failUnless( 'int *[2][3][4][5]' == aaaa_type.decl_string, aaaa_type.decl_string )
33+
34+
def test3(self):
35+
code = 'int aaaa[2];'
36+
src_reader = parser.source_reader_t( self.config )
37+
global_ns = declarations.get_global_namespace( src_reader.read_string( code ) )
38+
aaaa_type = global_ns.var('aaaa').type
39+
self.failUnless( 'int[2]' == aaaa_type.decl_string, aaaa_type.decl_string )
40+
41+
def test4(self):
42+
code = 'struct xyz{}; xyz aaaa[2][3];'
43+
src_reader = parser.source_reader_t( self.config )
44+
global_ns = declarations.get_global_namespace( src_reader.read_string( code ) )
45+
aaaa_type = global_ns.var('aaaa').type
46+
self.failUnless( '::xyz[2][3]' == aaaa_type.decl_string, aaaa_type.decl_string )
47+
48+
49+
def create_suite():
50+
suite = unittest.TestSuite()
51+
suite.addTest( unittest.makeSuite(tester_t))
52+
return suite
53+
54+
def run_suite():
55+
unittest.TextTestRunner(verbosity=2).run( create_suite() )
56+
57+
if __name__ == "__main__":
58+
run_suite()

unittests/test_all.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import undname_creator_tester
5555
import calling_convention_tester
5656
import const_volatile_arg_tester
57+
import array_bug_tester
5758

5859
testers = [
5960
decl_string_tester
@@ -104,6 +105,7 @@
104105
, undname_creator_tester
105106
, calling_convention_tester
106107
, const_volatile_arg_tester
108+
, array_bug_tester
107109
]
108110

109111
def create_suite():

0 commit comments

Comments
 (0)