File Modules/_io/_iomodule.c changed (mode: 100644) (index 8f0b72a55b..5d804ece79) |
... |
... |
_PyIO_ConvertSsize_t(PyObject *obj, void *result) { |
549 |
549 |
if (obj == Py_None) { |
if (obj == Py_None) { |
550 |
550 |
limit = -1; |
limit = -1; |
551 |
551 |
} |
} |
552 |
|
else if (PyNumber_Check(obj)) { |
|
|
552 |
|
else if (PyIndex_Check(obj)) { |
553 |
553 |
limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError); |
limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError); |
554 |
|
if (limit == -1 && PyErr_Occurred()) |
|
|
554 |
|
if (limit == -1 && PyErr_Occurred()) { |
555 |
555 |
return 0; |
return 0; |
|
556 |
|
} |
556 |
557 |
} |
} |
557 |
558 |
else { |
else { |
558 |
559 |
PyErr_Format(PyExc_TypeError, |
PyErr_Format(PyExc_TypeError, |
559 |
|
"integer argument expected, got '%.200s'", |
|
|
560 |
|
"argument should be integer or None, not '%.200s'", |
560 |
561 |
Py_TYPE(obj)->tp_name); |
Py_TYPE(obj)->tp_name); |
561 |
562 |
return 0; |
return 0; |
562 |
563 |
} |
} |
File Modules/_io/bytesio.c changed (mode: 100644) (index 0a0e5e72d7..59b917d0bd) |
... |
... |
_io_BytesIO_truncate_impl(bytesio *self, PyObject *arg) |
578 |
578 |
/* Truncate to current position if no argument is passed. */ |
/* Truncate to current position if no argument is passed. */ |
579 |
579 |
size = self->pos; |
size = self->pos; |
580 |
580 |
} |
} |
581 |
|
else { |
|
|
581 |
|
else if (PyIndex_Check(arg)) { |
582 |
582 |
size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); |
size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); |
583 |
583 |
if (size == -1 && PyErr_Occurred()) { |
if (size == -1 && PyErr_Occurred()) { |
584 |
584 |
return NULL; |
return NULL; |
585 |
585 |
} |
} |
586 |
586 |
} |
} |
|
587 |
|
else { |
|
588 |
|
PyErr_Format(PyExc_TypeError, |
|
589 |
|
"argument should be integer or None, not '%.200s'", |
|
590 |
|
Py_TYPE(arg)->tp_name); |
|
591 |
|
return NULL; |
|
592 |
|
} |
587 |
593 |
|
|
588 |
594 |
if (size < 0) { |
if (size < 0) { |
589 |
595 |
PyErr_Format(PyExc_ValueError, |
PyErr_Format(PyExc_ValueError, |
File Modules/_io/stringio.c changed (mode: 100644) (index 788dcb1984..a73171fd8f) |
... |
... |
_io_StringIO_truncate_impl(stringio *self, PyObject *arg) |
458 |
458 |
CHECK_INITIALIZED(self); |
CHECK_INITIALIZED(self); |
459 |
459 |
CHECK_CLOSED(self); |
CHECK_CLOSED(self); |
460 |
460 |
|
|
461 |
|
if (PyNumber_Check(arg)) { |
|
|
461 |
|
if (PyIndex_Check(arg)) { |
462 |
462 |
size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); |
size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); |
463 |
|
if (size == -1 && PyErr_Occurred()) |
|
|
463 |
|
if (size == -1 && PyErr_Occurred()) { |
464 |
464 |
return NULL; |
return NULL; |
|
465 |
|
} |
465 |
466 |
} |
} |
466 |
467 |
else if (arg == Py_None) { |
else if (arg == Py_None) { |
467 |
468 |
/* Truncate to current position if no argument is passed. */ |
/* Truncate to current position if no argument is passed. */ |
468 |
469 |
size = self->pos; |
size = self->pos; |
469 |
470 |
} |
} |
470 |
471 |
else { |
else { |
471 |
|
PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'", |
|
|
472 |
|
PyErr_Format(PyExc_TypeError, |
|
473 |
|
"argument should be integer or None, not '%.200s'", |
472 |
474 |
Py_TYPE(arg)->tp_name); |
Py_TYPE(arg)->tp_name); |
473 |
475 |
return NULL; |
return NULL; |
474 |
476 |
} |
} |
File Modules/mmapmodule.c changed (mode: 100644) (index 7a94464e7b..7c15d377cf) |
... |
... |
mmap_convert_ssize_t(PyObject *obj, void *result) { |
247 |
247 |
if (obj == Py_None) { |
if (obj == Py_None) { |
248 |
248 |
limit = -1; |
limit = -1; |
249 |
249 |
} |
} |
250 |
|
else if (PyNumber_Check(obj)) { |
|
|
250 |
|
else if (PyIndex_Check(obj)) { |
251 |
251 |
limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError); |
limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError); |
252 |
|
if (limit == -1 && PyErr_Occurred()) |
|
|
252 |
|
if (limit == -1 && PyErr_Occurred()) { |
253 |
253 |
return 0; |
return 0; |
|
254 |
|
} |
254 |
255 |
} |
} |
255 |
256 |
else { |
else { |
256 |
257 |
PyErr_Format(PyExc_TypeError, |
PyErr_Format(PyExc_TypeError, |
257 |
|
"integer argument expected, got '%.200s'", |
|
|
258 |
|
"argument should be integer or None, not '%.200s'", |
258 |
259 |
Py_TYPE(obj)->tp_name); |
Py_TYPE(obj)->tp_name); |
259 |
260 |
return 0; |
return 0; |
260 |
261 |
} |
} |
File Objects/bytes_methods.c changed (mode: 100644) (index d5c4fe6346..85d9ceea52) |
... |
... |
_Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to) |
399 |
399 |
#include "stringlib/find.h" |
#include "stringlib/find.h" |
400 |
400 |
|
|
401 |
401 |
/* |
/* |
402 |
|
Wraps stringlib_parse_args_finds() and additionally checks whether the |
|
403 |
|
first argument is an integer in range(0, 256). |
|
|
402 |
|
Wraps stringlib_parse_args_finds() and additionally checks the first |
|
403 |
|
argument type. |
404 |
404 |
|
|
405 |
|
If this is the case, writes the integer value to the byte parameter |
|
406 |
|
and sets subobj to NULL. Otherwise, sets the first argument to subobj |
|
407 |
|
and doesn't touch byte. The other parameters are similar to those of |
|
|
405 |
|
In case the first argument is a bytes-like object, sets it to subobj, |
|
406 |
|
and doesn't touch the byte parameter. |
|
407 |
|
In case it is an integer in range(0, 256), writes the integer value |
|
408 |
|
to byte, and sets subobj to NULL. |
|
409 |
|
|
|
410 |
|
The other parameters are similar to those of |
408 |
411 |
stringlib_parse_args_finds(). |
stringlib_parse_args_finds(). |
409 |
412 |
*/ |
*/ |
410 |
413 |
|
|
|
... |
... |
parse_args_finds_byte(const char *function_name, PyObject *args, |
415 |
418 |
{ |
{ |
416 |
419 |
PyObject *tmp_subobj; |
PyObject *tmp_subobj; |
417 |
420 |
Py_ssize_t ival; |
Py_ssize_t ival; |
418 |
|
PyObject *err; |
|
419 |
421 |
|
|
420 |
422 |
if(!stringlib_parse_args_finds(function_name, args, &tmp_subobj, |
if(!stringlib_parse_args_finds(function_name, args, &tmp_subobj, |
421 |
423 |
start, end)) |
start, end)) |
422 |
424 |
return 0; |
return 0; |
423 |
425 |
|
|
424 |
|
if (!PyNumber_Check(tmp_subobj)) { |
|
|
426 |
|
if (PyObject_CheckBuffer(tmp_subobj)) { |
425 |
427 |
*subobj = tmp_subobj; |
*subobj = tmp_subobj; |
426 |
428 |
return 1; |
return 1; |
427 |
429 |
} |
} |
428 |
430 |
|
|
429 |
|
ival = PyNumber_AsSsize_t(tmp_subobj, PyExc_OverflowError); |
|
430 |
|
if (ival == -1) { |
|
431 |
|
err = PyErr_Occurred(); |
|
432 |
|
if (err && !PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { |
|
433 |
|
PyErr_Clear(); |
|
434 |
|
*subobj = tmp_subobj; |
|
435 |
|
return 1; |
|
436 |
|
} |
|
|
431 |
|
if (!PyIndex_Check(tmp_subobj)) { |
|
432 |
|
PyErr_Format(PyExc_TypeError, |
|
433 |
|
"argument should be integer or bytes-like object, " |
|
434 |
|
"not '%.200s'", |
|
435 |
|
Py_TYPE(tmp_subobj)->tp_name); |
|
436 |
|
return 0; |
437 |
437 |
} |
} |
438 |
438 |
|
|
|
439 |
|
ival = PyNumber_AsSsize_t(tmp_subobj, NULL); |
|
440 |
|
if (ival == -1 && PyErr_Occurred()) { |
|
441 |
|
return 0; |
|
442 |
|
} |
439 |
443 |
if (ival < 0 || ival > 255) { |
if (ival < 0 || ival > 255) { |
440 |
444 |
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); |
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); |
441 |
445 |
return 0; |
return 0; |