Skip to content

Commit

Permalink
Merge branch 'hotfix/v1.8.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
iMichka committed Feb 22, 2017
2 parents 69e78cf + 5b07065 commit b632d7e
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 27 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Changes
=======

Version 1.8.5
-------------

1. Fix multiple calls to ``` __hash__()``` (#70)

2. ```Static``` and ```extern``` qualifiers are now no more treated as equivalents
in the type_qualifiers class (for ```CastXML```).
The old behaviour is kept for ```GCC-XML``` (```static == extern```).

3. Fix for ```declarations.is_noncopyable``` when used on a ```pointer_t```.

Version 1.8.4
-------------

Expand Down
2 changes: 1 addition & 1 deletion pygccxml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
# TODO:
# 1. Add "explicit" property for constructors

__version__ = '1.8.4'
__version__ = '1.8.5'
4 changes: 2 additions & 2 deletions pygccxml/declarations/calldef.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ def __eq__(self, other):

def __hash__(self):
if "GCC" in utils.xml_generator:
return (super.__hash__(self) ^
return (super(calldef_t, self).__hash__() ^
hash(self.return_type) ^
hash(self.demangled_name))
elif "CastXML" in utils.xml_generator:
# No demangled name with castxml. Use the normal name.
return (super.__hash__(self) ^
return (super(calldef_t, self).__hash__() ^
hash(self.return_type) ^
hash(self.name))

Expand Down
2 changes: 1 addition & 1 deletion pygccxml/declarations/calldef_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __eq__(self, other):
and self.has_const == other.has_const

def __hash__(self):
return super.__hash__(self)
return super(member_calldef_t, self).__hash__()

@property
def virtuality(self):
Expand Down
12 changes: 7 additions & 5 deletions pygccxml/declarations/cpptypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,18 +924,20 @@ class type_qualifiers_t(object):

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

def __init__(self, has_static=False, has_mutable=False):
def __init__(self, has_static=False, has_mutable=False, has_extern=False):
self._has_static = has_static
self._has_extern = has_extern
self._has_mutable = has_mutable

def __eq__(self, other):
if not isinstance(other, type_qualifiers_t):
return False
return self.has_static == other.has_static \
and self.has_extern == other.has_extern \
and self.has_mutable == other.has_mutable

def __hash__(self):
return super.__hash__(self)
return super(type_qualifiers_t, self).__hash__()

def __ne__(self, other):
return not self.__eq__(other)
Expand All @@ -944,6 +946,7 @@ def __lt__(self, other):
if not isinstance(other, type_qualifiers_t):
return object.__lt__(self, other)
return self.has_static < other.has_static \
and self.has_extern < other.has_extern \
and self.has_mutable < other.has_mutable

@property
Expand All @@ -956,12 +959,11 @@ def has_static(self, has_static):

@property
def has_extern(self):
"""synonym to static"""
return self.has_static
return self._has_extern

@has_extern.setter
def has_extern(self, has_extern):
self.has_static = has_extern
self._has_extern = has_extern

@property
def has_mutable(self):
Expand Down
2 changes: 1 addition & 1 deletion pygccxml/declarations/enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __eq__(self, other):
return self.values == other.values

def __hash__(self):
return super.__hash__(self)
return super(enumeration_t, self).__hash__()

def _get__cmp__items(self):
"""implementation details"""
Expand Down
2 changes: 1 addition & 1 deletion pygccxml/declarations/scopedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __eq__(self, other):
# return self_decls == other_decls

def __hash__(self):
return super.__hash__(self)
return super(scopedef_t, self).__hash__()

def _get_declarations_impl(self):
raise NotImplementedError()
Expand Down
1 change: 1 addition & 0 deletions pygccxml/declarations/type_traits_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class declaration_xxx_traits(object):
- get reference to the declaration
"""
sequence = [
type_traits.remove_pointer,
type_traits.remove_alias,
type_traits.remove_cv,
type_traits.remove_declarated]
Expand Down
2 changes: 1 addition & 1 deletion pygccxml/declarations/typedef.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __eq__(self, other):
return self.decl_type == other.decl_type

def __hash__(self):
return super.__hash__(self)
return super(typedef_t, self).__hash__()

@property
def type(self):
Expand Down
2 changes: 1 addition & 1 deletion pygccxml/declarations/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __eq__(self, other):
and self.bits == other.bits

def __hash__(self):
return super.__hash__(self)
return super(variable_t, self).__hash__()

@property
def type(self):
Expand Down
11 changes: 10 additions & 1 deletion pygccxml/parser/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,16 @@ def __read_typedef(self, attrs):
def __read_variable(self, attrs):
type_qualifiers = declarations.type_qualifiers_t()
type_qualifiers.has_mutable = attrs.get(XML_AN_MUTABLE, False)
type_qualifiers.has_static = attrs.get(XML_AN_EXTERN, False)
if "GCC-XML" in utils.xml_generator:
# Old behaviour with gccxml. Will be dropped when gccxml
# is removed.
type_qualifiers.has_static = attrs.get(XML_AN_EXTERN, False)
# With gccxml both were equivalent (at least this was the old
# behaviour in pygccxml)
type_qualifiers.has_extern = type_qualifiers.has_static
else:
type_qualifiers.has_static = attrs.get(XML_AN_STATIC, False)
type_qualifiers.has_extern = attrs.get(XML_AN_EXTERN, False)
bits = attrs.get(XML_AN_BITS)
if bits:
bits = int(bits)
Expand Down
9 changes: 7 additions & 2 deletions unittests/data/declarations_variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace declarations{ namespace variables{
const long unsigned int initialized = 10122004;
int array[255];

//TODO: explain why such variables is not peeked
extern int static_var;
static int static_var;
extern int extern_var;

struct struct_variables_t{
mutable int m_mutable;
Expand All @@ -22,6 +22,11 @@ struct struct_variables_holder_t{
struct_variables_t m_struct_variables;
};

struct struct_static_variables_t{
static const int ssv_static_var;
static const int ssv_static_var_value = 1;
};

} }

#endif//__declarations_variables_hpp__
Expand Down
18 changes: 18 additions & 0 deletions unittests/data/non_copyable_classes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ class MainFoo5 : Foo5 {
char b;
};

// ----------------------------------------------- Member with static qualifiers

// Foo6 is a base class (with a static const variable foo)
class Foo6 {
private:
Foo6();
protected:
static const int foo1;
};

// Use the base class: this class is copyable, it has a public ctor, and
// the base class does not contain non-copyable members (because of the static
// qualifier)
class MainFoo6 : Foo6 {
public:
MainFoo6();
};

}

#endif//__non_copyable_classes_hpp__
2 changes: 2 additions & 0 deletions unittests/data/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ namespace yes{
typedef detail::g_t g_t;
typedef detail::const_container const_container_t;
typedef detail::const_item const_item_t;
typedef detail::const_item *const_item_t_ptr;

}
namespace no{
Expand All @@ -200,6 +201,7 @@ namespace no{
typedef std::set< std::string > string_set_type;
typedef std::multimap< std::string, std::string > s2s_multimap_type;
typedef detail::vertex vertex_type;
typedef detail::vertex *vertex_type_ptr;
}
}

Expand Down
75 changes: 64 additions & 11 deletions unittests/declarations_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,78 @@ def test_variables(self):
declarations.const_t,
declarations.long_unsigned_int_t)

static_var = initialized = self.global_ns.variable(name='static_var')
m_mutable = self.global_ns.variable(name="m_mutable")
self.assertFalse(
m_mutable.type_qualifiers.has_static,
"m_mutable must not have static type qualifier")

if "GCC-XML" in utils.xml_generator:
# Old GCC-XML behaviour. Can be dropped once GCC-XML is removed.
static_var = self.global_ns.variable(name="extern_var")
self.assertTrue(
static_var.type_qualifiers.has_static,
"static_var must have static type qualifier")
self.assertFalse(
static_var.type_qualifiers.has_mutable,
"static_var must not have mutable type qualifier")
return

# CastXML only tests --------------

self.assertTrue(
m_mutable.type_qualifiers.has_mutable,
"m_mutable must have mutable type qualifier")

# External static variable
extern_var = self.global_ns.variable(name="extern_var")
self.assertTrue(
extern_var.type_qualifiers.has_extern,
"extern_var must have extern type qualifier")
self.assertFalse(
extern_var.type_qualifiers.has_static,
"extern_var must not have a static type qualifier")
self.assertFalse(
extern_var.type_qualifiers.has_mutable,
"static_var must not have mutable type qualifier")

# Static variable
static_var = self.global_ns.variable(name="static_var")
self.assertTrue(
static_var.type_qualifiers.has_static,
"static_var must have static type qualifier")
self.assertTrue(
not static_var.type_qualifiers.has_mutable,
self.assertFalse(
static_var.type_qualifiers.has_extern,
"static_var must not have an extern type qualifier")
self.assertFalse(
static_var.type_qualifiers.has_mutable,
"static_var must not have mutable type qualifier")

ssv_static_var = self.global_ns.variable(name="ssv_static_var")
self.assertTrue(
ssv_static_var.type_qualifiers.has_static,
"ssv_static_var must have static type qualifier")
self.assertFalse(
ssv_static_var.type_qualifiers.has_extern,
"ssv_static_var must not have an extern type qualifier")
self.assertFalse(
ssv_static_var.type_qualifiers.has_mutable,
"ssv_static_var must not have mutable type qualifier")

ssv_static_var_value = self.global_ns.variable(
name="ssv_static_var_value")
self.assertTrue(
ssv_static_var_value.type_qualifiers.has_static,
"ssv_static_var_value must have static type qualifier")
self.assertFalse(
ssv_static_var_value.type_qualifiers.has_extern,
"ssv_static_var_value must not have an extern type qualifier")
self.assertFalse(
ssv_static_var_value.type_qualifiers.has_mutable,
"ssv_static_var_value must not have mutable type qualifier")

if 'PDB' in utils.xml_generator:
return # TODO find out work around

m_mutable = initialized = self.global_ns.variable(name='m_mutable')
self.assertTrue(
not m_mutable.type_qualifiers.has_static,
"m_mutable must not have static type qualifier")
# TODO: "There is bug in GCCXML: doesn't write mutable qualifier."
# self.assertTrue( m_mutable.type_qualifiers.has_mutable
# , "static_var must have mutable type qualifier" )

def test_calldef_free_functions(self):
ns = self.global_ns.namespace('calldef')

Expand Down
7 changes: 7 additions & 0 deletions unittests/non_copyable_classes_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pygccxml import parser
from pygccxml import declarations
from pygccxml import utils


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

if "CastXML" in utils.xml_generator:
# CastXML only test
# MainFoo6 is copyable
main_foo_6 = self.global_ns.class_('MainFoo6')
self.assertFalse(declarations.is_noncopyable(main_foo_6))


def create_suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit b632d7e

Please sign in to comment.