Skip to content

Access violation while trying to parse a simple test.h file. #262

@Jerem2360

Description

@Jerem2360

I was trying to parse the following "test.h" file:

void foo() {}

which I created for testing purposes.

The directory tree is:

project
    - header_parser.py
    - test.py
    - test.h
    - tools
        - gcc.exe
        - castxml.exe

test.py looks like this:

import header_parser

parser = header_parser.HeaderParser()
data = parser.parse("test.h")
print(data)

and header_parser.py looks like this:

import pygccxml
import pygccxml.utils
import pygccxml.parser


class HeaderParser:
    def __init__(self):
        genpath, genname = pygccxml.utils.find_xml_generator(search_path="tools")

        self._config = pygccxml.parser.xml_generator_configuration_t(
            xml_generator_path=genpath,
            xml_generator=genname,
            compiler_path="tools/gcc.exe",
        )

    def parse(self, *filenames: str):
        declarations = pygccxml.parser.parse(list(filenames), self._config)

        return pygccxml.declarations.get_global_namespace(declarations)

However, running test.py with a mere python 3.13 installation and no arguments produces this output:

INFO Parsing source file "XXX\test.h" ... 
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: XXX\\tools\\castxml.EXE -I. -c -x c++ --castxml-cc-gnu XXX\\tools\\gcc.exe --castxml-gccxml -o C:\\Users\\XXX\\AppData\\Local\\Temp\\tmp20h39snb.xml D:\\Jerem\\Dev\\py\\pycincluder\\test\\test.h
Exception Code: 0xC0000005
0x00007FFD17CB5C25, D:\Programs\x64\mingw64\bin\libstdc++-6.dll(0x00007FFD17BC0000) + 0xF5C25 byte(s), _ZNSt6localeaSERKS_() + 0x75 byte(s)
0x00007FFD17CD5D18, D:\Programs\x64\mingw64\bin\libstdc++-6.dll(0x00007FFD17BC0000) + 0x115D18 byte(s), _ZNSt8ios_base7_M_initEv() + 0x38 byte(s)
0x00007FFD17CD76C1, D:\Programs\x64\mingw64\bin\libstdc++-6.dll(0x00007FFD17BC0000) + 0x1176C1 byte(s), _ZNSt9basic_iosIcSt11char_traitsIcEE4initEPSt15basic_streambufIcS1_E() + 0x11 byte(s)
0x00007FF781024DBB, XXX\tools\castxml.exe(0x00007FF781010000) + 0x14DBB byte(s)
0x00007FF7810259F3, XXX\tools\castxml.exe(0x00007FF781010000) + 0x159F3 byte(s)
0x00007FF785B43C82, XXX\tools\castxml.exe(0x00007FF781010000) + 0x4B33C82 byte(s)
0x00007FF7810112EF, XXX\tools\castxml.exe(0x00007FF781010000) + 0x12EF byte(s)
0x00007FF781011406, XXX\tools\castxml.exe(0x00007FF781010000) + 0x1406 byte(s)
0x00007FFD8DB9259D, C:\WINDOWS\System32\KERNEL32.DLL(0x00007FFD8DB80000) + 0x1259D byte(s), BaseThreadInitThunk() + 0x1D byte(s)
0x00007FFD8F5AAF78, C:\WINDOWS\SYSTEM32\ntdll.dll(0x00007FFD8F550000) + 0x5AF78 byte(s), RtlUserThreadStart() + 0x28 byte(s)
Traceback (most recent call last):
  File "XXX\test.py", line 4, in <module>
    data = parser.parse("test.h")
  File "XXX\header_parser.py", line 17, in parse
    declarations = pygccxml.parser.parse(list(filenames), self._config)
  File "D:\Programs\x64\Python\3.13\Lib\site-packages\pygccxml\parser\__init__.py", line 51, in parse
    declarations = parser.read_files(files, compilation_mode)
  File "D:\Programs\x64\Python\3.13\Lib\site-packages\pygccxml\parser\project_reader.py", line 264, in read_files
    return self.__parse_file_by_file(files)
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "D:\Programs\x64\Python\3.13\Lib\site-packages\pygccxml\parser\project_reader.py", line 292, in __parse_file_by_file
    decls = reader.read_file(header)
  File "D:\Programs\x64\Python\3.13\Lib\site-packages\pygccxml\parser\source_reader.py", line 303, in read_file
    return self.read_cpp_source_file(source_file)
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "D:\Programs\x64\Python\3.13\Lib\site-packages\pygccxml\parser\source_reader.py", line 322, in read_cpp_source_file
    xml_file = self.create_xml_file(ffname)
  File "D:\Programs\x64\Python\3.13\Lib\site-packages\pygccxml\parser\source_reader.py", line 268, in create_xml_file
    raise RuntimeError(
    ...<2 lines>...
        ": %s status:%s" % (msg, exit_status))
RuntimeError: Error occurred while running CASTXML:  status:3221225477

And indeed, hex(3221225477) is 0xc0000005 which is ERROR_ACCESS_VIOLATION on windows.

OS: Windows 11
GCC version 13.2.0 from Mingw64
castxml.exe downloaded from https://github.com/CastXML/CastXMLSuperbuild/releases
Python version: 3.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions