From 43174f13a8863c9304c58a38e1a1dc1379b3a6ef Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Sun, 17 Nov 2024 21:41:39 +0100 Subject: [PATCH 1/6] changelog: add missing entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec5e3902..bc1da215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Version 2.6.0 5. Fix a bug in build_decl_string with elaborated type specifiers +6. Fix a bug where the declared widht of arrays args where lost (by using the original type xml tag) + Version 2.5.0 ------------- From 6c8603600d6bd0e705144d52360515d2972eacbf Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Mon, 2 Dec 2024 23:13:54 +0100 Subject: [PATCH 2/6] tests: fix compilation with c++14/17 Fixes: ---------------------------- Captured stderr setup ----------------------------- /<>/.pybuild/cpython3_3.12_pygccxml/build/tests/data/core_types.hpp:57:38: error: ISO C++17 does not allow dynamic exception specifications [-Wdynamic-exception-spec] 57 | int some_function( double hi) const throw( exception ){ | ^~~~~~~~~~~~~~~~~~ /<>/.pybuild/cpython3_3.12_pygccxml/build/tests/data/core_types.hpp:57:38: note: use 'noexcept(false)' instead 57 | int some_function( double hi) const throw( exception ){ | ^~~~~~~~~~~~~~~~~~ | noexcept(false) 1 error generated. ----- No need to keep the throws / or to replace it with noexcept. We are not really testing this functionality here, so lets write code that is generic enough for all c++ versions --- tests/data/core_types.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/data/core_types.hpp b/tests/data/core_types.hpp index 41dc655d..4038865e 100644 --- a/tests/data/core_types.hpp +++ b/tests/data/core_types.hpp @@ -48,13 +48,11 @@ typedef EFavoriteDrinks typedef_EFavoriteDrinks; typedef int (*function_ptr)(int, double); -struct exception{}; - struct members_pointers_t{ int some_function( double hi, int i ){ return 0; } - int some_function( double hi) const throw( exception ){ + int some_function( double hi) const { return 0; }; int m_some_const_member; From 65c5502a81d5704e2fbc57dbac75e1b759252941 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Sat, 7 Dec 2024 16:51:43 +0100 Subject: [PATCH 3/6] ci: move to macos13 macos12 CI is gone --- .github/workflows/tests.yml | 4 ++-- tests/test_remove_template_defaults.py | 9 ++++++++- tests/test_source_reader.py | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3c68ef7a..a3b5f842 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -70,7 +70,7 @@ jobs: castxml-epic: 1 cppstd: "-std=c++11" - - os: macos-12 + - os: macos-13 compiler: xcode version: "default" python-version: "3.8" @@ -96,7 +96,7 @@ jobs: run: | wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/bdbb67a10c5f8d1b738cd19cb074f409d4803e8077cb8c1072ef4eaf738fa871a73643f9c8282d58cae28d188df842c82ad6620b6d590b0396a0172a27438dce/download | tar zxf - -C ~/ - name: Setup castxml for Mac - if: matrix.os == 'macos-12' + if: matrix.os == 'macos-13' run: | wget -q -O - https://data.kitware.com/api/v1/file/hashsum/sha512/5d937e938f7b882a3a3e7941e68f8312d0898aaf2082e00003dd362b1ba70b98b0a08706a1be28e71652a6a0f1e66f89768b5eaa20e5a100592d5b3deefec3f0/download | tar zxf - -C ~/ - name: Run tests diff --git a/tests/test_remove_template_defaults.py b/tests/test_remove_template_defaults.py index b1706c4c..5f5024a4 100644 --- a/tests/test_remove_template_defaults.py +++ b/tests/test_remove_template_defaults.py @@ -3,6 +3,8 @@ # Distributed under the Boost Software License, Version 1.0. # See http://www.boost.org/LICENSE_1_0.txt +import platform + import pytest from . import autoconfig @@ -20,7 +22,12 @@ def global_ns(): COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE config = autoconfig.cxx_parsers_cfg.config.clone() - config.cflags = "-std=c++11" + if platform.system() == "Darwin": + config.cflags = "-std=c++11 -Dat_quick_exit=atexit -Dquick_exit=exit" + # https://fr.mathworks.com/matlabcentral/answers/2013982-clibgen-generatelibrarydefinition-error-the-global-scope-has-no-quick_exit-on-mac-m2#answer_1439856 + # https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01 + else: + config.cflags = "-std=c++11" decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) global_ns = declarations.get_global_namespace(decls) global_ns.init_optimizer() diff --git a/tests/test_source_reader.py b/tests/test_source_reader.py index 355e225e..20e403a6 100644 --- a/tests/test_source_reader.py +++ b/tests/test_source_reader.py @@ -3,6 +3,8 @@ # Distributed under the Boost Software License, Version 1.0. # See http://www.boost.org/LICENSE_1_0.txt +import platform + import pytest from . import autoconfig @@ -19,6 +21,10 @@ def global_ns(): COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE config = autoconfig.cxx_parsers_cfg.config.clone() + if platform.system() == "Darwin": + config.cflags = "-Dat_quick_exit=atexit -Dquick_exit=exit" + # https://fr.mathworks.com/matlabcentral/answers/2013982-clibgen-generatelibrarydefinition-error-the-global-scope-has-no-quick_exit-on-mac-m2#answer_1439856 + # https://github.com/jetbrains/kotlin/commit/d50f585911dedec5723213da8835707ac95e1c01 decls = parser.parse(TEST_FILES, config, COMPILATION_MODE) global_ns = declarations.get_global_namespace(decls) global_ns.init_optimizer() From 0698c3cb9365fdf8bf658daf1a7379e014c38d9d Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Thu, 12 Dec 2024 20:30:20 +0100 Subject: [PATCH 4/6] type-traits: fix string equivalences Add missing spaces, which should fix some equivalence detection in the defaults_eraser function --- pyproject.toml | 3 + src/pygccxml/declarations/container_traits.py | 21 +++---- src/pygccxml/declarations/type_traits.py | 60 ++++++++++++++----- 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3dbe90f2..d966316d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,3 +64,6 @@ docs = [ examples = [ "notebook", ] +[tool.pytest.ini_options] + pythonpath = [ + "src"] \ No newline at end of file diff --git a/src/pygccxml/declarations/container_traits.py b/src/pygccxml/declarations/container_traits.py index e5035782..b2c4c104 100644 --- a/src/pygccxml/declarations/container_traits.py +++ b/src/pygccxml/declarations/container_traits.py @@ -29,20 +29,17 @@ def normalize(self, type_str): return type_str.replace(' ', '') def replace_basic_string(self, cls_name): - - # Take the lists of all possible string variations - # and clean them up by replacing ::std by std. - str_eq = [ - v.replace("::std", "std") for v in - type_traits.string_equivalences] - wstr_eq = [ - v.replace("::std", "std") for v in - type_traits.wstring_equivalences] - # Replace all the variations of strings by the smallest one. strings = { - "std::string": [v for v in str_eq if not v == "std::string"], - "std::wstring": [v for v in wstr_eq if not v == "std::wstring"]} + "std::string": + [v for v in + type_traits.normalized_string_equivalences + if not v == "std::string"], + "std::wstring": + [v for v in + type_traits.normalized_wstring_equivalences + if not v == "std::wstring"] + } new_name = cls_name for short_name, long_names in strings.items(): diff --git a/src/pygccxml/declarations/type_traits.py b/src/pygccxml/declarations/type_traits.py index bc9be8de..49aa6950 100644 --- a/src/pygccxml/declarations/type_traits.py +++ b/src/pygccxml/declarations/type_traits.py @@ -480,27 +480,55 @@ def is_fundamental(type_): (cpptypes.volatile_t, cpptypes.const_t)) +def _normalize(string): + return string.replace(' ', '').replace("::std", "std") + + +def _normalize_equivalences(equivalences): + return [_normalize(eq) for eq in equivalences] + + string_equivalences = [ ( - '::std::basic_string,' - 'std::allocator>'), - '::std::basic_string', '::std::string'] + '::std::basic_string, ' + 'std::allocator>' + ), + '::std::basic_string', + '::std::string' + ] wstring_equivalences = [ ( - '::std::basic_string,' + - 'std::allocator>'), - '::std::basic_string', '::std::wstring'] + '::std::basic_string, ' + 'std::allocator>' + ), + '::std::basic_string', + '::std::wstring' + ] ostream_equivalences = [ - '::std::basic_ostream>', + '::std::basic_ostream>', '::std::basic_ostream', '::std::ostream'] wostream_equivalences = [ - '::std::basic_ostream>', + '::std::basic_ostream>', '::std::basic_ostream', '::std::wostream'] +normalized_string_equivalences = _normalize_equivalences( + string_equivalences + ) +normalized_wstring_equivalences = _normalize_equivalences( + wstring_equivalences + ) +normalized_ostream_equivalences = _normalize_equivalences( + ostream_equivalences + ) +normalized_wostream_equivalences = _normalize_equivalences( + wostream_equivalences + ) + + def is_std_string(type_): """ Returns True, if type represents C++ `std::string`, False otherwise. @@ -508,12 +536,12 @@ def is_std_string(type_): """ if isinstance(type_, str): - return type_ in string_equivalences + return _normalize(type_) in normalized_string_equivalences type_ = remove_alias(type_) type_ = remove_reference(type_) type_ = remove_cv(type_) - return type_.decl_string.replace(' ', '') in string_equivalences + return _normalize(type_.decl_string) in normalized_string_equivalences def is_std_wstring(type_): @@ -523,12 +551,12 @@ def is_std_wstring(type_): """ if isinstance(type_, str): - return type_ in wstring_equivalences + return _normalize(type_) in normalized_wstring_equivalences type_ = remove_alias(type_) type_ = remove_reference(type_) type_ = remove_cv(type_) - return type_.decl_string.replace(' ', '') in wstring_equivalences + return _normalize(type_.decl_string) in normalized_wstring_equivalences def is_std_ostream(type_): @@ -538,12 +566,12 @@ def is_std_ostream(type_): """ if isinstance(type_, str): - return type_ in ostream_equivalences + return _normalize(type_) in normalized_ostream_equivalences type_ = remove_alias(type_) type_ = remove_reference(type_) type_ = remove_cv(type_) - return type_.decl_string.replace(' ', '') in ostream_equivalences + return _normalize(type_.decl_string) in normalized_ostream_equivalences def is_std_wostream(type_): @@ -553,9 +581,9 @@ def is_std_wostream(type_): """ if isinstance(type_, str): - return type_ in wostream_equivalences + return _normalize(type_) in normalized_wostream_equivalences type_ = remove_alias(type_) type_ = remove_reference(type_) type_ = remove_cv(type_) - return type_.decl_string.replace(' ', '') in wostream_equivalences + return _normalize(type_.decl_string) in normalized_wostream_equivalences From da9b147919b806d081a0465227e362b91a08ecec Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Sun, 8 Dec 2024 20:55:07 +0100 Subject: [PATCH 5/6] tests: fix macos tests Fix string replacement (broken due to space mismatches) --- pyproject.toml | 3 --- src/pygccxml/declarations/container_traits.py | 21 +++++++++------- src/pygccxml/declarations/type_traits.py | 24 +++++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d966316d..3dbe90f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,3 @@ docs = [ examples = [ "notebook", ] -[tool.pytest.ini_options] - pythonpath = [ - "src"] \ No newline at end of file diff --git a/src/pygccxml/declarations/container_traits.py b/src/pygccxml/declarations/container_traits.py index b2c4c104..0f8d1d61 100644 --- a/src/pygccxml/declarations/container_traits.py +++ b/src/pygccxml/declarations/container_traits.py @@ -19,6 +19,16 @@ std_namespaces = ('std', 'stdext', '__gnu_cxx') +# Take into account different equivalences (with or without spaces) +string_equivalences = type_traits.string_equivalences + \ + type_traits.normalized_string_equivalences +string_equivalences = [ + v for v in string_equivalences if not v == "std::string"] +wstring_equivalences = type_traits.wstring_equivalences + \ + type_traits.normalized_wstring_equivalences +wstring_equivalences = [ + v for v in wstring_equivalences if not v == "std::wstring"] + class defaults_eraser(object): @@ -29,16 +39,9 @@ def normalize(self, type_str): return type_str.replace(' ', '') def replace_basic_string(self, cls_name): - # Replace all the variations of strings by the smallest one. strings = { - "std::string": - [v for v in - type_traits.normalized_string_equivalences - if not v == "std::string"], - "std::wstring": - [v for v in - type_traits.normalized_wstring_equivalences - if not v == "std::wstring"] + "std::string": string_equivalences, + "std::wstring": wstring_equivalences } new_name = cls_name diff --git a/src/pygccxml/declarations/type_traits.py b/src/pygccxml/declarations/type_traits.py index 49aa6950..ba129259 100644 --- a/src/pygccxml/declarations/type_traits.py +++ b/src/pygccxml/declarations/type_traits.py @@ -490,29 +490,33 @@ def _normalize_equivalences(equivalences): string_equivalences = [ ( - '::std::basic_string, ' + 'std::basic_string, ' 'std::allocator>' ), - '::std::basic_string', - '::std::string' + 'std::basic_string', + 'std::string' ] wstring_equivalences = [ ( - '::std::basic_string, ' + 'std::basic_string, ' 'std::allocator>' ), - '::std::basic_string', - '::std::wstring' + 'std::basic_string', + 'std::wstring' ] ostream_equivalences = [ - '::std::basic_ostream>', - '::std::basic_ostream', '::std::ostream'] + 'std::basic_ostream>', + 'std::basic_ostream', + 'std::ostream' + ] wostream_equivalences = [ - '::std::basic_ostream>', - '::std::basic_ostream', '::std::wostream'] + 'std::basic_ostream>', + 'std::basic_ostream', + 'std::wostream' + ] normalized_string_equivalences = _normalize_equivalences( From 9a828cd0014edf7cb51d3eb83e1bac8c9c6c39a8 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Sat, 14 Dec 2024 23:01:59 +0100 Subject: [PATCH 6/6] Bump version to 2.6.1 --- CHANGELOG.md | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc1da215..959b5290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changes ======= +Version 2.6.1 +------------- + +1. Fix test_remove_template_defaults when tested on macos 13 + +2. Fix some test compilation with c++14/17 + Version 2.6.0 ------------- diff --git a/pyproject.toml b/pyproject.toml index 3dbe90f2..8abdfac0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ keywords = [ "CastXML", "gccxml", ] -version = "2.6.0" +version = "2.6.1" classifiers = [ "Development Status :: 5 - Production/Stable",