mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #20440: Applied yet one patch for using Py_SETREF.
The patch is automatically generated, it replaces the code that uses Py_CLEAR.
This commit is contained in:
		
							parent
							
								
									a5892abf23
								
							
						
					
					
						commit
						4a1e70fc31
					
				
					 11 changed files with 63 additions and 106 deletions
				
			
		|  | @ -540,9 +540,8 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length) | |||
|     if (d->eof) { | ||||
|         d->needs_input = 0; | ||||
|         if (d->bzs_avail_in_real > 0) { | ||||
|             Py_CLEAR(d->unused_data); | ||||
|             d->unused_data = PyBytes_FromStringAndSize( | ||||
|                 bzs->next_in, d->bzs_avail_in_real); | ||||
|             Py_SETREF(d->unused_data, | ||||
|                       PyBytes_FromStringAndSize(bzs->next_in, d->bzs_avail_in_real)); | ||||
|             if (d->unused_data == NULL) | ||||
|                 goto error; | ||||
|         } | ||||
|  |  | |||
|  | @ -1196,8 +1196,7 @@ _buffered_readline(buffered *self, Py_ssize_t limit) | |||
|         Py_CLEAR(res); | ||||
|         goto end; | ||||
|     } | ||||
|     Py_CLEAR(res); | ||||
|     res = _PyBytes_Join(_PyIO_empty_bytes, chunks); | ||||
|     Py_SETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks)); | ||||
| 
 | ||||
| end: | ||||
|     LEAVE_BUFFERED(self) | ||||
|  | @ -1452,9 +1451,8 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw, | |||
|     if (_PyIOBase_check_readable(raw, Py_True) == NULL) | ||||
|         return -1; | ||||
| 
 | ||||
|     Py_CLEAR(self->raw); | ||||
|     Py_INCREF(raw); | ||||
|     self->raw = raw; | ||||
|     Py_SETREF(self->raw, raw); | ||||
|     self->buffer_size = buffer_size; | ||||
|     self->readable = 1; | ||||
|     self->writable = 0; | ||||
|  | @ -1805,9 +1803,8 @@ _io_BufferedWriter___init___impl(buffered *self, PyObject *raw, | |||
|     if (_PyIOBase_check_writable(raw, Py_True) == NULL) | ||||
|         return -1; | ||||
| 
 | ||||
|     Py_CLEAR(self->raw); | ||||
|     Py_INCREF(raw); | ||||
|     self->raw = raw; | ||||
|     Py_SETREF(self->raw, raw); | ||||
|     self->readable = 0; | ||||
|     self->writable = 1; | ||||
| 
 | ||||
|  | @ -2309,9 +2306,8 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw, | |||
|     if (_PyIOBase_check_writable(raw, Py_True) == NULL) | ||||
|         return -1; | ||||
| 
 | ||||
|     Py_CLEAR(self->raw); | ||||
|     Py_INCREF(raw); | ||||
|     self->raw = raw; | ||||
|     Py_SETREF(self->raw, raw); | ||||
|     self->buffer_size = buffer_size; | ||||
|     self->readable = 1; | ||||
|     self->writable = 1; | ||||
|  |  | |||
|  | @ -995,8 +995,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, | |||
|                 "Oi", self->decoder, (int)self->readtranslate); | ||||
|             if (incrementalDecoder == NULL) | ||||
|                 goto error; | ||||
|             Py_CLEAR(self->decoder); | ||||
|             self->decoder = incrementalDecoder; | ||||
|             Py_SETREF(self->decoder, incrementalDecoder); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -1374,8 +1373,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) | |||
| static void | ||||
| textiowrapper_set_decoded_chars(textio *self, PyObject *chars) | ||||
| { | ||||
|     Py_CLEAR(self->decoded_chars); | ||||
|     self->decoded_chars = chars; | ||||
|     Py_SETREF(self->decoded_chars, chars); | ||||
|     self->decoded_chars_used = 0; | ||||
| } | ||||
| 
 | ||||
|  | @ -1523,8 +1521,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint) | |||
|             dec_buffer = NULL; /* Reference lost to PyBytes_Concat */ | ||||
|             goto fail; | ||||
|         } | ||||
|         Py_CLEAR(self->snapshot); | ||||
|         self->snapshot = Py_BuildValue("NN", dec_flags, next_input); | ||||
|         Py_SETREF(self->snapshot, Py_BuildValue("NN", dec_flags, next_input)); | ||||
|     } | ||||
|     Py_DECREF(input_chunk); | ||||
| 
 | ||||
|  | @ -1630,8 +1627,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n) | |||
|         if (chunks != NULL) { | ||||
|             if (result != NULL && PyList_Append(chunks, result) < 0) | ||||
|                 goto fail; | ||||
|             Py_CLEAR(result); | ||||
|             result = PyUnicode_Join(_PyIO_empty_str, chunks); | ||||
|             Py_SETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks)); | ||||
|             if (result == NULL) | ||||
|                 goto fail; | ||||
|             Py_CLEAR(chunks); | ||||
|  |  | |||
|  | @ -1011,9 +1011,8 @@ decompress(Decompressor *d, uint8_t *data, size_t len, Py_ssize_t max_length) | |||
|     if (d->eof) { | ||||
|         d->needs_input = 0; | ||||
|         if (lzs->avail_in > 0) { | ||||
|             Py_CLEAR(d->unused_data); | ||||
|             d->unused_data = PyBytes_FromStringAndSize( | ||||
|                 (char *)lzs->next_in, lzs->avail_in); | ||||
|             Py_SETREF(d->unused_data, | ||||
|                       PyBytes_FromStringAndSize((char *)lzs->next_in, lzs->avail_in)); | ||||
|             if (d->unused_data == NULL) | ||||
|                 goto error; | ||||
|         } | ||||
|  |  | |||
|  | @ -846,9 +846,8 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value) | |||
| static int | ||||
| _Pickler_ClearBuffer(PicklerObject *self) | ||||
| { | ||||
|     Py_CLEAR(self->output_buffer); | ||||
|     self->output_buffer = | ||||
|         PyBytes_FromStringAndSize(NULL, self->max_output_len); | ||||
|     Py_SETREF(self->output_buffer, | ||||
|               PyBytes_FromStringAndSize(NULL, self->max_output_len)); | ||||
|     if (self->output_buffer == NULL) | ||||
|         return -1; | ||||
|     self->output_len = 0; | ||||
|  | @ -3089,9 +3088,8 @@ fix_imports(PyObject **module_name, PyObject **global_name) | |||
|                          Py_TYPE(item)->tp_name); | ||||
|             return -1; | ||||
|         } | ||||
|         Py_CLEAR(*module_name); | ||||
|         Py_INCREF(item); | ||||
|         *module_name = item; | ||||
|         Py_SETREF(*module_name, item); | ||||
|     } | ||||
|     else if (PyErr_Occurred()) { | ||||
|         return -1; | ||||
|  |  | |||
|  | @ -1437,8 +1437,7 @@ s_init(PyObject *self, PyObject *args, PyObject *kwds) | |||
|         return -1; | ||||
|     } | ||||
| 
 | ||||
|     Py_CLEAR(soself->s_format); | ||||
|     soself->s_format = o_format; | ||||
|     Py_SETREF(soself->s_format, o_format); | ||||
| 
 | ||||
|     ret = prepare_s(soself); | ||||
|     return ret; | ||||
|  |  | |||
|  | @ -793,8 +793,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx, | |||
|                               ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0); | ||||
|     if (r == NULL) { | ||||
|         /* recover the original pending buffer */ | ||||
|         Py_CLEAR(ctx->pending); | ||||
|         ctx->pending = origpending; | ||||
|         Py_SETREF(ctx->pending, origpending); | ||||
|         origpending = NULL; | ||||
|         goto errorexit; | ||||
|     } | ||||
|  |  | |||
|  | @ -159,15 +159,12 @@ groupby_setstate(groupbyobject *lz, PyObject *state) | |||
|     PyObject *currkey, *currvalue, *tgtkey; | ||||
|     if (!PyArg_ParseTuple(state, "OOO", &currkey, &currvalue, &tgtkey)) | ||||
|         return NULL; | ||||
|     Py_CLEAR(lz->currkey); | ||||
|     lz->currkey = currkey; | ||||
|     Py_INCREF(lz->currkey); | ||||
|     Py_CLEAR(lz->currvalue); | ||||
|     lz->currvalue = currvalue; | ||||
|     Py_INCREF(lz->currvalue); | ||||
|     Py_CLEAR(lz->tgtkey); | ||||
|     lz->tgtkey = tgtkey; | ||||
|     Py_INCREF(lz->tgtkey); | ||||
|     Py_INCREF(currkey); | ||||
|     Py_SETREF(lz->currkey, currkey); | ||||
|     Py_INCREF(currvalue); | ||||
|     Py_SETREF(lz->currvalue, currvalue); | ||||
|     Py_INCREF(tgtkey); | ||||
|     Py_SETREF(lz->tgtkey, tgtkey); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -747,9 +744,8 @@ tee_setstate(teeobject *to, PyObject *state) | |||
|         PyErr_SetString(PyExc_ValueError, "Index out of range"); | ||||
|         return NULL; | ||||
|     } | ||||
|     Py_CLEAR(to->dataobj); | ||||
|     to->dataobj = tdo; | ||||
|     Py_INCREF(to->dataobj); | ||||
|     Py_INCREF(tdo); | ||||
|     Py_SETREF(to->dataobj, tdo); | ||||
|     to->index = index; | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
|  | @ -974,9 +970,8 @@ cycle_setstate(cycleobject *lz, PyObject *state) | |||
|     int firstpass; | ||||
|     if (!PyArg_ParseTuple(state, "Oi", &saved, &firstpass)) | ||||
|         return NULL; | ||||
|     Py_CLEAR(lz->saved); | ||||
|     lz->saved = saved; | ||||
|     Py_XINCREF(lz->saved); | ||||
|     Py_XINCREF(saved); | ||||
|     Py_SETREF(lz->saved, saved); | ||||
|     lz->firstpass = firstpass != 0; | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
|  | @ -1901,12 +1896,10 @@ chain_setstate(chainobject *lz, PyObject *state) | |||
|     if (! PyArg_ParseTuple(state, "O|O", &source, &active)) | ||||
|         return NULL; | ||||
| 
 | ||||
|     Py_CLEAR(lz->source); | ||||
|     lz->source = source; | ||||
|     Py_INCREF(lz->source); | ||||
|     Py_CLEAR(lz->active); | ||||
|     lz->active = active; | ||||
|     Py_XINCREF(lz->active); | ||||
|     Py_INCREF(source); | ||||
|     Py_SETREF(lz->source, source); | ||||
|     Py_XINCREF(active); | ||||
|     Py_SETREF(lz->active, active); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -2262,8 +2255,7 @@ product_setstate(productobject *lz, PyObject *state) | |||
|         Py_INCREF(element); | ||||
|         PyTuple_SET_ITEM(result, i, element); | ||||
|     } | ||||
|     Py_CLEAR(lz->result); | ||||
|     lz->result = result; | ||||
|     Py_SETREF(lz->result, result); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -2585,8 +2577,7 @@ combinations_setstate(combinationsobject *lz, PyObject *state) | |||
|         PyTuple_SET_ITEM(result, i, element); | ||||
|     } | ||||
| 
 | ||||
|     Py_CLEAR(lz->result); | ||||
|     lz->result = result; | ||||
|     Py_SETREF(lz->result, result); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -2916,8 +2907,7 @@ cwr_setstate(cwrobject *lz, PyObject *state) | |||
|         Py_INCREF(element); | ||||
|         PyTuple_SET_ITEM(result, i, element); | ||||
|     } | ||||
|     Py_CLEAR(lz->result); | ||||
|     lz->result = result; | ||||
|     Py_SETREF(lz->result, result); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -3310,8 +3300,7 @@ permutations_setstate(permutationsobject *po, PyObject *state) | |||
|         Py_INCREF(element); | ||||
|         PyTuple_SET_ITEM(result, i, element); | ||||
|     } | ||||
|     Py_CLEAR(po->result); | ||||
|     po->result = result; | ||||
|     Py_SETREF(po->result, result); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -3481,9 +3470,8 @@ accumulate_reduce(accumulateobject *lz) | |||
| static PyObject * | ||||
| accumulate_setstate(accumulateobject *lz, PyObject *state) | ||||
| { | ||||
|     Py_CLEAR(lz->total); | ||||
|     lz->total = state; | ||||
|     Py_INCREF(lz->total); | ||||
|     Py_INCREF(state); | ||||
|     Py_SETREF(lz->total, state); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  | @ -4464,9 +4452,8 @@ zip_longest_reduce(ziplongestobject *lz) | |||
| static PyObject * | ||||
| zip_longest_setstate(ziplongestobject *lz, PyObject *state) | ||||
| { | ||||
|     Py_CLEAR(lz->fillvalue); | ||||
|     lz->fillvalue = state; | ||||
|     Py_INCREF(lz->fillvalue); | ||||
|     Py_INCREF(state); | ||||
|     Py_SETREF(lz->fillvalue, state); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -206,8 +206,7 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val) | |||
|     seq = PySequence_Tuple(val); | ||||
|     if (!seq) | ||||
|         return -1; | ||||
|     Py_CLEAR(self->args); | ||||
|     self->args = seq; | ||||
|     Py_SETREF(self->args, seq); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
|  | @ -646,9 +645,8 @@ ImportError_init(PyImportErrorObject *self, PyObject *args, PyObject *kwds) | |||
|     if (!PyArg_UnpackTuple(args, "ImportError", 1, 1, &msg)) | ||||
|         return -1; | ||||
| 
 | ||||
|     Py_CLEAR(self->msg);          /* replacing */ | ||||
|     self->msg = msg; | ||||
|     Py_INCREF(self->msg); | ||||
|     Py_INCREF(msg); | ||||
|     Py_SETREF(self->msg, msg); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
|  | @ -858,8 +856,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args, | |||
| #endif | ||||
| 
 | ||||
|     /* Steals the reference to args */ | ||||
|     Py_CLEAR(self->args); | ||||
|     self->args = args; | ||||
|     Py_SETREF(self->args, args); | ||||
|     *p_args = args = NULL; | ||||
| 
 | ||||
|     return 0; | ||||
|  | @ -1278,9 +1275,8 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) | |||
|         return -1; | ||||
| 
 | ||||
|     if (lenargs >= 1) { | ||||
|         Py_CLEAR(self->msg); | ||||
|         self->msg = PyTuple_GET_ITEM(args, 0); | ||||
|         Py_INCREF(self->msg); | ||||
|         Py_INCREF(PyTuple_GET_ITEM(args, 0)); | ||||
|         Py_SETREF(self->msg, PyTuple_GET_ITEM(args, 0)); | ||||
|     } | ||||
|     if (lenargs == 2) { | ||||
|         info = PyTuple_GET_ITEM(args, 1); | ||||
|  | @ -1295,21 +1291,17 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds) | |||
|             return -1; | ||||
|         } | ||||
| 
 | ||||
|         Py_CLEAR(self->filename); | ||||
|         self->filename = PyTuple_GET_ITEM(info, 0); | ||||
|         Py_INCREF(self->filename); | ||||
|         Py_INCREF(PyTuple_GET_ITEM(info, 0)); | ||||
|         Py_SETREF(self->filename, PyTuple_GET_ITEM(info, 0)); | ||||
| 
 | ||||
|         Py_CLEAR(self->lineno); | ||||
|         self->lineno = PyTuple_GET_ITEM(info, 1); | ||||
|         Py_INCREF(self->lineno); | ||||
|         Py_INCREF(PyTuple_GET_ITEM(info, 1)); | ||||
|         Py_SETREF(self->lineno, PyTuple_GET_ITEM(info, 1)); | ||||
| 
 | ||||
|         Py_CLEAR(self->offset); | ||||
|         self->offset = PyTuple_GET_ITEM(info, 2); | ||||
|         Py_INCREF(self->offset); | ||||
|         Py_INCREF(PyTuple_GET_ITEM(info, 2)); | ||||
|         Py_SETREF(self->offset, PyTuple_GET_ITEM(info, 2)); | ||||
| 
 | ||||
|         Py_CLEAR(self->text); | ||||
|         self->text = PyTuple_GET_ITEM(info, 3); | ||||
|         Py_INCREF(self->text); | ||||
|         Py_INCREF(PyTuple_GET_ITEM(info, 3)); | ||||
|         Py_SETREF(self->text, PyTuple_GET_ITEM(info, 3)); | ||||
| 
 | ||||
|         Py_DECREF(info); | ||||
| 
 | ||||
|  | @ -1554,8 +1546,7 @@ set_unicodefromstring(PyObject **attr, const char *value) | |||
|     PyObject *obj = PyUnicode_FromString(value); | ||||
|     if (!obj) | ||||
|         return -1; | ||||
|     Py_CLEAR(*attr); | ||||
|     *attr = obj; | ||||
|     Py_SETREF(*attr, obj); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
|  | @ -1961,8 +1952,7 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) | |||
|         Py_buffer view; | ||||
|         if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0) | ||||
|             goto error; | ||||
|         Py_CLEAR(ude->object); | ||||
|         ude->object = PyBytes_FromStringAndSize(view.buf, view.len); | ||||
|         Py_SETREF(ude->object, PyBytes_FromStringAndSize(view.buf, view.len)); | ||||
|         PyBuffer_Release(&view); | ||||
|         if (!ude->object) | ||||
|             goto error; | ||||
|  | @ -2871,9 +2861,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start) | |||
|     } | ||||
|     if (PyUnicode_Tailmatch(self->text, print_prefix, | ||||
|                             start, text_len, -1)) { | ||||
|         Py_CLEAR(self->msg); | ||||
|         self->msg = PyUnicode_FromString( | ||||
|                    "Missing parentheses in call to 'print'"); | ||||
|         Py_SETREF(self->msg, | ||||
|                   PyUnicode_FromString("Missing parentheses in call to 'print'")); | ||||
|         return 1; | ||||
|     } | ||||
| 
 | ||||
|  | @ -2886,9 +2875,8 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start) | |||
|     } | ||||
|     if (PyUnicode_Tailmatch(self->text, exec_prefix, | ||||
|                             start, text_len, -1)) { | ||||
|         Py_CLEAR(self->msg); | ||||
|         self->msg = PyUnicode_FromString( | ||||
|                     "Missing parentheses in call to 'exec'"); | ||||
|         Py_SETREF(self->msg, | ||||
|                   PyUnicode_FromString("Missing parentheses in call to 'exec'")); | ||||
|         return 1; | ||||
|     } | ||||
|     /* Fall back to the default error message */ | ||||
|  |  | |||
|  | @ -1001,8 +1001,7 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state) | |||
|         return NULL; | ||||
|     cmp = PyObject_RichCompareBool(state, zero, Py_LT); | ||||
|     if (cmp > 0) { | ||||
|         Py_CLEAR(r->index); | ||||
|         r->index = zero; | ||||
|         Py_SETREF(r->index, zero); | ||||
|         Py_RETURN_NONE; | ||||
|     } | ||||
|     Py_DECREF(zero); | ||||
|  | @ -1015,9 +1014,8 @@ longrangeiter_setstate(longrangeiterobject *r, PyObject *state) | |||
|     if (cmp > 0) | ||||
|         state = r->len; | ||||
| 
 | ||||
|     Py_CLEAR(r->index); | ||||
|     r->index = state; | ||||
|     Py_INCREF(r->index); | ||||
|     Py_INCREF(state); | ||||
|     Py_SETREF(r->index, state); | ||||
|     Py_RETURN_NONE; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -4410,10 +4410,8 @@ _PyEval_SetCoroutineWrapper(PyObject *wrapper) | |||
| { | ||||
|     PyThreadState *tstate = PyThreadState_GET(); | ||||
| 
 | ||||
|     Py_CLEAR(tstate->coroutine_wrapper); | ||||
| 
 | ||||
|     Py_XINCREF(wrapper); | ||||
|     tstate->coroutine_wrapper = wrapper; | ||||
|     Py_SETREF(tstate->coroutine_wrapper, wrapper); | ||||
| } | ||||
| 
 | ||||
| PyObject * | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka