Thomas Applencourt a04ceb02ad
[libclang/python] Return actual C types from libclang functions instead of Python bool (#166446)
In the previous implementation, 43 libclang functions are registered in
FUNCTION_LIST with return type ctypes.c_bool. However, none of these
functions actually return a C bool type; instead, they return unsigned
or signed integers (unsigned int / int) on the C side.

Although ctypes automatically casts nonzero integers to True and zero to
False, this implicit conversion hides the "true" c-return type.

This PR updates those functions to use their proper “native” ctypes
return types (c_uint or c_int) and updates the corresponding Python
convenience wrappers to explicitly cast their results using the bool
constructor.

As a side effect, the related `# type: ignore` annotations have been
removed, as they are no longer necessary.

Some libclang functions are used directly without any intermediate
Python wrapper. These functions (`clang_equalCursors`,
`clang_equalLocations`, `clang_equalRanges`, `clang_equalTypes`,
`clang_File_isEqual`, and `clang_isFileMultipleIncludeGuarded`) are now
explicitly cast to bool at their call sites. Note that
`clang_isFileMultipleIncludeGuarded` is never called in the binding.

Thix fix #164915.
2025-11-07 13:00:54 +04:00
..

//===----------------------------------------------------------------------===//
// Clang Python Bindings
//===----------------------------------------------------------------------===//

This directory implements Python bindings for Clang.

You may need to set CLANG_LIBRARY_PATH so that the Clang library can be
found. The unit tests are designed to be run with any standard test
runner. For example:
--
$ env PYTHONPATH=$(echo ~/llvm/clang/bindings/python/) \
      CLANG_LIBRARY_PATH=$(llvm-config --libdir) \
  python3 -m unittest discover -v
tests.cindex.test_index.test_create ... ok
...

OK
--