Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ed25adc

Browse filesBrowse files
authored
Merge pull request #19238 from QuLogic/disable-lto
Fix build with LTO disabled in environment
2 parents 30a0064 + 988bfc5 commit ed25adc
Copy full SHA for ed25adc

File tree

Expand file treeCollapse file tree

6 files changed

+34
-25
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+34
-25
lines changed

‎.github/workflows/tests.yml

Copy file name to clipboardExpand all lines: .github/workflows/tests.yml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
python-version: 3.7
3333
extra-requirements: '-r requirements/testing/travis_extra.txt'
3434
XVFB_RUN: xvfb-run -a
35+
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
3536
- os: ubuntu-16.04
3637
python-version: 3.8
3738
extra-requirements: '-r requirements/testing/travis_extra.txt'

‎setup.py

Copy file name to clipboardExpand all lines: setup.py
+26-12Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,34 @@ def add_optimization_flags(self):
106106
"""
107107

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

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

‎setupext.py

Copy file name to clipboardExpand all lines: setupext.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ def get_extensions(self):
447447
ext = Extension(
448448
"matplotlib.backends._tkagg", [
449449
"src/_tkagg.cpp",
450-
"src/py_converters.cpp",
451450
],
452451
include_dirs=["src"],
453452
# psapi library needed for finding Tcl/Tk at run time.

‎src/_tkagg.cpp

Copy file name to clipboardExpand all lines: src/_tkagg.cpp
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@
3333
#define dlsym GetProcAddress
3434
#else
3535
#include <dlfcn.h>
36-
// Suppress -Wunused-function on POSIX, but not on Windows where that would
37-
// lead to PY_ARRAY_UNIQUE_SYMBOL being an unresolved external.
38-
#define NO_IMPORT_ARRAY
3936
#endif
4037

4138
// Include our own excerpts from the Tcl / Tk headers
4239
#include "_tkmini.h"
43-
#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+
}
4447

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

‎src/py_converters.cpp

Copy file name to clipboardExpand all lines: src/py_converters.cpp
-7Lines changed: 0 additions & 7 deletions
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

Copy file name to clipboardExpand all lines: src/py_converters.h
-1Lines changed: 0 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.