summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-30 06:15:31 (GMT)
committerGitHub <noreply@github.com>2017-03-30 06:15:31 (GMT)
commit762bf40438a572a398e500c74e38f9894ea20a45 (patch)
treee3cec204dd4f633631650bf10222344a2c605929 /Python
parentea720fe7e99d68924deab38de955fe97f87e2b29 (diff)
downloadcpython-762bf40438a572a398e500c74e38f9894ea20a45.zip
cpython-762bf40438a572a398e500c74e38f9894ea20a45.tar.gz
cpython-762bf40438a572a398e500c74e38f9894ea20a45.tar.bz2
bpo-29852: Argument Clinic Py_ssize_t converter now supports None (#716)
if pass `accept={int, NoneType}`.
Diffstat (limited to 'Python')
-rw-r--r--Python/modsupport.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c
index 9637191..8a77a7b 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -12,6 +12,31 @@ static PyObject **va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_
/* Package context -- the full module name for package imports */
const char *_Py_PackageContext = NULL;
+
+int
+_Py_convert_optional_to_ssize_t(PyObject *obj, void *result)
+{
+ Py_ssize_t limit;
+ if (obj == Py_None) {
+ return 1;
+ }
+ else if (PyIndex_Check(obj)) {
+ limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError);
+ if (limit == -1 && PyErr_Occurred()) {
+ return 0;
+ }
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "argument should be integer or None, not '%.200s'",
+ Py_TYPE(obj)->tp_name);
+ return 0;
+ }
+ *((Py_ssize_t *)result) = limit;
+ return 1;
+}
+
+
/* Helper for mkvalue() to scan the length of a format */
static Py_ssize_t