cpython: fd36d72f6030 (original) (raw)

Mercurial > cpython

changeset 99669:fd36d72f6030 3.5

Issue #20440: Massive replacing unsafe attribute setting code with special macro Py_SETREF. [#20440]

Serhiy Storchaka storchaka@gmail.com
date Thu, 24 Dec 2015 10:35:59 +0200
parents 105bf5dd93b8
children c4e8751ce637 ed62cf0cf256
files Include/object.h Misc/NEWS Modules/_csv.c Modules/_ctypes/_ctypes.c Modules/_curses_panel.c Modules/_io/bytesio.c Modules/_sqlite/connection.c Modules/_sqlite/cursor.c Modules/_sre.c Modules/_ssl.c Modules/faulthandler.c Modules/itertoolsmodule.c Modules/signalmodule.c Modules/zipimport.c Modules/zlibmodule.c Objects/bytesobject.c Objects/descrobject.c Objects/exceptions.c Objects/frameobject.c Objects/funcobject.c Objects/moduleobject.c Objects/rangeobject.c Objects/typeobject.c Objects/unicodeobject.c Parser/tokenizer.c Python/_warnings.c Python/ceval.c Python/compile.c
diffstat 28 files changed, 92 insertions(+), 120 deletions(-)[+] [-] Include/object.h 26 Misc/NEWS 3 Modules/_csv.c 6 Modules/_ctypes/_ctypes.c 41 Modules/_curses_panel.c 5 Modules/_io/bytesio.c 3 Modules/_sqlite/connection.c 13 Modules/_sqlite/cursor.c 13 Modules/_sre.c 3 Modules/_ssl.c 6 Modules/faulthandler.c 9 Modules/itertoolsmodule.c 3 Modules/signalmodule.c 3 Modules/zipimport.c 3 Modules/zlibmodule.c 6 Objects/bytesobject.c 3 Objects/descrobject.c 3 Objects/exceptions.c 3 Objects/frameobject.c 3 Objects/funcobject.c 15 Objects/moduleobject.c 3 Objects/rangeobject.c 3 Objects/typeobject.c 9 Objects/unicodeobject.c 12 Parser/tokenizer.c 3 Python/_warnings.c 3 Python/ceval.c 6 Python/compile.c 3

line wrap: on

line diff

--- a/Include/object.h +++ b/Include/object.h @@ -846,6 +846,32 @@ PyAPI_FUNC(void) _Py_Dealloc(PyObject ) Py_DECREF(_py_xdecref_tmp); [](#l1.4) } while (0) +#ifndef Py_LIMITED_API +/ Safely decref op and set op to op2.

+ +#endif /* ifndef Py_LIMITED_API / + / These are provided as conveniences to Python runtime embedders, so that they can have object code that is not dependent on Python compilation flags.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: tba Core and Builtins ----------------- +- Issue #20440: Massive replacing unsafe attribute setting code with special

--- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -276,9 +276,8 @@ static int else { if (PyUnicode_READY(src) == -1) return -1;

--- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -391,8 +391,7 @@ StructUnionType_new(PyTypeObject *type, Py_DECREF((PyObject *)dict); return NULL; }

@@ -871,8 +870,7 @@ PyCPointerType_SetProto(StgDictObject *s return -1; } Py_INCREF(proto);

@@ -962,8 +960,7 @@ PyCPointerType_new(PyTypeObject *type, P Py_DECREF((PyObject *)stgdict); return NULL; }

return (PyObject *)result; } @@ -1406,8 +1403,7 @@ PyCArrayType_new(PyTypeObject type, PyO / replace the class dict by our updated spam dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) goto error;

return (PyObject *)result; } @@ -1949,8 +1944,7 @@ PyCSimpleType_new(PyTypeObject *type, Py Py_DECREF((PyObject *)stgdict); return NULL; }

/* Install from_param class methods in ctypes base classes. Overrides the PyCSimpleType_from_param generic method. @@ -2313,8 +2307,7 @@ PyCFuncPtrType_new(PyTypeObject *type, P Py_DECREF((PyObject *)stgdict); return NULL; }

if (-1 == make_funcptrtype_dict(stgdict)) { Py_DECREF(result); @@ -2458,8 +2451,7 @@ KeepRef(CDataObject *target, Py_ssize_t return -1; } if (ob->b_objects == NULL || !PyDict_CheckExact(ob->b_objects)) {

@@ -2993,9 +2984,8 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject return -1; } Py_XDECREF(self->checker);

@@ -3033,11 +3023,9 @@ PyCFuncPtr_set_argtypes(PyCFuncPtrObject converters = converters_from_argtypes(ob); if (!converters) return -1;

bself = (PyBaseExceptionObject *)self;

return 0; }

--- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -312,9 +312,8 @@ PyCursesPanel_replace_panel(PyCursesPane PyErr_SetString(_curses_panelstate_global->PyCursesError, "replace_panel() returned ERR"); return NULL; }

--- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -969,8 +969,7 @@ static int if (initvalue && initvalue != Py_None) { if (PyBytes_CheckExact(initvalue)) { Py_INCREF(initvalue);

--- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -204,8 +204,8 @@ void pysqlite_flush_statement_cache(pysq node = node->next; }

} static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) @@ -827,8 +825,7 @@ static void _pysqlite_drop_unused_cursor } }

} PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)

--- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -170,8 +170,7 @@ int pysqlite_build_row_cast_map(pysqlite return 0; }

for (i = 0; i < sqlite3_column_count(self->statement->st); i++) { converter = NULL; @@ -510,9 +509,8 @@ PyObject* _pysqlite_query_execute(pysqli goto error; /* reset description and rowcount */

@@ -654,8 +652,7 @@ PyObject* _pysqlite_query_execute(pysqli numcols = sqlite3_column_count(self->statement->st); Py_END_ALLOW_THREADS

--- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -756,8 +756,7 @@ deepcopy(PyObject** object, PyObject* me if (!copy) return 0;

return 1; /* success */ }

--- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -1589,8 +1589,7 @@ static int PySSL_set_context(PySSLSocket return -1; #else Py_INCREF(value);

#endif } else { @@ -1647,8 +1646,7 @@ PySSL_get_owner(PySSLSocket *self, void static int PySSL_set_owner(PySSLSocket *self, PyObject *value, void *c) {

--- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -380,9 +380,8 @@ faulthandler_enable(PyObject *self, PyOb if (tstate == NULL) return NULL;

--- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -636,8 +636,7 @@ tee_next(teeobject *to) link = teedataobject_jumplink(to->dataobj); if (link == NULL) return NULL;

--- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1266,8 +1266,7 @@ PyInit__signal(void) if (Handlers[SIGINT].func == DefaultHandler) { /* Install default int handler */ Py_INCREF(IntHandler);

--- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -155,8 +155,7 @@ zipimporter_init(ZipImporter *self, PyOb tmp = PyUnicode_FromFormat("%U%c", self->prefix, SEP); if (tmp == NULL) goto error;

--- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -667,8 +667,7 @@ save_unconsumed_input(compobject *self, PyBytes_AS_STRING(self->unused_data), old_size); Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size, self->zst.next_in, self->zst.avail_in);

--- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3520,8 +3520,7 @@ PyBytes_Concat(PyObject **pv, PyObject / Multiple references, need to create new object */ PyObject *v; v = bytes_concat(*pv, w);

--- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1509,8 +1509,7 @@ property_init(PyObject *self, PyObject * PyObject *get_doc = PyObject_GetAttrId(get, &PyId___doc_); if (get_doc) { if (Py_TYPE(self) == &PyProperty_Type) {

--- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -236,8 +236,7 @@ BaseException_set_tb(PyBaseExceptionObje } Py_XINCREF(tb);

--- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -857,8 +857,7 @@ dict_to_map(PyObject *map, Py_ssize_t nm } } else if (values[j] != value) { Py_XINCREF(value);

--- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -127,8 +127,7 @@ PyFunction_SetDefaults(PyObject *op, PyO PyErr_SetString(PyExc_SystemError, "non-tuple default args"); return -1; }

@@ -159,8 +158,7 @@ PyFunction_SetKwDefaults(PyObject *op, P "non-dict keyword only default args"); return -1; }

@@ -192,8 +190,7 @@ PyFunction_SetClosure(PyObject *op, PyOb closure->ob_type->tp_name); return -1; }

@@ -224,8 +221,7 @@ PyFunction_SetAnnotations(PyObject *op, "non-dict annotations"); return -1; }

@@ -531,8 +527,7 @@ func_new(PyTypeObject* type, PyObject* a if (name != Py_None) { Py_INCREF(name);

--- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -69,8 +69,7 @@ module_init_dict(PyModuleObject *mod, Py return -1; if (PyUnicode_CheckExact(name)) { Py_INCREF(name);

--- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -1066,8 +1066,7 @@ longrangeiter_next(longrangeiterobject * result = PyNumber_Add(r->start, product); Py_DECREF(product); if (result) {

--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -315,9 +315,8 @@ assign_version_tag(PyTypeObject *type) are borrowed reference */ for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) { method_cache[i].value = NULL;

@@ -462,8 +461,7 @@ type_set_qualname(PyTypeObject type, Py et = (PyHeapTypeObject)type; Py_INCREF(value);

@@ -2910,8 +2908,7 @@ PyObject * else method_cache_misses++; #endif

--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1665,8 +1665,7 @@ unicode_resize(PyObject **p_unicode, Py_ _Py_INCREF_UNICODE_EMPTY(); if (!unicode_empty) return -1;

--- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -524,9 +524,8 @@ fp_setreadl(struct tok_state *tok, const if (stream == NULL) goto cleanup;

--- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -680,8 +680,7 @@ setup_context(Py_ssize_t stack_level, Py goto handle_error; } else if (!is_true) {

--- a/Python/ceval.c +++ b/Python/ceval.c @@ -3214,8 +3214,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func);

@@ -4670,8 +4669,7 @@ call_function(PyObject ***pp_stack, int Py_INCREF(self); func = PyMethod_GET_FUNCTION(func); Py_INCREF(func);

--- a/Python/compile.c +++ b/Python/compile.c @@ -1795,8 +1795,7 @@ compiler_class(struct compiler c, stmt_ { / use the class name for name mangling */ Py_INCREF(s->v.ClassDef.name);