mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #24731: Fixed crash on converting objects with special methods
__bytes__, __trunc__, and __float__ returning instances of subclasses of bytes, int, and float to subclasses of bytes, int, and float correspondingly.
This commit is contained in:
commit
f9afda57ad
8 changed files with 50 additions and 10 deletions
|
@ -3146,7 +3146,7 @@ static PyNumberMethods bytes_as_number = {
|
|||
};
|
||||
|
||||
static PyObject *
|
||||
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
bytes_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject *
|
||||
bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
|
@ -3161,7 +3161,7 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
_Py_IDENTIFIER(__bytes__);
|
||||
|
||||
if (type != &PyBytes_Type)
|
||||
return str_subtype_new(type, args, kwds);
|
||||
return bytes_subtype_new(type, args, kwds);
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:bytes", kwlist, &x,
|
||||
&encoding, &errors))
|
||||
return NULL;
|
||||
|
@ -3388,7 +3388,7 @@ PyBytes_FromObject(PyObject *x)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
bytes_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *tmp, *pnew;
|
||||
Py_ssize_t n;
|
||||
|
@ -3397,7 +3397,7 @@ str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
tmp = bytes_new(&PyBytes_Type, args, kwds);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
assert(PyBytes_CheckExact(tmp));
|
||||
assert(PyBytes_Check(tmp));
|
||||
n = PyBytes_GET_SIZE(tmp);
|
||||
pnew = type->tp_alloc(type, n);
|
||||
if (pnew != NULL) {
|
||||
|
|
|
@ -1568,7 +1568,7 @@ float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
tmp = float_new(&PyFloat_Type, args, kwds);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
assert(PyFloat_CheckExact(tmp));
|
||||
assert(PyFloat_Check(tmp));
|
||||
newobj = type->tp_alloc(type, 0);
|
||||
if (newobj == NULL) {
|
||||
Py_DECREF(tmp);
|
||||
|
|
|
@ -4611,7 +4611,7 @@ long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
tmp = (PyLongObject *)long_new(&PyLong_Type, args, kwds);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
assert(PyLong_CheckExact(tmp));
|
||||
assert(PyLong_Check(tmp));
|
||||
n = Py_SIZE(tmp);
|
||||
if (n < 0)
|
||||
n = -n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue