Skip to content

Commit 956f0fd

Browse files
committed
fix: fix compilation errors on latest 3.11.0
1 parent 9097c0d commit 956f0fd

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- "3.8"
4040
- "3.9"
4141
- "3.10"
42-
- "3.11.0-alpha.5"
42+
- "3.11.0-beta.1"
4343
- "pypy-3.7"
4444
exclude:
4545
# Windows PyPy doesn't seem to work?

.github/workflows/kit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ jobs:
239239
py:
240240
# PYVERSIONS. Available versions:
241241
# https://github.com/actions/python-versions/blob/main/versions-manifest.json
242-
- "3.11.0-alpha.5"
242+
- "3.11.0-beta.1"
243243
fail-fast: false
244244

245245
steps:

CHANGES.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ development at the same time, such as 4.5.x and 5.0.
2020
Unreleased
2121
----------
2222

23-
Nothing yet.
23+
- Fix: Coverage.py now builds successfully on CPython 3.11 (3.11.0b1) again.
24+
Closes `issue 1367`_. Some results for generators may have changed.
25+
26+
.. _issue 1367: https://github.com/nedbat/coveragepy/issues/1367
2427

2528

2629
.. _changes_632:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Coverage.py runs on these versions of Python:
2727

2828
.. PYVERSIONS
2929
30-
* CPython 3.7 through 3.11.0a5.
30+
* CPython 3.7 through 3.11.0b1.
3131
* PyPy3 7.3.8.
3232

3333
Documentation is on `Read the Docs`_. Code repository and issue tracker are on

coverage/ctracer/tracer.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
307307
PyObject * plugin = NULL;
308308
PyObject * plugin_name = NULL;
309309
PyObject * next_tracename = NULL;
310+
#ifdef RESUME
311+
PyObject * pCode = NULL;
312+
#endif
310313

311314
/* Borrowed references. */
312315
PyObject * filename = NULL;
@@ -526,16 +529,16 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
526529
*/
527530
BOOL real_call = FALSE;
528531

529-
#ifdef RESUME // 3.11.0a4
532+
#ifdef RESUME
530533
/*
531534
* The current opcode is guaranteed to be RESUME. The argument
532535
* determines what kind of resume it is.
533536
*/
534-
PyObject * pCode = MyFrame_GetCode(frame)->co_code;
535-
real_call = (PyBytes_AS_STRING(pCode)[MyFrame_lasti(frame) + 1] == 0);
537+
pCode = MyCode_GetCode(MyFrame_GetCode(frame));
538+
real_call = (PyBytes_AS_STRING(pCode)[MyFrame_GetLasti(frame) + 1] == 0);
536539
#else
537540
// f_lasti is -1 for a true call, and a real byte offset for a generator re-entry.
538-
real_call = (MyFrame_lasti(frame) < 0);
541+
real_call = (MyFrame_GetLasti(frame) < 0);
539542
#endif
540543

541544
if (real_call) {
@@ -549,6 +552,9 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
549552
ret = RET_OK;
550553

551554
error:
555+
#ifdef RESUME
556+
MyCode_FreeCode(pCode);
557+
#endif
552558
Py_XDECREF(next_tracename);
553559
Py_XDECREF(disposition);
554560
Py_XDECREF(plugin);
@@ -689,6 +695,8 @@ CTracer_handle_return(CTracer *self, PyFrameObject *frame)
689695
{
690696
int ret = RET_ERROR;
691697

698+
PyObject * pCode = NULL;
699+
692700
STATS( self->stats.returns++; )
693701
/* A near-copy of this code is above in the missing-return handler. */
694702
if (CTracer_set_pdata_stack(self) < 0) {
@@ -699,8 +707,8 @@ CTracer_handle_return(CTracer *self, PyFrameObject *frame)
699707
if (self->pdata_stack->depth >= 0) {
700708
if (self->tracing_arcs && self->pcur_entry->file_data) {
701709
BOOL real_return = FALSE;
702-
PyObject * pCode = MyFrame_GetCode(frame)->co_code;
703-
int lasti = MyFrame_lasti(frame);
710+
pCode = MyCode_GetCode(MyFrame_GetCode(frame));
711+
int lasti = MyFrame_GetLasti(frame);
704712
Py_ssize_t code_size = PyBytes_GET_SIZE(pCode);
705713
unsigned char * code_bytes = (unsigned char *)PyBytes_AS_STRING(pCode);
706714
#ifdef RESUME
@@ -760,6 +768,7 @@ CTracer_handle_return(CTracer *self, PyFrameObject *frame)
760768

761769
error:
762770

771+
MyCode_FreeCode(pCode);
763772
return ret;
764773
}
765774

coverage/ctracer/util.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
// to make this work, but it's all I've got until https://bugs.python.org/issue40421
1818
// is resolved.
1919
#include <internal/pycore_frame.h>
20-
#define MyFrame_lasti(f) ((f)->f_frame->f_lasti * 2)
20+
#if PY_VERSION_HEX >= 0x030B00A7
21+
#define MyFrame_GetLasti(f) (PyFrame_GetLasti(f))
22+
#else
23+
#define MyFrame_GetLasti(f) ((f)->f_frame->f_lasti * 2)
24+
#endif
2125
#elif PY_VERSION_HEX >= 0x030A00A7
2226
// The f_lasti field changed meaning in 3.10.0a7. It had been bytes, but
2327
// now is instructions, so we need to adjust it to use it as a byte index.
24-
#define MyFrame_lasti(f) ((f)->f_lasti * 2)
28+
#define MyFrame_GetLasti(f) ((f)->f_lasti * 2)
2529
#else
26-
#define MyFrame_lasti(f) ((f)->f_lasti)
30+
#define MyFrame_GetLasti(f) ((f)->f_lasti)
2731
#endif
2832

2933
// Access f_code should be done through a helper starting in 3.9.
@@ -33,6 +37,14 @@
3337
#define MyFrame_GetCode(f) ((f)->f_code)
3438
#endif
3539

40+
#if PY_VERSION_HEX >= 0x030B00A7
41+
#define MyCode_GetCode(co) (PyObject_GetAttrString((PyObject *)(co), "co_code"))
42+
#define MyCode_FreeCode(code) Py_XDECREF(code)
43+
#else
44+
#define MyCode_GetCode(co) ((co)->co_code)
45+
#define MyCode_FreeCode(code)
46+
#endif
47+
3648
/* The values returned to indicate ok or error. */
3749
#define RET_OK 0
3850
#define RET_ERROR -1

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ supported on:
1818

1919
.. PYVERSIONS
2020
21-
* Python versions 3.7 through 3.11.0a5.
21+
* Python versions 3.7 through 3.11.0b1.
2222

2323
* PyPy3 7.3.8.
2424

0 commit comments

Comments
 (0)