Skip to content

[libclang/python] Register integer returning library functions as integer instead of bool #164915

@DeinAlptraum

Description

@DeinAlptraum

In the libclang/python bindings, we currently have 43 library library functions registered as ctypes functions returning bool. None of the libclang functions on C-side seem to return booleans, instead they return unsigned (and sometimes signed) ints.

The ctypes module seems to automatically cast the actual unsigned return values to a value of the registered bool type, which works as expected: a return of 0 is interpreted as false, all other returns are interpreted as true.
However, this makes the code confusing to read as it obfuscates the real return type of these library functions in the bindings code. The library functions should be registered with return types matching their declaration, e.g. c_uint.

This means

  • checking all bool return types in the FUNCTION_LIST and adapting their return types to c_uint or c_int respectively
  • adding a bool cast to the return of all functions directly returning the results of these library functions
  • removing type: ignore [no-any-return] annotations where such a cast is applied

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions