From 846f291940f5219febe16ae70650b4fb0a920fc6 Mon Sep 17 00:00:00 2001 From: hai shi Date: Thu, 18 Jul 2019 20:19:22 +0800 Subject: [PATCH 1/6] Deleteing PyCField_new function --- Lib/ctypes/test/test_struct_fields.py | 6 ++++++ Modules/_ctypes/cfield.c | 11 ++--------- Modules/_ctypes/stgdict.c | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Lib/ctypes/test/test_struct_fields.py b/Lib/ctypes/test/test_struct_fields.py index 8045cc82679cc1..5bf5971baf1213 100644 --- a/Lib/ctypes/test/test_struct_fields.py +++ b/Lib/ctypes/test/test_struct_fields.py @@ -46,6 +46,12 @@ class Y(X): Y._fields_ = [] self.assertRaises(AttributeError, setattr, X, "_fields_", []) + def test_5(self): + class X(Structure): + _fields_ = [("x", c_int)] + CField = type(X.x) + self.assertRaises(TypeError, CField) + # __set__ and __get__ should raise a TypeError in case their self # argument is not a ctype instance. def test___set__(self): diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index e0a50fde6a07a3..71dadc3a7bde08 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -22,13 +22,6 @@ static void pymem_destructor(PyObject *ptr) /* PyCField_Type */ -static PyObject * -PyCField_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - CFieldObject *obj; - obj = (CFieldObject *)type->tp_alloc(type, 0); - return (PyObject *)obj; -} /* * Expects the size, index and offset for the current field in *psize and @@ -60,7 +53,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index, #define CONT_BITFIELD 2 #define EXPAND_BITFIELD 3 - self = (CFieldObject *)_PyObject_CallNoArg((PyObject *)&PyCField_Type); + self = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0); if (self == NULL) return NULL; dict = PyType_stgdict(desc); @@ -336,7 +329,7 @@ PyTypeObject PyCField_Type = { 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - PyCField_new, /* tp_new */ + 0, /* tp_new */ 0, /* tp_free */ }; diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 235a4d79ad2ca1..cf37ef5e69a03a 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -248,7 +248,7 @@ MakeFields(PyObject *type, CFieldObject *descr, } continue; } - new_descr = (CFieldObject *)_PyObject_CallNoArg((PyObject *)&PyCField_Type); + new_descr = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0); if (new_descr == NULL) { Py_DECREF(fdescr); Py_DECREF(fieldlist); From 04fe03720fbcd06fa5eac44993039a0bed604b49 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 18 Jul 2019 12:31:51 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst b/Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst new file mode 100644 index 00000000000000..514bfcd865b827 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst @@ -0,0 +1 @@ +Remove the ``PyCField_new`` which user cannot call it directly. \ No newline at end of file From 88199f45fa581a83e7228f3d09eca515e76730b6 Mon Sep 17 00:00:00 2001 From: hai shi Date: Thu, 18 Jul 2019 20:48:24 +0800 Subject: [PATCH 3/6] fix whitespace --- Lib/ctypes/test/test_struct_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ctypes/test/test_struct_fields.py b/Lib/ctypes/test/test_struct_fields.py index 5bf5971baf1213..be6e40d2fc6248 100644 --- a/Lib/ctypes/test/test_struct_fields.py +++ b/Lib/ctypes/test/test_struct_fields.py @@ -48,7 +48,7 @@ class Y(X): def test_5(self): class X(Structure): - _fields_ = [("x", c_int)] + _fields_ = [("x", c_int)] CField = type(X.x) self.assertRaises(TypeError, CField) From b1709fdf190bc53f177235eec68b32f026e92e60 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Sun, 18 Dec 2022 18:57:47 +0800 Subject: [PATCH 4/6] resolve conflict --- Lib/test/test_ctypes/test_struct_fields.py | 12 ++++++------ .../2019-07-18-12-31-49.bpo-34697.XemM5T.rst | 1 - .../2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst | 1 + Modules/_ctypes/cfield.c | 4 ---- Modules/_ctypes/stgdict.c | 4 ---- 5 files changed, 7 insertions(+), 15 deletions(-) delete mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst diff --git a/Lib/test/test_ctypes/test_struct_fields.py b/Lib/test/test_ctypes/test_struct_fields.py index d9c704ca37f22f..e444f5e1f77919 100644 --- a/Lib/test/test_ctypes/test_struct_fields.py +++ b/Lib/test/test_ctypes/test_struct_fields.py @@ -48,17 +48,17 @@ class Y(X): def test_5(self): class X(Structure): -<<<<<<< HEAD:Lib/ctypes/test/test_struct_fields.py - _fields_ = [("x", c_int)] - CField = type(X.x) - self.assertRaises(TypeError, CField) -======= _fields_ = (("char", c_char * 5),) x = X(b'#' * 5) x.char = b'a\0b\0' self.assertEqual(bytes(x), b'a\x00###') ->>>>>>> origin/main:Lib/test/test_ctypes/test_struct_fields.py + + def test_6(self): + class X(Structure): + _fields_ = [("x", c_int)] + CField = type(X.x) + self.assertRaises(TypeError, CField) def test_gh99275(self): class BrokenStructure(Structure): diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst b/Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst deleted file mode 100644 index 514bfcd865b827..00000000000000 --- a/Misc/NEWS.d/next/Core and Builtins/2019-07-18-12-31-49.bpo-34697.XemM5T.rst +++ /dev/null @@ -1 +0,0 @@ -Remove the ``PyCField_new`` which user cannot call it directly. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst new file mode 100644 index 00000000000000..d4040423d38a6d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst @@ -0,0 +1 @@ +Remove the ``PyCField_new`` which user cannot call it directly. diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index d0c9e0f4be2e6d..796a1bec966de1 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -61,11 +61,7 @@ PyCField_FromDesc(PyObject *desc, Py_ssize_t index, #define CONT_BITFIELD 2 #define EXPAND_BITFIELD 3 -<<<<<<< HEAD self = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0); -======= - self = (CFieldObject *)_PyObject_CallNoArgs((PyObject *)&PyCField_Type); ->>>>>>> origin/main if (self == NULL) return NULL; dict = PyType_stgdict(desc); diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 9a9f0d8eff3d68..9a4041fb25280e 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -257,11 +257,7 @@ MakeFields(PyObject *type, CFieldObject *descr, } continue; } -<<<<<<< HEAD new_descr = (CFieldObject *)PyCField_Type.tp_alloc((PyTypeObject *)&PyCField_Type, 0); -======= - new_descr = (CFieldObject *)_PyObject_CallNoArgs((PyObject *)&PyCField_Type); ->>>>>>> origin/main if (new_descr == NULL) { Py_DECREF(fdescr); Py_DECREF(fieldlist); From e1b34150c170abcd20baa5e3760c04642421cb54 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Mon, 19 Dec 2022 20:48:30 +0800 Subject: [PATCH 5/6] Update News --- .../2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst | 1 - .../2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst deleted file mode 100644 index d4040423d38a6d..00000000000000 --- a/Misc/NEWS.d/next/Core and Builtins/2022-12-18-19-07-29.gh-issue-78878.00QOp1.rst +++ /dev/null @@ -1 +0,0 @@ -Remove the ``PyCField_new`` which user cannot call it directly. diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst new file mode 100644 index 00000000000000..8b455fd2ef7ff0 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst @@ -0,0 +1 @@ +Fix crash when creating an instance of :class:`!_ctypes.CField`. From a53a5704fa401e17afd70b5771e0039f4657e430 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Mon, 19 Dec 2022 20:54:48 +0800 Subject: [PATCH 6/6] update News --- .../2022-12-19-20-54-04.gh-issue-78878.JrkYqJ.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst => Library/2022-12-19-20-54-04.gh-issue-78878.JrkYqJ.rst} (100%) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst b/Misc/NEWS.d/next/Library/2022-12-19-20-54-04.gh-issue-78878.JrkYqJ.rst similarity index 100% rename from Misc/NEWS.d/next/Core and Builtins/2022-12-19-20-47-55.gh-issue-78878.JrkYqJ.rst rename to Misc/NEWS.d/next/Library/2022-12-19-20-54-04.gh-issue-78878.JrkYqJ.rst pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy