[clang] [libclang/python] Ensure all library functions are registered (PR #140015)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 04:52:29 PDT 2025
================
@@ -0,0 +1,17 @@
+import os
+
+from clang.cindex import Config, conf, FUNCTION_LIST
+
+if "CLANG_LIBRARY_PATH" in os.environ:
+ Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
+
+import unittest
+
+
+class TestIndex(unittest.TestCase):
+ def test_functions_registered(self):
+ IGNORED = set(["_FuncPtr", "_name", "_handle"])
+ lib_functions = set(vars(conf.lib).keys())
----------------
Endilll wrote:
I think what this test actually tests is whether `getattr` was called on `conf.lib` with everything that's in FUNCTION_LIST, i.e. it test `register_function` and code around it:
```python
import ctypes
from pprint import pprint
lib = ctypes.cdll.LoadLibrary("/home/user/endill/ramdisk/llvm-build/lib/libclang.so")
print("--- before getattr")
pprint(vars(lib))
getattr(lib, "clang_createIndex")
print("--- after getattr")
pprint(vars(lib))
```
outputs:
```
--- before getattr
{'_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>,
'_handle': 906416256,
'_name': '/home/user/endill/ramdisk/llvm-build/lib/libclang.so'}
--- after getattr
{'_FuncPtr': <class 'ctypes.CDLL.__init__.<locals>._FuncPtr'>,
'_handle': 906416256,
'_name': '/home/user/endill/ramdisk/llvm-build/lib/libclang.so',
'clang_createIndex': <_FuncPtr object at 0x7f8296567dd0>}
```
So for purposes of testing for completeness of `FUNCTION_LIST`, this is an echo chamber.
I'm looking into other ways to test that.
https://github.com/llvm/llvm-project/pull/140015
More information about the cfe-commits
mailing list