Rebased to Python 3.8.0b4

Patch 189 rebased for new setuptools/pip version.

Patch 331 added to fix clang: https://bugzilla.redhat.com/show_bug.cgi?id=1715016

importlib.metadata is now a simple module, not a folder.
This commit is contained in:
Miro Hrončok 2019-08-30 15:47:05 +02:00
parent 8f6e3122a8
commit 4352870f13
10 changed files with 282 additions and 30 deletions

View File

@ -1,4 +1,4 @@
From 8a93e612de3f9f1e1c04ca2b31f207a2ce611fe1 Mon Sep 17 00:00:00 2001
From 06e1abca862a731ab42dd4f04c232511a2ade166 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 13 Jan 2010 21:25:18 +0000
Subject: [PATCH] 00001: Fixup distutils/unixccompiler.py to remove standard

View File

@ -1,4 +1,4 @@
From ee7b218babbed91c283445021a99d4b28fc12b2f Mon Sep 17 00:00:00 2001
From 331d11692ff564f152157bffbcaaf97e4c2676d2 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 13 Jan 2010 21:25:18 +0000
Subject: [PATCH] 00102: Change the various install paths to use /usr/lib64/
@ -198,10 +198,10 @@ index 5f80738188..73d7913441 100644
return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
}
diff --git a/configure b/configure
index cb5f130d38..b30b4008f2 100755
index 3cd9b8866c..7d4cbab2c0 100755
--- a/configure
+++ b/configure
@@ -15195,9 +15195,9 @@ fi
@@ -15197,9 +15197,9 @@ fi
if test x$PLATFORM_TRIPLET = x; then
@ -214,10 +214,10 @@ index cb5f130d38..b30b4008f2 100755
diff --git a/configure.ac b/configure.ac
index b31ed242f1..42d17bc0ad 100644
index 033a93cd3f..5c8a04f61e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4663,9 +4663,9 @@ fi
@@ -4665,9 +4665,9 @@ fi
dnl define LIBPL after ABIFLAGS and LDVERSION is defined.
AC_SUBST(PY_ENABLE_SHARED)
if test x$PLATFORM_TRIPLET = x; then
@ -230,7 +230,7 @@ index b31ed242f1..42d17bc0ad 100644
AC_SUBST(LIBPL)
diff --git a/setup.py b/setup.py
index 6cbbec9e12..a5092861cf 100644
index be2ac0b01d..624274a75b 100644
--- a/setup.py
+++ b/setup.py
@@ -648,7 +648,7 @@ class PyBuildExt(build_ext):
@ -242,7 +242,7 @@ index 6cbbec9e12..a5092861cf 100644
add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
# only change this for cross builds for 3.3, issues on Mageia
if CROSS_COMPILING:
@@ -944,11 +944,11 @@ class PyBuildExt(build_ext):
@@ -946,11 +946,11 @@ class PyBuildExt(build_ext):
elif curses_library:
readline_libs.append(curses_library)
elif self.compiler.find_library_file(self.lib_dirs +

View File

@ -1,4 +1,4 @@
From 65208ffdf868d06e6e16eeb12e3f47205a738ed3 Mon Sep 17 00:00:00 2001
From 9b7b6251f0fa17d6ab9eff945b3fe43cce549f13 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 18 Jan 2010 17:59:07 +0000
Subject: [PATCH] 00111: Don't try to build a libpythonMAJOR.MINOR.a

View File

@ -1,4 +1,4 @@
From 327e040bd14b6bd05314b24e59ffcdb2179f9757 Mon Sep 17 00:00:00 2001
From b377643b13abe774c95350c4b2534eb7aa001de4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Wed, 15 Aug 2018 15:36:29 +0200
Subject: [PATCH] 00189: Instead of bundled wheels, use our RPM packaged wheels
@ -9,7 +9,7 @@ We keep them in /usr/share/python-wheels
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
index 63de20e288..4d17e413db 100644
index fc0edec6e3..4d17e413db 100644
--- a/Lib/ensurepip/__init__.py
+++ b/Lib/ensurepip/__init__.py
@@ -1,16 +1,27 @@
@ -26,9 +26,9 @@ index 63de20e288..4d17e413db 100644
+_WHEEL_DIR = "/usr/share/python-wheels/"
-_SETUPTOOLS_VERSION = "41.0.1"
-_SETUPTOOLS_VERSION = "41.2.0"
-_PIP_VERSION = "19.2.1"
-_PIP_VERSION = "19.2.3"
+def _get_most_recent_wheel_version(pkg):
+ prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
+ suffix = "-py2.py3-none-any.whl"

View File

@ -1,4 +1,4 @@
From 27348866d660c1344a1f78a6337436443e1ed19c Mon Sep 17 00:00:00 2001
From b610ba33332054763d46a43af205e3b9e6724bac Mon Sep 17 00:00:00 2001
From: Michal Cyprian <m.cyprian@gmail.com>
Date: Mon, 26 Jun 2017 16:32:56 +0200
Subject: [PATCH] 00251: Change user install location

View File

@ -1,4 +1,4 @@
From c827bec294a7fb9481a55c1f7d78e80007e38816 Mon Sep 17 00:00:00 2001
From c79add9be412d3e42e3b623e04e7071dfadf75d1 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pviktori@redhat.com>
Date: Mon, 28 Aug 2017 17:16:46 +0200
Subject: [PATCH] 00274: Upstream uses Debian-style architecture naming, change
@ -29,7 +29,7 @@ index ba37cf99e2..52a9ec6662 100755
ppc64le | powerpc64little)
basic_machine=powerpc64le-unknown
diff --git a/configure.ac b/configure.ac
index 42d17bc0ad..637a99f159 100644
index 5c8a04f61e..807e379537 100644
--- a/configure.ac
+++ b/configure.ac
@@ -741,9 +741,9 @@ cat >> conftest.c <<EOF

View File

@ -1,4 +1,4 @@
From 1df081ef9044c6b30fd75d591b6999eb62c48d9b Mon Sep 17 00:00:00 2001
From 616cc366d97f4402cc50e0338954d1c82b843027 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Thu, 11 Jul 2019 13:44:13 +0200
Subject: [PATCH] 00328: Restore pyc to TIMESTAMP invalidation mode as default

View File

@ -0,0 +1,246 @@
From 091ae930cd8bac805a083ea68e4f886200f57de0 Mon Sep 17 00:00:00 2001
From: "Miss Islington (bot)"
<31488909+miss-islington@users.noreply.github.com>
Date: Fri, 30 Aug 2019 05:50:44 -0700
Subject: [PATCH] 00331: Fix StructUnionType_paramfunc()
Fix a ctypes regression of Python 3.8. When a ctypes.Structure is
passed by copy to a function, ctypes internals created a temporary
object which had the side effect of calling the structure finalizer
(__del__) twice. The Python semantics requires a finalizer to be
called exactly once. Fix ctypes internals to no longer call the
finalizer twice.
Create a new internal StructParam_Type which is only used by
_ctypes_callproc() to call PyMem_Free(ptr) on Py_DECREF(argument).
StructUnionType_paramfunc() creates such object.
(cherry picked from commit 96b4087ce784ee7434dffdf69c475f5b40543982)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
---
Lib/ctypes/test/test_structures.py | 51 +++++++++++--
.../2019-08-30-11-21-10.bpo-37140.cFAX-a.rst | 5 ++
Modules/_ctypes/_ctypes.c | 73 +++++++++++++++----
3 files changed, 109 insertions(+), 20 deletions(-)
create mode 100644 Misc/NEWS.d/next/Library/2019-08-30-11-21-10.bpo-37140.cFAX-a.rst
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index d1ea43bc7e..fda104563d 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -3,7 +3,7 @@ from ctypes import *
from ctypes.test import need_symbol
from struct import calcsize
import _ctypes_test
-import test.support
+from test import support
class SubclassesTest(unittest.TestCase):
def test_subclass(self):
@@ -202,7 +202,7 @@ class StructureTestCase(unittest.TestCase):
"_pack_": -1}
self.assertRaises(ValueError, type(Structure), "X", (Structure,), d)
- @test.support.cpython_only
+ @support.cpython_only
def test_packed_c_limits(self):
# Issue 15989
import _testcapi
@@ -396,27 +396,66 @@ class StructureTestCase(unittest.TestCase):
self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7))
def test_pass_by_value(self):
- # This should mirror the structure in Modules/_ctypes/_ctypes_test.c
- class X(Structure):
+ # This should mirror the Test structure
+ # in Modules/_ctypes/_ctypes_test.c
+ class Test(Structure):
_fields_ = [
('first', c_ulong),
('second', c_ulong),
('third', c_ulong),
]
- s = X()
+ s = Test()
s.first = 0xdeadbeef
s.second = 0xcafebabe
s.third = 0x0bad1dea
dll = CDLL(_ctypes_test.__file__)
func = dll._testfunc_large_struct_update_value
- func.argtypes = (X,)
+ func.argtypes = (Test,)
func.restype = None
func(s)
self.assertEqual(s.first, 0xdeadbeef)
self.assertEqual(s.second, 0xcafebabe)
self.assertEqual(s.third, 0x0bad1dea)
+ def test_pass_by_value_finalizer(self):
+ # bpo-37140: Similar to test_pass_by_value(), but the Python structure
+ # has a finalizer (__del__() method): the finalizer must only be called
+ # once.
+
+ finalizer_calls = []
+
+ class Test(Structure):
+ _fields_ = [
+ ('first', c_ulong),
+ ('second', c_ulong),
+ ('third', c_ulong),
+ ]
+ def __del__(self):
+ finalizer_calls.append("called")
+
+ s = Test(1, 2, 3)
+ # Test the StructUnionType_paramfunc() code path which copies the
+ # structure: if the stucture is larger than sizeof(void*).
+ self.assertGreater(sizeof(s), sizeof(c_void_p))
+
+ dll = CDLL(_ctypes_test.__file__)
+ func = dll._testfunc_large_struct_update_value
+ func.argtypes = (Test,)
+ func.restype = None
+ func(s)
+ # bpo-37140: Passing the structure by refrence must not call
+ # its finalizer!
+ self.assertEqual(finalizer_calls, [])
+ self.assertEqual(s.first, 1)
+ self.assertEqual(s.second, 2)
+ self.assertEqual(s.third, 3)
+
+ # The finalizer must be called exactly once
+ s = None
+ support.gc_collect()
+ self.assertEqual(finalizer_calls, ["called"])
+
def test_pass_by_value_in_register(self):
class X(Structure):
_fields_ = [
diff --git a/Misc/NEWS.d/next/Library/2019-08-30-11-21-10.bpo-37140.cFAX-a.rst b/Misc/NEWS.d/next/Library/2019-08-30-11-21-10.bpo-37140.cFAX-a.rst
new file mode 100644
index 0000000000..4eaa226147
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-08-30-11-21-10.bpo-37140.cFAX-a.rst
@@ -0,0 +1,5 @@
+Fix a ctypes regression of Python 3.8. When a ctypes.Structure is passed by
+copy to a function, ctypes internals created a temporary object which had
+the side effect of calling the structure finalizer (__del__) twice. The
+Python semantics requires a finalizer to be called exactly once. Fix ctypes
+internals to no longer call the finalizer twice.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 2201c4520a..4728874006 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -392,6 +392,35 @@ _ctypes_alloc_format_string_with_shape(int ndim, const Py_ssize_t *shape,
return result;
}
+/* StructParamObject and StructParam_Type are used in _ctypes_callproc()
+ for argument.keep to call PyMem_Free(ptr) on Py_DECREF(argument).
+
+ StructUnionType_paramfunc() creates such object when a ctypes Structure is
+ passed by copy to a C function. */
+typedef struct {
+ PyObject_HEAD
+ void *ptr;
+} StructParamObject;
+
+
+static void
+StructParam_dealloc(PyObject *myself)
+{
+ StructParamObject *self = (StructParamObject *)myself;
+ PyMem_Free(self->ptr);
+ Py_TYPE(self)->tp_free(myself);
+}
+
+
+static PyTypeObject StructParam_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "_ctypes.StructParam_Type",
+ .tp_basicsize = sizeof(StructParamObject),
+ .tp_dealloc = StructParam_dealloc,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+};
+
+
/*
PyCStructType_Type - a meta type/class. Creating a new class using this one as
__metaclass__ will call the constructor StructUnionType_new. It replaces the
@@ -403,35 +432,47 @@ static PyCArgObject *
StructUnionType_paramfunc(CDataObject *self)
{
PyCArgObject *parg;
- CDataObject *copied_self;
+ PyObject *obj;
StgDictObject *stgdict;
+ void *ptr;
if ((size_t)self->b_size > sizeof(void*)) {
- void *new_ptr = PyMem_Malloc(self->b_size);
- if (new_ptr == NULL)
+ ptr = PyMem_Malloc(self->b_size);
+ if (ptr == NULL) {
return NULL;
- memcpy(new_ptr, self->b_ptr, self->b_size);
- copied_self = (CDataObject *)PyCData_AtAddress(
- (PyObject *)Py_TYPE(self), new_ptr);
- copied_self->b_needsfree = 1;
+ }
+ memcpy(ptr, self->b_ptr, self->b_size);
+
+ /* Create a Python object which calls PyMem_Free(ptr) in
+ its deallocator. The object will be destroyed
+ at _ctypes_callproc() cleanup. */
+ obj = (&StructParam_Type)->tp_alloc(&StructParam_Type, 0);
+ if (obj == NULL) {
+ PyMem_Free(ptr);
+ return NULL;
+ }
+
+ StructParamObject *struct_param = (StructParamObject *)obj;
+ struct_param->ptr = ptr;
} else {
- copied_self = self;
- Py_INCREF(copied_self);
+ ptr = self->b_ptr;
+ obj = (PyObject *)self;
+ Py_INCREF(obj);
}
parg = PyCArgObject_new();
if (parg == NULL) {
- Py_DECREF(copied_self);
+ Py_DECREF(obj);
return NULL;
}
parg->tag = 'V';
- stgdict = PyObject_stgdict((PyObject *)copied_self);
+ stgdict = PyObject_stgdict((PyObject *)self);
assert(stgdict); /* Cannot be NULL for structure/union instances */
parg->pffi_type = &stgdict->ffi_type_pointer;
- parg->value.p = copied_self->b_ptr;
- parg->size = copied_self->b_size;
- parg->obj = (PyObject *)copied_self;
+ parg->value.p = ptr;
+ parg->size = self->b_size;
+ parg->obj = obj;
return parg;
}
@@ -5700,6 +5741,10 @@ PyInit__ctypes(void)
if (PyType_Ready(&DictRemover_Type) < 0)
return NULL;
+ if (PyType_Ready(&StructParam_Type) < 0) {
+ return NULL;
+ }
+
#ifdef MS_WIN32
if (create_comerror() < 0)
return NULL;
--
2.21.0

View File

@ -14,10 +14,10 @@ URL: https://www.python.org/
# WARNING When rebasing to a new Python version,
# remember to update the python3-docs package as well
%global general_version %{pybasever}.0
%global prerel b3
%global prerel b4
%global upstream_version %{general_version}%{?prerel}
Version: %{general_version}%{?prerel:~%{prerel}}
Release: 2%{?dist}
Release: 1%{?dist}
License: Python
@ -261,6 +261,13 @@ Patch274: 00274-fix-arch-names.patch
# See https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/57#comment-27426
Patch328: 00328-pyc-timestamp-invalidation-mode.patch
# 00331 #
# Fix StructUnionType_paramfunc()
# Fix a ctypes regression of Python 3.8
# Merged upstream https://bugs.python.org/issue37140
# Fixes clang FTBFS https://bugzilla.redhat.com/show_bug.cgi?id=1715016
Patch331: 00331-fix-structuniontype_paramfunc.patch
# (New patches go here ^^^)
#
# When adding new patches to "python" and "python3" in Fedora, EL, etc.,
@ -373,8 +380,8 @@ Summary: Python runtime libraries
Requires: python-setuptools-wheel
Requires: python-pip-wheel
%else
Provides: bundled(python3-pip) = 19.2.1
Provides: bundled(python3-setuptools) = 41.0.1
Provides: bundled(python3-pip) = 19.2.3
Provides: bundled(python3-setuptools) = 41.2.0
%endif
%{?python_provide:%python_provide python3-libs}
@ -550,8 +557,8 @@ The debug runtime additionally supports debug builds of C-API extensions
Requires: python-setuptools-wheel
Requires: python-pip-wheel
%else
Provides: bundled(python3-pip) = 19.2.1
Provides: bundled(python3-setuptools) = 41.0.1
Provides: bundled(python3-pip) = 19.2.3
Provides: bundled(python3-setuptools) = 41.2.0
%endif
# The description for the flat package
@ -597,6 +604,7 @@ rm Lib/ensurepip/_bundled/*.whl
%patch251 -p1
%patch274 -p1
%patch328 -p1
%patch331 -p1
# Remove files that should be generated by the build
@ -1163,6 +1171,7 @@ CheckPython optimized
%{dynload_dir}/_socket.%{SOABI_optimized}.so
%{dynload_dir}/_sqlite3.%{SOABI_optimized}.so
%{dynload_dir}/_ssl.%{SOABI_optimized}.so
%{dynload_dir}/_statistics.%{SOABI_optimized}.so
%{dynload_dir}/_struct.%{SOABI_optimized}.so
%{dynload_dir}/array.%{SOABI_optimized}.so
%{dynload_dir}/audioop.%{SOABI_optimized}.so
@ -1239,11 +1248,6 @@ CheckPython optimized
%{pylibdir}/importlib/*.py
%{pylibdir}/importlib/__pycache__/*%{bytecode_suffixes}
%dir %{pylibdir}/importlib/metadata/
%dir %{pylibdir}/importlib/metadata/__pycache__/
%{pylibdir}/importlib/metadata/*.py
%{pylibdir}/importlib/metadata/__pycache__/*%{bytecode_suffixes}
%dir %{pylibdir}/json/
%dir %{pylibdir}/json/__pycache__/
%{pylibdir}/json/*.py
@ -1441,6 +1445,7 @@ CheckPython optimized
%{dynload_dir}/_socket.%{SOABI_debug}.so
%{dynload_dir}/_sqlite3.%{SOABI_debug}.so
%{dynload_dir}/_ssl.%{SOABI_debug}.so
%{dynload_dir}/_statistics.%{SOABI_debug}.so
%{dynload_dir}/_struct.%{SOABI_debug}.so
%{dynload_dir}/array.%{SOABI_debug}.so
%{dynload_dir}/audioop.%{SOABI_debug}.so
@ -1522,7 +1527,8 @@ CheckPython optimized
# ======================================================
%changelog
* Sat Aug 31 2019 Miro Hrončok <mhroncok@redhat.com> - 3.8.0~b3-2
* Sat Aug 31 2019 Miro Hrončok <mhroncok@redhat.com> - 3.8.0~b4-1
- Rebased to Python 3.8.0b4
- Enable Profile-guided optimization for all arches, not just x86 (#1741015)
* Mon Jul 29 2019 Miro Hrončok <mhroncok@redhat.com> - 3.8.0~b3-1

View File

@ -1 +1 @@
SHA512 (Python-3.8.0b3.tar.xz) = 5b29e580514704150b397850b5bf5f3e4b98a45d9a9f8ac0364bef51caac74862f9f349b5d3d1bbcdcc5b48b2722f1a9e5e0a9837bf44360fe74a396e915ae35
SHA512 (Python-3.8.0b4.tar.xz) = 91cf7a6988a52edbffa544f4154219864c09f0726b617c79078fe6d00f4c85255cf302a087f80a0a1697ef6d7c9547c20fe9d8901ce8d6ef553e3b36bf87dbde