Skip to content

‘CPyModule__ctypes’ undeclared #16687

Open
@juhasch

Description

@juhasch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-mypycmypyc bugs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions