Skip to content

Instantly share code, notes, and snippets.

@lisa
Created May 23, 2018 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lisa/f54db1b21c3b9666bf3eba3b3d29dc75 to your computer and use it in GitHub Desktop.
Save lisa/f54db1b21c3b9666bf3eba3b3d29dc75 to your computer and use it in GitHub Desktop.
Python bug?

The makesetup script is responsible for creating the Makefile for Python 2.7 and is especially relevant when modules are added to Modules/Setup. See https://github.com/python/cpython/blob/2.7/Modules/Setup.dist#L13-L25 for details.

The usage notes has a note which explains how modules are defined: each on a line in the format <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]. Pay special attention to <cpparg> is anything starting with -I, -D, -U or -C. This means -I/build/zlib-1.2.3 or -DUSE_GLIBC or whatnot.

Here is an example:

pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI -DHAVE_SYSCALL_GETRANDOM

The bug happens with makesetup's assumptions about the data appearing in the Setup files:

Line 131 (https://github.com/python/cpython/blob/2.7/Modules/makesetup#L131) has code that seems to be in support of adding definitions to the Makefile for later use therein. However, -DVERSION=123 is a valid ccparg and the makesetup sees it instead as a definition (to be added to the Makefile) because the makesetup script blindly applies *=* that matches -DVERSION=123 and thus breaks the Makefile.

Reproduction:

curl -LO https://www.python.org/ftp/python/2.7.15/Python-2.7.15rc1.tar.xz
unxz Python-${PYTHON_BASE_VERSION}${PYTHON_RC}.tar.xz
tar -xf Python-${PYTHON_BASE_VERSION}${PYTHON_RC}.tar
cd Python-2.7.15rc1
cp Modules/Setup.dist Modules/Setup
echo "breaking foo.c -DBREAKSMAKEFILE=1" >> Modules/Setup
./configure
make
Makefile:226: *** missing separator (did you mean TAB instead of 8 spaces?).  Stop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment