This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author larry
Recipients benjamin.peterson, georg.brandl, larry
Date 2015-04-16.23:38:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429227526.01.0.733275706487.issue23980@psf.upfronthosting.co.za>
In-reply-to
Content
Documentation is here:

    https://docs.python.org/3/c-api/arg.html#arg-parsing


The first line of documentation for each format unit follows this convention:
    formatunit (pythontype) [arguments, to, pyarg_parsetuple]

These represent the format unit itself, followed by the Python type it consumes in parentheses, followed by the C types it outputs in square brackets.  Thus
    i (int) [int]
means the format unit is 'i', it consumes a Python 'int', and it produces a C 'int'.  Similarly,
    s (str) [const char *]
means the format unit is 's', it consumes a Python 'str', and it produces a C 'const char *'.

When you call PyArg_ParseTuple (AndKeywords), you pass in a pointer to the thing you expect.  If it gives you an int, you pass in &my_int. So the type of the expression you pass in for 'i' is actually "int *".  And the type you pass in for 's' is actually "char **".

The format units that deal with encodings are a bit weirder.  You actually pass in a const char * string first, followed by the buffer you want to write data too.  Technically the types of the values you pass in for "es" are "const char *, char **".  But the documentation for es says
    es (str) [const char *encoding, char **buffer]

This led me to believe that I actually had to pass in a "char ***" for buffer!  Which is wrong and doing so makes your programs explode-y.


The documentation should

* explain this first-line convention precisely, and

* use the types consistently.

My suspicion is that the things in brackets have to be the precise C type, e.g. "int *" for i, "char **" for s, "const char *, char **" for es.
History
Date User Action Args
2015-04-16 23:38:46larrysetrecipients: + larry, georg.brandl, benjamin.peterson
2015-04-16 23:38:46larrysetmessageid: <1429227526.01.0.733275706487.issue23980@psf.upfronthosting.co.za>
2015-04-16 23:38:45larrylinkissue23980 messages
2015-04-16 23:38:45larrycreate