-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ | |
# TODO: | ||
# 1. Add "explicit" property for constructors | ||
|
||
__version__ = '1.8.5' | ||
__version__ = '1.8.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2014-2016 Insight Software Consortium. | ||
// Copyright 2004-2008 Roman Yakovenko. | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// See http://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <sstream> | ||
|
||
// Demonstration of the real problem with basic c++ | ||
namespace Test1 { | ||
|
||
// Forward declaration | ||
class Base2; | ||
|
||
// Base 1, with pointer to Base2 | ||
class Base1 { | ||
private: | ||
Base1(); | ||
|
||
protected: | ||
Base2* aBasePtr2; | ||
}; | ||
|
||
// Base 2, child class of Base1 | ||
class Base2: public Base1 { | ||
private: | ||
Base2(); | ||
}; | ||
|
||
// Child class of Base2 | ||
// Holds a pointer to Base2 | ||
class Child: public Base2 { | ||
private: | ||
Child(); | ||
|
||
protected: | ||
Base2* aBasePtr2; | ||
}; | ||
|
||
} | ||
|
||
// Real-life test with std::istream where this happened | ||
namespace Test2 { | ||
|
||
class FileStreamDataStream { | ||
public: | ||
FileStreamDataStream(const std::istream* s) {} | ||
|
||
protected: | ||
std::istream* mInStream; | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2014-2016 Insight Software Consortium. | ||
# Copyright 2004-2009 Roman Yakovenko. | ||
# Distributed under the Boost Software License, Version 1.0. | ||
# See http://www.boost.org/LICENSE_1_0.txt | ||
|
||
import unittest | ||
import parser_test_case | ||
|
||
from pygccxml import parser | ||
from pygccxml import declarations | ||
|
||
|
||
class Test(parser_test_case.parser_test_case_t): | ||
|
||
def __init__(self, *args): | ||
parser_test_case.parser_test_case_t.__init__(self, *args) | ||
self.header = "test_non_copyable_recursive.hpp" | ||
|
||
def test_infinite_recursion_base_classes(self): | ||
""" | ||
Test find_noncopyable_vars | ||
See #71 | ||
find_noncopyable_vars was throwing: | ||
RuntimeError: maximum recursion depth exceeded while | ||
calling a Python object | ||
""" | ||
decls = parser.parse([self.header], self.config) | ||
global_ns = declarations.get_global_namespace(decls) | ||
|
||
# Description of the problem (before the fix): | ||
# find_noncopyable_vars (on Child class) looks up the variables, | ||
# and finds aBasePtr2 (a pointer to the Base2 class). | ||
# Then it looks recursively at the base classes of Base2, and finds | ||
# Base1. Then, it looks up the variables from Base, to check if Base1 | ||
# is non copyable. It finds another aBasePtr2 variable, which leads to | ||
# a new check of Base2; this recurses infinitely. | ||
test_ns = global_ns.namespace('Test1') | ||
cls = test_ns.class_('Child') | ||
declarations.type_traits_classes.find_noncopyable_vars(cls) | ||
self.assertTrue(declarations.type_traits_classes.is_noncopyable(cls)) | ||
|
||
def test_infinite_recursion_sstream(self): | ||
""" | ||
Test find_noncopyable_vars | ||
See #71 | ||
find_noncopyable_vars was throwing: | ||
RuntimeError: maximum recursion depth exceeded while | ||
calling a Python object | ||
""" | ||
decls = parser.parse([self.header], self.config) | ||
global_ns = declarations.get_global_namespace(decls) | ||
|
||
# Real life example of the bug. This leads to a similar error, | ||
# but the situation is more complex as there are multiple | ||
# classes that are related the one to the others | ||
# (basic_istream, basic_ios, ios_base, ...) | ||
test_ns = global_ns.namespace('Test2') | ||
cls = test_ns.class_('FileStreamDataStream') | ||
declarations.type_traits_classes.find_noncopyable_vars(cls) | ||
self.assertFalse(declarations.type_traits_classes.is_noncopyable(cls)) | ||
|
||
|
||
def create_suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(Test)) | ||
return suite | ||
|
||
|
||
def run_suite(): | ||
unittest.TextTestRunner(verbosity=2).run(create_suite()) | ||
|
||
if __name__ == "__main__": | ||
run_suite() |