Skip to content

solve windows clang-17.0.6 get_version() access violation exception  #136

@huhutm

Description

@huhutm

It's because that clang_getClangVersion interface return type is not c_char_p but CXString. Below is my modify:

class CXString(ctypes.Structure):
    _fields_ = [
        ('data', ctypes.POINTER(None)),
        ('private_flags', ctypes.c_uint32),
    ]

def clang_version():
    """Pull the clang C library version from the API"""
    # avoid loading the cindex API (cindex.conf.lib) to avoid version conflicts
    get_version = cindex.conf.get_cindex_library().clang_getClangVersion
    get_version.restype = CXString
    version_string = get_version()
    version_string = ctypes.cast(version_string.data, ctypes.c_char_p).value
    version = 'Unknown'
    if version_string and len(version_string) > 0:
        version_groups = re.match(br'.+version ((\d+\.)?(\d+\.)?(\*|\d+))', version_string)
        if version_groups and len(version_groups.groups()) > 0:
            version = version_groups.group(1).decode()
    return version

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions