New GitHub issue #118892 from mingzeng8:<br>

<hr>

<pre>
# Bug report

### Bug description:

Hi,
I'm new here, and apologize if not writing this properly.
I found a bug when using ctypes on Ubuntu 22.04.4 LTS 64-bit, and both python versions 3.10.12. and 3.12.2 have been tested. The attachment show how it occurs.
[show_ctypes_bug.tar.gz](https://github.com/python/cpython/files/15273907/show_ctypes_bug.tar.gz)
Unpack this file, go to the folder, and run show_bug.sh. This file firstly create the shared lib libfoo.so, and link to create the executable main. Then it runs the executable and has expected output. But then it runs warper.py, which use ctypes to call the function foo(), and we obtain unexpected results. The outputs are the following:

> Excuting main
> In func main.
> In func foo.
> In func hcreate.
> In func hdestroy.
> In func whateverelse.

> Excuting python warper.py
> In func foo.
> In func whateverelse.

We can see that `main` has correctly called the functions `hcreate`, `hdestroy`, and `whateverelse`, but `python warper.py` has not called the correct `hcreate` and `hdestroy`. The reason is that the self-defined function names `hcreate` and `hdestroy` conflict with the system library. The regularly linked executable `main` has correctly treated the conflict, but ctypes has not, and it may have called the functions in the system library instead of the self-defined ones.

I also show the testing files in the following:
`foo.c`

> #include <stdio.h>
> int hcreate(){
>    printf("In func hcreate.\n");
>    return 0;
> };

> int hdestroy(){
>    printf("In func hdestroy.\n");
>    return 0;
> };

> int whateverelse(){
>    printf("In func whateverelse.\n");
>    return 0;
> };

> int foo(){
>    printf("In func foo.\n");
>    hcreate();
>    hdestroy();
>    whateverelse();
>    return 0;
> }

`main.c`

> #include <stdio.h>
> int foo();

> int main(int argc, char** argv){
>    printf("In func main.\n");
>    foo();
>    return 0;
> }

`warper.py`

> from ctypes import *

> dll = cdll.LoadLibrary("./libfoo.so")
> dll.foo()

`show_bug.sh`

> rm *.o
> rm *.so
> gcc -c foo.c
> gcc -c main.c

> gcc foo.o -shared -o libfoo.so
> gcc main.o -o main -L. -lfoo
> #ar rcs libfoo.a foo.o
> #gcc main.o -o main -L. -l:libfoo.a

> echo
> export LD_LIBRARY_PATH=.
> echo Excuting main
> ./main
> echo
> echo Excuting python warper.py
> python warper.py

### CPython versions tested on:

3.12

### Operating systems tested on:

Linux
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/118892">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>