Skip to content

Commit bae33a0

Browse files
authored
Merge pull request #19386 from meeseeksmachine/auto-backport-of-pr-19238-on-v3.3.x
Backport PR #19238 on branch v3.3.x (Fix build with LTO disabled in environment)
2 parents db5b330 + 81305b4 commit bae33a0

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

.github/workflows/tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
python-version: 3.7
3232
extra-requirements: '-r requirements/testing/travis_extra.txt'
3333
XVFB_RUN: xvfb-run -a
34+
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
3435
- os: ubuntu-16.04
3536
python-version: 3.8
3637
extra-requirements: '-r requirements/testing/travis_extra.txt'

setup.py

+26-12
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,34 @@ def add_optimization_flags(self):
103103
"""
104104

105105
env = os.environ.copy()
106-
if not setupext.config.getboolean('libs', 'enable_lto', fallback=True):
107-
return env
108106
if sys.platform == 'win32':
109107
return env
110-
111-
cppflags = []
112-
if 'CPPFLAGS' in os.environ:
113-
cppflags.append(os.environ['CPPFLAGS'])
114-
cxxflags = []
115-
if 'CXXFLAGS' in os.environ:
116-
cxxflags.append(os.environ['CXXFLAGS'])
117-
ldflags = []
118-
if 'LDFLAGS' in os.environ:
119-
ldflags.append(os.environ['LDFLAGS'])
108+
enable_lto = setupext.config.getboolean('libs', 'enable_lto',
109+
fallback=None)
110+
111+
def prepare_flags(name, enable_lto):
112+
"""
113+
Prepare *FLAGS from the environment.
114+
115+
If set, return them, and also check whether LTO is disabled in each
116+
one, raising an error if Matplotlib config explicitly enabled LTO.
117+
"""
118+
if name in os.environ:
119+
if '-fno-lto' in os.environ[name]:
120+
if enable_lto is True:
121+
raise ValueError('Configuration enable_lto=True, but '
122+
'{0} contains -fno-lto'.format(name))
123+
enable_lto = False
124+
return [os.environ[name]], enable_lto
125+
return [], enable_lto
126+
127+
_, enable_lto = prepare_flags('CFLAGS', enable_lto) # Only check lto.
128+
cppflags, enable_lto = prepare_flags('CPPFLAGS', enable_lto)
129+
cxxflags, enable_lto = prepare_flags('CXXFLAGS', enable_lto)
130+
ldflags, enable_lto = prepare_flags('LDFLAGS', enable_lto)
131+
132+
if enable_lto is False:
133+
return env
120134

121135
if has_flag(self.compiler, '-fvisibility=hidden'):
122136
for ext in self.extensions:

setupext.py

-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ def get_extensions(self):
399399
ext = Extension(
400400
"matplotlib.backends._tkagg", [
401401
"src/_tkagg.cpp",
402-
"src/py_converters.cpp",
403402
],
404403
include_dirs=["src"],
405404
# psapi library needed for finding Tcl/Tk at run time.

src/_tkagg.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@
3737

3838
// Include our own excerpts from the Tcl / Tk headers
3939
#include "_tkmini.h"
40-
#include "py_converters.h"
40+
41+
static int convert_voidptr(PyObject *obj, void *p)
42+
{
43+
void **val = (void **)p;
44+
*val = PyLong_AsVoidPtr(obj);
45+
return *val != NULL ? 1 : !PyErr_Occurred();
46+
}
4147

4248
// Global vars for Tk functions. We load these symbols from the tkinter
4349
// extension module or loaded Tk libraries at run-time.

src/py_converters.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ int convert_from_attr(PyObject *obj, const char *name, converter func, void *p)
9494
return 1;
9595
}
9696

97-
int convert_voidptr(PyObject *obj, void *p)
98-
{
99-
void **val = (void **)p;
100-
*val = PyLong_AsVoidPtr(obj);
101-
return *val != NULL ? 1 : !PyErr_Occurred();
102-
}
103-
10497
int convert_double(PyObject *obj, void *p)
10598
{
10699
double *val = (double *)p;

src/py_converters.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ typedef int (*converter)(PyObject *, void *);
2222
int convert_from_attr(PyObject *obj, const char *name, converter func, void *p);
2323
int convert_from_method(PyObject *obj, const char *name, converter func, void *p);
2424

25-
int convert_voidptr(PyObject *obj, void *p);
2625
int convert_double(PyObject *obj, void *p);
2726
int convert_bool(PyObject *obj, void *p);
2827
int convert_cap(PyObject *capobj, void *capp);

0 commit comments

Comments
 (0)