Issue #14705: Add 'p' format character to PyArg_ParseTuple* for bool support.

This commit is contained in:
Larry Hastings 2012-05-05 16:54:29 -07:00
parent 6b03f2ce45
commit faf91e75ab
4 changed files with 62 additions and 0 deletions

View file

@ -814,6 +814,18 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
break;
}
case 'p': {/* boolean *p*redicate */
int *p = va_arg(*p_va, int *);
int val = PyObject_IsTrue(arg);
if (val > 0)
*p = 1;
else if (val == 0)
*p = 0;
else
RETURN_ERR_OCCURRED;
break;
}
/* XXX WAAAAH! 's', 'y', 'z', 'u', 'Z', 'e', 'w' codes all
need to be cleaned up! */