‘CPyModule__ctypes’ undeclared
Open
Nobody has claimed this yet.
bug
topic-mypyc
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When trying to use mypyc with ctypes, I get a compile error:
$ mypyc ioctl.py
running build_ext
building 'ioctl' extension
gcc -pthread -B /home/mypy/source/compiler_compat -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/mypy/source/include -fPIC -O2 -isystem /home/mypy/source/include -fPIC -I/home/mypy/source/lib/python3.11/site-packages/mypyc/lib-rt -I/home/mypy/source/include/python3.11 -c build/__native.c -o build/temp.linux-x86_64-cpython-311/build/__native.o -O3 -g1 -Werror -Wno-unused-function -Wno-unused-label -Wno-unreachable-code -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-ignored-optimization-argument -Wno-cpp
build/__native.c: In function ‘CPyDef___top_level__’:
build/__native.c:189:17: error: ‘CPyModule__ctypes’ undeclared (first use in this function); did you mean ‘CPyModule_ctypes’?
189 | cpy_r_r19 = CPyModule__ctypes;
| ^~~~~~~~~~~~~~~~~
| CPyModule_ctypes
build/__native.c:189:17: note: each undeclared identifier is reported only once for each function it appears in
build/__native.c: At top level:
cc1: note: unrecognized command-line option ‘-Wno-ignored-optimization-argument’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option ‘-Wno-unused-command-line-argument’ may have been intended to silence earlier diagnostics
error: command '/usr/bin/gcc' failed with exit code 1
To Reproduce
Test script ioctl.py:
import ctypes
class _GPIOchipInfo(ctypes.Structure):
_fields_ = [
('name', ctypes.c_char * 32),
('label', ctypes.c_char * 32),
('lines', ctypes.c_uint32),
]
Workaround
Adding
#define CPyModule__ctypes CPyModule_ctypes
in the CPy.h include file "fixes" this error and the compiler succeeds.
Your Environment
- Mypy version used: 1.7.1
- Python version used: 3.11.6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with mypyc 1.7.1 and the provided ioctl.py script, then inspect generated build/__native.c and the CPy.h include file. Trace why the generated code refers to CPyModule__ctypes while CPyModule_ctypes is declared; done means compiling the ctypes example without the reported undeclared-identifier error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100