Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 8c192c4

Browse files
author
Anselm Kruis
committed
Stackless issue #253: disable Cython hack starting with Python 3.8.0b1
Disable the support for Cython versions below 0.29. Starting with Stackless version 3.8.0b1 extension modules compiled with regular C-Python and Cython versions below 0.29 no longer work with Stackless Python.
1 parent 326ce5e commit 8c192c4

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

Include/internal/stackless_impl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ extern "C" {
3030
* This would usually be done in place with the assembly macros.
3131
*/
3232

33+
#ifndef SLP_END_OF_OLD_CYTHON_HACK_VERSION
34+
/*
35+
* If PY_VERSION_HEX < SLP_END_OF_OLD_CYTHON_VERSION_HEX support for
36+
* Cython versions prior to 0.29 (2018-10-14) is enabled.
37+
*
38+
* It is a hack for binary compatibility with Cython extension modules, which
39+
* were created with an older Cython compiled with regular C-Python.
40+
* See Stackless issue #168
41+
*/
42+
#define SLP_END_OF_OLD_CYTHON_HACK_VERSION (0x030800b1)
43+
#endif
44+
3345
/*
3446
* Macros used to extract bit-field values from an integer in a portable
3547
* way.

Objects/frameobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ frame_dealloc(PyFrameObject *f)
447447

448448
Py_TRASHCAN_SAFE_BEGIN(f)
449449

450-
#if defined(STACKLESS) && PY_VERSION_HEX < 0x03080000
450+
#if defined(STACKLESS) && PY_VERSION_HEX < SLP_END_OF_OLD_CYTHON_HACK_VERSION
451451
/* Clear the magic for the old Cython frame hack.
452452
* See below in PyFrame_New() for a detailed explanation.
453453
*/
@@ -777,7 +777,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code,
777777
PyFrameObject *f = _PyFrame_New_NoTrack(tstate, code, globals, locals);
778778
if (f) {
779779
_PyObject_GC_TRACK(f);
780-
#if defined(STACKLESS) && PY_VERSION_HEX < 0x03080000
780+
#if defined(STACKLESS) && PY_VERSION_HEX < SLP_END_OF_OLD_CYTHON_HACK_VERSION
781781
if (code->co_argcount > 0) {
782782
/*
783783
* A hack for binary compatibility with Cython extension modules, which

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
39553955
*/
39563956
f->f_execute = PyEval_EvalFrameEx_slp;
39573957

3958-
#if PY_VERSION_HEX < 0x03080000
3958+
#if PY_VERSION_HEX < SLP_END_OF_OLD_CYTHON_HACK_VERSION
39593959
/* Older versions of Cython used to create frames using C-Python layout
39603960
* of PyFrameObject. As a consequence f_code is overwritten by the first
39613961
* item of f_localsplus[]. To be able to fix it, we have a copy of

Stackless/changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://github.com/stackless-dev/stackless/issues/253
13+
Disable the support for Cython versions below 0.29.
14+
Starting with Stackless version 3.8.0b1 extension modules compiled with
15+
regular C-Python and Cython versions below 0.29 no longer work with
16+
Stackless Python.
17+
1218
- https://github.com/stackless-dev/stackless/issues/231
1319
Update Stackless related bitbucket.org URLs to github.com
1420

Stackless/module/stacklessmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,9 @@ PyInit__stackless(void)
18261826
INSERT("channel", &PyChannel_Type);
18271827
INSERT("atomic", &PyAtomic_Type);
18281828
INSERT("pickle_with_tracing_state", Py_False);
1829+
#if PY_VERSION_HEX < SLP_END_OF_OLD_CYTHON_HACK_VERSION
1830+
INSERT("_with_old_cython_hack", Py_True);
1831+
#endif
18291832

18301833
tmp = get_test_nostacklesscallobj();
18311834
if (!tmp)

Stackless/unittests/test_capi.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import glob
3535
import pickle
3636
import _teststackless
37-
3837
from support import test_main # @UnusedImport
3938
from support import (StacklessTestCase, withThreads, require_one_thread,
4039
testcase_leaks_references)
@@ -49,6 +48,12 @@
4948
else:
5049
_thread = None
5150

51+
try:
52+
from stackless._stackless import _with_old_cython_hack
53+
except ImportError:
54+
_with_old_cython_hack = False
55+
56+
5257

5358
class Test_PyEval_EvalFrameEx(StacklessTestCase):
5459
@staticmethod
@@ -169,6 +174,7 @@ def f():
169174
self.assertIn(str(exc), msg)
170175
#print(msg)
171176

177+
@unittest.skipUnless(_with_old_cython_hack, "feature not enabled at compile time")
172178
def test_oldcython_frame(self):
173179
# A test for Stackless issue #168
174180
self.assertEqual(self.call_PyEval_EvalFrameEx(47110816, oldcython=True), 47110816)
@@ -182,7 +188,8 @@ def f2(code):
182188
return code
183189

184190
self.assertIs(_teststackless.test_PyEval_EvalFrameEx(f.__code__, f.__globals__, (f.__code__,), oldcython=False), f.__code__)
185-
self.assertIs(_teststackless.test_PyEval_EvalFrameEx(f.__code__, f.__globals__, (f2.__code__,), oldcython=True), f2.__code__)
191+
if _with_old_cython_hack:
192+
self.assertIs(_teststackless.test_PyEval_EvalFrameEx(f.__code__, f.__globals__, (f2.__code__,), oldcython=True), f2.__code__)
186193

187194
@testcase_leaks_references("f->f_code get overwritten without Py_DECREF")
188195
def test_oldcython_frame_code_is_1st_arg_bad(self):

0 commit comments

Comments
 (0)