/Doc/c-api/arg.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 559 lines · 424 code · 135 blank · 0 comment · 0 complexity · 876893ce2eab8f0d4fcd6298ffb3384a MD5 · raw file

  1. .. highlightlang:: c
  2. .. _arg-parsing:
  3. Parsing arguments and building values
  4. =====================================
  5. These functions are useful when creating your own extensions functions and
  6. methods. Additional information and examples are available in
  7. :ref:`extending-index`.
  8. The first three of these functions described, :cfunc:`PyArg_ParseTuple`,
  9. :cfunc:`PyArg_ParseTupleAndKeywords`, and :cfunc:`PyArg_Parse`, all use
  10. *format strings* which are used to tell the function about the expected
  11. arguments. The format strings use the same syntax for each of these
  12. functions.
  13. A format string consists of zero or more "format units." A format unit
  14. describes one Python object; it is usually a single character or a
  15. parenthesized sequence of format units. With a few exceptions, a format unit
  16. that is not a parenthesized sequence normally corresponds to a single address
  17. argument to these functions. In the following description, the quoted form is
  18. the format unit; the entry in (round) parentheses is the Python object type
  19. that matches the format unit; and the entry in [square] brackets is the type
  20. of the C variable(s) whose address should be passed.
  21. ``s`` (string or Unicode object) [const char \*]
  22. Convert a Python string or Unicode object to a C pointer to a character
  23. string. You must not provide storage for the string itself; a pointer to
  24. an existing string is stored into the character pointer variable whose
  25. address you pass. The C string is NUL-terminated. The Python string must
  26. not contain embedded NUL bytes; if it does, a :exc:`TypeError` exception is
  27. raised. Unicode objects are converted to C strings using the default
  28. encoding. If this conversion fails, a :exc:`UnicodeError` is raised.
  29. ``s#`` (string, Unicode or any read buffer compatible object) [const char \*, int (or :ctype:`Py_ssize_t`, see below)]
  30. This variant on ``s`` stores into two C variables, the first one a pointer
  31. to a character string, the second one its length. In this case the Python
  32. string may contain embedded null bytes. Unicode objects pass back a
  33. pointer to the default encoded string version of the object if such a
  34. conversion is possible. All other read-buffer compatible objects pass back
  35. a reference to the raw internal data representation.
  36. Starting with Python 2.5 the type of the length argument can be controlled
  37. by defining the macro :cmacro:`PY_SSIZE_T_CLEAN` before including
  38. :file:`Python.h`. If the macro is defined, length is a :ctype:`Py_ssize_t`
  39. rather than an int.
  40. ``s*`` (string, Unicode, or any buffer compatible object) [Py_buffer \*]
  41. Similar to ``s#``, this code fills a Py_buffer structure provided by the
  42. caller. The buffer gets locked, so that the caller can subsequently use
  43. the buffer even inside a ``Py_BEGIN_ALLOW_THREADS`` block; the caller is
  44. responsible for calling ``PyBuffer_Release`` with the structure after it
  45. has processed the data.
  46. .. versionadded:: 2.6
  47. ``z`` (string or ``None``) [const char \*]
  48. Like ``s``, but the Python object may also be ``None``, in which case the C
  49. pointer is set to *NULL*.
  50. ``z#`` (string or ``None`` or any read buffer compatible object) [const char \*, int]
  51. This is to ``s#`` as ``z`` is to ``s``.
  52. ``z*`` (string or ``None`` or any buffer compatible object) [Py_buffer*]
  53. This is to ``s*`` as ``z`` is to ``s``.
  54. .. versionadded:: 2.6
  55. ``u`` (Unicode object) [Py_UNICODE \*]
  56. Convert a Python Unicode object to a C pointer to a NUL-terminated buffer
  57. of 16-bit Unicode (UTF-16) data. As with ``s``, there is no need to
  58. provide storage for the Unicode data buffer; a pointer to the existing
  59. Unicode data is stored into the :ctype:`Py_UNICODE` pointer variable whose
  60. address you pass.
  61. ``u#`` (Unicode object) [Py_UNICODE \*, int]
  62. This variant on ``u`` stores into two C variables, the first one a pointer
  63. to a Unicode data buffer, the second one its length. Non-Unicode objects
  64. are handled by interpreting their read-buffer pointer as pointer to a
  65. :ctype:`Py_UNICODE` array.
  66. ``es`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
  67. This variant on ``s`` is used for encoding Unicode and objects convertible
  68. to Unicode into a character buffer. It only works for encoded data without
  69. embedded NUL bytes.
  70. This format requires two arguments. The first is only used as input, and
  71. must be a :ctype:`const char\*` which points to the name of an encoding as
  72. a NUL-terminated string, or *NULL*, in which case the default encoding is
  73. used. An exception is raised if the named encoding is not known to Python.
  74. The second argument must be a :ctype:`char\*\*`; the value of the pointer
  75. it references will be set to a buffer with the contents of the argument
  76. text. The text will be encoded in the encoding specified by the first
  77. argument.
  78. :cfunc:`PyArg_ParseTuple` will allocate a buffer of the needed size, copy
  79. the encoded data into this buffer and adjust *\*buffer* to reference the
  80. newly allocated storage. The caller is responsible for calling
  81. :cfunc:`PyMem_Free` to free the allocated buffer after use.
  82. ``et`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
  83. Same as ``es`` except that 8-bit string objects are passed through without
  84. recoding them. Instead, the implementation assumes that the string object
  85. uses the encoding passed in as parameter.
  86. ``es#`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer, int \*buffer_length]
  87. This variant on ``s#`` is used for encoding Unicode and objects convertible
  88. to Unicode into a character buffer. Unlike the ``es`` format, this variant
  89. allows input data which contains NUL characters.
  90. It requires three arguments. The first is only used as input, and must be
  91. a :ctype:`const char\*` which points to the name of an encoding as a
  92. NUL-terminated string, or *NULL*, in which case the default encoding is
  93. used. An exception is raised if the named encoding is not known to Python.
  94. The second argument must be a :ctype:`char\*\*`; the value of the pointer
  95. it references will be set to a buffer with the contents of the argument
  96. text. The text will be encoded in the encoding specified by the first
  97. argument. The third argument must be a pointer to an integer; the
  98. referenced integer will be set to the number of bytes in the output buffer.
  99. There are two modes of operation:
  100. If *\*buffer* points a *NULL* pointer, the function will allocate a buffer
  101. of the needed size, copy the encoded data into this buffer and set
  102. *\*buffer* to reference the newly allocated storage. The caller is
  103. responsible for calling :cfunc:`PyMem_Free` to free the allocated buffer
  104. after usage.
  105. If *\*buffer* points to a non-*NULL* pointer (an already allocated buffer),
  106. :cfunc:`PyArg_ParseTuple` will use this location as the buffer and
  107. interpret the initial value of *\*buffer_length* as the buffer size. It
  108. will then copy the encoded data into the buffer and NUL-terminate it. If
  109. the buffer is not large enough, a :exc:`ValueError` will be set.
  110. In both cases, *\*buffer_length* is set to the length of the encoded data
  111. without the trailing NUL byte.
  112. ``et#`` (string, Unicode object or character buffer compatible object) [const char \*encoding, char \*\*buffer]
  113. Same as ``es#`` except that string objects are passed through without
  114. recoding them. Instead, the implementation assumes that the string object
  115. uses the encoding passed in as parameter.
  116. ``b`` (integer) [unsigned char]
  117. Convert a nonnegative Python integer to an unsigned tiny int, stored in a C
  118. :ctype:`unsigned char`.
  119. ``B`` (integer) [unsigned char]
  120. Convert a Python integer to a tiny int without overflow checking, stored in
  121. a C :ctype:`unsigned char`.
  122. .. versionadded:: 2.3
  123. ``h`` (integer) [short int]
  124. Convert a Python integer to a C :ctype:`short int`.
  125. ``H`` (integer) [unsigned short int]
  126. Convert a Python integer to a C :ctype:`unsigned short int`, without
  127. overflow checking.
  128. .. versionadded:: 2.3
  129. ``i`` (integer) [int]
  130. Convert a Python integer to a plain C :ctype:`int`.
  131. ``I`` (integer) [unsigned int]
  132. Convert a Python integer to a C :ctype:`unsigned int`, without overflow
  133. checking.
  134. .. versionadded:: 2.3
  135. ``l`` (integer) [long int]
  136. Convert a Python integer to a C :ctype:`long int`.
  137. ``k`` (integer) [unsigned long]
  138. Convert a Python integer or long integer to a C :ctype:`unsigned long`
  139. without overflow checking.
  140. .. versionadded:: 2.3
  141. ``L`` (integer) [PY_LONG_LONG]
  142. Convert a Python integer to a C :ctype:`long long`. This format is only
  143. available on platforms that support :ctype:`long long` (or :ctype:`_int64`
  144. on Windows).
  145. ``K`` (integer) [unsigned PY_LONG_LONG]
  146. Convert a Python integer or long integer to a C :ctype:`unsigned long long`
  147. without overflow checking. This format is only available on platforms that
  148. support :ctype:`unsigned long long` (or :ctype:`unsigned _int64` on
  149. Windows).
  150. .. versionadded:: 2.3
  151. ``n`` (integer) [Py_ssize_t]
  152. Convert a Python integer or long integer to a C :ctype:`Py_ssize_t`.
  153. .. versionadded:: 2.5
  154. ``c`` (string of length 1) [char]
  155. Convert a Python character, represented as a string of length 1, to a C
  156. :ctype:`char`.
  157. ``f`` (float) [float]
  158. Convert a Python floating point number to a C :ctype:`float`.
  159. ``d`` (float) [double]
  160. Convert a Python floating point number to a C :ctype:`double`.
  161. ``D`` (complex) [Py_complex]
  162. Convert a Python complex number to a C :ctype:`Py_complex` structure.
  163. ``O`` (object) [PyObject \*]
  164. Store a Python object (without any conversion) in a C object pointer. The
  165. C program thus receives the actual object that was passed. The object's
  166. reference count is not increased. The pointer stored is not *NULL*.
  167. ``O!`` (object) [*typeobject*, PyObject \*]
  168. Store a Python object in a C object pointer. This is similar to ``O``, but
  169. takes two C arguments: the first is the address of a Python type object,
  170. the second is the address of the C variable (of type :ctype:`PyObject\*`)
  171. into which the object pointer is stored. If the Python object does not
  172. have the required type, :exc:`TypeError` is raised.
  173. ``O&`` (object) [*converter*, *anything*]
  174. Convert a Python object to a C variable through a *converter* function.
  175. This takes two arguments: the first is a function, the second is the
  176. address of a C variable (of arbitrary type), converted to :ctype:`void \*`.
  177. The *converter* function in turn is called as follows::
  178. status = converter(object, address);
  179. where *object* is the Python object to be converted and *address* is the
  180. :ctype:`void\*` argument that was passed to the :cfunc:`PyArg_Parse\*`
  181. function. The returned *status* should be ``1`` for a successful
  182. conversion and ``0`` if the conversion has failed. When the conversion
  183. fails, the *converter* function should raise an exception and leave the
  184. content of *address* unmodified.
  185. ``S`` (string) [PyStringObject \*]
  186. Like ``O`` but requires that the Python object is a string object. Raises
  187. :exc:`TypeError` if the object is not a string object. The C variable may
  188. also be declared as :ctype:`PyObject\*`.
  189. ``U`` (Unicode string) [PyUnicodeObject \*]
  190. Like ``O`` but requires that the Python object is a Unicode object. Raises
  191. :exc:`TypeError` if the object is not a Unicode object. The C variable may
  192. also be declared as :ctype:`PyObject\*`.
  193. ``t#`` (read-only character buffer) [char \*, int]
  194. Like ``s#``, but accepts any object which implements the read-only buffer
  195. interface. The :ctype:`char\*` variable is set to point to the first byte
  196. of the buffer, and the :ctype:`int` is set to the length of the buffer.
  197. Only single-segment buffer objects are accepted; :exc:`TypeError` is raised
  198. for all others.
  199. ``w`` (read-write character buffer) [char \*]
  200. Similar to ``s``, but accepts any object which implements the read-write
  201. buffer interface. The caller must determine the length of the buffer by
  202. other means, or use ``w#`` instead. Only single-segment buffer objects are
  203. accepted; :exc:`TypeError` is raised for all others.
  204. ``w#`` (read-write character buffer) [char \*, Py_ssize_t]
  205. Like ``s#``, but accepts any object which implements the read-write buffer
  206. interface. The :ctype:`char \*` variable is set to point to the first byte
  207. of the buffer, and the :ctype:`Py_ssize_t` is set to the length of the
  208. buffer. Only single-segment buffer objects are accepted; :exc:`TypeError`
  209. is raised for all others.
  210. ``w*`` (read-write byte-oriented buffer) [Py_buffer \*]
  211. This is to ``w`` what ``s*`` is to ``s``.
  212. .. versionadded:: 2.6
  213. ``(items)`` (tuple) [*matching-items*]
  214. The object must be a Python sequence whose length is the number of format
  215. units in *items*. The C arguments must correspond to the individual format
  216. units in *items*. Format units for sequences may be nested.
  217. .. note::
  218. Prior to Python version 1.5.2, this format specifier only accepted a
  219. tuple containing the individual parameters, not an arbitrary sequence.
  220. Code which previously caused :exc:`TypeError` to be raised here may now
  221. proceed without an exception. This is not expected to be a problem for
  222. existing code.
  223. It is possible to pass Python long integers where integers are requested;
  224. however no proper range checking is done --- the most significant bits are
  225. silently truncated when the receiving field is too small to receive the value
  226. (actually, the semantics are inherited from downcasts in C --- your mileage
  227. may vary).
  228. A few other characters have a meaning in a format string. These may not occur
  229. inside nested parentheses. They are:
  230. ``|``
  231. Indicates that the remaining arguments in the Python argument list are
  232. optional. The C variables corresponding to optional arguments should be
  233. initialized to their default value --- when an optional argument is not
  234. specified, :cfunc:`PyArg_ParseTuple` does not touch the contents of the
  235. corresponding C variable(s).
  236. ``:``
  237. The list of format units ends here; the string after the colon is used as
  238. the function name in error messages (the "associated value" of the
  239. exception that :cfunc:`PyArg_ParseTuple` raises).
  240. ``;``
  241. The list of format units ends here; the string after the semicolon is used
  242. as the error message *instead* of the default error message. ``:`` and
  243. ``;`` mutually exclude each other.
  244. Note that any Python object references which are provided to the caller are
  245. *borrowed* references; do not decrement their reference count!
  246. Additional arguments passed to these functions must be addresses of variables
  247. whose type is determined by the format string; these are used to store values
  248. from the input tuple. There are a few cases, as described in the list of
  249. format units above, where these parameters are used as input values; they
  250. should match what is specified for the corresponding format unit in that case.
  251. For the conversion to succeed, the *arg* object must match the format and the
  252. format must be exhausted. On success, the :cfunc:`PyArg_Parse\*` functions
  253. return true, otherwise they return false and raise an appropriate exception.
  254. When the :cfunc:`PyArg_Parse\*` functions fail due to conversion failure in
  255. one of the format units, the variables at the addresses corresponding to that
  256. and the following format units are left untouched.
  257. .. cfunction:: int PyArg_ParseTuple(PyObject *args, const char *format, ...)
  258. Parse the parameters of a function that takes only positional parameters
  259. into local variables. Returns true on success; on failure, it returns
  260. false and raises the appropriate exception.
  261. .. cfunction:: int PyArg_VaParse(PyObject *args, const char *format, va_list vargs)
  262. Identical to :cfunc:`PyArg_ParseTuple`, except that it accepts a va_list
  263. rather than a variable number of arguments.
  264. .. cfunction:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...)
  265. Parse the parameters of a function that takes both positional and keyword
  266. parameters into local variables. Returns true on success; on failure, it
  267. returns false and raises the appropriate exception.
  268. .. cfunction:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs)
  269. Identical to :cfunc:`PyArg_ParseTupleAndKeywords`, except that it accepts a
  270. va_list rather than a variable number of arguments.
  271. .. cfunction:: int PyArg_Parse(PyObject *args, const char *format, ...)
  272. Function used to deconstruct the argument lists of "old-style" functions
  273. --- these are functions which use the :const:`METH_OLDARGS` parameter
  274. parsing method. This is not recommended for use in parameter parsing in
  275. new code, and most code in the standard interpreter has been modified to no
  276. longer use this for that purpose. It does remain a convenient way to
  277. decompose other tuples, however, and may continue to be used for that
  278. purpose.
  279. .. cfunction:: int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)
  280. A simpler form of parameter retrieval which does not use a format string to
  281. specify the types of the arguments. Functions which use this method to
  282. retrieve their parameters should be declared as :const:`METH_VARARGS` in
  283. function or method tables. The tuple containing the actual parameters
  284. should be passed as *args*; it must actually be a tuple. The length of the
  285. tuple must be at least *min* and no more than *max*; *min* and *max* may be
  286. equal. Additional arguments must be passed to the function, each of which
  287. should be a pointer to a :ctype:`PyObject\*` variable; these will be filled
  288. in with the values from *args*; they will contain borrowed references. The
  289. variables which correspond to optional parameters not given by *args* will
  290. not be filled in; these should be initialized by the caller. This function
  291. returns true on success and false if *args* is not a tuple or contains the
  292. wrong number of elements; an exception will be set if there was a failure.
  293. This is an example of the use of this function, taken from the sources for
  294. the :mod:`_weakref` helper module for weak references::
  295. static PyObject *
  296. weakref_ref(PyObject *self, PyObject *args)
  297. {
  298. PyObject *object;
  299. PyObject *callback = NULL;
  300. PyObject *result = NULL;
  301. if (PyArg_UnpackTuple(args, "ref", 1, 2, &object, &callback)) {
  302. result = PyWeakref_NewRef(object, callback);
  303. }
  304. return result;
  305. }
  306. The call to :cfunc:`PyArg_UnpackTuple` in this example is entirely
  307. equivalent to this call to :cfunc:`PyArg_ParseTuple`::
  308. PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
  309. .. versionadded:: 2.2
  310. .. versionchanged:: 2.5
  311. This function used an :ctype:`int` type for *min* and *max*. This might
  312. require changes in your code for properly supporting 64-bit systems.
  313. .. cfunction:: PyObject* Py_BuildValue(const char *format, ...)
  314. Create a new value based on a format string similar to those accepted by
  315. the :cfunc:`PyArg_Parse\*` family of functions and a sequence of values.
  316. Returns the value or *NULL* in the case of an error; an exception will be
  317. raised if *NULL* is returned.
  318. :cfunc:`Py_BuildValue` does not always build a tuple. It builds a tuple
  319. only if its format string contains two or more format units. If the format
  320. string is empty, it returns ``None``; if it contains exactly one format
  321. unit, it returns whatever object is described by that format unit. To
  322. force it to return a tuple of size 0 or one, parenthesize the format
  323. string.
  324. When memory buffers are passed as parameters to supply data to build
  325. objects, as for the ``s`` and ``s#`` formats, the required data is copied.
  326. Buffers provided by the caller are never referenced by the objects created
  327. by :cfunc:`Py_BuildValue`. In other words, if your code invokes
  328. :cfunc:`malloc` and passes the allocated memory to :cfunc:`Py_BuildValue`,
  329. your code is responsible for calling :cfunc:`free` for that memory once
  330. :cfunc:`Py_BuildValue` returns.
  331. In the following description, the quoted form is the format unit; the entry
  332. in (round) parentheses is the Python object type that the format unit will
  333. return; and the entry in [square] brackets is the type of the C value(s) to
  334. be passed.
  335. The characters space, tab, colon and comma are ignored in format strings
  336. (but not within format units such as ``s#``). This can be used to make
  337. long format strings a tad more readable.
  338. ``s`` (string) [char \*]
  339. Convert a null-terminated C string to a Python object. If the C string
  340. pointer is *NULL*, ``None`` is used.
  341. ``s#`` (string) [char \*, int]
  342. Convert a C string and its length to a Python object. If the C string
  343. pointer is *NULL*, the length is ignored and ``None`` is returned.
  344. ``z`` (string or ``None``) [char \*]
  345. Same as ``s``.
  346. ``z#`` (string or ``None``) [char \*, int]
  347. Same as ``s#``.
  348. ``u`` (Unicode string) [Py_UNICODE \*]
  349. Convert a null-terminated buffer of Unicode (UCS-2 or UCS-4) data to a
  350. Python Unicode object. If the Unicode buffer pointer is *NULL*,
  351. ``None`` is returned.
  352. ``u#`` (Unicode string) [Py_UNICODE \*, int]
  353. Convert a Unicode (UCS-2 or UCS-4) data buffer and its length to a
  354. Python Unicode object. If the Unicode buffer pointer is *NULL*, the
  355. length is ignored and ``None`` is returned.
  356. ``i`` (integer) [int]
  357. Convert a plain C :ctype:`int` to a Python integer object.
  358. ``b`` (integer) [char]
  359. Convert a plain C :ctype:`char` to a Python integer object.
  360. ``h`` (integer) [short int]
  361. Convert a plain C :ctype:`short int` to a Python integer object.
  362. ``l`` (integer) [long int]
  363. Convert a C :ctype:`long int` to a Python integer object.
  364. ``B`` (integer) [unsigned char]
  365. Convert a C :ctype:`unsigned char` to a Python integer object.
  366. ``H`` (integer) [unsigned short int]
  367. Convert a C :ctype:`unsigned short int` to a Python integer object.
  368. ``I`` (integer/long) [unsigned int]
  369. Convert a C :ctype:`unsigned int` to a Python integer object or a Python
  370. long integer object, if it is larger than ``sys.maxint``.
  371. ``k`` (integer/long) [unsigned long]
  372. Convert a C :ctype:`unsigned long` to a Python integer object or a
  373. Python long integer object, if it is larger than ``sys.maxint``.
  374. ``L`` (long) [PY_LONG_LONG]
  375. Convert a C :ctype:`long long` to a Python long integer object. Only
  376. available on platforms that support :ctype:`long long`.
  377. ``K`` (long) [unsigned PY_LONG_LONG]
  378. Convert a C :ctype:`unsigned long long` to a Python long integer object.
  379. Only available on platforms that support :ctype:`unsigned long long`.
  380. ``n`` (int) [Py_ssize_t]
  381. Convert a C :ctype:`Py_ssize_t` to a Python integer or long integer.
  382. .. versionadded:: 2.5
  383. ``c`` (string of length 1) [char]
  384. Convert a C :ctype:`int` representing a character to a Python string of
  385. length 1.
  386. ``d`` (float) [double]
  387. Convert a C :ctype:`double` to a Python floating point number.
  388. ``f`` (float) [float]
  389. Same as ``d``.
  390. ``D`` (complex) [Py_complex \*]
  391. Convert a C :ctype:`Py_complex` structure to a Python complex number.
  392. ``O`` (object) [PyObject \*]
  393. Pass a Python object untouched (except for its reference count, which is
  394. incremented by one). If the object passed in is a *NULL* pointer, it is
  395. assumed that this was caused because the call producing the argument
  396. found an error and set an exception. Therefore, :cfunc:`Py_BuildValue`
  397. will return *NULL* but won't raise an exception. If no exception has
  398. been raised yet, :exc:`SystemError` is set.
  399. ``S`` (object) [PyObject \*]
  400. Same as ``O``.
  401. ``N`` (object) [PyObject \*]
  402. Same as ``O``, except it doesn't increment the reference count on the
  403. object. Useful when the object is created by a call to an object
  404. constructor in the argument list.
  405. ``O&`` (object) [*converter*, *anything*]
  406. Convert *anything* to a Python object through a *converter* function.
  407. The function is called with *anything* (which should be compatible with
  408. :ctype:`void \*`) as its argument and should return a "new" Python
  409. object, or *NULL* if an error occurred.
  410. ``(items)`` (tuple) [*matching-items*]
  411. Convert a sequence of C values to a Python tuple with the same number of
  412. items.
  413. ``[items]`` (list) [*matching-items*]
  414. Convert a sequence of C values to a Python list with the same number of
  415. items.
  416. ``{items}`` (dictionary) [*matching-items*]
  417. Convert a sequence of C values to a Python dictionary. Each pair of
  418. consecutive C values adds one item to the dictionary, serving as key and
  419. value, respectively.
  420. If there is an error in the format string, the :exc:`SystemError` exception
  421. is set and *NULL* returned.
  422. .. cfunction:: PyObject* Py_VaBuildValue(const char *format, va_list vargs)
  423. Identical to :cfunc:`Py_BuildValue`, except that it accepts a va_list
  424. rather than a variable number of arguments.