bpo-28261: fix err msgs where PyArg_ParseTuple is used to parse norma… · python/cpython@13614e3 (original) (raw)

`@@ -531,7 +531,15 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)

`

531

531

`_PyIO_str_getstate, NULL);

`

532

532

`if (state == NULL)

`

533

533

`return NULL;

`

534

``

`-

if (!PyArg_ParseTuple(state, "OK", &buffer, &flag)) {

`

``

534

`+

if (!PyTuple_Check(state)) {

`

``

535

`+

PyErr_SetString(PyExc_TypeError,

`

``

536

`+

"illegal decoder state");

`

``

537

`+

Py_DECREF(state);

`

``

538

`+

return NULL;

`

``

539

`+

}

`

``

540

`+

if (!PyArg_ParseTuple(state, "OK;illegal decoder state",

`

``

541

`+

&buffer, &flag))

`

``

542

`+

{

`

535

543

`Py_DECREF(state);

`

536

544

`return NULL;

`

537

545

` }

`

`@@ -669,7 +677,7 @@ typedef struct

`

669

677

` written, or NULL */

`

670

678

`Py_ssize_t pending_bytes_count;

`

671

679

``

672

``

`-

/* snapshot is either None, or a tuple (dec_flags, next_input) where

`

``

680

`+

/* snapshot is either NULL, or a tuple (dec_flags, next_input) where

`

673

681

` * dec_flags is the second (integer) item of the decoder state and

`

674

682

` * next_input is the chunk of input bytes that comes next after the

`

675

683

` * snapshot point. We use this to reconstruct decoder states in tell().

`

`@@ -2351,6 +2359,7 @@ _io_TextIOWrapper_tell_impl(textio *self)

`

2351

2359

` goto fail;

`

2352

2360

``

2353

2361

`/* Skip backward to the snapshot point (see _read_chunk). */

`

``

2362

`+

assert(PyTuple_Check(self->snapshot));

`

2354

2363

`if (!PyArg_ParseTuple(self->snapshot, "iO", &cookie.dec_flags, &next_input))

`

2355

2364

` goto fail;

`

2356

2365

``

`@@ -2378,7 +2387,15 @@ _io_TextIOWrapper_tell_impl(textio *self)

`

2378

2387

` _PyIO_str_getstate, NULL); \

`

2379

2388

` if (_state == NULL) \

`

2380

2389

` goto fail; \

`

2381

``

`-

if (!PyArg_ParseTuple(_state, "Oi", &dec_buffer, &dec_flags)) { \

`

``

2390

`+

if (!PyTuple_Check(_state)) { \

`

``

2391

`+

PyErr_SetString(PyExc_TypeError, \

`

``

2392

`+

"illegal decoder state"); \

`

``

2393

`+

Py_DECREF(_state); \

`

``

2394

`+

goto fail; \

`

``

2395

`+

} \

`

``

2396

`+

if (!PyArg_ParseTuple(_state, "Oi;illegal decoder state", \

`

``

2397

`+

&dec_buffer, &dec_flags)) \

`

``

2398

`+

{ \

`

2382

2399

` Py_DECREF(_state); \

`

2383

2400

` goto fail; \

`

2384

2401

` } \

`