diff options
| author | arcadia-devtools <[email protected]> | 2022-03-18 09:10:23 +0300 |
|---|---|---|
| committer | arcadia-devtools <[email protected]> | 2022-03-18 09:10:23 +0300 |
| commit | fef2b3a8ed5955b63c71e8e541a5acf2e393925a (patch) | |
| tree | e55d2882d5c2c71561a0aa89158ec174d81f92fd /contrib/tools/python3/src/Objects | |
| parent | 2acc0fc3cdc40434ea286f2fac62386e3fd9c19d (diff) | |
intermediate changes
ref:102662f6c42fba80d7bfd4a328124cbb4294be48
Diffstat (limited to 'contrib/tools/python3/src/Objects')
| -rw-r--r-- | contrib/tools/python3/src/Objects/clinic/floatobject.c.h | 24 | ||||
| -rw-r--r-- | contrib/tools/python3/src/Objects/descrobject.c | 12 | ||||
| -rw-r--r-- | contrib/tools/python3/src/Objects/floatobject.c | 10 | ||||
| -rw-r--r-- | contrib/tools/python3/src/Objects/setobject.c | 47 | ||||
| -rw-r--r-- | contrib/tools/python3/src/Objects/typeobject.c | 29 |
5 files changed, 79 insertions, 43 deletions
diff --git a/contrib/tools/python3/src/Objects/clinic/floatobject.c.h b/contrib/tools/python3/src/Objects/clinic/floatobject.c.h index b7554832b5a..6ecdd9e66e9 100644 --- a/contrib/tools/python3/src/Objects/clinic/floatobject.c.h +++ b/contrib/tools/python3/src/Objects/clinic/floatobject.c.h @@ -289,8 +289,8 @@ exit: return return_value; } -PyDoc_STRVAR(float___set_format____doc__, -"__set_format__($type, typestr, fmt, /)\n" +PyDoc_STRVAR(float___setformat____doc__, +"__setformat__($type, typestr, fmt, /)\n" "--\n" "\n" "You probably don\'t want to use this function.\n" @@ -307,25 +307,25 @@ PyDoc_STRVAR(float___set_format____doc__, "Override the automatic determination of C-level floating point type.\n" "This affects how floats are converted to and from binary strings."); -#define FLOAT___SET_FORMAT___METHODDEF \ - {"__set_format__", (PyCFunction)(void(*)(void))float___set_format__, METH_FASTCALL|METH_CLASS, float___set_format____doc__}, +#define FLOAT___SETFORMAT___METHODDEF \ + {"__setformat__", (PyCFunction)(void(*)(void))float___setformat__, METH_FASTCALL|METH_CLASS, float___setformat____doc__}, static PyObject * -float___set_format___impl(PyTypeObject *type, const char *typestr, - const char *fmt); +float___setformat___impl(PyTypeObject *type, const char *typestr, + const char *fmt); static PyObject * -float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs) +float___setformat__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; const char *typestr; const char *fmt; - if (!_PyArg_CheckPositional("__set_format__", nargs, 2, 2)) { + if (!_PyArg_CheckPositional("__setformat__", nargs, 2, 2)) { goto exit; } if (!PyUnicode_Check(args[0])) { - _PyArg_BadArgument("__set_format__", "argument 1", "str", args[0]); + _PyArg_BadArgument("__setformat__", "argument 1", "str", args[0]); goto exit; } Py_ssize_t typestr_length; @@ -338,7 +338,7 @@ float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs goto exit; } if (!PyUnicode_Check(args[1])) { - _PyArg_BadArgument("__set_format__", "argument 2", "str", args[1]); + _PyArg_BadArgument("__setformat__", "argument 2", "str", args[1]); goto exit; } Py_ssize_t fmt_length; @@ -350,7 +350,7 @@ float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } - return_value = float___set_format___impl(type, typestr, fmt); + return_value = float___setformat___impl(type, typestr, fmt); exit: return return_value; @@ -387,4 +387,4 @@ float___format__(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=25fbbe253f44e2df input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a6af179ec5f83fba input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/src/Objects/descrobject.c b/contrib/tools/python3/src/Objects/descrobject.c index 075a92d4084..00349ab1791 100644 --- a/contrib/tools/python3/src/Objects/descrobject.c +++ b/contrib/tools/python3/src/Objects/descrobject.c @@ -1134,11 +1134,11 @@ static PyMethodDef mappingproxy_methods[] = { PyDoc_STR("D.get(k[,d]) -> D[k] if k in D, else d." " d defaults to None.")}, {"keys", (PyCFunction)mappingproxy_keys, METH_NOARGS, - PyDoc_STR("D.keys() -> list of D's keys")}, + PyDoc_STR("D.keys() -> a set-like object providing a view on D's keys")}, {"values", (PyCFunction)mappingproxy_values, METH_NOARGS, - PyDoc_STR("D.values() -> list of D's values")}, + PyDoc_STR("D.values() -> an object providing a view on D's values")}, {"items", (PyCFunction)mappingproxy_items, METH_NOARGS, - PyDoc_STR("D.items() -> list of D's (key, value) pairs, as 2-tuples")}, + PyDoc_STR("D.items() -> a set-like object providing a view on D's items")}, {"copy", (PyCFunction)mappingproxy_copy, METH_NOARGS, PyDoc_STR("D.copy() -> a shallow copy of D")}, {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, @@ -1508,7 +1508,7 @@ static PyMemberDef property_members[] = { PyDoc_STRVAR(getter_doc, - "Descriptor to change the getter on a property."); + "Descriptor to obtain a copy of the property with a different getter."); static PyObject * property_getter(PyObject *self, PyObject *getter) @@ -1518,7 +1518,7 @@ property_getter(PyObject *self, PyObject *getter) PyDoc_STRVAR(setter_doc, - "Descriptor to change the setter on a property."); + "Descriptor to obtain a copy of the property with a different setter."); static PyObject * property_setter(PyObject *self, PyObject *setter) @@ -1528,7 +1528,7 @@ property_setter(PyObject *self, PyObject *setter) PyDoc_STRVAR(deleter_doc, - "Descriptor to change the deleter on a property."); + "Descriptor to obtain a copy of the property with a different deleter."); static PyObject * property_deleter(PyObject *self, PyObject *deleter) diff --git a/contrib/tools/python3/src/Objects/floatobject.c b/contrib/tools/python3/src/Objects/floatobject.c index 8538a051b19..6ac6127ae51 100644 --- a/contrib/tools/python3/src/Objects/floatobject.c +++ b/contrib/tools/python3/src/Objects/floatobject.c @@ -1702,7 +1702,7 @@ float___getformat___impl(PyTypeObject *type, const char *typestr) /*[clinic input] @classmethod -float.__set_format__ +float.__setformat__ typestr: str Must be 'double' or 'float'. @@ -1721,9 +1721,9 @@ This affects how floats are converted to and from binary strings. [clinic start generated code]*/ static PyObject * -float___set_format___impl(PyTypeObject *type, const char *typestr, - const char *fmt) -/*[clinic end generated code: output=504460f5dc85acbd input=5306fa2b81a997e4]*/ +float___setformat___impl(PyTypeObject *type, const char *typestr, + const char *fmt) +/*[clinic end generated code: output=06864de1fb5f1f04 input=c0e9e04dd87f9988]*/ { float_format_type f; float_format_type detected; @@ -1825,7 +1825,7 @@ static PyMethodDef float_methods[] = { FLOAT_IS_INTEGER_METHODDEF FLOAT___GETNEWARGS___METHODDEF FLOAT___GETFORMAT___METHODDEF - FLOAT___SET_FORMAT___METHODDEF + FLOAT___SETFORMAT___METHODDEF FLOAT___FORMAT___METHODDEF {NULL, NULL} /* sentinel */ }; diff --git a/contrib/tools/python3/src/Objects/setobject.c b/contrib/tools/python3/src/Objects/setobject.c index 4bd5777f967..6d156bd4e08 100644 --- a/contrib/tools/python3/src/Objects/setobject.c +++ b/contrib/tools/python3/src/Objects/setobject.c @@ -1207,17 +1207,21 @@ set_intersection(PySetObject *so, PyObject *other) while (set_next((PySetObject *)other, &pos, &entry)) { key = entry->key; hash = entry->hash; + Py_INCREF(key); rv = set_contains_entry(so, key, hash); if (rv < 0) { Py_DECREF(result); + Py_DECREF(key); return NULL; } if (rv) { if (set_add_entry(result, key, hash)) { Py_DECREF(result); + Py_DECREF(key); return NULL; } } + Py_DECREF(key); } return (PyObject *)result; } @@ -1357,11 +1361,16 @@ set_isdisjoint(PySetObject *so, PyObject *other) other = tmp; } while (set_next((PySetObject *)other, &pos, &entry)) { - rv = set_contains_entry(so, entry->key, entry->hash); - if (rv < 0) + PyObject *key = entry->key; + Py_INCREF(key); + rv = set_contains_entry(so, key, entry->hash); + Py_DECREF(key); + if (rv < 0) { return NULL; - if (rv) + } + if (rv) { Py_RETURN_FALSE; + } } Py_RETURN_TRUE; } @@ -1420,11 +1429,16 @@ set_difference_update_internal(PySetObject *so, PyObject *other) Py_INCREF(other); } - while (set_next((PySetObject *)other, &pos, &entry)) - if (set_discard_entry(so, entry->key, entry->hash) < 0) { + while (set_next((PySetObject *)other, &pos, &entry)) { + PyObject *key = entry->key; + Py_INCREF(key); + if (set_discard_entry(so, key, entry->hash) < 0) { Py_DECREF(other); + Py_DECREF(key); return -1; } + Py_DECREF(key); + } Py_DECREF(other); } else { @@ -1515,17 +1529,21 @@ set_difference(PySetObject *so, PyObject *other) while (set_next(so, &pos, &entry)) { key = entry->key; hash = entry->hash; + Py_INCREF(key); rv = _PyDict_Contains(other, key, hash); if (rv < 0) { Py_DECREF(result); + Py_DECREF(key); return NULL; } if (!rv) { if (set_add_entry((PySetObject *)result, key, hash)) { Py_DECREF(result); + Py_DECREF(key); return NULL; } } + Py_DECREF(key); } return result; } @@ -1534,17 +1552,21 @@ set_difference(PySetObject *so, PyObject *other) while (set_next(so, &pos, &entry)) { key = entry->key; hash = entry->hash; + Py_INCREF(key); rv = set_contains_entry((PySetObject *)other, key, hash); if (rv < 0) { Py_DECREF(result); + Py_DECREF(key); return NULL; } if (!rv) { if (set_add_entry((PySetObject *)result, key, hash)) { Py_DECREF(result); + Py_DECREF(key); return NULL; } } + Py_DECREF(key); } return result; } @@ -1641,17 +1663,21 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other) while (set_next(otherset, &pos, &entry)) { key = entry->key; hash = entry->hash; + Py_INCREF(key); rv = set_discard_entry(so, key, hash); if (rv < 0) { Py_DECREF(otherset); + Py_DECREF(key); return NULL; } if (rv == DISCARD_NOTFOUND) { if (set_add_entry(so, key, hash)) { Py_DECREF(otherset); + Py_DECREF(key); return NULL; } } + Py_DECREF(key); } Py_DECREF(otherset); Py_RETURN_NONE; @@ -1726,11 +1752,16 @@ set_issubset(PySetObject *so, PyObject *other) Py_RETURN_FALSE; while (set_next(so, &pos, &entry)) { - rv = set_contains_entry((PySetObject *)other, entry->key, entry->hash); - if (rv < 0) + PyObject *key = entry->key; + Py_INCREF(key); + rv = set_contains_entry((PySetObject *)other, key, entry->hash); + Py_DECREF(key); + if (rv < 0) { return NULL; - if (!rv) + } + if (!rv) { Py_RETURN_FALSE; + } } Py_RETURN_TRUE; } diff --git a/contrib/tools/python3/src/Objects/typeobject.c b/contrib/tools/python3/src/Objects/typeobject.c index 1cdf80bfcf5..cb0bb46145c 100644 --- a/contrib/tools/python3/src/Objects/typeobject.c +++ b/contrib/tools/python3/src/Objects/typeobject.c @@ -5622,24 +5622,29 @@ PyType_Ready(PyTypeObject *type) static int add_subclass(PyTypeObject *base, PyTypeObject *type) { - int result = -1; - PyObject *dict, *key, *newobj; + PyObject *key = PyLong_FromVoidPtr((void *) type); + if (key == NULL) + return -1; - dict = base->tp_subclasses; + PyObject *ref = PyWeakref_NewRef((PyObject *)type, NULL); + if (ref == NULL) { + Py_DECREF(key); + return -1; + } + + // Only get tp_subclasses after creating the key and value. + // PyWeakref_NewRef() can trigger a garbage collection which can execute + // arbitrary Python code and so modify base->tp_subclasses. + PyObject *dict = base->tp_subclasses; if (dict == NULL) { base->tp_subclasses = dict = PyDict_New(); if (dict == NULL) return -1; } assert(PyDict_CheckExact(dict)); - key = PyLong_FromVoidPtr((void *) type); - if (key == NULL) - return -1; - newobj = PyWeakref_NewRef((PyObject *)type, NULL); - if (newobj != NULL) { - result = PyDict_SetItem(dict, key, newobj); - Py_DECREF(newobj); - } + + int result = PyDict_SetItem(dict, key, ref); + Py_DECREF(ref); Py_DECREF(key); return result; } @@ -7231,7 +7236,7 @@ static slotdef slotdefs[] = { UNSLOT("__abs__", nb_absolute, slot_nb_absolute, wrap_unaryfunc, "abs(self)"), UNSLOT("__bool__", nb_bool, slot_nb_bool, wrap_inquirypred, - "self != 0"), + "True if self else False"), UNSLOT("__invert__", nb_invert, slot_nb_invert, wrap_unaryfunc, "~self"), BINSLOT("__lshift__", nb_lshift, slot_nb_lshift, "<<"), RBINSLOT("__rlshift__", nb_lshift, slot_nb_lshift, "<<"), |
