Skip to content

Pygccxml update, use --castxml-output=1 modern xml format from castxml#5695

Merged
hjmjohnson merged 14 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:pygccxml-update
Jan 29, 2026
Merged

Pygccxml update, use --castxml-output=1 modern xml format from castxml#5695
hjmjohnson merged 14 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:pygccxml-update

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

First step towards resolving issues related to wrapping on newer compilers.

#5540 (comment)

Related to issues identified in: #5636

PR Checklist

@github-actions github-actions Bot added area:Python wrapping Python bindings for a class area:ThirdParty Issues affecting the ThirdParty module labels Dec 16, 2025
@thewtex thewtex requested a review from iMichka December 16, 2025 22:32
Copy link
Copy Markdown
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update looks good on a glance, but there are CI failures.

@hjmjohnson
Copy link
Copy Markdown
Member Author

Update looks good on a glance, but there are CI failures.

I think we need an updated version of CastXML to complement this.

@dzenanz dzenanz mentioned this pull request Dec 18, 2025
2 tasks
@hjmjohnson
Copy link
Copy Markdown
Member Author

hjmjohnson commented Dec 18, 2025

Related to

See #5540 (comment) for an explanation of the failure.

@hjmjohnson hjmjohnson force-pushed the pygccxml-update branch 2 times, most recently from a08445c to 092e3df Compare January 28, 2026 13:23
@hjmjohnson hjmjohnson changed the title Pygccxml update Pygccxml update, use --castxml-output=1 modern xml format from castxml Jan 28, 2026
@hjmjohnson
Copy link
Copy Markdown
Member Author

NOTE:

          # for constructors like                                                                                                                                                                     
          # vnl_matrix(unsigned r, unsigned c, unsigned n, const T values[]);                                                                                                                         
          # ====                                                                                                                                                                                      
          # pygccxml v2.4.0 and `castxml  --castxml-gccxml `                                                                                                                                          
          # wrote the following to the vnl_matrix.i file                                                                                                                                              
          # vnl_matrixD(unsigned int r, unsigned int c, unsigned int n,                                                                                                                               
          #             double const * values);                                                                                                                                                       
          # ====                                                                                                                                                                                      
          # pygccxml v3.0.4 and `castxml --castxml-output=1`                                                                                                                                          
          # wrote the following to the vnl_matrix.i file                                                                                                                                              
          # vnl_matrixD(unsigned int r, unsigned int c, unsigned int n,                                                                                                                               
          #             double const [0] values);                                                                                                                                                     
          #                          ^^^ <- Invalid for swig wrapping                                                                                                                                 
          #                                                                                                                                                                                           
          # In function parameter lists, C and C++ apply array-to-pointer adjustment:                                                                                                                 
          #                                                                                                                                                                                           
          # Any parameter of type T[] or T[N] is adjusted to T*.

hjmjohnson and others added 14 commits January 28, 2026 14:16
This corresponds to commit hash
  62f600c98ec6a25fd3d264774c6fc811ec3c46e4
from upstream repository
  https://github.com/CastXML/pygccxml
Remove reliance on the "--castxml-gccxml" that does not support newer
compilers.

For example:
LLVM PR 114788 switched libc++'s <cstddef> to use decltype() to define
size_t. Any build using libc++ 21 or later will have this problem, not
just those that get it via the macOS SDK.
pygccxml does not support rvalue types (i.e. move constructors
with &&).

Previously move-constructors became duplicate no-argument
constructors declarations in .i files

```c++
class test
{
public:
        test() {};
        test(test &&) {};
}
```

```c++
  test();
  test(); # <-- Generated because the invalid first argument is dropped
          #     due to ?unknown? result from pygccxml when
          #     castxml xml file has RValueReferenceType argument
```
This includes variable name refactoring and return path simplification
to remove syntactic noise

It is part of the support needed to move castxml from

"--castxml-gccxml"
to
"--castxml-output=1"

to support newer compilers.
New versions of castxml and pygccxml > 3
have explicit support for presenting arguments
as array, but swig only supports pointers.

```c++
\# below are functionally equivalent
void func(int a [],size_t n); # <- new pygccxml and castxml
void func(int * a, size_t n); # <- only supported format for swig
```
New versions of castxml with --castxml-output=1 and new version of
pygccxml have syntax formatting differences that were not captured
in the previous simple string replacments.

```diff
- std::basic_string< char >   # --castxml-gccxml   ; pygccxml < 3
+ std::basic_string<char>     # --castxml-output=1 ; pygccxml > 3
```

The re.sub mechansism works with both variants.
Update `igenerator.py` to use raw strings for regex patterns, enhancing
readability and consistency.

Allow for spaces before or after optional white space
(mostly in template<> parameters) to support both old and new castxml format results.
Ensure proper module import order and improve compliance with linting standards.

Silence PEP 8 Warning:
 E402 module level import not at top of file
Consolidate redundant code as a helper function
Add method to reduce redundancy in kwargs processing
Copy link
Copy Markdown
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pushing this forward.

Copy link
Copy Markdown
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tremendous!!!~ 🥇 Thank you, Hans!

Comment thread Modules/ThirdParty/pygccxml/src/pygccxml/declarations/calldef.py
Comment thread Modules/ThirdParty/pygccxml/src/pygccxml/declarations/calldef.py
@hjmjohnson hjmjohnson merged commit 74902b3 into InsightSoftwareConsortium:main Jan 29, 2026
17 checks passed
@hjmjohnson hjmjohnson deleted the pygccxml-update branch March 12, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Python wrapping Python bindings for a class area:ThirdParty Issues affecting the ThirdParty module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants