Skip to content

Commit d9f459d

Browse files
committed
linux: patch ctypes to avoid OSError on module load
See the inline comment for more.
1 parent d3cae50 commit d9f459d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cpython-linux/build-cpython.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ cat Makefile.extra
2828

2929
pushd Python-${PYTHON_VERSION}
3030

31+
# Code that runs at ctypes module import time does not work with
32+
# non-dynamic binaries. Patch Python to work around this.
33+
# See https://bugs.python.org/issue37060.
34+
patch -p1 << EOF
35+
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
36+
--- a/Lib/ctypes/__init__.py
37+
+++ b/Lib/ctypes/__init__.py
38+
@@ -441,7 +441,10 @@ if _os.name == "nt":
39+
elif _sys.platform == "cygwin":
40+
pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
41+
else:
42+
- pythonapi = PyDLL(None)
43+
+ try:
44+
+ pythonapi = PyDLL(None)
45+
+ except OSError:
46+
+ pythonapi = None
47+
48+
49+
if _os.name == "nt":
50+
EOF
51+
3152
cp Modules/readline.c Modules/readline-libedit.c
3253

3354
# Python supports using libedit instead of readline. But Modules/readline.c

cpython-linux/build.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ RUN apt-get install \
33
file \
44
libc6-dev \
55
make \
6+
patch \
67
perl \
78
tar \
89
xz-utils \

0 commit comments

Comments
 (0)