Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3e17c788
Commit
3e17c788
authored
Feb 08, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #26198: Fixed error messages for some argument parsing errors.
parents
503f9080
c4b813d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
13 deletions
+21
-13
Lib/test/test_capi.py
Lib/test/test_capi.py
+1
-1
Python/getargs.c
Python/getargs.c
+20
-12
No files found.
Lib/test/test_capi.py
View file @
3e17c788
...
...
@@ -489,7 +489,7 @@ class SkipitemTest(unittest.TestCase):
format
.
encode
(
"ascii"
),
keywords
)
when_not_skipped
=
False
except
TypeError
as
e
:
s
=
"argument 1
must be impossible<bad format char>, not int
"
s
=
"argument 1
(impossible<bad format char>)
"
when_not_skipped
=
(
str
(
e
)
==
s
)
except
RuntimeError
as
e
:
when_not_skipped
=
False
...
...
Python/getargs.c
View file @
3e17c788
...
...
@@ -342,7 +342,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
flags
,
levels
,
msgbuf
,
sizeof
(
msgbuf
),
&
freelist
);
if
(
msg
)
{
seterror
(
i
+
1
,
msg
,
levels
,
fname
,
m
sg
);
seterror
(
i
+
1
,
msg
,
levels
,
fname
,
m
essage
);
return
cleanreturn
(
0
,
&
freelist
);
}
}
...
...
@@ -535,9 +535,15 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
{
assert
(
expected
!=
NULL
);
assert
(
arg
!=
NULL
);
PyOS_snprintf
(
msgbuf
,
bufsize
,
"must be %.50s, not %.50s"
,
expected
,
arg
==
Py_None
?
"None"
:
arg
->
ob_type
->
tp_name
);
if
(
expected
[
0
]
==
'('
)
{
PyOS_snprintf
(
msgbuf
,
bufsize
,
"%.100s"
,
expected
);
}
else
{
PyOS_snprintf
(
msgbuf
,
bufsize
,
"must be %.50s, not %.50s"
,
expected
,
arg
==
Py_None
?
"None"
:
arg
->
ob_type
->
tp_name
);
}
return
msgbuf
;
}
...
...
@@ -741,7 +747,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if
(
PyLong_Check
(
arg
))
ival
=
PyLong_AsUnsignedLongMask
(
arg
);
else
return
converterr
(
"int
eger<k>
"
,
arg
,
msgbuf
,
bufsize
);
return
converterr
(
"int"
,
arg
,
msgbuf
,
bufsize
);
*
p
=
ival
;
break
;
}
...
...
@@ -766,7 +772,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if
(
PyLong_Check
(
arg
))
ival
=
PyLong_AsUnsignedLongLongMask
(
arg
);
else
return
converterr
(
"int
eger<K>
"
,
arg
,
msgbuf
,
bufsize
);
return
converterr
(
"int"
,
arg
,
msgbuf
,
bufsize
);
*
p
=
ival
;
break
;
}
...
...
@@ -1123,9 +1129,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
else
{
if
(
size
+
1
>
BUFFER_LEN
)
{
Py_DECREF
(
s
);
return
converterr
(
"(buffer overflow)"
,
arg
,
msgbuf
,
bufsize
);
PyErr_Format
(
PyExc_TypeError
,
"encoded string too long "
"(%zd, maximum length %zd)"
,
(
Py_ssize_t
)
size
,
(
Py_ssize_t
)(
BUFFER_LEN
-
1
));
RETURN_ERR_OCCURRED
;
}
}
memcpy
(
*
buffer
,
ptr
,
size
+
1
);
...
...
@@ -1147,7 +1155,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if
((
Py_ssize_t
)
strlen
(
ptr
)
!=
size
)
{
Py_DECREF
(
s
);
return
converterr
(
"encoded string without
NULL
bytes"
,
"encoded string without
null
bytes"
,
arg
,
msgbuf
,
bufsize
);
}
*
buffer
=
PyMem_NEW
(
char
,
size
+
1
);
...
...
@@ -1237,7 +1245,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
if
(
*
format
!=
'*'
)
return
converterr
(
"
invalid use of 'w' format character
"
,
"
(invalid use of 'w' format character)
"
,
arg
,
msgbuf
,
bufsize
);
format
++
;
...
...
@@ -1261,7 +1269,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
default:
return
converterr
(
"
impossible<bad format char>
"
,
arg
,
msgbuf
,
bufsize
);
return
converterr
(
"
(impossible<bad format char>)
"
,
arg
,
msgbuf
,
bufsize
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment