[New-bugs-announce] [issue23926] skipitem() in getargs.c still supports 'w' and 'w#', and shouldn't

Larry Hastings report at bugs.python.org
Mon Apr 13 04:44:00 CEST 2015

New submission from Larry Hastings:

tl;dr: skipitem() in Python 3 still supports "w" and "w#", which were abandoned.  They should be removed.


* you have an extension that parses its arguments with
  PyArg_ParseTupleAndKeywords (or its cousins),
* you have optional positional parameters, and
* you run out of positional arguments

CPython will call skipitem() to skip over the remaining positional parameters so it can process keyword arguments.  It does this by knowing all the format units, and iterating over them and throwing away the various varargs pointers until it hits the keyword arguments part of the format string.

PyArg_ParseTuple() etc. in Python 2 supported "w" and "w#" for parsing "objects with the read-write buffer interface".  These were removed in Python 3.

skipitem() in Python 3 still supports both skipping "w" and "w#".  But in fact the only legal format unit starting with a 'w' in Python 3 is 'w*'.  So a function with a 'w*' as an optional parameter that got skipped would be misinterpreted; skipitem would see the 'w', not recognize the following '*' and leave it there, then the next function that read a character from the format string (either skipitem() or convertsimple()) would see the '*' and throw an "impossible <bad format char>" exception.

assignee: larry
messages: 240587
nosy: larry
priority: low
severity: normal
stage: test needed
status: open
title: skipitem() in getargs.c still supports 'w' and 'w#', and shouldn't
type: crash
versions: Python 3.4, Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list