Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit 821f021

Browse files
author
Gabriel Corona
committed
Add support for Python 3.7
1 parent c151d2f commit 821f021

File tree

13 files changed

+133
-20
lines changed

13 files changed

+133
-20
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
- PYVERSION=python3.4
1313
- PYVERSION=python3.5
1414
- PYVERSION=python3.6
15+
- PYVERSION=python3.7
1516

1617
addons:
1718
apt:

configure.ac

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ PKG_CHECK_MODULES([PY36], [python-3.6], [enable_py36="yes"], [AC_MSG_WARN([Build
111111
AM_CONDITIONAL([ENABLE_PY36], [test x"$enable_py36" = xyes])
112112
AM_COND_IF([ENABLE_PY36], [AC_DEFINE([ENABLE_PY36], [1], [Python 3.6 will be enabled])])
113113

114-
AS_IF([test x"$enable_py26" = xyes -o x"$enable_py34" = xyes -o x"$enable_py36" = xyes],
114+
enable_py37=no
115+
PKG_CHECK_MODULES([PY37], [python-3.7], [enable_py37="yes"], [AC_MSG_WARN([Building without Python 3.7 support])])
116+
AM_CONDITIONAL([ENABLE_PY37], [test x"$enable_py37" = xyes])
117+
AM_COND_IF([ENABLE_PY37], [AC_DEFINE([ENABLE_PY37], [1], [Python 3.7 will be enabled])])
118+
119+
AS_IF([test x"$enable_py26" = xyes -o x"$enable_py34" = xyes -o x"$enable_py36" = xyes -o x"$enable_py37" = xyes],
115120
[AC_MSG_NOTICE([Found at least one copy of Python.h])],
116121
[AC_MSG_ERROR([Failed to find a supported Python.h])]
117122
)
@@ -127,7 +132,8 @@ echo
127132
echo " with threads = $enable_threads"
128133
echo " with Python 2.6/7 = $enable_py26"
129134
echo " with Python 3.4/5 = $enable_py34"
130-
echo " with Python 3.6+ = $enable_py36"
135+
echo " with Python 3.6 = $enable_py36"
136+
echo " with Python 3.7+ = $enable_py37"
131137
echo
132138
echo " CXX = $CXX"
133139
echo " CXXFLAGS = $CXXFLAGS"

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ What Python Versions Are Supported?
77
Python 2 is tested with Python 2.6 and 2.7. Earlier versions of Python 2 are
88
likely to work as well, but have not been tested.
99

10-
Python 3 is tested with Python 3.4, 3.5, and 3.6. Python 3.6 introduces a new
10+
Python 3 is tested with Python 3.4, 3.5, 3.6 and 3.7 Python 3.6 introduces a new
1111
ABI for the ``PyCodeObject`` type, so Pyflame only supports the Python 3
1212
versions that header files were available for when Pyflame was compiled.
1313

docs/man.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The following options are less commonly used.
8787
cases when profiling embedded Python builds (e.g. uWSGI), and only if
8888
pyflame doesn't automatically detect the correct ABI. *VERSION* should be a
8989
two digit integer consisting of the Python major and minor version, e.g. 27
90-
for Python 2.7 or 36 for Python 3.6.
90+
for Python 2.7, 36 for Python 3.6 or 37 for Python 3.7.
9191

9292
**--flamechart**
9393
: Print the timestamp for each stack. This is useful for generating "flame

docs/pyflame.man

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ uWSGI), and only if pyflame doesn\[aq]t automatically detect the correct
119119
ABI.
120120
\f[I]VERSION\f[] should be a two digit integer consisting of the Python
121121
major and minor version, e.g.
122-
27 for Python 2.7 or 36 for Python 3.6.
122+
27 for Python 2.7, 36 for Python 3.6 or 37 for Python 3.7.
123123
.RS
124124
.RE
125125
.TP

src/Makefile.am

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#
33
# The way this code is structured is the code that know about Python interpreter
44
# internals is in frob.cc. This file isn't compiled directly, instead there are
5-
# files frob{26,34,36}.cc that define preprocessor macros to compile frob.cc for
5+
# files frob{26,34,36,37}.cc that define preprocessor macros to compile frob.cc for
66
# different Python ABIs.
77
#
88
# The libtool magic here makes it so that frob26.cc is compiled with python2
9-
# flags, and frob3{4,6}.cc are compiled with python3.4/3.6 flags.
9+
# flags, and frob3{4,6,7}.cc are compiled with python3.4/3.6/3.7 flags.
1010

1111
bin_PROGRAMS = pyflame
1212
pyflame_SOURCES = aslr.cc frame.cc thread.cc namespace.cc posix.cc prober.cc ptrace.cc pyflame.cc pyfrob.cc symbol.cc
@@ -34,3 +34,11 @@ libfrob36_la_CXXFLAGS = $(PY36_CFLAGS)
3434
noinst_LTLIBRARIES += libfrob36.la
3535
pyflame_LDADD += libfrob36.la
3636
endif
37+
38+
if ENABLE_PY37
39+
libfrob37_la_SOURCES = frob37.cc offset37.c
40+
libfrob37_la_CFLAGS = $(PY37_CFLAGS)
41+
libfrob37_la_CXXFLAGS = $(PY37_CFLAGS)
42+
noinst_LTLIBRARIES += libfrob37.la
43+
pyflame_LDADD += libfrob37.la
44+
endif

src/frob.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// information.
1818

1919
#include <Python.h>
20+
2021
#include <frameobject.h>
2122

2223
#if PYFLAME_PY_VERSION >= 34
@@ -89,6 +90,22 @@ unsigned long ByteData(unsigned long addr) {
8990
return addr + offsetof(PyBytesObject, ob_sval);
9091
}
9192

93+
#elif PYFLAME_PY_VERSION == 37
94+
namespace py37 {
95+
std::string StringDataPython3(pid_t pid, unsigned long addr);
96+
97+
unsigned long StringSize(unsigned long addr) {
98+
return addr + offsetof(PyVarObject, ob_size);
99+
}
100+
101+
std::string StringData(pid_t pid, unsigned long addr) {
102+
return StringDataPython3(pid, addr);
103+
}
104+
105+
unsigned long ByteData(unsigned long addr) {
106+
return addr + offsetof(PyBytesObject, ob_sval);
107+
}
108+
92109
#else
93110
static_assert(false, "uh oh, bad PYFLAME_PY_VERSION");
94111
#endif

src/frob37.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 Uber Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// ABI for Python 3.7
16+
#define PYFLAME_PY_VERSION 37
17+
18+
#include "./frob.cc"

src/offset37.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 Uber Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#define Py_BUILD_CORE
16+
#include <stddef.h>
17+
#include <stdatomic.h>
18+
#include <Python.h>
19+
#include <internal/pystate.h>
20+
21+
// We needd to include pystate.h which needs to include pyatomic.h
22+
// which needs to include stdatomic.h which currently fails to work in C++
23+
// with GCC. We do this in C instead.
24+
//
25+
size_t PYFLAME_PYTHON37_OFFSET = offsetof(_PyRuntimeState, gilstate) +
26+
offsetof(struct _gilstate_runtime_state, tstate_current);

src/prober.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static const char usage_str[] =
6464
" -x, --exclude-idle Exclude idle time from statistics\n"
6565
"\n"
6666
"Advanced Options:\n"
67-
" --abi Force a particular Python ABI (26, 34, 36)\n"
67+
" --abi Force a particular Python ABI (26, 34, 36, 37)\n"
6868
" --flamechart Include timestamps for generating Chrome "
6969
"\"flamecharts\"\n");
7070

@@ -79,6 +79,9 @@ static const int build_abis[] = {
7979
#ifdef ENABLE_PY36
8080
36,
8181
#endif
82+
#ifdef ENABLE_PY37
83+
37,
84+
#endif
8285
};
8386

8487
static_assert(sizeof(build_abis) > 0, "No Python ABIs detected!");
@@ -221,6 +224,9 @@ int Prober::ParseOpts(int argc, char **argv) {
221224
case 36:
222225
abi_ = PyABI::Py36;
223226
break;
227+
case 37:
228+
abi_ = PyABI::Py37;
229+
break;
224230
default:
225231
std::cerr << "Unknown or unsupported ABI version: " << abi_version
226232
<< "\n";

0 commit comments

Comments
 (0)