Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
python-version: 3.7
extra-requirements: '-r requirements/testing/travis_extra.txt'
XVFB_RUN: xvfb-run -a
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
- os: ubuntu-16.04
python-version: 3.8
extra-requirements: '-r requirements/testing/travis_extra.txt'
Expand Down
38 changes: 26 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,34 @@ def add_optimization_flags(self):
"""

env = os.environ.copy()
if not setupext.config.getboolean('libs', 'enable_lto', fallback=True):
return env
if sys.platform == 'win32':
return env

cppflags = []
if 'CPPFLAGS' in os.environ:
cppflags.append(os.environ['CPPFLAGS'])
cxxflags = []
if 'CXXFLAGS' in os.environ:
cxxflags.append(os.environ['CXXFLAGS'])
ldflags = []
if 'LDFLAGS' in os.environ:
ldflags.append(os.environ['LDFLAGS'])
enable_lto = setupext.config.getboolean('libs', 'enable_lto',
fallback=None)

def prepare_flags(name, enable_lto):
"""
Prepare *FLAGS from the environment.

If set, return them, and also check whether LTO is disabled in each
one, raising an error if Matplotlib config explicitly enabled LTO.
"""
if name in os.environ:
if '-fno-lto' in os.environ[name]:
if enable_lto is True:
raise ValueError('Configuration enable_lto=True, but '
'{0} contains -fno-lto'.format(name))
enable_lto = False
return [os.environ[name]], enable_lto
return [], enable_lto

_, enable_lto = prepare_flags('CFLAGS', enable_lto) # Only check lto.
cppflags, enable_lto = prepare_flags('CPPFLAGS', enable_lto)
cxxflags, enable_lto = prepare_flags('CXXFLAGS', enable_lto)
ldflags, enable_lto = prepare_flags('LDFLAGS', enable_lto)

if enable_lto is False:
return env

if has_flag(self.compiler, '-fvisibility=hidden'):
for ext in self.extensions:
Expand Down
1 change: 0 additions & 1 deletion setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ def get_extensions(self):
ext = Extension(
"matplotlib.backends._tkagg", [
"src/_tkagg.cpp",
"src/py_converters.cpp",
],
include_dirs=["src"],
# psapi library needed for finding Tcl/Tk at run time.
Expand Down
8 changes: 7 additions & 1 deletion src/_tkagg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@

// Include our own excerpts from the Tcl / Tk headers
#include "_tkmini.h"
#include "py_converters.h"

static int convert_voidptr(PyObject *obj, void *p)
{
void **val = (void **)p;
*val = PyLong_AsVoidPtr(obj);
return *val != NULL ? 1 : !PyErr_Occurred();
}

// Global vars for Tk functions. We load these symbols from the tkinter
// extension module or loaded Tk libraries at run-time.
Expand Down
7 changes: 0 additions & 7 deletions src/py_converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ int convert_from_attr(PyObject *obj, const char *name, converter func, void *p)
return 1;
}

int convert_voidptr(PyObject *obj, void *p)
{
void **val = (void **)p;
*val = PyLong_AsVoidPtr(obj);
return *val != NULL ? 1 : !PyErr_Occurred();
}

int convert_double(PyObject *obj, void *p)
{
double *val = (double *)p;
Expand Down
1 change: 0 additions & 1 deletion src/py_converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ typedef int (*converter)(PyObject *, void *);
int convert_from_attr(PyObject *obj, const char *name, converter func, void *p);
int convert_from_method(PyObject *obj, const char *name, converter func, void *p);

int convert_voidptr(PyObject *obj, void *p);
int convert_double(PyObject *obj, void *p);
int convert_bool(PyObject *obj, void *p);
int convert_cap(PyObject *capobj, void *capp);
Expand Down