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
d2557a67
Commit
d2557a67
authored
Jan 28, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #26198: Added tests for "es", "et", "es#", "et#" and "C" format units
of PyArg_Parse*() functions.
parents
60387e03
c8241fdd
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
228 additions
and
43 deletions
+228
-43
Lib/test/test_getargs2.py
Lib/test/test_getargs2.py
+135
-42
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+93
-1
No files found.
Lib/test/test_getargs2.py
View file @
d2557a67
This diff is collapsed.
Click to expand it.
Modules/_testcapimodule.c
View file @
d2557a67
...
...
@@ -1088,7 +1088,16 @@ getargs_c(PyObject *self, PyObject *args)
char
c
;
if
(
!
PyArg_ParseTuple
(
args
,
"c"
,
&
c
))
return
NULL
;
return
PyBytes_FromStringAndSize
(
&
c
,
1
);
return
PyLong_FromLong
((
unsigned
char
)
c
);
}
static
PyObject
*
getargs_C
(
PyObject
*
self
,
PyObject
*
args
)
{
int
c
;
if
(
!
PyArg_ParseTuple
(
args
,
"C"
,
&
c
))
return
NULL
;
return
PyLong_FromLong
(
c
);
}
static
PyObject
*
...
...
@@ -1243,6 +1252,84 @@ getargs_Z_hash(PyObject *self, PyObject *args)
Py_RETURN_NONE
;
}
static
PyObject
*
getargs_es
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
arg
,
*
result
;
const
char
*
encoding
=
NULL
;
char
*
str
;
if
(
!
PyArg_ParseTuple
(
args
,
"O|s"
,
&
arg
,
&
encoding
))
return
NULL
;
if
(
!
PyArg_Parse
(
arg
,
"es"
,
encoding
,
&
str
))
return
NULL
;
result
=
PyBytes_FromString
(
str
);
PyMem_Free
(
str
);
return
result
;
}
static
PyObject
*
getargs_et
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
arg
,
*
result
;
const
char
*
encoding
=
NULL
;
char
*
str
;
if
(
!
PyArg_ParseTuple
(
args
,
"O|s"
,
&
arg
,
&
encoding
))
return
NULL
;
if
(
!
PyArg_Parse
(
arg
,
"et"
,
encoding
,
&
str
))
return
NULL
;
result
=
PyBytes_FromString
(
str
);
PyMem_Free
(
str
);
return
result
;
}
static
PyObject
*
getargs_es_hash
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
arg
,
*
result
;
const
char
*
encoding
=
NULL
;
PyByteArrayObject
*
buffer
=
NULL
;
char
*
str
=
NULL
;
Py_ssize_t
size
;
if
(
!
PyArg_ParseTuple
(
args
,
"O|sY"
,
&
arg
,
&
encoding
,
&
buffer
))
return
NULL
;
if
(
buffer
!=
NULL
)
{
str
=
PyByteArray_AS_STRING
(
buffer
);
size
=
PyByteArray_GET_SIZE
(
buffer
);
}
if
(
!
PyArg_Parse
(
arg
,
"es#"
,
encoding
,
&
str
,
&
size
))
return
NULL
;
result
=
PyBytes_FromStringAndSize
(
str
,
size
);
if
(
buffer
==
NULL
)
PyMem_Free
(
str
);
return
result
;
}
static
PyObject
*
getargs_et_hash
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
arg
,
*
result
;
const
char
*
encoding
=
NULL
;
PyByteArrayObject
*
buffer
=
NULL
;
char
*
str
=
NULL
;
Py_ssize_t
size
;
if
(
!
PyArg_ParseTuple
(
args
,
"O|sY"
,
&
arg
,
&
encoding
,
&
buffer
))
return
NULL
;
if
(
buffer
!=
NULL
)
{
str
=
PyByteArray_AS_STRING
(
buffer
);
size
=
PyByteArray_GET_SIZE
(
buffer
);
}
if
(
!
PyArg_Parse
(
arg
,
"et#"
,
encoding
,
&
str
,
&
size
))
return
NULL
;
result
=
PyBytes_FromStringAndSize
(
str
,
size
);
if
(
buffer
==
NULL
)
PyMem_Free
(
str
);
return
result
;
}
/* Test the s and z codes for PyArg_ParseTuple.
*/
static
PyObject
*
...
...
@@ -3590,6 +3677,7 @@ static PyMethodDef TestMethods[] = {
{
"test_L_code"
,
(
PyCFunction
)
test_L_code
,
METH_NOARGS
},
#endif
{
"getargs_c"
,
getargs_c
,
METH_VARARGS
},
{
"getargs_C"
,
getargs_C
,
METH_VARARGS
},
{
"getargs_s"
,
getargs_s
,
METH_VARARGS
},
{
"getargs_s_star"
,
getargs_s_star
,
METH_VARARGS
},
{
"getargs_s_hash"
,
getargs_s_hash
,
METH_VARARGS
},
...
...
@@ -3604,6 +3692,10 @@ static PyMethodDef TestMethods[] = {
{
"getargs_Z"
,
getargs_Z
,
METH_VARARGS
},
{
"getargs_Z_hash"
,
getargs_Z_hash
,
METH_VARARGS
},
{
"getargs_w_star"
,
getargs_w_star
,
METH_VARARGS
},
{
"getargs_es"
,
getargs_es
,
METH_VARARGS
},
{
"getargs_et"
,
getargs_et
,
METH_VARARGS
},
{
"getargs_es_hash"
,
getargs_es_hash
,
METH_VARARGS
},
{
"getargs_et_hash"
,
getargs_et_hash
,
METH_VARARGS
},
{
"codec_incrementalencoder"
,
(
PyCFunction
)
codec_incrementalencoder
,
METH_VARARGS
},
{
"codec_incrementaldecoder"
,
...
...
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