Skip to content

Commit 95d8737

Browse files
committed
Merge branch 'hotfix/v1.9.1' into develop
Conflicts: CHANGELOG.md pygccxml/declarations/type_traits_classes.py
2 parents 3e4bce1 + daa290a commit 95d8737

File tree

5 files changed

+104
-15
lines changed

5 files changed

+104
-15
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ Version 2.0.0 (unreleased)
1717
`declarations.get_dependencies_from_decl(decl)` function from the
1818
`declarations` module, which returns the same result.
1919

20+
Version 1.9.1
21+
-------------
22+
23+
1. Fix bug in the ```find_noncopyable_vars``` method which wrongly returned
24+
member variables of pointer type (#84)
25+
26+
2. Fix bug in the ```smart_pointer_traits.value_type``` and
27+
```auto_pointer_traits.value_type``` methods which didn't find the expected
28+
```value_type``` declaration (#85)
29+
30+
3. Fix bug in the ```smart_pointer_traits.is_smart_pointer``` and
31+
```auto_pointer_traits.is_smart_pointer``` methods which didn't properly
32+
work (#85)
33+
2034
Version 1.9.0
2135
-------------
2236

pygccxml/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
# TODO:
4242
# 1. Add "explicit" property for constructors
4343

44-
__version__ = '1.9.0'
44+
__version__ = '1.9.1'

pygccxml/declarations/smart_pointer_traits.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from . import class_declaration_traits
1010
from . import class_traits
1111
from . import traits_impl_details
12+
from . import runtime_errors
1213

1314

1415
class internal_type_traits(object):
@@ -17,8 +18,8 @@ class internal_type_traits(object):
1718
# TODO: add exists function
1819
@staticmethod
1920
def get_by_name(type_, name):
20-
if class_declaration_traits.is_my_case(type_):
21-
cls = class_traits.declaration_class(type_)
21+
if class_traits.is_my_case(type_):
22+
cls = class_traits.get_declaration(type_)
2223
return type_traits.remove_declarated(
2324
cls.typedef(name, recursive=False).decl_type)
2425
elif class_declaration_traits.is_my_case(type_):
@@ -72,7 +73,10 @@ def value_type(type_):
7273
'Type "%s" is not an instantiation of \
7374
boost::shared_ptr or std::shared_ptr' %
7475
type_.decl_string)
75-
return internal_type_traits.get_by_name(type_, "value_type")
76+
try:
77+
return internal_type_traits.get_by_name(type_, "element_type")
78+
except runtime_errors.declaration_not_found_t:
79+
return _search_in_bases(type_)
7680

7781

7882
class auto_ptr_traits(object):
@@ -103,4 +107,23 @@ def value_type(type_):
103107
raise TypeError(
104108
'Type "%s" is not instantiation of std::auto_ptr' %
105109
type_.decl_string)
106-
return internal_type_traits.get_by_name(type_, "element_type")
110+
try:
111+
return internal_type_traits.get_by_name(type_, "element_type")
112+
except runtime_errors.declaration_not_found_t:
113+
return _search_in_bases(type_)
114+
115+
116+
def _search_in_bases(type_):
117+
"""Implementation detail."""
118+
found = False
119+
for base_type in type_.declaration.bases:
120+
try:
121+
found = internal_type_traits.get_by_name(
122+
base_type.related_class, "element_type")
123+
except runtime_errors.declaration_not_found_t:
124+
pass
125+
if found:
126+
return found
127+
raise RuntimeError(
128+
("Unable to find 'element_type' declaration '%s'"
129+
"in type '%s'.") % type_.decl_string)

pygccxml/declarations/type_traits_classes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def find_noncopyable_vars(class_type, already_visited_cls_vars=None):
208208
continue
209209

210210
if class_traits.is_my_case(var_type):
211-
212211
cls = class_traits.get_declaration(var_type)
213212

214213
# Exclude classes that have already been visited.

unittests/test_smart_pointer.py

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,93 @@ def __init__(self, *args):
1717
parser_test_case.parser_test_case_t.__init__(self, *args)
1818
self.header = "test_smart_pointer.hpp"
1919
self.config.cflags = "-std=c++11"
20+
self.global_ns = None
2021

21-
def test_smart_pointer(self):
22+
def setUp(self):
23+
if self.config.xml_generator == "gccxml":
24+
return
25+
decls = parser.parse([self.header], self.config)
26+
self.global_ns = declarations.get_global_namespace(decls)
27+
28+
def test_is_smart_pointer(self):
2229
"""
23-
Test code in the smart_pointer_traits module.
30+
Test smart_pointer_traits.is_smart_pointer method.
2431
2532
"""
2633

2734
if self.config.xml_generator == "gccxml":
2835
return
2936

30-
decls = parser.parse([self.header], self.config)
31-
global_ns = declarations.get_global_namespace(decls)
32-
3337
criteria = declarations.declaration_matcher(name="yes1")
34-
decls = declarations.matcher.find(criteria, global_ns)
38+
decls = declarations.matcher.find(criteria, self.global_ns)
3539
self.assertTrue(
3640
declarations.smart_pointer_traits.is_smart_pointer(
3741
decls[0].decl_type))
3842

43+
criteria = declarations.declaration_matcher(name="no1")
44+
decls = declarations.matcher.find(criteria, self.global_ns)
45+
self.assertFalse(
46+
declarations.smart_pointer_traits.is_smart_pointer(
47+
decls[0].decl_type))
48+
49+
criteria = declarations.declaration_matcher(name="no2")
50+
decls = declarations.matcher.find(criteria, self.global_ns)
51+
self.assertFalse(
52+
declarations.smart_pointer_traits.is_smart_pointer(
53+
decls[0].decl_type))
54+
55+
def test_is_auto_pointer(self):
56+
"""
57+
Test auto_ptr_traits.is_smart_pointer method.
58+
59+
"""
60+
61+
if self.config.xml_generator == "gccxml":
62+
return
63+
3964
criteria = declarations.declaration_matcher(name="yes2")
40-
decls = declarations.matcher.find(criteria, global_ns)
65+
decls = declarations.matcher.find(criteria, self.global_ns)
4166
self.assertTrue(
4267
declarations.auto_ptr_traits.is_smart_pointer(decls[0].decl_type))
4368

4469
criteria = declarations.declaration_matcher(name="no1")
45-
decls = declarations.matcher.find(criteria, global_ns)
70+
decls = declarations.matcher.find(criteria, self.global_ns)
4671
self.assertFalse(
4772
declarations.auto_ptr_traits.is_smart_pointer(decls[0].decl_type))
4873

4974
criteria = declarations.declaration_matcher(name="no2")
50-
decls = declarations.matcher.find(criteria, global_ns)
75+
decls = declarations.matcher.find(criteria, self.global_ns)
5176
self.assertFalse(
5277
declarations.auto_ptr_traits.is_smart_pointer(decls[0].decl_type))
5378

79+
def test_smart_pointer_value_type(self):
80+
"""
81+
Test smart_pointer_traits.value_type method.
82+
83+
"""
84+
85+
if self.config.xml_generator == "gccxml":
86+
return
87+
88+
criteria = declarations.declaration_matcher(name="yes1")
89+
decls = declarations.matcher.find(criteria, self.global_ns)
90+
vt = declarations.smart_pointer_traits.value_type(decls[0].decl_type)
91+
self.assertIsInstance(vt, declarations.int_t)
92+
93+
def test_auto_pointer_value_type(self):
94+
"""
95+
Test auto_pointer_traits.value_type method.
96+
97+
"""
98+
99+
if self.config.xml_generator == "gccxml":
100+
return
101+
102+
criteria = declarations.declaration_matcher(name="yes2")
103+
decls = declarations.matcher.find(criteria, self.global_ns)
104+
vt = declarations.auto_ptr_traits.value_type(decls[0].decl_type)
105+
self.assertIsInstance(vt, declarations.double_t)
106+
54107

55108
def create_suite():
56109
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)