Skip to content

Commit b632d7e

Browse files
committed
Merge branch 'hotfix/v1.8.5'
2 parents 69e78cf + 5b07065 commit b632d7e

16 files changed

+135
-27
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changes
22
=======
33

4+
Version 1.8.5
5+
-------------
6+
7+
1. Fix multiple calls to ``` __hash__()``` (#70)
8+
9+
2. ```Static``` and ```extern``` qualifiers are now no more treated as equivalents
10+
in the type_qualifiers class (for ```CastXML```).
11+
The old behaviour is kept for ```GCC-XML``` (```static == extern```).
12+
13+
3. Fix for ```declarations.is_noncopyable``` when used on a ```pointer_t```.
14+
415
Version 1.8.4
516
-------------
617

pygccxml/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
# TODO:
4141
# 1. Add "explicit" property for constructors
4242

43-
__version__ = '1.8.4'
43+
__version__ = '1.8.5'

pygccxml/declarations/calldef.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ def __eq__(self, other):
264264

265265
def __hash__(self):
266266
if "GCC" in utils.xml_generator:
267-
return (super.__hash__(self) ^
267+
return (super(calldef_t, self).__hash__() ^
268268
hash(self.return_type) ^
269269
hash(self.demangled_name))
270270
elif "CastXML" in utils.xml_generator:
271271
# No demangled name with castxml. Use the normal name.
272-
return (super.__hash__(self) ^
272+
return (super(calldef_t, self).__hash__() ^
273273
hash(self.return_type) ^
274274
hash(self.name))
275275

pygccxml/declarations/calldef_members.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __eq__(self, other):
6464
and self.has_const == other.has_const
6565

6666
def __hash__(self):
67-
return super.__hash__(self)
67+
return super(member_calldef_t, self).__hash__()
6868

6969
@property
7070
def virtuality(self):

pygccxml/declarations/cpptypes.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -924,18 +924,20 @@ class type_qualifiers_t(object):
924924

925925
"""contains additional information about type: mutable, static, extern"""
926926

927-
def __init__(self, has_static=False, has_mutable=False):
927+
def __init__(self, has_static=False, has_mutable=False, has_extern=False):
928928
self._has_static = has_static
929+
self._has_extern = has_extern
929930
self._has_mutable = has_mutable
930931

931932
def __eq__(self, other):
932933
if not isinstance(other, type_qualifiers_t):
933934
return False
934935
return self.has_static == other.has_static \
936+
and self.has_extern == other.has_extern \
935937
and self.has_mutable == other.has_mutable
936938

937939
def __hash__(self):
938-
return super.__hash__(self)
940+
return super(type_qualifiers_t, self).__hash__()
939941

940942
def __ne__(self, other):
941943
return not self.__eq__(other)
@@ -944,6 +946,7 @@ def __lt__(self, other):
944946
if not isinstance(other, type_qualifiers_t):
945947
return object.__lt__(self, other)
946948
return self.has_static < other.has_static \
949+
and self.has_extern < other.has_extern \
947950
and self.has_mutable < other.has_mutable
948951

949952
@property
@@ -956,12 +959,11 @@ def has_static(self, has_static):
956959

957960
@property
958961
def has_extern(self):
959-
"""synonym to static"""
960-
return self.has_static
962+
return self._has_extern
961963

962964
@has_extern.setter
963965
def has_extern(self, has_extern):
964-
self.has_static = has_extern
966+
self._has_extern = has_extern
965967

966968
@property
967969
def has_mutable(self):

pygccxml/declarations/enumeration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __eq__(self, other):
4747
return self.values == other.values
4848

4949
def __hash__(self):
50-
return super.__hash__(self)
50+
return super(enumeration_t, self).__hash__()
5151

5252
def _get__cmp__items(self):
5353
"""implementation details"""

pygccxml/declarations/scopedef.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def __eq__(self, other):
228228
# return self_decls == other_decls
229229

230230
def __hash__(self):
231-
return super.__hash__(self)
231+
return super(scopedef_t, self).__hash__()
232232

233233
def _get_declarations_impl(self):
234234
raise NotImplementedError()

pygccxml/declarations/type_traits_classes.py

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class declaration_xxx_traits(object):
5656
- get reference to the declaration
5757
"""
5858
sequence = [
59+
type_traits.remove_pointer,
5960
type_traits.remove_alias,
6061
type_traits.remove_cv,
6162
type_traits.remove_declarated]

pygccxml/declarations/typedef.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __eq__(self, other):
4444
return self.decl_type == other.decl_type
4545

4646
def __hash__(self):
47-
return super.__hash__(self)
47+
return super(typedef_t, self).__hash__()
4848

4949
@property
5050
def type(self):

pygccxml/declarations/variable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __eq__(self, other):
6161
and self.bits == other.bits
6262

6363
def __hash__(self):
64-
return super.__hash__(self)
64+
return super(variable_t, self).__hash__()
6565

6666
@property
6767
def type(self):

pygccxml/parser/scanner.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,16 @@ def __read_typedef(self, attrs):
556556
def __read_variable(self, attrs):
557557
type_qualifiers = declarations.type_qualifiers_t()
558558
type_qualifiers.has_mutable = attrs.get(XML_AN_MUTABLE, False)
559-
type_qualifiers.has_static = attrs.get(XML_AN_EXTERN, False)
559+
if "GCC-XML" in utils.xml_generator:
560+
# Old behaviour with gccxml. Will be dropped when gccxml
561+
# is removed.
562+
type_qualifiers.has_static = attrs.get(XML_AN_EXTERN, False)
563+
# With gccxml both were equivalent (at least this was the old
564+
# behaviour in pygccxml)
565+
type_qualifiers.has_extern = type_qualifiers.has_static
566+
else:
567+
type_qualifiers.has_static = attrs.get(XML_AN_STATIC, False)
568+
type_qualifiers.has_extern = attrs.get(XML_AN_EXTERN, False)
560569
bits = attrs.get(XML_AN_BITS)
561570
if bits:
562571
bits = int(bits)

unittests/data/declarations_variables.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace declarations{ namespace variables{
1111
const long unsigned int initialized = 10122004;
1212
int array[255];
1313

14-
//TODO: explain why such variables is not peeked
15-
extern int static_var;
14+
static int static_var;
15+
extern int extern_var;
1616

1717
struct struct_variables_t{
1818
mutable int m_mutable;
@@ -22,6 +22,11 @@ struct struct_variables_holder_t{
2222
struct_variables_t m_struct_variables;
2323
};
2424

25+
struct struct_static_variables_t{
26+
static const int ssv_static_var;
27+
static const int ssv_static_var_value = 1;
28+
};
29+
2530
} }
2631

2732
#endif//__declarations_variables_hpp__

unittests/data/non_copyable_classes.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ class MainFoo5 : Foo5 {
106106
char b;
107107
};
108108

109+
// ----------------------------------------------- Member with static qualifiers
110+
111+
// Foo6 is a base class (with a static const variable foo)
112+
class Foo6 {
113+
private:
114+
Foo6();
115+
protected:
116+
static const int foo1;
117+
};
118+
119+
// Use the base class: this class is copyable, it has a public ctor, and
120+
// the base class does not contain non-copyable members (because of the static
121+
// qualifier)
122+
class MainFoo6 : Foo6 {
123+
public:
124+
MainFoo6();
125+
};
126+
109127
}
110128

111129
#endif//__non_copyable_classes_hpp__

unittests/data/type_traits.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ namespace yes{
191191
typedef detail::g_t g_t;
192192
typedef detail::const_container const_container_t;
193193
typedef detail::const_item const_item_t;
194+
typedef detail::const_item *const_item_t_ptr;
194195

195196
}
196197
namespace no{
@@ -200,6 +201,7 @@ namespace no{
200201
typedef std::set< std::string > string_set_type;
201202
typedef std::multimap< std::string, std::string > s2s_multimap_type;
202203
typedef detail::vertex vertex_type;
204+
typedef detail::vertex *vertex_type_ptr;
203205
}
204206
}
205207

unittests/declarations_tester.py

+64-11
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,78 @@ def test_variables(self):
5656
declarations.const_t,
5757
declarations.long_unsigned_int_t)
5858

59-
static_var = initialized = self.global_ns.variable(name='static_var')
59+
m_mutable = self.global_ns.variable(name="m_mutable")
60+
self.assertFalse(
61+
m_mutable.type_qualifiers.has_static,
62+
"m_mutable must not have static type qualifier")
63+
64+
if "GCC-XML" in utils.xml_generator:
65+
# Old GCC-XML behaviour. Can be dropped once GCC-XML is removed.
66+
static_var = self.global_ns.variable(name="extern_var")
67+
self.assertTrue(
68+
static_var.type_qualifiers.has_static,
69+
"static_var must have static type qualifier")
70+
self.assertFalse(
71+
static_var.type_qualifiers.has_mutable,
72+
"static_var must not have mutable type qualifier")
73+
return
74+
75+
# CastXML only tests --------------
76+
77+
self.assertTrue(
78+
m_mutable.type_qualifiers.has_mutable,
79+
"m_mutable must have mutable type qualifier")
80+
81+
# External static variable
82+
extern_var = self.global_ns.variable(name="extern_var")
83+
self.assertTrue(
84+
extern_var.type_qualifiers.has_extern,
85+
"extern_var must have extern type qualifier")
86+
self.assertFalse(
87+
extern_var.type_qualifiers.has_static,
88+
"extern_var must not have a static type qualifier")
89+
self.assertFalse(
90+
extern_var.type_qualifiers.has_mutable,
91+
"static_var must not have mutable type qualifier")
92+
93+
# Static variable
94+
static_var = self.global_ns.variable(name="static_var")
6095
self.assertTrue(
6196
static_var.type_qualifiers.has_static,
6297
"static_var must have static type qualifier")
63-
self.assertTrue(
64-
not static_var.type_qualifiers.has_mutable,
98+
self.assertFalse(
99+
static_var.type_qualifiers.has_extern,
100+
"static_var must not have an extern type qualifier")
101+
self.assertFalse(
102+
static_var.type_qualifiers.has_mutable,
65103
"static_var must not have mutable type qualifier")
66104

105+
ssv_static_var = self.global_ns.variable(name="ssv_static_var")
106+
self.assertTrue(
107+
ssv_static_var.type_qualifiers.has_static,
108+
"ssv_static_var must have static type qualifier")
109+
self.assertFalse(
110+
ssv_static_var.type_qualifiers.has_extern,
111+
"ssv_static_var must not have an extern type qualifier")
112+
self.assertFalse(
113+
ssv_static_var.type_qualifiers.has_mutable,
114+
"ssv_static_var must not have mutable type qualifier")
115+
116+
ssv_static_var_value = self.global_ns.variable(
117+
name="ssv_static_var_value")
118+
self.assertTrue(
119+
ssv_static_var_value.type_qualifiers.has_static,
120+
"ssv_static_var_value must have static type qualifier")
121+
self.assertFalse(
122+
ssv_static_var_value.type_qualifiers.has_extern,
123+
"ssv_static_var_value must not have an extern type qualifier")
124+
self.assertFalse(
125+
ssv_static_var_value.type_qualifiers.has_mutable,
126+
"ssv_static_var_value must not have mutable type qualifier")
127+
67128
if 'PDB' in utils.xml_generator:
68129
return # TODO find out work around
69130

70-
m_mutable = initialized = self.global_ns.variable(name='m_mutable')
71-
self.assertTrue(
72-
not m_mutable.type_qualifiers.has_static,
73-
"m_mutable must not have static type qualifier")
74-
# TODO: "There is bug in GCCXML: doesn't write mutable qualifier."
75-
# self.assertTrue( m_mutable.type_qualifiers.has_mutable
76-
# , "static_var must have mutable type qualifier" )
77-
78131
def test_calldef_free_functions(self):
79132
ns = self.global_ns.namespace('calldef')
80133

unittests/non_copyable_classes_tester.py

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from pygccxml import parser
99
from pygccxml import declarations
10+
from pygccxml import utils
1011

1112

1213
class Test(parser_test_case.parser_test_case_t):
@@ -52,6 +53,12 @@ def test(self):
5253
main_foo_5 = self.global_ns.class_('MainFoo5')
5354
self.assertTrue(declarations.is_noncopyable(main_foo_5))
5455

56+
if "CastXML" in utils.xml_generator:
57+
# CastXML only test
58+
# MainFoo6 is copyable
59+
main_foo_6 = self.global_ns.class_('MainFoo6')
60+
self.assertFalse(declarations.is_noncopyable(main_foo_6))
61+
5562

5663
def create_suite():
5764
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)