Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iMichka committed Dec 15, 2024
2 parents e178aeb + ea300f6 commit e906269
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
-------------

Expand All @@ -14,6 +21,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
-------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ keywords = [
"CastXML",
"gccxml",
]
version = "2.6.0"
version = "2.6.1"

classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down
26 changes: 13 additions & 13 deletions src/pygccxml/declarations/container_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -29,20 +39,10 @@ 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": string_equivalences,
"std::wstring": wstring_equivalences
}

new_name = cls_name
for short_name, long_names in strings.items():
Expand Down
68 changes: 50 additions & 18 deletions src/pygccxml/declarations/type_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,25 +480,57 @@ 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<char,std::char_traits<char>,'
'std::allocator<char>>'),
'::std::basic_string<char>', '::std::string']
'std::basic_string<char, std::char_traits<char>, '
'std::allocator<char>>'
),
'std::basic_string<char>',
'std::string'
]

wstring_equivalences = [
(
'::std::basic_string<wchar_t,std::char_traits<wchar_t>,' +
'std::allocator<wchar_t>>'),
'::std::basic_string<wchar_t>', '::std::wstring']
'std::basic_string<wchar_t, std::char_traits<wchar_t>, '
'std::allocator<wchar_t>>'
),
'std::basic_string<wchar_t>',
'std::wstring'
]

ostream_equivalences = [
'::std::basic_ostream<char,std::char_traits<char>>',
'::std::basic_ostream<char>', '::std::ostream']
'std::basic_ostream<char, std::char_traits<char>>',
'std::basic_ostream<char>',
'std::ostream'
]

wostream_equivalences = [
'::std::basic_ostream<wchar_t,std::char_traits<wchar_t>>',
'::std::basic_ostream<wchar_t>', '::std::wostream']
'std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
'std::basic_ostream<wchar_t>',
'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_):
Expand All @@ -508,12 +540,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_):
Expand All @@ -523,12 +555,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_):
Expand All @@ -538,12 +570,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_):
Expand All @@ -553,9 +585,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
4 changes: 1 addition & 3 deletions tests/data/core_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion tests/test_remove_template_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_source_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit e906269

Please sign in to comment.