Skip to content

Commit 4d5f96d

Browse files
committed
mingw-w64: ctypes/ffi build fixes
1. Export DllGetClassObject and DllCanUnloadNow in _ctypes module 2. Don't compile src/dlmalloc.c for Windows 3. Use forward slashes for ffi_{build,src}dir
1 parent 6bfe21c commit 4d5f96d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Modules/_ctypes/libffi/fficonfig.py.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ ffi_platforms = {
2323
'FRV': ['src/frv/eabi.S', 'src/frv/ffi.c'],
2424
'S390': ['src/s390/sysv.S', 'src/s390/ffi.c'],
2525
'X86_64': ['src/x86/ffi64.c', 'src/x86/unix64.S', 'src/x86/ffi.c', 'src/x86/sysv.S'],
26+
'X86_WIN64': ['src/x86/ffi.c', 'src/x86/win64.S'],
2627
'SH': ['src/sh/sysv.S', 'src/sh/ffi.c'],
2728
'SH64': ['src/sh64/sysv.S', 'src/sh64/ffi.c'],
2829
'PA': ['src/pa/linux.S', 'src/pa/ffi.c'],
2930
'PA_LINUX': ['src/pa/linux.S', 'src/pa/ffi.c'],
3031
'PA_HPUX': ['src/pa/hpux32.S', 'src/pa/ffi.c'],
3132
}
3233

34+
ffi_target = '@TARGET@'
35+
if ffi_target not in ['X86_WIN32', 'X86_WIN64']:
36+
ffi_sources += 'src/dlmalloc.c'
3337
ffi_sources += ffi_platforms['@TARGET@']
3438

3539
ffi_cflags = '@CFLAGS@'

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,10 @@ def configure_ctypes_darwin(self, ext):
18801880
return True
18811881

18821882
def configure_ctypes(self, ext):
1883+
if host_platform == 'win32':
1884+
ext.libraries.extend(['ole32', 'oleaut32', 'uuid'])
1885+
ext.export_symbols.extend(['DllGetClassObject PRIVATE',
1886+
'DllCanUnloadNow PRIVATE'])
18831887
if not self.use_system_libffi:
18841888
if host_platform == 'darwin':
18851889
return self.configure_ctypes_darwin(ext)
@@ -1904,6 +1908,10 @@ def configure_ctypes(self, ext):
19041908
if not self.verbose:
19051909
config_args.append("-q")
19061910

1911+
if host_platform == 'win32':
1912+
table = str.maketrans('\\', '/')
1913+
ffi_builddir = ffi_builddir.translate(table)
1914+
ffi_srcdir = ffi_srcdir.translate(table)
19071915
# Pass empty CFLAGS because we'll just append the resulting
19081916
# CFLAGS to Python's; -g or -O2 is to be avoided.
19091917
cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \

0 commit comments

Comments
 (0)