cpython/Modules/_ctypes
George Alexopoulos 8717f792f7
gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555)
For dlsym(), a return value of NULL does not necessarily indicate
an error [1].

Therefore, to avoid using stale (or NULL) dlerror() values, we must:

 1. clear the previous error state by calling dlerror()
 2. call dlsym()
 3. call dlerror()

If the return value of dlerror() is not NULL, an error occured.

In ctypes we choose to treat a NULL return value from dlsym()
as a "not found" error. This is the same as the fallback
message we use on Windows, Cygwin or when getting/formatting
the error reason fails.

[1]: https://man7.org/linux/man-pages/man3/dlsym.3.html

Signed-off-by: Georgios Alexopoulos <grgalex42@gmail.com>
Signed-off-by: Georgios Alexopoulos <grgalex@ba.uoa.gr>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-11-15 11:05:51 +01:00
..
clinic gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords (GH-126564) 2024-11-08 14:23:50 +02:00
_ctypes.c gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) 2024-11-15 11:05:51 +01:00
_ctypes_test.c gh-125206: Bug in ctypes with old libffi is fixed (#125322) 2024-10-15 16:17:10 +00:00
_ctypes_test.h
_ctypes_test_generated.c.h gh-97588: Align ctypes struct layout to GCC/MSVC (GH-97702) 2024-05-29 12:02:53 +02:00
callbacks.c gh-117142: Port _ctypes to multi-phase init (GH-117181) 2024-04-10 11:00:01 +00:00
callproc.c gh-126554: ctypes: Correctly handle NULL dlsym values (GH-126555) 2024-11-15 11:05:51 +01:00
cfield.c gh-125206: Bug in ctypes with old libffi is fixed (#125322) 2024-10-15 16:17:10 +00:00
ctypes.h gh-125206: Bug in ctypes with old libffi is fixed (#125322) 2024-10-15 16:17:10 +00:00
malloc_closure.c gh-108765: Python.h no longer includes <unistd.h> (#108783) 2023-09-02 16:50:18 +02:00
stgdict.c gh-110190: Fix ctypes structs with array on SPARC (GH-118233) 2024-09-17 19:06:53 +02:00