[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 06:12:26 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:

Exploring the "list all symbols" solution:

1) I checked what WinAPI calls CPython's `ctypes` do, and there's nothing interesting beyond `GetProcAddress`.

2) It seems that there is a WinAPI function to enumerate all exported function from a DLL: https://learn.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumsymbols. However, it comes from `dbghelp.dll`, so availability on various Windows versions has to be checked.

3) I wasn't able to find anything equivalent for Linux.

4) So it's likely that we need an external tool for this. Using LLVM toolchain, here are the best ways I was able to figure out: `llvm-nm --dynamic --defined-only` for Linux, `llvm-objdump --private-headers` for Windows (this one has additional information that we'd need to filter out).

https://github.com/llvm/llvm-project/pull/140015


More information about the cfe-commits mailing list